prorm API Reference
    Preparing search index...

    Class CreateQueryInterface

    CreateQueryInterface - Provides migration operations for all database dialects

    Index
    • Create a partitioned table (PostgreSQL 10+)

      Parameters

      • tableName: string

        Name of the table to create

      • columns: Record<string, TableColumnDefinition>

        Column definitions

      • Optionaloptions: TableOptions & QueryInterfaceOptions & {
            partitionBy: { type: PartitionType; column: string | string[] };
            partitions?: {
                name: string;
                bound?: PartitionBound;
                tablespace?: string;
                storageParameters?: Record<string, string | number>;
            }[];
        }

        Table options including partition configuration

      Returns Promise<void>

    • Drop a partition (PostgreSQL 10+)

      Parameters

      • partitionName: string

        Name of the partition to drop

      • Optionaloptions: { ifExists?: boolean; cascade?: boolean } & QueryInterfaceOptions

        Drop options

      Returns Promise<void>

    • Remove a column from a table

      Parameters

      • tableName: string

        Name of the table

      • columnName: string

        Name of the column to remove

      • Optional_options: QueryInterfaceOptions

      Returns Promise<void>

    • Rename a column

      Parameters

      • tableName: string

        Name of the table

      • oldColumnName: string

        Current column name

      • newColumnName: string

        New column name

      • Optional_options: QueryInterfaceOptions

      Returns Promise<void>

    • Remove an index from a table

      Parameters

      • tableName: string

        Name of the table

      • indexName: string

        Name of the index to remove

      • Optional_options: QueryInterfaceOptions

      Returns Promise<void>

    • Show all indexes for a table

      Parameters

      • tableName: string

        Name of the table

      Returns Promise<{ name: string; fields: string[]; unique: boolean }[]>

    • Remove a constraint from a table

      Parameters

      • tableName: string

        Name of the table

      • constraintName: string

        Name of the constraint to remove

      • Optional_typeOrOptions: string | QueryInterfaceOptions

      Returns Promise<void>

    • Check if an index exists on a table

      Parameters

      • tableName: string
      • indexName: string

      Returns Promise<boolean>

    • Bulk insert records

      Parameters

      • tableName: string

        Name of the table

      • records: Record<string, any>[]

        Records to insert

      • Optional_options: BulkOperationOptions

      Returns Promise<number>

    • Show all tables in the database

      Returns Promise<string[]>

    • Check if a table exists

      Parameters

      • tableName: string

        Name of the table

      Returns Promise<boolean>

    • Get all table names with schema (for PostgreSQL, MySQL, etc.)

      Parameters

      • Optional_schema: string

        Optional schema name

      Returns Promise<string[]>

    • Get foreign keys for a table

      Parameters

      • _tableName: string

      Returns Promise<any[]>

    • Get constraints for a table

      Parameters

      • _tableName: string

      Returns Promise<any[]>

    • Create a database view.

      Define the view the same way you would write the query it saves — a view is a saved query, so definition takes the findAll() options and the dialect compiles them:

      await qi.createView('customer_info', {
      from: Customer,
      attributes: ['firstName', 'lastName', 'email'],
      where: { country: 'USA' },
      });

      Parameters

      • viewName: string

        Name of the view to create

      • definition: string | ViewDefinition

        The view body as query options. A raw SELECT string is still accepted for backwards compatibility, but writing SQL by hand gives up dialect portability and identifier quoting; prefer the object form.

      • Optionaloptions: ViewOptions & QueryInterfaceOptions

        View options

      Returns Promise<void>

    • Show all views in the database

      Returns Promise<string[]>

    • Check if a view exists

      Parameters

      • viewName: string

        Name of the view

      Returns Promise<boolean>

    • Create a materialized view.

      Takes the same structured definition as createView — pass query options rather than a SELECT string:

      await qi.createMaterializedView({
      name: 'order_totals',
      definition: {
      from: Order,
      attributes: ['userId', [fn('COUNT', col('id')), 'orderCount']],
      group: 'userId',
      },
      });

      Parameters

      • options: MaterializedViewInput

        Materialized view options, carrying either a definition or (for backwards compatibility) a raw query string.

      Returns Promise<void>

    • Check if a materialized view exists

      Parameters

      • viewName: string

        Name of the materialized view

      Returns Promise<boolean>

    • Show all materialized views in the database

      Returns Promise<string[]>

    • Drop a sequence.

      Parameters

      • name: string
      • Optionaloptions: { ifExists?: boolean }

      Returns Promise<void>

    • Create a trigger.

      On PostgreSQL this also creates the backing trigger function, which the database requires and which a hand-written CREATE TRIGGER easily forgets.

      Parameters

      Returns Promise<void>

    • Drop a trigger.

      Parameters

      • name: string
      • table: string
      • Optionaloptions: { ifExists?: boolean }

      Returns Promise<void>

    • Enable row-level security on a table (PostgreSQL family).

      Parameters

      • table: string

      Returns Promise<void>

    • Disable row-level security on a table (PostgreSQL family).

      Parameters

      • table: string

      Returns Promise<void>

    • Create a row-level security policy.

      Parameters

      Returns Promise<void>

      await qi.createPolicy({
      name: 'users_own_rows',
      table: 'users',
      for: 'SELECT',
      using: 'user_id = current_user_id()',
      });
    • Register a function written in a language other than SQL.

      Two shapes, matching what databases offer. Compiled — you wrote C, built a shared library, and want the database to call into it:

      // MySQL: the library lives in the server's plugin_dir
      await qi.createExternalFunction({
      name: 'levenshtein',
      language: 'c',
      returns: 'INTEGER',
      library: 'my_udf.so',
      });

      // PostgreSQL: object file plus the exported symbol
      await qi.createExternalFunction({
      name: 'levenshtein',
      language: 'c',
      returns: 'integer',
      params: [{ name: 'a', type: 'text' }, { name: 'b', type: 'text' }],
      library: '$libdir/my_udf',
      symbol: 'pg_levenshtein',
      strict: true,
      volatility: 'IMMUTABLE',
      });

      Or interpreted — the source is stored in the database and run by a procedural-language handler:

      await qi.createExternalFunction({
      name: 'slugify',
      language: 'plpython3u',
      returns: 'text',
      params: [{ name: 'value', type: 'text' }],
      source: 'import re\nreturn re.sub(r"[^a-z0-9]+", "-", value.lower()).strip("-")',
      });

      source is code in that language — it is stored verbatim and never parsed as SQL. MySQL supports only the compiled form.

      Parameters

      Returns Promise<void>

    • Drop an external function.

      PostgreSQL identifies overloads by argument types, so pass the same params used to create it when more than one overload exists.

      Parameters

      • name: string
      • Optionaloptions: { ifExists?: boolean; params?: StoredProcedureParam[]; schema?: string }

      Returns Promise<void>

    • Drop a row-level security policy.

      Parameters

      • name: string
      • table: string
      • Optionaloptions: { ifExists?: boolean }

      Returns Promise<void>

    • Quote an identifier

      Parameters

      • identifier: string

        The identifier to quote

      Returns string

    • Escape a value

      Parameters

      • value: any

        The value to escape

      Returns string