QuerySet class¶
edgy.QuerySet
¶
QuerySet(
model_class,
*,
database=None,
filter_clauses=_empty_set,
select_related=_empty_set,
prefetch_related=_empty_set,
limit_count=None,
limit=None,
limit_offset=None,
offset=None,
batch_size=None,
order_by=_empty_set,
group_by=_empty_set,
distinct_on=None,
distinct=None,
only_fields=None,
only=_empty_set,
defer_fields=None,
defer=_empty_set,
embed_parent=None,
using_schema=Undefined,
table=None,
exclude_secrets=False,
extra_select=None,
reference_select=None,
)
Bases: BaseQuerySet
Source code in edgy/core/db/querysets/base.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
model_class
instance-attribute
¶
The model class associated with this QuerySet.
pkcolumns
property
¶
Returns a sequence of primary key column names for the model class associated with this queryset.
This property directly delegates to the pkcolumns property of the
model_class, providing access to the underlying database column names
that constitute the primary key.
| RETURNS | DESCRIPTION |
|---|---|
Sequence[str]
|
Sequence[str]: A sequence (e.g., list or tuple) of strings, where each string is the name of a primary key column in the database. |
_extra_select
instance-attribute
¶
_reference_select
instance-attribute
¶
bulk_select_or_insert
class-attribute
instance-attribute
¶
bulk_select_or_insert = bulk_get_or_create
build_where_clause
async
¶
(This method is now a simple forwarder to the Compiler. It's kept for API compatibility, e.g. for QuerySet(QuerySet) filters)
Source code in edgy/core/db/querysets/base.py
using
¶
Enables and switches the database schema and/or database connection for the queryset.
This method creates a new QuerySet instance that operates within the specified database and/or schema context. It's designed to support multi-tenancy by allowing dynamic selection of the database or schema without modifying the original QuerySet.
| PARAMETER | DESCRIPTION |
|---|---|
_positional
|
Deprecated positional argument for
TYPE:
|
database
|
Specifies the database to use.
Use an extra connection name (
TYPE:
|
schema
|
Specifies the database schema to use.
Use a schema name (
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet instance configured with the specified database and/or schema settings. This new instance allows chaining operations within the new context.
TYPE:
|
| WARNS | DESCRIPTION |
|---|---|
DeprecationWarning
|
If positional arguments are passed to this method for
|
Source code in edgy/core/db/querysets/mixins/tenancy.py
prefetch_related
¶
Performs a reverse lookup for foreign keys and other relationships, populating results onto the main model instances.
This method is distinct from select_related in that select_related
performs a SQL JOIN to fetch related data in the same query, whereas
prefetch_related executes separate queries for each relationship
and then joins the results in Python. This is particularly useful for
many-to-many relationships or reverse foreign key lookups, or when
preloading related objects for a large set of parent objects.
| PARAMETER | DESCRIPTION |
|---|---|
*prefetch
|
One or more
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
QuerySetError
|
If any argument passed to |
Source code in edgy/core/db/querysets/prefetch.py
using_with_db
¶
Switches the database connection and optionally the schema for the queryset.
This method is deprecated in favor of the more flexible using method, which
accepts both database and schema as keyword arguments.
| PARAMETER | DESCRIPTION |
|---|---|
connection_name
|
The name of the database connection (registered
in the model's registry's
TYPE:
|
schema
|
The schema name to use.
Use a schema name (
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet instance configured with the specified database connection and schema.
TYPE:
|
| WARNS | DESCRIPTION |
|---|---|
DeprecationWarning
|
This method is deprecated. Users should migrate to
|
Source code in edgy/core/db/querysets/mixins/tenancy.py
_clone
¶
This is core to the builder pattern
Source code in edgy/core/db/querysets/base.py
_as_select_with_tables
async
¶
(This is the new internal method for the base class) Builds the query select by delegating to the QueryCompiler.
Source code in edgy/core/db/querysets/base.py
_clear_cache
¶
Source code in edgy/core/db/querysets/base.py
_build_order_by_iterable
¶
This is a helper for the compiler but is called by it, so it's okay for it to live here as it's part of the 'builder' logic.
Source code in edgy/core/db/querysets/base.py
_validate_only_and_defer
¶
_get_join_graph_data
¶
Gets the join graph, building it via the compiler if needed.
This is the new "bridge" that manages the _cached_select_related_expression variable to satisfy brittle tests, while keeping the compiler itself stateless.
Source code in edgy/core/db/querysets/base.py
as_select_with_tables
async
¶
(Refactored: Now delegates to the Compiler)
Source code in edgy/core/db/querysets/base.py
as_select
async
¶
_kwargs_to_clauses
¶
This is part of the 'filter' builder logic
Source code in edgy/core/db/querysets/base.py
_prepare_order_by
¶
(Helper for 'order_by' builder logic, but called by compiler)
Source code in edgy/core/db/querysets/base.py
_update_select_related_weak
¶
Source code in edgy/core/db/querysets/base.py
_update_select_related
¶
Source code in edgy/core/db/querysets/base.py
_prepare_distinct
¶
Helper for 'distinct' builder, but called by compiler
Source code in edgy/core/db/querysets/base.py
_embed_parent_in_result
async
¶
This is a result transformation, called by the Parser.
Source code in edgy/core/db/querysets/base.py
get_schema
¶
_execute_iterate
async
¶
(Refactored: Now delegates to the Executor)
Source code in edgy/core/db/querysets/base.py
_execute_all
async
¶
Still relies on _execute_iterate.
Source code in edgy/core/db/querysets/base.py
_filter_or_exclude
¶
This is the core 'filter' builder logic.
Source code in edgy/core/db/querysets/base.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 | |
raw_delete
async
¶
(Refactored: Now delegates to the Executor)
Source code in edgy/core/db/querysets/base.py
_get_raw
async
¶
(Refactored: Builder logic stays, execution logic delegates)
Source code in edgy/core/db/querysets/base.py
_combine
¶
Internal helper used by union(), intersect(), and except_() to build
a CombinedQuerySet.
We keep the core set operation in op and pass the all_ flag through
so that CombinedQuerySet (and its compiler) can decide whether to emit
e.g. UNION vs UNION ALL.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The secondary
TYPE:
|
op
|
The base set operation type ('union', 'intersect', or 'except').
TYPE:
|
all_
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CombinedQuerySet
|
A |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
QuerySetError
|
If the models ( |
Source code in edgy/core/db/querysets/queryset.py
union
¶
Returns a result set that is the UNION of the current QuerySet and another QuerySet.
By default, UNION returns only distinct rows (UNION DISTINCT).
If all=True, it returns UNION ALL, which includes duplicate rows.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The other
TYPE:
|
all
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CombinedQuerySet
|
A |
Source code in edgy/core/db/querysets/queryset.py
union_all
¶
Returns a result set that is the UNION ALL of the current QuerySet and another QuerySet.
This is a shortcut method equivalent to calling union(other, all=True).
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The other
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CombinedQuerySet
|
A |
Source code in edgy/core/db/querysets/queryset.py
intersect
¶
Returns a result set that is the INTERSECT (intersection) of the current QuerySet and another QuerySet.
By default, INTERSECT returns only distinct rows (INTERSECT DISTINCT).
If all=True, the behavior depends on the backend but typically implies INTERSECT ALL.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The other
TYPE:
|
all
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CombinedQuerySet
|
A |
Source code in edgy/core/db/querysets/queryset.py
except_
¶
Returns a result set that is the EXCEPT (difference) of the current QuerySet and another QuerySet (rows in the first but not in the second).
By default, EXCEPT returns only distinct rows (EXCEPT DISTINCT).
If all=True, performs EXCEPT ALL.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The other
TYPE:
|
all
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CombinedQuerySet
|
A |
Source code in edgy/core/db/querysets/queryset.py
_sql_helper
async
¶
Helper method to compile the SQL query represented by the current QuerySet into a string.
This is primarily used for debugging, introspection, or logging the generated SQL. The method ensures that literal bind values (parameters) are included in the final string.
| RETURNS | DESCRIPTION |
|---|---|
Any
|
A string containing the compiled SQL query. |
Source code in edgy/core/db/querysets/queryset.py
select_for_update
¶
Request row-level locks on the rows selected by this queryset, using
dialect-appropriate SELECT ... FOR UPDATE semantics via SQLAlchemy's
with_for_update().
| PARAMETER | DESCRIPTION |
|---|---|
nowait
|
Fail immediately if a lock cannot be acquired.
TYPE:
|
skip_locked
|
Skip rows that are locked by other transactions (where supported).
TYPE:
|
read
|
Shared lock variant (PostgreSQL's FOR SHARE).
TYPE:
|
key_share
|
PostgreSQL's FOR KEY SHARE.
TYPE:
|
of
|
Models whose tables should be explicitly locked (PostgreSQL's OF ...). The models must be part of the FROM/JOIN set for this query.
TYPE:
|
Notes
- Most databases require running inside an explicit transaction: async with database.transaction(): ...
- On unsupported dialects (e.g. SQLite), this is a no-op.
- For PostgreSQL,
read=Truemaps to FOR SHARE andkey_share=Trueto FOR KEY SHARE. of=[ModelA, ...]restricts locking to specific tables (PostgreSQL only). You should include related models in the query viaselect_related(...)if you plan to lock them withof=....
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A cloned queryset with locking enabled.
TYPE:
|
Source code in edgy/core/db/querysets/queryset.py
filter
¶
Filters the QuerySet by the given clauses and keyword arguments, combining them with the AND operand.
This is the primary method for constructing the WHERE clause of a query. Multiple clauses and kwargs are implicitly combined using AND.
| PARAMETER | DESCRIPTION |
|---|---|
*clauses
|
Positional arguments which can be:
- SQLAlchemy Binary Expressions (e.g.,
TYPE:
|
**kwargs
|
Keyword arguments for Django-style lookups (e.g.,
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet instance with the additional filters applied. |
Source code in edgy/core/db/querysets/queryset.py
all
¶
Returns a cloned QuerySet instance, or simply clears the cache of the current instance.
| PARAMETER | DESCRIPTION |
|---|---|
clear_cache
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet clone or the current QuerySet instance ( |
Source code in edgy/core/db/querysets/queryset.py
or_
¶
Filters the QuerySet by the given clauses and keyword arguments, combining them with the OR operand.
This method is used to construct a disjunction (OR logic) for the WHERE clause.
| PARAMETER | DESCRIPTION |
|---|---|
*clauses
|
Positional arguments for filtering (same types as
TYPE:
|
**kwargs
|
Keyword arguments for filtering (Django-style lookups).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet instance with the OR filters applied. |
Source code in edgy/core/db/querysets/queryset.py
local_or
¶
Filters the QuerySet using the OR operand, but only applies the OR logic locally.
This prevents the OR operation from becoming a global OR that overrides existing, unrelated AND filters, often by applying the OR clause within parentheses.
| PARAMETER | DESCRIPTION |
|---|---|
*clauses
|
Positional arguments for filtering.
TYPE:
|
**kwargs
|
Keyword arguments for filtering.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet instance with the local OR filters applied. |
Source code in edgy/core/db/querysets/queryset.py
and_
¶
Filters the QuerySet by the given clauses and keyword arguments, using the AND operand.
This method is an alias for filter(), explicitly stating the AND logic.
| PARAMETER | DESCRIPTION |
|---|---|
*clauses
|
Positional arguments for filtering.
TYPE:
|
**kwargs
|
Keyword arguments for filtering.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet instance with the AND filters applied. |
Source code in edgy/core/db/querysets/queryset.py
not_
¶
Excludes results from the QuerySet by negating the given clauses and keyword arguments.
This method is an alias for exclude(), explicitly stating the NOT logic.
| PARAMETER | DESCRIPTION |
|---|---|
*clauses
|
Positional arguments for exclusion.
TYPE:
|
**kwargs
|
Keyword arguments for exclusion.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet instance with the exclusion applied. |
Source code in edgy/core/db/querysets/queryset.py
exclude
¶
Excludes results from the QuerySet by negating the given clauses and keyword arguments.
The exclusion logic is typically implemented by calling _filter_or_exclude
with the exclude=True flag.
| PARAMETER | DESCRIPTION |
|---|---|
*clauses
|
Positional arguments for exclusion (same types as
TYPE:
|
**kwargs
|
Keyword arguments for exclusion (Django-style lookups).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet instance with the exclusion applied. |
Source code in edgy/core/db/querysets/queryset.py
exclude_secrets
¶
Marks the QuerySet to exclude any model fields declared with secret=True from being leaked
or serialized in the final result set.
| PARAMETER | DESCRIPTION |
|---|---|
exclude_secrets
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet clone with the |
Source code in edgy/core/db/querysets/queryset.py
extra_select
¶
Adds extra columns or expressions to the SELECT statement.
| PARAMETER | DESCRIPTION |
|---|---|
*extra
|
Additional SQLAlchemy column clauses or expressions.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySetType
|
A new QuerySet with the extra select clauses.
TYPE:
|
Source code in edgy/core/db/querysets/queryset.py
reference_select
¶
Adds references to the SELECT statement, used for specific model field handling.
| PARAMETER | DESCRIPTION |
|---|---|
references
|
A dictionary defining reference selections.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySetType
|
A new QuerySet with the added reference selections.
TYPE:
|
Source code in edgy/core/db/querysets/queryset.py
batch_size
¶
Sets the batch or chunk size for results. This is primarily used in conjunction
with iteration methods (like QuerySet.iterate()) to control memory usage.
| PARAMETER | DESCRIPTION |
|---|---|
batch_size
|
The number of records to fetch in each database round-trip.
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet clone with the batch size set. |
Source code in edgy/core/db/querysets/queryset.py
lookup
¶
Performs a broader, case-insensitive search for a given term across all CharField and TextField instances defined on the model.
The search uses the SQL LIKE operator with wildcards (%) and typically
maps to ILIKE on PostgreSQL for case-insensitivity.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The search term to look for.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet instance with the combined OR filter applied to all searchable fields. |
Source code in edgy/core/db/querysets/queryset.py
order_by
¶
Returns a QuerySet ordered by the given fields.
Sorting is applied in ascending order by default. Prepending a field name with
a hyphen (-) specifies descending order (e.g., -created_at).
| PARAMETER | DESCRIPTION |
|---|---|
*order_by
|
One or more field names to sort by.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet clone with the specified ordering. |
Source code in edgy/core/db/querysets/queryset.py
reverse
¶
Reverses the established order of the QuerySet.
If an order_by is already set, it negates the sorting direction of every field.
If no order_by is set, it defaults to reversing the primary key columns.
It also adjusts internal cache pointers for consistency if caching is active.
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet clone with the reversed ordering. |
Source code in edgy/core/db/querysets/queryset.py
limit
¶
Limits the number of results returned by the QuerySet (SQL LIMIT clause).
| PARAMETER | DESCRIPTION |
|---|---|
limit_count
|
The maximum number of rows to return.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet clone with the limit applied. |
Source code in edgy/core/db/querysets/queryset.py
offset
¶
Skips the specified number of results before starting to return rows (SQL OFFSET clause).
| PARAMETER | DESCRIPTION |
|---|---|
offset
|
The number of rows to skip.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet clone with the offset applied. |
Source code in edgy/core/db/querysets/queryset.py
group_by
¶
Groups the results of the QuerySet by the given fields (SQL GROUP BY clause).
| PARAMETER | DESCRIPTION |
|---|---|
*group_by
|
One or more field names to group the results by.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet clone with the grouping applied. |
Source code in edgy/core/db/querysets/queryset.py
distinct
¶
Returns a queryset with distinct results.
| PARAMETER | DESCRIPTION |
|---|---|
first
|
If True, applies
TYPE:
|
*distinct_on
|
Additional fields for
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet with the distinct clause applied.
TYPE:
|
Source code in edgy/core/db/querysets/queryset.py
only
¶
Restricts the QuerySet to retrieve only the specified fields from the database for the model instances, along with the primary key field(s).
This method is used for performance optimization when only a subset of columns is needed. The primary key is automatically included to ensure object identity and saving functionality.
| PARAMETER | DESCRIPTION |
|---|---|
*fields
|
The names of the model fields (columns) to include in the SELECT statement.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet clone with the |
Source code in edgy/core/db/querysets/queryset.py
defer
¶
Excludes the specified fields from being retrieved from the database.
When accessing a deferred field on a model instance, a subsequent database query will be triggered to fetch its value. This is useful for large, rarely accessed fields (e.g., large text blobs).
| PARAMETER | DESCRIPTION |
|---|---|
*fields
|
The names of the model fields (columns) to exclude from the SELECT statement.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuerySet
|
A new QuerySet clone with the |
Source code in edgy/core/db/querysets/queryset.py
select_related
¶
Returns a QuerySet that will “follow” foreign-key relationships, selecting additional related-object data when it executes its query.
This is a performance booster which results in a single more complex query but means
later use of foreign-key relationships won't require database queries.
Source code in edgy/core/db/querysets/queryset.py
values
async
¶
Executes the query and returns the results as a list of Python dictionaries, rather than model instances.
| PARAMETER | DESCRIPTION |
|---|---|
fields
|
A sequence of field names to include in the resulting dictionaries.
If
TYPE:
|
exclude
|
A sequence of field names to exclude from the resulting dictionaries.
TYPE:
|
exclude_none
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[dict]
|
A list of dictionaries representing the selected data rows. |
| RAISES | DESCRIPTION |
|---|---|
QuerySetError
|
If the |
Source code in edgy/core/db/querysets/queryset.py
values_list
async
¶
Executes the query and returns the results as a list of tuples or, if flat=True,
a flat list of values for a single field.
| PARAMETER | DESCRIPTION |
|---|---|
fields
|
A sequence of field names to include. Must contain exactly one field if
TYPE:
|
exclude
|
A sequence of field names to exclude.
TYPE:
|
exclude_none
|
If
TYPE:
|
flat
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Any]
|
A list of tuples, or a flat list of values if |
| RAISES | DESCRIPTION |
|---|---|
QuerySetError
|
If |
Source code in edgy/core/db/querysets/queryset.py
exists
async
¶
Returns a boolean indicating if one or more records matching the QuerySet's criteria exists.
If keyword arguments are provided, it first checks the cache for an existence match.
| PARAMETER | DESCRIPTION |
|---|---|
**kwargs
|
Optional filters to apply before checking for existence (e.g.,
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if at least one record exists, False otherwise. |
Source code in edgy/core/db/querysets/queryset.py
count
async
¶
Executes a SELECT COUNT statement and returns the total number of records matching the query.
The result is cached internally to prevent redundant database calls for subsequent counts.
For queries that may produce duplicate rows at the SQL level (e.g. OR across joined relations, select_related joins, GROUP BY), this method counts DISTINCT primary keys to reflect the number of unique model instances rather than raw joined rows.
Source code in edgy/core/db/querysets/queryset.py
get_or_none
async
¶
Fetches a single object matching the parameters.
If no object is found (raises ObjectNotFound), returns None.
| PARAMETER | DESCRIPTION |
|---|---|
**kwargs
|
Filters to identify the single object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EdgyEmbedTarget | None
|
The matching model instance, or |
Source code in edgy/core/db/querysets/queryset.py
get
async
¶
Fetches a single object matching the parameters.
| PARAMETER | DESCRIPTION |
|---|---|
**kwargs
|
Filters to identify the single object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EdgyEmbedTarget
|
The matching model instance. |
| RAISES | DESCRIPTION |
|---|---|
ObjectNotFound
|
If no object is found. |
MultipleObjectsReturned
|
If more than one object is found (implicitly handled by underlying |
Source code in edgy/core/db/querysets/queryset.py
first
async
¶
Returns the first record from the QuerySet, respecting any ordering and limits.
If the count is zero or the first record is already cached, it returns the cached result.
| RETURNS | DESCRIPTION |
|---|---|
EdgyEmbedTarget | None
|
The first model instance, or |
Source code in edgy/core/db/querysets/queryset.py
last
async
¶
Returns the last record from the QuerySet...
Source code in edgy/core/db/querysets/queryset.py
create
async
¶
Creates and saves a single record in the database table associated with the QuerySet's model.
| PARAMETER | DESCRIPTION |
|---|---|
*args
|
Positional arguments for model instantiation.
TYPE:
|
**kwargs
|
Keyword arguments for model instantiation and field values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EdgyEmbedTarget
|
The newly created model instance. |
Source code in edgy/core/db/querysets/queryset.py
bulk_create
async
¶
Bulk creates multiple records in a single batch operation.
This method bypasses model-level save hooks (except for pre/post-save) for efficiency,
and returns None.
| PARAMETER | DESCRIPTION |
|---|---|
objs
|
An iterable of dictionaries or model instances to be created.
TYPE:
|
Source code in edgy/core/db/querysets/queryset.py
bulk_update
async
¶
Bulk updates records in a table based on the provided list of model instances and fields.
The primary key of each model instance is used to identify the record to update. This operation is performed within a database transaction.
| PARAMETER | DESCRIPTION |
|---|---|
objs
|
A list of existing model instances to update.
TYPE:
|
fields
|
A list of field names that should be updated across all instances.
TYPE:
|
Source code in edgy/core/db/querysets/queryset.py
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 | |
bulk_get_or_create
async
¶
Bulk gets or creates records in a table.
If records exist based on unique fields, they are retrieved. Otherwise, new records are created.
| PARAMETER | DESCRIPTION |
|---|---|
objs
|
A list of objects or dictionaries.
TYPE:
|
unique_fields
|
Fields that determine uniqueness. If None, all records are treated as new.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[EdgyModel]
|
list[EdgyModel]: A list of retrieved or newly created objects. |
Source code in edgy/core/db/querysets/queryset.py
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
delete
async
¶
Deletes records from the database.
This method triggers pre_delete and post_delete signals.
If use_models is True or the model has specific deletion requirements,
it performs a model-based deletion.
| PARAMETER | DESCRIPTION |
|---|---|
use_models
|
If True, deletion is performed by iterating and deleting individual model instances. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The number of rows deleted.
TYPE:
|
Source code in edgy/core/db/querysets/queryset.py
update
async
¶
Updates records in a specific table with the given keyword arguments, matching the QuerySet's filters.
This performs a database-level update operation without fetching and saving model instances.
Warning:
- Does not execute instance-level pre_save_callback/post_save_callback hooks.
- Values are processed directly for column mapping and validation but do not pass through model instance saving.
| PARAMETER | DESCRIPTION |
|---|---|
**kwargs
|
The field names and new values to apply to the matching records.
TYPE:
|
Source code in edgy/core/db/querysets/queryset.py
get_or_create
async
¶
Fetches a single object matching kwargs. If found, returns the object and False.
If not found, creates a new object using kwargs (with defaults applied) and returns it with True.
| PARAMETER | DESCRIPTION |
|---|---|
defaults
|
Optional dictionary of values to use if a new object must be created.
Can also be a
TYPE:
|
*args
|
Positional arguments for model creation if object is not found.
TYPE:
|
**kwargs
|
Filters used to attempt retrieval, and primary creation arguments if not found.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EdgyEmbedTarget
|
A tuple containing the fetched/created model instance and a boolean indicating |
bool
|
if the object was created ( |
Source code in edgy/core/db/querysets/queryset.py
update_or_create
async
¶
Updates a single object matching kwargs using defaults. If not found, creates a new object.
| PARAMETER | DESCRIPTION |
|---|---|
defaults
|
Optional dictionary of values to apply as updates if the object is found,
or to use as creation values if the object is new. Can also be a
TYPE:
|
*args
|
Positional arguments for model creation if object is not found.
TYPE:
|
**kwargs
|
Filters used to attempt retrieval.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EdgyEmbedTarget
|
A tuple containing the fetched/created model instance and a boolean indicating |
bool
|
if the object was created ( |
Source code in edgy/core/db/querysets/queryset.py
contains
async
¶
Checks if the QuerySet contains a specific model instance by verifying its existence in the database using its primary key(s).
| PARAMETER | DESCRIPTION |
|---|---|
instance
|
The model instance to check for containment.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the record exists in the database and matches the QuerySet filters, False otherwise. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the provided object is not a model instance or has a missing primary key. |
Source code in edgy/core/db/querysets/queryset.py
transaction
¶
Returns a database transaction context manager for the assigned database.
| PARAMETER | DESCRIPTION |
|---|---|
force_rollback
|
If
TYPE:
|
**kwargs
|
Additional keyword arguments passed to the underlying database transaction factory.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Transaction
|
A |