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[EdgyModel, EdgyEmbedTarget], Generic[EdgyModel, EdgyEmbedTarget]
Source code in edgy/core/db/querysets/base.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 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 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 | |
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
raw_delete
async
¶
Internal delete method.
Exposes remove_referenced_call and doesn't raise an extra signal.
Delegates to QueryExecutor.delete.
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
¶
Retrieve the schema.
_execute_iterate
async
¶
(Refactored: Now delegates to the Executor)
Source code in edgy/core/db/querysets/base.py
_execute_all
async
¶
Resolves to an array and deduplicate.
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
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 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 | |
_get_raw
async
¶
Base method used by get like methods.
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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[EdgyModel, EdgyEmbedTarget]
|
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
update_embed_parent
¶
update_embed_parent(
embed_parent: None,
) -> QuerySet[EdgyModel, EdgyModel]
update_embed_parent(
embed_parent: tuple[str, str],
) -> QuerySet[EdgyModel, EdgyEmbedTarget]
Update or remove (provide None) embed_parent applied on instances. Note: this doesn't affect embed_parent for filters.
| PARAMETER | DESCRIPTION |
|---|---|
embed_parent
|
define the new embed_parent.
TYPE:
|
Returns: QuerySetType: A new QuerySet instance with the new embedding.
Source code in edgy/core/db/querysets/queryset.py
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:
|
Returns: int | None: Amount of rows changed if known for the database.
Source code in edgy/core/db/querysets/queryset.py
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 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 | |
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
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 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 | |
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
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 plain instances which may are incomplete.
| PARAMETER | DESCRIPTION |
|---|---|
objs
|
An iterable of dictionaries or model instances to create.
TYPE:
|
Kwargs: ignore_conflicts (bool): Ignore insert conflicts. Support varies between database systems. resolve_embed (bool): Triggers mode in which embedding is applied when True.
| RETURNS | DESCRIPTION |
|---|---|
list[EdgyModel | None] | list[EdgyEmbedTarget | None]
|
list[EdgyModel | None] | list[EdgyEmbedTarget | None]:
A list of created objects.
Warning: for performance reasons no embedding is applied by default and
the returned objects are maybe incomplete (check |
Source code in edgy/core/db/querysets/queryset.py
bulk_update
async
¶
Update multiple objects in a single bulk operation.
| PARAMETER | DESCRIPTION |
|---|---|
objs
|
A sequence of model instances to update.
TYPE:
|
Kwargs: update_fields (Iterable[str]): A list of field names to update for each object. If None use all fields. unique_fields (Iterable[str] | None): Fields that determine uniqueness. If None, pknames are used. If empty it fails. resolve_embed (bool): Triggers mode in which embedding is applied when True.
| RETURNS | DESCRIPTION |
|---|---|
list[EdgyModel | None] | list[EdgyEmbedTarget | None]
|
list[EdgyModel | None] | list[EdgyEmbedTarget | None]:
A list of updated objects.
Warning: for performance reasons no embedding is applied by default and
the returned objects are maybe incomplete (check |
Source code in edgy/core/db/querysets/queryset.py
1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 | |
bulk_update_or_create
async
¶
Bulk updates 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:
|
Kwargs: update_fields (Iterable[str]): A list of field names to update for each object (when found). If None use all fields. unique_fields (Iterable[str] | None): Fields that determine uniqueness. If None, pknames are used. If empty it fails. resolve_embed (bool): Triggers mode in which embedding is applied when True.
| RETURNS | DESCRIPTION |
|---|---|
list[tuple[EdgyModel | None, bool]] | list[tuple[EdgyEmbedTarget | None, bool]]
|
list[tuple[EdgyModel, bool]] | list[tuple[EdgyEmbedTarget, bool]]:
A list of |
Source code in edgy/core/db/querysets/queryset.py
1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 | |
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:
|
Kwargs: unique_fields (Iterable[str] | None): Fields that determine uniqueness. If None, pknames are used. If empty it fails. resolve_embed (bool): Triggers mode in which embedding is applied when True.
| RETURNS | DESCRIPTION |
|---|---|
list[tuple[EdgyModel | None, bool]] | list[tuple[EdgyEmbedTarget | None, bool]]
|
list[tuple[EdgyModel | None, bool]] | list[tuple[EdgyEmbedTarget | None, bool]]:
A list of tuples with retrieved or newly created objects and created flag.
Warning: for performance reasons no embedding is applied by default and
the returned objects are maybe incomplete (check |
Source code in edgy/core/db/querysets/queryset.py
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 | |
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 |