BaseSBModel
BaseSBModel
¶
Bases: BaseModel
, ABC
Abstract base model for Supabase tables, integrating with Pydantic.
This class provides a foundation for creating Pydantic models that map to tables in a Supabase database.
Subclasses should define their table structure using Pydantic's field
definition syntax. They can override methods such as db_client()
to
customize the database client used for interactions.
Classes:
Name | Description |
---|---|
DoesNotExist |
Exception raised when a query returns no results but at least one result was expected. |
MultipleObjectsReturned |
Exception raised when a query returns multiple results but only one result was expected. |
Methods:
Name | Description |
---|---|
db_client |
Gets the database client class to use for interactions. |
delete |
Deletes the model instance from the database. |
save |
Saves the model instance to the database (either inserting or updating). |
DoesNotExist
¶
Bases: Exception
Exception raised when a query returns no results but at least one result was expected.
MultipleObjectsReturned
¶
Bases: Exception
Exception raised when a query returns multiple results but only one result was expected.
db_client
classmethod
¶
db_client() -> type[BaseClient]
Gets the database client class to use for interactions.
This method can be overridden in subclasses to provide a custom database
client implementation. The default implementation returns SupabaseClient
.
Returns:
Type | Description |
---|---|
BaseClient
|
The database client class. |
Source code in supadantic/models.py
133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
delete
¶
delete() -> None
Deletes the model instance from the database.
This method deletes the record from the database corresponding to the model instance's ID. If the model instance does not have an ID, this method does nothing.
Source code in supadantic/models.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
save
¶
save() -> _M
Saves the model instance to the database (either inserting or updating).
If the model instance has an ID, it is updated in the database. Otherwise, it is inserted as a new record. The model instance is updated with the data returned from the database after the save operation.
Returns:
Type | Description |
---|---|
_M
|
The saved model instance, updated with data from the database (e.g., the assigned ID for a new record). |
Source code in supadantic/models.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|