SQL Expressions Repository
Contents
SQL Expressions Repository#
SQLExprRepo is a repository that relies on SQLAlchemy’s SQL expressions which are pieces of SQL code represented in Python.
It can be initiated using SQLAlchemy engine:
from sqlalchemy import create_engine
from redbird.repos import SQLExprRepo
engine = create_engine('sqlite://')
repo = SQLExprRepo(engine=engine, table="my_table")
Usage#
Now you may use the repository the same way as any other repository. Please see:
Class#
- class redbird.repos.SQLExprRepo(*args, model=<class 'dict'>, id_field=None, query_model=<class 'redbird.base.BasicQuery'>, errors_query='raise', field_access='infer', ordered=False, table=None, engine=None)#
- insert(item)#
Insert item to the repository
- Parameters
item (instance of model) – Item to insert to the repository
Examples
repo.insert(Item(id="a", color="red"))
- filter_by(**kwargs)#
Filter the repository
- Parameters
**kwargs (dict) – Query which is used to conduct furher operation.
Examples
repo.filter_by(color="red")
- update(item)#
Update item in the repository
- Parameters
item (instance of model) – Item to update in the repository
Examples
repo.update(Item(id="a", color="red"))
- delete(item)#
Delete item from the repository
- Parameters
item (instance of model) – Item to delete from the repository
Examples
repo.delete(Item(id="a", color="red"))