prisma-ts-select 0.1.6 → 0.1.8

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Adrian Elton-Browning
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/dist/bin.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- require('./chunk-GSIFF2TF.cjs');
4
+ require('./chunk-RX2M26LV.cjs');
5
5
 
package/dist/bin.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import './chunk-NFKUA5XM.js';
2
+ import './chunk-F7HSD6UA.js';
@@ -51,6 +51,7 @@ generatorHandler({
51
51
  }, []).join(", ")}`);
52
52
  }
53
53
  const modelToId = {};
54
+ const m2mMap = {};
54
55
  const models = options.dmmf.datamodel.models.reduce((acc, model) => {
55
56
  const modelObj = acc[model.name] = acc[model.name] ?? {
56
57
  fields: {},
@@ -79,6 +80,11 @@ generatorHandler({
79
80
  } else {
80
81
  if (!isManyToManyRelationShip(field)) continue;
81
82
  const joinTableName = "_" + field.relationName;
83
+ const src = model.name, tgt = field.type;
84
+ (m2mMap[src] ??= {})[tgt] ??= /* @__PURE__ */ new Set();
85
+ m2mMap[src][tgt].add(joinTableName);
86
+ (m2mMap[tgt] ??= {})[src] ??= /* @__PURE__ */ new Set();
87
+ m2mMap[tgt][src].add(joinTableName);
82
88
  const joinTableModel = acc[joinTableName] = acc[joinTableName] ?? {
83
89
  fields: {
84
90
  "A": "",
@@ -214,7 +220,7 @@ export { ${provider}Dialect as dialect, ${provider}Dialect, ${ctxName} as dialec
214
220
  const PLACEHOLDER = "type SelectFnContext<_TSources extends TArrSources, _TFields extends TFieldsType> = BaseSelectFnContext<_TSources, _TFields>;";
215
221
  const JOIN_RETURN_RE = /type _fJoinReturn<[^>]+>[^;]+;/;
216
222
  const joinReturnReplacement = omittedMethods.length > 0 ? `type _fJoinReturn<TSources extends TArrSources, TFields extends TFieldsType, TCTEs extends Record<string, Record<string, any>> = {}> = Omit<_fJoin<TSources, TFields, TCTEs>, ${omittedMethods.map((m) => `"${m}"`).join(" | ")}>;` : `type _fJoinReturn<TSources extends TArrSources, TFields extends TFieldsType, TCTEs extends Record<string, Record<string, any>> = {}> = _fJoin<TSources, TFields, TCTEs>;`;
217
- const replacedExtendDts = extendDts.replace("declare const DB: DBType;", declaration).replace(
223
+ const replacedExtendDts = extendDts.replace("declare const DB: DBType;", declaration).replace("type M2MMap = {};", generateM2MMapDeclaration(m2mMap)).replace(
218
224
  PLACEHOLDER,
219
225
  `type SelectFnContext<_TSources extends TArrSources, _TFields extends TFieldsType> = Omit<BaseSelectFnContext<_TSources, _TFields>, keyof DialectFns<ColEntries<_TSources, _TFields>, WhereCriteria<_TSources, _TFields>>> & DialectFns<ColEntries<_TSources, _TFields>, WhereCriteria<_TSources, _TFields>>;`
220
226
  ).replace(JOIN_RETURN_RE, joinReturnReplacement);
@@ -300,3 +306,19 @@ function generateReadonlyDeclaration(db) {
300
306
  ${traverse(db, 1)}
301
307
  };`;
302
308
  }
309
+ function generateM2MMapDeclaration(m2mMap) {
310
+ if (Object.keys(m2mMap).length === 0) return "type M2MMap = {};";
311
+ const lines = ["type M2MMap = {"];
312
+ for (const [source, targets] of Object.entries(m2mMap)) {
313
+ lines.push(` readonly "${source}": {`);
314
+ for (const [target, junctions] of Object.entries(targets)) {
315
+ const junctionLiterals = Array.from(junctions).map((j) => `"${j}"`).join(" | ");
316
+ lines.push(` readonly "${target}": ${junctionLiterals};`);
317
+ }
318
+ lines.push(" };");
319
+ }
320
+ lines.push("};");
321
+ return lines.join("\n");
322
+ }
323
+
324
+ export { generateM2MMapDeclaration };
@@ -59,6 +59,7 @@ generatorHelper.generatorHandler({
59
59
  }, []).join(", ")}`);
60
60
  }
61
61
  const modelToId = {};
62
+ const m2mMap = {};
62
63
  const models = options.dmmf.datamodel.models.reduce((acc, model) => {
63
64
  const modelObj = acc[model.name] = acc[model.name] ?? {
64
65
  fields: {},
@@ -87,6 +88,11 @@ generatorHelper.generatorHandler({
87
88
  } else {
88
89
  if (!isManyToManyRelationShip(field)) continue;
89
90
  const joinTableName = "_" + field.relationName;
91
+ const src = model.name, tgt = field.type;
92
+ (m2mMap[src] ??= {})[tgt] ??= /* @__PURE__ */ new Set();
93
+ m2mMap[src][tgt].add(joinTableName);
94
+ (m2mMap[tgt] ??= {})[src] ??= /* @__PURE__ */ new Set();
95
+ m2mMap[tgt][src].add(joinTableName);
90
96
  const joinTableModel = acc[joinTableName] = acc[joinTableName] ?? {
91
97
  fields: {
92
98
  "A": "",
@@ -222,7 +228,7 @@ export { ${provider}Dialect as dialect, ${provider}Dialect, ${ctxName} as dialec
222
228
  const PLACEHOLDER = "type SelectFnContext<_TSources extends TArrSources, _TFields extends TFieldsType> = BaseSelectFnContext<_TSources, _TFields>;";
223
229
  const JOIN_RETURN_RE = /type _fJoinReturn<[^>]+>[^;]+;/;
224
230
  const joinReturnReplacement = omittedMethods.length > 0 ? `type _fJoinReturn<TSources extends TArrSources, TFields extends TFieldsType, TCTEs extends Record<string, Record<string, any>> = {}> = Omit<_fJoin<TSources, TFields, TCTEs>, ${omittedMethods.map((m) => `"${m}"`).join(" | ")}>;` : `type _fJoinReturn<TSources extends TArrSources, TFields extends TFieldsType, TCTEs extends Record<string, Record<string, any>> = {}> = _fJoin<TSources, TFields, TCTEs>;`;
225
- const replacedExtendDts = extendDts.replace("declare const DB: DBType;", declaration).replace(
231
+ const replacedExtendDts = extendDts.replace("declare const DB: DBType;", declaration).replace("type M2MMap = {};", generateM2MMapDeclaration(m2mMap)).replace(
226
232
  PLACEHOLDER,
227
233
  `type SelectFnContext<_TSources extends TArrSources, _TFields extends TFieldsType> = Omit<BaseSelectFnContext<_TSources, _TFields>, keyof DialectFns<ColEntries<_TSources, _TFields>, WhereCriteria<_TSources, _TFields>>> & DialectFns<ColEntries<_TSources, _TFields>, WhereCriteria<_TSources, _TFields>>;`
228
234
  ).replace(JOIN_RETURN_RE, joinReturnReplacement);
@@ -308,3 +314,19 @@ function generateReadonlyDeclaration(db) {
308
314
  ${traverse(db, 1)}
309
315
  };`;
310
316
  }
317
+ function generateM2MMapDeclaration(m2mMap) {
318
+ if (Object.keys(m2mMap).length === 0) return "type M2MMap = {};";
319
+ const lines = ["type M2MMap = {"];
320
+ for (const [source, targets] of Object.entries(m2mMap)) {
321
+ lines.push(` readonly "${source}": {`);
322
+ for (const [target, junctions] of Object.entries(targets)) {
323
+ const junctionLiterals = Array.from(junctions).map((j) => `"${j}"`).join(" | ");
324
+ lines.push(` readonly "${target}": ${junctionLiterals};`);
325
+ }
326
+ lines.push(" };");
327
+ }
328
+ lines.push("};");
329
+ return lines.join("\n");
330
+ }
331
+
332
+ exports.generateM2MMapDeclaration = generateM2MMapDeclaration;
@@ -48,7 +48,7 @@ var sqliteContextFns = (quoteFn, condFn) => ({
48
48
  if (isDistinct(col) && sep !== void 0) {
49
49
  throw new Error("SQLite does not support GROUP_CONCAT(DISTINCT col, sep) \u2014 omit the separator.");
50
50
  }
51
- return sqlExpr(`GROUP_CONCAT(${inner}${sep !== void 0 ? `, '${sep.replace(/'/g, "''")}'` : ""})`);
51
+ return sqlExpr(`GROUP_CONCAT(${inner}${sep !== void 0 ? `, '${esc(sep)}'` : ""})`);
52
52
  },
53
53
  total: (col) => sqlExpr(`TOTAL(${quoteFn(col)})`),
54
54
  // SQLite MIN/MAX return bigint for integer columns — override base (number) return types
@@ -123,11 +123,11 @@ var sqliteDialect = {
123
123
  name: "sqlite",
124
124
  needsBooleanCoercion: () => true,
125
125
  quote: (name, _isAlias) => {
126
- if (_isAlias) return "`" + name + "`";
126
+ if (_isAlias) return "`" + name.replace(/`/g, "``") + "`";
127
127
  return name;
128
128
  },
129
129
  quoteTableIdentifier: (name, _isAlias) => {
130
- if (_isAlias) return "`" + name + "`";
130
+ if (_isAlias) return "`" + name.replace(/`/g, "``") + "`";
131
131
  return name;
132
132
  },
133
133
  quoteQualifiedColumn: (ref) => {
@@ -151,12 +151,12 @@ var sqliteDialect = {
151
151
  var mysqlDialect = {
152
152
  name: "mysql",
153
153
  needsBooleanCoercion: () => true,
154
- quote: (id, _isAlias) => `\`${id}\``,
155
- quoteTableIdentifier: (name, _isAlias) => `\`${name}\``,
154
+ quote: (id, _isAlias) => `\`${id.replace(/`/g, "``")}\``,
155
+ quoteTableIdentifier: (name, _isAlias) => `\`${name.replace(/`/g, "``")}\``,
156
156
  quoteQualifiedColumn: (ref) => {
157
- if (!ref.includes(".")) return `\`${ref}\``;
157
+ if (!ref.includes(".")) return `\`${ref.replace(/`/g, "``")}\``;
158
158
  const [table, col] = ref.split(".", 2);
159
- return `\`${table}\`.\`${col}\``;
159
+ return `\`${table.replace(/`/g, "``")}\`.\`${col.replace(/`/g, "``")}\``;
160
160
  },
161
161
  quoteOrderByClause: (clause) => {
162
162
  const parts = clause.trim().split(/\s+/);
@@ -174,12 +174,12 @@ var mysqlDialect = {
174
174
  var postgresqlDialect = {
175
175
  name: "postgresql",
176
176
  needsBooleanCoercion: () => false,
177
- quote: (id, _isAlias) => `"${id}"`,
178
- quoteTableIdentifier: (name, _isAlias) => `"${name}"`,
177
+ quote: (id, _isAlias) => `"${id.replace(/"/g, '""')}"`,
178
+ quoteTableIdentifier: (name, _isAlias) => `"${name.replace(/"/g, '""')}"`,
179
179
  quoteQualifiedColumn: (ref) => {
180
- if (!ref.includes(".")) return `"${ref}"`;
180
+ if (!ref.includes(".")) return `"${ref.replace(/"/g, '""')}"`;
181
181
  const [table, col] = ref.split(".", 2);
182
- return `"${table}"."${col}"`;
182
+ return `"${table.replace(/"/g, '""')}"."${col.replace(/"/g, '""')}"`;
183
183
  },
184
184
  quoteOrderByClause: (clause) => {
185
185
  const parts = clause.trim().split(/\s+/);
@@ -1,7 +1,7 @@
1
1
  import { IntervalUnit } from './mysql.js';
2
2
  export { mysqlDialect } from './mysql.js';
3
3
  import { J as JSONValue, a as JSONObject } from '../types-B0F8m0ok.js';
4
- import { S as SQLExpr, a as SQLDistinct } from '../sql-expr-BGSEwzCi.js';
4
+ import { S as SQLExpr, a as SQLDistinct, D as DISTINCT_BRAND } from '../sql-expr-BGSEwzCi.js';
5
5
  import { ColName, FilterCols, ColTypeOf, FilterJsonCols } from './shared.js';
6
6
  import * as _prisma_client_runtime_client from '@prisma/client/runtime/client';
7
7
  import './types.js';
@@ -16,10 +16,12 @@ declare const mysqlV6ContextFns: <TColEntries extends [string, unknown] = never,
16
16
  floor: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<bigint | number>;
17
17
  mod: (col: FilterCols<TColEntries, number> | SQLExpr<number>, divisor: number) => SQLExpr<bigint | number>;
18
18
  sign: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<bigint | number>;
19
- avg: (col: SQLExpr<number> | FilterCols<TColEntries, number>) => SQLExpr<_prisma_client_runtime_client.Decimal>;
20
- sum: (col: SQLExpr<number> | FilterCols<TColEntries, number>) => SQLExpr<_prisma_client_runtime_client.Decimal>;
21
- distinct: <Col extends ColName<TColEntries>>(col: Col) => SQLDistinct<NonNullable<ColTypeOf<TColEntries, Col>>>;
22
- groupConcat: (col: SQLExpr<string> | ColName<TColEntries>, sep?: string) => SQLExpr<string>;
19
+ avg: (col: SQLExpr<number | null> | FilterCols<TColEntries, number>) => SQLExpr<_prisma_client_runtime_client.Decimal>;
20
+ sum: (col: SQLExpr<number | null> | FilterCols<TColEntries, number>) => SQLExpr<_prisma_client_runtime_client.Decimal>;
21
+ distinct: <Col extends ColName<TColEntries>>(col: Col) => SQLDistinct<ColTypeOf<TColEntries, Col>>;
22
+ groupConcat: (<T extends string | null>(col: SQLDistinct<T>, sep?: string) => SQLExpr<T>) & (<Col extends ColName<TColEntries>>(col: Col, sep?: string) => SQLExpr<null extends ColTypeOf<TColEntries, Col> ? string | (ColTypeOf<TColEntries, Col> & null) : string>) & (<T extends string | null>(col: SQLExpr<T> & {
23
+ readonly [DISTINCT_BRAND]?: never;
24
+ }, sep?: string) => SQLExpr<T>);
23
25
  bitAnd: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
24
26
  bitOr: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
25
27
  bitXor: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
@@ -101,4 +103,4 @@ declare const mysqlV6ContextFns: <TColEntries extends [string, unknown] = never,
101
103
  };
102
104
  type DialectFns<TColEntries extends [string, unknown] = never, TCriteria extends object = object> = ReturnType<typeof mysqlV6ContextFns<TColEntries, TCriteria>>;
103
105
 
104
- export { type DialectFns, IntervalUnit, mysqlV6ContextFns };
106
+ export { DISTINCT_BRAND, type DialectFns, IntervalUnit, mysqlV6ContextFns };
@@ -128,12 +128,12 @@ var mysqlContextFns = (quoteFn, condFn) => ({
128
128
  var mysqlDialect = {
129
129
  name: "mysql",
130
130
  needsBooleanCoercion: () => true,
131
- quote: (id, _isAlias) => `\`${id}\``,
132
- quoteTableIdentifier: (name, _isAlias) => `\`${name}\``,
131
+ quote: (id, _isAlias) => `\`${id.replace(/`/g, "``")}\``,
132
+ quoteTableIdentifier: (name, _isAlias) => `\`${name.replace(/`/g, "``")}\``,
133
133
  quoteQualifiedColumn: (ref) => {
134
- if (!ref.includes(".")) return `\`${ref}\``;
134
+ if (!ref.includes(".")) return `\`${ref.replace(/`/g, "``")}\``;
135
135
  const [table, col] = ref.split(".", 2);
136
- return `\`${table}\`.\`${col}\``;
136
+ return `\`${table.replace(/`/g, "``")}\`.\`${col.replace(/`/g, "``")}\``;
137
137
  },
138
138
  quoteOrderByClause: (clause) => {
139
139
  const parts = clause.trim().split(/\s+/);
@@ -161,4 +161,4 @@ var mysqlV6ContextFns = (quoteFn, condFn) => ({
161
161
  sign: (col) => sqlExpr(`SIGN(${resolveArg(col, quoteFn)})`)
162
162
  });
163
163
 
164
- export { mysqlDialect, mysqlV6ContextFns };
164
+ export { DISTINCT_BRAND, mysqlDialect, mysqlV6ContextFns };
@@ -128,12 +128,12 @@ var mysqlContextFns = (quoteFn, condFn) => ({
128
128
  var mysqlDialect = {
129
129
  name: "mysql",
130
130
  needsBooleanCoercion: () => true,
131
- quote: (id, _isAlias) => `\`${id}\``,
132
- quoteTableIdentifier: (name, _isAlias) => `\`${name}\``,
131
+ quote: (id, _isAlias) => `\`${id.replace(/`/g, "``")}\``,
132
+ quoteTableIdentifier: (name, _isAlias) => `\`${name.replace(/`/g, "``")}\``,
133
133
  quoteQualifiedColumn: (ref) => {
134
- if (!ref.includes(".")) return `\`${ref}\``;
134
+ if (!ref.includes(".")) return `\`${ref.replace(/`/g, "``")}\``;
135
135
  const [table, col] = ref.split(".", 2);
136
- return `\`${table}\`.\`${col}\``;
136
+ return `\`${table.replace(/`/g, "``")}\`.\`${col.replace(/`/g, "``")}\``;
137
137
  },
138
138
  quoteOrderByClause: (clause) => {
139
139
  const parts = clause.trim().split(/\s+/);
@@ -1,5 +1,5 @@
1
1
  import { Dialect } from './types.js';
2
- import { S as SQLExpr, a as SQLDistinct } from '../sql-expr-BGSEwzCi.js';
2
+ import { S as SQLExpr, a as SQLDistinct, D as DISTINCT_BRAND } from '../sql-expr-BGSEwzCi.js';
3
3
  import { J as JSONValue, a as JSONObject } from '../types-B0F8m0ok.js';
4
4
  import { Decimal } from '@prisma/client/runtime/client';
5
5
  import { FilterCols, ColName, ColTypeOf, FilterJsonCols } from './shared.js';
@@ -19,14 +19,16 @@ type MySQLCastTypeMap = {
19
19
  };
20
20
  type IntervalUnit = 'MICROSECOND' | 'SECOND' | 'MINUTE' | 'HOUR' | 'DAY' | 'WEEK' | 'MONTH' | 'QUARTER' | 'YEAR';
21
21
  declare const mysqlContextFns: <TColEntries extends [string, unknown] = never, TCriteria extends object = object>(quoteFn: (ref: string) => string, condFn: (criteria: TCriteria) => string) => {
22
- avg: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<Decimal>;
23
- sum: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<Decimal>;
22
+ avg: (col: FilterCols<TColEntries, number> | SQLExpr<number | null>) => SQLExpr<Decimal>;
23
+ sum: (col: FilterCols<TColEntries, number> | SQLExpr<number | null>) => SQLExpr<Decimal>;
24
24
  countAll: () => SQLExpr<bigint>;
25
25
  count: (col: ColName<TColEntries> | "*" | SQLExpr<unknown>) => SQLExpr<bigint>;
26
26
  countDistinct: (col: ColName<TColEntries>) => SQLExpr<bigint>;
27
- distinct: <Col extends ColName<TColEntries>>(col: Col) => SQLDistinct<NonNullable<ColTypeOf<TColEntries, Col>>>;
27
+ distinct: <Col extends ColName<TColEntries>>(col: Col) => SQLDistinct<ColTypeOf<TColEntries, Col>>;
28
28
  length: (col: FilterCols<TColEntries, string> | SQLExpr<string>) => SQLExpr<bigint>;
29
- groupConcat: (col: ColName<TColEntries> | SQLExpr<string>, sep?: string) => SQLExpr<string>;
29
+ groupConcat: ((<T extends string | null>(col: SQLDistinct<T>, sep?: string) => SQLExpr<T>) & (<Col extends ColName<TColEntries>>(col: Col, sep?: string) => SQLExpr<null extends ColTypeOf<TColEntries, Col> ? string | null : string>) & (<T extends string | null>(col: SQLExpr<T> & {
30
+ readonly [DISTINCT_BRAND]?: never;
31
+ }, sep?: string) => SQLExpr<T>));
30
32
  bitAnd: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
31
33
  bitOr: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
32
34
  bitXor: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
@@ -146,12 +146,12 @@ var supportedJoinMethods = [
146
146
  var mysqlDialect = {
147
147
  name: "mysql",
148
148
  needsBooleanCoercion: () => true,
149
- quote: (id, _isAlias) => `\`${id}\``,
150
- quoteTableIdentifier: (name, _isAlias) => `\`${name}\``,
149
+ quote: (id, _isAlias) => `\`${id.replace(/`/g, "``")}\``,
150
+ quoteTableIdentifier: (name, _isAlias) => `\`${name.replace(/`/g, "``")}\``,
151
151
  quoteQualifiedColumn: (ref) => {
152
- if (!ref.includes(".")) return `\`${ref}\``;
152
+ if (!ref.includes(".")) return `\`${ref.replace(/`/g, "``")}\``;
153
153
  const [table, col] = ref.split(".", 2);
154
- return `\`${table}\`.\`${col}\``;
154
+ return `\`${table.replace(/`/g, "``")}\`.\`${col.replace(/`/g, "``")}\``;
155
155
  },
156
156
  quoteOrderByClause: (clause) => {
157
157
  const parts = clause.trim().split(/\s+/);
@@ -3,7 +3,7 @@ import { Decimal } from '@prisma/client/runtime/client';
3
3
  import { PgExtractField, PgDateTruncUnit } from './postgresql.js';
4
4
  export { postgresqlDialect } from './postgresql.js';
5
5
  import { J as JSONValue, a as JSONObject } from '../types-B0F8m0ok.js';
6
- import { S as SQLExpr, a as SQLDistinct } from '../sql-expr-BGSEwzCi.js';
6
+ import { S as SQLExpr, a as SQLDistinct, D as DISTINCT_BRAND } from '../sql-expr-BGSEwzCi.js';
7
7
  import { ColName, FilterCols, ColTypeOf, FilterJsonCols } from './shared.js';
8
8
  import './types.js';
9
9
 
@@ -13,11 +13,13 @@ declare const postgresqlV6ContextFns: <TColEntries extends [string, unknown] = n
13
13
  countDistinct: (col: ColName<TColEntries>) => SQLExpr<bigint>;
14
14
  ceil: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<number | Decimal>;
15
15
  floor: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<number | Decimal>;
16
- avg: (col: SQLExpr<number> | FilterCols<TColEntries, number>) => SQLExpr<number>;
17
- sum: (col: SQLExpr<number> | FilterCols<TColEntries, number>) => SQLExpr<number>;
18
- distinct: <Col extends ColName<TColEntries>>(col: Col) => SQLDistinct<NonNullable<ColTypeOf<TColEntries, Col>>>;
16
+ avg: (col: SQLExpr<number | null> | FilterCols<TColEntries, number>) => SQLExpr<number>;
17
+ sum: (col: SQLExpr<number | null> | FilterCols<TColEntries, number>) => SQLExpr<number>;
18
+ distinct: <Col extends ColName<TColEntries>>(col: Col) => SQLDistinct<ColTypeOf<TColEntries, Col>>;
19
19
  length: (col: SQLExpr<string> | FilterCols<TColEntries, string>) => SQLExpr<number>;
20
- stringAgg: (col: SQLExpr<string> | ColName<TColEntries>, sep: string) => SQLExpr<string>;
20
+ stringAgg: (<T extends string | null>(col: SQLDistinct<T>, sep: string) => SQLExpr<T>) & (<Col extends ColName<TColEntries>>(col: Col, sep: string) => SQLExpr<null extends ColTypeOf<TColEntries, Col> ? string | (ColTypeOf<TColEntries, Col> & null) : string>) & (<T extends string | null>(col: SQLExpr<T> & {
21
+ readonly [DISTINCT_BRAND]?: never;
22
+ }, sep: string) => SQLExpr<T>);
21
23
  arrayAgg: (col: SQLExpr<unknown> | ColName<TColEntries>) => SQLExpr<unknown[]>;
22
24
  stddevPop: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
23
25
  stddevSamp: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
@@ -99,4 +101,4 @@ declare const postgresqlV6ContextFns: <TColEntries extends [string, unknown] = n
99
101
  };
100
102
  type DialectFns<TColEntries extends [string, unknown] = never, _TCriteria extends object = object> = ReturnType<typeof postgresqlV6ContextFns<TColEntries>>;
101
103
 
102
- export { type DialectFns, PgDateTruncUnit, PgExtractField, postgresqlV6ContextFns };
104
+ export { DISTINCT_BRAND, type DialectFns, PgDateTruncUnit, PgExtractField, postgresqlV6ContextFns };
@@ -122,12 +122,12 @@ var postgresqlContextFns = (quoteFn) => ({
122
122
  var postgresqlDialect = {
123
123
  name: "postgresql",
124
124
  needsBooleanCoercion: () => false,
125
- quote: (id, _isAlias) => `"${id}"`,
126
- quoteTableIdentifier: (name, _isAlias) => `"${name}"`,
125
+ quote: (id, _isAlias) => `"${id.replace(/"/g, '""')}"`,
126
+ quoteTableIdentifier: (name, _isAlias) => `"${name.replace(/"/g, '""')}"`,
127
127
  quoteQualifiedColumn: (ref) => {
128
- if (!ref.includes(".")) return `"${ref}"`;
128
+ if (!ref.includes(".")) return `"${ref.replace(/"/g, '""')}"`;
129
129
  const [table, col] = ref.split(".", 2);
130
- return `"${table}"."${col}"`;
130
+ return `"${table.replace(/"/g, '""')}"."${col.replace(/"/g, '""')}"`;
131
131
  },
132
132
  quoteOrderByClause: (clause) => {
133
133
  const parts = clause.trim().split(/\s+/);
@@ -151,4 +151,4 @@ var postgresqlV6ContextFns = (quoteFn) => ({
151
151
  floor: (col) => sqlExpr(`FLOOR(${resolveArg(col, quoteFn)})`)
152
152
  });
153
153
 
154
- export { postgresqlDialect, postgresqlV6ContextFns };
154
+ export { DISTINCT_BRAND, postgresqlDialect, postgresqlV6ContextFns };
@@ -3,7 +3,7 @@ import { Decimal } from '@prisma/client/runtime/client';
3
3
  import { PgExtractField, PgDateTruncUnit } from './postgresql.js';
4
4
  export { postgresqlDialect } from './postgresql.js';
5
5
  import { J as JSONValue, a as JSONObject } from '../types-B0F8m0ok.js';
6
- import { S as SQLExpr, a as SQLDistinct } from '../sql-expr-BGSEwzCi.js';
6
+ import { S as SQLExpr, a as SQLDistinct, D as DISTINCT_BRAND } from '../sql-expr-BGSEwzCi.js';
7
7
  import { ColName, FilterCols, ColTypeOf, FilterJsonCols } from './shared.js';
8
8
  import './types.js';
9
9
 
@@ -13,11 +13,13 @@ declare const postgresqlV7ContextFns: <TColEntries extends [string, unknown] = n
13
13
  countDistinct: (col: ColName<TColEntries>) => SQLExpr<bigint>;
14
14
  ceil: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<number | Decimal>;
15
15
  floor: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<number | Decimal>;
16
- avg: (col: SQLExpr<number> | FilterCols<TColEntries, number>) => SQLExpr<number>;
17
- sum: (col: SQLExpr<number> | FilterCols<TColEntries, number>) => SQLExpr<number>;
18
- distinct: <Col extends ColName<TColEntries>>(col: Col) => SQLDistinct<NonNullable<ColTypeOf<TColEntries, Col>>>;
16
+ avg: (col: SQLExpr<number | null> | FilterCols<TColEntries, number>) => SQLExpr<number>;
17
+ sum: (col: SQLExpr<number | null> | FilterCols<TColEntries, number>) => SQLExpr<number>;
18
+ distinct: <Col extends ColName<TColEntries>>(col: Col) => SQLDistinct<ColTypeOf<TColEntries, Col>>;
19
19
  length: (col: SQLExpr<string> | FilterCols<TColEntries, string>) => SQLExpr<number>;
20
- stringAgg: (col: SQLExpr<string> | ColName<TColEntries>, sep: string) => SQLExpr<string>;
20
+ stringAgg: (<T extends string | null>(col: SQLDistinct<T>, sep: string) => SQLExpr<T>) & (<Col extends ColName<TColEntries>>(col: Col, sep: string) => SQLExpr<null extends ColTypeOf<TColEntries, Col> ? string | (ColTypeOf<TColEntries, Col> & null) : string>) & (<T extends string | null>(col: SQLExpr<T> & {
21
+ readonly [DISTINCT_BRAND]?: never;
22
+ }, sep: string) => SQLExpr<T>);
21
23
  arrayAgg: (col: SQLExpr<unknown> | ColName<TColEntries>) => SQLExpr<unknown[]>;
22
24
  stddevPop: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
23
25
  stddevSamp: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
@@ -99,4 +101,4 @@ declare const postgresqlV7ContextFns: <TColEntries extends [string, unknown] = n
99
101
  };
100
102
  type DialectFns<TColEntries extends [string, unknown] = never, _TCriteria extends object = object> = ReturnType<typeof postgresqlV7ContextFns<TColEntries>>;
101
103
 
102
- export { type DialectFns, PgDateTruncUnit, PgExtractField, postgresqlV7ContextFns };
104
+ export { DISTINCT_BRAND, type DialectFns, PgDateTruncUnit, PgExtractField, postgresqlV7ContextFns };
@@ -122,12 +122,12 @@ var postgresqlContextFns = (quoteFn) => ({
122
122
  var postgresqlDialect = {
123
123
  name: "postgresql",
124
124
  needsBooleanCoercion: () => false,
125
- quote: (id, _isAlias) => `"${id}"`,
126
- quoteTableIdentifier: (name, _isAlias) => `"${name}"`,
125
+ quote: (id, _isAlias) => `"${id.replace(/"/g, '""')}"`,
126
+ quoteTableIdentifier: (name, _isAlias) => `"${name.replace(/"/g, '""')}"`,
127
127
  quoteQualifiedColumn: (ref) => {
128
- if (!ref.includes(".")) return `"${ref}"`;
128
+ if (!ref.includes(".")) return `"${ref.replace(/"/g, '""')}"`;
129
129
  const [table, col] = ref.split(".", 2);
130
- return `"${table}"."${col}"`;
130
+ return `"${table.replace(/"/g, '""')}"."${col.replace(/"/g, '""')}"`;
131
131
  },
132
132
  quoteOrderByClause: (clause) => {
133
133
  const parts = clause.trim().split(/\s+/);
@@ -151,4 +151,4 @@ var postgresqlV7ContextFns = (quoteFn) => ({
151
151
  floor: (col) => sqlExpr(`FLOOR(${resolveArg(col, quoteFn)})`)
152
152
  });
153
153
 
154
- export { postgresqlDialect, postgresqlV7ContextFns };
154
+ export { DISTINCT_BRAND, postgresqlDialect, postgresqlV7ContextFns };
@@ -1,5 +1,5 @@
1
1
  import { Dialect } from './types.js';
2
- import { S as SQLExpr, a as SQLDistinct } from '../sql-expr-BGSEwzCi.js';
2
+ import { S as SQLExpr, a as SQLDistinct, D as DISTINCT_BRAND } from '../sql-expr-BGSEwzCi.js';
3
3
  import { J as JSONValue, a as JSONObject } from '../types-B0F8m0ok.js';
4
4
  import { FilterCols, ColName, ColTypeOf, FilterJsonCols } from './shared.js';
5
5
  import '@prisma/client/runtime/client';
@@ -19,14 +19,16 @@ type PgCastTypeMap = {
19
19
  type PgExtractField = 'YEAR' | 'MONTH' | 'DAY' | 'HOUR' | 'MINUTE' | 'SECOND' | 'DOW' | 'DOY' | 'EPOCH' | 'WEEK' | 'QUARTER';
20
20
  type PgDateTruncUnit = 'microseconds' | 'milliseconds' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' | 'decade' | 'century' | 'millennium';
21
21
  declare const postgresqlContextFns: <TColEntries extends [string, unknown] = never>(quoteFn: (ref: string) => string) => {
22
- avg: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<number>;
23
- sum: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<number>;
22
+ avg: (col: FilterCols<TColEntries, number> | SQLExpr<number | null>) => SQLExpr<number>;
23
+ sum: (col: FilterCols<TColEntries, number> | SQLExpr<number | null>) => SQLExpr<number>;
24
24
  countAll: () => SQLExpr<number>;
25
25
  count: (col: ColName<TColEntries> | "*" | SQLExpr<unknown>) => SQLExpr<number>;
26
26
  countDistinct: (col: ColName<TColEntries>) => SQLExpr<number>;
27
- distinct: <Col extends ColName<TColEntries>>(col: Col) => SQLDistinct<NonNullable<ColTypeOf<TColEntries, Col>>>;
27
+ distinct: <Col extends ColName<TColEntries>>(col: Col) => SQLDistinct<ColTypeOf<TColEntries, Col>>;
28
28
  length: (col: FilterCols<TColEntries, string> | SQLExpr<string>) => SQLExpr<number>;
29
- stringAgg: (col: ColName<TColEntries> | SQLExpr<string>, sep: string) => SQLExpr<string>;
29
+ stringAgg: ((<T extends string | null>(col: SQLDistinct<T>, sep: string) => SQLExpr<T>) & (<Col extends ColName<TColEntries>>(col: Col, sep: string) => SQLExpr<null extends ColTypeOf<TColEntries, Col> ? string | null : string>) & (<T extends string | null>(col: SQLExpr<T> & {
30
+ readonly [DISTINCT_BRAND]?: never;
31
+ }, sep: string) => SQLExpr<T>));
30
32
  arrayAgg: (col: ColName<TColEntries> | SQLExpr<unknown>) => SQLExpr<unknown[]>;
31
33
  stddevPop: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
32
34
  stddevSamp: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
@@ -143,12 +143,12 @@ var supportedJoinMethods = [
143
143
  var postgresqlDialect = {
144
144
  name: "postgresql",
145
145
  needsBooleanCoercion: () => false,
146
- quote: (id, _isAlias) => `"${id}"`,
147
- quoteTableIdentifier: (name, _isAlias) => `"${name}"`,
146
+ quote: (id, _isAlias) => `"${id.replace(/"/g, '""')}"`,
147
+ quoteTableIdentifier: (name, _isAlias) => `"${name.replace(/"/g, '""')}"`,
148
148
  quoteQualifiedColumn: (ref) => {
149
- if (!ref.includes(".")) return `"${ref}"`;
149
+ if (!ref.includes(".")) return `"${ref.replace(/"/g, '""')}"`;
150
150
  const [table, col] = ref.split(".", 2);
151
- return `"${table}"."${col}"`;
151
+ return `"${table.replace(/"/g, '""')}"."${col.replace(/"/g, '""')}"`;
152
152
  },
153
153
  quoteOrderByClause: (clause) => {
154
154
  const parts = clause.trim().split(/\s+/);
@@ -13,16 +13,16 @@ type SqliteCastTypeMap = {
13
13
  BLOB: Buffer;
14
14
  };
15
15
  declare const sqliteContextFns: <TColEntries extends [string, unknown] = never, TCriteria extends object = object>(quoteFn: (ref: string) => string, condFn: (criteria: TCriteria) => string) => {
16
- avg: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<number>;
17
- sum: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<bigint | number>;
16
+ avg: (col: FilterCols<TColEntries, number> | SQLExpr<number | null>) => SQLExpr<number>;
17
+ sum: (col: FilterCols<TColEntries, number> | SQLExpr<number | null>) => SQLExpr<bigint | number>;
18
18
  countAll: () => SQLExpr<bigint>;
19
19
  count: (col: ColName<TColEntries> | "*" | SQLExpr<unknown>) => SQLExpr<bigint>;
20
20
  countDistinct: (col: ColName<TColEntries>) => SQLExpr<bigint>;
21
- distinct: <Col extends ColName<TColEntries>>(col: Col) => SQLDistinct<NonNullable<ColTypeOf<TColEntries, Col>>>;
21
+ distinct: <Col extends ColName<TColEntries>>(col: Col) => SQLDistinct<ColTypeOf<TColEntries, Col>>;
22
22
  length: (col: FilterCols<TColEntries, string> | SQLExpr<string>) => SQLExpr<bigint>;
23
- groupConcat: (((col: SQLDistinct<string>) => SQLExpr<string>) & ((col: ColName<TColEntries> | (SQLExpr<string> & {
23
+ groupConcat: ((<T extends string | null>(col: SQLDistinct<T>) => SQLExpr<T>) & (<Col extends ColName<TColEntries>>(col: Col, sep?: string) => SQLExpr<null extends ColTypeOf<TColEntries, Col> ? string | null : string>) & (<T extends string | null>(col: SQLExpr<T> & {
24
24
  readonly [DISTINCT_BRAND]?: never;
25
- }), sep?: string) => SQLExpr<string>));
25
+ }, sep?: string) => SQLExpr<T>));
26
26
  total: (col: ColName<TColEntries>) => SQLExpr<number>;
27
27
  min: <Col extends ColName<TColEntries>>(col: Col) => SQLExpr<SqliteMinMaxResult<TColEntries, Col>>;
28
28
  max: <Col extends ColName<TColEntries>>(col: Col) => SQLExpr<SqliteMinMaxResult<TColEntries, Col>>;
@@ -45,7 +45,7 @@ var sqliteContextFns = (quoteFn, condFn) => ({
45
45
  if (isDistinct(col) && sep !== void 0) {
46
46
  throw new Error("SQLite does not support GROUP_CONCAT(DISTINCT col, sep) \u2014 omit the separator.");
47
47
  }
48
- return sqlExpr(`GROUP_CONCAT(${inner}${sep !== void 0 ? `, '${sep.replace(/'/g, "''")}'` : ""})`);
48
+ return sqlExpr(`GROUP_CONCAT(${inner}${sep !== void 0 ? `, '${esc(sep)}'` : ""})`);
49
49
  },
50
50
  total: (col) => sqlExpr(`TOTAL(${quoteFn(col)})`),
51
51
  // SQLite MIN/MAX return bigint for integer columns — override base (number) return types
@@ -135,11 +135,11 @@ var sqliteDialect = {
135
135
  name: "sqlite",
136
136
  needsBooleanCoercion: () => true,
137
137
  quote: (name, _isAlias) => {
138
- if (_isAlias) return "`" + name + "`";
138
+ if (_isAlias) return "`" + name.replace(/`/g, "``") + "`";
139
139
  return name;
140
140
  },
141
141
  quoteTableIdentifier: (name, _isAlias) => {
142
- if (_isAlias) return "`" + name + "`";
142
+ if (_isAlias) return "`" + name.replace(/`/g, "``") + "`";
143
143
  return name;
144
144
  },
145
145
  quoteQualifiedColumn: (ref) => {