dialect.d.ts 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { entityKind } from "../entity.js";
  2. import type { MigrationConfig, MigrationMeta } from "../migrator.js";
  3. import { type BuildRelationalQueryResult, type DBQueryConfig, type Relation, type TableRelationalConfig, type TablesRelationalConfig } from "../relations.js";
  4. import { SQL } from "../sql/sql.js";
  5. import type { QueryWithTypings } from "../sql/sql.js";
  6. import { type Casing, type UpdateSet } from "../utils.js";
  7. import { MySqlColumn } from "./columns/common.js";
  8. import type { MySqlDeleteConfig } from "./query-builders/delete.js";
  9. import type { MySqlInsertConfig } from "./query-builders/insert.js";
  10. import type { MySqlSelectConfig } from "./query-builders/select.types.js";
  11. import type { MySqlUpdateConfig } from "./query-builders/update.js";
  12. import type { MySqlSession } from "./session.js";
  13. import { MySqlTable } from "./table.js";
  14. export interface MySqlDialectConfig {
  15. casing?: Casing;
  16. }
  17. export declare class MySqlDialect {
  18. static readonly [entityKind]: string;
  19. constructor(config?: MySqlDialectConfig);
  20. migrate(migrations: MigrationMeta[], session: MySqlSession, config: Omit<MigrationConfig, 'migrationsSchema'>): Promise<void>;
  21. escapeName(name: string): string;
  22. escapeParam(_num: number): string;
  23. escapeString(str: string): string;
  24. private buildWithCTE;
  25. buildDeleteQuery({ table, where, returning, withList, limit, orderBy, }: MySqlDeleteConfig): SQL;
  26. buildUpdateSet(table: MySqlTable, set: UpdateSet): SQL;
  27. buildUpdateQuery({ table, set, where, returning, withList, limit, orderBy, }: MySqlUpdateConfig): SQL;
  28. /**
  29. * Builds selection SQL with provided fields/expressions
  30. *
  31. * Examples:
  32. *
  33. * `select <selection> from`
  34. *
  35. * `insert ... returning <selection>`
  36. *
  37. * If `isSingleTable` is true, then columns won't be prefixed with table name
  38. */
  39. private buildSelection;
  40. private buildLimit;
  41. private buildOrderBy;
  42. private buildIndex;
  43. buildSelectQuery({ withList, fields, fieldsFlat, where, having, table, joins, orderBy, groupBy, limit, offset, lockingClause, distinct, setOperators, useIndex, forceIndex, ignoreIndex, }: MySqlSelectConfig): SQL;
  44. buildSetOperations(leftSelect: SQL, setOperators: MySqlSelectConfig['setOperators']): SQL;
  45. buildSetOperationQuery({ leftSelect, setOperator: { type, isAll, rightSelect, limit, orderBy, offset }, }: {
  46. leftSelect: SQL;
  47. setOperator: MySqlSelectConfig['setOperators'][number];
  48. }): SQL;
  49. buildInsertQuery({ table, values: valuesOrSelect, ignore, onConflict, select, }: MySqlInsertConfig): {
  50. sql: SQL;
  51. generatedIds: Record<string, unknown>[];
  52. };
  53. sqlToQuery(sql: SQL, invokeSource?: 'indexes' | undefined): QueryWithTypings;
  54. buildRelationalQuery({ fullSchema, schema, tableNamesMap, table, tableConfig, queryConfig: config, tableAlias, nestedQueryRelation, joinOn, }: {
  55. fullSchema: Record<string, unknown>;
  56. schema: TablesRelationalConfig;
  57. tableNamesMap: Record<string, string>;
  58. table: MySqlTable;
  59. tableConfig: TableRelationalConfig;
  60. queryConfig: true | DBQueryConfig<'many', true>;
  61. tableAlias: string;
  62. nestedQueryRelation?: Relation;
  63. joinOn?: SQL;
  64. }): BuildRelationalQueryResult<MySqlTable, MySqlColumn>;
  65. buildRelationalQueryWithoutLateralSubqueries({ fullSchema, schema, tableNamesMap, table, tableConfig, queryConfig: config, tableAlias, nestedQueryRelation, joinOn, }: {
  66. fullSchema: Record<string, unknown>;
  67. schema: TablesRelationalConfig;
  68. tableNamesMap: Record<string, string>;
  69. table: MySqlTable;
  70. tableConfig: TableRelationalConfig;
  71. queryConfig: true | DBQueryConfig<'many', true>;
  72. tableAlias: string;
  73. nestedQueryRelation?: Relation;
  74. joinOn?: SQL;
  75. }): BuildRelationalQueryResult<MySqlTable, MySqlColumn>;
  76. }