uql-orm 0.91.1 → 0.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/dist/browser/http/bus.js +3 -4
  2. package/dist/browser/http/http.d.ts +1 -2
  3. package/dist/browser/http/http.js +8 -7
  4. package/dist/browser/index.d.ts +0 -1
  5. package/dist/browser/index.js +0 -1
  6. package/dist/browser/querier/httpQuerier.d.ts +18 -20
  7. package/dist/browser/querier/httpQuerier.js +20 -56
  8. package/dist/browser/type/index.d.ts +0 -1
  9. package/dist/browser/type/index.js +0 -1
  10. package/dist/browser/uql-browser.min.js +2 -2
  11. package/dist/browser/uql-browser.min.js.map +11 -12
  12. package/dist/cockroachdb/cockroachDialect.d.ts +4 -1
  13. package/dist/cockroachdb/cockroachDialect.js +5 -1
  14. package/dist/dialect/abstractDialect.d.ts +1 -1
  15. package/dist/dialect/abstractDialect.js +4 -1
  16. package/dist/dialect/abstractSqlDialect.d.ts +24 -28
  17. package/dist/dialect/abstractSqlDialect.js +47 -45
  18. package/dist/dialect/aliases.d.ts +4 -1
  19. package/dist/dialect/aliases.js +5 -2
  20. package/dist/dialect/hydrateColumn.js +3 -10
  21. package/dist/dialect/jsonSql.d.ts +4 -1
  22. package/dist/dialect/jsonSql.js +4 -1
  23. package/dist/dialect/mergeSqlDialect.d.ts +4 -3
  24. package/dist/dialect/mergeSqlDialect.js +5 -4
  25. package/dist/dialect/mysqlLikeSqlDialect.d.ts +7 -21
  26. package/dist/dialect/mysqlLikeSqlDialect.js +9 -36
  27. package/dist/dialect/pgLikeSqlDialect.d.ts +3 -7
  28. package/dist/dialect/pgLikeSqlDialect.js +11 -21
  29. package/dist/http/contract.d.ts +4 -0
  30. package/dist/http/contract.js +1 -0
  31. package/dist/http/handler.d.ts +2 -2
  32. package/dist/http/handler.js +17 -19
  33. package/dist/http/query.d.ts +5 -3
  34. package/dist/http/query.js +42 -42
  35. package/dist/index.d.ts +1 -1
  36. package/dist/index.js +1 -1
  37. package/dist/maria/mariaDialect.d.ts +2 -3
  38. package/dist/maria/mariaDialect.js +1 -5
  39. package/dist/migrate/builder/columnBuilder.d.ts +5 -15
  40. package/dist/migrate/builder/columnBuilder.js +50 -86
  41. package/dist/migrate/builder/expressions.d.ts +12 -18
  42. package/dist/migrate/builder/expressions.js +39 -42
  43. package/dist/migrate/builder/migrationBuilder.d.ts +3 -11
  44. package/dist/migrate/builder/migrationBuilder.js +41 -81
  45. package/dist/migrate/builder/tableBuilder.d.ts +0 -7
  46. package/dist/migrate/builder/tableBuilder.js +17 -28
  47. package/dist/migrate/builder/types.d.ts +2 -2
  48. package/dist/migrate/codegen/entityCodeGenerator.js +3 -3
  49. package/dist/migrate/codegen/entityTypes.js +2 -2
  50. package/dist/migrate/codegen/fieldOptionsSource.d.ts +2 -2
  51. package/dist/migrate/codegen/fieldOptionsSource.js +27 -12
  52. package/dist/migrate/codegen/indexDecoratorSource.js +64 -41
  53. package/dist/migrate/ddl/index.d.ts +2 -4
  54. package/dist/migrate/ddl/index.js +14 -5
  55. package/dist/migrate/ddl/mssqlTableDdl.d.ts +1 -0
  56. package/dist/migrate/ddl/mssqlTableDdl.js +4 -1
  57. package/dist/migrate/ddl/mysqlTableDdl.d.ts +17 -0
  58. package/dist/migrate/ddl/mysqlTableDdl.js +33 -0
  59. package/dist/migrate/ddl/pgTableDdl.d.ts +7 -0
  60. package/dist/migrate/ddl/pgTableDdl.js +17 -0
  61. package/dist/migrate/ddl/tableDdl.d.ts +15 -10
  62. package/dist/migrate/ddl/tableDdl.js +31 -32
  63. package/dist/migrate/drift/driftDetector.js +46 -59
  64. package/dist/migrate/generator/definitionToNode.d.ts +11 -7
  65. package/dist/migrate/generator/definitionToNode.js +27 -34
  66. package/dist/migrate/generator/indexNodeToSchema.d.ts +3 -3
  67. package/dist/migrate/generator/indexNodeToSchema.js +5 -4
  68. package/dist/migrate/index.js +1 -1
  69. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +10 -5
  70. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +10 -0
  71. package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -1
  72. package/dist/migrate/introspection/baseSqlIntrospector.js +6 -8
  73. package/dist/migrate/introspection/mssqlIntrospector.js +3 -8
  74. package/dist/migrate/introspection/mysqlIntrospector.d.ts +11 -4
  75. package/dist/migrate/introspection/mysqlIntrospector.js +25 -11
  76. package/dist/migrate/introspection/postgresIntrospector.d.ts +2 -2
  77. package/dist/migrate/introspection/postgresIntrospector.js +3 -3
  78. package/dist/migrate/introspection/sqliteIntrospector.d.ts +1 -1
  79. package/dist/migrate/introspection/sqliteIntrospector.js +7 -10
  80. package/dist/migrate/migrationTarget.js +3 -3
  81. package/dist/migrate/schemaGenerator.d.ts +8 -12
  82. package/dist/migrate/schemaGenerator.js +35 -61
  83. package/dist/migrate/triggerSql.d.ts +1 -1
  84. package/dist/migrate/triggerSql.js +8 -6
  85. package/dist/mongo/mongoDialect.d.ts +4 -3
  86. package/dist/mongo/mongoDialect.js +52 -38
  87. package/dist/mongo/mongoIntrospector.js +1 -1
  88. package/dist/mongo/mongoSchemaGenerator.d.ts +7 -4
  89. package/dist/mongo/mongoSchemaGenerator.js +18 -21
  90. package/dist/mongo/mongodbQuerier.d.ts +2 -3
  91. package/dist/mongo/mongodbQuerier.js +9 -28
  92. package/dist/mssql/mssqlDialect.d.ts +4 -5
  93. package/dist/mssql/mssqlDialect.js +9 -7
  94. package/dist/postgres/postgresDialect.js +2 -2
  95. package/dist/querier/abstractQuerier.d.ts +16 -11
  96. package/dist/querier/abstractQuerier.js +74 -26
  97. package/dist/querier/abstractQuerierPool.d.ts +26 -24
  98. package/dist/querier/abstractQuerierPool.js +26 -64
  99. package/dist/querier/abstractSqlQuerier.d.ts +2 -3
  100. package/dist/querier/abstractSqlQuerier.js +8 -26
  101. package/dist/querier/cursor.d.ts +10 -0
  102. package/dist/querier/cursor.js +81 -0
  103. package/dist/querier/keyset.d.ts +19 -0
  104. package/dist/querier/keyset.js +198 -0
  105. package/dist/schema/canonicalType.d.ts +3 -3
  106. package/dist/schema/canonicalType.js +13 -12
  107. package/dist/schema/indexDifferences.d.ts +14 -7
  108. package/dist/schema/indexDifferences.js +7 -5
  109. package/dist/schema/schemaAST.d.ts +0 -1
  110. package/dist/schema/schemaAST.js +0 -2
  111. package/dist/schema/schemaASTBuilder.js +28 -20
  112. package/dist/schema/schemaASTDiffer.d.ts +7 -9
  113. package/dist/schema/schemaASTDiffer.js +54 -107
  114. package/dist/schema/sqlExpression.d.ts +22 -0
  115. package/dist/schema/sqlExpression.js +28 -0
  116. package/dist/schema/types.d.ts +48 -105
  117. package/dist/sqlite/sqliteDialect.d.ts +9 -13
  118. package/dist/sqlite/sqliteDialect.js +10 -29
  119. package/dist/type/dialect.d.ts +20 -3
  120. package/dist/type/entity.d.ts +3 -3
  121. package/dist/type/migration.d.ts +7 -7
  122. package/dist/type/querier.d.ts +19 -26
  123. package/dist/type/query.d.ts +104 -24
  124. package/dist/type/query.js +21 -28
  125. package/dist/type/universalQuerier.d.ts +31 -5
  126. package/dist/type/utility.d.ts +10 -0
  127. package/dist/util/bytes.d.ts +7 -0
  128. package/dist/util/bytes.js +22 -0
  129. package/dist/util/date.d.ts +5 -0
  130. package/dist/util/date.js +5 -0
  131. package/dist/util/dialect.util.d.ts +1 -25
  132. package/dist/util/dialect.util.js +4 -50
  133. package/dist/util/field.util.d.ts +9 -0
  134. package/dist/util/field.util.js +15 -0
  135. package/dist/util/fieldOption.util.js +2 -2
  136. package/dist/util/index.d.ts +1 -0
  137. package/dist/util/index.js +1 -0
  138. package/dist/util/object.util.d.ts +0 -2
  139. package/dist/util/object.util.js +0 -7
  140. package/dist/util/query.util.d.ts +40 -0
  141. package/dist/util/query.util.js +76 -0
  142. package/dist/util/raw.d.ts +5 -0
  143. package/dist/util/raw.js +5 -0
  144. package/dist/util/relationQuery.util.js +18 -16
  145. package/dist/util/rowKey.util.js +2 -3
  146. package/dist/util/sql.util.d.ts +8 -2
  147. package/dist/util/sql.util.js +16 -17
  148. package/dist/util/sqlLiteral.js +2 -12
  149. package/dist/util/string.util.d.ts +5 -0
  150. package/dist/util/string.util.js +12 -0
  151. package/package.json +1 -1
  152. package/skills/uql-orm/SKILL.md +21 -10
  153. package/dist/browser/options.d.ts +0 -4
  154. package/dist/browser/options.js +0 -13
  155. package/dist/browser/type/clientQuerierPool.d.ts +0 -4
  156. package/dist/browser/type/clientQuerierPool.js +0 -1
@@ -1,4 +1,5 @@
1
1
  import { type ColumnFamily, type DdlRenderOptions, type EntityData, type EntityMeta, type EntityWhereMeta, type FieldKey, type FieldOptions, type IsolationLevel, type JsonColumnType, type JsonUpdateOp, type Query, type QueryAggMap, type QueryAggregate, type QueryBuildFn, type QueryComparisonOptions, type QueryConflictPaths, type QueryContext, type QueryContextOptions, type QueryExclude, type QueryGroupMap, type QueryGroupOp, type QueryHavingMap, type QueryRenderOptions, type QueryPage, type QueryPager, QueryRaw, type QueryRawFnOptions, type QuerySearch, type QuerySelectValue, type QuerySizeComparisonOps, type QueryTextSearchOptions, type QueryWhere, type QueryWhereArray, type QueryWhereFieldOp, type QueryWhereOptions, type RelationAggregateSpec, type RelationMeta, type SqlDialectName, type SqlQueryDialect, type TriggerRows, type TriggerWrite, type Type, type UpdatePayload } from '../type/index.js';
2
+ import { type SortDirection } from '../util/index.js';
2
3
  import type { HydrateKind } from './hydrateColumn.js';
3
4
  import { type JsonAccessMode, type JsonSlot } from './jsonSql.js';
4
5
  import { type QueryJoins, type QuerySortOptions } from './queryJoins.js';
@@ -16,11 +17,8 @@ type InsertShape<E> = {
16
17
  };
17
18
  /** One entry of {@link AbstractSqlDialect.hydratableFields}: a field key and how it decodes. */
18
19
  type HydratableField = readonly [string, HydrateKind];
19
- /** A direction as a statement writes it: the suffix, and where the caller asked nulls to land. */
20
- type SortOrder = {
21
- readonly direction?: string;
22
- readonly nulls?: 'first' | 'last';
23
- };
20
+ /** A sort term's direction. A vector distance has none: it always ranks nearest first. */
21
+ type SortOrder = Partial<SortDirection>;
24
22
  /** A sort term of a relation's rows as their aggregate orders by it: the column carrying it out. */
25
23
  export type SortRef = SortOrder & {
26
24
  readonly ref: string;
@@ -94,10 +92,9 @@ export declare abstract class AbstractSqlDialect extends VectorSqlDialect implem
94
92
  * `SqlDialectFeatures.serialDeclaresPrimaryKey`.
95
93
  */
96
94
  abstract readonly autoIncrementSuffix: string;
97
- abstract readonly tableOptions: string;
98
- abstract readonly beginTransactionCommand: string;
99
- abstract readonly commitTransactionCommand: string;
100
- abstract readonly rollbackTransactionCommand: string;
95
+ readonly beginTransactionCommand: string;
96
+ readonly commitTransactionCommand: string;
97
+ readonly rollbackTransactionCommand: string;
101
98
  /**
102
99
  * How this engine declares a namespace, so a generated migration creates the schemas its tables
103
100
  * need before creating them. Only reached where {@link DialectFeatures.schemas} is on. MySQL and
@@ -105,16 +102,8 @@ export declare abstract class AbstractSqlDialect extends VectorSqlDialect implem
105
102
  */
106
103
  createSchemaSql(schema: string): string;
107
104
  readonly isolationLevelStrategy: 'inline' | 'set-before' | 'none';
108
- readonly alterColumnStrategy: 'separate-clauses' | 'single-statement';
109
- readonly alterColumnSyntax: 'ALTER COLUMN' | 'MODIFY COLUMN';
110
- readonly dropForeignKeySyntax: 'DROP CONSTRAINT' | 'DROP FOREIGN KEY';
111
- /**
112
- * `DROP CONSTRAINT <name>` where a primary key is a named constraint like any other; MySQL spells
113
- * it `DROP PRIMARY KEY` and takes no name, since a table's key is always called `PRIMARY` there.
114
- */
115
- readonly dropPrimaryKeySyntax: 'DROP CONSTRAINT' | 'DROP PRIMARY KEY';
116
- readonly dropIndexSyntax: 'on-table' | 'standalone';
117
105
  readonly booleanLiteral: 'native' | 'integer';
106
+ readonly currentTimestamp: string;
118
107
  /**
119
108
  * Maximum number of bind parameters the driver accepts in a single statement.
120
109
  * `insertMany` splits larger batches into multiple statements based on this limit.
@@ -140,10 +129,12 @@ export declare abstract class AbstractSqlDialect extends VectorSqlDialect implem
140
129
  */
141
130
  protected renderOperands<T>(ctx: QueryContext, operands: readonly T[], render: (ctx: QueryContext, operand: T) => void): string[];
142
131
  addValue(ctx: QueryContext, value: unknown): string;
132
+ /** When set, a `Date` binds as UTC text with this zone suffix (`''` for none). Unset, the driver gets the `Date`. */
133
+ protected readonly dateZone?: string;
143
134
  /**
144
- * A parameter value as this engine's driver takes it: a boolean as the integer an engine with no
145
- * boolean type stores, and everything else as it is - a `bigint` included, which every driver here
146
- * binds exactly, where a number would round it past 2^53. A driver that refuses one (D1) overrides.
135
+ * Converts a parameter value to what this engine's driver takes: a `Date` per {@link dateZone}, a boolean to
136
+ * 1/0 on an engine with no boolean type, and anything else unchanged. A `bigint` passes as is, since every
137
+ * driver here binds it exactly where a number would round past 2^53; a driver that refuses one (D1) overrides.
147
138
  */
148
139
  normalizeValue(value: unknown): unknown;
149
140
  /**
@@ -369,6 +360,8 @@ export declare abstract class AbstractSqlDialect extends VectorSqlDialect implem
369
360
  * value. An engine that orders JSON as text reads a number first, then the text.
370
361
  */
371
362
  protected readonly jsonSortModes: readonly JsonAccessMode[];
363
+ /** The `LIMIT` meaning all rows, for an engine that accepts an `OFFSET` only after a `LIMIT`. */
364
+ protected readonly unboundedLimit?: string;
372
365
  /**
373
366
  * `LIMIT`/`OFFSET`. `sorted` says whether an `ORDER BY` was emitted just before, which
374
367
  * {@link MergeSqlDialect} needs: SQL Server refuses to page a statement that has none.
@@ -423,13 +416,12 @@ export declare abstract class AbstractSqlDialect extends VectorSqlDialect implem
423
416
  /** The SQL referencing one of an aggregate's emitted columns, rejecting any other name. */
424
417
  private aggregateRef;
425
418
  protected having(ctx: QueryContext, having: QueryHavingMap, emittedColumns: Record<string, string>): void;
426
- private resolveSortDirection;
427
419
  /**
428
420
  * One `ORDER BY` term. A placement the engine has no `NULLS FIRST/LAST` for becomes a term of its
429
421
  * own in front of it, which is why one is only ever emitted where the caller asked for it: no index
430
422
  * serves an expression. SQL Server needs a `CASE`, having no orderable boolean.
431
423
  */
432
- protected orderByTerm(expr: string, { direction, nulls }: SortOrder): string;
424
+ protected orderByTerm(expr: string, { desc, nulls }: SortOrder): string;
433
425
  /** Every operator of one `HAVING` condition, `AND`-joined. */
434
426
  protected havingCondition(ctx: QueryContext, expr: string, condition: QueryHavingMap[string]): void;
435
427
  /**
@@ -448,6 +440,11 @@ export declare abstract class AbstractSqlDialect extends VectorSqlDialect implem
448
440
  * another table of the statement took it first.
449
441
  */
450
442
  private readOptions;
443
+ /**
444
+ * The clause that returns the written ids, shared by every insert and upsert. It is `''` on an engine whose
445
+ * statement cannot return them, and on a composite key, which has no id to ask for.
446
+ */
447
+ protected insertedIdReturning<E>(meta: EntityMeta<E>): string;
451
448
  insert<E>(ctx: QueryContext, entity: Type<E>, payload: E | E[], opts?: QueryRenderOptions): void;
452
449
  /**
453
450
  * What a text search matches and a fulltext index covers, which have to agree for the index to serve the
@@ -566,12 +563,12 @@ export declare abstract class AbstractSqlDialect extends VectorSqlDialect implem
566
563
  protected jsonArrayOf(elem: string): string;
567
564
  /** Whether an element is not the pulled value, both read as JSON. */
568
565
  protected jsonDiffers(elem: string, operand: string): string;
569
- /** Shallow assignment of top-level keys, matching PostgreSQL's `jsonb || jsonb`. */
570
- protected abstract jsonSet(ctx: QueryContext, expr: string, set: Record<string, unknown>, field?: FieldOptions): string;
566
+ /** Shallow assignment of top-level keys, matching PostgreSQL's `jsonb || jsonb`, through `JSON_SET`. */
567
+ protected jsonSet(ctx: QueryContext, expr: string, set: Record<string, unknown>, field?: FieldOptions): string;
571
568
  /** Append one value per array key, creating the array when the key is absent. */
572
569
  protected abstract jsonPush(ctx: QueryContext, expr: string, push: Record<string, unknown>): string;
573
- /** Remove object keys. */
574
- protected abstract jsonUnset(ctx: QueryContext, expr: string, unset: readonly string[]): string;
570
+ /** Remove object keys, through `JSON_REMOVE`. */
571
+ protected jsonUnset(_ctx: QueryContext, expr: string, unset: readonly string[]): string;
575
572
  /**
576
573
  * The text of SQL a schema declares, as DDL carries it: values written as literals, and none left bound,
577
574
  * since a `CREATE` statement has no placeholder to bind one into. An entity's SQL reads its fields, a
@@ -700,7 +697,6 @@ export declare abstract class AbstractSqlDialect extends VectorSqlDialect implem
700
697
  private vectorNearCondition;
701
698
  /** ANSI-style single-quote escaping. */
702
699
  escape(value: unknown): string;
703
- protected get regexpOp(): string;
704
700
  /**
705
701
  * The `$regex` predicate. An infix operator on the MySQL family (`REGEXP`) and the Postgres one
706
702
  * (`~`), but a function on Oracle and SQL Server 2025 (`REGEXP_LIKE(col, ?)`) - which is why this
@@ -1,11 +1,12 @@
1
1
  import { fieldOf, getMeta, relationOf, soleIdOf } from '../entity/index.js';
2
2
  import { COUNT_RESULT_KEY, parseQueryLock, QueryRaw, RAW_ALIAS, } from '../type/index.js';
3
+ import { utcTimestamp } from '../util/date.js';
3
4
  import { isInlinedExpression } from '../util/field.util.js';
4
- import { isSelectList, assertNonNegativeInteger, assertWhere, definedEntries, escapeSqlId, fillOnFields, filterFieldKeys, getInsertFieldKeys, getKeys, getRelationRequestSummary, getSoftDeleteValue, hasKeys, idOnlyQuery, columnFamily, countedRelations, fieldUpdateOf, fulltextIndexOver, fulltextWeights, isFieldUpdateOp, isJsonObject, isJsonUpdateOp, isOperatorMap, isOperatorKey, isVectorSearch, normalizeScalarFieldSelection, parentJoins, rankedTextSearch, targetKeyColumns, textSearchFields, textSortOf, textWeightSteps, parseGroupMap, parseRelationAtKey, parseRelationSize, populatesRelations, aggregateOf, raw, refs, throwUnknownAggregateColumn, withoutSoftDeleteFilter, } from '../util/index.js';
5
+ import { isSelectList, assertNonNegativeInteger, assertWhere, definedEntries, escapeSqlId, fillOnFields, filterFieldKeys, getInsertFieldKeys, getKeys, getRelationRequestSummary, getSoftDeleteValue, hasKeys, idOnlyQuery, whereAnd, columnFamily, fieldFamily, countedRelations, fieldUpdateOf, fulltextIndexOver, fulltextWeights, isFieldUpdateOp, isJsonObject, isJsonUpdateOp, isOperatorMap, isOperatorKey, isVectorSearch, normalizeScalarFieldSelection, parentJoins, rankedTextSearch, targetKeyColumns, textSearchFields, textSortOf, textWeightSteps, parseGroupMap, parseRelationAtKey, parseRelationSize, parseSortDirection, populatesRelations, aggregateOf, raw, refs, throwUnknownAggregateColumn, withoutSoftDeleteFilter, } from '../util/index.js';
5
6
  import { escapeAnsiSqlLiteral } from '../util/sqlLiteral.js';
6
7
  import { kindOf, UqlUsageError } from '../util/uqlError.js';
7
8
  import { AGGREGATE_PAGE_ALIAS, AGGREGATE_VALUE_ALIAS, ROWS_ALIAS, JSON_ELEM_ALIAS, JSON_PULL_ALIAS, relationSortColumn, } from './aliases.js';
8
- import { holdsOperator, isJsonScalar, jsonCompareMode, jsonElemExists, jsonPath, } from './jsonSql.js';
9
+ import { holdsOperator, isJsonScalar, jsonCompareMode, jsonElemExists, jsonPath, jsonRemoveCall, jsonSetCall, jsonSetTarget, } from './jsonSql.js';
9
10
  import { betweenBounds, COMPARE_OPS, EQUALITY_OPS, GROUP_OPS, groupClauses, inOperands, isGroupOp, isOrderedOp, isVectorQuery, LIKE_OPS, namesRows, ORDERED_OPS, VECTOR_QUERY_KEY_SET, whereOperators, } from './operators.js';
10
11
  import { SqlQueryContext } from './queryContext.js';
11
12
  import { groupPathField, NO_JOINS, aggregateColumnField, resolveGroupJoins, resolveQueryJoins, relationSortTerms, resolveSortableJoin, } from './queryJoins.js';
@@ -70,21 +71,14 @@ const AGGREGATE_FN = {
70
71
  $min: 'MIN',
71
72
  $max: 'MAX',
72
73
  };
73
- const SORT_DIRECTION_MAP = new Map([
74
- [1, {}],
75
- ['asc', {}],
76
- ['desc', { direction: ' DESC' }],
77
- [-1, { direction: ' DESC' }],
78
- ['ascNullsFirst', { nulls: 'first' }],
79
- ['ascNullsLast', { nulls: 'last' }],
80
- ['descNullsFirst', { direction: ' DESC', nulls: 'first' }],
81
- ['descNullsLast', { direction: ' DESC', nulls: 'last' }],
82
- ]);
83
74
  export class AbstractSqlDialect extends VectorSqlDialect {
84
75
  /** Itself, unless the engine is a fork running another's SQL, which is the only case that overrides. */
85
76
  get dialectFamily() {
86
77
  return this.dialectName;
87
78
  }
79
+ beginTransactionCommand = 'BEGIN';
80
+ commitTransactionCommand = 'COMMIT';
81
+ rollbackTransactionCommand = 'ROLLBACK';
88
82
  /**
89
83
  * How this engine declares a namespace, so a generated migration creates the schemas its tables
90
84
  * need before creating them. Only reached where {@link DialectFeatures.schemas} is on. MySQL and
@@ -94,16 +88,8 @@ export class AbstractSqlDialect extends VectorSqlDialect {
94
88
  return `CREATE SCHEMA IF NOT EXISTS ${this.escapeId(schema, true)}`;
95
89
  }
96
90
  isolationLevelStrategy = 'inline';
97
- alterColumnStrategy = 'single-statement';
98
- alterColumnSyntax = 'ALTER COLUMN';
99
- dropForeignKeySyntax = 'DROP CONSTRAINT';
100
- /**
101
- * `DROP CONSTRAINT <name>` where a primary key is a named constraint like any other; MySQL spells
102
- * it `DROP PRIMARY KEY` and takes no name, since a table's key is always called `PRIMARY` there.
103
- */
104
- dropPrimaryKeySyntax = 'DROP CONSTRAINT';
105
- dropIndexSyntax = 'standalone';
106
91
  booleanLiteral = 'native';
92
+ currentTimestamp = 'CURRENT_TIMESTAMP';
107
93
  /**
108
94
  * Maximum number of bind parameters the driver accepts in a single statement.
109
95
  * `insertMany` splits larger batches into multiple statements based on this limit.
@@ -161,12 +147,17 @@ export class AbstractSqlDialect extends VectorSqlDialect {
161
147
  ctx.values.push(this.normalizeValue(value));
162
148
  return this.placeholder(ctx.values.length);
163
149
  }
150
+ /** When set, a `Date` binds as UTC text with this zone suffix (`''` for none). Unset, the driver gets the `Date`. */
151
+ dateZone;
164
152
  /**
165
- * A parameter value as this engine's driver takes it: a boolean as the integer an engine with no
166
- * boolean type stores, and everything else as it is - a `bigint` included, which every driver here
167
- * binds exactly, where a number would round it past 2^53. A driver that refuses one (D1) overrides.
153
+ * Converts a parameter value to what this engine's driver takes: a `Date` per {@link dateZone}, a boolean to
154
+ * 1/0 on an engine with no boolean type, and anything else unchanged. A `bigint` passes as is, since every
155
+ * driver here binds it exactly where a number would round past 2^53; a driver that refuses one (D1) overrides.
168
156
  */
169
157
  normalizeValue(value) {
158
+ if (value instanceof Date && this.dateZone !== undefined) {
159
+ return utcTimestamp(value, this.dateZone);
160
+ }
170
161
  if (typeof value === 'boolean' && this.booleanLiteral !== 'native') {
171
162
  return value ? 1 : 0;
172
163
  }
@@ -839,7 +830,7 @@ export class AbstractSqlDialect extends VectorSqlDialect {
839
830
  // Where projected in the SELECT list, ordered by that alias rather than scored twice.
840
831
  const { order, project } = textSortOf(sort);
841
832
  const expr = project ? this.escapeId(project) : this.buildFragment(ctx, opts.rankText);
842
- columns.push({ key, expr, ...this.resolveSortDirection(order), output: project !== undefined });
833
+ columns.push({ key, expr, ...parseSortDirection(order), output: project !== undefined });
843
834
  continue;
844
835
  }
845
836
  if (relation) {
@@ -856,7 +847,7 @@ export class AbstractSqlDialect extends VectorSqlDialect {
856
847
  vectors.push({ key: name, expr, output: false });
857
848
  }
858
849
  else {
859
- columns.push({ key: keyPath, expr, ...this.resolveSortDirection(direction), output: false });
850
+ columns.push({ key: keyPath, expr, ...parseSortDirection(direction), output: false });
860
851
  }
861
852
  }
862
853
  if (rest === undefined) {
@@ -882,7 +873,7 @@ export class AbstractSqlDialect extends VectorSqlDialect {
882
873
  });
883
874
  continue;
884
875
  }
885
- const order = this.resolveSortDirection(value);
876
+ const order = parseSortDirection(value);
886
877
  // A JSON path can sort by more than one reading, each carried under a name of its own.
887
878
  this.sortColumns(ctx, meta, key, prefix).forEach((column, index) => {
888
879
  columns.push({ key: index ? `${keyPath}:${index}` : keyPath, ...column, ...order });
@@ -915,6 +906,8 @@ export class AbstractSqlDialect extends VectorSqlDialect {
915
906
  * value. An engine that orders JSON as text reads a number first, then the text.
916
907
  */
917
908
  jsonSortModes = ['json'];
909
+ /** The `LIMIT` meaning all rows, for an engine that accepts an `OFFSET` only after a `LIMIT`. */
910
+ unboundedLimit;
918
911
  /**
919
912
  * `LIMIT`/`OFFSET`. `sorted` says whether an `ORDER BY` was emitted just before, which
920
913
  * {@link MergeSqlDialect} needs: SQL Server refuses to page a statement that has none.
@@ -924,6 +917,9 @@ export class AbstractSqlDialect extends VectorSqlDialect {
924
917
  if (opts.$limit !== undefined) {
925
918
  ctx.append(` LIMIT ${assertNonNegativeInteger(opts.$limit, '$limit')}`);
926
919
  }
920
+ else if (opts.$skip !== undefined && this.unboundedLimit) {
921
+ ctx.append(` LIMIT ${this.unboundedLimit}`);
922
+ }
927
923
  if (opts.$skip !== undefined) {
928
924
  ctx.append(` OFFSET ${assertNonNegativeInteger(opts.$skip, '$skip')}`);
929
925
  }
@@ -1093,7 +1089,7 @@ export class AbstractSqlDialect extends VectorSqlDialect {
1093
1089
  Object.entries(sort).forEach(([key, dir], index) => {
1094
1090
  if (index > 0)
1095
1091
  ctx.append(', ');
1096
- ctx.append(this.orderByTerm(this.aggregateRef(emittedColumns, key, '$sort'), this.resolveSortDirection(dir)));
1092
+ ctx.append(this.orderByTerm(this.aggregateRef(emittedColumns, key, '$sort'), parseSortDirection(dir)));
1097
1093
  });
1098
1094
  return true;
1099
1095
  }
@@ -1114,16 +1110,13 @@ export class AbstractSqlDialect extends VectorSqlDialect {
1114
1110
  this.havingCondition(ctx, this.aggregateRef(emittedColumns, alias, '$having'), condition);
1115
1111
  });
1116
1112
  }
1117
- resolveSortDirection(sort) {
1118
- const order = SORT_DIRECTION_MAP.get(sort);
1119
- return orRefuse(order, `unknown sort direction: ${sort}`);
1120
- }
1121
1113
  /**
1122
1114
  * One `ORDER BY` term. A placement the engine has no `NULLS FIRST/LAST` for becomes a term of its
1123
1115
  * own in front of it, which is why one is only ever emitted where the caller asked for it: no index
1124
1116
  * serves an expression. SQL Server needs a `CASE`, having no orderable boolean.
1125
1117
  */
1126
- orderByTerm(expr, { direction = '', nulls }) {
1118
+ orderByTerm(expr, { desc, nulls }) {
1119
+ const direction = desc ? ' DESC' : '';
1127
1120
  if (!nulls) {
1128
1121
  return expr + direction;
1129
1122
  }
@@ -1177,11 +1170,15 @@ export class AbstractSqlDialect extends VectorSqlDialect {
1177
1170
  const alias = ctx.claimAlias(name);
1178
1171
  return alias === name ? opts : { ...opts, alias };
1179
1172
  }
1173
+ /**
1174
+ * The clause that returns the written ids, shared by every insert and upsert. It is `''` on an engine whose
1175
+ * statement cannot return them, and on a composite key, which has no id to ask for.
1176
+ */
1177
+ insertedIdReturning(meta) {
1178
+ return this.insertIdSource === 'returning' ? this.returningId(meta) : '';
1179
+ }
1180
1180
  insert(ctx, entity, payload, opts) {
1181
- // Every engine whose ids come back from the statement itself wants the same clause, so it is
1182
- // built once here instead of in an identical `insert` override per dialect. `returningId` is
1183
- // empty on a composite key, which has no id to ask for.
1184
- const returning = this.insertIdSource === 'returning' ? this.returningId(getMeta(entity)) : '';
1181
+ const returning = this.insertedIdReturning(getMeta(entity));
1185
1182
  if (returning && this.returningPosition === 'after-target') {
1186
1183
  this.appendInsertValues(ctx, entity, payload, returning);
1187
1184
  return;
@@ -1380,7 +1377,7 @@ export class AbstractSqlDialect extends VectorSqlDialect {
1380
1377
  const keys = this.getUpsertConflictPathsStr(meta, conflictPaths);
1381
1378
  const onConflict = update ? `DO UPDATE SET ${update}` : 'DO NOTHING';
1382
1379
  // Composed rather than concatenated: a composite key contributes no id item, and a dialect's own
1383
- // item (Postgres's `_created`) still has to be the *first* thing after the keyword when it is.
1380
+ // item (Postgres's created flag) must then come right after the keyword, with no comma before it.
1384
1381
  const returning = [this.returningIdExpression(meta), extraReturning].filter(Boolean).join(', ');
1385
1382
  this.appendInsertValues(ctx, entity, payload);
1386
1383
  ctx.append(` ON CONFLICT (${keys}) ${onConflict}${returning ? ` RETURNING ${returning}` : ''}`);
@@ -1618,6 +1615,14 @@ export class AbstractSqlDialect extends VectorSqlDialect {
1618
1615
  jsonDiffers(elem, operand) {
1619
1616
  return `${elem} <> ${operand}`;
1620
1617
  }
1618
+ /** Shallow assignment of top-level keys, matching PostgreSQL's `jsonb || jsonb`, through `JSON_SET`. */
1619
+ jsonSet(ctx, expr, set, field) {
1620
+ return jsonSetCall((value) => this.jsonScalarParam(ctx, value), jsonSetTarget(expr, field, `'{}'`), set, this.maxFunctionArgs);
1621
+ }
1622
+ /** Remove object keys, through `JSON_REMOVE`. */
1623
+ jsonUnset(_ctx, expr, unset) {
1624
+ return jsonRemoveCall(expr, unset, this.maxFunctionArgs);
1625
+ }
1621
1626
  compileDdl(sql, entity, { rows, escapedPrefix, operand } = {}) {
1622
1627
  const ctx = this.createContext({ inlineValues: true });
1623
1628
  if (sql instanceof QueryRaw) {
@@ -1785,7 +1790,7 @@ export class AbstractSqlDialect extends VectorSqlDialect {
1785
1790
  const query = {
1786
1791
  ...page,
1787
1792
  $select: [read.as(AGGREGATE_VALUE_ALIAS)],
1788
- $where: { ...$where, $and: [...($where?.$and ?? []), correlation] },
1793
+ $where: whereAnd($where, [correlation]),
1789
1794
  };
1790
1795
  const joins = resolveQueryJoins(getMeta(entity), query, (path) => ctx.claimAlias(path));
1791
1796
  this.read(ctx, entity, query, { alias }, joins);
@@ -1839,7 +1844,7 @@ export class AbstractSqlDialect extends VectorSqlDialect {
1839
1844
  this.assertDistinctSort(relMeta, relKey, query);
1840
1845
  const alias = ctx.claimAlias(relKey, parent);
1841
1846
  const correlation = raw(({ ctx: rowsCtx }) => this.appendCorrelation(rowsCtx, meta, relation, parent, alias));
1842
- const rows = { ...query, $where: { ...query.$where, $and: [...(query.$where?.$and ?? []), correlation] } };
1847
+ const rows = { ...query, $where: whereAnd(query.$where, [correlation]) };
1843
1848
  const joins = resolveQueryJoins(relMeta, rows, (path) => ctx.claimAlias(path));
1844
1849
  this.appendRelationArray(ctx, { entity, query: rows, alias, joins, distinct });
1845
1850
  }
@@ -1913,7 +1918,7 @@ export class AbstractSqlDialect extends VectorSqlDialect {
1913
1918
  carriedFields = {};
1914
1919
  /** `expr` as it crosses JSON, by its field's family: see {@link carriedFields}. */
1915
1920
  carried(expr, field) {
1916
- const family = columnFamily(field.columnType ?? field.type);
1921
+ const family = fieldFamily(field);
1917
1922
  return (family && this.carriedFields[family]?.(expr, field)) ?? expr;
1918
1923
  }
1919
1924
  /** `'key', column, ...`: the arguments of a JSON object call over `pairs`. */
@@ -1969,9 +1974,6 @@ export class AbstractSqlDialect extends VectorSqlDialect {
1969
1974
  escape(value) {
1970
1975
  return escapeAnsiSqlLiteral(value);
1971
1976
  }
1972
- get regexpOp() {
1973
- return 'REGEXP';
1974
- }
1975
1977
  /**
1976
1978
  * The `$regex` predicate. An infix operator on the MySQL family (`REGEXP`) and the Postgres one
1977
1979
  * (`~`), but a function on Oracle and SQL Server 2025 (`REGEXP_LIKE(col, ?)`) - which is why this
@@ -1979,7 +1981,7 @@ export class AbstractSqlDialect extends VectorSqlDialect {
1979
1981
  * throw, the way {@link appendTextSearch} already does.
1980
1982
  */
1981
1983
  regexCondition(operand, placeholder) {
1982
- return `${operand} ${this.regexpOp} ${placeholder}`;
1984
+ return `${operand} REGEXP ${placeholder}`;
1983
1985
  }
1984
1986
  /** `operand IN (...)` of each value as `bind` renders it, or the constant an empty set reduces to: no value is in it. */
1985
1987
  formatIn(_ctx, operand, values, negate, bind) {
@@ -32,6 +32,7 @@ export declare const TEXT_SCORE_ALIAS = "_uql_text_score";
32
32
  /**
33
33
  * The field a MongoDB `$sort` placing nulls orders by first: 1 where the value is null or missing, 0
34
34
  * where it is not. MongoDB takes no `NULLS FIRST`, so the placement is this flag plus the sort on it.
35
+ * A dot becomes `_o` and an underscore `__`, so two paths such as `a.b` and `a_b` never share a flag.
35
36
  */
36
37
  export declare function nullsSortField(path: string): string;
37
38
  /** Prefix for the field a MongoDB relation lookup parks its result on, one per condition. */
@@ -41,11 +42,13 @@ export declare const REL_NESTED_KEY = "_uql_target";
41
42
  /**
42
43
  * The alias MySQL's upsert gives the row being inserted, so its `ON DUPLICATE KEY UPDATE`
43
44
  * assignments read `_uql_new.col` instead of the deprecated `VALUES(col)`. MariaDB has no such
44
- * syntax and keeps `VALUES(col)`.
45
+ * syntax and reads `VALUE(col)`.
45
46
  */
46
47
  export declare const UPSERT_NEW_ROW_ALIAS = "_uql_new";
47
48
  /** The row source a `MERGE` upsert reads its incoming values from, on SQL Server and Oracle. */
48
49
  export declare const UPSERT_SOURCE_ALIAS = "_uql_src";
50
+ /** The column a Postgres upsert returns beside the id: `(xmax = 0)`, true when it inserted the row. */
51
+ export declare const UPSERT_CREATED_ALIAS = "_uql_created";
49
52
  /**
50
53
  * Where a `$sort` by a relation's aggregate - its size, or its nearest row - parks the value until the
51
54
  * ordering has run. A function, so the `$sort` that names the field and the stage that produces it cannot
@@ -33,9 +33,10 @@ export const TEXT_SCORE_ALIAS = '_uql_text_score';
33
33
  /**
34
34
  * The field a MongoDB `$sort` placing nulls orders by first: 1 where the value is null or missing, 0
35
35
  * where it is not. MongoDB takes no `NULLS FIRST`, so the placement is this flag plus the sort on it.
36
+ * A dot becomes `_o` and an underscore `__`, so two paths such as `a.b` and `a_b` never share a flag.
36
37
  */
37
38
  export function nullsSortField(path) {
38
- return `_uql_nulls_${path.replace(/\./g, '_')}`;
39
+ return `_uql_nulls_${path.replace(/[._]/g, (char) => (char === '.' ? '_o' : '__'))}`;
39
40
  }
40
41
  /** Prefix for the field a MongoDB relation lookup parks its result on, one per condition. */
41
42
  export const REL_TEMP_PREFIX = '_uql_rel_';
@@ -44,11 +45,13 @@ export const REL_NESTED_KEY = '_uql_target';
44
45
  /**
45
46
  * The alias MySQL's upsert gives the row being inserted, so its `ON DUPLICATE KEY UPDATE`
46
47
  * assignments read `_uql_new.col` instead of the deprecated `VALUES(col)`. MariaDB has no such
47
- * syntax and keeps `VALUES(col)`.
48
+ * syntax and reads `VALUE(col)`.
48
49
  */
49
50
  export const UPSERT_NEW_ROW_ALIAS = '_uql_new';
50
51
  /** The row source a `MERGE` upsert reads its incoming values from, on SQL Server and Oracle. */
51
52
  export const UPSERT_SOURCE_ALIAS = '_uql_src';
53
+ /** The column a Postgres upsert returns beside the id: `(xmax = 0)`, true when it inserted the row. */
54
+ export const UPSERT_CREATED_ALIAS = '_uql_created';
52
55
  /**
53
56
  * Where a `$sort` by a relation's aggregate - its size, or its nearest row - parks the value until the
54
57
  * ordering has run. A function, so the `$sort` that names the field and the stage that produces it cannot
@@ -1,3 +1,4 @@
1
+ import { hexToBytes } from '../util/bytes.js';
1
2
  import { decodeDate } from '../util/date.js';
2
3
  import { decodeWideNumber } from '../util/wideNumber.js';
3
4
  import { decodeFloat32s, parseVectorLiteral } from './vectorCast.js';
@@ -18,7 +19,7 @@ function fromText(decode) {
18
19
  /** A vector's text in the literal its cast writes, or its packed float32s in hex, which MariaDB reads. */
19
20
  function vectorDecoder(cast) {
20
21
  return fromText((text, value) => text.startsWith(BYTES_PREFIX)
21
- ? decodeFloat32s(hexBytes(text.slice(BYTES_PREFIX.length)))
22
+ ? decodeFloat32s(hexToBytes(text.slice(BYTES_PREFIX.length)))
22
23
  : (parseVectorLiteral(text, cast) ?? value));
23
24
  }
24
25
  const denseVector = vectorDecoder('vector');
@@ -34,7 +35,7 @@ const DECODERS = {
34
35
  boolean: (value) => (typeof value === 'boolean' ? value : Boolean(value)),
35
36
  date: (value) => (typeof value === 'string' ? decodeDate(value) : value),
36
37
  // Only a string can be bytes that crossed JSON: bytes a driver already decoded stay as they are.
37
- bytes: (value) => typeof value === 'string' && value.startsWith(BYTES_PREFIX) ? hexBytes(value.slice(BYTES_PREFIX.length)) : value,
38
+ bytes: (value) => typeof value === 'string' && value.startsWith(BYTES_PREFIX) ? hexToBytes(value.slice(BYTES_PREFIX.length)) : value,
38
39
  // A number too, not just text: `type: BigInt` is BIGINT, which the pg pools decode at the wire.
39
40
  bigint: (value) => {
40
41
  if (typeof value === 'bigint') {
@@ -67,14 +68,6 @@ const DECODERS = {
67
68
  * which every dialect spells, so a string a driver reads from a column on its own is never mistaken.
68
69
  */
69
70
  export const BYTES_PREFIX = '\\x';
70
- /** Two hex digits per byte, back to bytes. */
71
- function hexBytes(hex) {
72
- const bytes = new Uint8Array(hex.length / 2);
73
- for (let at = 0; at < bytes.length; at++) {
74
- bytes[at] = Number.parseInt(hex.slice(at * 2, at * 2 + 2), 16);
75
- }
76
- return bytes;
77
- }
78
71
  /** Lazy so a consumer that never reads an encoded column never constructs one. */
79
72
  let decoder;
80
73
  /** The text a driver returned, bytes included (`bun:sql` hands a MySQL decimal as a `Buffer`), or `undefined`. */
@@ -30,7 +30,10 @@ export declare function chainedCall(fn: string, target: string, groups: readonly
30
30
  * appends an accessor per key (SQLite's `[#]` append). Values bind in key order through `bindValue`.
31
31
  */
32
32
  export declare function jsonSetCall(bindValue: (value: unknown) => string, target: string, entries: Record<string, unknown>, maxArgs: number, pathSuffix?: string): string;
33
- /** The `$set` target: a nullable column needs a `COALESCE` fallback to build on. */
33
+ /**
34
+ * The target a `$set` builds on. A nullable column gets a `COALESCE` fallback; a NOT NULL one goes in bare,
35
+ * which keeps MySQL's partial in-place JSON update, since that needs the column itself as `JSON_SET`'s input.
36
+ */
34
37
  export declare function jsonSetTarget(expr: string, field: FieldOptions | undefined, empty: string): string;
35
38
  /** `JSON_REMOVE(expr, path, ...)`, which MySQL and SQLite share, nested past `maxArgs`. */
36
39
  export declare function jsonRemoveCall(expr: string, keys: readonly string[], maxArgs: number): string;
@@ -47,7 +47,10 @@ export function jsonSetCall(bindValue, target, entries, maxArgs, pathSuffix = ''
47
47
  const pairs = Object.entries(entries).map(([key, value]) => `${jsonPath(key, pathSuffix)}, ${bindValue(value)}`);
48
48
  return chainedCall('JSON_SET', target, pairs, 2, maxArgs);
49
49
  }
50
- /** The `$set` target: a nullable column needs a `COALESCE` fallback to build on. */
50
+ /**
51
+ * The target a `$set` builds on. A nullable column gets a `COALESCE` fallback; a NOT NULL one goes in bare,
52
+ * which keeps MySQL's partial in-place JSON update, since that needs the column itself as `JSON_SET`'s input.
53
+ */
51
54
  export function jsonSetTarget(expr, field, empty) {
52
55
  return field?.nullable === false ? expr : `COALESCE(${expr}, ${empty})`;
53
56
  }
@@ -8,10 +8,11 @@ export declare abstract class MergeSqlDialect extends AbstractSqlDialect {
8
8
  $distinct?: boolean;
9
9
  }, sorted?: boolean): void;
10
10
  /**
11
- * `MERGE`, its rows a `VALUES` source built by {@link AbstractSqlDialect.insertShape}. Every value binds
12
- * before the assignments, so `?` placeholders read in order.
11
+ * `MERGE` with its rows as a `VALUES` source built by {@link AbstractSqlDialect.insertShape}. The update
12
+ * assignments bind their values before the rows, though they follow them in the SQL; this works only because
13
+ * SQL Server numbers each placeholder (`@p1`).
13
14
  */
14
- upsert<E>(ctx: QueryContext, entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E | E[], extraReturning?: string): void;
15
+ upsert<E>(ctx: QueryContext, entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E | E[]): void;
15
16
  /** `<target>.<col> = <source>.<col>` for every conflict key, which is what makes a row "the same". */
16
17
  private mergeOn;
17
18
  /**
@@ -21,10 +21,11 @@ export class MergeSqlDialect extends AbstractSqlDialect {
21
21
  }
22
22
  }
23
23
  /**
24
- * `MERGE`, its rows a `VALUES` source built by {@link AbstractSqlDialect.insertShape}. Every value binds
25
- * before the assignments, so `?` placeholders read in order.
24
+ * `MERGE` with its rows as a `VALUES` source built by {@link AbstractSqlDialect.insertShape}. The update
25
+ * assignments bind their values before the rows, though they follow them in the SQL; this works only because
26
+ * SQL Server numbers each placeholder (`@p1`).
26
27
  */
27
- upsert(ctx, entity, conflictPaths, payload, extraReturning = '') {
28
+ upsert(ctx, entity, conflictPaths, payload) {
28
29
  const meta = getMeta(entity);
29
30
  const table = this.escapedTableName(meta);
30
31
  const source = this.escapeId(UPSERT_SOURCE_ALIAS, true);
@@ -41,7 +42,7 @@ export class MergeSqlDialect extends AbstractSqlDialect {
41
42
  ctx.append(` WHEN MATCHED THEN UPDATE SET ${update}`);
42
43
  }
43
44
  ctx.append(` WHEN NOT MATCHED THEN INSERT (${columns}) VALUES (${shape.columns.map((col) => `${source}.${col}`).join(', ')})`);
44
- const returning = [this.returningIdExpression(meta), extraReturning].filter(Boolean).join(', ');
45
+ const returning = this.returningIdExpression(meta);
45
46
  if (returning) {
46
47
  ctx.append(` ${this.mergeReturning(returning)}`);
47
48
  }
@@ -1,9 +1,9 @@
1
- import type { EntityMeta, FieldOptions, InsertIdSource, Query, QueryConflictPaths, QueryContext, QueryOptions, QueryPager, QueryTextSearchOptions, RowLockFeatures, SqlDialectFeatures, SqlDialectName, Type } from '../type/index.js';
1
+ import type { EntityMeta, InsertIdSource, Query, QueryConflictPaths, QueryContext, QueryOptions, QueryTextSearchOptions, RowLockFeatures, SqlDialectFeatures, SqlDialectName, Type } from '../type/index.js';
2
2
  import { AbstractSqlDialect, type DerivedRelation, type RelationRows } from './abstractSqlDialect.js';
3
3
  import { type JsonSlot } from './jsonSql.js';
4
- /** What the MySQL-family engines have. */
5
4
  /** Declared apart so MariaDB, which has no `FOR UPDATE OF`, can restate that one part of it. */
6
5
  export declare const MYSQL_ROW_LOCKS: RowLockFeatures;
6
+ /** The features of MySQL, which MariaDB starts from. */
7
7
  export declare const MYSQL_FEATURES: SqlDialectFeatures;
8
8
  /** What MySQL and MariaDB share, their JSON functions above all: `JSON_LENGTH`, `JSON_CONTAINS`, `JSON_TABLE`, `JSON_SET`. */
9
9
  export declare abstract class MysqlLikeSqlDialect extends AbstractSqlDialect {
@@ -16,29 +16,21 @@ export declare abstract class MysqlLikeSqlDialect extends AbstractSqlDialect {
16
16
  * from the connection's own database rather than a same-named table in another one.
17
17
  */
18
18
  estimatedCount<E>(ctx: QueryContext, entity: Type<E>): void;
19
- /** `OFFSET` is only legal after a `LIMIT` here, so a bare `$skip` needs one. */
20
- pager(ctx: QueryContext, opts: QueryPager): void;
19
+ protected readonly unboundedLimit: string;
21
20
  /** A signed key, so a foreign key taking its type from it matches, as MySQL refuses an `UNSIGNED` mismatch. */
22
21
  readonly autoIncrementSuffix = "AUTO_INCREMENT";
23
22
  readonly escapeIdChar = "`";
24
- readonly tableOptions = "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
25
23
  readonly beginTransactionCommand = "START TRANSACTION";
26
- readonly commitTransactionCommand = "COMMIT";
27
- readonly rollbackTransactionCommand = "ROLLBACK";
28
24
  readonly isolationLevelStrategy = "set-before";
29
- readonly dropForeignKeySyntax = "DROP FOREIGN KEY";
30
- readonly dropPrimaryKeySyntax = "DROP PRIMARY KEY";
31
- readonly dropIndexSyntax = "on-table";
32
- readonly alterColumnSyntax = "MODIFY COLUMN";
33
25
  readonly booleanLiteral = "integer";
26
+ /** `(3)` keeps milliseconds; a bare `CURRENT_TIMESTAMP` has whole seconds only. */
27
+ readonly currentTimestamp = "CURRENT_TIMESTAMP(3)";
34
28
  readonly insertIdSource: InsertIdSource;
35
29
  /**
36
30
  * `INSERT ... ON DUPLICATE KEY UPDATE`, or `INSERT IGNORE` where there is nothing to assign. The
37
31
  * assignments bind after the insert, where a `?` reads them.
38
32
  */
39
33
  upsert<E>(ctx: QueryContext, entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E | E[]): void;
40
- /** Appended to both branches above: empty on MySQL, which has no `INSERT ... RETURNING`. */
41
- protected upsertReturning<E>(_meta: EntityMeta<E>): string;
42
34
  /**
43
35
  * The alias the inserted row is given after the values list, and read back by the assignments.
44
36
  * Undefined where the dialect has no such syntax - MariaDB, which reads that row through
@@ -73,13 +65,13 @@ export declare abstract class MysqlLikeSqlDialect extends AbstractSqlDialect {
73
65
  protected readonly carriedFields: {
74
66
  numeric: (expr: string) => string;
75
67
  blob: (expr: string) => string;
76
- vector: (expr: string, field: FieldOptions) => string;
68
+ vector: (expr: string, field: import("../type/entity.js").FieldOptions) => string;
77
69
  };
78
70
  /** Bytes as the hex text `decodeColumn` reads back, whole. */
79
71
  protected bytesAsText(expr: string): string;
80
72
  escape(value: unknown): string;
81
73
  /** A date as UTC text, which a `DATETIME` stores as is, where a driver would convert it to its own zone. */
82
- normalizeValue(value: unknown): unknown;
74
+ protected readonly dateZone = "";
83
75
  /**
84
76
  * `MATCH(cols) AGAINST(?)`, which needs a `FULLTEXT` index over exactly those columns: without one
85
77
  * the server answers "Can't find FULLTEXT index matching the column list". Declare it with
@@ -94,11 +86,6 @@ export declare abstract class MysqlLikeSqlDialect extends AbstractSqlDialect {
94
86
  /** `DOUBLE`, never a bare `DECIMAL`, which is `DECIMAL(10,0)` and rounds `1.4` to `1`. */
95
87
  protected numericCast(expr: string): string;
96
88
  neExpr(field: string, ph: string): string;
97
- /**
98
- * Omitting the `COALESCE` on a NOT NULL column keeps MySQL's partial in-place JSON update
99
- * applicable: it requires the target column as the direct `JSON_SET` input.
100
- */
101
- protected jsonSet(ctx: QueryContext, expr: string, set: Record<string, unknown>, field?: FieldOptions): string;
102
89
  /**
103
90
  * `JSON_MERGE_PRESERVE` concatenates arrays and creates absent keys, so every pushed key is
104
91
  * handled in one call that references `expr` once - unlike `JSON_ARRAY_APPEND`, which needs a
@@ -112,7 +99,6 @@ export declare abstract class MysqlLikeSqlDialect extends AbstractSqlDialect {
112
99
  protected jsonPathReading(escapedColumn: string, path: string, mode: 'json' | 'text'): string;
113
100
  /** `JSON_CONTAINS` of the array as the path reads it, which is what a multi-valued index is matched by. */
114
101
  protected jsonContains(ctx: QueryContext, slot: JsonSlot, values: readonly unknown[]): string;
115
- protected jsonUnset(_ctx: QueryContext, expr: string, unset: readonly string[]): string;
116
102
  /** Only an array's, where `JSON_LENGTH` counts a scalar as 1 and an object by its keys. */
117
103
  protected jsonLength(slot: JsonSlot): string;
118
104
  protected jsonIsArray(slot: JsonSlot): string;