ormlite package
Module contents
- ormlite.connect_to_sqlite(file_name)[source]
Opens a new sqlite connection in Auto-commit mode.
- Parameters:
file_name (
str) – sqlite database file to open (or create if it doesn’t exist yet). Use the special argument of “:memory:” to only hold the database in memory and skip writing to file.- Return type:
Connection
- ormlite.migrate(db)[source]
Warning: This will destructively delete your data. Don’t use this if want to keep old tables data around even if there’s no corresponding python model.
Your python code is treated as the source of truth, and migrate forces your sqlite schema to match.
Every python class with the @model decorator is synced with a sqlite table. Every sqlite table that has no corresponding model is deleted.
- Specifically, this:
Creates new tables to match new models
Drops tables that don’t correspond to any defined models
Adds new columns to existing tables
Drops old columns from existing tables
- ormlite.select(model)[source]
Begin a select query. Literally just an alias for the
SelectQueryconstructor.- Parameters:
model (
type[TypeVar(Model)]) – Model class; this determines which model is when binding the sql rows into python objects- Return type:
SelectQuery[TypeVar(Model)]
- ormlite.upsert(db, records, *, update)[source]
Insert records, on conflict, update fields but only specific ones
- Parameters:
db (
DatabaseConnection) – A sqlite database connectionrecords (
list[TypeVar(Model)]) – Records to insert or updateupdate (
list[str]) – List of column names to update in case of conflict
ormlite.query module
- class ormlite.query.SelectQuery(model)[source]
Select query builder. This object is mutable and chainable way to describe a sql query. These methods mutate the builder and return the builder to continue the chain:
extra
where
limit
join
order_by
- These methods execute the current query:
rows
models
dicts
- extra(*fields)[source]
- Return type:
SelectQuery[TypeVar(Model)]
- join(model, /)[source]
Join with another table. :param: model
- Return type:
SelectQuery[TypeVar(Model)]
- limit(limit, /)[source]
Applies a sql LIMIT. Note that calling this multiple times on the same query, will override the previously set limit.
- Return type:
SelectQuery[TypeVar(Model)]
- order_by(clause, /)[source]
- Return type:
SelectQuery[TypeVar(Model)]
- where(condition=None, /, **kwargs)[source]
- Return type:
SelectQuery[TypeVar(Model)]