qubu 0.6.0 → 0.6.1
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/README.md +112 -0
- package/dist/codegen.d.mts +1 -1
- package/dist/codegen.mjs +1 -1
- package/dist/{column-r1Y4ivwt.mjs → column-BzN8KFJa.mjs} +39 -2
- package/dist/{column-Da37jYSD.mjs → column-CFvSbil0.mjs} +1 -1
- package/dist/{complete-types-CY0KbzNw.d.mts → complete-types-CNMWBWap.d.mts} +1 -1
- package/dist/{constraints-YGyNPQ_z.mjs → constraints-DM_tarXc.mjs} +2 -2
- package/dist/core.d.mts +1 -1
- package/dist/core.mjs +2 -3
- package/dist/diagnostics-I9vVtXkc.mjs +40 -0
- package/dist/diff.d.mts +2 -2
- package/dist/expressions-BCjc08zw.mjs +129 -0
- package/dist/{index-B2rZf3-2.d.mts → index-CGui70hi.d.mts} +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +58 -15
- package/dist/introspection/mysql.d.mts +26 -0
- package/dist/introspection/mysql.mjs +1145 -0
- package/dist/introspection/postgres.d.mts +40 -0
- package/dist/introspection/postgres.mjs +1554 -0
- package/dist/introspection/sqlite.d.mts +15 -0
- package/dist/introspection/sqlite.mjs +986 -0
- package/dist/introspection.d.mts +3 -78
- package/dist/introspection.mjs +5 -3683
- package/dist/mysql.d.mts +1 -1
- package/dist/mysql.mjs +2 -2
- package/dist/{on-conflict-DZQ85f1t.mjs → on-conflict-CnaY5qso.mjs} +76 -4
- package/dist/postgres-Dey7QXPL.mjs +69 -0
- package/dist/postgres.d.mts +3 -3
- package/dist/postgres.mjs +3 -52
- package/dist/registry-oWDiqD7i.mjs +127 -0
- package/dist/{relational-CxnLCqZQ.mjs → relational-DSAJ-l58.mjs} +1 -2
- package/dist/schema.d.mts +1 -1
- package/dist/schema.mjs +7 -6
- package/dist/{serialize-BN07IK0v.mjs → serialize-CE-gw5_s.mjs} +3 -3
- package/dist/{serialize-CEIIlWhC.d.mts → serialize-OvXCLzjm.d.mts} +1 -1
- package/dist/snapshot/mysql.d.mts +2 -2
- package/dist/snapshot/mysql.mjs +28 -28
- package/dist/snapshot/postgres.d.mts +4 -4
- package/dist/snapshot/postgres.mjs +21 -21
- package/dist/snapshot/sqlite.d.mts +4 -4
- package/dist/snapshot/sqlite.mjs +27 -27
- package/dist/{snapshot-Xam8-q0j.mjs → snapshot-DgsOhf_8.mjs} +4 -42
- package/dist/snapshot.d.mts +4 -4
- package/dist/snapshot.mjs +1 -1
- package/dist/{source-SqrKWjFJ.mjs → source-BDuUXmAk.mjs} +2 -2
- package/dist/sqlite.d.mts +1 -1
- package/dist/sqlite.mjs +6 -6
- package/dist/{table-BwflqeAj.mjs → table-C1QGNe4P.mjs} +3 -3
- package/dist/{types-CTCqtFlS.d.mts → types-BEn0N_al.d.mts} +1 -1
- package/dist/{types-BIJsj2fJ.mjs → types-BLNRatG_.mjs} +2 -4
- package/dist/{types-C0VkiwpR.d.mts → types-DUe6eeI0.d.mts} +57 -28
- package/docs/guides/compose-queries.md +22 -0
- package/docs/guides/drizzle.md +11 -11
- package/docs/guides/mutations.md +89 -0
- package/docs/guides/valtio-sync.md +113 -0
- package/docs/migrations/index.md +50 -12
- package/docs/migrations/operations.md +20 -6
- package/docs/reference/supported-surface.md +17 -6
- package/docs/schema/code-generation.md +3 -2
- package/docs/schema/introspection.md +3 -2
- package/docs/sql-semantic-types.md +8 -0
- package/package.json +13 -1
- package/dist/registry-BRcUuazJ.mjs +0 -256
- package/dist/standard-DfcZEVOj.mjs +0 -12
- package/dist/value-D14I_XgL.mjs +0 -29
package/dist/sqlite.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { o as createDialect, r as sqliteJson } from "./json-Db7XRD91.mjs";
|
|
2
|
-
import { d as nativeStorage, u as nativeColumn } from "./column-
|
|
2
|
+
import { d as nativeStorage, u as nativeColumn } from "./column-CFvSbil0.mjs";
|
|
3
3
|
import { r as sqliteExplain } from "./explain-CkIK13L_.mjs";
|
|
4
|
-
import { i as onConflict, n as doUpdate, r as excluded, t as doNothing } from "./on-conflict-
|
|
4
|
+
import { i as onConflict, n as doUpdate, r as excluded, t as doNothing } from "./on-conflict-CnaY5qso.mjs";
|
|
5
5
|
//#region src/dialects/sqlite.ts
|
|
6
6
|
/** Declare a SQLite `INTEGER` timestamp with a live Date codec. */
|
|
7
7
|
function sqliteTimestamp(options) {
|
|
@@ -28,7 +28,7 @@ function sqliteTimestamp(options) {
|
|
|
28
28
|
}
|
|
29
29
|
}).$type();
|
|
30
30
|
}
|
|
31
|
-
function
|
|
31
|
+
function renderSchemaLiteral(value) {
|
|
32
32
|
if (value === null) return "NULL";
|
|
33
33
|
if (typeof value === "boolean") return value ? "1" : "0";
|
|
34
34
|
if (typeof value === "string") return `'${value.replaceAll("'", "''")}'`;
|
|
@@ -39,7 +39,7 @@ function renderSqliteSchemaLiteral(value) {
|
|
|
39
39
|
}
|
|
40
40
|
throw new TypeError(`Unsupported SQLite schema literal type: ${value === void 0 ? "undefined" : typeof value}`);
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function renderPagination(context, parts) {
|
|
43
43
|
const fetch = parts.find((part) => part.kind === "fetch");
|
|
44
44
|
const offset = parts.find((part) => part.kind === "offset");
|
|
45
45
|
context.append("LIMIT ");
|
|
@@ -54,7 +54,7 @@ function sqliteDialect() {
|
|
|
54
54
|
return createDialect({
|
|
55
55
|
name: "sqlite",
|
|
56
56
|
placeholder: () => "?",
|
|
57
|
-
pagination: { render:
|
|
57
|
+
pagination: { render: renderPagination },
|
|
58
58
|
capabilities: ["on-conflict"],
|
|
59
59
|
json: sqliteJson,
|
|
60
60
|
castTypes: {
|
|
@@ -66,7 +66,7 @@ function sqliteDialect() {
|
|
|
66
66
|
json: "TEXT",
|
|
67
67
|
binary: "BLOB"
|
|
68
68
|
},
|
|
69
|
-
renderSchemaLiteral
|
|
69
|
+
renderSchemaLiteral,
|
|
70
70
|
explain: sqliteExplain
|
|
71
71
|
});
|
|
72
72
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as columnResultValue } from "./column-
|
|
3
|
-
import { r as exposeColumns, t as createSource } from "./source-
|
|
1
|
+
import { A as parenthesize, B as resultValueOf, R as resultShapeValue, i as identifier, t as createColumnReference, v as materializeSchemaObjectRecord, y as resolveSqlNames } from "./column-BzN8KFJa.mjs";
|
|
2
|
+
import { a as columnResultValue } from "./column-CFvSbil0.mjs";
|
|
3
|
+
import { r as exposeColumns, t as createSource } from "./source-BDuUXmAk.mjs";
|
|
4
4
|
//#region src/schema/alias.ts
|
|
5
5
|
function alias(sourceOrQuery, name) {
|
|
6
6
|
const input = sourceOrQuery;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { s as resolveCastTarget } from "./json-Db7XRD91.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { a as columnResultValue } from "./column-Da37jYSD.mjs";
|
|
5
|
-
import { t as asValue } from "./value-D14I_XgL.mjs";
|
|
2
|
+
import { C as makeExpression, H as standardDialect, O as fragment, o as asValue, w as makeSchemaExpression } from "./column-BzN8KFJa.mjs";
|
|
3
|
+
import { a as columnResultValue } from "./column-CFvSbil0.mjs";
|
|
6
4
|
//#region src/core/render.ts
|
|
7
5
|
function render(query, options = {}) {
|
|
8
6
|
const dialect = isDialect(options) ? options : options.dialect ?? standardDialect();
|
|
@@ -1687,36 +1687,37 @@ declare function typedCall<TSqlType extends AnySqlType, TOutput = unknown>(): <c
|
|
|
1687
1687
|
} ? never : T_1 : never : never), "function">;
|
|
1688
1688
|
//#endregion
|
|
1689
1689
|
//#region src/expressions/functions/string.d.ts
|
|
1690
|
+
type TextOperandValidation<TInput> = SqlCapabilityValidation<OperandSqlType<TInput, SqlText>, SqlTextLike>;
|
|
1690
1691
|
type TextArgumentsValidation<TArguments extends readonly unknown[]> = TArguments extends readonly [infer THead, ...infer TTail] ? SqlCapabilityValidation<OperandSqlType<THead, SqlText>, SqlTextLike> & TextArgumentsValidation<TTail> : unknown;
|
|
1691
|
-
type CoalesceValidation<TFirst, TRest extends readonly unknown[]> = TRest extends readonly [infer THead, ...infer TTail] ? SqlEqualityValidation<ExpressionSqlType<TFirst>,
|
|
1692
|
-
declare function lower<
|
|
1692
|
+
type CoalesceValidation<TFirst, TRest extends readonly unknown[]> = TRest extends readonly [infer THead, ...infer TTail] ? SqlEqualityValidation<ExpressionSqlType<TFirst>, OperandSqlType<THead, ExpressionSqlType<TFirst>>> & CoalesceValidation<TFirst, TTail> : unknown;
|
|
1693
|
+
declare function lower<const TInput extends Operand<string>>(input: TInput & TextOperandValidation<TInput>): SchemaExpression<ResultMeta<string, (MetadataOf<TInput> extends (infer T) ? T extends MetadataOf<TInput> ? T extends {
|
|
1693
1694
|
readonly kind: "result";
|
|
1694
|
-
} ? T : never : never : never) extends (infer T_1) ? T_1 extends (MetadataOf<
|
|
1695
|
+
} ? T : never : never : never) extends (infer T_1) ? T_1 extends (MetadataOf<TInput> extends (infer T_2) ? T_2 extends MetadataOf<TInput> ? T_2 extends {
|
|
1695
1696
|
readonly kind: "result";
|
|
1696
1697
|
} ? T_2 : never : never : never) ? T_1 extends {
|
|
1697
1698
|
readonly nullableFrom: infer TSource;
|
|
1698
|
-
} ? TSource : never : never : never, SqlText> | ExpressionMeta<MetadataOf<
|
|
1699
|
+
} ? TSource : never : never : never, SqlText> | ExpressionMeta<MetadataOf<TInput> extends (infer T_3) ? T_3 extends MetadataOf<TInput> ? T_3 extends {
|
|
1699
1700
|
readonly kind: "expression";
|
|
1700
1701
|
readonly dependencies: infer TDependencies;
|
|
1701
|
-
} ? TDependencies : never : never : never> | (MetadataOf<
|
|
1702
|
+
} ? TDependencies : never : never : never> | (MetadataOf<TInput> extends (infer T_4) ? T_4 extends MetadataOf<TInput> ? T_4 extends {
|
|
1702
1703
|
readonly kind: "result" | "cardinality";
|
|
1703
1704
|
} ? never : T_4 : never : never), "function">;
|
|
1704
|
-
declare function upper<
|
|
1705
|
+
declare function upper<const TInput extends Operand<string>>(input: TInput & TextOperandValidation<TInput>): SchemaExpression<ResultMeta<string, (MetadataOf<TInput> extends (infer T) ? T extends MetadataOf<TInput> ? T extends {
|
|
1705
1706
|
readonly kind: "result";
|
|
1706
|
-
} ? T : never : never : never) extends (infer T_1) ? T_1 extends (MetadataOf<
|
|
1707
|
+
} ? T : never : never : never) extends (infer T_1) ? T_1 extends (MetadataOf<TInput> extends (infer T_2) ? T_2 extends MetadataOf<TInput> ? T_2 extends {
|
|
1707
1708
|
readonly kind: "result";
|
|
1708
1709
|
} ? T_2 : never : never : never) ? T_1 extends {
|
|
1709
1710
|
readonly nullableFrom: infer TSource;
|
|
1710
|
-
} ? TSource : never : never : never, SqlText> | ExpressionMeta<MetadataOf<
|
|
1711
|
+
} ? TSource : never : never : never, SqlText> | ExpressionMeta<MetadataOf<TInput> extends (infer T_3) ? T_3 extends MetadataOf<TInput> ? T_3 extends {
|
|
1711
1712
|
readonly kind: "expression";
|
|
1712
1713
|
readonly dependencies: infer TDependencies;
|
|
1713
|
-
} ? TDependencies : never : never : never> | (MetadataOf<
|
|
1714
|
+
} ? TDependencies : never : never : never> | (MetadataOf<TInput> extends (infer T_4) ? T_4 extends MetadataOf<TInput> ? T_4 extends {
|
|
1714
1715
|
readonly kind: "result" | "cardinality";
|
|
1715
1716
|
} ? never : T_4 : never : never), "function">;
|
|
1716
|
-
declare function coalesce<T,
|
|
1717
|
+
declare function coalesce<T, TFirst extends ExpressionWithOutput<T>, const TRest extends readonly Operand<NoInfer<T>>[]>(first: TFirst, ...rest: TRest & CoalesceValidation<TFirst, TRest>): SchemaExpression<ResultMeta<T, never, ExpressionSqlType<TFirst>> | ExpressionMeta<MetadataOf<[TFirst, ...TRest][number]> extends (infer T_1) ? T_1 extends MetadataOf<[TFirst, ...TRest][number]> ? T_1 extends {
|
|
1717
1718
|
readonly kind: "expression";
|
|
1718
1719
|
readonly dependencies: infer TDependencies;
|
|
1719
|
-
} ? TDependencies : never : never : never> | (MetadataOf<
|
|
1720
|
+
} ? TDependencies : never : never : never> | (MetadataOf<[TFirst, ...TRest][number]> extends (infer T_2) ? T_2 extends MetadataOf<[TFirst, ...TRest][number]> ? T_2 extends {
|
|
1720
1721
|
readonly kind: "result" | "cardinality";
|
|
1721
1722
|
} ? never : T_2 : never : never), "function">;
|
|
1722
1723
|
declare function concat<const TArguments extends readonly Operand<string>[]>(...argumentsToConcat: TArguments & TextArgumentsValidation<TArguments>): SchemaExpression<ResultMeta<string, (MetadataOf<TArguments[number]> extends (infer T) ? T extends MetadataOf<TArguments[number]> ? T extends {
|
|
@@ -3499,13 +3500,15 @@ interface MutationQuery<TConfig extends MutationQueryConfig = {}> extends Query<
|
|
|
3499
3500
|
}> {
|
|
3500
3501
|
readonly queryKind: MutationConfigKind<TConfig>;
|
|
3501
3502
|
}
|
|
3502
|
-
|
|
3503
|
+
/** Metadata inherited from clauses and expressions composed into a mutation. */
|
|
3504
|
+
type MutationMetadata<T> = CapabilityMetadataOf<T> | RequiresOuterMetadataOf<T>;
|
|
3503
3505
|
interface AllowAllClause extends Fragment<never> {
|
|
3504
3506
|
readonly clauseKind: "allow-all";
|
|
3505
3507
|
}
|
|
3506
3508
|
declare function allowAll(): AllowAllClause;
|
|
3507
3509
|
type MutationConditionClause = WhereClause<any>;
|
|
3508
|
-
type
|
|
3510
|
+
type MutationWithClause = WithClause<any>;
|
|
3511
|
+
type MutationClause = MutationConditionClause | AllowAllClause | MutationReturningClause | MutationWithClause;
|
|
3509
3512
|
type MutationSafetyValidation<TClauses extends readonly unknown[]> = Extract<TClauses[number], MutationConditionClause | AllowAllClause> extends never ? QueryTypeValidation<"unsafe-mutation", "mutation.safety", "Add where(...) or allowAll() explicitly."> : unknown;
|
|
3510
3513
|
type MutationReturningClause = ReturningClause<any>;
|
|
3511
3514
|
type MutationReturning<TClauses extends readonly unknown[]> = Extract<TClauses[number], MutationReturningClause>;
|
|
@@ -3513,17 +3516,31 @@ type MutationRow<TClauses extends readonly unknown[]> = ReturningRow<MutationRet
|
|
|
3513
3516
|
type MutationSqlTypes<TClauses extends readonly unknown[]> = ReturningSqlTypes<MutationReturning<TClauses>>;
|
|
3514
3517
|
type MutationScopeValidation<TSource, TClauses extends readonly unknown[]> = [Exclude<RequiresOf<TClauses[number]>, SourceIdentity<TSource>>] extends [never] ? unknown : QueryTypeValidation<"missing-source", "mutation.scope", "Use clauses that reference the mutation table or an explicitly correlated source.", Exclude<RequiresOf<TClauses[number]>, SourceIdentity<TSource>>>;
|
|
3515
3518
|
//#endregion
|
|
3519
|
+
//#region src/query/mutation/update-from.d.ts
|
|
3520
|
+
/** A PostgreSQL FROM clause that contributes typed sources to an UPDATE scope. */
|
|
3521
|
+
interface UpdateFromClause<TSources extends readonly AnySource[] = readonly AnySource[], TMetadata = RequiresOuterMetadataOf<TSources[number]> | CapabilityMetadataOf<TSources[number]> | RequiresCapabilityMeta<"update-from">> extends Fragment<TMetadata> {
|
|
3522
|
+
readonly clauseKind: "update-from";
|
|
3523
|
+
readonly sources: TSources;
|
|
3524
|
+
}
|
|
3525
|
+
/** Introduce one or more PostgreSQL sources to an UPDATE statement. */
|
|
3526
|
+
declare function updateFrom<const TSources extends readonly [AnySource, ...AnySource[]]>(...sources: TSources): UpdateFromClause<TSources>;
|
|
3527
|
+
/** Source identities introduced to an UPDATE by updateFrom(). */
|
|
3528
|
+
type UpdateFromScope<T> = T extends UpdateFromClause<infer TSources> ? ProvidedSourceIdentity<TSources[number]> : never;
|
|
3529
|
+
//#endregion
|
|
3516
3530
|
//#region src/query/mutation/update.d.ts
|
|
3517
3531
|
/** A value, target-compatible expression, or explicitly omitted update field. */
|
|
3518
3532
|
type UpdateAssignmentValue<T> = T | ExpressionWithOutput<T> | Omit$1;
|
|
3519
3533
|
/** Writable table fields accepted by {@link update}. */
|
|
3520
3534
|
type UpdateAssignments<TTable extends AnyTable> = { -readonly [K in keyof TableUpdateInput<TTable["definitions"]>]?: UpdateAssignmentValue<TableUpdateInput<TTable["definitions"]>[K]>; };
|
|
3521
3535
|
type InvalidUpdateAssignments<TTable extends AnyTable, TAssignments> = TAssignments extends UpdateAssignments<TTable> ? Exclude<keyof TAssignments, keyof UpdateAssignments<TTable>> extends never ? unknown : QueryTypeValidation<"invalid-update", "update.assignments", "Use only columns declared by the update table.", Exclude<keyof TAssignments, keyof UpdateAssignments<TTable>>> : QueryTypeValidation<"invalid-update", "update.assignments", "Provide values or expressions matching the update table columns.", TAssignments>;
|
|
3522
|
-
type AssignmentScopeValidation<TTable extends AnyTable, TAssignments> = [Exclude<RequiresOf<TAssignments extends object ? TAssignments[keyof TAssignments] : never>, SourceIdentity<TTable>>] extends [never] ? unknown : QueryTypeValidation<"missing-source", "update.assignments", "Use expressions scoped to the update table.", Exclude<RequiresOf<TAssignments extends object ? TAssignments[keyof TAssignments] : never>, SourceIdentity<TTable>>>;
|
|
3523
|
-
|
|
3536
|
+
type AssignmentScopeValidation<TTable extends AnyTable, TAssignments, TClauses extends readonly UpdateClause[]> = [Exclude<RequiresOf<TAssignments extends object ? TAssignments[keyof TAssignments] : never>, SourceIdentity<TTable> | UpdateFromScope<TClauses[number]>>] extends [never] ? unknown : QueryTypeValidation<"missing-source", "update.assignments", "Use expressions scoped to the update table or an updateFrom() source.", Exclude<RequiresOf<TAssignments extends object ? TAssignments[keyof TAssignments] : never>, SourceIdentity<TTable> | UpdateFromScope<TClauses[number]>>>;
|
|
3537
|
+
type UpdateClause = MutationClause | UpdateFromClause;
|
|
3538
|
+
type UpdateScopeValidation<TTable extends AnyTable, TClauses extends readonly UpdateClause[]> = [Exclude<RequiresOf<TClauses[number]>, SourceIdentity<TTable> | UpdateFromScope<TClauses[number]>>] extends [never] ? unknown : QueryTypeValidation<"missing-source", "mutation.scope", "Use clauses that reference the update table or an updateFrom() source.", Exclude<RequiresOf<TClauses[number]>, SourceIdentity<TTable> | UpdateFromScope<TClauses[number]>>>;
|
|
3539
|
+
type UpdateFromSourceValidation<TClauses extends readonly UpdateClause[]> = [Exclude<RequiresOuterOf<Extract<TClauses[number], UpdateFromClause>>, UpdateFromScope<TClauses[number]>>] extends [never] ? unknown : QueryTypeValidation<"missing-source", "update.from", "Use FROM sources whose outer requirements are provided by another updateFrom() source.", Exclude<RequiresOuterOf<Extract<TClauses[number], UpdateFromClause>>, UpdateFromScope<TClauses[number]>>>;
|
|
3540
|
+
declare function update<const TTable extends AnyTable, const TAssignments extends object, const TClauses extends readonly UpdateClause[]>(table: TTable, assignments: TAssignments & InvalidUpdateAssignments<TTable, TAssignments> & AssignmentScopeValidation<TTable, TAssignments, TClauses>, ...clauses: TClauses & UpdateScopeValidation<TTable, TClauses> & UpdateFromSourceValidation<TClauses> & MutationSafetyValidation<TClauses>): MutationQuery<{
|
|
3524
3541
|
readonly row: MutationRow<TClauses>;
|
|
3525
3542
|
readonly kind: "update";
|
|
3526
|
-
readonly metadata:
|
|
3543
|
+
readonly metadata: MutationMetadata<TClauses[number] | (TAssignments extends object ? TAssignments[keyof TAssignments] : never)>;
|
|
3527
3544
|
readonly sqlTypes: MutationSqlTypes<TClauses>;
|
|
3528
3545
|
}>;
|
|
3529
3546
|
//#endregion
|
|
@@ -3556,8 +3573,15 @@ type TableConstraints<TTable extends AnyTable> = TTable extends {
|
|
|
3556
3573
|
readonly constraints: infer TConstraints extends SourceConstraintsRecord;
|
|
3557
3574
|
} ? TConstraints : never;
|
|
3558
3575
|
type TableKeyConstraint<TTable extends AnyTable> = Extract<TableConstraints<TTable>[keyof TableConstraints<TTable>], KeyConstraint>;
|
|
3559
|
-
|
|
3560
|
-
|
|
3576
|
+
type TableIndexes<TTable extends AnyTable> = TTable extends {
|
|
3577
|
+
readonly indexes: infer TIndexes extends SourceIndexesRecord;
|
|
3578
|
+
} ? TIndexes : never;
|
|
3579
|
+
type PostgresUniqueIndex<TIndex> = TIndex extends SourceIndex ? TIndex["unique"] extends true ? [Exclude<TIndex["dialect"], undefined>] extends [never] ? TIndex : Exclude<TIndex["dialect"], undefined> extends {
|
|
3580
|
+
readonly dialect: "postgresql";
|
|
3581
|
+
} ? TIndex : never : never : never;
|
|
3582
|
+
type TableConflictIndex<TTable extends AnyTable> = PostgresUniqueIndex<TableIndexes<TTable>[keyof TableIndexes<TTable>]>;
|
|
3583
|
+
/** A declared primary key, unique constraint, or PostgreSQL-compatible unique index. */
|
|
3584
|
+
type ConflictTarget<TTable extends AnyTable = AnyTable> = TableKeyConstraint<TTable> | TableConflictIndex<TTable>;
|
|
3561
3585
|
type ConflictSources<TTable extends AnyTable> = SourceIdentity<TTable> | ExcludedIdentity<SourceIdentity<TTable>>;
|
|
3562
3586
|
type ConflictAssignmentValidation<TTable extends AnyTable, TAssignments> = TAssignments extends UpdateAssignments<TTable> ? Exclude<keyof TAssignments, keyof UpdateAssignments<TTable>> extends never ? [Exclude<RequiresOf<TAssignments[keyof TAssignments]>, ConflictSources<TTable>>] extends [never] ? unknown : QueryTypeValidation<"missing-source", "upsert.update.assignments", "Use expressions scoped to the target table or excluded row.", Exclude<RequiresOf<TAssignments[keyof TAssignments]>, ConflictSources<TTable>>> : QueryTypeValidation<"invalid-update", "upsert.update.assignments", "Use only writable columns declared by the target table.", Exclude<keyof TAssignments, keyof UpdateAssignments<TTable>>> : QueryTypeValidation<"invalid-update", "upsert.update.assignments", "Provide values or expressions matching the target table update columns.", TAssignments>;
|
|
3563
3587
|
type ConflictWhereValidation<TTable extends AnyTable, TWhere> = TWhere extends undefined ? unknown : [Exclude<RequiresOf<TWhere>, ConflictSources<TTable>>] extends [never] ? unknown : QueryTypeValidation<"missing-source", "upsert.update.where", "Use expressions scoped to the target table or excluded row.", Exclude<RequiresOf<TWhere>, ConflictSources<TTable>>>;
|
|
@@ -3565,10 +3589,10 @@ type ConflictActionValidation<TTable extends AnyTable, TAction extends ConflictA
|
|
|
3565
3589
|
type ConflictActionCapabilities<TAction extends ConflictAction> = TAction extends DoUpdateAction<infer TAssignments, infer TWhere> ? CapabilityMetadataOf<TAssignments[keyof TAssignments] | Exclude<TWhere, undefined>> : never;
|
|
3566
3590
|
interface OnConflictClause<TAction extends ConflictAction = ConflictAction> extends Fragment<RequiresCapabilityMeta<"on-conflict"> | ConflictActionCapabilities<TAction>> {
|
|
3567
3591
|
readonly clauseKind: "on-conflict";
|
|
3568
|
-
readonly target: KeyConstraint | undefined;
|
|
3592
|
+
readonly target: KeyConstraint | SourceIndex | undefined;
|
|
3569
3593
|
readonly action: TAction;
|
|
3570
3594
|
}
|
|
3571
|
-
type InsertClause = MutationReturningClause | OnConflictClause;
|
|
3595
|
+
type InsertClause = MutationReturningClause | OnConflictClause | MutationWithClause;
|
|
3572
3596
|
declare function onConflict(action: DoNothingAction): OnConflictClause<DoNothingAction>;
|
|
3573
3597
|
declare function onConflict<const TTable extends AnyTable, const TTarget extends ConflictTarget<TTable>, const TAction extends ConflictAction>(table: TTable, target: TTarget, action: TAction & ConflictActionValidation<TTable, TAction>): OnConflictClause<TAction>;
|
|
3574
3598
|
//#endregion
|
|
@@ -3589,9 +3613,14 @@ interface InsertSelectSource<TQuery extends AnyQuery = AnyQuery, TColumns extend
|
|
|
3589
3613
|
}
|
|
3590
3614
|
declare function insertSelect<TQuery extends AnyQuery, const TColumns extends readonly [string, ...string[]]>(query: TQuery, columns: TColumns): InsertSelectSource<TQuery, TColumns>;
|
|
3591
3615
|
type InsertSource = ValuesSource<any> | DefaultValuesSource | InsertSelectSource<any, any>;
|
|
3592
|
-
type
|
|
3593
|
-
|
|
3594
|
-
type
|
|
3616
|
+
type InsertSourceMetadata<TSource extends InsertSource> = TSource extends InsertSelectSource<infer TQuery, any> ? CapabilityMetadataOf<TQuery> | RequiresOuterMetadataOf<TQuery> : TSource extends ValuesSource<infer TRows> ? CapabilityMetadataOf<InsertRowsValue<TRows>> : never;
|
|
3617
|
+
/** A raw application input or target-compatible expression accepted by an insert field. */
|
|
3618
|
+
type InsertValue<T> = T | ExpressionWithOutput<T>;
|
|
3619
|
+
/** Writable table fields accepted by {@link insertInto} through {@link values}. */
|
|
3620
|
+
type InsertValuesRow<TTable extends AnyTable> = { -readonly [K in keyof TableInsertInput<TTable["definitions"]>]: InsertValue<TableInsertInput<TTable["definitions"]>[K]>; };
|
|
3621
|
+
type InsertRowsValue<TRows extends readonly object[]> = TRows[number] extends (infer TRow) ? TRow extends object ? TRow[keyof TRow] : never : never;
|
|
3622
|
+
type InsertValuesScopeValidation<TSource extends InsertSource> = TSource extends ValuesSource<infer TRows> ? [RequiresOf<InsertRowsValue<TRows>>] extends [never] ? unknown : QueryTypeValidation<"missing-source", "insert.values.row", "Use source-free expressions in INSERT values.", RequiresOf<InsertRowsValue<TRows>>> : unknown;
|
|
3623
|
+
type InvalidInsertRow<TTable extends AnyTable, TRow> = TRow extends InsertValuesRow<TTable> ? Exclude<keyof TRow, keyof InsertValuesRow<TTable>> extends never ? unknown : QueryTypeValidation<"invalid-insert", "insert.values.columns", "Use only columns declared by the insert table.", Exclude<keyof TRow, keyof InsertValuesRow<TTable>>> : QueryTypeValidation<"invalid-insert", "insert.values.row", "Provide values matching the insert table columns.", TRow>;
|
|
3595
3624
|
type ValidInsertSource<TTable extends AnyTable, TSource extends InsertSource> = TSource extends ValuesSource<infer TRows> ? TRows[number] extends (infer TRow) ? InvalidInsertRow<TTable, TRow> : never : TSource extends DefaultValuesSource ? Exclude<keyof TTable["definitions"], { [K in keyof TTable["definitions"]]-?: ColumnIsGenerated<TTable["definitions"][K]> extends true ? K : TTable["definitions"][K] extends {
|
|
3596
3625
|
hasDefault: true;
|
|
3597
3626
|
} | {
|
|
@@ -3601,10 +3630,10 @@ type ValidInsertSource<TTable extends AnyTable, TSource extends InsertSource> =
|
|
|
3601
3630
|
} | {
|
|
3602
3631
|
hasRuntimeDefault: true;
|
|
3603
3632
|
} ? K : never; }[keyof TTable["definitions"]]>> : TSource extends InsertSelectSource<any, infer TColumns> ? Exclude<TColumns[number], keyof TTable["definitions"]> extends never ? Exclude<{ [K in keyof TTable["definitions"]]-?: ColumnIsGenerated<TTable["definitions"][K]> extends true ? never : ColumnHasDefault<TTable["definitions"][K]> extends true ? never : K; }[keyof TTable["definitions"]], TColumns[number]> extends never ? unknown : QueryTypeValidation<"invalid-insert", "insert.select.columns", "Include every required insert column in the target list.", Exclude<{ [K in keyof TTable["definitions"]]-?: ColumnIsGenerated<TTable["definitions"][K]> extends true ? never : ColumnHasDefault<TTable["definitions"][K]> extends true ? never : K; }[keyof TTable["definitions"]], TColumns[number]>> : QueryTypeValidation<"invalid-insert", "insert.select.columns", "Use only columns declared by the insert table.", Exclude<TColumns[number], keyof TTable["definitions"]>> : never;
|
|
3604
|
-
declare function insertInto<const TTable extends AnyTable, const TSource extends InsertSource, const TClauses extends readonly InsertClause[]>(table: TTable, source: TSource & ValidInsertSource<TTable, TSource>, ...clauses: TClauses & MutationScopeValidation<TTable, TClauses>): MutationQuery<{
|
|
3633
|
+
declare function insertInto<const TTable extends AnyTable, const TSource extends InsertSource, const TClauses extends readonly InsertClause[]>(table: TTable, source: TSource & ValidInsertSource<TTable, TSource> & InsertValuesScopeValidation<TSource>, ...clauses: TClauses & MutationScopeValidation<TTable, TClauses>): MutationQuery<{
|
|
3605
3634
|
readonly row: MutationRow<TClauses>;
|
|
3606
3635
|
readonly kind: "insert";
|
|
3607
|
-
readonly metadata:
|
|
3636
|
+
readonly metadata: MutationMetadata<TClauses[number]> | InsertSourceMetadata<TSource>;
|
|
3608
3637
|
readonly sqlTypes: MutationSqlTypes<TClauses>;
|
|
3609
3638
|
}>;
|
|
3610
3639
|
//#endregion
|
|
@@ -3612,7 +3641,7 @@ declare function insertInto<const TTable extends AnyTable, const TSource extends
|
|
|
3612
3641
|
declare function deleteFrom<const TTable extends AnyTable, const TClauses extends readonly MutationClause[]>(table: TTable, ...clauses: TClauses & MutationScopeValidation<TTable, TClauses> & MutationSafetyValidation<TClauses>): MutationQuery<{
|
|
3613
3642
|
readonly row: MutationRow<TClauses>;
|
|
3614
3643
|
readonly kind: "delete";
|
|
3615
|
-
readonly metadata:
|
|
3644
|
+
readonly metadata: MutationMetadata<TClauses[number]>;
|
|
3616
3645
|
readonly sqlTypes: MutationSqlTypes<TClauses>;
|
|
3617
3646
|
}>;
|
|
3618
3647
|
//#endregion
|
|
@@ -3869,7 +3898,7 @@ type QuerySqlTypeMap<T> = T extends {
|
|
|
3869
3898
|
//#endregion
|
|
3870
3899
|
//#region src/core/dialect.d.ts
|
|
3871
3900
|
/** Capabilities whose syntax must be explicitly supported by a dialect. */
|
|
3872
|
-
type DialectCapability = "ilike" | "json" | "on-conflict" | "row-locking";
|
|
3901
|
+
type DialectCapability = "ilike" | "json" | "on-conflict" | "row-locking" | "update-from";
|
|
3873
3902
|
/**
|
|
3874
3903
|
* Optional dialect hook used by schema expressions when a JavaScript value must become SQL text
|
|
3875
3904
|
* instead of a query parameter.
|
|
@@ -4249,4 +4278,4 @@ type SchemaSnapshotInput = SchemaSnapshot | Readonly<Record<string, unknown>>;
|
|
|
4249
4278
|
/** Expose the schema generic in tooling declarations without widening APIs. */
|
|
4250
4279
|
type AnySchema = Schema<any>;
|
|
4251
4280
|
//#endregion
|
|
4252
|
-
export { PaginationKind as $, SqlTag as $a, QubuStreamingTransaction as $c, SourceIndexesRecord as $i, AggregateMeta as $l, WithClause as $n, ColumnStorageDialectOf as $o, generatedTableName as $r, ResolvedColumnBehavior as $s, nullsLast as $t, SqlNumericLike as $u, SnapshotStorage as A, jsonBoolean as Aa, ExplainReadOptions as Ac, catalogCheck as Ai, ExpressionNullability as Al, MutationReturningClause as An, value as Ao, SchemaExpressionErrorCode as Ar, numeric as As, SourceSqlTypeMap as At, RequiresOuterMetadataOf as Au, CastTarget as B, concat as Ba, HookQueryOperation as Bc, AliasedSource as Bi, withDialectCapability as Bl, select as Bn, ColumnHasDefault as Bo, renderSchemaSql as Br, DefaultDescriptor as Bs, TableDefinitions as Bt, isFragment as Bu, SnapshotIndexTerm as C, SelectClause as Ca, ExecutionOptions as Cc, SourceConstraintsRecord as Ci, ColumnDependency as Cl, update as Cn, isTrue as Co, SelectionSqlTypes as Cr, date as Cs, SourceColumns as Ct, ProvidesOuterSourceMeta as Cu, SnapshotLiteral as D, multiply as Da, ExplainOptions as Dc, UniqueConstraint as Di, AnySchemaExpression as Dl, MutationQuery as Dn, SqlCapabilityValidation as Do, createSchemaDialect as Dr, nativeColumn as Ds, SourceKind as Dt, RenderFunction as Du, SnapshotKeyConstraint as E, modulo as Ea, ExplainMutationOptions as Ec, TableLike as Ei, AnyExpression as El, MutationKind as En, OperandSqlType as Eo, SchemaDialectHooks as Er, json as Es, SourceIdentity as Et, RenderContext as Eu, neutralSnapshotDialect as F, denseRank as Fa, HookMetadata as Fc, references as Fi, SchemaExpression as Fl, ReturningClause as Fn, ColumnDefaultOf as Fo, UnsafeSchemaSqlExpression as Fr, CanonicalLiteral as Fs, exposeColumns as Ft, SqlTypeOf as Fu, DialectJson as G, typedCall as Ga, QubuClient as Gc, alias as Gi, ResultDecodingError as Gl, MissingScope as Gn, ColumnIsNullable as Go, SchemaNamingPolicy as Gr, GeneratedColumnDescriptor as Gs, TableRow as Gt, SqlBinary as Gu, DialectCapability as H, upper as Ha, HookSuccessOutcome as Hc, LateralSource as Hi, ResultDecodeContext as Hl, AvailableScope as Hn, ColumnIdentityOf as Ho, unsafeSchemaSql as Hr, ExpressionGeneratedColumnDescriptor as Hs, TableInsertInput as Ht, sequence as Hu, schemaSnapshotDialectVersion as I, over as Ia, HookMetadataValue as Ic, unique as Ii, SchemaExpressionBrand as Il, ReturningRow as In, ColumnDefinition as Io, defineSchemaExpression as Ir, ColumnBehaviorError as Is, sourceIdentity as It, SubqueryMeta as Iu, DialectRowLocking as J, countDistinct as Ja, QubuExplainableTransactionalClient as Jc, IndexOptions as Ji, booleanResultDecoder as Jl, ScopeValidation as Jn, ColumnOutput as Jo, SchemaTableNames as Jr, IdentityDescriptor as Js, table as Jt, SqlDecimal as Ju, DialectOptions as K, avg as Ka, QubuExplainableClient as Kc, lateral as Ki, ResultField as Kl, RequiredOuterScope as Kn, ColumnOnUpdateOf as Ko, SchemaOptions as Kr, GeneratedColumnMode as Ks, TableSqlTypes as Kt, SqlBoolean as Ku, schemaSnapshotFormat as L, rank as La, HookOperation as Lc, uniqueConstraint as Li, isExpression as Ll, ReturningSqlTypes as Ln, ColumnDefinitionConfig as Lo, isUnsafeSchemaSql as Lr, ColumnBehaviorErrorCode as Ls, AnyTable as Lt, VisibleDependenciesOf as Lu, SnapshotTable as M, jsonNumber as Ma, ExplainResult as Mc, check as Mi, ExpressionRequires as Ml, MutationScopeValidation as Mn, cast as Mo, SchemaExpressionMode as Mr, text as Ms, UnknownSourceSqlTypes as Mt, RequiresOuterSourceMeta as Mu, SnapshotUniqueConstraint as N, jsonPath as Na, ExplainableQueryAdapter as Nc, foreignKey as Ni, ExpressionSqlType as Nl, MutationSqlTypes as Nn, typedCast as No, SchemaRenderContext as Nr, timestamp as Ns, createSource as Nt, RequiresSourceMeta as Nu, SnapshotNamingPolicy as O, subtract as Oa, ExplainOptionsFor as Oc, UniqueConstraintOptions as Oi, Expression as Ol, MutationQueryConfig as On, asValue as Oo, RenderedSchemaExpression as Or, nativeStorage as Os, SourceProvision as Ot, RequiresCapabilityMeta as Ou, SnapshotValidationContext as P, jsonText as Pa, HookErrorOutcome as Pc, primaryKey as Pi, ExpressionWithOutput as Pl, allowAll as Pn, ColumnCodec as Po, SchemaRenderOptions as Pr, uuid as Ps, customSource as Pt, ResultMeta as Pu, NamedCastTarget as Q, SqlFragment as Qa, QubuStreamingExplainableClient as Qc, SourceIndex as Qi, AggregateDependenciesOf as Ql, RecursiveCteSource as Qn, ColumnStorageDescriptor as Qo, defaultSchemaNamingPolicy as Qr, MysqlIdentityExtension as Qs, nullsFirst as Qt, SqlJson as Qu, schemaSnapshotNamingPolicyVersion as R, rowNumber as Ra, HookOperationKind as Rc, validateConstraintDialect as Ri, makeExpression as Rl, returning as Rn, ColumnFromOptions as Ro, normalizeSchemaSql as Rr, ColumnDefault as Rs, Table as Rt, WindowMeta as Ru, SnapshotIndex as S, ClausePlacement as Sa, DriverValueEncoder as Sc, SourceConstraint as Si, QueryValidationIssue as Sl, UpdateAssignments as Sn, isNull as So, SelectionOutput as Sr, columnResultValue as Ss, Source as St, ProvidesOuterOf as Su, SnapshotJsonValue as T, divide as Ta, ExecutionResult as Tc, SqliteConstraintExtension as Ti, expressionFragment as Tl, MutationClause as Tn, OperandNullability as To, SchemaDialect as Tr, integer as Ts, SourceConstraints as Tt, QueryCardinality as Tu, DialectCastTypes as U, call as Ua, HookTransactionOperation as Uc, QueryAliasIdentity as Ui, ResultDecoder as Ul, ClauseScope as Un, ColumnInsertInput as Uo, Schema as Ur, ExternalDefaultDescriptor as Us, TableMetadataCallback as Ut, AnySqlType as Uu, Dialect as V, lower as Va, HookStreamEnd as Vc, LateralIdentity as Vi, DecodableResultType as Vl, AvailableOuterScope as Vn, ColumnHasRuntimeDefault as Vo, schemaExpression as Vr, ExpressionDefaultDescriptor as Vs, TableIdentity as Vt, parenthesize as Vu, DialectExplain as W, schemaCall as Wa, OperationEndHook as Wc, QuerySource as Wi, ResultDecoders as Wl, GroupingValidation as Wn, ColumnIsGenerated as Wo, SchemaDiagnostic as Wr, ExternalGeneratedColumnDescriptor as Ws, TableOptions as Wt, SqlBigInt as Wu, ExplainRenderOptions as X, min as Xa, QubuOptions as Xc, MysqlIndexExtension as Xi, jsonTextResultDecoder as Xl, SelectQuery as Xn, ColumnStorage as Xo, SchemaTableRegistry as Xr, IdentityGeneration as Xs, asc as Xt, SqlEqualityCompatible as Xu, ExplainFormat as Y, max as Ya, QubuHooks as Yc, IndexTerm as Yi, dateResultDecoder as Yl, SelectCardinality as Yn, ColumnSqlType as Yo, SchemaTableRecord as Yr, IdentityDialectExtension as Ys, OrderTerm as Yt, SqlEqualityComparable as Yu, JsonScalarKind as Z, sum as Za, QubuStreamingClient as Zc, PostgresIndexExtension as Zi, timestampResultDecoder as Zl, CteSource as Zn, ColumnStorageDeclarationOf as Zo, SchemaValidationError as Zr, LiteralDefaultDescriptor as Zs, desc as Zt, SqlInteger as Zu, SnapshotExpressionContext as _, fetchNext as _a, generatedSchemaObjectName as _c, KeyConstraint as _i, RenderedQuery as _l, doNothing as _n, notLike as _o, FromScope as _r, StorageTypeOf as _s, AnySource as _t, MetadataOf as _u, SnapshotBigInt as a, and as aa, generatedColumn as ac, SqlTimestamp as ad, CheckConstraint as ai, StreamableQuery as al, InsertSource as an, notExists as ao, except as ar, DialectNativeStorage as as, SchemaLiteralRenderer as at, DependenciesOf as au, SnapshotGeneratedColumn as b, distinct as ba, materializeSchemaObjectRecord as bc, PostgresConstraintExtension as bi, QueryValidationError as bl, onConflict as bn, notIn as bo, Selection as br, boolean as bs, ProvidedSourceIdentity as bt, NullableSourcesOf as bu, SnapshotConstraint as c, Omit$1 as ca, SchemaDialectExtension as cc, SqlUuid as cd, ConstraintOptions as ci, TransactionOptions as cl, insertInto as cn, eq as co, unionAll as cr, NativeStorageDescriptor as cs, resolveCastTarget as ct, FragmentMeta as cu, SnapshotDefault as d, omit as da, SchemaMetadataValidationError as dc, FieldLikeOptions as di, executeRows as dl, ConflictAction as dn, isDistinctFrom as do, innerJoin as dr, PortableStorageDescriptor as ds, QueryConfig as dt, GroupingMeta as du, SqliteIndexExtension as ea, SchemaLiteralValue as ec, SqlOrderCompatible as ed, schema as ei, QubuStreamingTransactionalClient as el, order as en, TypedSqlTag as eo, cte as er, ColumnStorageKindOf as es, PaginationPart as et, AnyFragment as eu, SnapshotDiagnostic as f, where as fa, SchemaObjectIdentity as fc, ForeignKeyConstraint as fi, explain as fl, ConflictTarget as fn, isNotDistinctFrom as fo, leftJoin as fr, PortableStorageType as fs, QueryKind as ft, HasAggregate as fu, SnapshotExpression as g, fetchFirst as ga, freezeSchemaMetadata as gc, ForeignKeyTargetInput as gi, RenderOptions as gl, OnConflictClause as gn, ne as go, FromClause as gr, StorageOf as gs, Row as gt, InheritedMetadataOf as gu, SnapshotDialectExtension as h, rowLock as ha, dialectMismatchDiagnostic as hc, ForeignKeyTarget as hi, RenderCapabilityValidation as hl, ExcludedSource as hn, lte as ho, groupBy as hr, StorageDialectOf as hs, QueryWithRow as ht, InheritedMetadata as hu, SchemaSnapshotInput as i, DeclaredColumnNullability as ia, externalGeneratedColumn as ic, SqlTextLike as id, CatalogCheckSql as ii, QueryExecutor as il, InsertSelectSource as in, inQuery as io, SetQuery as ir, ColumnUpdateInput as is, RowLockWaitPolicy as it, CardinalityOf as iu, SnapshotStorageContext as j, jsonExists as ja, ExplainRequest as jc, catalogForeignKey as ji, ExpressionOutput as jl, MutationRow as jn, mapResult as jo, SchemaExpressionInput as jr, portableStorage as js, SourceSqlTypes as jt, RequiresOuterOf as ju, SnapshotSpecialNumber as k, JsonPath as ka, ExplainPlanRow as kc, UniqueNullSemantics as ki, ExpressionKind as kl, MutationReturning as kn, typedValue as ko, SchemaExpressionError as kr, nullable as ks, SourceRow as kt, RequiresOf as ku, SnapshotCreateResult as l, OmittableSelectClause as la, SchemaDialectName as lc, ConstraintTiming as li, TransactionalQueryAdapter as ll, insertSelect as ln, gt as lo, crossJoin as lr, PortableColumnStorage as ls, AnyQuery as lt, GroupingDependenciesOf as lu, SnapshotDialect as m, RowLockOptions as ma, assertSchemaDialectSupport as mc, ForeignKeyOptions as mi, stream as ml, DoUpdateAction as mn, lt as mo, rightJoin as mr, StorageDescriptor as ms, QuerySqlTypeMap as mt, HasWindow as mu, SchemaSnapshot as n, index as na, canonicalLiteral as nc, SqlSemanticType as nd, AnyKeyColumn as ni, QubuTransactionalClient as nl, deleteFrom as nn, caseWhen as no, withCte as nr, ColumnStorageType as ns, PortableCastType as nt, CapabilityMetadataOf as nu, SnapshotCheckConstraint as o, not as oa, identityColumn as oc, SqlTypeSatisfies as od, CheckConstraintOptions as oi, StreamingQueryAdapter as ol, ValuesSource as on, scalar as oo, intersect as or, NativeColumnStorage as os, assertDialectCapability as ot, ExpressionMeta as ou, SnapshotDiagnosticCode as p, RowLockClause as pa, SchemaObjectNameOptions as pc, ForeignKeyMatch as pi, qubu as pl, DoNothingAction as pn, like as po, naturalJoin as pr, StorageDeclarationOf as ps, QueryRow as pt, HasSubquery as pu, DialectPagination as q, count as qa, QubuExplainableStreamingTransactionalClient as qc, IndexDialectExtension as qi, ResultShape as ql, RequiredScope as qn, ColumnOptions as qo, SchemaTableEntry as qr, GeneratedDescriptor as qs, TableUpdateInput as qt, SqlDate as qu, SchemaSnapshotAdapter as r, validateIndexDialect as ra, externalDefault as rc, SqlText as rd, CatalogCheckExpression as ri, QueryAdapter as rl, DefaultValuesSource as rn, exists as ro, SetOperator as rr, ColumnStorageTypeOf as rs, RowLockMode as rt, CardinalityMeta as ru, SnapshotColumn as s, or as sa, resolveColumnBehavior as sc, SqlUnknown as sd, ConstraintDialectExtension as si, StreamingTransactionalQueryAdapter as sl, defaultValues as sn, ComparisonValidation as so, union as sr, NativeStorage as ss, createDialect as st, Fragment as su, AnySchema as t, TableIndex as ta, SqliteIdentityExtension as tc, SqlOrderable as td, schemaNamingPolicyVersion as ti, QubuTransaction as tl, orderBy as tn, sql as to, recursiveCte as tr, ColumnStorageOf as ts, PortableCastTarget as tt, CapabilitiesOf as tu, SnapshotDecodeResult as u, SelectPart as ua, SchemaMetadataDiagnostic as uc, FieldLike as ui, execute as ul, values as un, gte as uo, fullJoin as ur, PortableStorage as us, Query as ut, GroupingKeysOf as uu, SnapshotExtensionContext as v, offset as va, isValidSchemaObjectName as vc, KeyConstraintOptions as vi, render as vl, doUpdate as vn, between as vo, FromSource as vr, bigint as vs, CustomSource as vt, NullabilityOf as vu, SnapshotIndexTermExpression as w, add as wa, ExecutionRequest as wc, SourceLike as wi, ColumnReference as wl, AllowAllClause as wn, Operand as wo, all as wr, encodeColumnParameter as ws, SourceConfig as wt, ProvidesSourceMeta as wu, SnapshotIdentity as x, AnySelectClause as xa, AdapterExecutionResult as xc, ReferentialAction as xi, QueryValidationErrorCode as xl, UpdateAssignmentValue as xn, isNotNull as xo, SelectionObject as xr, column as xs, ProvidedSourceRow as xt, OutputOf as xu, SnapshotForeignKey as y, having as ya, materializeSchemaObjectIdentity as yc, MysqlConstraintExtension as yi, QueryTypeValidation as yl, excluded as yn, inList as yo, from as yr, binary as ys, CustomSourceOptions as yt, NullableSourceMeta as yu, schemaSnapshotVersion as z, coalesce as za, HookOutcome as zc, AliasIdentity as zi, markExpressionCategory as zl, correlate as zn, ColumnGeneratedOf as zo, renderSchemaExpression as zr, ColumnDefaultInput as zs, TableColumns as zt, fragment as zu };
|
|
4281
|
+
export { PaginationKind as $, countDistinct as $a, QubuExplainableTransactionalClient as $c, IndexOptions as $i, booleanResultDecoder as $l, ScopeValidation as $n, ColumnOutput as $o, SchemaTableNames as $r, IdentityDescriptor as $s, nullsLast as $t, SqlDecimal as $u, SnapshotStorage as A, divide as Aa, ExecutionResult as Ac, SqliteConstraintExtension as Ai, expressionFragment as Al, MutationClause as An, OperandNullability as Ao, SchemaDialect as Ar, integer as As, SourceSqlTypeMap as At, QueryCardinality as Au, CastTarget as B, denseRank as Ba, HookMetadata as Bc, references as Bi, SchemaExpression as Bl, ReturningClause as Bn, ColumnDefaultOf as Bo, UnsafeSchemaSqlExpression as Br, CanonicalLiteral as Bs, TableDefinitions as Bt, SqlTypeOf as Bu, SnapshotIndexTerm as C, offset as Ca, isValidSchemaObjectName as Cc, KeyConstraintOptions as Ci, render as Cl, UpdateAssignmentValue as Cn, between as Co, FromSource as Cr, bigint as Cs, SourceColumns as Ct, NullabilityOf as Cu, SnapshotLiteral as D, ClausePlacement as Da, DriverValueEncoder as Dc, SourceConstraint as Di, QueryValidationIssue as Dl, UpdateFromScope as Dn, isNull as Do, SelectionOutput as Dr, columnResultValue as Ds, SourceKind as Dt, ProvidesOuterOf as Du, SnapshotKeyConstraint as E, AnySelectClause as Ea, AdapterExecutionResult as Ec, ReferentialAction as Ei, QueryValidationErrorCode as El, UpdateFromClause as En, isNotNull as Eo, SelectionObject as Er, column as Es, SourceIdentity as Et, OutputOf as Eu, neutralSnapshotDialect as F, jsonBoolean as Fa, ExplainReadOptions as Fc, catalogCheck as Fi, ExpressionNullability as Fl, MutationReturningClause as Fn, value as Fo, SchemaExpressionErrorCode as Fr, numeric as Fs, exposeColumns as Ft, RequiresOuterMetadataOf as Fu, DialectJson as G, concat as Ga, HookQueryOperation as Gc, AliasedSource as Gi, withDialectCapability as Gl, select as Gn, ColumnHasDefault as Go, renderSchemaSql as Gr, DefaultDescriptor as Gs, TableRow as Gt, isFragment as Gu, DialectCapability as H, rank as Ha, HookOperation as Hc, uniqueConstraint as Hi, isExpression as Hl, ReturningSqlTypes as Hn, ColumnDefinitionConfig as Ho, isUnsafeSchemaSql as Hr, ColumnBehaviorErrorCode as Hs, TableInsertInput as Ht, VisibleDependenciesOf as Hu, schemaSnapshotDialectVersion as I, jsonExists as Ia, ExplainRequest as Ic, catalogForeignKey as Ii, ExpressionOutput as Il, MutationRow as In, mapResult as Io, SchemaExpressionInput as Ir, portableStorage as Is, sourceIdentity as It, RequiresOuterOf as Iu, DialectRowLocking as J, call as Ja, HookTransactionOperation as Jc, QueryAliasIdentity as Ji, ResultDecoder as Jl, ClauseScope as Jn, ColumnInsertInput as Jo, Schema as Jr, ExternalDefaultDescriptor as Js, table as Jt, AnySqlType as Ju, DialectOptions as K, lower as Ka, HookStreamEnd as Kc, LateralIdentity as Ki, DecodableResultType as Kl, AvailableOuterScope as Kn, ColumnHasRuntimeDefault as Ko, schemaExpression as Kr, ExpressionDefaultDescriptor as Ks, TableSqlTypes as Kt, parenthesize as Ku, schemaSnapshotFormat as L, jsonNumber as La, ExplainResult as Lc, check as Li, ExpressionRequires as Ll, MutationScopeValidation as Ln, cast as Lo, SchemaExpressionMode as Lr, text as Ls, AnyTable as Lt, RequiresOuterSourceMeta as Lu, SnapshotTable as M, multiply as Ma, ExplainOptions as Mc, UniqueConstraint as Mi, AnySchemaExpression as Ml, MutationQuery as Mn, SqlCapabilityValidation as Mo, createSchemaDialect as Mr, nativeColumn as Ms, UnknownSourceSqlTypes as Mt, RenderFunction as Mu, SnapshotUniqueConstraint as N, subtract as Na, ExplainOptionsFor as Nc, UniqueConstraintOptions as Ni, Expression as Nl, MutationQueryConfig as Nn, asValue as No, RenderedSchemaExpression as Nr, nativeStorage as Ns, createSource as Nt, RequiresCapabilityMeta as Nu, SnapshotNamingPolicy as O, SelectClause as Oa, ExecutionOptions as Oc, SourceConstraintsRecord as Oi, ColumnDependency as Ol, updateFrom as On, isTrue as Oo, SelectionSqlTypes as Or, date as Os, SourceProvision as Ot, ProvidesOuterSourceMeta as Ou, SnapshotValidationContext as P, JsonPath as Pa, ExplainPlanRow as Pc, UniqueNullSemantics as Pi, ExpressionKind as Pl, MutationReturning as Pn, typedValue as Po, SchemaExpressionError as Pr, nullable as Ps, customSource as Pt, RequiresOf as Pu, NamedCastTarget as Q, count as Qa, QubuExplainableStreamingTransactionalClient as Qc, IndexDialectExtension as Qi, ResultShape as Ql, RequiredScope as Qn, ColumnOptions as Qo, SchemaTableEntry as Qr, GeneratedDescriptor as Qs, nullsFirst as Qt, SqlDate as Qu, schemaSnapshotNamingPolicyVersion as R, jsonPath as Ra, ExplainableQueryAdapter as Rc, foreignKey as Ri, ExpressionSqlType as Rl, MutationSqlTypes as Rn, typedCast as Ro, SchemaRenderContext as Rr, timestamp as Rs, Table as Rt, RequiresSourceMeta as Ru, SnapshotIndex as S, fetchNext as Sa, generatedSchemaObjectName as Sc, KeyConstraint as Si, RenderedQuery as Sl, onConflict as Sn, notLike as So, FromScope as Sr, StorageTypeOf as Ss, Source as St, MetadataOf as Su, SnapshotJsonValue as T, distinct as Ta, materializeSchemaObjectRecord as Tc, PostgresConstraintExtension as Ti, QueryValidationError as Tl, update as Tn, notIn as To, Selection as Tr, boolean as Ts, SourceConstraints as Tt, NullableSourcesOf as Tu, DialectCastTypes as U, rowNumber as Ua, HookOperationKind as Uc, validateConstraintDialect as Ui, makeExpression as Ul, returning as Un, ColumnFromOptions as Uo, normalizeSchemaSql as Ur, ColumnDefault as Us, TableMetadataCallback as Ut, WindowMeta as Uu, Dialect as V, over as Va, HookMetadataValue as Vc, unique as Vi, SchemaExpressionBrand as Vl, ReturningRow as Vn, ColumnDefinition as Vo, defineSchemaExpression as Vr, ColumnBehaviorError as Vs, TableIdentity as Vt, SubqueryMeta as Vu, DialectExplain as W, coalesce as Wa, HookOutcome as Wc, AliasIdentity as Wi, markExpressionCategory as Wl, correlate as Wn, ColumnGeneratedOf as Wo, renderSchemaExpression as Wr, ColumnDefaultInput as Ws, TableOptions as Wt, fragment as Wu, ExplainRenderOptions as X, typedCall as Xa, QubuClient as Xc, alias as Xi, ResultDecodingError as Xl, MissingScope as Xn, ColumnIsNullable as Xo, SchemaNamingPolicy as Xr, GeneratedColumnDescriptor as Xs, asc as Xt, SqlBinary as Xu, ExplainFormat as Y, schemaCall as Ya, OperationEndHook as Yc, QuerySource as Yi, ResultDecoders as Yl, GroupingValidation as Yn, ColumnIsGenerated as Yo, SchemaDiagnostic as Yr, ExternalGeneratedColumnDescriptor as Ys, OrderTerm as Yt, SqlBigInt as Yu, JsonScalarKind as Z, avg as Za, QubuExplainableClient as Zc, lateral as Zi, ResultField as Zl, RequiredOuterScope as Zn, ColumnOnUpdateOf as Zo, SchemaOptions as Zr, GeneratedColumnMode as Zs, desc as Zt, SqlBoolean as Zu, SnapshotExpressionContext as _, where as _a, SchemaObjectIdentity as _c, ForeignKeyConstraint as _i, explain as _l, ExcludedSource as _n, isNotDistinctFrom as _o, leftJoin as _r, PortableStorageType as _s, AnySource as _t, HasAggregate as _u, SnapshotBigInt as a, SqliteIndexExtension as aa, SchemaLiteralValue as ac, SqlOrderCompatible as ad, schema as ai, QubuStreamingTransactionalClient as al, InsertSource as an, TypedSqlTag as ao, cte as ar, ColumnStorageKindOf as as, SchemaLiteralRenderer as at, AnyFragment as au, SnapshotGeneratedColumn as b, rowLock as ba, dialectMismatchDiagnostic as bc, ForeignKeyTarget as bi, RenderCapabilityValidation as bl, doUpdate as bn, lte as bo, groupBy as br, StorageDialectOf as bs, ProvidedSourceIdentity as bt, InheritedMetadata as bu, SnapshotConstraint as c, validateIndexDialect as ca, externalDefault as cc, SqlText as cd, CatalogCheckExpression as ci, QueryAdapter as cl, ValuesSource as cn, exists as co, SetOperator as cr, ColumnStorageTypeOf as cs, resolveCastTarget as ct, CardinalityMeta as cu, SnapshotDefault as d, not as da, identityColumn as dc, SqlTypeSatisfies as dd, CheckConstraintOptions as di, StreamingQueryAdapter as dl, insertSelect as dn, scalar as do, intersect as dr, NativeColumnStorage as ds, QueryConfig as dt, ExpressionMeta as du, IndexTerm as ea, IdentityDialectExtension as ec, SqlEqualityComparable as ed, SchemaTableRecord as ei, QubuHooks as el, order as en, max as eo, SelectCardinality as er, ColumnSqlType as es, PaginationPart as et, dateResultDecoder as eu, SnapshotDiagnostic as f, or as fa, resolveColumnBehavior as fc, SqlUnknown as fd, ConstraintDialectExtension as fi, StreamingTransactionalQueryAdapter as fl, values as fn, ComparisonValidation as fo, union as fr, NativeStorage as fs, QueryKind as ft, Fragment as fu, SnapshotExpression as g, omit as ga, SchemaMetadataValidationError as gc, FieldLikeOptions as gi, executeRows as gl, DoUpdateAction as gn, isDistinctFrom as go, innerJoin as gr, PortableStorageDescriptor as gs, Row as gt, GroupingMeta as gu, SnapshotDialectExtension as h, SelectPart as ha, SchemaMetadataDiagnostic as hc, FieldLike as hi, execute as hl, DoNothingAction as hn, gte as ho, fullJoin as hr, PortableStorage as hs, QueryWithRow as ht, GroupingKeysOf as hu, SchemaSnapshotInput as i, SourceIndexesRecord as ia, ResolvedColumnBehavior as ic, SqlNumericLike as id, generatedTableName as ii, QubuStreamingTransaction as il, InsertSelectSource as in, SqlTag as io, WithClause as ir, ColumnStorageDialectOf as is, RowLockWaitPolicy as it, AggregateMeta as iu, SnapshotStorageContext as j, modulo as ja, ExplainMutationOptions as jc, TableLike as ji, AnyExpression as jl, MutationKind as jn, OperandSqlType as jo, SchemaDialectHooks as jr, json as js, SourceSqlTypes as jt, RenderContext as ju, SnapshotSpecialNumber as k, add as ka, ExecutionRequest as kc, SourceLike as ki, ColumnReference as kl, AllowAllClause as kn, Operand as ko, all as kr, encodeColumnParameter as ks, SourceRow as kt, ProvidesSourceMeta as ku, SnapshotCreateResult as l, DeclaredColumnNullability as la, externalGeneratedColumn as lc, SqlTextLike as ld, CatalogCheckSql as li, QueryExecutor as ll, defaultValues as ln, inQuery as lo, SetQuery as lr, ColumnUpdateInput as ls, AnyQuery as lt, CardinalityOf as lu, SnapshotDialect as m, OmittableSelectClause as ma, SchemaDialectName as mc, ConstraintTiming as mi, TransactionalQueryAdapter as ml, ConflictTarget as mn, gt as mo, crossJoin as mr, PortableColumnStorage as ms, QuerySqlTypeMap as mt, GroupingDependenciesOf as mu, SchemaSnapshot as n, PostgresIndexExtension as na, LiteralDefaultDescriptor as nc, SqlInteger as nd, SchemaValidationError as ni, QubuStreamingClient as nl, deleteFrom as nn, sum as no, CteSource as nr, ColumnStorageDeclarationOf as ns, PortableCastType as nt, timestampResultDecoder as nu, SnapshotCheckConstraint as o, TableIndex as oa, SqliteIdentityExtension as oc, SqlOrderable as od, schemaNamingPolicyVersion as oi, QubuTransaction as ol, InsertValue as on, sql as oo, recursiveCte as or, ColumnStorageOf as os, assertDialectCapability as ot, CapabilitiesOf as ou, SnapshotDiagnosticCode as p, Omit$1 as pa, SchemaDialectExtension as pc, SqlUuid as pd, ConstraintOptions as pi, TransactionOptions as pl, ConflictAction as pn, eq as po, unionAll as pr, NativeStorageDescriptor as ps, QueryRow as pt, FragmentMeta as pu, DialectPagination as q, upper as qa, HookSuccessOutcome as qc, LateralSource as qi, ResultDecodeContext as ql, AvailableScope as qn, ColumnIdentityOf as qo, unsafeSchemaSql as qr, ExpressionGeneratedColumnDescriptor as qs, TableUpdateInput as qt, sequence as qu, SchemaSnapshotAdapter as r, SourceIndex as ra, MysqlIdentityExtension as rc, SqlJson as rd, defaultSchemaNamingPolicy as ri, QubuStreamingExplainableClient as rl, DefaultValuesSource as rn, SqlFragment as ro, RecursiveCteSource as rr, ColumnStorageDescriptor as rs, RowLockMode as rt, AggregateDependenciesOf as ru, SnapshotColumn as s, index as sa, canonicalLiteral as sc, SqlSemanticType as sd, AnyKeyColumn as si, QubuTransactionalClient as sl, InsertValuesRow as sn, caseWhen as so, withCte as sr, ColumnStorageType as ss, createDialect as st, CapabilityMetadataOf as su, AnySchema as t, MysqlIndexExtension as ta, IdentityGeneration as tc, SqlEqualityCompatible as td, SchemaTableRegistry as ti, QubuOptions as tl, orderBy as tn, min as to, SelectQuery as tr, ColumnStorage as ts, PortableCastTarget as tt, jsonTextResultDecoder as tu, SnapshotDecodeResult as u, and as ua, generatedColumn as uc, SqlTimestamp as ud, CheckConstraint as ui, StreamableQuery as ul, insertInto as un, notExists as uo, except as ur, DialectNativeStorage as us, Query as ut, DependenciesOf as uu, SnapshotExtensionContext as v, RowLockClause as va, SchemaObjectNameOptions as vc, ForeignKeyMatch as vi, qubu as vl, OnConflictClause as vn, like as vo, naturalJoin as vr, StorageDeclarationOf as vs, CustomSource as vt, HasSubquery as vu, SnapshotIndexTermExpression as w, having as wa, materializeSchemaObjectIdentity as wc, MysqlConstraintExtension as wi, QueryTypeValidation as wl, UpdateAssignments as wn, inList as wo, from as wr, binary as ws, SourceConfig as wt, NullableSourceMeta as wu, SnapshotIdentity as x, fetchFirst as xa, freezeSchemaMetadata as xc, ForeignKeyTargetInput as xi, RenderOptions as xl, excluded as xn, ne as xo, FromClause as xr, StorageOf as xs, ProvidedSourceRow as xt, InheritedMetadataOf as xu, SnapshotForeignKey as y, RowLockOptions as ya, assertSchemaDialectSupport as yc, ForeignKeyOptions as yi, stream as yl, doNothing as yn, lt as yo, rightJoin as yr, StorageDescriptor as ys, CustomSourceOptions as yt, HasWindow as yu, schemaSnapshotVersion as z, jsonText as za, HookErrorOutcome as zc, primaryKey as zi, ExpressionWithOutput as zl, allowAll as zn, ColumnCodec as zo, SchemaRenderOptions as zr, uuid as zs, TableColumns as zt, ResultMeta as zu };
|
|
@@ -28,6 +28,28 @@ The rendered statement includes the `WITH` clause before `SELECT`. Selected
|
|
|
28
28
|
camelCase keys use snake_case while they belong to the CTE relation; the outer
|
|
29
29
|
result projection aliases them back to camelCase for the returned row.
|
|
30
30
|
|
|
31
|
+
Attach the same clause to an insert, update, or delete when the mutation reads
|
|
32
|
+
through the CTE. For example, an insert can consume a filtered CTE through
|
|
33
|
+
`insertSelect()`:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { insertInto, insertSelect, returning } from "qubu"
|
|
37
|
+
|
|
38
|
+
const archivedUsers = table("archived_users", { name: text() })
|
|
39
|
+
const archive = insertInto(
|
|
40
|
+
archivedUsers,
|
|
41
|
+
insertSelect(select({ name: activeUsers.name }, from(activeUsers)), ["name"]),
|
|
42
|
+
withCte(activeUsers),
|
|
43
|
+
returning({ name: archivedUsers.name }),
|
|
44
|
+
)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Qubu renders `WITH ... INSERT` and keeps CTE parameters before mutation
|
|
48
|
+
parameters. For update and delete predicates, select from the CTE in a scalar,
|
|
49
|
+
`IN`, or `EXISTS` subquery; `withCte()` defines the relation but does not add it
|
|
50
|
+
directly to the mutation target's column scope. Recursive CTEs use the same
|
|
51
|
+
pattern and render `WITH RECURSIVE` before the mutation keyword.
|
|
52
|
+
|
|
31
53
|
## Build a recursive CTE
|
|
32
54
|
|
|
33
55
|
`recursiveCte()` uses the anchor projection as the contract for a recursive
|
package/docs/guides/drizzle.md
CHANGED
|
@@ -22,7 +22,7 @@ your database:
|
|
|
22
22
|
|
|
23
23
|
```ts
|
|
24
24
|
import { integer, schema, table, text } from "qubu"
|
|
25
|
-
import {
|
|
25
|
+
import { toDrizzleSchema } from "@qubu/drizzle/postgres"
|
|
26
26
|
|
|
27
27
|
const users = table("user_records", {
|
|
28
28
|
id: integer({ generated: true }),
|
|
@@ -31,17 +31,17 @@ const users = table("user_records", {
|
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
const appSchema = schema({ users }, { namespace: "app" })
|
|
34
|
-
const drizzleTables =
|
|
34
|
+
const drizzleTables = toDrizzleSchema(appSchema)
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
The import path selects the dialect. Each module imports only its matching
|
|
38
38
|
Drizzle core package:
|
|
39
39
|
|
|
40
|
-
| Database | Import | Converter
|
|
41
|
-
| ---------- | ------------------------ |
|
|
42
|
-
| PostgreSQL | `@qubu/drizzle/postgres` | `
|
|
43
|
-
| MySQL | `@qubu/drizzle/mysql` | `
|
|
44
|
-
| SQLite | `@qubu/drizzle/sqlite` | `
|
|
40
|
+
| Database | Import | Converter |
|
|
41
|
+
| ---------- | ------------------------ | ------------------- |
|
|
42
|
+
| PostgreSQL | `@qubu/drizzle/postgres` | `toDrizzleSchema()` |
|
|
43
|
+
| MySQL | `@qubu/drizzle/mysql` | `toDrizzleSchema()` |
|
|
44
|
+
| SQLite | `@qubu/drizzle/sqlite` | `toDrizzleSchema()` |
|
|
45
45
|
|
|
46
46
|
`@qubu/drizzle` exports the shared conversion error and dialect types. It does
|
|
47
47
|
not import a dialect core or provide a universal runtime converter.
|
|
@@ -75,7 +75,7 @@ Unix timestamps and Drizzle must continue reading and writing `Date` values:
|
|
|
75
75
|
|
|
76
76
|
```ts
|
|
77
77
|
import { schema, table } from "qubu"
|
|
78
|
-
import {
|
|
78
|
+
import { toDrizzleSchema } from "@qubu/drizzle/sqlite"
|
|
79
79
|
import { sqliteTimestamp } from "qubu/sqlite"
|
|
80
80
|
|
|
81
81
|
const events = table("events", {
|
|
@@ -85,7 +85,7 @@ const events = table("events", {
|
|
|
85
85
|
}),
|
|
86
86
|
})
|
|
87
87
|
|
|
88
|
-
const drizzleTables =
|
|
88
|
+
const drizzleTables = toDrizzleSchema(schema({ events }))
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
`timestamp` stores Unix seconds and `timestamp_ms` stores Unix milliseconds.
|
|
@@ -129,13 +129,13 @@ belong to the selected dialect:
|
|
|
129
129
|
|
|
130
130
|
```ts
|
|
131
131
|
import { nativeColumn, schema, table } from "qubu"
|
|
132
|
-
import {
|
|
132
|
+
import { toDrizzleSchema } from "@qubu/drizzle/postgres"
|
|
133
133
|
|
|
134
134
|
const records = table("records", {
|
|
135
135
|
handle: nativeColumn("postgresql", "CITEXT"),
|
|
136
136
|
})
|
|
137
137
|
|
|
138
|
-
const tables =
|
|
138
|
+
const tables = toDrizzleSchema(schema({ records }))
|
|
139
139
|
```
|
|
140
140
|
|
|
141
141
|
Conversion first runs Qubu's snapshot validation for the selected dialect.
|
package/docs/guides/mutations.md
CHANGED
|
@@ -44,6 +44,63 @@ render(query)
|
|
|
44
44
|
|
|
45
45
|
Use `defaultValues()` only when every non-generated column has a database
|
|
46
46
|
default. Use `insertSelect(query, columns)` for an `INSERT ... SELECT` source.
|
|
47
|
+
An ordinary or recursive `withCte()` clause can prefix any mutation; see
|
|
48
|
+
[Compose queries](compose-queries.md#turn-a-query-into-a-cte) for the typed
|
|
49
|
+
`WITH ... INSERT`, `WITH ... UPDATE`, and `WITH ... DELETE` patterns.
|
|
50
|
+
|
|
51
|
+
Each field may also be a typed expression whose output is compatible with the
|
|
52
|
+
target column. Expressions render directly and retain their dialect
|
|
53
|
+
requirements; ordinary application values still pass through the column's
|
|
54
|
+
parameter encoder:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { upper } from "qubu"
|
|
58
|
+
|
|
59
|
+
insertInto(users, values({ name: upper("Ada") }))
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
An `INSERT ... VALUES` row does not introduce a relational source, so its
|
|
63
|
+
expressions cannot reference columns from the target table or another table.
|
|
64
|
+
Use `insertSelect()` when inserted values need a query source.
|
|
65
|
+
|
|
66
|
+
## Resolve PostgreSQL conflicts
|
|
67
|
+
|
|
68
|
+
PostgreSQL upserts can target a primary key, a `unique()` constraint, or a
|
|
69
|
+
declared unique index from the inserted table. A partial unique index carries
|
|
70
|
+
its predicate into the conflict target so PostgreSQL can infer the same index:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { boolean, eq, index, table, text, value } from "qubu"
|
|
74
|
+
import { doUpdate, excluded, onConflict } from "qubu/postgres"
|
|
75
|
+
|
|
76
|
+
const accounts = table(
|
|
77
|
+
"accounts",
|
|
78
|
+
{ email: text(), active: boolean(), name: text() },
|
|
79
|
+
(accounts) => ({
|
|
80
|
+
constraints: {},
|
|
81
|
+
indexes: {
|
|
82
|
+
activeEmail: index([accounts.email], {
|
|
83
|
+
unique: true,
|
|
84
|
+
where: eq(accounts.active, value(true)),
|
|
85
|
+
dialect: { dialect: "postgresql" },
|
|
86
|
+
}),
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
const incoming = excluded(accounts)
|
|
92
|
+
const conflict = onConflict(
|
|
93
|
+
accounts,
|
|
94
|
+
accounts.indexes.activeEmail,
|
|
95
|
+
doUpdate({ name: incoming.name }),
|
|
96
|
+
)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The index must be unique, declared on the insert target, and portable or marked
|
|
100
|
+
for PostgreSQL. Index expressions and predicates use the same deterministic,
|
|
101
|
+
parameter-free schema-expression rules as the declared index. Constraint-based
|
|
102
|
+
targets keep their existing cross-dialect behavior; unique-index inference is
|
|
103
|
+
PostgreSQL-specific.
|
|
47
104
|
|
|
48
105
|
## Update with a predicate
|
|
49
106
|
|
|
@@ -64,6 +121,38 @@ const query = update(
|
|
|
64
121
|
The assignment expression is source-aware, so a column from an unrelated table
|
|
65
122
|
cannot silently enter the update.
|
|
66
123
|
|
|
124
|
+
PostgreSQL updates can introduce one or more typed sources with `updateFrom()`.
|
|
125
|
+
Those sources are available to assignments, the predicate, and `RETURNING`:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { eq, integer, render, returning, table, text, update, where } from "qubu"
|
|
129
|
+
import { postgresDialect, updateFrom } from "qubu/postgres"
|
|
130
|
+
|
|
131
|
+
const changes = table("user_changes", {
|
|
132
|
+
userId: integer(),
|
|
133
|
+
name: text(),
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
const query = update(
|
|
137
|
+
users,
|
|
138
|
+
{ name: changes.name },
|
|
139
|
+
updateFrom(changes),
|
|
140
|
+
where(eq(users.id, changes.userId)),
|
|
141
|
+
returning({ id: users.id, sourceName: changes.name }),
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
render(query, postgresDialect())
|
|
145
|
+
// UPDATE "users" SET "name" = "user_changes"."name"
|
|
146
|
+
// FROM "user_changes"
|
|
147
|
+
// WHERE ("users"."id" = "user_changes"."user_id")
|
|
148
|
+
// RETURNING "users"."id" AS "id", "user_changes"."name" AS "sourceName"
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
`UPDATE ... FROM` carries a dialect capability requirement, so rendering it
|
|
152
|
+
with the default, SQLite, or MySQL dialect is rejected. Qubu still requires a
|
|
153
|
+
predicate or an explicit `allowAll()` marker; introducing a source does not
|
|
154
|
+
authorize an unrestricted update.
|
|
155
|
+
|
|
67
156
|
Use `omit` for a runtime-conditional assignment. Qubu removes omitted fields
|
|
68
157
|
before validating and rendering the effective assignment set:
|
|
69
158
|
|