@vibeorm/sql 4.1.0 → 4.2.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.
package/dist/dialect.d.ts CHANGED
@@ -93,6 +93,19 @@ export type ConflictKeyEquality = {
93
93
  */
94
94
  readonly duplicatesInOneStatement: "reject" | "lastWriteWins";
95
95
  };
96
+ /**
97
+ * How an INSERT that names no column renders, when every value is its column
98
+ * default. `defaultValues`: `INSERT INTO t DEFAULT VALUES`, exactly one row per
99
+ * statement; `conflictClause` says whether a conflict clause may follow it
100
+ * (postgres: yes; sqlite's grammar has no upsert clause after DEFAULT VALUES).
101
+ * `emptyRow`: `INSERT INTO t () VALUES ()`, any number of rows (mysql).
102
+ */
103
+ export type EmptyInsertSyntax = {
104
+ readonly form: "defaultValues";
105
+ readonly conflictClause: boolean;
106
+ } | {
107
+ readonly form: "emptyRow";
108
+ };
96
109
  export type SqlDialect = {
97
110
  readonly name: Dialect;
98
111
  /** Frozen feature table — consumed by runtime, migrate, generator, tests. */
@@ -230,6 +243,8 @@ export type SqlDialect = {
230
243
  * rows are grouped by column set into separate statements there (M4).
231
244
  */
232
245
  readonly rowDefaultKeyword: boolean;
246
+ /** How an INSERT that names no column renders ({@link EmptyInsertSyntax}). */
247
+ readonly emptyInsert: EmptyInsertSyntax;
233
248
  /**
234
249
  * How a {@link ChainStatement} (an ordered chain of read and data-modifying
235
250
  * steps ending in one SELECT — round-trip campaign EPIC 4/F) renders, or
package/dist/index.d.ts CHANGED
@@ -40,7 +40,7 @@ export type { ResultDecoder, ResultReadDecoder, ResultParameterEncoder, ResultSc
40
40
  export { compileExclusion, renderExclusionSetup, renderExclusionDdl, renderExclusionCatalog, renderExclusionProbe } from "./exclusion.ts";
41
41
  export type { AdvisoryLockKey, AdvisoryLockStatement, AggFn, AggRef, AggSelect, ChainResult, ChainRowSource, ChainStatement, ChainStep, ChainStepStatement, ChainTally, ChainVeto, ColRef, ComparisonOp, CountSubquery, DeleteStatement, ExcludedRef, InnerJoin, KeyTableJoin, KeyTableMember, InsertSelectStatement, InsertStatement, ReturningColumn, JsonFilterOp, LateralJoin, ListSetOperation, OnConflictClause, OnConflictDoNothing, OnConflictUpdate, OrderByAggregate, OrderByColumn, OrderBySubquery, OrderTerm, RowLock, RowNumberProjection, DbNowMarker, JsonParamCell, SelectExpr, SelectStatement, SetOperation, SetOperator, SqlExpr, SqlStatement, StepColumnRef, TableRef, UpdateStatement, } from "./ast.ts";
42
42
  export { ADVISORY_LOCK_RESULT_COLUMN, CHAIN_VETO_PREFIX, CHAIN_VETO_TOKEN_PATTERN, SQL_DEFAULT_CELL, chainVetoToken, dbNowMarker, excludedRef, isDbNowMarker, isExcludedRef, isJsonParamCell, isListSetOperation, isSetOperation, isSqlDefaultCell, isStepColumnRef, jsonParamCell, returningColumnName, stepColumnRef, } from "./ast.ts";
43
- export type { AdvisoryLockFunctions, AdvisoryLockModeFunctions, RowLockSyntax, SqlDialect, } from "./dialect.ts";
43
+ export type { AdvisoryLockFunctions, AdvisoryLockModeFunctions, RowLockSyntax, EmptyInsertSyntax, SqlDialect, } from "./dialect.ts";
44
44
  export { ADVISORY_KEY_BOUNDS, describeRowLock, renderAdvisoryLock, renderRowLockClause } from "./locks.ts";
45
45
  export { JSON_TRANSPORT, projectionOutputName } from "./json-transport.ts";
46
46
  export { postgresDialect } from "./dialects/postgres.ts";
package/dist/index.js CHANGED
@@ -1369,6 +1369,7 @@ var sqliteDialect = {
1369
1369
  rowLockSyntax: null,
1370
1370
  advisoryLockFunctions: null,
1371
1371
  rowDefaultKeyword: false,
1372
+ emptyInsert: { form: "defaultValues", conflictClause: false },
1372
1373
  statementChain: null,
1373
1374
  paramBudget: 900,
1374
1375
  booleanLiteral: { true: "1", false: "0" },
@@ -2433,6 +2434,7 @@ var postgresDialect = {
2433
2434
  keyCast: Object.freeze({ single: "::bigint", pair: "::int4" })
2434
2435
  },
2435
2436
  rowDefaultKeyword: true,
2437
+ emptyInsert: { form: "defaultValues", conflictClause: true },
2436
2438
  statementChain: "dataModifyingCte",
2437
2439
  paramBudget: 30000,
2438
2440
  booleanLiteral: { true: "true", false: "false" },
@@ -2495,6 +2497,7 @@ var mysqlDialect = {
2495
2497
  },
2496
2498
  advisoryLockFunctions: null,
2497
2499
  rowDefaultKeyword: true,
2500
+ emptyInsert: { form: "emptyRow" },
2498
2501
  statementChain: null,
2499
2502
  paramBudget: 1e4,
2500
2503
  booleanLiteral: { true: "1", false: "0" },
@@ -3758,12 +3761,20 @@ function renderSelect(params) {
3758
3761
  }
3759
3762
  function renderInsert(params) {
3760
3763
  const { dialect, statement, collector } = params;
3761
- if (statement.columns.length === 0) {
3762
- throw internalError2({ message: "insert requires at least one column" });
3763
- }
3764
3764
  if (statement.rows.length === 0) {
3765
3765
  throw internalError2({ message: "insert requires at least one row" });
3766
3766
  }
3767
+ const defaultValues = statement.columns.length === 0 && dialect.emptyInsert.form === "defaultValues";
3768
+ if (defaultValues && statement.rows.length !== 1) {
3769
+ throw internalError2({ message: `${dialect.name} inserts an all-default row as DEFAULT VALUES, one row per statement` });
3770
+ }
3771
+ if (defaultValues && statement.onConflict !== undefined && !(dialect.emptyInsert.form === "defaultValues" && dialect.emptyInsert.conflictClause)) {
3772
+ throw unsupportedCapability16({
3773
+ dialect: dialect.name,
3774
+ feature: "a conflict clause on an all-default row (DEFAULT VALUES)",
3775
+ hint: "supply at least one column value, or drop the conflict clause"
3776
+ });
3777
+ }
3767
3778
  for (const row of statement.rows) {
3768
3779
  if (row.length !== statement.columns.length) {
3769
3780
  throw internalError2({
@@ -3790,7 +3801,7 @@ function renderInsert(params) {
3790
3801
  }
3791
3802
  return "DEFAULT";
3792
3803
  }).join(", ")})`).join(", ");
3793
- let text = `${insertKeyword} ${renderTable(dialect, statement.table)} (${columnList}) VALUES ${rowsSql}`;
3804
+ let text = defaultValues ? `${insertKeyword} ${renderTable(dialect, statement.table)} DEFAULT VALUES` : `${insertKeyword} ${renderTable(dialect, statement.table)} (${columnList}) VALUES ${rowsSql}`;
3794
3805
  if (onConflict !== undefined && !("doNothing" in onConflict) && dialect.excludedRowRef.form === "rowAlias" && Object.values(onConflict.update).some((value) => isExcludedRef(value) || isSqlFragment(value) && sqlUsesIncoming({ fragment: value }))) {
3795
3806
  text += ` AS ${dialect.quoteIdent({ name: dialect.excludedRowRef.alias })}`;
3796
3807
  }
@@ -4810,4 +4821,4 @@ export {
4810
4821
  toPgArrayLiteral
4811
4822
  };
4812
4823
 
4813
- //# debugId=02AD9A2144138F0F64756E2164756E21
4824
+ //# debugId=71705578A45D011664756E2164756E21