Package pexicdb

Pexicdb

Pexicdb is a simple model based file database, pexicdb is a lightweight and stores data in the folders and files, basically a folder is called container.

There are 2 types of files inside container

  1. container file(models stored in this)
  2. data file(contains all data about the container)

Pexicdb interact with the containers using model which is usually a list of fields.

from pexicdb.fields import StringField, UUIDField
from pexicdb import connect

user_model = {
    "id": UUIDField("id"),
    "name": StringField("name")
}

users = connect("users", list(user_model).values())

NOTE : The first field of any Model must be either UUIDField or an IntegerField.

Expand source code
"""
    # Pexicdb

    Pexicdb is a simple model based file database, pexicdb is a lightweight and stores
    data in the folders and files, basically a folder is called container.

    There are 2 types of files inside container
    
    1. container file(models stored in this)
    2. data file(contains all data about the container)

    Pexicdb interact with the containers using model which is usually a list of fields.
    ```
    from pexicdb.fields import StringField, UUIDField
    from pexicdb import connect

    user_model = {
        "id": UUIDField("id"),
        "name": StringField("name")
    }

    users = connect("users", list(user_model).values())
    ```

    **NOTE :** The first field of any Model must be either `UUIDField` or an `IntegerField`.
"""

from .__about__ import __name__, __version__, __author__, __author_email__, __license__
from .functions import connect

__all__ = ["connect", ]

Sub-modules

pexicdb.core
pexicdb.fields
pexicdb.functions
pexicdb.helpers
pexicdb.lock

Functions

def connect(name: str, model: list, *args, **kwargs) ‑> PexicdbCursor

connect to the container using the name and you have to provide a model that is passed to the cursor.

connect() function's main work is to create the container if it does not exists and create the cursor with all file pointers and return it.

Arguments

name: container name

model: model of the list containing fields

Returns

returns the PexicdbCursor object to the container

Expand source code
def connect(name: str, model: list, *args, **kwargs) -> PexicdbCursor:
    """
    connect to the container using the name and you have to provide a model
    that is passed to the cursor.

    `connect` function's main work is to create the container if it does not exists
    and create the cursor with all file pointers and return it.


    Arguments:
        `name`: container name

        `model`: model of the list containing fields
    
    Returns:
        returns the PexicdbCursor object to the container
    """
    # if container not found or not exists
    if os.path.exists(name) is not True or os.path.isdir(name) is not True:
        # create new one
        __create_fresh(name)

    return PexicdbCursor(
        name,
        model,
        open(os.path.join(name, "datafile"), "rb+"),
        open(get_current_container_name(name), "rb+"),
        *args,
        **kwargs
    )