Skip to main content

A lightweight ORM for SQLite with VECTOR

Project description

SQLite VEC ORM

SQLite VEC ORM is

Quickstart

  1. Define a Pomodoro model

    import sqlite_orm
    
    class Pomodoro(sqlite_orm.Model):
    
        id = sqlite_orm.IntegerField(primary_key=True) # auto-increment
        task = sqlite_orm.StringField()
        interval = sqlite_orm.IntegerField()
    
  2. Create a Database instance

    db = sqlite_orm.Database('example.db')
    
  3. Set it as backend of Pomodoro model objects, CRUD operations thus can be performed later

    Pomodoro.objects.backend = db
    
  4. Create a Pomodoro timer record (primary key is auto-increment) and insert it to backend (auto-commited)

    pomodoro = Pomodoro({'task': 'do something', 'interval': 25})
    pomodoro.save()
    

    which is equivalent to

    pomodoro = Pomodoro({'task': 'do something', 'interval': 25})
    Pomodoro.objects.add(pomodoro)   
    
  5. Retrieve all the records in the backend

    Pomodoro.objects.all()
    
  6. Retrieve single record by its primary key and update it (auto-commited)

    obj = Pomodoro.objects.get(pk=1)
    obj['task'] = 'do something else'
    obj.update()
    

    which is equivalent to

    obj = Pomodoro.objects.get(pk=1)
    obj['task'] = 'do something else'
    Pomodoro.objects.update(obj)
    
  7. Retrieve single record by its primary key and delete it (auto-commited)

    Pomodoro.objects.get(pk=1).delete()
    

    which is equivalent to

    obj = Pomodoro.objects.get(pk=1)
    Pomodoro.objects.remove(obj)
    
  8. Disconnect the backend

    Pomodoro.objects.backend.close()
    

Install SQLite VEC ORM

$ pip install orm-sqlite

Documentation

Module Database

class sqlite_orm.Database(database[, timeout, detect_types, isolation_level, check_same_thread, factory, cached_statements, uri])
  • connected

    Instance attribute: Whether or not the SQLite database is connected.

  • connection

    Instance attribute: sqlite3.Connection object

  • cursor

    Instance attribute: sqlite3.Cursor object

  • connect()

    Instance method: Connects the SQLite database if disconnected.

  • close()

    Instance method: Disconnects the SQLite database if connected.

  • select(sql, *args, size=None)

    Instance method: Returns query results, a list of sqlite3.Row objects.

  • execute(sql, *args, autocommit=True)

    Instance method: Executes an SQL statement and returns rows affected.

  • commit()

    Instance method: Commits the staged transaction.

Module StringField

class sqlite_orm.StringField(name=None, default='')
  • name

    Instance attribute: Column name. Default: None.

  • type

    Instance attribute: Column type. Default: TEXT.

  • default

    Instance attribute: Column default value. Default: ''.

  • primary_key

    Instance attribute: Whether or not it is the primary key. Default: False.

Module IntegerField

class sqlite_orm.IntegerField(name=None, default=0, primary_key=False)
  • name

    Instance attribute: Column name. Default: None.

  • type

    Instance attribute: Column type. Default: INTEGER.

  • default

    Instance attribute: Column default value. Default: 0.

  • primary_key

    Instance attribute: Whether or not it is the primary key. Default: False.

Module FloatField

class sqlite_orm.StringField(name=None, default=0.0)
  • name

    Instance attribute: Column name. Default: None.

  • type

    Instance attribute: Column type. Default: REAL.

  • default

    Instance attribute: Column default value. Default: 0.0.

  • primary_key

    Instance attribute: Whether or not it is the primary key. Default: False.

Module Model

class sqlite_orm.Model(*args, **kwargs)
  • __table__

    Class attribute: Table.

  • __mappings__

    Class attribute: Object Relational Mappings (ORMs).

  • __primary_key__

    Class attribute: Primary key.

  • __fields__

    Class attribute: Fields except primary key.

  • objects

    Class-only attribute: sqlite_orm.Manager object used to manage corresponding Model objects.

  • exists()

    Class-only method: Whether or not the table exists in the connected database.

  • create()

    Class-only method: Create the table if not exists in the connected database.

  • drop()

    Class-only method: Drop the table if exists in the connected database, objects.backend.commit() needed to confirm. Extremely Dangerous.

  • save()

    Instance method: Inserts Model object to table in the connected database and returns rows affected (1 or -1).

  • update()

    Instance method: Updates Model object from table in the connected database and returns rows affected (1 or -1). Dangerous.

  • delete()

    Instance method: Deletes Model object from table in the connected database and returns rows affected (1 or -1). Dangerous.

  • keys(), values(), items(), copy(), etc. methods inherited from standard dict.

Practical template for customized model:

import sqlite_orm

class MyModel(sqlite_orm.Model):

    id = sqlite_orm.IntegerField(primary_key=True) # auto-increment
    # TODO:   

Module Manager

class sqlite_orm.Manager()
  • backend

    Instance attribute: sqlite_orm.Database object serving as backend of Model objects.

  • all()

    Instance method: Returns all Model objects from table in the connected database.

  • find(filter=None, order_by=None, **extra)

    Instance method: Returns all Model objects satified the conditions from table in the connected database.

  • get(pk)

    Instance method: Returns single Model object by its primary key from table in the connected database.

  • exists(pk)

    Instance method: Whether or not a primary key exists in the table from the connected database.

  • aggregate(self, expression, filter=None)

    Instance method: Returns the result of an aggregate function performed on table in the connected database.

  • add(obj)

    Instance method: Inserts Model object to table in the connected database and returns rows affected (1 or -1).

  • update(obj)

    Instance method: Updates Model object from table in the connected database and returns rows affected (1 or -1). Dangerous.

  • remove(obj)

    Instance method: Deletes Model object from table in the connected database and returns rows affected (1 or -1). Dangerous.

  • clear()

    Instance method: Deletes all Model objects from table in the connected database and returns rows affected (1 or -1), backend.commit() needed to confirm. Extremely Dangerous.

Helper Function

  • root_logger(log_dir='.')

    Returns root logger, a logging.logger object, logging in main module.

  • child_logger(child)

    Returns child logger, a logging.logger object, logging in auxiliary module.

Related Projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlite_orm_vec_qpython-0.1.5.tar.gz (826.3 kB view details)

Uploaded Source

Built Distribution

sqlite_orm_vec_qpython-0.1.5-py3-none-any.whl (825.7 kB view details)

Uploaded Python 3

File details

Details for the file sqlite_orm_vec_qpython-0.1.5.tar.gz.

File metadata

  • Download URL: sqlite_orm_vec_qpython-0.1.5.tar.gz
  • Upload date:
  • Size: 826.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for sqlite_orm_vec_qpython-0.1.5.tar.gz
Algorithm Hash digest
SHA256 8dd64c16dc40c2260e1ec9deb8768420e30caa1b67fb4687d80809e8b9f88eef
MD5 7068940c79fa21a97b80d252cec572c3
BLAKE2b-256 3a4830f92a299fdd9d776dc8d7edb7a26f323698c0e55f92a1de8696ce38482e

See more details on using hashes here.

File details

Details for the file sqlite_orm_vec_qpython-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlite_orm_vec_qpython-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 bd48c03d6d04ee21d58a55c892395274d0417412fe193f753bc830e93abb20b2
MD5 bede24c11e1de76da01bba6be4e24261
BLAKE2b-256 f5b3187d43d462a900c5ff258ccf71b90d817093f9b97f973e55cf9273a8b14f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page