ORM-SQLite
ORM-SQLite is
- a lightweight ORM for SQLite
- written in Python (3.7+) Standard Library
Quickstart
-
Define a
Pomodoromodelimport orm_sqlite class Pomodoro(orm_sqlite.Model): id = orm_sqlite.IntegerField(primary_key=True) # auto-increment task = orm_sqlite.StringField() interval = orm_sqlite.IntegerField()
-
Create a
Databaseinstancedb = orm_sqlite.Database('example.db')
-
Set it as backend of
Pomodoromodel objects, CRUD operations thus can be performed laterPomodoro.objects.backend = db
-
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)
-
Retrieve all the records in the backend
Pomodoro.objects.all()
-
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)
-
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)
-
Disconnect the backend
Pomodoro.objects.backend.close()
Install ORM-SQLite
$ pip install orm-sqlite
Documentation
Module Database
class orm_sqlite.Database(database[, timeout, detect_types, isolation_level, check_same_thread, factory, cached_statements, uri])
-
connectedInstance attribute: Whether or not the SQLite database is connected.
-
connectionInstance attribute:
sqlite3.Connectionobject -
cursorInstance attribute:
sqlite3.Cursorobject -
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.Rowobjects. -
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 orm_sqlite.StringField(name=None, default='')
-
nameInstance attribute: Column name. Default:
None. -
typeInstance attribute: Column type. Default:
TEXT. -
defaultInstance attribute: Column default value. Default:
''. -
primary_keyInstance attribute: Whether or not it is the primary key. Default:
False.
Module IntegerField
class orm_sqlite.IntegerField(name=None, default=0, primary_key=False)
-
nameInstance attribute: Column name. Default:
None. -
typeInstance attribute: Column type. Default:
INTEGER. -
defaultInstance attribute: Column default value. Default:
0. -
primary_keyInstance attribute: Whether or not it is the primary key. Default:
False.
Module FloatField
class orm_sqlite.StringField(name=None, default=0.0)
-
nameInstance attribute: Column name. Default:
None. -
typeInstance attribute: Column type. Default:
REAL. -
defaultInstance attribute: Column default value. Default:
0.0. -
primary_keyInstance attribute: Whether or not it is the primary key. Default:
False.
Module Model
class orm_sqlite.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.
-
objectsClass-only attribute:
orm_sqlite.Managerobject used to manage correspondingModelobjects. -
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
Modelobject to table in the connected database and returns rows affected (1 or -1). -
update()Instance method: Updates
Modelobject from table in the connected database and returns rows affected (1 or -1). Dangerous. -
delete()Instance method: Deletes
Modelobject from table in the connected database and returns rows affected (1 or -1). Dangerous. -
keys(),values(),items(),copy(), etc. methods inherited from standarddict.
Practical template for customized model:
import orm_sqlite
class MyModel(orm_sqlite.Model):
id = orm_sqlite.IntegerField(primary_key=True) # auto-increment
# TODO:
Module Manager
class orm_sqlite.Manager()
-
backendInstance attribute:
orm_sqlite.Databaseobject serving as backend ofModelobjects. -
all()Instance method: Returns all
Modelobjects from table in the connected database. -
find(filter=None, order_by=None, **extra)Instance method: Returns all
Modelobjects satified the conditions from table in the connected database. -
get(pk)Instance method: Returns single
Modelobject 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
Modelobject to table in the connected database and returns rows affected (1 or -1). -
update(obj)Instance method: Updates
Modelobject from table in the connected database and returns rows affected (1 or -1). Dangerous. -
remove(obj)Instance method: Deletes
Modelobject from table in the connected database and returns rows affected (1 or -1). Dangerous. -
clear()Instance method: Deletes all
Modelobjects 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.loggerobject, logging in main module. -
child_logger(child)Returns child logger, a
logging.loggerobject, logging in auxiliary module.
Related Projects
- Inspired by Django ORM
Metadata
Release files for ORM-SQLite 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ORM-SQLite-0.0.2.tar.gz | 7.3 kB | Without provenance | Details for ORM-SQLite-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ORM_SQLite-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for ORM_SQLite-0.0.2-py3-none-any.whl |
Total release size: 15.5 kB
Release files / ORM-SQLite-0.0.2.tar.gz
| Download URL | ORM-SQLite-0.0.2.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
16601b25e8d4504df3c149ef842f953347d148922defa26eb50ae5a882d96354
|
|
BLAKE2b-256 checksum How to use checksums |
d1799f9ca7f9db65ca303cf0bc20f7d60ff0afb47c381e02dc8b37b3f328c824
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.6.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7
|
Release files / ORM_SQLite-0.0.2-py3-none-any.whl
| Download URL | ORM_SQLite-0.0.2-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dffe9ec45fddad3eba141b0699f7fed13e40426577778ec35aa1dc002308adb3
|
|
BLAKE2b-256 checksum How to use checksums |
be56bba152268a16f25ec97c7b3d58f72be779dd5c35166940a228401b952cd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.6.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7
|
Security for ORM-SQLite 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.