Model
Bases: BaseModel
The base model representing SQLite tables Inherits directly from pydantic.BaseModel
Attributes:
Name | Type | Description |
---|---|---|
__rowid__ |
int | None
|
(class attribute) when an object is returned by a query it will contain the rowid field that can be used for update and deletion. |
__pk__ |
str | None
|
(class attribute) Holds the primary key column name of the table |
__tablename__ |
str
|
(class attribute) the name of the table in the database |
__schema__(str) |
str
|
the (class attribute) schema for the table. |
Example
from ardilla import Model, Field
# Field is actually pydantic.Field but it's imported here for the convenience of the developer
class User(Model):
__tablename__ = 'users' # by default the tablename is just the model's name in lowercase
id: int = Field(primary=True) # sets this field as the primary key
name: str
Source code in ardilla/models.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
Fields
Helper class to generate foreing key field constrains.
Intead of instantiating this class the developer should use
the already instantiated ardilla.fields.ForeignKey
instead of directly instantiating this class.
Attributes:
Name | Type | Description |
---|---|---|
NO_ACTION |
str
|
(class attribute) The database won't take action. This most likely will result in errors |
RESTRICT |
str
|
(class attribute) The app will not be able to delete the foreing row unless there's no related child elements left |
SET_NULL |
str
|
(class attribute) The app will set the child to Null if the parent is deleted |
SET_DEFAULT |
str
|
(class attribute) Returns the value of this field to the default of the child when the parent is deleted or updated |
CASCADE |
str
|
(class attribute) If the parent gets deleted or updated the child follows |
Source code in ardilla/fields.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
__call__(*, references, on_delete=NO_ACTION, on_update=NO_ACTION, **kws)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
references |
type[Model]
|
The model this foreign key points to |
required |
on_delete |
str
|
defaults to 'NO ACTION' what happens when the referenced row gets deleted |
NO_ACTION
|
on_update |
str
|
defaults to 'NO ACTION' what happens when the referenced row gets updated |
NO_ACTION
|
Returns:
Type | Description |
---|---|
Any
|
A |
Raises:
Type | Description |
---|---|
KeyError
|
if the referenced value is not a type of model |
ValueError
|
if the referenced model does not have a primary key or has not yet been instantiated |
Source code in ardilla/fields.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|