Skip to main content

Vys Documentation

DB Schema documentation:

SqLite Syntax

from Vys import models

cfg = models.DbCredentials(database='test.db')

class Employee(models.LiteSchema):
    def __init__(self, *args, **kwargs):
        super().__init__(db_credentials=cfg, table='employee')

Create the schema parameters

class Employee(models.LiteSchema):
    def __init__(self, *args, **kwargs):
        super().__init__(db_credentials=cfg, table='employee')
        self.add_params({
            'name': {
                'dbtype': 'varchar(255)',
                'type': str
            },
            'manager': {
                'dbtype': 'varchar(9)'
            }
        })
        self.init_schema(args, kwargs)

IDs for SqLite are added automatically.

Dbtype and type is different purely for validation purposes - type is for schema validation, dbtype corresponds to the data type in the database.

Query

user = User
x = user.find(
    query={
        'user': 'connor.white'
    },
    fetch=['perms']
)
# Returns [{'ID': 'ShlLuRWaa', 'createdAt': '2020-09-04 11:32:44.132863', 'updatedAt': '2020-09-04 11:32:44.132863', 'manager': None, 'name': 'tefrstf'}

x = user.find_one(
    query={
        'user': 'connor.white'
    },
    fetch=['perms']
)
# Returns {'ID': 'ShlLuRWaa', 'createdAt': '2020-09-04 11:32:44.132863', 'updatedAt': '2020-09-04 11:32:44.132863', 'manager': None, 'name': 'tefrstf'}

user.populate(
    query={'name': 'tefrstf'} 
)
print(user)

# OR

user.populate(
    name='newname'
)

# Returns # Returns {'ID': 'ShlLuRWaa', 'createdAt': '2020-09-04 11:32:44.132863', 'updatedAt': '2020-09-04 11:32:44.132863', 'manager': None, 'name': 'tefrstf'}

user.populate_many(
    query={'name': 'tefrstf'} 
)
print(user)
# Returns {'createdAt': ['2020-09-04 11:32:44.132863', '2020-09-04 11:33:02.841748', '2020-09-04 11:33:37.348974', '2020-09-04 11:37:57.689165', '2020-09-04 11:38:11.541987', '2020-09-04 11:39:46.465859', '2020-09-04 11:40:28.353423'], 'updatedAt': ['2020-09-04 11:32:44.132863', '2020-09-04 11:33:02.841748', '2020-09-04 11:33:37.348974', '2020-09-04 11:37:57.689165', '2020-09-04 11:38:11.541987', '2020-09-04 11:39:46.465859', '2020-09-04 11:40:28.353423'], 'name': ['tefrstf', 'tefrstf', 'tefrstf', 'tefrstf', 'tefrstf', 'tefrstf', 'tefrstf'], 'manager': [None, None, None, None, None, None, None], 'ID': ['ShlLuRWaa', 'jkkVrB06P', 'LXCBlqUhN', 'tLCrf5EzW', '8EJzjBtwO', 'TrPxwtTXo', 'wRTuXYKe1']}

The fetch parameter is not required here, excluding it will return all columns. Find will return multiple, find_one only one.

Create

User.create({
    'user': 'new',
    'password': 'hffgv'
})

user = User('create', name='name', password='hffgv')

The id will be done automatically, as will the "CreatedAt" and "UpdatedAt" Fields. This will insert a new row into the db.

Update

User.find_and_update(
    query={
        'perms': 'user'
    },
    update={
        'perms': 'silly'
    }
)

############################################

User.populate({
    'name': 'tefrstf'
})

mark.update({
    'name': 'testing123'
})

# OR

mark.update(
    name='testing123'
)

Find and update will update all instances - as the "find" function returns a python dict, you can input them directly into the query section here. Using the .update function on a class that has been populated will only update that row.

Adding a foreign key to a table.

options = {
    'column': 'manager',
    'table': 'managers',
    'foreign column': 'ID'
}


class Employee(models.LiteSchema):
    def __init__(self, *args, **kwargs):
        super().__init__(db_credentials=cfg, table='employee', f_keys=options)
        self.add_params({
            'name': {
                'dbtype': 'varchar(255)',
                'type': str
            },
            'manager': {
                'dbtype': 'varchar(9)'
            }
        })
        self.expand_param(
            param='manager',
            fetch='ID, name'
        )
        self.init_schema(args, kwargs)

This snippet creates a column linked to a foreign key. In the "options" dict, the keys should be self explanatory. The expand_param function expands the return - so instead of returning the ID of the field, it will return info from the column in which that key is present in the other table.

Creating the virtual population.

class Manager(models.LiteSchema):
    def __init__(self, db_credentials=cfg, table='managers'):
        super().__init__(db_credentials, table)
        self.add_params({
            'name': {
                'dbtype': 'varchar(255)',
                'type': str
            }
        })
        self.add_virtual({
            'table': 'employee',
            'foreign_column': 'manager',
            'field': 'ID'
        })

The dict takes 3 arguments. "Table" is the target table where the foreign key is located. "Foreign column" is the column where the key is located. "Field" is the local column where the key is located.

Populating the virtual field.

manager = Manager()

manager.populate_new(name='connor')
manager.populate_virtual()

print(manager.virtual)

# Returns [{'ID': 'o0l5i2nIr', 'createdAt': '2020-08-31 20:51:08.422624', 'updatedAt': '2020-09-02 08:43:51.600846', 'manager': 'w47mlx4df', 'name': 'mark'}]

print(manager.virtual.o0l5i2nIr)

# Returns {'ID': 'o0l5i2nIr', 'createdAt': '2020-08-31 20:51:08.422624', 'updatedAt': '2020-09-02 08:43:51.600846', 'manager': 'w47mlx4df', 'name': 'mark'}

Datetime manipulation

DatetimeGenerator

datetime_object = DatetimeGenerator(
    datetime_input=datetime.strptime('2000-08-31 10:22:08', '%Y-%m-%d %H:%M:%S'),
    format='iso',
    str_format='%Y-%m-%d'
)
datetime_object.add(hours=9, days=12)

Datetime input can be any datetime object. Format can be either "datetime", "iso", "unix", or "string".

Leaving datetime input blank will generate the current time. Leaving the format blank defaults to datetime. Str_format should only be used when the format is put as string.

You can add or subtract values of time with the add and subtract methods.

Metadata

Release files for Vys 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Vys 0.2.2
File Size Uploaded
Vys-0.2.2.tar.gz 13.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Vys 0.2.2
File Interpreter ABI Platform
Vys-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 29.1 kB

Release files / Vys-0.2.2.tar.gz

Download URL Vys-0.2.2.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
682d48f3a7ed67cde2ec40688c2a354182a6552555ea5ed597d5aa8fb6bf0203
BLAKE2b-256 checksum
How to use checksums
8ab7bf23c1dd5c2f95a5db2041880f2c27652b61d2758ee18c5e65cf165cf471
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release files / Vys-0.2.2-py3-none-any.whl

Download URL Vys-0.2.2-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc0bb5d267c45b95ab09db616e6fcffbd8726cc4044df07459fa012e75147f35
BLAKE2b-256 checksum
How to use checksums
b3e97d4ce0ba4f4e0a47c36bce910c1a47232f0d3240a606a8a3d6c3f0e049a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page