Skip to content

Latest commit

 

History

113 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ardilla

Downloads PyPI - Python Version PyPI GitHub Documentation Status

Ardilla (pronounced ahr-dee-yah) means "SQuirreL" in spanish.

This library aims to be a simple way to add an SQLite database and basic C.R.U.D. methods to Python applications. It uses pydantic v2 for data validation and supports both a sync engine and an async (aiosqlite) version.

Who and what is this for

This library is well suited for developers seeking to incorporate SQLite into their Python applications using simple C.R.U.D. methods. It excels in its simplicity and ease of implementation, but may not be suitable for those who require complex querying, intricate relationships, or top performance.

For more advanced features, consider tortoise-orm, sqlalchemy, pony, or peewee.

Links

Source code: github.com/chrisdewa/ardilla

Documentation: ardilla.rtfd.io

Install

Install the latest release from PyPI:

pip install -U ardilla
pip install -U ardilla[async]  # includes aiosqlite
pip install -U ardilla[dev]    # includes formatting and testing dependencies

Or install the latest 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]
pip install git+https://github.com/chrisdewa/ardilla.git#egg=ardilla[dev]

How to use

from ardilla import Engine, Model, Field

class User(Model):
    id: int = Field(pk=True, auto=True)
    name: str
    age: int

with Engine('db.sqlite') as engine:
    crud = engine.crud(User)
    user = crud.get_or_none(id=1)
    user2, was_created = crud.get_or_create(id=2, name='chris', age=35)
    users = crud.get_many(name='chris')
    user3 = User(id=3, name='moni', age=35)
    user2.age += 1
    crud.save_one(user3)
    crud.save_many(user2, user3)

Supported CRUD methods

  • crud.insert — inserts a record, raises an error on conflict
  • crud.insert_or_ignore — inserts a record, silently ignores if it already exists
  • crud.save_one — upserts a single object
  • crud.save_many — upserts multiple objects
  • crud.get_all — equivalent to SELECT * FROM tablename
  • crud.get_many — returns all objects matching the given criteria
  • crud.get_or_create — returns a tuple of (object, created: bool)
  • crud.get_or_none — returns the first matching object, or None
  • crud.delete_one — deletes a single object
  • crud.delete_many — deletes multiple objects

Examples

About

A simplistic sqlite python ORM with pydantic models

Resources

Stars

26 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages