durcno 1.0.0-alpha.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/LICENSE +201 -0
- package/README.md +56 -0
- package/dist/bin.cjs +13522 -0
- package/dist/src/_virtual/_rolldown/runtime.mjs +28 -0
- package/dist/src/cli/helpers.mjs +16 -0
- package/dist/src/columns/bigint.d.mts +19 -0
- package/dist/src/columns/bigint.mjs +32 -0
- package/dist/src/columns/bigserial.d.mts +24 -0
- package/dist/src/columns/bigserial.mjs +35 -0
- package/dist/src/columns/boolean.d.mts +19 -0
- package/dist/src/columns/boolean.mjs +31 -0
- package/dist/src/columns/bytea.d.mts +19 -0
- package/dist/src/columns/bytea.mjs +33 -0
- package/dist/src/columns/char.d.mts +32 -0
- package/dist/src/columns/char.mjs +44 -0
- package/dist/src/columns/cidr.d.mts +19 -0
- package/dist/src/columns/cidr.mjs +31 -0
- package/dist/src/columns/common.d.mts +233 -0
- package/dist/src/columns/common.mjs +276 -0
- package/dist/src/columns/date.d.mts +19 -0
- package/dist/src/columns/date.mjs +32 -0
- package/dist/src/columns/enum.d.mts +21 -0
- package/dist/src/columns/enum.mjs +35 -0
- package/dist/src/columns/inet.d.mts +19 -0
- package/dist/src/columns/inet.mjs +36 -0
- package/dist/src/columns/integer.d.mts +19 -0
- package/dist/src/columns/integer.mjs +32 -0
- package/dist/src/columns/json.d.mts +52 -0
- package/dist/src/columns/json.mjs +67 -0
- package/dist/src/columns/jsonb.d.mts +53 -0
- package/dist/src/columns/jsonb.mjs +68 -0
- package/dist/src/columns/macaddr.d.mts +19 -0
- package/dist/src/columns/macaddr.mjs +31 -0
- package/dist/src/columns/numeric.d.mts +42 -0
- package/dist/src/columns/numeric.mjs +57 -0
- package/dist/src/columns/postgis/geography/index.d.mts +18 -0
- package/dist/src/columns/postgis/geography/index.mjs +17 -0
- package/dist/src/columns/postgis/geography/linestring.d.mts +38 -0
- package/dist/src/columns/postgis/geography/linestring.mjs +70 -0
- package/dist/src/columns/postgis/geography/multilinestring.d.mts +39 -0
- package/dist/src/columns/postgis/geography/multilinestring.mjs +70 -0
- package/dist/src/columns/postgis/geography/multipoint.d.mts +38 -0
- package/dist/src/columns/postgis/geography/multipoint.mjs +70 -0
- package/dist/src/columns/postgis/geography/multipolygon.d.mts +40 -0
- package/dist/src/columns/postgis/geography/multipolygon.mjs +70 -0
- package/dist/src/columns/postgis/geography/point.d.mts +36 -0
- package/dist/src/columns/postgis/geography/point.mjs +69 -0
- package/dist/src/columns/postgis/geography/polygon.d.mts +39 -0
- package/dist/src/columns/postgis/geography/polygon.mjs +70 -0
- package/dist/src/columns/serial.d.mts +24 -0
- package/dist/src/columns/serial.mjs +35 -0
- package/dist/src/columns/smallint.d.mts +19 -0
- package/dist/src/columns/smallint.mjs +32 -0
- package/dist/src/columns/smallserial.d.mts +24 -0
- package/dist/src/columns/smallserial.mjs +35 -0
- package/dist/src/columns/text.d.mts +19 -0
- package/dist/src/columns/text.mjs +30 -0
- package/dist/src/columns/time.d.mts +44 -0
- package/dist/src/columns/time.mjs +47 -0
- package/dist/src/columns/timestamp.d.mts +44 -0
- package/dist/src/columns/timestamp.mjs +47 -0
- package/dist/src/columns/uuid.d.mts +33 -0
- package/dist/src/columns/uuid.mjs +44 -0
- package/dist/src/columns/varchar.d.mts +32 -0
- package/dist/src/columns/varchar.mjs +44 -0
- package/dist/src/connectors/bun.d.mts +18 -0
- package/dist/src/connectors/bun.mjs +97 -0
- package/dist/src/connectors/common.d.mts +148 -0
- package/dist/src/connectors/common.mjs +65 -0
- package/dist/src/connectors/pg.d.mts +18 -0
- package/dist/src/connectors/pg.mjs +103 -0
- package/dist/src/connectors/pglite.d.mts +19 -0
- package/dist/src/connectors/pglite.mjs +94 -0
- package/dist/src/connectors/postgres.d.mts +18 -0
- package/dist/src/connectors/postgres.mjs +93 -0
- package/dist/src/constraints/check.d.mts +88 -0
- package/dist/src/constraints/check.mjs +307 -0
- package/dist/src/constraints/primary-key.d.mts +28 -0
- package/dist/src/constraints/primary-key.mjs +36 -0
- package/dist/src/constraints/unique.d.mts +28 -0
- package/dist/src/constraints/unique.mjs +36 -0
- package/dist/src/db.d.mts +180 -0
- package/dist/src/db.mjs +191 -0
- package/dist/src/entity.mjs +23 -0
- package/dist/src/enumtype.d.mts +27 -0
- package/dist/src/enumtype.mjs +42 -0
- package/dist/src/filters/array.d.mts +97 -0
- package/dist/src/filters/array.mjs +150 -0
- package/dist/src/filters/custom.d.mts +12 -0
- package/dist/src/filters/custom.mjs +7 -0
- package/dist/src/filters/index.d.mts +155 -0
- package/dist/src/filters/index.mjs +318 -0
- package/dist/src/functions/index.d.mts +24 -0
- package/dist/src/functions/index.mjs +29 -0
- package/dist/src/index.d.mts +129 -0
- package/dist/src/index.mjs +78 -0
- package/dist/src/indexes.d.mts +31 -0
- package/dist/src/indexes.mjs +43 -0
- package/dist/src/migration/consts.d.mts +8 -0
- package/dist/src/migration/consts.mjs +8 -0
- package/dist/src/migration/ddl.d.mts +747 -0
- package/dist/src/migration/ddl.mjs +1084 -0
- package/dist/src/migration/index.d.mts +15 -0
- package/dist/src/migration/index.mjs +5 -0
- package/dist/src/migration/snapshot.d.mts +169 -0
- package/dist/src/migration/snapshot.mjs +123 -0
- package/dist/src/migration/statement.d.mts +89 -0
- package/dist/src/migration/statement.mjs +61 -0
- package/dist/src/models.d.mts +34 -0
- package/dist/src/models.mjs +27 -0
- package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.mjs +126 -0
- package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.mjs +29 -0
- package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.mjs +165 -0
- package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.mjs +92 -0
- package/dist/src/query-builders/aggregates.d.mts +20 -0
- package/dist/src/query-builders/aggregates.mjs +43 -0
- package/dist/src/query-builders/count.d.mts +19 -0
- package/dist/src/query-builders/count.mjs +36 -0
- package/dist/src/query-builders/delete.d.mts +19 -0
- package/dist/src/query-builders/delete.mjs +57 -0
- package/dist/src/query-builders/distinct.d.mts +19 -0
- package/dist/src/query-builders/distinct.mjs +42 -0
- package/dist/src/query-builders/exists.d.mts +19 -0
- package/dist/src/query-builders/exists.mjs +37 -0
- package/dist/src/query-builders/first.d.mts +17 -0
- package/dist/src/query-builders/first.mjs +46 -0
- package/dist/src/query-builders/insert-returning.d.mts +16 -0
- package/dist/src/query-builders/insert-returning.mjs +63 -0
- package/dist/src/query-builders/insert.d.mts +22 -0
- package/dist/src/query-builders/insert.mjs +93 -0
- package/dist/src/query-builders/orderby-clause.d.mts +14 -0
- package/dist/src/query-builders/orderby-clause.mjs +20 -0
- package/dist/src/query-builders/pre.d.mts +36 -0
- package/dist/src/query-builders/pre.mjs +60 -0
- package/dist/src/query-builders/query-promise.d.mts +14 -0
- package/dist/src/query-builders/query-promise.mjs +21 -0
- package/dist/src/query-builders/query.d.mts +14 -0
- package/dist/src/query-builders/query.mjs +17 -0
- package/dist/src/query-builders/raw.d.mts +14 -0
- package/dist/src/query-builders/raw.mjs +26 -0
- package/dist/src/query-builders/rq.d.mts +36 -0
- package/dist/src/query-builders/rq.mjs +231 -0
- package/dist/src/query-builders/select.d.mts +48 -0
- package/dist/src/query-builders/select.mjs +118 -0
- package/dist/src/query-builders/update.d.mts +24 -0
- package/dist/src/query-builders/update.mjs +99 -0
- package/dist/src/sequence.d.mts +48 -0
- package/dist/src/sequence.mjs +53 -0
- package/dist/src/sql.d.mts +15 -0
- package/dist/src/sql.mjs +36 -0
- package/dist/src/symbols.d.mts +4 -0
- package/dist/src/symbols.mjs +4 -0
- package/dist/src/table.d.mts +144 -0
- package/dist/src/table.mjs +134 -0
- package/dist/src/types.d.mts +4 -0
- package/dist/src/utils.mjs +10 -0
- package/dist/src/validators/zod.d.mts +23 -0
- package/dist/src/validators/zod.mjs +27 -0
- package/dist/src/wkx/binaryreader.mjs +56 -0
- package/dist/src/wkx/binarywriter.mjs +110 -0
- package/dist/src/wkx/geometry.mjs +101 -0
- package/dist/src/wkx/geometrycollection.mjs +113 -0
- package/dist/src/wkx/index.mjs +18 -0
- package/dist/src/wkx/linestring.mjs +124 -0
- package/dist/src/wkx/multilinestring.mjs +133 -0
- package/dist/src/wkx/multipoint.mjs +120 -0
- package/dist/src/wkx/multipolygon.mjs +155 -0
- package/dist/src/wkx/parser.mjs +183 -0
- package/dist/src/wkx/point.mjs +159 -0
- package/dist/src/wkx/polygon.mjs +189 -0
- package/dist/src/wkx/types.mjs +37 -0
- package/dist/src/wkx/wktparser.mjs +109 -0
- package/dist/src/wkx/zigzag.mjs +18 -0
- package/package.json +100 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { entityType } from "../symbols.mjs";
|
|
2
|
+
import { Arg } from "../query-builders/pre.mjs";
|
|
3
|
+
import { camelToSnake } from "../utils.mjs";
|
|
4
|
+
import { Sql } from "../sql.mjs";
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
//#region src/columns/common.ts
|
|
7
|
+
const notNull = true;
|
|
8
|
+
const unique = true;
|
|
9
|
+
const primaryKey = true;
|
|
10
|
+
var Column = class {
|
|
11
|
+
static [entityType] = "Column";
|
|
12
|
+
config;
|
|
13
|
+
$;
|
|
14
|
+
ValType;
|
|
15
|
+
ValTypeInsert;
|
|
16
|
+
ValTypeUpdate;
|
|
17
|
+
ValTypeSelect;
|
|
18
|
+
#default;
|
|
19
|
+
#insertFn;
|
|
20
|
+
#updateFn;
|
|
21
|
+
#primaryKey;
|
|
22
|
+
#unique;
|
|
23
|
+
#notNull;
|
|
24
|
+
#generated;
|
|
25
|
+
#as;
|
|
26
|
+
#references;
|
|
27
|
+
#name;
|
|
28
|
+
#nameSnake;
|
|
29
|
+
#table;
|
|
30
|
+
constructor(config) {
|
|
31
|
+
this.config = config;
|
|
32
|
+
this.#primaryKey = "primaryKey" in config ? !!config.primaryKey : false;
|
|
33
|
+
this.#unique = "unique" in config ? !!config.unique : false;
|
|
34
|
+
this.#notNull = "notNull" in config ? !!config.notNull : false;
|
|
35
|
+
this.#generated = "generated" in config ? config.generated : void 0;
|
|
36
|
+
this.#as = "as" in config ? config.as : void 0;
|
|
37
|
+
this.#references = void 0;
|
|
38
|
+
}
|
|
39
|
+
_ = {
|
|
40
|
+
setName: (name) => {
|
|
41
|
+
this.#name = name;
|
|
42
|
+
this.#nameSnake = camelToSnake(name);
|
|
43
|
+
},
|
|
44
|
+
setTable: (table) => {
|
|
45
|
+
this.#table = table;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
get name() {
|
|
49
|
+
return this.#name;
|
|
50
|
+
}
|
|
51
|
+
get nameSnake() {
|
|
52
|
+
return this.#nameSnake;
|
|
53
|
+
}
|
|
54
|
+
get table() {
|
|
55
|
+
return this.#table;
|
|
56
|
+
}
|
|
57
|
+
get generated() {
|
|
58
|
+
return this.#generated;
|
|
59
|
+
}
|
|
60
|
+
get as() {
|
|
61
|
+
return this.#as;
|
|
62
|
+
}
|
|
63
|
+
get isPrimaryKey() {
|
|
64
|
+
return this.#primaryKey;
|
|
65
|
+
}
|
|
66
|
+
get isGenerated() {
|
|
67
|
+
return typeof this.#generated === "string";
|
|
68
|
+
}
|
|
69
|
+
get isUnique() {
|
|
70
|
+
return this.#unique;
|
|
71
|
+
}
|
|
72
|
+
get isNotNull() {
|
|
73
|
+
return this.#notNull;
|
|
74
|
+
}
|
|
75
|
+
get sqlType() {
|
|
76
|
+
const base = this.sqlTypeScalar;
|
|
77
|
+
if (!this.config.dimension) return base;
|
|
78
|
+
return `${base}${this.config.dimension.map((d) => d === null ? "[]" : `[${d}]`).join("")}`;
|
|
79
|
+
}
|
|
80
|
+
get zodType() {
|
|
81
|
+
let schema = this.zodTypeScaler;
|
|
82
|
+
if (!this.config.dimension) return schema;
|
|
83
|
+
for (const dim of this.config.dimension) if (typeof dim === "number") schema = z.tuple(Array(dim).map(() => schema));
|
|
84
|
+
else schema = z.array(schema);
|
|
85
|
+
return schema;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Returns the fully-qualified, double-quoted column identifier separated by a dot.
|
|
89
|
+
* @returns string `"table"."column"`
|
|
90
|
+
*/
|
|
91
|
+
get fullName() {
|
|
92
|
+
return `"${this.table?._.name}"."${this.nameSnake}"`;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Converts a JavaScript value to the PostgreSQL driver format.
|
|
96
|
+
* Handles array dimensions if configured, otherwise delegates to scalar implementation.
|
|
97
|
+
*/
|
|
98
|
+
toDriver(value) {
|
|
99
|
+
if (value === null) return null;
|
|
100
|
+
if (value instanceof Sql) return value.string;
|
|
101
|
+
if (!this.config.dimension) return this.toDriverScalar(value);
|
|
102
|
+
return value.map((item) => this.#toDriverArrayElement(item, 0));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Helper to recursively process multi-dimensional arrays for toDriver.
|
|
106
|
+
*/
|
|
107
|
+
#toDriverArrayElement(value, dimIndex) {
|
|
108
|
+
if (dimIndex >= this.config.dimension.length - 1) return this.toDriverScalar(value);
|
|
109
|
+
return value.map((item) => this.#toDriverArrayElement(item, dimIndex + 1));
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Converts a JavaScript value to SQL string literal.
|
|
113
|
+
* Handles array dimensions with ARRAY[...] syntax if configured.
|
|
114
|
+
*/
|
|
115
|
+
toSQL(value) {
|
|
116
|
+
if (value instanceof Sql) return value.string;
|
|
117
|
+
if (!this.config.dimension) return this.toSQLScalar(value);
|
|
118
|
+
return this.#toSQLArray(value, 0);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Helper to recursively process multi-dimensional arrays for toSQL.
|
|
122
|
+
*/
|
|
123
|
+
#toSQLArray(arr, dimIndex) {
|
|
124
|
+
const dimensions = this.config.dimension;
|
|
125
|
+
if (arr.length === 0) return "'{}'";
|
|
126
|
+
if (dimIndex >= dimensions.length - 1) return `ARRAY[${arr.map((item) => this.toSQLScalar(item)).join(", ")}]`;
|
|
127
|
+
return `ARRAY[${arr.map((item) => this.#toSQLArray(item, dimIndex + 1)).join(", ")}]`;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Converts a PostgreSQL result back to JavaScript value.
|
|
131
|
+
* Handles array dimensions if configured, otherwise delegates to scalar implementation.
|
|
132
|
+
*/
|
|
133
|
+
fromDriver(value) {
|
|
134
|
+
if (value === null) return null;
|
|
135
|
+
if (!this.config.dimension) return this.fromDriverScalar(value);
|
|
136
|
+
let arr;
|
|
137
|
+
if (typeof value === "string") arr = this.#parsePostgresArrayString(value);
|
|
138
|
+
else arr = value;
|
|
139
|
+
return this.#fromDriverArray(arr, 0);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Parses a PostgreSQL array string format like {val1,val2,val3} into a JavaScript array.
|
|
143
|
+
* Handles nested arrays and quoted strings.
|
|
144
|
+
*/
|
|
145
|
+
#parsePostgresArrayString(str) {
|
|
146
|
+
if (str === "{}") return [];
|
|
147
|
+
const inner = str.slice(1, -1);
|
|
148
|
+
const result = [];
|
|
149
|
+
let depth = 0;
|
|
150
|
+
let current = "";
|
|
151
|
+
let inQuotes = false;
|
|
152
|
+
for (let i = 0; i < inner.length; i++) {
|
|
153
|
+
const char = inner[i];
|
|
154
|
+
if (char === "\"" && (i === 0 || inner[i - 1] !== "\\")) {
|
|
155
|
+
inQuotes = !inQuotes;
|
|
156
|
+
current += char;
|
|
157
|
+
} else if (!inQuotes && char === "{") {
|
|
158
|
+
depth++;
|
|
159
|
+
current += char;
|
|
160
|
+
} else if (!inQuotes && char === "}") {
|
|
161
|
+
depth--;
|
|
162
|
+
current += char;
|
|
163
|
+
} else if (!inQuotes && char === "," && depth === 0) {
|
|
164
|
+
result.push(this.#parsePostgresArrayElement(current));
|
|
165
|
+
current = "";
|
|
166
|
+
} else current += char;
|
|
167
|
+
}
|
|
168
|
+
if (current) result.push(this.#parsePostgresArrayElement(current));
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Parses a single element from a PostgreSQL array string.
|
|
173
|
+
*/
|
|
174
|
+
#parsePostgresArrayElement(element) {
|
|
175
|
+
if (element.startsWith("{") && element.endsWith("}")) return this.#parsePostgresArrayString(element);
|
|
176
|
+
if (element.startsWith("\"") && element.endsWith("\"")) return element.slice(1, -1).replace(/\\"/g, "\"").replace(/\\\\/g, "\\");
|
|
177
|
+
if (element === "NULL") return null;
|
|
178
|
+
return element;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Helper to recursively process multi-dimensional arrays for fromDriver.
|
|
182
|
+
*/
|
|
183
|
+
#fromDriverArray(arr, dimIndex) {
|
|
184
|
+
if (dimIndex >= this.config.dimension.length - 1) return arr.map((item) => this.fromDriverScalar(item));
|
|
185
|
+
return arr.map((item) => this.#fromDriverArray(item, dimIndex + 1));
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Sets a default value for this column.
|
|
189
|
+
* SQL equivalent: `DEFAULT <value>`
|
|
190
|
+
* @param value - The default value or SQL expression
|
|
191
|
+
* @returns this column instance
|
|
192
|
+
*/
|
|
193
|
+
default(value) {
|
|
194
|
+
this.#default = value;
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
get hasDefault() {
|
|
198
|
+
return this.#default !== void 0;
|
|
199
|
+
}
|
|
200
|
+
defaultToSQL() {
|
|
201
|
+
if (this.#default === void 0) return void 0;
|
|
202
|
+
return this.toSQL(this.#default);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Sets a foreign key reference for this column.
|
|
206
|
+
* SQL equivalent: `REFERENCES <table>(<column>) [ON DELETE <action>]`
|
|
207
|
+
* @param ref - A function returning the referenced column, or an object with column and onDelete
|
|
208
|
+
* @returns this column instance
|
|
209
|
+
*/
|
|
210
|
+
references(ref) {
|
|
211
|
+
if (typeof ref === "function") this.#references = {
|
|
212
|
+
column: ref,
|
|
213
|
+
onDelete: "CASCADE"
|
|
214
|
+
};
|
|
215
|
+
else this.#references = {
|
|
216
|
+
column: ref.column,
|
|
217
|
+
onDelete: ref.onDelete ?? "CASCADE"
|
|
218
|
+
};
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
get hasReferences() {
|
|
222
|
+
return this.#references !== void 0;
|
|
223
|
+
}
|
|
224
|
+
get referencesCol() {
|
|
225
|
+
return this.#references ? this.#references.column() : null;
|
|
226
|
+
}
|
|
227
|
+
get referencesOnDelete() {
|
|
228
|
+
return this.#references ? this.#references.onDelete : null;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Sets a function to be called during INSERT queries to generate a value.
|
|
232
|
+
* @param fn - A function that returns the value to insert
|
|
233
|
+
* @returns HasInsertFn<this>
|
|
234
|
+
*/
|
|
235
|
+
$insertFn(fn) {
|
|
236
|
+
this.#insertFn = fn;
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
get hasInsertFn() {
|
|
240
|
+
return this.#insertFn !== void 0;
|
|
241
|
+
}
|
|
242
|
+
getInsertFnVal() {
|
|
243
|
+
return this.#insertFn ? this.#insertFn() : null;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Sets a function to be called during UPDATE queries to generate a value.
|
|
247
|
+
* @param fn - A function that returns the value to use in updates
|
|
248
|
+
* @returns HasUpdateFn<this>
|
|
249
|
+
*/
|
|
250
|
+
$updateFn(fn) {
|
|
251
|
+
this.#updateFn = fn;
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
get hasUpdateFn() {
|
|
255
|
+
return this.#updateFn !== void 0;
|
|
256
|
+
}
|
|
257
|
+
getUpdateFnVal() {
|
|
258
|
+
return this.#updateFn ? this.#updateFn() : null;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Specifies the TypeScript type for this column's value.
|
|
262
|
+
* This is a compile-time only operation and does not affect runtime behavior.
|
|
263
|
+
* @returns this column with the specified value type
|
|
264
|
+
*/
|
|
265
|
+
$type() {
|
|
266
|
+
return this;
|
|
267
|
+
}
|
|
268
|
+
/** Creates an `Arg` instance for this column, to be used in prepared queries.
|
|
269
|
+
* @returns an `Arg` instance with the type of this column
|
|
270
|
+
*/
|
|
271
|
+
arg() {
|
|
272
|
+
return new Arg(this.toDriver.bind(this));
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
//#endregion
|
|
276
|
+
export { Column, notNull, primaryKey, unique };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Sql } from "../sql.mjs";
|
|
2
|
+
import { Column, ColumnConfig } from "./common.mjs";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/columns/date.d.ts
|
|
6
|
+
type DateValType = Date;
|
|
7
|
+
type DateConfig = ColumnConfig;
|
|
8
|
+
declare class DateColumn<TConfig extends DateConfig> extends Column<TConfig, DateValType> {
|
|
9
|
+
static readonly id = "Column.Date";
|
|
10
|
+
get sqlTypeScalar(): string;
|
|
11
|
+
get zodTypeScaler(): z.ZodDate;
|
|
12
|
+
toDriverScalar(value: DateValType | Sql | null): string | null;
|
|
13
|
+
toSQLScalar(value: Date | Sql | null): string;
|
|
14
|
+
fromDriverScalar(value: Date | string | null): DateValType | null;
|
|
15
|
+
}
|
|
16
|
+
/** Creates a `date` column. PostgreSQL calendar date (no time), maps to `Date`. */
|
|
17
|
+
declare function date<TConfig extends DateConfig>(config: TConfig): DateColumn<TConfig>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { date };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Column } from "./common.mjs";
|
|
2
|
+
import { Sql } from "../sql.mjs";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
//#region src/columns/date.ts
|
|
5
|
+
var DateColumn = class extends Column {
|
|
6
|
+
static id = "Column.Date";
|
|
7
|
+
get sqlTypeScalar() {
|
|
8
|
+
return "date";
|
|
9
|
+
}
|
|
10
|
+
get zodTypeScaler() {
|
|
11
|
+
return z.date();
|
|
12
|
+
}
|
|
13
|
+
toDriverScalar(value) {
|
|
14
|
+
if (value === null) return null;
|
|
15
|
+
return value instanceof Sql ? value.string : value.toISOString().slice(0, 10);
|
|
16
|
+
}
|
|
17
|
+
toSQLScalar(value) {
|
|
18
|
+
if (value === null) return "NULL";
|
|
19
|
+
return value instanceof Sql ? value.string : `'${value.toISOString().slice(0, 10)}'`;
|
|
20
|
+
}
|
|
21
|
+
fromDriverScalar(value) {
|
|
22
|
+
if (value === null) return null;
|
|
23
|
+
if (value instanceof Date) return new Date(Date.UTC(value.getFullYear(), value.getMonth(), value.getDate()));
|
|
24
|
+
return /* @__PURE__ */ new Date(`${value}T00:00:00Z`);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/** Creates a `date` column. PostgreSQL calendar date (no time), maps to `Date`. */
|
|
28
|
+
function date(config) {
|
|
29
|
+
return new DateColumn(config);
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { date };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Sql } from "../sql.mjs";
|
|
2
|
+
import { Column, ColumnConfig } from "./common.mjs";
|
|
3
|
+
import { Enum } from "../enumtype.mjs";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/columns/enum.d.ts
|
|
7
|
+
type EnumedConfig = ColumnConfig;
|
|
8
|
+
declare class EnumedColumn<TValue extends string, TConfig extends EnumedConfig> extends Column<TConfig, TValue> {
|
|
9
|
+
#private;
|
|
10
|
+
static readonly id = "Column.Enumed";
|
|
11
|
+
constructor(enm: Enum<TValue>, config: TConfig);
|
|
12
|
+
get sqlTypeScalar(): string;
|
|
13
|
+
get zodTypeScaler(): z.ZodEnum<{ [k_1 in TValue]: k_1 } extends infer T ? { [k in keyof T]: T[k] } : never>;
|
|
14
|
+
toDriverScalar(value: TValue | Sql | null): string | null;
|
|
15
|
+
toSQLScalar(value: TValue | Sql | null): string;
|
|
16
|
+
fromDriverScalar(value: TValue | null): TValue | null;
|
|
17
|
+
}
|
|
18
|
+
/** Creates an `enum` column bound to a user-defined PostgreSQL enum type. Maps to a union of string literals. */
|
|
19
|
+
declare function enumed<TValue extends string, TConfig extends EnumedConfig>(enm: Enum<TValue>, config: TConfig): EnumedColumn<TValue, TConfig>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { EnumedColumn, EnumedConfig, enumed };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Column } from "./common.mjs";
|
|
2
|
+
import { Sql } from "../sql.mjs";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
//#region src/columns/enum.ts
|
|
5
|
+
var EnumedColumn = class extends Column {
|
|
6
|
+
static id = "Column.Enumed";
|
|
7
|
+
#enum;
|
|
8
|
+
constructor(enm, config) {
|
|
9
|
+
super(config);
|
|
10
|
+
this.#enum = enm;
|
|
11
|
+
}
|
|
12
|
+
get sqlTypeScalar() {
|
|
13
|
+
return `"${this.#enum.schema}"."${this.#enum.name}"`;
|
|
14
|
+
}
|
|
15
|
+
get zodTypeScaler() {
|
|
16
|
+
return z.enum(this.#enum.values);
|
|
17
|
+
}
|
|
18
|
+
toDriverScalar(value) {
|
|
19
|
+
if (value === null) return null;
|
|
20
|
+
return value instanceof Sql ? value.string : value;
|
|
21
|
+
}
|
|
22
|
+
toSQLScalar(value) {
|
|
23
|
+
if (value === null) return "NULL";
|
|
24
|
+
return value instanceof Sql ? value.string : `'${value.replace(/'/g, "''")}'`;
|
|
25
|
+
}
|
|
26
|
+
fromDriverScalar(value) {
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/** Creates an `enum` column bound to a user-defined PostgreSQL enum type. Maps to a union of string literals. */
|
|
31
|
+
function enumed(enm, config) {
|
|
32
|
+
return new EnumedColumn(enm, config);
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { enumed };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Sql } from "../sql.mjs";
|
|
2
|
+
import { Column, ColumnConfig } from "./common.mjs";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/columns/inet.d.ts
|
|
6
|
+
type InetValType = string;
|
|
7
|
+
type InetConfig = ColumnConfig;
|
|
8
|
+
declare class InetColumn<TConfig extends InetConfig> extends Column<TConfig, InetValType> {
|
|
9
|
+
static readonly id = "Column.Inet";
|
|
10
|
+
get sqlTypeScalar(): string;
|
|
11
|
+
get zodTypeScaler(): z.ZodUnion<readonly [z.ZodIPv4, z.ZodIPv6, z.ZodCIDRv4, z.ZodCIDRv6]>;
|
|
12
|
+
toDriverScalar(value: InetValType | Sql | null): string | null;
|
|
13
|
+
toSQLScalar(value: InetValType | Sql | null): string;
|
|
14
|
+
fromDriverScalar(value: string | null): InetValType | null;
|
|
15
|
+
}
|
|
16
|
+
/** Creates an `inet` column. PostgreSQL IPv4/IPv6 host address type, maps to `string`. */
|
|
17
|
+
declare function inet<TConfig extends InetConfig>(config: TConfig): InetColumn<TConfig>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { inet };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Column } from "./common.mjs";
|
|
2
|
+
import { Sql } from "../sql.mjs";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
//#region src/columns/inet.ts
|
|
5
|
+
var InetColumn = class extends Column {
|
|
6
|
+
static id = "Column.Inet";
|
|
7
|
+
get sqlTypeScalar() {
|
|
8
|
+
return "inet";
|
|
9
|
+
}
|
|
10
|
+
get zodTypeScaler() {
|
|
11
|
+
return z.union([
|
|
12
|
+
z.ipv4(),
|
|
13
|
+
z.ipv6(),
|
|
14
|
+
z.cidrv4(),
|
|
15
|
+
z.cidrv6()
|
|
16
|
+
]);
|
|
17
|
+
}
|
|
18
|
+
toDriverScalar(value) {
|
|
19
|
+
if (value === null) return null;
|
|
20
|
+
return value instanceof Sql ? value.string : value;
|
|
21
|
+
}
|
|
22
|
+
toSQLScalar(value) {
|
|
23
|
+
if (value === null) return "NULL";
|
|
24
|
+
if (value instanceof Sql) return value.string;
|
|
25
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
26
|
+
}
|
|
27
|
+
fromDriverScalar(value) {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/** Creates an `inet` column. PostgreSQL IPv4/IPv6 host address type, maps to `string`. */
|
|
32
|
+
function inet(config) {
|
|
33
|
+
return new InetColumn(config);
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { inet };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Sql } from "../sql.mjs";
|
|
2
|
+
import { Column, ColumnConfig } from "./common.mjs";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/columns/integer.d.ts
|
|
6
|
+
type IntegerValType = number;
|
|
7
|
+
type IntegerConfig = ColumnConfig;
|
|
8
|
+
declare class IntegerColumn<TConfig extends IntegerConfig> extends Column<TConfig, IntegerValType> {
|
|
9
|
+
static readonly id = "Column.Integer";
|
|
10
|
+
get sqlTypeScalar(): string;
|
|
11
|
+
get zodTypeScaler(): z.ZodCoercedNumber<unknown>;
|
|
12
|
+
toDriverScalar(value: IntegerValType | Sql | null): string | number | null;
|
|
13
|
+
toSQLScalar(value: number | Sql | null): string;
|
|
14
|
+
fromDriverScalar(value: number | string | null): IntegerValType | null;
|
|
15
|
+
}
|
|
16
|
+
/** Creates an `integer` column. PostgreSQL 32-bit signed integer, maps to `number`. */
|
|
17
|
+
declare function integer<TConfig extends IntegerConfig>(config: TConfig): IntegerColumn<TConfig>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { integer };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Column } from "./common.mjs";
|
|
2
|
+
import { Sql } from "../sql.mjs";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
//#region src/columns/integer.ts
|
|
5
|
+
var IntegerColumn = class extends Column {
|
|
6
|
+
static id = "Column.Integer";
|
|
7
|
+
get sqlTypeScalar() {
|
|
8
|
+
return "integer";
|
|
9
|
+
}
|
|
10
|
+
get zodTypeScaler() {
|
|
11
|
+
return z.coerce.number();
|
|
12
|
+
}
|
|
13
|
+
toDriverScalar(value) {
|
|
14
|
+
if (value === null) return null;
|
|
15
|
+
return value instanceof Sql ? value.string : value;
|
|
16
|
+
}
|
|
17
|
+
toSQLScalar(value) {
|
|
18
|
+
if (value === null) return "NULL";
|
|
19
|
+
if (value instanceof Sql) return value.string;
|
|
20
|
+
return value.toString();
|
|
21
|
+
}
|
|
22
|
+
fromDriverScalar(value) {
|
|
23
|
+
if (value === null) return null;
|
|
24
|
+
return typeof value === "string" ? parseInt(value, 10) : value;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/** Creates an `integer` column. PostgreSQL 32-bit signed integer, maps to `number`. */
|
|
28
|
+
function integer(config) {
|
|
29
|
+
return new IntegerColumn(config);
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { integer };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Sql } from "../sql.mjs";
|
|
2
|
+
import { Column, ColumnConfig } from "./common.mjs";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/columns/json.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* The base value type for JSON columns.
|
|
8
|
+
* JSON can store any valid JSON value: objects, arrays, strings, numbers, booleans, or null.
|
|
9
|
+
*/
|
|
10
|
+
type JsonValType = unknown;
|
|
11
|
+
type JsonConfig = ColumnConfig;
|
|
12
|
+
/**
|
|
13
|
+
* PostgreSQL JSON column type.
|
|
14
|
+
* Stores JSON data in text format, preserving exact input formatting.
|
|
15
|
+
*
|
|
16
|
+
* Key differences from JSONB:
|
|
17
|
+
* - Preserves whitespace and key ordering
|
|
18
|
+
* - No indexing support for JSON path queries
|
|
19
|
+
* - Slightly faster to insert (no parsing overhead)
|
|
20
|
+
* - Slower to query (must be reparsed on each access)
|
|
21
|
+
*
|
|
22
|
+
* Use $type<T>() to specify a TypeScript type for the column value.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* // Basic JSON column
|
|
27
|
+
* const table = table('users', {
|
|
28
|
+
* metadata: json({}),
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Typed JSON column
|
|
32
|
+
* interface UserSettings {
|
|
33
|
+
* theme: 'light' | 'dark';
|
|
34
|
+
* notifications: boolean;
|
|
35
|
+
* }
|
|
36
|
+
* const table = table('users', {
|
|
37
|
+
* settings: json({}).$type<UserSettings>(),
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare class JsonColumn<TConfig extends JsonConfig> extends Column<TConfig, JsonValType> {
|
|
42
|
+
static readonly id = "Column.Json";
|
|
43
|
+
get sqlTypeScalar(): string;
|
|
44
|
+
get zodTypeScaler(): z.ZodUnknown;
|
|
45
|
+
toDriverScalar(value: JsonValType | Sql | null): string | null;
|
|
46
|
+
toSQLScalar(value: JsonValType | Sql | null): string;
|
|
47
|
+
fromDriverScalar(value: unknown): JsonValType | null;
|
|
48
|
+
}
|
|
49
|
+
/** Creates a `json` column. Stores JSON as text, preserving formatting. Maps to `unknown` (use `$type<T>()` to narrow). */
|
|
50
|
+
declare function json<TConfig extends JsonConfig>(config: TConfig): JsonColumn<TConfig>;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { json };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Column } from "./common.mjs";
|
|
2
|
+
import { Sql } from "../sql.mjs";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
//#region src/columns/json.ts
|
|
5
|
+
/**
|
|
6
|
+
* PostgreSQL JSON column type.
|
|
7
|
+
* Stores JSON data in text format, preserving exact input formatting.
|
|
8
|
+
*
|
|
9
|
+
* Key differences from JSONB:
|
|
10
|
+
* - Preserves whitespace and key ordering
|
|
11
|
+
* - No indexing support for JSON path queries
|
|
12
|
+
* - Slightly faster to insert (no parsing overhead)
|
|
13
|
+
* - Slower to query (must be reparsed on each access)
|
|
14
|
+
*
|
|
15
|
+
* Use $type<T>() to specify a TypeScript type for the column value.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* // Basic JSON column
|
|
20
|
+
* const table = table('users', {
|
|
21
|
+
* metadata: json({}),
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Typed JSON column
|
|
25
|
+
* interface UserSettings {
|
|
26
|
+
* theme: 'light' | 'dark';
|
|
27
|
+
* notifications: boolean;
|
|
28
|
+
* }
|
|
29
|
+
* const table = table('users', {
|
|
30
|
+
* settings: json({}).$type<UserSettings>(),
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
var JsonColumn = class extends Column {
|
|
35
|
+
static id = "Column.Json";
|
|
36
|
+
get sqlTypeScalar() {
|
|
37
|
+
return "json";
|
|
38
|
+
}
|
|
39
|
+
get zodTypeScaler() {
|
|
40
|
+
return z.unknown();
|
|
41
|
+
}
|
|
42
|
+
toDriverScalar(value) {
|
|
43
|
+
if (value === null) return null;
|
|
44
|
+
if (value instanceof Sql) return value.string;
|
|
45
|
+
return JSON.stringify(value);
|
|
46
|
+
}
|
|
47
|
+
toSQLScalar(value) {
|
|
48
|
+
if (value === null) return "NULL";
|
|
49
|
+
if (value instanceof Sql) return value.string;
|
|
50
|
+
return `'${JSON.stringify(value).replace(/'/g, "''")}'::json`;
|
|
51
|
+
}
|
|
52
|
+
fromDriverScalar(value) {
|
|
53
|
+
if (value === null) return null;
|
|
54
|
+
if (typeof value === "string") try {
|
|
55
|
+
return JSON.parse(value);
|
|
56
|
+
} catch {
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
/** Creates a `json` column. Stores JSON as text, preserving formatting. Maps to `unknown` (use `$type<T>()` to narrow). */
|
|
63
|
+
function json(config) {
|
|
64
|
+
return new JsonColumn(config);
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { json };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Sql } from "../sql.mjs";
|
|
2
|
+
import { Column, ColumnConfig } from "./common.mjs";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/columns/jsonb.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* The base value type for JSONB columns.
|
|
8
|
+
* JSONB can store any valid JSON value: objects, arrays, strings, numbers, booleans, or null.
|
|
9
|
+
*/
|
|
10
|
+
type JsonbValType = unknown;
|
|
11
|
+
type JsonbConfig = ColumnConfig;
|
|
12
|
+
/**
|
|
13
|
+
* PostgreSQL JSONB column type.
|
|
14
|
+
* Stores JSON data in a decomposed binary format for efficient processing.
|
|
15
|
+
*
|
|
16
|
+
* Key differences from JSON:
|
|
17
|
+
* - Does not preserve whitespace or key ordering
|
|
18
|
+
* - Supports GIN indexing for fast path queries
|
|
19
|
+
* - Slightly slower to insert (parsing overhead)
|
|
20
|
+
* - Faster to query (no reparsing needed)
|
|
21
|
+
* - Supports containment and existence operators (@>, ?, ?|, ?&)
|
|
22
|
+
*
|
|
23
|
+
* Use $type<T>() to specify a TypeScript type for the column value.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* // Basic JSONB column
|
|
28
|
+
* const table = table('users', {
|
|
29
|
+
* metadata: jsonb({}),
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Typed JSONB column
|
|
33
|
+
* interface UserSettings {
|
|
34
|
+
* theme: 'light' | 'dark';
|
|
35
|
+
* notifications: boolean;
|
|
36
|
+
* }
|
|
37
|
+
* const table = table('users', {
|
|
38
|
+
* settings: jsonb({}).$type<UserSettings>(),
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare class JsonbColumn<TConfig extends JsonbConfig> extends Column<TConfig, JsonbValType> {
|
|
43
|
+
static readonly id = "Column.Jsonb";
|
|
44
|
+
get sqlTypeScalar(): string;
|
|
45
|
+
get zodTypeScaler(): z.ZodUnknown;
|
|
46
|
+
toDriverScalar(value: JsonbValType | Sql | null): string | null;
|
|
47
|
+
toSQLScalar(value: JsonbValType | Sql | null): string;
|
|
48
|
+
fromDriverScalar(value: unknown): JsonbValType | null;
|
|
49
|
+
}
|
|
50
|
+
/** Creates a `jsonb` column. Stores JSON in decomposed binary format for efficient querying. Maps to `unknown` (use `$type<T>()` to narrow). */
|
|
51
|
+
declare function jsonb<TConfig extends JsonbConfig>(config: TConfig): JsonbColumn<TConfig>;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { jsonb };
|