ProtectedconnectionProtected ReadonlydreamProtected ReadonlydreamProtecteddreamProtected Readonly InternalinnerRetrieves the average value of the specified column for this Query
await Game.query().avg('score')
// 1
a column name on the model
the average of the values of the specified column for this Query
Retrieves the number of records in the database
await User.query().count()
The number of records in the database
InternalThis method is used internally by a Query driver to take the result of a single row in a database, and turn that row into the provided dream instance.
If needed, the return type can be overriden to explicitly define the resulting dream instance, in cases where a proper type for the dream class cannot be inferred, i.e.
this.dbResultToDreamInstance<typeof Dream, DreamInstance>(result, this.dreamClass)
executes provided query instance as a deletion query.
the number of deleted rows
InternalUsed to hydrate dreams with the provided associations
InternalUsed by loadBuider
Retrieves the max value of the specified column for this Query
await User.query().max('id')
// 99
a column name on the model
the max value of the specified column for this Query
Retrieves the min value of the specified column for this Query
await User.query().min('id')
// 1
a column name on the model
the min value of the specified column for this Query
Returns a new Kysely SelectQueryBuilder instance to be used in a sub Query
const records = await User.where({
id: Post.query().nestedSelect('userId'),
}).all()
// [User{id: 1}, ...]
the column to use for your nested Query
A Kysely SelectQueryBuilder instance
InternalRuns the query and extracts plucked values
An array of plucked values
Returns the sql that would be executed by this Query
User.where({ email: 'how@yadoin' }).sql()
// {
// query: {
// kind: 'SelectQueryNode',
// from: { kind: 'FromNode', froms: [Array] },
// selections: [ [Object] ],
// distinctOn: undefined,
// joins: undefined,
// groupBy: undefined,
// orderBy: undefined,
// where: { kind: 'WhereNode', where: [Object] },
// frontModifiers: undefined,
// endModifiers: undefined,
// limit: undefined,
// offset: undefined,
// with: undefined,
// having: undefined,
// explain: undefined,
// setOperations: undefined
// },
// sql: 'select "users".* from "users" where ("users"."email" = $1 and "users"."deleted_at" is null)',
// parameters: [ 'how@yadoin' ]
//}
An object representing the underlying sql statement
Retrieves the sum value of the specified column for this Query
await Game.query().sum('score')
// 1
a column name on the model
the sum of the values of the specified column for this Query
InternalRetrieves an array containing all records matching the Query.
Be careful using this, since it will attempt to pull every
record into memory at once. When querying might return a large
number of records, consider using .findEach, which will pull
the records in batches.
await User.query().all()
an array of dreams
InternalUsed for applying first and last queries
A dream instance or null
Converts the given dream class into a Kysely query, enabling you to build custom queries using the Kysely API
await User.query().toKysely('select').where('email', '=', 'how@yadoin').execute()
the type of Kysely query builder instance you would like to obtain
A Kysely query. Depending on the type passed, it will return either a SelectQueryBuilder, DeleteQueryBuilder, or an UpdateQueryBuilder
executes provided query instance as an update query.
the number of updated rows
Staticdbcreate the database. Must respond to the NODE_ENV value.
Staticdbdelete the database. Must respond to the NODE_ENV value.
StaticdbOptionaldreamTransaction: DreamTransaction<I, I["DB"]> | nullStaticdestroydestroys a dream, possibly implementing soft delete if reallyDestroy is false and the record being deleted implements soft delete.
the dream instance you wish to destroy
a transaction to encapsulate, consistently provided by underlying dream mechanisms
whether or not to reallyDestroy. If false, soft delete will be attempted when relevant
StaticdialectStaticduplicateStaticensureStaticenumInternalthis is used by getColumnData to serialize enums
StaticforeignInternalreturns the foreign key type based on the primary key received. gives the driver the opportunity to switch i.e. bigserial to bigint.
StaticgenerateThis should build a new migration file in the migrations folder
of your application. This will then need to be read and run
whenever the migrate method is called. The filename should
contain a timestamp at the front of the filename, so that it
is sorted by date in the file tree, and, more importantly, so
they can be run in order by your migration runner.
StaticgetInternalthis is used by the SchemaBuilder to store column data permanently within the types/dream.ts file.
Staticmigratemigrate the database. Must respond to the NODE_ENV value.
StaticprimaryInternalused to return the computed primary key type based on the primaryKeyType set in the DreamApp class.
Staticrollbackrollback the database. Must respond to the NODE_ENV value.
Staticsavepersists any unsaved changes to the database. If a transaction is provided as a second argument, it will use that transaction to encapsulate the persisting of the dream, as well as any subsequent model hooks that are fired.
StaticsetInternalthis method is called when dream is initializing, and is used to configure the database to utilize custom type parsers for a variety of data types.
the name of the connection you are doing this for
void
Staticsyncdefines the syncing behavior for dream and psychic,
which is run whenever the sync command is called.
StatictransactionBuilds a new DreamTransaction instance, provides the instance to the provided callback.
await ApplicationModel.transaction(async txn => {
const user = await User.txn(txn).create({ email: 'how@yadoin' })
await Pet.txn(txn).create({ user })
})
A callback function to call. The transaction provided to the callback can be passed to subsequent database calls within the transaction callback
void
stores the Dream models joined in this Query instance