kern-orm 0.5.0 → 0.6.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/{database-BJ0hNYrF.mjs → database-CP4oapsQ.mjs} +2348 -1623
- package/dist/{index-Cag6_erK.d.mts → index-CoKpXcBp.d.mts} +1301 -772
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +90 -7
- package/dist/testing.d.mts +1 -1
- package/dist/testing.mjs +12 -3
- package/dist/{text-BTFErHIi.mjs → text-Cti9QLK7.mjs} +7 -1
- package/dist/{types-D9LtZ9W-.mjs → types-DfoL8Oi9.mjs} +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/types.mjs +2 -2
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
export { type AnyColumn, type AnyDb, type AnyExpression, type AnyMutationQuery, type AnyQuery, type AnyRecordQuery, type AnySchema, type AnySelectQuery, type AnySqlQuery, type AnyTable, type AnyTableKeys, type AnyType, type BaseOperators, type BaseType, type BindOptions, type BooleanResult, type BoundOperators, type BoundSelectQuery, type CaseBranch, type CaseCondition, type CaseValue, type Column, type ColumnAttributes, type ColumnDefinitions, type ColumnOperators, type ColumnRefKey, type ColumnRefs, type ColumnShape, type ColumnValue, type ColumnValues, type CombinedCondition, type ComparisonSignature, type CompileOptions, type Condition, type ConditionOperand, type Connection, type CountValueType, type Database, type DatabaseOptions, type Db, type DbMutationState, type DbOf, type DbQueryState, type DeclaredRelations, type DecodedFields, type Driver, type DriverResult, type EmptyRecord, type EqValue, type EqualityOperator, type EqualityOperators, type ExistsValueType, type Expression, type ExpressionInput, type ExpressionOperators, type ExpressionValue, FALSE, type FieldTypes, type FilteredRows, type FilteredStateRows, type FollowingOperand, type GenericOperator, type GenericOperatorImplementation, type HasEquality, type Helper, type HelperEffect, type InSignature, type InitialMutationState, type InitialQueryState, type InitialSqlQueryState, type InsertValues, type KeyCheck, type KeyColumns, type KeyKind, type Literal, type MatchCheck, type MatchResult, type MergeOperators, type MergeRelations, type MergeSelection, type MutationQuery, type MutationQueryState, type NestedQuery, type NoOperators, type NoRelations, type NotAColumn, type NotAKey, NotFoundError, type NullSkippingResult, type NumberTypeOperators, type OneRelationKeys, type OneRow, type OneValueRows, type Operand, type OperandUses, type OperandValue, type OperatorDefinitions, type OperatorSignature, type OrderColumns, type OrderDirection, type OrderKey, type OrderTerm, type OrderTerms, type Ordering, type PatternSignature, type Predicate, type PrimaryKeyValues, type QueryContext, type QueryResult, type QueryState, type QueryStateOf, type QueryValueType, type RecordQuery, type RecordQueryState, type Relation, type RelationDeclaration, type RelationDeclarations, type RelationKey, type RelationKeys, type RelationKind, type RelationRefs, type RequiredMember, RequiredRelationError, type ResultByRows, ResultDecodeError, type ResultMode, type ResultOf, type ResultRows, type ScalarQuery, type Schema, type SchemaContext, type SchemaPart, type SchemaPartRelations, type SchemaRelations, type SchemaTables, type SelectQuery, type SelectQueryKind, type SelectQueryState, type Selectable, type SelectedRefs, type Selection, type SelectionResult, type SelectionState, type SelectionUses, type SqlQuery, type SqlQueryState, type SqlStatement, type SqlTemplate, TRUE, type Table, type TableContext, type TableKeys, type TableOptions, type TableRelations, type Tables, type TextConversionSignature, type TextLengthSignature, type TextOperators, type TextTypeOperators, type TextValue, type ToColumn, type ToColumns, type TransactionCoordinator, type TransactionFailure, type TransactionOptions, type Type, type TypeInput, type TypeOperators, type TypeOptions, type TypeOutput, type TypeTransform, type TypedExpression, type TypedOperand, type TypedOperandInput, type TypedOperandOperators, type TypedScalarQuery, type UntypedExpression, type UpdateSet, type UpdateValues, type UsableRelation, type UsedRelation, type ValueRows, type ValuesQuery, type WhereCallback, type WhereCondition, type WhereFilter, type WhereValues, and, asc, caseWhen, coalesce, compare, createDatabase, createStatement, defineExpression, defineGenericOperator, defineHelper, defineSchema, defineTable, defineType, desc, equalityOperators, from, greatest, identifier, least, literal, many, matches, not, one, or, orderBy, orderingOperators, param, sql, textOperators };
|
|
1
|
+
import { $ as NoRelations, $n as UpdateSet, $r as AnyTableKeys, $t as least, A as Db, Ai as TypeOptions, An as some, Ar as CompileOptions, At as DecodedFields, Bi as MergeOperators, Bn as asc, Br as compare, Bt as HelperEffect, C as BaseOperators, Ci as createStatement, Cn as UnfilteredStringAggOptions, Cr as FilteredRows, Ct as AnyRecordQuery, D as UntypedExpression, Di as Type, Dn as every, Dr as ResultByRows, Dt as AnyQuery, E as TypedExpression, Ei as TextValue, En as countDistinct, Er as QueryResult, Et as SelectionState, F as DatabaseOptions, Fi as Column, Fn as OrderKey, Fr as equalityOperators, Ft as AnyMutationQuery, Gi as OperatorSignature, Gn as RelationRefs, Gr as EmptyRecord, Gt as FollowingOperand, Hi as OperatorDefinitions, Hn as orderBy, Hr as ScalarQuery, Ht as CaseBranch, I as TransactionOptions, Ii as ColumnAttributes, In as OrderTerm, Ir as BooleanResult, It as InitialMutationState, J as SynchronousResult, Jn as ResultOf, Jr as QueryState, Jt as TypedOperandInput, K as AnyTransformedQuery, Ki as defineGenericOperator, Kn as AnySelectQuery, Kr as Grouped, Kt as NullSkippingResult, L as createDatabase, Li as KeyKind, Ln as OrderTerms, Lr as ComparisonSignature, Lt as MutationQuery, M as DbOf, Mi as TypeTransform, Mn as sum, Mr as EqualityOperators, Mt as InitialSqlQueryState, N as DbQueryState, Ni as defineType, Nn as OrderColumns, Nr as HasEquality, Nt as SqlQuery, O as AnyDb, Oi as TypeInput, On as max, Or as ValueRows, Ot as SelectQueryKind, P as Database, Pi as AnyColumn, Pn as OrderDirection, Pr as InSignature, Pt as SqlQueryState, Q as MergeRelations, Qn as InsertValues, Qr as AnyTable, Qt as greatest, R as TransactionCoordinator, Ri as ToColumn, Rn as Ordering, Rr as Operand, Rt as MutationQueryState, S as AnyExpression, Si as TransactionFailure, Sn as UnfilteredAggregateOptions, Sr as ExistsValueType, St as defineSchema, T as ExpressionOperators, Ti as BaseType, Tn as count, Tr as OneValueRows, Tt as RecordQueryState, Ui as GenericOperator, Un as ColumnRefs, Ur as TypedScalarQuery, Ut as CaseCondition, Vi as NoOperators, Vn as desc, Vr as OperandUses, Vt as defineHelper, Wi as GenericOperatorImplementation, Wn as QueryContext, Wr as ValuesQuery, Wt as CaseValue, X as TransformedQueryState, Xn as from, Xr as QueryValueType, Xt as caseWhen, Y as TransformedQuery, Yn as SelectQuery, Yr as QueryStateOf, Yt as TypedOperandOperators, Z as DeclaredRelations, Zn as ColumnValue, Zr as SelectQueryState, Zt as coalesce, _ as TextOperators, _i as ResultRows, _n as AggregateOptions, _r as ConditionOperand, _t as Schema, a as sql, ai as Selectable, an as GroupedField, ar as GroupTerm, at as RelationKeys, b as NumberTypeOperators, bi as DriverResult, bn as GroupValue, br as not, bt as SchemaTables, c as MatchResult, ci as TableKeys, cn as NestedQuery, cr as NotAKey, ct as SchemaContext, d as defineExpression, di as createTableFactory, dn as SelectionFieldTypes, dr as WhereCallback, dt as TableRelations, ei as ColumnDefinitions, en as ColumnFieldTypes, er as UpdateValues, et as OneRelationKeys, f as FALSE, fi as defineTable, fn as SelectionResult, fr as WhereCondition, ft as UsableRelation, g as TextLengthSignature, gi as ResultMode, gn as AggregateExpression, gr as Condition, gt as AnySchema, h as TextConversionSignature, hi as ResultDecodeError, hn as literal, hr as CombinedCondition, ht as one, i as param, ii as KeyColumns, in as GroupSelectionResult, ir as RowLockOptions, it as RelationKey, j as DbMutationState, ji as TypeOutput, jn as stringAgg, jr as EqualityOperator, jt as FieldTypes, k as BindOptions, ki as TypeOperators, kn as min, kr as CountValueType, kt as AnySqlQuery, l as NotAColumn, li as TableOptions, ln as SelectedFieldTypes, lr as PrimaryKeyValues, lt as SchemaRelations, m as PatternSignature, mi as RequiredRelationError, mn as Literal, mr as WhereValues, mt as many, n as SqlTemplate, ni as ColumnShape, nn as ExpressionValue, nr as GroupedState, nt as RelationDeclaration, o as ColumnRefKey, oi as Table, on as GroupedRecord, or as GroupTerms, ot as RelationKind, p as TRUE, pi as NotFoundError, pn as SelectionUses, pr as WhereFilter, pt as UsedRelation, q as NotSynchronous, qn as BoundSelectQuery, qr as InitialQueryState, qt as TypedOperand, r as identifier, ri as ColumnValues, rn as GroupOperandValue, rr as SelectedOperandType, rt as RelationDeclarations, s as MatchCheck, si as TableFactoryOptions, sn as MergeSelection, sr as KeyCheck, st as RequiredMember, t as toSnakeCase, ti as ColumnOperators, tn as ExpressionInput, tr as FilteredStateRows, tt as Relation, u as matches, ui as ToColumns, un as Selection, ur as EqValue, ut as TableContext, v as TextTypeOperators, vi as Connection, vn as CountExpression, vr as Predicate, vt as SchemaPart, w as Expression, wi as AnyType, wn as avg, wr as OneRow, wt as RecordQuery, x as orderingOperators, xi as SqlStatement, xn as StringAggOptions, xr as or, xt as Tables, y as textOperators, yi as Driver, yn as GroupAggregateExpression, yr as and, yt as SchemaPartRelations, zi as BoundOperators, zn as SelectedRefs, zr as OperandValue, zt as Helper } from "./index-CoKpXcBp.mjs";
|
|
2
|
+
export { type AggregateExpression, type AggregateOptions, type AnyColumn, type AnyDb, type AnyExpression, type AnyMutationQuery, type AnyQuery, type AnyRecordQuery, type AnySchema, type AnySelectQuery, type AnySqlQuery, type AnyTable, type AnyTableKeys, type AnyTransformedQuery, type AnyType, type BaseOperators, type BaseType, type BindOptions, type BooleanResult, type BoundOperators, type BoundSelectQuery, type CaseBranch, type CaseCondition, type CaseValue, type Column, type ColumnAttributes, type ColumnDefinitions, type ColumnFieldTypes, type ColumnOperators, type ColumnRefKey, type ColumnRefs, type ColumnShape, type ColumnValue, type ColumnValues, type CombinedCondition, type ComparisonSignature, type CompileOptions, type Condition, type ConditionOperand, type Connection, type CountExpression, type CountValueType, type Database, type DatabaseOptions, type Db, type DbMutationState, type DbOf, type DbQueryState, type DeclaredRelations, type DecodedFields, type Driver, type DriverResult, type EmptyRecord, type EqValue, type EqualityOperator, type EqualityOperators, type ExistsValueType, type Expression, type ExpressionInput, type ExpressionOperators, type ExpressionValue, FALSE, type FieldTypes, type FilteredRows, type FilteredStateRows, type FollowingOperand, type GenericOperator, type GenericOperatorImplementation, type GroupAggregateExpression, type GroupOperandValue, type GroupSelectionResult, type GroupTerm, type GroupTerms, type GroupValue, type Grouped, type GroupedField, type GroupedRecord, type GroupedState, type HasEquality, type Helper, type HelperEffect, type InSignature, type InitialMutationState, type InitialQueryState, type InitialSqlQueryState, type InsertValues, type KeyCheck, type KeyColumns, type KeyKind, type Literal, type MatchCheck, type MatchResult, type MergeOperators, type MergeRelations, type MergeSelection, type MutationQuery, type MutationQueryState, type NestedQuery, type NoOperators, type NoRelations, type NotAColumn, type NotAKey, NotFoundError, type NotSynchronous, type NullSkippingResult, type NumberTypeOperators, type OneRelationKeys, type OneRow, type OneValueRows, type Operand, type OperandUses, type OperandValue, type OperatorDefinitions, type OperatorSignature, type OrderColumns, type OrderDirection, type OrderKey, type OrderTerm, type OrderTerms, type Ordering, type PatternSignature, type Predicate, type PrimaryKeyValues, type QueryContext, type QueryResult, type QueryState, type QueryStateOf, type QueryValueType, type RecordQuery, type RecordQueryState, type Relation, type RelationDeclaration, type RelationDeclarations, type RelationKey, type RelationKeys, type RelationKind, type RelationRefs, type RequiredMember, RequiredRelationError, type ResultByRows, ResultDecodeError, type ResultMode, type ResultOf, type ResultRows, type RowLockOptions, type ScalarQuery, type Schema, type SchemaContext, type SchemaPart, type SchemaPartRelations, type SchemaRelations, type SchemaTables, type SelectQuery, type SelectQueryKind, type SelectQueryState, type Selectable, type SelectedFieldTypes, type SelectedOperandType, type SelectedRefs, type Selection, type SelectionFieldTypes, type SelectionResult, type SelectionState, type SelectionUses, type SqlQuery, type SqlQueryState, type SqlStatement, type SqlTemplate, type StringAggOptions, type SynchronousResult, TRUE, type Table, type TableContext, type TableFactoryOptions, type TableKeys, type TableOptions, type TableRelations, type Tables, type TextConversionSignature, type TextLengthSignature, type TextOperators, type TextTypeOperators, type TextValue, type ToColumn, type ToColumns, type TransactionCoordinator, type TransactionFailure, type TransactionOptions, type TransformedQuery, type TransformedQueryState, type Type, type TypeInput, type TypeOperators, type TypeOptions, type TypeOutput, type TypeTransform, type TypedExpression, type TypedOperand, type TypedOperandInput, type TypedOperandOperators, type TypedScalarQuery, type UnfilteredAggregateOptions, type UnfilteredStringAggOptions, type UntypedExpression, type UpdateSet, type UpdateValues, type UsableRelation, type UsedRelation, type ValueRows, type ValuesQuery, type WhereCallback, type WhereCondition, type WhereFilter, type WhereValues, and, asc, avg, caseWhen, coalesce, compare, count, countDistinct, createDatabase, createStatement, createTableFactory, defineExpression, defineGenericOperator, defineHelper, defineSchema, defineTable, defineType, desc, equalityOperators, every, from, greatest, identifier, least, literal, many, matches, max, min, not, one, or, orderBy, orderingOperators, param, some, sql, stringAgg, sum, textOperators, toSnakeCase };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as
|
|
2
|
-
import {
|
|
1
|
+
import { B as noOrder, C as toNode, D as isType, E as defineType, F as createNode, L as falseNode, N as defineGenericOperator, P as createList, S as toFunctionOperandNode, T as getBooleanType, U as trueNode, _ as isOperandSource, b as toCastValueNode, c as textOperators, d as orderingOperators, f as compare, g as isExpression, h as getType, k as equalityOperators, v as operandNode, x as toExpression, y as toBooleanExpression } from "./text-Cti9QLK7.mjs";
|
|
2
|
+
import { A as not, C as countType, D as literal, E as toAggregateType, M as combineNodes, O as and, S as countProjection, T as createCountCall, _ as createTableFactory, a as defineSchema, b as RequiredRelationError, c as requireDerived, d as desc, f as orderBy, g as createStatement, h as one, i as sql, j as or, k as isColumnValues, l as addTerms, m as many, n as identifier, o as SelectQuery, p as matchColumn, r as param, s as from, t as createDatabase, u as asc, v as defineTable, w as createAggregateCall, x as ResultDecodeError, y as NotFoundError } from "./database-CP4oapsQ.mjs";
|
|
3
3
|
// src/expression/constants.ts
|
|
4
4
|
/** Condition that always holds, such as for a branch of `and` built in code: `and(check, isAdmin ? TRUE : other)`. */
|
|
5
5
|
const TRUE = /* @__PURE__ */ toExpression(trueNode, /* @__PURE__ */ getBooleanType());
|
|
@@ -42,18 +42,91 @@ function toCaseConditionNode(condition) {
|
|
|
42
42
|
}
|
|
43
43
|
/** Creates the expression of the call of the SQL function `name`, of the type of its first operand. */
|
|
44
44
|
function callFunction(name, first, rest) {
|
|
45
|
-
const expression = toTypedExpression(first, name);
|
|
45
|
+
const expression = toTypedExpression(first, `The first operand of ${name}`);
|
|
46
46
|
const type = getType(expression);
|
|
47
47
|
const operands = [toNode(expression)];
|
|
48
48
|
for (const value of rest) operands.push(toFunctionOperandNode(value, type, name));
|
|
49
49
|
return toExpression(createList(`${name}(`, operands, ")"), type);
|
|
50
50
|
}
|
|
51
|
-
/** Converts
|
|
52
|
-
function toTypedExpression(value,
|
|
51
|
+
/** Converts an operand, which the error names as `subject`, into an expression with a type, rejecting any other value. */
|
|
52
|
+
function toTypedExpression(value, subject) {
|
|
53
53
|
const expression = value instanceof SelectQuery ? value.expr() : value;
|
|
54
|
-
if (!isExpression(expression) || getType(expression) === void 0) throw new TypeError(
|
|
54
|
+
if (!isExpression(expression) || getType(expression) === void 0) throw new TypeError(`${subject} must be a query of one value of a table or an expression with a type to decode the result; build a sql fragment with a type, such as sql(t.integer)`);
|
|
55
55
|
return expression;
|
|
56
56
|
}
|
|
57
|
+
// src/expression/aggregates.ts
|
|
58
|
+
function count(...values) {
|
|
59
|
+
if (values.length === 0) return toExpression(countProjection.expression, countType);
|
|
60
|
+
const first = values[0];
|
|
61
|
+
if (values.length === 1 && isOptions(first)) {
|
|
62
|
+
const filter = readFilter(first, "count");
|
|
63
|
+
return toExpression(filter === void 0 ? countProjection.expression : createCountCall(filter), countType);
|
|
64
|
+
}
|
|
65
|
+
return callAggregate("count", first, values[1]);
|
|
66
|
+
}
|
|
67
|
+
function countDistinct(value, options) {
|
|
68
|
+
return callAggregate("countDistinct", value, options);
|
|
69
|
+
}
|
|
70
|
+
function min(value, options) {
|
|
71
|
+
return callAggregate("min", value, options);
|
|
72
|
+
}
|
|
73
|
+
function max(value, options) {
|
|
74
|
+
return callAggregate("max", value, options);
|
|
75
|
+
}
|
|
76
|
+
function sum(value, options) {
|
|
77
|
+
return callAggregate("sum", value, options);
|
|
78
|
+
}
|
|
79
|
+
function avg(value, options) {
|
|
80
|
+
return callAggregate("avg", value, options);
|
|
81
|
+
}
|
|
82
|
+
function every(value, options) {
|
|
83
|
+
return callAggregate("every", value, options);
|
|
84
|
+
}
|
|
85
|
+
function some(value, options) {
|
|
86
|
+
return callAggregate("some", value, options);
|
|
87
|
+
}
|
|
88
|
+
function stringAgg(value, delimiter, options) {
|
|
89
|
+
if (typeof delimiter !== "string") throw new TypeError("The delimiter of stringAgg must be a string");
|
|
90
|
+
return callAggregate("stringAgg", value, options, delimiter);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Creates the expression of the aggregate of `method` over the values of `value`, of the type that decodes its value, with the options of `options`.
|
|
94
|
+
*
|
|
95
|
+
* `delimiter` is the delimiter of `stringAgg`, whose options also take `orderBy`.
|
|
96
|
+
*/
|
|
97
|
+
function callAggregate(method, value, options, delimiter) {
|
|
98
|
+
const expression = toTypedExpression(value, `The argument of ${method}`);
|
|
99
|
+
const filter = readFilter(options, method);
|
|
100
|
+
let orderBy = noOrder;
|
|
101
|
+
const terms = method === "stringAgg" ? options?.orderBy : void 0;
|
|
102
|
+
if (terms !== void 0) {
|
|
103
|
+
const order = [];
|
|
104
|
+
addTerms(order, terms, "The option orderBy of stringAgg takes");
|
|
105
|
+
orderBy = order;
|
|
106
|
+
}
|
|
107
|
+
return toExpression(createAggregateCall(method, toNode(expression), delimiter, orderBy, filter), toAggregateType(method, getType(expression)));
|
|
108
|
+
}
|
|
109
|
+
/** Tells whether `value` is an object of options rather than an argument: a plain object, of this or another realm, other than an expression. */
|
|
110
|
+
function isOptions(value) {
|
|
111
|
+
if (typeof value !== "object" || value === null || isOperandSource(value)) return false;
|
|
112
|
+
const prototype = Object.getPrototypeOf(value);
|
|
113
|
+
return prototype === null || Object.getPrototypeOf(prototype) === null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Returns the node of the condition of `options`, the options of the aggregate function `method`, or `undefined` without options or a condition.
|
|
117
|
+
*
|
|
118
|
+
* It rejects options other than a plain object and a key other than the options of `method`, so that an object of column values passed instead of an argument fails rather than leaving the rows unfiltered.
|
|
119
|
+
* It rejects a condition other than an expression or a query of one value, such as an object of column values, which has no table to resolve against there.
|
|
120
|
+
*/
|
|
121
|
+
function readFilter(options, method) {
|
|
122
|
+
if (options === void 0) return;
|
|
123
|
+
if (!isOptions(options)) throw new TypeError(`The options of ${method} must be a plain object`);
|
|
124
|
+
for (const key of Object.keys(options)) if (key !== "filter" && (key !== "orderBy" || method !== "stringAgg")) throw new TypeError(`${method} has no option ${JSON.stringify(key)}`);
|
|
125
|
+
const { filter } = options;
|
|
126
|
+
if (filter === void 0) return;
|
|
127
|
+
if (!isOperandSource(filter)) throw new TypeError(`The filter of ${method} must be an expression or a query of one Boolean value`);
|
|
128
|
+
return filter[operandNode]();
|
|
129
|
+
}
|
|
57
130
|
// src/query/reusable-expression.ts
|
|
58
131
|
function defineExpression(_table, expression) {
|
|
59
132
|
return expression;
|
|
@@ -74,4 +147,14 @@ function matches(columns, values) {
|
|
|
74
147
|
function defineHelper(_table, helper) {
|
|
75
148
|
return (query, ...args) => requireDerived(query, helper(query, ...args), "The callback of a helper");
|
|
76
149
|
}
|
|
77
|
-
|
|
150
|
+
// src/table/snake-case.ts
|
|
151
|
+
const wordStart = /(?<=[\p{Ll}\p{N}])(?=\p{Lu})|(?<=\p{Lu})(?=\p{Lu}(?!s$)\p{Ll})/gu;
|
|
152
|
+
/**
|
|
153
|
+
* Converts a column key to snake case, such as `form_id` for `formId`, for the `columnName` option of `createTableFactory`.
|
|
154
|
+
*
|
|
155
|
+
* A run of capital letters is one word, such as `user_id` for `userID`, and digits stay in their word, such as `line2`.
|
|
156
|
+
*/
|
|
157
|
+
function toSnakeCase(key) {
|
|
158
|
+
return key.replace(wordStart, "_").toLowerCase();
|
|
159
|
+
}
|
|
160
|
+
export { FALSE, NotFoundError, RequiredRelationError, ResultDecodeError, TRUE, and, asc, avg, caseWhen, coalesce, compare, count, countDistinct, createDatabase, createStatement, createTableFactory, defineExpression, defineGenericOperator, defineHelper, defineSchema, defineTable, defineType, desc, equalityOperators, every, from, greatest, identifier, least, literal, many, matches, max, min, not, one, or, orderBy, orderingOperators, param, some, sql, stringAgg, sum, textOperators, toSnakeCase };
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as PendingTestFixture, G as createTestHelpers, H as TestHelpers, U as TestHooks, V as TestFixture, W as TestTransactionOptions, yi as Driver, z as OpenedTestFixture } from "./index-CoKpXcBp.mjs";
|
|
2
2
|
/** Options of `describeDriverContract`: how to create the driver under test. */
|
|
3
3
|
interface DriverContractOptions {
|
|
4
4
|
/** Creates a driver over a new client of the test database with `max` connections. */
|
package/dist/testing.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as text, t as char } from "./text-
|
|
2
|
-
import { a as defineSchema, g as
|
|
3
|
-
import { _ as timestamptz, a as numeric, b as array, d as jsonb, f as enumOf, g as timestamp, h as time, i as integer, l as inet, m as interval, n as bigint, p as date, r as doublePrecision, t as uuid, v as boolean, y as bytea } from "./types-
|
|
1
|
+
import { n as text, t as char } from "./text-Cti9QLK7.mjs";
|
|
2
|
+
import { O as and, a as defineSchema, g as createStatement, i as sql, r as param, t as createDatabase, v as defineTable } from "./database-CP4oapsQ.mjs";
|
|
3
|
+
import { _ as timestamptz, a as numeric, b as array, d as jsonb, f as enumOf, g as timestamp, h as time, i as integer, l as inet, m as interval, n as bigint, p as date, r as doublePrecision, t as uuid, v as boolean, y as bytea } from "./types-DfoL8Oi9.mjs";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
// src/execution/testing.ts
|
|
6
6
|
/** Creates the test helpers of a database created with `test: true`, registering fixtures with the hooks of a test runner. */
|
|
@@ -142,6 +142,15 @@ function describeDriverContract(options, runner) {
|
|
|
142
142
|
assert.deepEqual(selected.columns, ["id", "label"]);
|
|
143
143
|
assert.deepEqual(selected.rows, []);
|
|
144
144
|
});
|
|
145
|
+
it("reports no command for a statement without a command tag", async () => {
|
|
146
|
+
for (const text of ["", "-- only a comment"]) {
|
|
147
|
+
const { command, count, columns, rows } = await database.execute(createStatement(text));
|
|
148
|
+
assert.equal(command, null);
|
|
149
|
+
assert.equal(count, 0);
|
|
150
|
+
assert.deepEqual(columns, []);
|
|
151
|
+
assert.deepEqual(rows, []);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
145
154
|
it("infers the types of parameters from the statement", async () => {
|
|
146
155
|
assert.equal(await selectValue("SELECT $1::integer + $2", ["1", "2"]), "3");
|
|
147
156
|
assert.equal(await selectValue("SELECT $1", ["text"]), "text");
|
|
@@ -21,6 +21,12 @@ function createList(prefix, items, suffix) {
|
|
|
21
21
|
}
|
|
22
22
|
/** Filters of a query without conditions. */
|
|
23
23
|
const noFilters = /* @__PURE__ */ Object.freeze({});
|
|
24
|
+
/** Order without sort keys. */
|
|
25
|
+
const noOrder = /* @__PURE__ */ Object.freeze([]);
|
|
26
|
+
/** Joins of a query that reads only its source. */
|
|
27
|
+
const noJoins = /* @__PURE__ */ Object.freeze([]);
|
|
28
|
+
/** Projections of a query that selects nothing, such as the query of `EXISTS`. */
|
|
29
|
+
const noProjections = /* @__PURE__ */ Object.freeze([]);
|
|
24
30
|
/** Creates a query of all rows of `from` with `projections`. */
|
|
25
31
|
function createSelectNode(from, projections = []) {
|
|
26
32
|
return Object.freeze({
|
|
@@ -484,4 +490,4 @@ const text = /* @__PURE__ */ getTextType();
|
|
|
484
490
|
const varchar = /* @__PURE__ */ defineTextType("varchar").withParameters((length) => formatTypeName("varchar", length));
|
|
485
491
|
/** Fixed-length string that PostgreSQL pads with spaces; `char` alone has length 1, and `char.with(length)` sets the length. */
|
|
486
492
|
const char = /* @__PURE__ */ defineTextType("char", "bpchar").withParameters((length) => formatTypeName("char", length));
|
|
487
|
-
export { hasEquality as A,
|
|
493
|
+
export { hasEquality as A, noOrder as B, toNode as C, isType as D, defineType as E, createNode as F, oneNode as H, createSelectNode as I, falseNode as L, valuesQueryNode as M, defineGenericOperator as N, Column as O, createList as P, noFilters as R, toFunctionOperandNode as S, getBooleanType as T, trueNode as U, noProjections as V, isOperandSource as _, stringifyJson as a, toCastValueNode as b, textOperators as c, orderingOperators as d, compare as f, isExpression as g, getType as h, formatTypeName as i, isEqualityCompatible as j, equalityOperators as k, defineNumberType as l, createIsNullNode as m, text as n, decodeBytea as o, compareNodes as p, varchar as r, encodeBytea as s, char as t, getIntegerType as u, operandNode as v, toValueNode as w, toExpression as x, toBooleanExpression as y, noJoins as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as hasEquality, E as defineType, T as getBooleanType, a as stringifyJson, d as orderingOperators, i as formatTypeName, k as equalityOperators, l as defineNumberType, o as decodeBytea, s as encodeBytea, u as getIntegerType } from "./text-
|
|
1
|
+
import { A as hasEquality, E as defineType, T as getBooleanType, a as stringifyJson, d as orderingOperators, i as formatTypeName, k as equalityOperators, l as defineNumberType, o as decodeBytea, s as encodeBytea, u as getIntegerType } from "./text-Cti9QLK7.mjs";
|
|
2
2
|
// src/type/builtins/array.ts
|
|
3
3
|
/**
|
|
4
4
|
* Creates a one-dimensional array type of `element` values.
|
package/dist/types.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Bi as MergeOperators, Di as Type, Hi as OperatorDefinitions, Lr as ComparisonSignature, Mr as EqualityOperators, Nr as HasEquality, Pr as InSignature, S as AnyExpression, Ti as BaseType, Ui as GenericOperator, Vi as NoOperators, _ as TextOperators, b as NumberTypeOperators, jr as EqualityOperator, v as TextTypeOperators } from "./index-CoKpXcBp.mjs";
|
|
2
2
|
/**
|
|
3
3
|
* Creates a one-dimensional array type of `element` values.
|
|
4
4
|
*
|
package/dist/types.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as text, r as varchar, t as char } from "./text-
|
|
2
|
-
import { _ as timestamptz, a as numeric, b as array, c as cidr, d as jsonb, f as enumOf, g as timestamp, h as time, i as integer, l as inet, m as interval, n as bigint, o as real, p as date, r as doublePrecision, s as smallint, t as uuid, u as json, v as boolean, y as bytea } from "./types-
|
|
1
|
+
import { n as text, r as varchar, t as char } from "./text-Cti9QLK7.mjs";
|
|
2
|
+
import { _ as timestamptz, a as numeric, b as array, c as cidr, d as jsonb, f as enumOf, g as timestamp, h as time, i as integer, l as inet, m as interval, n as bigint, o as real, p as date, r as doublePrecision, s as smallint, t as uuid, u as json, v as boolean, y as bytea } from "./types-DfoL8Oi9.mjs";
|
|
3
3
|
export { array, bigint, boolean, bytea, char, cidr, date, doublePrecision, enumOf as enum, inet, integer, interval, json, jsonb, numeric, real, smallint, text, time, timestamp, timestamptz, uuid, varchar };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kern-orm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Fully typed relational query builder for PostgreSQL with ambient transactions and single-query relation loading",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"orm",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"kern-orm-0.2.0": "https://registry.npmjs.org/kern-orm/-/kern-orm-0.2.0.tgz",
|
|
46
46
|
"kern-orm-0.3.0": "https://registry.npmjs.org/kern-orm/-/kern-orm-0.3.0.tgz",
|
|
47
47
|
"migrations-published": "https://registry.npmjs.org/@kern-orm/migrations/-/migrations-0.3.1.tgz",
|
|
48
|
+
"node-postgres-published": "https://registry.npmjs.org/@kern-orm/node-postgres/-/node-postgres-0.1.0.tgz",
|
|
48
49
|
"postgres": "catalog:",
|
|
49
50
|
"postgres-js-published": "https://registry.npmjs.org/@kern-orm/postgres-js/-/postgres-js-0.1.2.tgz",
|
|
50
51
|
"postgres-js-v3-published": "https://registry.npmjs.org/@kern-orm/postgres-js-v3/-/postgres-js-v3-0.1.2.tgz",
|