Documentation
¶
Index ¶
- Constants
- Variables
- func CT_GetObject(obj attrs.Definer) func(identifier any) (interface{}, error)
- func CT_ListObjects(obj attrs.Definer) func(offset, limit uint) ([]interface{}, error)
- func CT_ListObjectsByIDs(obj attrs.Definer) func(i []interface{}) ([]interface{}, error)
- func CountObjects[T attrs.Definer](obj T) (int64, error)
- func CreateObject[T attrs.Definer](obj T) error
- func DeleteObject[T attrs.Definer](obj T) (int64, error)
- func ForSelectAll(f attrs.Field) bool
- func GetObject[T attrs.Definer](object T, identifier any) (T, error)
- func ListObjects[T attrs.Definer](object T, offset, limit uint64, ordering ...string) ([]T, error)
- func ListObjectsByIDs[T attrs.Definer, T2 any](object T, offset, limit uint64, ids []T2) ([]T, error)
- func RegisterCompiler(driver driver.Driver, ...)
- func RegisterDriver(driver driver.Driver, database string, supportsReturning ...SupportsReturning)
- func SaveObject[T attrs.Definer](obj T) error
- func Subquery(qs *GenericQuerySet) expr.Expression
- func SubqueryCount(qs *GenericQuerySet) *subqueryExpr
- func SubqueryExists(qs *GenericQuerySet) expr.Expression
- func SubqueryIn(field any, qs *GenericQuerySet) expr.Expression
- func UpdateObject[T attrs.Definer](obj T) (int64, error)
- type AliasField
- type CompiledCountQuery
- type CompiledExistsQuery
- type CompiledQuery
- type CompiledValuesListQuery
- type DB
- type DataModel
- type FieldInfo
- func (f *FieldInfo) WriteField(sb *strings.Builder, inf *expr.ExpressionInfo, field attrs.Field, ...) (args []any, isSQL, written bool)
- func (f *FieldInfo) WriteFields(sb *strings.Builder, inf *expr.ExpressionInfo) []any
- func (f *FieldInfo) WriteUpdateFields(sb *strings.Builder, inf *expr.ExpressionInfo) []any
- type ForUseInQueries
- type ForUseInQueriesField
- type GenericQuerySet
- type JoinDef
- type ModelDataStore
- type OrderBy
- type QueryCompiler
- type QueryInfo
- type QueryObject
- type QuerySet
- func (qs *QuerySet[T]) Aggregate(annotations map[string]expr.Expression) (map[string]any, error)
- func (qs *QuerySet[T]) All() ([]*Row[T], error)
- func (qs *QuerySet[T]) Annotate(aliasOrAliasMap interface{}, exprs ...expr.Expression) *QuerySet[T]
- func (qs *QuerySet[T]) Clone() *QuerySet[T]
- func (qs *QuerySet[T]) Compiler() QueryCompiler
- func (qs *QuerySet[T]) Count() (int64, error)
- func (qs *QuerySet[T]) Create(value T) (T, error)
- func (qs *QuerySet[T]) DB() DB
- func (qs *QuerySet[T]) Delete() (int64, error)
- func (qs *QuerySet[T]) Distinct() *QuerySet[T]
- func (qs *QuerySet[T]) Exists() (bool, error)
- func (qs *QuerySet[T]) ExplicitSave() *QuerySet[T]
- func (qs *QuerySet[T]) Filter(key interface{}, vals ...interface{}) *QuerySet[T]
- func (qs *QuerySet[T]) First() (*Row[T], error)
- func (qs *QuerySet[T]) ForUpdate() *QuerySet[T]
- func (qs *QuerySet[T]) Get() (*Row[T], error)
- func (qs *QuerySet[T]) GetOrCreate(value T) (T, error)
- func (qs *QuerySet[T]) GoString() string
- func (qs *QuerySet[T]) GroupBy(fields ...string) *QuerySet[T]
- func (qs *QuerySet[T]) Having(key interface{}, vals ...interface{}) *QuerySet[T]
- func (qs *QuerySet[T]) Last() (*Row[T], error)
- func (qs *QuerySet[T]) LatestQuery() QueryInfo
- func (qs *QuerySet[T]) Limit(n int) *QuerySet[T]
- func (qs *QuerySet[T]) Model() attrs.Definer
- func (qs *QuerySet[T]) Offset(n int) *QuerySet[T]
- func (qs *QuerySet[T]) OrderBy(fields ...string) *QuerySet[T]
- func (qs *QuerySet[T]) Prefix(prefix string) *QuerySet[T]
- func (qs *QuerySet[T]) Reverse() *QuerySet[T]
- func (qs *QuerySet[T]) Select(fields ...any) *QuerySet[T]
- func (qs *QuerySet[T]) StartTransaction(ctx context.Context) (Transaction, error)
- func (w *QuerySet[T]) String() string
- func (qs *QuerySet[T]) Update(value T, expressions ...expr.NamedExpression) (int64, error)
- func (qs *QuerySet[T]) ValuesList(fields ...any) ([][]interface{}, error)
- type QuerySetDatabaseDefiner
- type QuerySetDefiner
- type QuerySetInternals
- type RelatedField
- type Relation
- type Row
- type SignalSave
- type SupportsReturning
- type Table
- type Transaction
- type VirtualField
Constants ¶
const MAX_GET_RESULTS = 21
Variables ¶
var ( // Signal to be executed before inserting / updating a model instance. SignalPreModelSave = signals_saving.Get("queries.model.pre_save") // Signal to be executed after inserting / updating a model instance. SignalPostModelSave = signals_saving.Get("queries.model.post_save") // Signal to be executed before deleting a model instance. SignalPreModelDelete = signals_deleting.Get("queries.model.pre_delete") // Signal to be executed after deleting a model instance. SignalPostModelDelete = signals_deleting.Get("queries.model.post_delete") )
var (
LogQueries = true
)
var QUERYSET_USE_CACHE_DEFAULT = true
Functions ¶
func CT_GetObject ¶
CT_GetObject retrieves an object from the database by its identifier.
This is a function with the CT_ prefix to indicate that it is a function to be used in a `contenttypes.ContentTypeDefinition` context.
func CT_ListObjects ¶
CT_ListObjects lists objects from the database.
This is a function with the CT_ prefix to indicate that it is a function to be used in a `contenttypes.ContentTypeDefinition` context.
func CT_ListObjectsByIDs ¶
CT_ListObjectsByIDs lists objects from the database by their IDs.
This is a function with the CT_ prefix to indicate that it is a function to be used in a `contenttypes.ContentTypeDefinition` context.
func CountObjects ¶
CountObjects counts the number of objects in the database.
func CreateObject ¶
CreateObject creates a new object in the database and sets its default values.
It sends a pre-save signal before saving and a post-save signal after saving.
If the object implements the models.Saver interface, it will call the Save method instead of executing a query.
func DeleteObject ¶
DeleteObject deletes an object from the database.
It sends a pre-delete signal before deleting and a post-delete signal after deleting.
If the object implements the models.Deleter interface, it will call the Delete method instead of executing a query.
func ForSelectAll ¶ added in v1.0.9
ForSelectAll returns true if the field should be selected in the query.
If the field is nil, it returns false.
If the field is a ForUseInQueriesField, it returns the result of `ForSelectAll()`.
Otherwise, it returns true.
func GetObject ¶
GetObject retrieves an object from the database by its identifier.
It takes an identifier as a parameter and returns the object of type T.
The identifier can be any type, but it is expected to be the primary key of the object.
func ListObjects ¶
ListObjects lists objects from the database.
It takes an offset and a limit as parameters and returns a slice of objects of type T.
func ListObjectsByIDs ¶
func ListObjectsByIDs[T attrs.Definer, T2 any](object T, offset, limit uint64, ids []T2) ([]T, error)
ListObjectsByIDs lists objects from the database by their IDs.
It takes an offset, limit, and a slice of IDs as parameters and returns a slice of objects of type T.
func RegisterCompiler ¶ added in v1.0.7
func RegisterCompiler(driver driver.Driver, compiler func(model attrs.Definer, defaultDB string) QueryCompiler)
RegisterCompiler registers a compiler for a given driver.
It should be used in the init() function of the package that implements the compiler.
The compiler function should take a model and a default database name as arguments, and return a QueryCompiler.
The default database name is used to determine the database connection to use and retrieve from the django.Global.Settings object.
func RegisterDriver ¶ added in v1.0.2
func RegisterDriver(driver driver.Driver, database string, supportsReturning ...SupportsReturning)
RegisterDriver registers a driver with the given database name.
This is used to determine the database type when using sqlx.
If your driver is not one of: - github.com/go-sql-driver/mysql.MySQLDriver - github.com/mattn/go-sqlite3.SQLiteDriver - github.com/jackc/pgx/v5/stdlib.Driver
Then it explicitly needs to be registered here.
func SaveObject ¶
SaveObject saves an object to the database.
It checks if the primary key is set. If it is not set, it creates a new object. If it is set, it updates the existing object.
It sends a pre-save signal before saving and a post-save signal after saving.
If the object implements the models.Saver interface, it will call the Save method instead of executing a query.
func Subquery ¶ added in v1.0.9
func Subquery(qs *GenericQuerySet) expr.Expression
func SubqueryCount ¶ added in v1.0.9
func SubqueryCount(qs *GenericQuerySet) *subqueryExpr
func SubqueryExists ¶ added in v1.0.9
func SubqueryExists(qs *GenericQuerySet) expr.Expression
func SubqueryIn ¶ added in v1.0.9
func SubqueryIn(field any, qs *GenericQuerySet) expr.Expression
func UpdateObject ¶
UpdateObject updates an existing object in the database.
It sends a pre-save signal before saving and a post-save signal after saving.
If the object implements the models.Saver interface, it will call the Save method instead of executing a query.
Types ¶
type AliasField ¶ added in v1.0.9
A field can adhere to this interface to indicate that the field should be aliased when generating the SQL for the field.
For example: this is used in annotations to alias the field name.
type CompiledCountQuery ¶ added in v1.0.9
type CompiledCountQuery CompiledQuery[int64]
A compiledQuery which returns the number of rows affected by the query.
type CompiledExistsQuery ¶ added in v1.0.9
type CompiledExistsQuery CompiledQuery[bool]
A compiledQuery which returns a boolean indicating if any rows were affected by the query.
type CompiledQuery ¶ added in v1.0.9
A CompiledQuery interface is used to execute a query.
It is possible to execute the query and retrieve the results.
The compiler will generally return a CompiledQuery interface, which the queryset will then store to be used as result on `LatestQuery()`.
type CompiledValuesListQuery ¶ added in v1.0.9
type CompiledValuesListQuery CompiledQuery[[][]any]
A compiledQuery which returns a list of values from the query.
type DB ¶ added in v1.0.7
type DB interface { QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row }
This interface is compatible with `*sql.DB` and `*sql.Tx`.
It is used for simple transaction management in the queryset.
If a transaction was started, the queryset will return the transaction instead of the database connection.
type DataModel ¶ added in v1.0.9
type DataModel interface {
ModelDataStore() ModelDataStore
}
A model can adhere to this interface to indicate that the queries package should use the model to store and retrieve annotated values.
Relations will also be stored here.
type FieldInfo ¶ added in v1.0.3
type FieldInfo struct { SourceField attrs.Field Model attrs.Definer RelType attrs.RelationType Table Table Chain []string Fields []attrs.Field }
func (*FieldInfo) WriteField ¶ added in v1.0.9
func (*FieldInfo) WriteFields ¶ added in v1.0.7
func (*FieldInfo) WriteUpdateFields ¶ added in v1.0.9
type ForUseInQueries ¶ added in v1.0.9
A model can adhere to this interface to indicate that the queries package should not automatically save or delete the model to/from the database when `django/models.SaveObject()` or `django/models.DeleteObject()` is called.
type ForUseInQueriesField ¶ added in v1.0.9
type ForUseInQueriesField interface { attrs.Field // ForUseInQueries returns true if the field is for use in queries. // This is used to determine if the field should be included in the query. // If the field does not implement this method, it is assumed to be for use in queries. ForSelectAll() bool }
ForUseInQueriesField is an interface that can be implemented by fields to indicate that the field should be included in the query.
For example, this is used in fields.RelationField to exclude the relation from the query, otherwise scanning errors will occur.
This is mostly for fields that do not actually exist in the database, I.E. reverse fk, o2o
type GenericQuerySet ¶ added in v1.0.9
QuerySet is a struct that represents a query set in the database.
It contains methods to filter, order, and limit the results of a query.
It is used to build and execute queries against the database.
Every method on the queryset returns a new queryset, so that the original queryset is not modified.
It also has a chainable api, so that you can easily build complex queries by chaining methods together.
Queries are built internally with the help of the QueryCompiler interface, which is responsible for generating the SQL queries for the database.
type ModelDataStore ¶ added in v1.0.9
type ModelDataStore interface { HasValue(key string) bool GetValue(key string) (any, bool) SetValue(key string, value any) error DeleteValue(key string) error }
Annotations from the database are stored in the `Row` struct, and if the model has a `ModelDataStore()` method that implements this interface, annotated values will be stored there too.
Relations are also stored in the model's data store.
type QueryCompiler ¶ added in v1.0.7
type QueryCompiler interface { // DB returns the database connection used by the query compiler. // // If a transaction was started, it will return the transaction instead of the database connection. DB() DB // Quote returns the quotes used by the database. // // This is used to quote table and field names. // For example, MySQL uses backticks (`) and PostgreSQL uses double quotes ("). Quote() (front string, back string) // SupportsReturning returns the type of returning supported by the database. // It can be one of the following: // // - SupportsReturningNone: no returning supported // - SupportsReturningLastInsertId: last insert id supported // - SupportsReturningColumns: returning columns supported SupportsReturning() SupportsReturning // StartTransaction starts a new transaction. StartTransaction(ctx context.Context) (Transaction, error) // CommitTransaction commits the current ongoing transaction. CommitTransaction() error // RollbackTransaction rolls back the current ongoing transaction. RollbackTransaction() error // InTransaction returns true if the current query compiler is in a transaction. InTransaction() bool // BuildSelectQuery builds a select query with the given parameters. BuildSelectQuery( ctx context.Context, qs *QuerySet[attrs.Definer], fields []FieldInfo, where []expr.LogicalExpression, having []expr.LogicalExpression, joins []JoinDef, groupBy []FieldInfo, orderBy []OrderBy, limit int, offset int, forUpdate bool, distinct bool, ) CompiledQuery[[][]interface{}] // BuildCountQuery builds a count query with the given parameters. BuildCountQuery( ctx context.Context, qs *QuerySet[attrs.Definer], where []expr.LogicalExpression, joins []JoinDef, groupBy []FieldInfo, limit int, offset int, ) CompiledQuery[int64] // BuildCreateQuery builds a create query with the given parameters. BuildCreateQuery( ctx context.Context, qs *QuerySet[attrs.Definer], fields FieldInfo, primary attrs.Field, values []any, ) CompiledQuery[[]interface{}] // BuildValuesListQuery builds a values list query with the given parameters. BuildUpdateQuery( ctx context.Context, qs *QuerySet[attrs.Definer], fields FieldInfo, where []expr.LogicalExpression, joins []JoinDef, groupBy []FieldInfo, values []any, ) CompiledQuery[int64] // BuildUpdateQuery builds an update query with the given parameters. BuildDeleteQuery( ctx context.Context, qs *QuerySet[attrs.Definer], where []expr.LogicalExpression, joins []JoinDef, groupBy []FieldInfo, ) CompiledQuery[int64] }
A QueryCompiler interface is used to compile a query.
It should be able to generate SQL queries and execute them.
It does not need to know about the model nor its field types.
func Compiler ¶ added in v1.0.7
func Compiler(model attrs.Definer, defaultDB string) QueryCompiler
Compiler returns a QueryCompiler for the given model and default database name.
If the default database name is empty, it will use the APPVAR_DATABASE setting.
If the database is not found in the settings, it will panic.
func NewGenericQueryBuilder ¶ added in v1.0.7
func NewGenericQueryBuilder(model attrs.Definer, db string) QueryCompiler
type QueryInfo ¶ added in v1.0.9
type QueryInfo interface { SQL() string Args() []any Model() attrs.Definer Compiler() QueryCompiler }
A QueryInfo interface is used to retrieve information about a query.
It is possible to introspect the queries' SQL, arguments, model, and compiler.
type QueryObject ¶ added in v1.0.7
type QueryObject[T1 any] struct { // contains filtered or unexported fields }
func (*QueryObject[T1]) Args ¶ added in v1.0.7
func (q *QueryObject[T1]) Args() []any
func (*QueryObject[T1]) Compiler ¶ added in v1.0.8
func (q *QueryObject[T1]) Compiler() QueryCompiler
func (*QueryObject[T1]) Exec ¶ added in v1.0.7
func (q *QueryObject[T1]) Exec() (T1, error)
func (*QueryObject[T1]) Model ¶ added in v1.0.7
func (q *QueryObject[T1]) Model() attrs.Definer
func (*QueryObject[T1]) SQL ¶ added in v1.0.7
func (q *QueryObject[T1]) SQL() string
type QuerySet ¶
type QuerySet[T attrs.Definer] struct { AliasGen *alias.Generator // contains filtered or unexported fields }
QuerySet is a struct that represents a query set in the database.
It contains methods to filter, order, and limit the results of a query.
It is used to build and execute queries against the database.
Every method on the queryset returns a new queryset, so that the original queryset is not modified.
It also has a chainable api, so that you can easily build complex queries by chaining methods together.
Queries are built internally with the help of the QueryCompiler interface, which is responsible for generating the SQL queries for the database.
func ChangeObjectsType ¶ added in v1.0.9
func GetQuerySet ¶ added in v1.0.9
GetQuerySet creates a new QuerySet for the given model.
If the model implements the QuerySetDefiner interface, it will use the GetQuerySet method to get the initial QuerySet.
A model should use Objects[T](model) to get the default QuerySet inside of it's GetQuerySet method. If not, it will recursively call itself.
See Objects for more details.
func Objects ¶
Objects creates a new QuerySet for the given model.
This function should only be called in a model's GetQuerySet method.
In other places the GetQuerySet function should be used instead.
It panics if: - the model is nil - the base query info cannot be retrieved
It returns a pointer to a new QuerySet.
The model must implement the Definer interface.
func (*QuerySet[T]) Aggregate ¶ added in v1.0.9
Aggregate is used to perform aggregation on the results of a query.
It takes a map of field names to expr.Expressions as arguments and returns a Query that can be executed to get the results.
func (*QuerySet[T]) All ¶
All is used to retrieve all rows from the database.
It returns a Query that can be executed to get the results, which is a slice of Row objects.
Each Row object contains the model object and a map of annotations.
If no fields are provided, it selects all fields from the model, see `Select()` for more details.
func (*QuerySet[T]) Annotate ¶ added in v1.0.9
func (qs *QuerySet[T]) Annotate(aliasOrAliasMap interface{}, exprs ...expr.Expression) *QuerySet[T]
Annotate is used to add annotations to the results of a query.
It takes a string or a map of strings to expr.Expressions as arguments and returns a new QuerySet with the annotations.
If a string is provided, it is used as the alias for the expr.Expression.
If a map is provided, the keys are used as aliases for the expr.Expressions.
func (*QuerySet[T]) Clone ¶
Clone creates a new QuerySet with the same parameters as the original one.
It is used to create a new QuerySet with the same parameters as the original one, so that the original one is not modified.
It is a shallow clone, underlying values like `*queries.Expr` are not cloned and have built- in immutability.
func (*QuerySet[T]) Compiler ¶ added in v1.0.7
func (qs *QuerySet[T]) Compiler() QueryCompiler
Return the compiler which the queryset is using.
func (*QuerySet[T]) Count ¶
Count is used to count the number of rows in the database.
It returns a CountQuery that can be executed to get the result, which is an int64 indicating the number of rows.
func (*QuerySet[T]) Create ¶ added in v1.0.7
Create is used to create a new object in the database.
It takes a definer object as an argument and returns a Query that can be executed to get the result, which is the created object.
It panics if a non- nullable field is null or if the field is not found in the model.
The model can adhere to django's `models.Saver` interface, in which case the `Save()` method will be called unless `ExplicitSave()` was called on the queryset.
If `ExplicitSave()` was called, the `Create()` method will return a query that can be executed to create the object without calling the `Save()` method on the model.
func (*QuerySet[T]) DB ¶ added in v1.0.7
Return the underlying database which the compiler is using.
func (*QuerySet[T]) Delete ¶ added in v1.0.3
Delete is used to delete an object from the database.
It returns a CountQuery that can be executed to get the result, which is the number of rows affected.
func (*QuerySet[T]) Distinct ¶ added in v1.0.3
Distinct is used to select distinct rows from the results of a query.
It is used to remove duplicate rows from the results.
func (*QuerySet[T]) Exists ¶ added in v1.0.3
Exists is used to check if any rows exist in the database.
It returns a Query that can be executed to get the result, which is a boolean indicating if any rows exist.
func (*QuerySet[T]) ExplicitSave ¶ added in v1.0.8
ExplicitSave is used to indicate that the save operation should be explicit.
It is used to prevent the automatic save operation from being performed on the model.
I.E. when using the `Create` method after calling `qs.ExplicitSave()`, it will **not** automatically save the model to the database using the model's own `Save` method.
func (*QuerySet[T]) Filter ¶
Filter is used to filter the results of a query.
It takes a key and a list of values as arguments and returns a new QuerySet with the filtered results.
The key can be a field name (string), an expr.Expression (expr.Expression) or a map of field names to values.
By default the `__exact` (=) operator is used, each where clause is separated by `AND`.
func (*QuerySet[T]) First ¶
First is used to retrieve the first row from the database.
It returns a Query that can be executed to get the result, which is a Row object that contains the model object and a map of annotations.
func (*QuerySet[T]) ForUpdate ¶
ForUpdate is used to lock the rows returned by a query for update.
It is used to prevent other transactions from modifying the rows until the current transaction is committed or rolled back.
func (*QuerySet[T]) Get ¶ added in v1.0.7
Get is used to retrieve a single row from the database.
It returns a Query that can be executed to get the result, which is a Row object that contains the model object and a map of annotations.
It panics if the queryset has no where clause.
If no rows are found, it returns queries.query_errors.ErrNoRows.
If multiple rows are found, it returns queries.query_errors.ErrMultipleRows.
func (*QuerySet[T]) GetOrCreate ¶ added in v1.0.7
GetOrCreate is used to retrieve a single row from the database or create it if it does not exist.
It returns the definer object and an error if any occurred.
This method executes a transaction to ensure that the object is created only once.
It panics if the queryset has no where clause.
func (*QuerySet[T]) GoString ¶ added in v1.0.8
Return a detailed string representation of the QuerySet.
func (*QuerySet[T]) GroupBy ¶
GroupBy is used to group the results of a query.
It takes a list of field names as arguments and returns a new QuerySet with the grouped results.
func (*QuerySet[T]) Having ¶
Having is used to filter the results of a query after aggregation.
It takes a key and a list of values as arguments and returns a new QuerySet with the filtered results.
The key can be a field name (string), an expr.Expression (expr.Expression) or a map of field names to values.
func (*QuerySet[T]) Last ¶ added in v1.0.3
Last is used to retrieve the last row from the database.
It reverses the order of the results and then calls First to get the last row.
It returns a Query that can be executed to get the result, which is a Row object that contains the model object and a map of annotations.
func (*QuerySet[T]) LatestQuery ¶ added in v1.0.9
LatestQuery returns the latest query that was executed on the queryset.
func (*QuerySet[T]) OrderBy ¶
OrderBy is used to order the results of a query.
It takes a list of field names as arguments and returns a new QuerySet with the ordered results.
The field names can be prefixed with a minus sign (-) to indicate descending order.
func (*QuerySet[T]) Reverse ¶ added in v1.0.3
Reverse is used to reverse the order of the results of a query.
It returns a new QuerySet with the reversed order.
func (*QuerySet[T]) Select ¶ added in v1.0.3
Select is used to select specific fields from the model.
It takes a list of field names as arguments and returns a new QuerySet with the selected fields.
If no fields are provided, it selects all fields from the model.
If the first field is "*", it selects all fields from the model, extra fields (i.e. relations) can be provided thereafter - these will also be added to the selection.
How to call Select:
`Select("*")` `Select("Field1", "Field2")` `Select("Field1", "Field2", "Relation.*")` `Select("*", "Relation.*")` `Select("Relation.*")` `Select("*", "Relation.Field1", "Relation.Field2", "Relation.Nested.*")`
func (*QuerySet[T]) StartTransaction ¶ added in v1.0.9
func (qs *QuerySet[T]) StartTransaction(ctx context.Context) (Transaction, error)
StartTransaction starts a transaction on the underlying database.
It returns a transaction object which can be used to commit or rollback the transaction.
func (*QuerySet[T]) Update ¶ added in v1.0.3
func (qs *QuerySet[T]) Update(value T, expressions ...expr.NamedExpression) (int64, error)
Update is used to update an object in the database.
It takes a definer object as an argument and returns a CountQuery that can be executed to get the result, which is the number of rows affected.
It panics if a non- nullable field is null or if the field is not found in the model.
If the model adheres to django's `models.Saver` interface, no where clause is provided and ExplicitSave() was not called, the `Save()` method will be called on the model
func (*QuerySet[T]) ValuesList ¶ added in v1.0.3
ValuesList is used to retrieve a list of values from the database.
It takes a list of field names as arguments and returns a ValuesListQuery.
type QuerySetDatabaseDefiner ¶ added in v1.0.9
A model can adhere to this interface to indicate that the queries package should use the database returned by `QuerySetDatabase()` to execute the query.
The database should be retrieved from the django.Global.Settings object using the returned key.
type QuerySetDefiner ¶ added in v1.0.9
A model can adhere to this interface to indicate that the queries package should use the queryset returned by `GetQuerySet()` to execute the query.
Calling `queries.Objects()` with a model that implements this interface will return the queryset returned by `GetQuerySet()`.
type QuerySetInternals ¶ added in v1.0.9
type QuerySetInternals struct { Annotations map[string]*queryField[any] Fields []FieldInfo Where []expr.LogicalExpression Having []expr.LogicalExpression Joins []JoinDef GroupBy []FieldInfo OrderBy []OrderBy Limit int Offset int ForUpdate bool Distinct bool // contains filtered or unexported fields }
type RelatedField ¶ added in v1.0.9
type RelatedField interface { attrs.Field // This is used to determine the column name for the field, for example for a through table. GetTargetField() attrs.Field RelatedName() string }
RelatedField is an interface that can be implemented by fields to indicate that the field is a related field.
For example, this is used in fields.RelationField to determine the column name for the target field.
If `GetTargetField()` returns nil, the primary field of the target model should be used instead.
type SignalSave ¶ added in v1.0.8
type SignalSave struct { Instance attrs.Definer Using QueryCompiler }
Signals are used to notify when a model instance is saved or deleted.
SignalSave is only meant to hold the model instance and the query compiler'
type SupportsReturning ¶ added in v1.0.7
type SupportsReturning = internal.SupportsReturning
const ( SupportsReturningNone SupportsReturning = internal.SupportsReturningNone SupportsReturningLastInsertId SupportsReturning = internal.SupportsReturningLastInsertId SupportsReturningColumns SupportsReturning = internal.SupportsReturningColumns )
func DBSupportsReturning ¶ added in v1.0.9
func DBSupportsReturning(db *sql.DB) SupportsReturning
type Transaction ¶ added in v1.0.7
This interface is compatible with `*sql.Tx`.
It is used for simple transaction management in the queryset.
type VirtualField ¶ added in v1.0.9
type VirtualField interface {
SQL(inf *expr.ExpressionInfo) (string, []any)
}
A field can adhere to this interface to indicate that the field should be rendered as SQL.
For example: this is used in fields.ExpressionField to render the expression as SQL.