A small package for performing basic CRUD operations with sqlite via aiosqlite and pydantic
Project description
ardilla
Ardilla (pronounced ahr-dee-yah) means "SQuirreL" in spanish.
A very simple library to quickly add SQLite to your program. It leverages pydantic for data validation and modeling. It comes in sync (sqlite3) and async (aiosqlite) flavors.
Who and what is this for:
The target audience for this library are developers who want to incorporate a SQLite database to their applications in a fast and easy way.
What this library excels in simplicity it lacks in flexibility so, if you're expecting to use complex queries and intricate relationships, you should should consider other libraries like tortoise-orm, sqlalchemy, pony or peewee.
install
Install lastest release from PyPi
pip install -U ardilla´
pip install -U ardilla[async]
Or install the lastest changes directly from github
pip install git+https://github.com/chrisdewa/ardilla.git
pip install git+https://github.com/chrisdewa/ardilla.git#egg=ardilla[async]
How to use:
from ardilla import Engine, Model, Crud
engine = Engine('db.sqlite3')
Crud.engine = engine
class User(Model):
id: int
name: str
age: int
user_crud: Crud[User] = Crud(User)
def main():
engine.setup() # creates tables
# get or none
user = user_crud.get_or_none(id=1)
# get or create
user2, was_created = user_crud.get_or_create(id=2, name='chris', age=35)
# save one
user3 = User(id=3, name='moni', age=35)
user_crud.save_one(user3)
# save many
user_crud.save_many(user, user2, user3)
# get many
users = user_crud.get_many(age=35)
Supported CRUD methods:
crud.get_or_none
Returns an object or Nonecrud.insert
Inserts a record, rises errors if there's a conflictcrud.insert_or_ignore
Inserts a record or silently ignores if it already existscrud.get_or_create
returns an tuple of the object and a bool, True if the object was newly createdcrud.get_all
equivalent toSELECT * FROM tablename
crud.get_many
returns all the objects that meet criteriacrud.save_one
upserts an objectcrud.save_many
upserts many objectscrud.delete_one
deletes one objectcrud.delete_many
deletes many objects
To-dos
- Docstring everything using Google format
- Add testing
- Add proper documentation
- propper as in a site with how to use
- Add a schema generator
- There should be a method to generate a table's schema off the pydantic model.
- Add a method somewhere to fetch relationships.
- Improve this read
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ardilla-0.0.3a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4ca70e9a12bd90363e340f56aaf1b5321f4b72e095bb76699d3b773faf69cc7 |
|
MD5 | dab7cdb8f07664b5ce6c8e47b1b60968 |
|
BLAKE2b-256 | 07c6a431c13cd0a804bcf10df6a6079ebb9f18ec15d37467f6bc605a3d3950ad |