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.
Files changed (174) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +56 -0
  3. package/dist/bin.cjs +13522 -0
  4. package/dist/src/_virtual/_rolldown/runtime.mjs +28 -0
  5. package/dist/src/cli/helpers.mjs +16 -0
  6. package/dist/src/columns/bigint.d.mts +19 -0
  7. package/dist/src/columns/bigint.mjs +32 -0
  8. package/dist/src/columns/bigserial.d.mts +24 -0
  9. package/dist/src/columns/bigserial.mjs +35 -0
  10. package/dist/src/columns/boolean.d.mts +19 -0
  11. package/dist/src/columns/boolean.mjs +31 -0
  12. package/dist/src/columns/bytea.d.mts +19 -0
  13. package/dist/src/columns/bytea.mjs +33 -0
  14. package/dist/src/columns/char.d.mts +32 -0
  15. package/dist/src/columns/char.mjs +44 -0
  16. package/dist/src/columns/cidr.d.mts +19 -0
  17. package/dist/src/columns/cidr.mjs +31 -0
  18. package/dist/src/columns/common.d.mts +233 -0
  19. package/dist/src/columns/common.mjs +276 -0
  20. package/dist/src/columns/date.d.mts +19 -0
  21. package/dist/src/columns/date.mjs +32 -0
  22. package/dist/src/columns/enum.d.mts +21 -0
  23. package/dist/src/columns/enum.mjs +35 -0
  24. package/dist/src/columns/inet.d.mts +19 -0
  25. package/dist/src/columns/inet.mjs +36 -0
  26. package/dist/src/columns/integer.d.mts +19 -0
  27. package/dist/src/columns/integer.mjs +32 -0
  28. package/dist/src/columns/json.d.mts +52 -0
  29. package/dist/src/columns/json.mjs +67 -0
  30. package/dist/src/columns/jsonb.d.mts +53 -0
  31. package/dist/src/columns/jsonb.mjs +68 -0
  32. package/dist/src/columns/macaddr.d.mts +19 -0
  33. package/dist/src/columns/macaddr.mjs +31 -0
  34. package/dist/src/columns/numeric.d.mts +42 -0
  35. package/dist/src/columns/numeric.mjs +57 -0
  36. package/dist/src/columns/postgis/geography/index.d.mts +18 -0
  37. package/dist/src/columns/postgis/geography/index.mjs +17 -0
  38. package/dist/src/columns/postgis/geography/linestring.d.mts +38 -0
  39. package/dist/src/columns/postgis/geography/linestring.mjs +70 -0
  40. package/dist/src/columns/postgis/geography/multilinestring.d.mts +39 -0
  41. package/dist/src/columns/postgis/geography/multilinestring.mjs +70 -0
  42. package/dist/src/columns/postgis/geography/multipoint.d.mts +38 -0
  43. package/dist/src/columns/postgis/geography/multipoint.mjs +70 -0
  44. package/dist/src/columns/postgis/geography/multipolygon.d.mts +40 -0
  45. package/dist/src/columns/postgis/geography/multipolygon.mjs +70 -0
  46. package/dist/src/columns/postgis/geography/point.d.mts +36 -0
  47. package/dist/src/columns/postgis/geography/point.mjs +69 -0
  48. package/dist/src/columns/postgis/geography/polygon.d.mts +39 -0
  49. package/dist/src/columns/postgis/geography/polygon.mjs +70 -0
  50. package/dist/src/columns/serial.d.mts +24 -0
  51. package/dist/src/columns/serial.mjs +35 -0
  52. package/dist/src/columns/smallint.d.mts +19 -0
  53. package/dist/src/columns/smallint.mjs +32 -0
  54. package/dist/src/columns/smallserial.d.mts +24 -0
  55. package/dist/src/columns/smallserial.mjs +35 -0
  56. package/dist/src/columns/text.d.mts +19 -0
  57. package/dist/src/columns/text.mjs +30 -0
  58. package/dist/src/columns/time.d.mts +44 -0
  59. package/dist/src/columns/time.mjs +47 -0
  60. package/dist/src/columns/timestamp.d.mts +44 -0
  61. package/dist/src/columns/timestamp.mjs +47 -0
  62. package/dist/src/columns/uuid.d.mts +33 -0
  63. package/dist/src/columns/uuid.mjs +44 -0
  64. package/dist/src/columns/varchar.d.mts +32 -0
  65. package/dist/src/columns/varchar.mjs +44 -0
  66. package/dist/src/connectors/bun.d.mts +18 -0
  67. package/dist/src/connectors/bun.mjs +97 -0
  68. package/dist/src/connectors/common.d.mts +148 -0
  69. package/dist/src/connectors/common.mjs +65 -0
  70. package/dist/src/connectors/pg.d.mts +18 -0
  71. package/dist/src/connectors/pg.mjs +103 -0
  72. package/dist/src/connectors/pglite.d.mts +19 -0
  73. package/dist/src/connectors/pglite.mjs +94 -0
  74. package/dist/src/connectors/postgres.d.mts +18 -0
  75. package/dist/src/connectors/postgres.mjs +93 -0
  76. package/dist/src/constraints/check.d.mts +88 -0
  77. package/dist/src/constraints/check.mjs +307 -0
  78. package/dist/src/constraints/primary-key.d.mts +28 -0
  79. package/dist/src/constraints/primary-key.mjs +36 -0
  80. package/dist/src/constraints/unique.d.mts +28 -0
  81. package/dist/src/constraints/unique.mjs +36 -0
  82. package/dist/src/db.d.mts +180 -0
  83. package/dist/src/db.mjs +191 -0
  84. package/dist/src/entity.mjs +23 -0
  85. package/dist/src/enumtype.d.mts +27 -0
  86. package/dist/src/enumtype.mjs +42 -0
  87. package/dist/src/filters/array.d.mts +97 -0
  88. package/dist/src/filters/array.mjs +150 -0
  89. package/dist/src/filters/custom.d.mts +12 -0
  90. package/dist/src/filters/custom.mjs +7 -0
  91. package/dist/src/filters/index.d.mts +155 -0
  92. package/dist/src/filters/index.mjs +318 -0
  93. package/dist/src/functions/index.d.mts +24 -0
  94. package/dist/src/functions/index.mjs +29 -0
  95. package/dist/src/index.d.mts +129 -0
  96. package/dist/src/index.mjs +78 -0
  97. package/dist/src/indexes.d.mts +31 -0
  98. package/dist/src/indexes.mjs +43 -0
  99. package/dist/src/migration/consts.d.mts +8 -0
  100. package/dist/src/migration/consts.mjs +8 -0
  101. package/dist/src/migration/ddl.d.mts +747 -0
  102. package/dist/src/migration/ddl.mjs +1084 -0
  103. package/dist/src/migration/index.d.mts +15 -0
  104. package/dist/src/migration/index.mjs +5 -0
  105. package/dist/src/migration/snapshot.d.mts +169 -0
  106. package/dist/src/migration/snapshot.mjs +123 -0
  107. package/dist/src/migration/statement.d.mts +89 -0
  108. package/dist/src/migration/statement.mjs +61 -0
  109. package/dist/src/models.d.mts +34 -0
  110. package/dist/src/models.mjs +27 -0
  111. package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.mjs +126 -0
  112. package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.mjs +29 -0
  113. package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.mjs +165 -0
  114. package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.mjs +92 -0
  115. package/dist/src/query-builders/aggregates.d.mts +20 -0
  116. package/dist/src/query-builders/aggregates.mjs +43 -0
  117. package/dist/src/query-builders/count.d.mts +19 -0
  118. package/dist/src/query-builders/count.mjs +36 -0
  119. package/dist/src/query-builders/delete.d.mts +19 -0
  120. package/dist/src/query-builders/delete.mjs +57 -0
  121. package/dist/src/query-builders/distinct.d.mts +19 -0
  122. package/dist/src/query-builders/distinct.mjs +42 -0
  123. package/dist/src/query-builders/exists.d.mts +19 -0
  124. package/dist/src/query-builders/exists.mjs +37 -0
  125. package/dist/src/query-builders/first.d.mts +17 -0
  126. package/dist/src/query-builders/first.mjs +46 -0
  127. package/dist/src/query-builders/insert-returning.d.mts +16 -0
  128. package/dist/src/query-builders/insert-returning.mjs +63 -0
  129. package/dist/src/query-builders/insert.d.mts +22 -0
  130. package/dist/src/query-builders/insert.mjs +93 -0
  131. package/dist/src/query-builders/orderby-clause.d.mts +14 -0
  132. package/dist/src/query-builders/orderby-clause.mjs +20 -0
  133. package/dist/src/query-builders/pre.d.mts +36 -0
  134. package/dist/src/query-builders/pre.mjs +60 -0
  135. package/dist/src/query-builders/query-promise.d.mts +14 -0
  136. package/dist/src/query-builders/query-promise.mjs +21 -0
  137. package/dist/src/query-builders/query.d.mts +14 -0
  138. package/dist/src/query-builders/query.mjs +17 -0
  139. package/dist/src/query-builders/raw.d.mts +14 -0
  140. package/dist/src/query-builders/raw.mjs +26 -0
  141. package/dist/src/query-builders/rq.d.mts +36 -0
  142. package/dist/src/query-builders/rq.mjs +231 -0
  143. package/dist/src/query-builders/select.d.mts +48 -0
  144. package/dist/src/query-builders/select.mjs +118 -0
  145. package/dist/src/query-builders/update.d.mts +24 -0
  146. package/dist/src/query-builders/update.mjs +99 -0
  147. package/dist/src/sequence.d.mts +48 -0
  148. package/dist/src/sequence.mjs +53 -0
  149. package/dist/src/sql.d.mts +15 -0
  150. package/dist/src/sql.mjs +36 -0
  151. package/dist/src/symbols.d.mts +4 -0
  152. package/dist/src/symbols.mjs +4 -0
  153. package/dist/src/table.d.mts +144 -0
  154. package/dist/src/table.mjs +134 -0
  155. package/dist/src/types.d.mts +4 -0
  156. package/dist/src/utils.mjs +10 -0
  157. package/dist/src/validators/zod.d.mts +23 -0
  158. package/dist/src/validators/zod.mjs +27 -0
  159. package/dist/src/wkx/binaryreader.mjs +56 -0
  160. package/dist/src/wkx/binarywriter.mjs +110 -0
  161. package/dist/src/wkx/geometry.mjs +101 -0
  162. package/dist/src/wkx/geometrycollection.mjs +113 -0
  163. package/dist/src/wkx/index.mjs +18 -0
  164. package/dist/src/wkx/linestring.mjs +124 -0
  165. package/dist/src/wkx/multilinestring.mjs +133 -0
  166. package/dist/src/wkx/multipoint.mjs +120 -0
  167. package/dist/src/wkx/multipolygon.mjs +155 -0
  168. package/dist/src/wkx/parser.mjs +183 -0
  169. package/dist/src/wkx/point.mjs +159 -0
  170. package/dist/src/wkx/polygon.mjs +189 -0
  171. package/dist/src/wkx/types.mjs +37 -0
  172. package/dist/src/wkx/wktparser.mjs +109 -0
  173. package/dist/src/wkx/zigzag.mjs +18 -0
  174. package/package.json +100 -0
@@ -0,0 +1,231 @@
1
+ import { QueryPromise } from "./query-promise.mjs";
2
+ import { snakeToCamel } from "../utils.mjs";
3
+ import { Query } from "./query.mjs";
4
+ //#region src/query-builders/rq.ts
5
+ var RelationQueryBuilder = class {
6
+ #table;
7
+ #relations;
8
+ #allRelations;
9
+ #config;
10
+ #executor;
11
+ constructor(table, relations, allRelations, config, executor) {
12
+ this.#table = table;
13
+ this.#relations = relations;
14
+ this.#allRelations = allRelations;
15
+ this.#config = config;
16
+ this.#executor = executor;
17
+ }
18
+ findMany(options) {
19
+ return new RelationQuery(this.#table, this.#relations, this.#allRelations, options, this.#config, this.#executor);
20
+ }
21
+ async findFirst(options) {
22
+ return (await new RelationQuery(this.#table, this.#relations, this.#allRelations, {
23
+ ...options,
24
+ limit: 1
25
+ }, this.#config, this.#executor)).at(0) ?? null;
26
+ }
27
+ };
28
+ var RelationQuery = class extends QueryPromise {
29
+ #table;
30
+ #relations;
31
+ #allRelations;
32
+ #options;
33
+ #config;
34
+ #executor;
35
+ constructor(table, relations, allRelations, options, config, executor) {
36
+ super();
37
+ this.#table = table;
38
+ this.#relations = relations;
39
+ this.#allRelations = allRelations;
40
+ this.#options = options;
41
+ this.#config = config;
42
+ this.#executor = executor;
43
+ }
44
+ toQuery() {
45
+ const options = this.#options;
46
+ const query = new Query("SELECT ", this.handleRows.bind(this));
47
+ const selects = [];
48
+ if (options.columns === void 0 || Object.keys(options.columns).length === 0) for (const [, column] of Object.entries(this.#table._.columns)) selects.push(column.fullName);
49
+ else if (Object.values(options.columns).at(0) === true) for (const [colName, column] of Object.entries(this.#table._.columns)) colName in options.columns && selects.push(column.fullName);
50
+ else for (const [colName, column] of Object.entries(this.#table._.columns)) !(colName in options.columns) && selects.push(column.fullName);
51
+ const relations = this.#allRelations[this.#table._.fullName];
52
+ if (relations) {
53
+ if (options.with) {
54
+ for (const key in options.with) if (relations.map[key]) {
55
+ const select = `"${key}"."data" AS "${key}"`;
56
+ selects.push(select);
57
+ }
58
+ }
59
+ }
60
+ query.sql += selects.join(", ");
61
+ query.sql += " FROM";
62
+ query.sql += ` ${this.#table._.fullName} "${this.#table._.name}"`;
63
+ if (options.with) for (const key in options.with) {
64
+ const o = options.with[key];
65
+ const relations = this.#allRelations[this.#table._.fullName];
66
+ if (relations) {
67
+ const relation = relations.map[key];
68
+ if (relation) query.sql += buildRelationSubquery(key, this.#table._.name, o, relation, this.#allRelations, this.#config);
69
+ }
70
+ }
71
+ if (options.where) query.sql += ` WHERE ${options.where.toSQL()}`;
72
+ if (options.orderBy) {
73
+ const orders = Array.isArray(options.orderBy) ? options.orderBy : [options.orderBy];
74
+ query.sql += ` ORDER BY ${orders.map((o) => o.toSQL()).join(", ")}`;
75
+ }
76
+ if (options.limit) query.sql += ` LIMIT ${options.limit}`;
77
+ const optionsWithOffset = this.#options;
78
+ if (optionsWithOffset.offset) query.sql += ` OFFSET ${optionsWithOffset.offset}`;
79
+ query.sql += ";";
80
+ return query;
81
+ }
82
+ async execute() {
83
+ const query = this.toQuery();
84
+ const res = await this.#executor.query(query.sql, query.arguments);
85
+ const rows = this.#executor.getRows(res);
86
+ return this.handleRows(rows);
87
+ }
88
+ handleRows(rows) {
89
+ rows.forEach((row) => {
90
+ convert(row, this.#table, this.#allRelations);
91
+ });
92
+ return rows;
93
+ }
94
+ };
95
+ /**
96
+ * Build the json_build_object selects for a relation, including nested relations.
97
+ * @param alias - The alias used for the inner subquery (e.g., "posts", "posts__comments")
98
+ * @param options - The options for this relation
99
+ * @param table - The table being selected from
100
+ * @param allRelations - All relations in the schema
101
+ */
102
+ function getJsonBuildObjectSelects(alias, options, table, allRelations) {
103
+ const selects = [];
104
+ if (options.columns === void 0 || Object.keys(options.columns).length === 0) for (const [colName, column] of Object.entries(table._.columns)) selects.push(`'${colName}', "${alias}"."${column.nameSnake}"`);
105
+ else if (Object.values(options.columns).at(0) === true) for (const [colName, column] of Object.entries(table._.columns)) colName in options.columns && selects.push(`'${colName}', "${alias}"."${column.nameSnake}"`);
106
+ else for (const [colName, column] of Object.entries(table._.columns)) !(colName in options.columns) && selects.push(`'${colName}', "${alias}"."${column.nameSnake}"`);
107
+ if (options.with) {
108
+ const tableRelations = allRelations[table._.fullName];
109
+ if (tableRelations) {
110
+ for (const nestedKey in options.with) if (tableRelations.map[nestedKey]) selects.push(`'${nestedKey}', "${alias}"."${nestedKey}_data"`);
111
+ }
112
+ }
113
+ return selects;
114
+ }
115
+ /**
116
+ * Build a LATERAL JOIN subquery for a relation, recursively handling nested relations.
117
+ * Alias path format: "relationKey" for top-level, "parent__child" for nested (debuggable).
118
+ *
119
+ * @param aliasPath - The full alias path (e.g., "posts", "posts__comments")
120
+ * @param parentTableAlias - The alias of the parent table (e.g., "users" for top-level, "posts" for nested)
121
+ * @param options - The options for this relation
122
+ * @param relation - The relation definition (Many, One, or Fk)
123
+ * @param allRelations - All relations in the schema
124
+ * @param config - The database config
125
+ */
126
+ function buildRelationSubquery(aliasPath, parentTableAlias, options, relation, allRelations, config) {
127
+ let sql = " LEFT JOIN LATERAL (";
128
+ const jsonSelects = getJsonBuildObjectSelects(aliasPath, options, relation.table, allRelations);
129
+ if (relation.t === "Many") sql += `SELECT coalesce(json_agg(json_build_object(${jsonSelects.join(", ")})), '[]'::json) AS "data"`;
130
+ else sql += `SELECT json_build_object(${jsonSelects.join(", ")}) AS "data"`;
131
+ sql += ` FROM (SELECT "${aliasPath}".*`;
132
+ if (options.with) {
133
+ const tableRelations = allRelations[relation.table._.fullName];
134
+ if (tableRelations) {
135
+ for (const nestedKey in options.with) if (tableRelations.map[nestedKey]) {
136
+ const nestedAliasPath = `${aliasPath}__${nestedKey}`;
137
+ sql += `, "${nestedAliasPath}"."data" AS "${nestedKey}_data"`;
138
+ }
139
+ }
140
+ }
141
+ sql += ` FROM ${relation.table._.fullName} "${aliasPath}"`;
142
+ if (options.with) {
143
+ const tableRelations = allRelations[relation.table._.fullName];
144
+ if (tableRelations) for (const nestedKey in options.with) {
145
+ const nestedOptions = options.with[nestedKey];
146
+ const nestedRelation = tableRelations.map[nestedKey];
147
+ if (nestedRelation && nestedOptions) {
148
+ const nestedAliasPath = `${aliasPath}__${nestedKey}`;
149
+ sql += buildNestedRelationSubquery(nestedAliasPath, aliasPath, nestedOptions, nestedRelation, allRelations, config);
150
+ }
151
+ }
152
+ }
153
+ if (relation.t === "Many" || relation.t === "One") {
154
+ const referencedCol = relation.col.referencesCol;
155
+ sql += ` WHERE "${aliasPath}"."${relation.col.nameSnake}" = "${parentTableAlias}"."${referencedCol.nameSnake}"`;
156
+ if (relation.t === "One") sql += ` LIMIT 1`;
157
+ } else if (relation.t === "Fk") {
158
+ const referencedCol = relation.col.referencesCol;
159
+ sql += ` WHERE "${aliasPath}"."${referencedCol.nameSnake}" = "${parentTableAlias}"."${relation.col.nameSnake}"`;
160
+ sql += ` LIMIT 1`;
161
+ }
162
+ sql += `) "${aliasPath}"`;
163
+ sql += `) "${aliasPath}" ON true`;
164
+ return sql;
165
+ }
166
+ /**
167
+ * Build a nested LATERAL JOIN subquery (for relations within relations).
168
+ * Similar to buildRelationSubquery but with parent alias reference for WHERE conditions.
169
+ */
170
+ function buildNestedRelationSubquery(aliasPath, parentAliasPath, options, relation, allRelations, config) {
171
+ let sql = " LEFT JOIN LATERAL (";
172
+ const jsonSelects = getJsonBuildObjectSelects(aliasPath, options, relation.table, allRelations);
173
+ if (relation.t === "Many") sql += `SELECT coalesce(json_agg(json_build_object(${jsonSelects.join(", ")})), '[]'::json) AS "data"`;
174
+ else sql += `SELECT json_build_object(${jsonSelects.join(", ")}) AS "data"`;
175
+ sql += ` FROM (SELECT "${aliasPath}".*`;
176
+ if (options.with) {
177
+ const tableRelations = allRelations[relation.table._.fullName];
178
+ if (tableRelations) {
179
+ for (const nestedKey in options.with) if (tableRelations.map[nestedKey]) {
180
+ const nestedAliasPath = `${aliasPath}__${nestedKey}`;
181
+ sql += `, "${nestedAliasPath}"."data" AS "${nestedKey}_data"`;
182
+ }
183
+ }
184
+ }
185
+ sql += ` FROM ${relation.table._.fullName} "${aliasPath}"`;
186
+ if (options.with) {
187
+ const tableRelations = allRelations[relation.table._.fullName];
188
+ if (tableRelations) for (const nestedKey in options.with) {
189
+ const nestedOptions = options.with[nestedKey];
190
+ const nestedRelation = tableRelations.map[nestedKey];
191
+ if (nestedRelation && nestedOptions) {
192
+ const nestedAliasPath = `${aliasPath}__${nestedKey}`;
193
+ sql += buildNestedRelationSubquery(nestedAliasPath, aliasPath, nestedOptions, nestedRelation, allRelations, config);
194
+ }
195
+ }
196
+ }
197
+ if (relation.t === "Many" || relation.t === "One") {
198
+ sql += ` WHERE "${aliasPath}"."${relation.col.nameSnake}" = "${parentAliasPath}"."${relation.col.referencesCol.nameSnake}"`;
199
+ if (relation.t === "One") sql += ` LIMIT 1`;
200
+ } else if (relation.t === "Fk") {
201
+ sql += ` WHERE "${aliasPath}"."${relation.col.referencesCol.nameSnake}" = "${parentAliasPath}"."${relation.col.nameSnake}"`;
202
+ sql += ` LIMIT 1`;
203
+ }
204
+ sql += `) "${aliasPath}"`;
205
+ sql += `) "${aliasPath}" ON true`;
206
+ return sql;
207
+ }
208
+ function convert(object, table, allRelations) {
209
+ for (const key of Object.keys(object)) {
210
+ const value = object[key];
211
+ const keyCamel = snakeToCamel(key);
212
+ const column = table._.columns[keyCamel];
213
+ if (column) {
214
+ object[keyCamel] = column.fromDriver(value);
215
+ if (keyCamel !== key) delete object[key];
216
+ } else {
217
+ const relations = allRelations[table._.fullName];
218
+ if (relations) {
219
+ const relation = relations.map[keyCamel];
220
+ if (relation) {
221
+ if (relation.t === "Many") for (const row in object[key]) convert(object[key][row], relation.table, allRelations);
222
+ else if (relation.t === "One" || relation.t === "Fk") {
223
+ if (object[key] !== null) convert(object[key], relation.table, allRelations);
224
+ }
225
+ }
226
+ }
227
+ }
228
+ }
229
+ }
230
+ //#endregion
231
+ export { RelationQueryBuilder };
@@ -0,0 +1,48 @@
1
+ import { Query } from "./query.mjs";
2
+ import { OrderBy } from "./orderby-clause.mjs";
3
+ import { QueryPromise } from "./query-promise.mjs";
4
+ import { BuildFilterExpression, StdCondition } from "../filters/index.mjs";
5
+ import { AnyColumn, AnyTableWithColumns, BuildScmTblColumns, StdTableColumn, TColsToLeftRight, TableColumn, TableWithColumns } from "../table.mjs";
6
+ import { Config } from "../index.mjs";
7
+ import { QueryExecutor } from "../connectors/common.mjs";
8
+
9
+ //#region src/query-builders/select.d.ts
10
+ declare class SelectBuilder<TTSchema extends string, TTName extends string, TTColumns extends Record<string, AnyColumn>, TPrepare extends boolean, TInnerJoins extends null | [{
11
+ table: AnyTableWithColumns;
12
+ on: BuildFilterExpression<TColsToLeftRight<AnyTableWithColumns["_"]["columns"]>>;
13
+ }, ...{
14
+ table: AnyTableWithColumns;
15
+ on: BuildFilterExpression<TColsToLeftRight<AnyTableWithColumns["_"]["columns"]>>;
16
+ }[]]> {
17
+ #private;
18
+ constructor(table: TableWithColumns<TTSchema, TTName, TTColumns>, innerJoins: TInnerJoins, distinctOn: StdTableColumn[] | undefined, config: Config, executor: QueryExecutor, prepare: TPrepare);
19
+ innerJoin<TJoinTSchema extends string, TJoinTName extends string, TJoinTColumns extends Record<string, AnyColumn>, TOn extends BuildFilterExpression<TColsToLeftRight<BuildScmTblColumns<TTSchema, TTName, TTColumns> & BuildScmTblColumns<TJoinTSchema, TJoinTName, TJoinTColumns> & (TInnerJoins extends unknown[] ? UnionToIntersection<TInnerJoins[number]["table"]["$"]["_"]["scmTblColumns"]> : Record<never, never>)>>>(table: TableWithColumns<TJoinTSchema, TJoinTName, TJoinTColumns>, on: TOn): SelectBuilder<TTSchema, TTName, TTColumns, TPrepare, TInnerJoins extends unknown[] ? [...TInnerJoins, {
20
+ table: TableWithColumns<TJoinTSchema, TJoinTName, TJoinTColumns>;
21
+ on: StdCondition;
22
+ }] : [{
23
+ table: TableWithColumns<TJoinTSchema, TJoinTName, TJoinTColumns>;
24
+ on: StdCondition;
25
+ }]>;
26
+ distinctOn(columns: SelfOrArray<Valueof<TableWithColumns<TTSchema, TTName, TTColumns>["_"]["columns"]> | (TInnerJoins extends unknown[] ? Valueof<TInnerJoins[number]["table"]["_"]["columns"]> : never)>): Omit<SelectBuilder<TTSchema, TTName, TTColumns, TPrepare, TInnerJoins>, "distinctOn" | "innerJoin">;
27
+ select(): SelectQuery<TTSchema, TTName, TTColumns, TInnerJoins, undefined, TPrepare, undefined, undefined>;
28
+ select<TSelects extends Record<string, Valueof<TableWithColumns<TTSchema, TTName, TTColumns>["_"]["columns"]> | (TInnerJoins extends unknown[] ? Valueof<TInnerJoins[number]["table"]["_"]["columns"]> : never)>>(selects: TSelects): SelectQuery<TTSchema, TTName, TTColumns, TInnerJoins, TSelects, TPrepare, undefined, undefined>;
29
+ }
30
+ declare class SelectQuery<TTSchema extends string, TTName extends string, TTColumns extends Record<string, AnyColumn>, TInnerJoins extends null | [{
31
+ table: AnyTableWithColumns;
32
+ on: BuildFilterExpression<TColsToLeftRight<AnyTableWithColumns["$"]["_"]["scmTblColumns"]>>;
33
+ }, ...{
34
+ table: AnyTableWithColumns;
35
+ on: BuildFilterExpression<TColsToLeftRight<AnyTableWithColumns["$"]["_"]["scmTblColumns"]>>;
36
+ }[]], TSelects extends Record<string, Valueof<NoInfer<TableWithColumns<TTSchema, TTName, TTColumns>>["_"]["columns"]> | (TInnerJoins extends unknown[] ? Valueof<TInnerJoins[number]["table"]["_"]["columns"]> : never)> | undefined, TPrepare extends boolean, TWhere extends BuildFilterExpression<TColsToLeftRight<NoInfer<TableWithColumns<TTSchema, TTName, TTColumns>>["_"]["columns"]>, TPrepare> | undefined, TOrderBy extends OrderBy<NoInfer<TableWithColumns<TTSchema, TTName, TTColumns>>> | OrderBy<NoInfer<TableWithColumns<TTSchema, TTName, TTColumns>>>[] | undefined, TReturn = (TSelects extends Record<string, unknown> ? { [TCol in keyof TSelects]: TSelects[TCol] extends TableColumn<string, string, Key, infer TColumn> ? TColumn["ValTypeSelect"] : never } : Prettify<TableWithColumns<TTSchema, TTName, TTColumns>["$"]["inferSelect"] & (TInnerJoins extends unknown[] ? UnionToIntersection<TInnerJoins[number]["table"]["$"]["inferSelect"]> : Record<never, never>)>)[]> extends QueryPromise<TReturn> {
37
+ #private;
38
+ constructor(table: TableWithColumns<TTSchema, TTName, TTColumns>, innerJoins: TInnerJoins, select: TSelects, distinctOn: StdTableColumn[] | undefined, where: TWhere, orderBy: TOrderBy, limit: number | undefined, offset: number | undefined, config: Config, executor: QueryExecutor, prepare: TPrepare);
39
+ where<TWhere extends BuildFilterExpression<TColsToLeftRight<BuildScmTblColumns<TTSchema, TTName, TTColumns> & (TInnerJoins extends unknown[] ? UnionToIntersection<TInnerJoins[number]["table"]["$"]["_"]["scmTblColumns"]> : Record<never, never>)>, TPrepare> | undefined>(where: TWhere): SelectQuery<TTSchema, TTName, TTColumns, TInnerJoins, TSelects, TPrepare, TWhere, TOrderBy, (TSelects extends Record<string, unknown> ? { [TCol in keyof TSelects]: TSelects[TCol] extends TableColumn<string, string, Key, infer TColumn extends AnyColumn> ? TColumn["ValTypeSelect"] : never } : TableWithColumns<TTSchema, TTName, TTColumns>["$"]["inferSelect"] & (TInnerJoins extends unknown[] ? UnionToIntersection<TInnerJoins[number]["table"]["$"]["inferSelect"]> : Record<never, never>) extends infer T ? { [K in keyof T]: T[K] } : never)[]>;
40
+ orderBy<TOrderBys extends (OrderBy<TableWithColumns<TTSchema, TTName, TTColumns>> | (TInnerJoins extends unknown[] ? OrderBy<TInnerJoins[number]["table"]> : never)) | (OrderBy<TableWithColumns<TTSchema, TTName, TTColumns>> | (TInnerJoins extends unknown[] ? OrderBy<TInnerJoins[number]["table"]> : never))[]>(orderBy: TOrderBys): SelectQuery<TTSchema, TTName, TTColumns, TInnerJoins, TSelects, TPrepare, TWhere, TOrderBys, (TSelects extends Record<string, unknown> ? { [TCol in keyof TSelects]: TSelects[TCol] extends TableColumn<string, string, Key, infer TColumn extends AnyColumn> ? TColumn["ValTypeSelect"] : never } : TableWithColumns<TTSchema, TTName, TTColumns>["$"]["inferSelect"] & (TInnerJoins extends unknown[] ? UnionToIntersection<TInnerJoins[number]["table"]["$"]["inferSelect"]> : Record<never, never>) extends infer T ? { [K in keyof T]: T[K] } : never)[]>;
41
+ limit(limit: number): Omit<this, "limit">;
42
+ offset(offset: number): Omit<this, "offset">;
43
+ toQuery(): Query<TReturn>;
44
+ execute(): Promise<TReturn>;
45
+ handleRows(rows: Record<string, unknown>[]): TReturn;
46
+ }
47
+ //#endregion
48
+ export { SelectBuilder, SelectQuery };
@@ -0,0 +1,118 @@
1
+ import { QueryPromise } from "./query-promise.mjs";
2
+ import { camelToSnake, snakeToCamel } from "../utils.mjs";
3
+ import { Query } from "./query.mjs";
4
+ //#region src/query-builders/select.ts
5
+ var SelectBuilder = class SelectBuilder {
6
+ #table;
7
+ #config;
8
+ #executor;
9
+ #prepare;
10
+ #$innerJoins;
11
+ #$distinctOn;
12
+ constructor(table, innerJoins, distinctOn, config, executor, prepare) {
13
+ this.#table = table;
14
+ this.#$innerJoins = innerJoins;
15
+ this.#$distinctOn = distinctOn;
16
+ this.#config = config;
17
+ this.#executor = executor;
18
+ this.#prepare = prepare;
19
+ }
20
+ innerJoin(table, on) {
21
+ return new SelectBuilder(this.#table, this.#$innerJoins ? [...this.#$innerJoins, {
22
+ table,
23
+ on
24
+ }] : [{
25
+ table,
26
+ on
27
+ }], void 0, this.#config, this.#executor, this.#prepare);
28
+ }
29
+ distinctOn(columns) {
30
+ return new SelectBuilder(this.#table, this.#$innerJoins, Array.isArray(columns) ? columns : [columns], this.#config, this.#executor, this.#prepare);
31
+ }
32
+ select(selects) {
33
+ return new SelectQuery(this.#table, this.#$innerJoins, selects, this.#$distinctOn, void 0, void 0, void 0, void 0, this.#config, this.#executor, this.#prepare);
34
+ }
35
+ };
36
+ var SelectQuery = class SelectQuery extends QueryPromise {
37
+ #table;
38
+ #$select;
39
+ #$distinctOn;
40
+ #$where;
41
+ #$innerJoins;
42
+ #$orderBy;
43
+ #$limit;
44
+ #$offset;
45
+ #config;
46
+ #executor;
47
+ #prepare;
48
+ constructor(table, innerJoins, select, distinctOn, where, orderBy, limit, offset, config, executor, prepare) {
49
+ super();
50
+ this.#table = table;
51
+ this.#$select = select;
52
+ this.#$distinctOn = distinctOn;
53
+ this.#$innerJoins = innerJoins;
54
+ this.#$where = where;
55
+ this.#$orderBy = orderBy;
56
+ this.#$limit = limit;
57
+ this.#$offset = offset;
58
+ this.#config = config;
59
+ this.#executor = executor;
60
+ this.#prepare = prepare;
61
+ }
62
+ where(where) {
63
+ return new SelectQuery(this.#table, this.#$innerJoins, this.#$select, this.#$distinctOn, where, this.#$orderBy, this.#$limit, this.#$offset, this.#config, this.#executor, this.#prepare);
64
+ }
65
+ orderBy(orderBy) {
66
+ return new SelectQuery(this.#table, this.#$innerJoins, this.#$select, this.#$distinctOn, this.#$where, orderBy, this.#$limit, this.#$offset, this.#config, this.#executor, this.#prepare);
67
+ }
68
+ limit(limit) {
69
+ return new SelectQuery(this.#table, this.#$innerJoins, this.#$select, this.#$distinctOn, this.#$where, this.#$orderBy, limit, this.#$offset, this.#config, this.#executor, this.#prepare);
70
+ }
71
+ offset(offset) {
72
+ return new SelectQuery(this.#table, this.#$innerJoins, this.#$select, this.#$distinctOn, this.#$where, this.#$orderBy, this.#$limit, offset, this.#config, this.#executor, this.#prepare);
73
+ }
74
+ toQuery() {
75
+ const query = new Query("SELECT ", this.handleRows.bind(this));
76
+ if (this.#$distinctOn?.length) query.sql += `DISTINCT ON (${this.#$distinctOn.map((c) => c.fullName).join(", ")}) `;
77
+ query.sql += this.#$select ? Object.entries(this.#$select).map(([key, column]) => `${column.fullName} AS ${camelToSnake(key)}`).join(", ") : "*";
78
+ query.sql += " FROM ";
79
+ query.sql += this.#table._.fullName;
80
+ this.#$innerJoins?.forEach((innerJoin) => {
81
+ const join = innerJoin;
82
+ query.sql += ` INNER JOIN ${join.table._.fullName} ON ${join.on.toSQL()}`;
83
+ });
84
+ if (this.#$where) {
85
+ query.sql += " WHERE ";
86
+ if (this.#prepare) this.#$where.toQuery(query);
87
+ else query.sql += this.#$where.toSQL();
88
+ }
89
+ if (this.#$orderBy) {
90
+ const orders = Array.isArray(this.#$orderBy) ? this.#$orderBy : [this.#$orderBy];
91
+ query.sql += ` ORDER BY ${orders.map((o) => o.toSQL()).join(", ")}`;
92
+ }
93
+ if (this.#$limit) query.sql += ` LIMIT ${this.#$limit}`;
94
+ if (this.#$offset) query.sql += ` OFFSET ${this.#$offset}`;
95
+ return query;
96
+ }
97
+ async execute() {
98
+ const query = this.toQuery();
99
+ query.sql += ";";
100
+ const res = await this.#executor.query(query.sql, query.arguments);
101
+ const rows = this.#executor.getRows(res);
102
+ return this.handleRows(rows);
103
+ }
104
+ handleRows(rows) {
105
+ const { columns } = this.#table._;
106
+ const cols = this.#$select ?? columns;
107
+ rows.forEach((row) => {
108
+ for (const [key, value] of Object.entries(row)) {
109
+ const keyCamel = snakeToCamel(key);
110
+ row[keyCamel] = cols[keyCamel].fromDriver(value);
111
+ if (keyCamel !== key) delete row[key];
112
+ }
113
+ });
114
+ return rows;
115
+ }
116
+ };
117
+ //#endregion
118
+ export { SelectBuilder };
@@ -0,0 +1,24 @@
1
+ import { Query } from "./query.mjs";
2
+ import { QueryPromise } from "./query-promise.mjs";
3
+ import { BuildFilterExpression } from "../filters/index.mjs";
4
+ import { AnyColumn, TColsToLeftRight, TableWithColumns } from "../table.mjs";
5
+ import { Config } from "../index.mjs";
6
+ import { QueryExecutor } from "../connectors/common.mjs";
7
+
8
+ //#region src/query-builders/update.d.ts
9
+ declare class UpdateBuilder<TTableWC extends TableWithColumns<string, string, Record<string, AnyColumn>>, TPrepare extends boolean> {
10
+ #private;
11
+ constructor(table: TTableWC, config: Config, executor: QueryExecutor, prepare: TPrepare);
12
+ set<TValues extends { [colName in keyof TTableWC["_"]["columns"]]?: TTableWC["_"]["columns"][colName]["ValTypeUpdate"] }>(values: TValues): UpdateQuery<TTableWC, TValues, TPrepare, undefined, undefined, null>;
13
+ }
14
+ declare class UpdateQuery<TTableWC extends TableWithColumns<string, string, Record<string, AnyColumn>>, TValues extends { [colName in keyof TTableWC["_"]["columns"]]?: TTableWC["_"]["columns"][colName]["ValTypeUpdate"] }, TPrepare extends boolean, TWhere extends BuildFilterExpression<TColsToLeftRight<TTableWC["_"]["columns"]>, TPrepare> | undefined, TReturning extends { [ColName in keyof TTableWC["_"]["columns"]]?: true } | { [ColName in keyof TTableWC["_"]["columns"]]?: false } | undefined, TReturn = (TReturning extends Record<Key, boolean> ? TReturning extends { [ColName in keyof TTableWC["_"]["columns"]]?: false } ? { [ColName in keyof TTableWC["_"]["columns"] as TReturning[ColName] extends false ? never : ColName]: TTableWC["_"]["columns"][ColName]["ValTypeSelect"] }[] : { [ColName in keyof TTableWC["_"]["columns"] as TReturning[ColName] extends true ? ColName : never]: TTableWC["_"]["columns"][ColName]["ValTypeSelect"] }[] : null)> extends QueryPromise<TReturn> {
15
+ #private;
16
+ constructor(table: TTableWC, values: TValues, where: TWhere, returnings: TReturning, config: Config, executor: QueryExecutor, prepare: TPrepare);
17
+ where<TWhere extends BuildFilterExpression<TColsToLeftRight<TTableWC["_"]["columns"]>, TPrepare>>(where: TWhere): UpdateQuery<TTableWC, TValues, TPrepare, TWhere, TReturning, TReturning extends Record<Key, boolean> ? TReturning extends { [ColName in keyof TTableWC["_"]["columns"]]?: false | undefined } ? { [ColName_1 in keyof TTableWC["_"]["columns"] as TReturning[ColName_1] extends false ? never : ColName_1]: TTableWC["_"]["columns"][ColName_1]["ValTypeSelect"] }[] : { [ColName_2 in keyof TTableWC["_"]["columns"] as TReturning[ColName_2] extends true ? ColName_2 : never]: TTableWC["_"]["columns"][ColName_2]["ValTypeSelect"] }[] : null>;
18
+ returning<TReturnings extends { [ColName in keyof TTableWC["_"]["columns"]]?: true } | { [ColName in keyof TTableWC["_"]["columns"]]?: false }>(returnings: TReturnings): UpdateQuery<TTableWC, TValues, TPrepare, TWhere, TReturnings, TReturnings extends Record<Key, boolean> ? TReturnings extends { [ColName in keyof TTableWC["_"]["columns"]]?: false | undefined } ? { [ColName_1 in keyof TTableWC["_"]["columns"] as TReturnings[ColName_1] extends false ? never : ColName_1]: TTableWC["_"]["columns"][ColName_1]["ValTypeSelect"] }[] : { [ColName_2 in keyof TTableWC["_"]["columns"] as TReturnings[ColName_2] extends true ? ColName_2 : never]: TTableWC["_"]["columns"][ColName_2]["ValTypeSelect"] }[] : null>;
19
+ toQuery(): Query<TReturn>;
20
+ execute(): Promise<TReturn>;
21
+ handleRows(rows: Record<string, unknown>[]): TReturn;
22
+ }
23
+ //#endregion
24
+ export { UpdateBuilder };
@@ -0,0 +1,99 @@
1
+ import { QueryPromise } from "./query-promise.mjs";
2
+ import { snakeToCamel } from "../utils.mjs";
3
+ import { Query } from "./query.mjs";
4
+ //#region src/query-builders/update.ts
5
+ var UpdateBuilder = class {
6
+ #table;
7
+ #config;
8
+ #executor;
9
+ #prepare;
10
+ constructor(table, config, executor, prepare) {
11
+ this.#table = table;
12
+ this.#config = config;
13
+ this.#executor = executor;
14
+ this.#prepare = prepare;
15
+ }
16
+ set(values) {
17
+ return new UpdateQuery(this.#table, values, void 0, void 0, this.#config, this.#executor, this.#prepare);
18
+ }
19
+ };
20
+ var UpdateQuery = class UpdateQuery extends QueryPromise {
21
+ #table;
22
+ #values;
23
+ #$where;
24
+ #$returning;
25
+ #config;
26
+ #executor;
27
+ #prepare;
28
+ constructor(table, values, where, returnings, config, executor, prepare) {
29
+ super();
30
+ this.#table = table;
31
+ this.#values = values;
32
+ this.#$where = where;
33
+ this.#$returning = returnings;
34
+ this.#config = config;
35
+ this.#executor = executor;
36
+ this.#prepare = prepare;
37
+ }
38
+ where(where) {
39
+ return new UpdateQuery(this.#table, this.#values, where, this.#$returning, this.#config, this.#executor, this.#prepare);
40
+ }
41
+ returning(returnings) {
42
+ return new UpdateQuery(this.#table, this.#values, this.#$where, returnings, this.#config, this.#executor, this.#prepare);
43
+ }
44
+ toQuery() {
45
+ const query = new Query("UPDATE ", this.handleRows.bind(this));
46
+ query.sql += this.#table._.fullName;
47
+ query.sql += " SET ";
48
+ const explicitFields = new Set(Object.keys(this.#values));
49
+ const allFields = [];
50
+ const allValues = [];
51
+ for (const field of explicitFields) {
52
+ allFields.push(field);
53
+ allValues.push(this.#values[field]);
54
+ }
55
+ for (const colName in this.#table._.columns) {
56
+ const column = this.#table._.columns[colName];
57
+ if (!explicitFields.has(colName) && column.hasUpdateFn) {
58
+ allFields.push(colName);
59
+ allValues.push(column.getUpdateFnVal());
60
+ }
61
+ }
62
+ if (this.#prepare) query.sql += allFields.map((field, index) => `"${field}" = ${this.#table._.columns[field].toSQL(allValues[index])}`).join(", ");
63
+ else {
64
+ query.arguments = allFields.map((field, index) => this.#table._.columns[field].toDriver(allValues[index]));
65
+ query.sql += allFields.map((field, index) => `"${this.#table._.columns[field].nameSnake}" = $${index + 1}`).join(", ");
66
+ }
67
+ if (this.#$where) {
68
+ query.sql += ` WHERE `;
69
+ if (this.#prepare) this.#$where.toQuery(query);
70
+ else query.sql += this.#$where.toSQL();
71
+ }
72
+ if (this.#$returning) {
73
+ query.sql += " RETURNING ";
74
+ const returningFields = Object.keys(this.#$returning).filter((k) => this.#$returning?.[k] === true);
75
+ query.sql += returningFields.map((field) => `"${this.#table._.columns[field].nameSnake}"`).join(", ");
76
+ }
77
+ query.sql += ";";
78
+ return query;
79
+ }
80
+ async execute() {
81
+ const query = this.toQuery();
82
+ const res = await this.#executor.query(query.sql, query.arguments);
83
+ const rows = this.#executor.getRows(res);
84
+ return this.handleRows(rows);
85
+ }
86
+ handleRows(rows) {
87
+ const { columns } = this.#table._;
88
+ rows.forEach((row) => {
89
+ for (const [key, value] of Object.entries(row)) {
90
+ const keyCamel = snakeToCamel(key);
91
+ row[keyCamel] = columns[keyCamel].fromDriver(value);
92
+ if (keyCamel !== key) delete row[key];
93
+ }
94
+ });
95
+ return rows;
96
+ }
97
+ };
98
+ //#endregion
99
+ export { UpdateBuilder };
@@ -0,0 +1,48 @@
1
+ import { Sql } from "./sql.mjs";
2
+ import { entityType } from "./symbols.mjs";
3
+
4
+ //#region src/sequence.d.ts
5
+ interface SequenceOptions {
6
+ /** The starting value of the sequence */
7
+ startWith?: number;
8
+ /** The increment value for the sequence */
9
+ increment?: number;
10
+ /** The minimum value of the sequence */
11
+ minValue?: number;
12
+ /** The maximum value of the sequence */
13
+ maxValue?: number;
14
+ /** Whether the sequence should cycle when it reaches its max/min value */
15
+ cycle?: boolean;
16
+ /** The number of sequence values to cache for faster access */
17
+ cache?: number;
18
+ }
19
+ declare class Sequence<TConfig extends SequenceOptions = SequenceOptions> {
20
+ #private;
21
+ static readonly [entityType] = "Sequence";
22
+ constructor(schema: string, name: string, config: TConfig);
23
+ get schema(): string;
24
+ get name(): string;
25
+ get config(): TConfig;
26
+ /** Returns SQL: nextval('schema.sequence_name') for use in column defaults or queries */
27
+ nextval(): Sql;
28
+ /** Returns SQL: currval('schema.sequence_name') */
29
+ currval(): Sql;
30
+ /** Returns SQL: setval('schema.sequence_name', value) */
31
+ setval(value: number): Sql;
32
+ }
33
+ /**
34
+ * Creates a typed PostgreSQL sequence definition.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { sequence } from "durcno";
39
+ *
40
+ * export const UserIdSeq = sequence("public", "user_id_seq", {
41
+ * startWith: 1,
42
+ * increment: 1,
43
+ * });
44
+ * ```
45
+ */
46
+ declare function sequence<TConfig extends SequenceOptions>(schema: string, name: string, config?: TConfig): Sequence<TConfig>;
47
+ //#endregion
48
+ export { Sequence, SequenceOptions, sequence };
@@ -0,0 +1,53 @@
1
+ import { entityType } from "./symbols.mjs";
2
+ import { Sql } from "./sql.mjs";
3
+ //#region src/sequence.ts
4
+ var Sequence = class {
5
+ static [entityType] = "Sequence";
6
+ #schema;
7
+ #name;
8
+ #config;
9
+ constructor(schema, name, config) {
10
+ this.#schema = schema;
11
+ this.#name = name;
12
+ this.#config = config;
13
+ }
14
+ get schema() {
15
+ return this.#schema;
16
+ }
17
+ get name() {
18
+ return this.#name;
19
+ }
20
+ get config() {
21
+ return this.#config;
22
+ }
23
+ /** Returns SQL: nextval('schema.sequence_name') for use in column defaults or queries */
24
+ nextval() {
25
+ return new Sql(`nextval('${this.#schema ? `"${this.#schema}"."${this.#name}"` : `"${this.#name}"`}')`);
26
+ }
27
+ /** Returns SQL: currval('schema.sequence_name') */
28
+ currval() {
29
+ return new Sql(`currval('${this.#schema ? `"${this.#schema}"."${this.#name}"` : `"${this.#name}"`}')`);
30
+ }
31
+ /** Returns SQL: setval('schema.sequence_name', value) */
32
+ setval(value) {
33
+ return new Sql(`setval('${this.#schema ? `"${this.#schema}"."${this.#name}"` : `"${this.#name}"`}', ${value})`);
34
+ }
35
+ };
36
+ /**
37
+ * Creates a typed PostgreSQL sequence definition.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import { sequence } from "durcno";
42
+ *
43
+ * export const UserIdSeq = sequence("public", "user_id_seq", {
44
+ * startWith: 1,
45
+ * increment: 1,
46
+ * });
47
+ * ```
48
+ */
49
+ function sequence(schema, name, config = {}) {
50
+ return new Sequence(schema, name, config);
51
+ }
52
+ //#endregion
53
+ export { Sequence, sequence };
@@ -0,0 +1,15 @@
1
+ import { Query } from "./query-builders/query.mjs";
2
+ import { AnyTableColumn } from "./table.mjs";
3
+
4
+ //#region src/sql.d.ts
5
+ declare class Sql {
6
+ #private;
7
+ constructor(sql: string);
8
+ get string(): string;
9
+ toSQL(): string;
10
+ toQuery(query: Query): void;
11
+ }
12
+ type SqlParam = string | number | bigint | boolean | null | undefined | AnyTableColumn;
13
+ declare function sql(strings: TemplateStringsArray, ...params: SqlParam[]): Sql;
14
+ //#endregion
15
+ export { Sql, sql };