@rvoh/dream
    Preparing search index...

    Class QueryDriverBase<DreamInstance>

    Type Parameters

    • DreamInstance extends Dream

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    connectionOverride: DbConnectionType | undefined
    dreamClass: DreamConstructorType<DreamInstance>
    dreamInstance: DreamInstance
    dreamTransaction: DreamTransaction<Dream, any> | null = null
    innerJoinDreamClasses: readonly typeof Dream[] = ...

    stores the Dream models joined in this Query instance

    query: Query<DreamInstance, any>

    Accessors

    Methods

    • Retrieves the average value of the specified column for this Query

      await Game.query().avg('score')
      // 1

      Parameters

      • columnName: string

        a column name on the model

      Returns Promise<any>

      the average of the values of the specified column for this Query

    • Retrieves the number of records in the database

      await User.query().count()
      

      Returns Promise<number>

      The number of records in the database

    • Internal

      This 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)
      

      Type Parameters

      Parameters

      • result: any
      • dreamClass: typeof Dream

      Returns RetType

    • executes provided query instance as a deletion query.

      Returns Promise<number>

      the number of deleted rows

    • Internal

      Used to hydrate dreams with the provided associations

      Parameters

      • dreams: Dream[]
      • association: AssociationStatement
      • preloadedDreamsAndWhatTheyPointTo: PreloadedDreamsAndWhatTheyPointTo[]

      Returns void

    • Retrieves the max value of the specified column for this Query

      await User.query().max('id')
      // 99

      Parameters

      • columnName: string

        a column name on the model

      Returns Promise<any>

      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

      Parameters

      • columnName: string

        a column name on the model

      Returns Promise<any>

      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}, ...]

      Type Parameters

      • SimpleFieldType extends
            | number
            | typeof iterator
            | "match"
            | "toString"
            | "charAt"
            | "charCodeAt"
            | "concat"
            | "indexOf"
            | "lastIndexOf"
            | "localeCompare"
            | "replace"
            | "search"
            | "slice"
            | "split"
            | "substring"
            | "toLowerCase"
            | "toLocaleLowerCase"
            | "toUpperCase"
            | "toLocaleUpperCase"
            | "trim"
            | "length"
            | "substr"
            | "valueOf"
            | "codePointAt"
            | "includes"
            | "endsWith"
            | "normalize"
            | "repeat"
            | "startsWith"
            | "anchor"
            | "big"
            | "blink"
            | "bold"
            | "fixed"
            | "fontcolor"
            | "fontsize"
            | "italics"
            | "link"
            | "small"
            | "strike"
            | "sub"
            | "sup"
            | "padStart"
            | "padEnd"
            | "trimEnd"
            | "trimStart"
            | "trimLeft"
            | "trimRight"
            | "matchAll"
            | "replaceAll"
            | "at"
            | "toLocaleString"
      • PluckThroughFieldType

      Parameters

      Returns SelectQueryBuilder<any, any, any>

      A Kysely SelectQueryBuilder instance

    • 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' ]
      //}

      Returns CompiledQuery<object>

      An object representing the underlying sql statement

    • Retrieves the sum value of the specified column for this Query

      await Game.query().sum('score')
      // 1

      Parameters

      • columnName: string

        a column name on the model

      Returns Promise<any>

      the sum of the values of the specified column for this Query

    • Retrieves 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()
      

      Parameters

      Returns Promise<DreamInstance[]>

      an array of dreams

    • 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()
      

      Type Parameters

      • QueryType extends "update" | "delete" | "select"
      • DbType = DreamInstance["DB"]
      • TableNames = DreamInstance["table"]
      • ToKyselyReturnType = QueryType extends "select"
            ? SelectQueryBuilder<DbType, TableNames & keyof DbType, unknown>
            : QueryType extends "delete"
                ? DeleteQueryBuilder<DbType, TableNames & keyof DbType, unknown>
                : QueryType extends "update"
                    ? UpdateQueryBuilder<
                        DbType,
                        TableNames & keyof DbType,
                        TableNames & keyof DbType,
                        unknown,
                    >
                    : never

      Parameters

      • type: QueryType

        the type of Kysely query builder instance you would like to obtain

      Returns ToKyselyReturnType

      A Kysely query. Depending on the type passed, it will return either a SelectQueryBuilder, DeleteQueryBuilder, or an UpdateQueryBuilder

    • create the database. Must respond to the NODE_ENV value.

      Parameters

      • connectionName: string

      Returns Promise<void>

    • delete the database. Must respond to the NODE_ENV value.

      Parameters

      • connectionName: string

      Returns Promise<void>

    • destroys a dream, possibly implementing soft delete if reallyDestroy is false and the record being deleted implements soft delete.

      Parameters

      • dream: Dream

        the dream instance you wish to destroy

      • txn: DreamTransaction<Dream>

        a transaction to encapsulate, consistently provided by underlying dream mechanisms

      • reallyDestroy: boolean

        whether or not to reallyDestroy. If false, soft delete will be attempted when relevant

      Returns Promise<void>

    • Parameters

      • connectionName: string

      Returns Promise<void>

    • Internal

      returns the foreign key type based on the primary key received. gives the driver the opportunity to switch i.e. bigserial to bigint.

      Parameters

      • primaryKey: LegacyCompatiblePrimaryKeyType

      Returns LegacyCompatiblePrimaryKeyType

    • This 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.

      Parameters

      • connectionName: string
      • migrationName: string
      • columnsWithTypes: string[]

      Returns Promise<void>

    • Parameters

      • connectionName: string
      • tableName: string
      • allTableAssociationData: { [key: string]: SchemaBuilderAssociationData }

      Returns Promise<{ [key: string]: SchemaBuilderColumnData }>

    • migrate the database. Must respond to the NODE_ENV value.

      Parameters

      • connectionName: string

      Returns Promise<void>

    • Internal

      used to return the computed primary key type based on the primaryKeyType set in the DreamApp class.

      Returns void

    • rollback the database. Must respond to the NODE_ENV value.

      Parameters

      • _: { connectionName: string; steps: number }

      Returns Promise<void>

    • persists 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.

      Parameters

      Returns Promise<any>

    • Internal

      this 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.

      Parameters

      • connectionName: string

        the name of the connection you are doing this for

      Returns Promise<void>

      void

    • defines the syncing behavior for dream and psychic, which is run whenever the sync command is called. This is an important step, and will be incredibly comlpex to override. You will need to do the following when overriding this method:

      1. introspect the db and use it to generate a db.ts file in the same shape as the existing one. Currently, the process for generating this file is extremely complex and messy, and will be difficult to achieve.
      2. generate a types/dream.ts file in the same shape as the existing one. This is normally done using the ASTSchemaBuilder but this will likely need to be overridden to tailor to your custom database engine.

      Parameters

      • connectionName: string
      • _: () => void | Promise<void>
      • options: { schemaOnly?: boolean } = {}

      Returns Promise<void>

    • Builds 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 })
      })

      Type Parameters

      Parameters

      • dreamInstance: DreamInstance
      • callback: CB

        A callback function to call. The transaction provided to the callback can be passed to subsequent database calls within the transaction callback

      Returns Promise<RetType>

      void