SQLite Database
Submodules
- sqlite_database.column module
- sqlite_database.csv module
- sqlite_database.errors module
- sqlite_database.locals module
- sqlite_database.operators module
- sqlite_database.query_builder module
- sqlite_database.signature module
- sqlite_database.table module
Table
Table.add_column()
Table.columns()
Table.delete()
Table.delete_one()
Table.deleted
Table.exists()
Table.force_nodelete()
Table.get_namespace()
Table.insert()
Table.insert_many()
Table.insert_multiple()
Table.name
Table.paginate_select()
Table.rename_column()
Table.select()
Table.select_one()
Table.update()
Table.update_one()
- sqlite_database.typings module
Module contents
Database
- class sqlite_database.Column(name: str, type_: str, foreign: bool = False, foreign_ref: str | None = None, primary: bool = False, unique: bool = False, nullable: bool = True, default: Any = None, on_delete: Literal['null', 'cascade', 'no act', 'default', 'restrict'] = 'cascade', on_update: Literal['null', 'cascade', 'no act', 'default', 'restrict'] = 'cascade')[source]
Bases:
object
tip: for foreign_ref, you can split with / to separate table and column name. e.g: user/id
- property default
Default value
- property foreign
Is foreign enabled?
- property name
Column Name
- property nullable
Nullable
- property on_delete
Delete setting
- property on_update
Update setting
- property primary
Is primary or not?
- property raw_source
Source / Foreign Reference
- property source
Source / Foreign Reference
- property source_column
Source column / Foreign reference column
- property type
Type
- property unique
Is unique
- class sqlite_database.Database(path: str, **kwargs)[source]
Bases:
object
Sqlite3 database, this provide basic integration.
- property closed
Is database closed?
- create_table(table: str, columns: Iterable[Column] | Iterable[BuilderColumn])[source]
Create table
- property path
Path to SQL Connection
- reset_table(table: str, columns: Iterable[Column] | Iterable[BuilderColumn]) Table [source]
Reset existing table with new, this rewrote entire table than altering it.
- property sql
SQL Connection
- class sqlite_database.Table(parent, table: str, _Table__columns: Iterable[Column] | None = None)[source]
Bases:
object
Table. Make sure you remember how the table goes.
- add_column(column: Column | BuilderColumn)[source]
Add column to table
- delete(condition: dict[str, Signature | ParsedFn | Any] | list[tuple[str, Signature | ParsedFn]] | None = None, limit: int = 0, order: dict[str, Literal['asc', 'desc']] | None = None)[source]
Delete row or rows
- Parameters:
condition (Condition, optional) – Condition to determine deletion See Signature class about conditional stuff. Defaults to None.
limit (int, optional) – Limit deletion by integer. Defaults to 0.
order (Optional[Orders], optional) – Order of deletion. Defaults to None.
- Returns:
Rows affected
- Return type:
int
- delete_one(condition: dict[str, Signature | ParsedFn | Any] | list[tuple[str, Signature | ParsedFn]] | None = None, order: dict[str, Literal['asc', 'desc']] | None = None)[source]
Delete a row
- Parameters:
condition (Condition, optional) – Conditional to determine deletion.
None. (Defaults to)
order (Optional[Orders], optional) – Order of deletion. Defaults to None.
- property deleted
Is table deleted
- exists(condition: dict[str, Signature | ParsedFn | Any] | list[tuple[str, Signature | ParsedFn]] | None = None)[source]
Check if data is exists or not.
- Parameters:
condition (Condition, optional) – Condition to use. Defaults to None.
- get_namespace() Type[TypicalNamedTuple] [source]
Generate or return pre-existed namespace/table.
- insert(data: dict[str, Any])[source]
Insert data to current table
- Parameters:
data (Data) – Data to insert. Make sure it’s compatible with the table.
- Returns:
Last rowid
- Return type:
int
- insert_multiple(datas: list[dict[str, Any]])[source]
Insert multiple values
- Parameters:
datas (Iterable[Data]) – Data to be inserted.
- property name
Table name
- paginate_select(condition: dict[str, Signature | ParsedFn | Any] | list[tuple[str, Signature | ParsedFn]] | None = None, only: tuple[str, ...] | Literal['*'] = '*', page: int = 0, length: int = 10, order: dict[str, Literal['asc', 'desc']] | None = None, squash: Literal[False] = False) Generator[list[Row[str, Any]], None, None] [source]
- paginate_select(condition: dict[str, Signature | ParsedFn | Any] | list[tuple[str, Signature | ParsedFn]] | None = None, only: tuple[str, ...] | Literal['*'] = '*', page: int = 0, length: int = 10, order: dict[str, Literal['asc', 'desc']] | None = None, squash: Literal[True] = True) Generator[Row[str, list[Any]], None, None]
Paginate select
- Parameters:
condition (Condition, optional) – Confitions to use. Defaults to None.
only (OnlyColumn, optional) – Select what you want. Default to None.
page (int) – Which page number be returned first
length (int, optional) – Pagination length. Defaults to 10.
order (Optional[Orders], optional) – Order. Defaults to None.
- Yields:
Generator[Queries, None, None] – Step-by-step paginated result.
- select(condition: dict[str, Signature | ParsedFn | Any] | list[tuple[str, Signature | ParsedFn]] | None = None, only: tuple[str, ...] | Literal['*'] = '*', limit: int = 0, offset: int = 0, order: dict[str, Literal['asc', 'desc']] | None = None, squash: Literal[False] = False) list[Row[str, Any]] [source]
- select(condition: dict[str, Signature | ParsedFn | Any] | list[tuple[str, Signature | ParsedFn]] | None = None, only: tuple[str, ...] | Literal['*'] = '*', limit: int = 0, offset: int = 0, order: dict[str, Literal['asc', 'desc']] | None = None, squash: Literal[True] = True) Row[str, list[Any]]
- select(condition: dict[str, Signature | ParsedFn | Any] | list[tuple[str, Signature | ParsedFn]] | None = None, only: ParsedFn = _null, limit: int = 0, offset: int = 0, order: dict[str, Literal['asc', 'desc']] | None = None, squash: Literal[False] = False) Any
Select data in current table. Bare .select() returns all data.
- Parameters:
condition (Condition, optional) – Conditions to used. Defaults to None.
only – (OnlyColumn, ParsedFn, optional): Select what you want. Default to None.
limit (int, optional) – Limit of select. Defaults to 0.
offset (int, optional) – Offset. Defaults to 0
order (Optional[Orders], optional) – Selection order. Defaults to None.
squash (bool) – Is it squashed?
- Returns:
Selected data
- Return type:
Queries
- select_one(condition: dict[str, Signature | ParsedFn | Any] | list[tuple[str, Signature | ParsedFn]] | None = None, only: ParsedFn = _null, order: dict[str, Literal['asc', 'desc']] | None = None) Any [source]
- select_one(condition: dict[str, Signature | ParsedFn | Any] | list[tuple[str, Signature | ParsedFn]] | None = None, only: tuple[str, ...] | Literal['*'] = '*', order: dict[str, Literal['asc', 'desc']] | None = None) Row[str, Any]
Select one data
- Parameters:
condition (Condition, optional) – Condition to use. Defaults to None.
only – (OnlyColumn, optional): Select what you want. Default to None.
order (Optional[Orders], optional) – Order of selection. Defaults to None.
- Returns:
Selected data
- Return type:
Any
- update(condition: dict[str, Signature | ParsedFn | Any] | list[tuple[str, Signature | ParsedFn]] | None = None, data: dict[str, Any] | None = None, limit: int = 0, order: dict[str, Literal['asc', 'desc']] | None = None)[source]
Update rows of current table
- Parameters:
data (Data) – New data to update
condition (Condition, optional) – Condition dictionary. See Signature about how condition works. Defaults to None.
limit (int, optional) – Limit updates. Defaults to 0.
order (Optional[Orders], optional) – Order of change. Defaults to None.
- Returns:
Rows affected
- Return type:
int
- sqlite_database.blob(name: str) BuilderColumn [source]
Create a blob column with name
- sqlite_database.integer(name: str) BuilderColumn [source]
Create a integer column with name
- sqlite_database.real(name: str) BuilderColumn [source]
Create a real column with name
- sqlite_database.text(name: str) BuilderColumn [source]
Create a text column with name