SupabaseModel¶
SupabaseModel
¶
Bases: BaseModel
Base class for tables — Pydantic model + PostgREST chain entry point.
Subclass with table-creation kwargs:
table— PostgREST table / view name. Required on concrete subclasses.pk— Primary key field name. Default"id".select— Override the auto-derived select string (escape hatch).query_class— Custom :class:QueryBuildersubclass for.query; inherited via MRO, so a project-wide base class can set it once.
Example
get
async
classmethod
¶
Fetch by primary key. Raises SupabaseORMDoesNotExist on miss.
Source code in src/supabase_orm/_async/_base.py
find
async
classmethod
¶
create
async
classmethod
¶
Insert a row in a single round-trip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
returning
|
ReturnMode
|
|
'representation'
|
**values
|
Any
|
Column values for the new row. |
{}
|
Returns:
| Type | Description |
|---|---|
Self | None
|
The inserted row, or |
Source code in src/supabase_orm/_async/_base.py
bulk_create
async
classmethod
¶
bulk_create(
rows: list[dict[str, Any]],
*,
returning: ReturnMode = "representation",
) -> list[Self] | None
Insert multiple rows in one round-trip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
list[dict[str, Any]]
|
One dict of column values per row. |
required |
returning
|
ReturnMode
|
|
'representation'
|
Returns:
| Type | Description |
|---|---|
list[Self] | None
|
Inserted rows; |
Source code in src/supabase_orm/_async/_base.py
upsert
async
classmethod
¶
upsert(
*,
on_conflict: "str | Column | list[str | Column] | None" = ...,
ignore_duplicates: Literal[False] = ...,
returning: Literal["representation"] = ...,
**values: Any,
) -> Self
upsert(
*,
on_conflict: "str | Column | list[str | Column] | None" = None,
ignore_duplicates: bool = False,
returning: ReturnMode = "representation",
**values: Any,
) -> Self | None
Insert or update on conflict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_conflict
|
'str | Column | list[str | Column] | None'
|
Unique-constraint column(s) used to detect duplicates.
Accepts a typed :class: |
None
|
ignore_duplicates
|
bool
|
Keep the existing row unchanged on conflict;
returns |
False
|
returning
|
ReturnMode
|
|
'representation'
|
**values
|
Any
|
Column values for the row. |
{}
|
Returns:
| Type | Description |
|---|---|
Self | None
|
The row; |
Source code in src/supabase_orm/_async/_base.py
bulk_upsert
async
classmethod
¶
bulk_upsert(
rows: list[dict[str, Any]],
*,
on_conflict: "str | Column | list[str | Column] | None" = None,
ignore_duplicates: bool = False,
returning: ReturnMode = "representation",
) -> list[Self] | None
Bulk-upsert.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
list[dict[str, Any]]
|
One dict of column values per row. |
required |
on_conflict
|
'str | Column | list[str | Column] | None'
|
See :meth: |
None
|
ignore_duplicates
|
bool
|
See :meth: |
False
|
returning
|
ReturnMode
|
See :meth: |
'representation'
|
Returns:
| Type | Description |
|---|---|
list[Self] | None
|
Resulting rows; |
Source code in src/supabase_orm/_async/_base.py
get_or_create
async
classmethod
¶
Fetch the row matching lookup, or create it.
Two round-trips; not race-safe — between the lookup and the insert
another writer can land a matching row. For atomic semantics, prefer
:meth:upsert with a unique constraint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
defaults
|
dict[str, Any] | None
|
Extra column values applied only on the create branch. |
None
|
**lookup
|
Any
|
Equality filters used to locate the existing row. |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[Self, bool]
|
|
Source code in src/supabase_orm/_async/_base.py
update_or_create
async
classmethod
¶
Update the row matching lookup (with defaults), or create.
Same race caveats as :meth:get_or_create.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
defaults
|
dict[str, Any] | None
|
Column values applied on update, or on the create branch. |
None
|
**lookup
|
Any
|
Equality filters used to locate the existing row. |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[Self, bool]
|
|
Source code in src/supabase_orm/_async/_base.py
update
async
¶
Assign the given fields and persist in one call.
Equivalent to setting each attribute and calling :meth:save. Each
assignment runs through Pydantic's validator (validate_assignment
is on), so type errors surface before the round-trip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**values
|
Any
|
Field=value pairs to set. Must include at least one; cannot target the primary key or a relation field. |
{}
|
Source code in src/supabase_orm/_async/_base.py
save
async
¶
Persist dirty fields and refresh local state in one round-trip.
For flat models the UPDATE returns the new row directly. For models with relations we still need a follow-up GET to populate embeds.
Source code in src/supabase_orm/_async/_base.py
delete
async
¶
Delete this single row by primary key.