prisma-ts-select 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -0
- package/assets/groupBy.gif +0 -0
- package/assets/joinUnsafeIgnoreType.gif +0 -0
- package/assets/joinUnsafeTypeEnforced.gif +0 -0
- package/assets/typesafe-join.gif +0 -0
- package/assets/typesafe-join.png +0 -0
- package/assets/whereIsNull.gif +0 -0
- package/assets/whereNotNull.gif +0 -0
- package/dist/bin.cjs +1 -1
- package/dist/bin.js +1 -1
- package/dist/{chunk-54D2J5AR.cjs → chunk-GSIFF2TF.cjs} +19 -0
- package/dist/{chunk-47KZVQLD.js → chunk-NFKUA5XM.js} +19 -0
- package/dist/extend/dialects/index.d.ts +1 -1
- package/dist/extend/dialects/index.js +18 -2
- package/dist/extend/dialects/mysql-v6.d.ts +5 -4
- package/dist/extend/dialects/mysql-v6.js +10 -3
- package/dist/extend/dialects/mysql-v7.d.ts +1 -1
- package/dist/extend/dialects/mysql-v7.js +9 -2
- package/dist/extend/dialects/mysql.d.ts +5 -4
- package/dist/extend/dialects/mysql.js +9 -2
- package/dist/extend/dialects/postgresql-v6.d.ts +6 -5
- package/dist/extend/dialects/postgresql-v6.js +11 -4
- package/dist/extend/dialects/postgresql-v7.d.ts +6 -5
- package/dist/extend/dialects/postgresql-v7.js +11 -4
- package/dist/extend/dialects/postgresql.d.ts +6 -5
- package/dist/extend/dialects/postgresql.js +10 -3
- package/dist/extend/dialects/shared.d.ts +3 -2
- package/dist/extend/dialects/sqlite.d.ts +7 -4
- package/dist/extend/dialects/sqlite.js +18 -2
- package/dist/extend/extend.d.ts +1 -1
- package/dist/extend/{sql-expr-BaKWzJ-r.d.ts → sql-expr-BGSEwzCi.d.ts} +5 -1
- package/dist/generator.cjs +1 -1
- package/dist/generator.js +1 -1
- package/package.json +26 -26
- package/LICENSE +0 -21
package/README.md
CHANGED
|
File without changes
|
package/assets/groupBy.gif
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/assets/typesafe-join.gif
CHANGED
|
File without changes
|
package/assets/typesafe-join.png
CHANGED
|
File without changes
|
package/assets/whereIsNull.gif
CHANGED
|
File without changes
|
package/assets/whereNotNull.gif
CHANGED
|
File without changes
|
package/dist/bin.cjs
CHANGED
package/dist/bin.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import './chunk-
|
|
2
|
+
import './chunk-NFKUA5XM.js';
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var generatorHelper = require('@prisma/generator-helper');
|
|
4
4
|
var internals = require('@prisma/internals');
|
|
5
5
|
var path2 = require('path');
|
|
6
|
+
var crypto = require('crypto');
|
|
6
7
|
var fs2 = require('fs');
|
|
7
8
|
var module$1 = require('module');
|
|
8
9
|
|
|
@@ -46,6 +47,7 @@ generatorHelper.generatorHandler({
|
|
|
46
47
|
const output = options.generator.output?.value;
|
|
47
48
|
if (!output) throw new Error(`${GENERATOR_NAME}: No output directory found. Please add an output directory to your schema.prisma file.`);
|
|
48
49
|
const outputPath = path2__default.default.resolve(output);
|
|
50
|
+
const packageName = options.generator.config.packageName ?? generatePackageName(outputPath);
|
|
49
51
|
fs2__default.default.mkdirSync(outputPath, { recursive: true });
|
|
50
52
|
console.log(`${GENERATOR_NAME}: Generating to ${outputPath}`);
|
|
51
53
|
const validDS = options.datasources.map((ds) => ds.provider).filter((type) => SupportedProviders[type]);
|
|
@@ -236,6 +238,20 @@ export { default } from './extend.js';
|
|
|
236
238
|
` + replacedExtendDts;
|
|
237
239
|
writeFileSafely(path2__default.default.join(outputPath, `extend-${ver}.d.ts`), vDts);
|
|
238
240
|
}
|
|
241
|
+
const pkg = {
|
|
242
|
+
name: packageName,
|
|
243
|
+
version: "0.0.0",
|
|
244
|
+
type: "module",
|
|
245
|
+
exports: {
|
|
246
|
+
".": { types: "./extend.d.ts", import: "./extend.js" },
|
|
247
|
+
"./extend-v6": { types: "./extend-v6.d.ts", import: "./extend-v6.js" },
|
|
248
|
+
"./extend-v7": { types: "./extend-v7.d.ts", import: "./extend-v7.js" },
|
|
249
|
+
"./dialects": { types: "./dialects/index.d.ts", import: "./dialects/index.js" },
|
|
250
|
+
"./dialects/*": { types: "./dialects/*.d.ts", import: "./dialects/*.js" }
|
|
251
|
+
},
|
|
252
|
+
sideEffects: false
|
|
253
|
+
};
|
|
254
|
+
await writeFileSafely(path2__default.default.join(outputPath, "package.json"), JSON.stringify(pkg, null, 2));
|
|
239
255
|
for (const file of fs2__default.default.readdirSync(srcDir)) {
|
|
240
256
|
if (file !== "extend.d.ts" && file !== "extend.js" && file.endsWith(".d.ts")) {
|
|
241
257
|
fs2__default.default.copyFileSync(path2__default.default.join(srcDir, file), path2__default.default.join(outputPath, file));
|
|
@@ -267,6 +283,9 @@ export { default } from './extend.js';
|
|
|
267
283
|
}
|
|
268
284
|
}
|
|
269
285
|
});
|
|
286
|
+
function generatePackageName(outputPath) {
|
|
287
|
+
return "prisma-ts-select-" + crypto.createHash("sha256").update(outputPath).digest("hex").slice(0, 8);
|
|
288
|
+
}
|
|
270
289
|
function generateReadonlyDeclaration(db) {
|
|
271
290
|
const traverse = (obj, level = 0) => {
|
|
272
291
|
const indent = " ".repeat(level);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { generatorHandler } from '@prisma/generator-helper';
|
|
2
2
|
import { logger } from '@prisma/internals';
|
|
3
3
|
import path2 from 'node:path';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
4
5
|
import fs2 from 'node:fs';
|
|
5
6
|
import { createRequire } from 'node:module';
|
|
6
7
|
|
|
@@ -38,6 +39,7 @@ generatorHandler({
|
|
|
38
39
|
const output = options.generator.output?.value;
|
|
39
40
|
if (!output) throw new Error(`${GENERATOR_NAME}: No output directory found. Please add an output directory to your schema.prisma file.`);
|
|
40
41
|
const outputPath = path2.resolve(output);
|
|
42
|
+
const packageName = options.generator.config.packageName ?? generatePackageName(outputPath);
|
|
41
43
|
fs2.mkdirSync(outputPath, { recursive: true });
|
|
42
44
|
console.log(`${GENERATOR_NAME}: Generating to ${outputPath}`);
|
|
43
45
|
const validDS = options.datasources.map((ds) => ds.provider).filter((type) => SupportedProviders[type]);
|
|
@@ -228,6 +230,20 @@ export { default } from './extend.js';
|
|
|
228
230
|
` + replacedExtendDts;
|
|
229
231
|
writeFileSafely(path2.join(outputPath, `extend-${ver}.d.ts`), vDts);
|
|
230
232
|
}
|
|
233
|
+
const pkg = {
|
|
234
|
+
name: packageName,
|
|
235
|
+
version: "0.0.0",
|
|
236
|
+
type: "module",
|
|
237
|
+
exports: {
|
|
238
|
+
".": { types: "./extend.d.ts", import: "./extend.js" },
|
|
239
|
+
"./extend-v6": { types: "./extend-v6.d.ts", import: "./extend-v6.js" },
|
|
240
|
+
"./extend-v7": { types: "./extend-v7.d.ts", import: "./extend-v7.js" },
|
|
241
|
+
"./dialects": { types: "./dialects/index.d.ts", import: "./dialects/index.js" },
|
|
242
|
+
"./dialects/*": { types: "./dialects/*.d.ts", import: "./dialects/*.js" }
|
|
243
|
+
},
|
|
244
|
+
sideEffects: false
|
|
245
|
+
};
|
|
246
|
+
await writeFileSafely(path2.join(outputPath, "package.json"), JSON.stringify(pkg, null, 2));
|
|
231
247
|
for (const file of fs2.readdirSync(srcDir)) {
|
|
232
248
|
if (file !== "extend.d.ts" && file !== "extend.js" && file.endsWith(".d.ts")) {
|
|
233
249
|
fs2.copyFileSync(path2.join(srcDir, file), path2.join(outputPath, file));
|
|
@@ -259,6 +275,9 @@ export { default } from './extend.js';
|
|
|
259
275
|
}
|
|
260
276
|
}
|
|
261
277
|
});
|
|
278
|
+
function generatePackageName(outputPath) {
|
|
279
|
+
return "prisma-ts-select-" + createHash("sha256").update(outputPath).digest("hex").slice(0, 8);
|
|
280
|
+
}
|
|
262
281
|
function generateReadonlyDeclaration(db) {
|
|
263
282
|
const traverse = (obj, level = 0) => {
|
|
264
283
|
const indent = " ".repeat(level);
|
|
@@ -3,7 +3,7 @@ export { FunctionRegistry, SUPPORTED_PROVIDERS } from './types.js';
|
|
|
3
3
|
export { sqliteDialect as dialect, sqliteContextFns as dialectContextFns, sqliteDialect } from './sqlite.js';
|
|
4
4
|
export { mysqlDialect } from './mysql.js';
|
|
5
5
|
export { postgresqlDialect } from './postgresql.js';
|
|
6
|
-
import '../sql-expr-
|
|
6
|
+
import '../sql-expr-BGSEwzCi.js';
|
|
7
7
|
import '../types-B0F8m0ok.js';
|
|
8
8
|
import '@prisma/client/runtime/client';
|
|
9
9
|
import './shared.js';
|
|
@@ -7,6 +7,15 @@ function sqlExpr(sql) {
|
|
|
7
7
|
return sql;
|
|
8
8
|
} };
|
|
9
9
|
}
|
|
10
|
+
var DISTINCT_BRAND = Symbol("sqlDistinct");
|
|
11
|
+
function sqlDistinct(sql) {
|
|
12
|
+
return { sql, [DISTINCT_BRAND]: true, toString() {
|
|
13
|
+
return sql;
|
|
14
|
+
} };
|
|
15
|
+
}
|
|
16
|
+
function isDistinct(val) {
|
|
17
|
+
return typeof val === "object" && val !== null && DISTINCT_BRAND in val;
|
|
18
|
+
}
|
|
10
19
|
function resolveArg(arg, quoteFn) {
|
|
11
20
|
if (typeof arg !== "string") return arg.sql;
|
|
12
21
|
return quoteFn(arg);
|
|
@@ -29,11 +38,18 @@ var sqliteContextFns = (quoteFn, condFn) => ({
|
|
|
29
38
|
sum: (col) => sqlExpr(`SUM(${resolveArg(col, quoteFn)})`),
|
|
30
39
|
// Aggregate integer-result fns — SQLite returns INTEGER → bigint
|
|
31
40
|
countAll: () => sqlExpr("COUNT(*)"),
|
|
32
|
-
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${
|
|
41
|
+
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${resolveArg(col, quoteFn)})`),
|
|
33
42
|
countDistinct: (col) => sqlExpr(`COUNT(DISTINCT ${quoteFn(col)})`),
|
|
43
|
+
distinct: (col) => sqlDistinct(`DISTINCT ${quoteFn(col)}`),
|
|
34
44
|
// LENGTH returns INTEGER → bigint in SQLite
|
|
35
45
|
length: (col) => sqlExpr(`LENGTH(${resolveArg(col, quoteFn)})`),
|
|
36
|
-
groupConcat: (col, sep) =>
|
|
46
|
+
groupConcat: (col, sep) => {
|
|
47
|
+
const inner = resolveArg(col, quoteFn);
|
|
48
|
+
if (isDistinct(col) && sep !== void 0) {
|
|
49
|
+
throw new Error("SQLite does not support GROUP_CONCAT(DISTINCT col, sep) \u2014 omit the separator.");
|
|
50
|
+
}
|
|
51
|
+
return sqlExpr(`GROUP_CONCAT(${inner}${sep !== void 0 ? `, '${sep.replace(/'/g, "''")}'` : ""})`);
|
|
52
|
+
},
|
|
37
53
|
total: (col) => sqlExpr(`TOTAL(${quoteFn(col)})`),
|
|
38
54
|
// SQLite MIN/MAX return bigint for integer columns — override base (number) return types
|
|
39
55
|
min: (col) => sqlExpr(`MIN(${quoteFn(col)})`),
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ColName, FilterCols, FilterJsonCols } from './shared.js';
|
|
2
1
|
import { IntervalUnit } from './mysql.js';
|
|
3
2
|
export { mysqlDialect } from './mysql.js';
|
|
4
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';
|
|
5
|
+
import { ColName, FilterCols, ColTypeOf, FilterJsonCols } from './shared.js';
|
|
5
6
|
import * as _prisma_client_runtime_client from '@prisma/client/runtime/client';
|
|
6
|
-
import { S as SQLExpr } from '../sql-expr-BaKWzJ-r.js';
|
|
7
7
|
import './types.js';
|
|
8
8
|
|
|
9
9
|
declare const mysqlV6ContextFns: <TColEntries extends [string, unknown] = never, TCriteria extends object = object>(quoteFn: (ref: string) => string, condFn: (criteria: TCriteria) => string) => {
|
|
10
10
|
countAll: () => SQLExpr<bigint>;
|
|
11
|
-
count: (col: ColName<TColEntries> | "*") => SQLExpr<bigint>;
|
|
11
|
+
count: (col: ColName<TColEntries> | "*" | SQLExpr<unknown>) => SQLExpr<bigint>;
|
|
12
12
|
countDistinct: (col: ColName<TColEntries>) => SQLExpr<bigint>;
|
|
13
13
|
length: (col: FilterCols<TColEntries, string> | SQLExpr<string>) => SQLExpr<bigint>;
|
|
14
14
|
abs: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<bigint | number>;
|
|
@@ -18,7 +18,8 @@ declare const mysqlV6ContextFns: <TColEntries extends [string, unknown] = never,
|
|
|
18
18
|
sign: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<bigint | number>;
|
|
19
19
|
avg: (col: SQLExpr<number> | FilterCols<TColEntries, number>) => SQLExpr<_prisma_client_runtime_client.Decimal>;
|
|
20
20
|
sum: (col: SQLExpr<number> | FilterCols<TColEntries, number>) => SQLExpr<_prisma_client_runtime_client.Decimal>;
|
|
21
|
-
|
|
21
|
+
distinct: <Col extends ColName<TColEntries>>(col: Col) => SQLDistinct<NonNullable<ColTypeOf<TColEntries, Col>>>;
|
|
22
|
+
groupConcat: (col: SQLExpr<string> | ColName<TColEntries>, sep?: string) => SQLExpr<string>;
|
|
22
23
|
bitAnd: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
23
24
|
bitOr: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
24
25
|
bitXor: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
@@ -4,6 +4,12 @@ function sqlExpr(sql) {
|
|
|
4
4
|
return sql;
|
|
5
5
|
} };
|
|
6
6
|
}
|
|
7
|
+
var DISTINCT_BRAND = Symbol("sqlDistinct");
|
|
8
|
+
function sqlDistinct(sql) {
|
|
9
|
+
return { sql, [DISTINCT_BRAND]: true, toString() {
|
|
10
|
+
return sql;
|
|
11
|
+
} };
|
|
12
|
+
}
|
|
7
13
|
function resolveArg(arg, quoteFn) {
|
|
8
14
|
if (typeof arg !== "string") return arg.sql;
|
|
9
15
|
return quoteFn(arg);
|
|
@@ -19,10 +25,11 @@ var mysqlContextFns = (quoteFn, condFn) => ({
|
|
|
19
25
|
avg: (col) => sqlExpr(`AVG(${resolveArg(col, quoteFn)})`),
|
|
20
26
|
sum: (col) => sqlExpr(`SUM(${resolveArg(col, quoteFn)})`),
|
|
21
27
|
countAll: () => sqlExpr("COUNT(*)"),
|
|
22
|
-
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${
|
|
28
|
+
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${resolveArg(col, quoteFn)})`),
|
|
23
29
|
countDistinct: (col) => sqlExpr(`COUNT(DISTINCT ${quoteFn(col)})`),
|
|
30
|
+
distinct: (col) => sqlDistinct(`DISTINCT ${quoteFn(col)}`),
|
|
24
31
|
length: (col) => sqlExpr(`LENGTH(${resolveArg(col, quoteFn)})`),
|
|
25
|
-
groupConcat: (col, sep) => sqlExpr(`GROUP_CONCAT(${
|
|
32
|
+
groupConcat: (col, sep) => sqlExpr(`GROUP_CONCAT(${resolveArg(col, quoteFn)}${sep !== void 0 ? ` SEPARATOR '${esc(sep)}'` : ""})`),
|
|
26
33
|
bitAnd: (col) => sqlExpr(`BIT_AND(${quoteFn(col)})`),
|
|
27
34
|
bitOr: (col) => sqlExpr(`BIT_OR(${quoteFn(col)})`),
|
|
28
35
|
bitXor: (col) => sqlExpr(`BIT_XOR(${quoteFn(col)})`),
|
|
@@ -144,7 +151,7 @@ var mysqlDialect = {
|
|
|
144
151
|
var mysqlV6ContextFns = (quoteFn, condFn) => ({
|
|
145
152
|
...mysqlContextFns(quoteFn, condFn),
|
|
146
153
|
countAll: () => sqlExpr("COUNT(*)"),
|
|
147
|
-
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${
|
|
154
|
+
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${resolveArg(col, quoteFn)})`),
|
|
148
155
|
countDistinct: (col) => sqlExpr(`COUNT(DISTINCT ${quoteFn(col)})`),
|
|
149
156
|
length: (col) => sqlExpr(`LENGTH(${resolveArg(col, quoteFn)})`),
|
|
150
157
|
abs: (col) => sqlExpr(`ABS(${resolveArg(col, quoteFn)})`),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { DialectFns, IntervalUnit, mysqlDialect, mysqlContextFns as mysqlV7ContextFns } from './mysql.js';
|
|
2
2
|
import './types.js';
|
|
3
|
-
import '../sql-expr-
|
|
3
|
+
import '../sql-expr-BGSEwzCi.js';
|
|
4
4
|
import '../types-B0F8m0ok.js';
|
|
5
5
|
import '@prisma/client/runtime/client';
|
|
6
6
|
import './shared.js';
|
|
@@ -4,6 +4,12 @@ function sqlExpr(sql) {
|
|
|
4
4
|
return sql;
|
|
5
5
|
} };
|
|
6
6
|
}
|
|
7
|
+
var DISTINCT_BRAND = Symbol("sqlDistinct");
|
|
8
|
+
function sqlDistinct(sql) {
|
|
9
|
+
return { sql, [DISTINCT_BRAND]: true, toString() {
|
|
10
|
+
return sql;
|
|
11
|
+
} };
|
|
12
|
+
}
|
|
7
13
|
function resolveArg(arg, quoteFn) {
|
|
8
14
|
if (typeof arg !== "string") return arg.sql;
|
|
9
15
|
return quoteFn(arg);
|
|
@@ -19,10 +25,11 @@ var mysqlContextFns = (quoteFn, condFn) => ({
|
|
|
19
25
|
avg: (col) => sqlExpr(`AVG(${resolveArg(col, quoteFn)})`),
|
|
20
26
|
sum: (col) => sqlExpr(`SUM(${resolveArg(col, quoteFn)})`),
|
|
21
27
|
countAll: () => sqlExpr("COUNT(*)"),
|
|
22
|
-
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${
|
|
28
|
+
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${resolveArg(col, quoteFn)})`),
|
|
23
29
|
countDistinct: (col) => sqlExpr(`COUNT(DISTINCT ${quoteFn(col)})`),
|
|
30
|
+
distinct: (col) => sqlDistinct(`DISTINCT ${quoteFn(col)}`),
|
|
24
31
|
length: (col) => sqlExpr(`LENGTH(${resolveArg(col, quoteFn)})`),
|
|
25
|
-
groupConcat: (col, sep) => sqlExpr(`GROUP_CONCAT(${
|
|
32
|
+
groupConcat: (col, sep) => sqlExpr(`GROUP_CONCAT(${resolveArg(col, quoteFn)}${sep !== void 0 ? ` SEPARATOR '${esc(sep)}'` : ""})`),
|
|
26
33
|
bitAnd: (col) => sqlExpr(`BIT_AND(${quoteFn(col)})`),
|
|
27
34
|
bitOr: (col) => sqlExpr(`BIT_OR(${quoteFn(col)})`),
|
|
28
35
|
bitXor: (col) => sqlExpr(`BIT_XOR(${quoteFn(col)})`),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Dialect } from './types.js';
|
|
2
|
-
import { S as SQLExpr } from '../sql-expr-
|
|
2
|
+
import { S as SQLExpr, a as SQLDistinct } 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
|
-
import { FilterCols, ColName, FilterJsonCols } from './shared.js';
|
|
5
|
+
import { FilterCols, ColName, ColTypeOf, FilterJsonCols } from './shared.js';
|
|
6
6
|
|
|
7
7
|
type MySQLCastTypeMap = {
|
|
8
8
|
SIGNED: bigint;
|
|
@@ -22,10 +22,11 @@ declare const mysqlContextFns: <TColEntries extends [string, unknown] = never, T
|
|
|
22
22
|
avg: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<Decimal>;
|
|
23
23
|
sum: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<Decimal>;
|
|
24
24
|
countAll: () => SQLExpr<bigint>;
|
|
25
|
-
count: (col: ColName<TColEntries> | "*") => SQLExpr<bigint>;
|
|
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
28
|
length: (col: FilterCols<TColEntries, string> | SQLExpr<string>) => SQLExpr<bigint>;
|
|
28
|
-
groupConcat: (col: ColName<TColEntries>, sep?: string) => SQLExpr<string>;
|
|
29
|
+
groupConcat: (col: ColName<TColEntries> | SQLExpr<string>, sep?: string) => SQLExpr<string>;
|
|
29
30
|
bitAnd: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
30
31
|
bitOr: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
31
32
|
bitXor: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
@@ -4,6 +4,12 @@ function sqlExpr(sql) {
|
|
|
4
4
|
return sql;
|
|
5
5
|
} };
|
|
6
6
|
}
|
|
7
|
+
var DISTINCT_BRAND = Symbol("sqlDistinct");
|
|
8
|
+
function sqlDistinct(sql) {
|
|
9
|
+
return { sql, [DISTINCT_BRAND]: true, toString() {
|
|
10
|
+
return sql;
|
|
11
|
+
} };
|
|
12
|
+
}
|
|
7
13
|
function resolveArg(arg, quoteFn) {
|
|
8
14
|
if (typeof arg !== "string") return arg.sql;
|
|
9
15
|
return quoteFn(arg);
|
|
@@ -19,10 +25,11 @@ var mysqlContextFns = (quoteFn, condFn) => ({
|
|
|
19
25
|
avg: (col) => sqlExpr(`AVG(${resolveArg(col, quoteFn)})`),
|
|
20
26
|
sum: (col) => sqlExpr(`SUM(${resolveArg(col, quoteFn)})`),
|
|
21
27
|
countAll: () => sqlExpr("COUNT(*)"),
|
|
22
|
-
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${
|
|
28
|
+
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${resolveArg(col, quoteFn)})`),
|
|
23
29
|
countDistinct: (col) => sqlExpr(`COUNT(DISTINCT ${quoteFn(col)})`),
|
|
30
|
+
distinct: (col) => sqlDistinct(`DISTINCT ${quoteFn(col)}`),
|
|
24
31
|
length: (col) => sqlExpr(`LENGTH(${resolveArg(col, quoteFn)})`),
|
|
25
|
-
groupConcat: (col, sep) => sqlExpr(`GROUP_CONCAT(${
|
|
32
|
+
groupConcat: (col, sep) => sqlExpr(`GROUP_CONCAT(${resolveArg(col, quoteFn)}${sep !== void 0 ? ` SEPARATOR '${esc(sep)}'` : ""})`),
|
|
26
33
|
bitAnd: (col) => sqlExpr(`BIT_AND(${quoteFn(col)})`),
|
|
27
34
|
bitOr: (col) => sqlExpr(`BIT_OR(${quoteFn(col)})`),
|
|
28
35
|
bitXor: (col) => sqlExpr(`BIT_XOR(${quoteFn(col)})`),
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import { ColName, FilterCols, FilterJsonCols } from './shared.js';
|
|
2
1
|
import * as _prisma_client_runtime_client from '@prisma/client/runtime/client';
|
|
3
2
|
import { Decimal } from '@prisma/client/runtime/client';
|
|
4
3
|
import { PgExtractField, PgDateTruncUnit } from './postgresql.js';
|
|
5
4
|
export { postgresqlDialect } from './postgresql.js';
|
|
6
5
|
import { J as JSONValue, a as JSONObject } from '../types-B0F8m0ok.js';
|
|
7
|
-
import { S as SQLExpr } from '../sql-expr-
|
|
6
|
+
import { S as SQLExpr, a as SQLDistinct } from '../sql-expr-BGSEwzCi.js';
|
|
7
|
+
import { ColName, FilterCols, ColTypeOf, FilterJsonCols } from './shared.js';
|
|
8
8
|
import './types.js';
|
|
9
9
|
|
|
10
10
|
declare const postgresqlV6ContextFns: <TColEntries extends [string, unknown] = never>(quoteFn: (ref: string) => string) => {
|
|
11
11
|
countAll: () => SQLExpr<bigint>;
|
|
12
|
-
count: (col: ColName<TColEntries> | "*") => SQLExpr<bigint>;
|
|
12
|
+
count: (col: ColName<TColEntries> | "*" | SQLExpr<unknown>) => SQLExpr<bigint>;
|
|
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
16
|
avg: (col: SQLExpr<number> | FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
17
17
|
sum: (col: SQLExpr<number> | FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
18
|
+
distinct: <Col extends ColName<TColEntries>>(col: Col) => SQLDistinct<NonNullable<ColTypeOf<TColEntries, Col>>>;
|
|
18
19
|
length: (col: SQLExpr<string> | FilterCols<TColEntries, string>) => SQLExpr<number>;
|
|
19
|
-
stringAgg: (col: ColName<TColEntries>, sep: string) => SQLExpr<string>;
|
|
20
|
-
arrayAgg: (col: ColName<TColEntries>) => SQLExpr<unknown[]>;
|
|
20
|
+
stringAgg: (col: SQLExpr<string> | ColName<TColEntries>, sep: string) => SQLExpr<string>;
|
|
21
|
+
arrayAgg: (col: SQLExpr<unknown> | ColName<TColEntries>) => SQLExpr<unknown[]>;
|
|
21
22
|
stddevPop: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
22
23
|
stddevSamp: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
23
24
|
varPop: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
@@ -4,6 +4,12 @@ function sqlExpr(sql) {
|
|
|
4
4
|
return sql;
|
|
5
5
|
} };
|
|
6
6
|
}
|
|
7
|
+
var DISTINCT_BRAND = Symbol("sqlDistinct");
|
|
8
|
+
function sqlDistinct(sql) {
|
|
9
|
+
return { sql, [DISTINCT_BRAND]: true, toString() {
|
|
10
|
+
return sql;
|
|
11
|
+
} };
|
|
12
|
+
}
|
|
7
13
|
function resolveArg(arg, quoteFn) {
|
|
8
14
|
if (typeof arg !== "string") return arg.sql;
|
|
9
15
|
return quoteFn(arg);
|
|
@@ -19,11 +25,12 @@ var postgresqlContextFns = (quoteFn) => ({
|
|
|
19
25
|
avg: (col) => sqlExpr(`AVG(${resolveArg(col, quoteFn)})`),
|
|
20
26
|
sum: (col) => sqlExpr(`SUM(${resolveArg(col, quoteFn)})`),
|
|
21
27
|
countAll: () => sqlExpr("COUNT(*)"),
|
|
22
|
-
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${
|
|
28
|
+
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${resolveArg(col, quoteFn)})`),
|
|
23
29
|
countDistinct: (col) => sqlExpr(`COUNT(DISTINCT ${quoteFn(col)})`),
|
|
30
|
+
distinct: (col) => sqlDistinct(`DISTINCT ${quoteFn(col)}`),
|
|
24
31
|
length: (col) => sqlExpr(`LENGTH(${resolveArg(col, quoteFn)})`),
|
|
25
|
-
stringAgg: (col, sep) => sqlExpr(`STRING_AGG(${
|
|
26
|
-
arrayAgg: (col) => sqlExpr(`ARRAY_AGG(${
|
|
32
|
+
stringAgg: (col, sep) => sqlExpr(`STRING_AGG(${resolveArg(col, quoteFn)}, '${esc(sep)}')`),
|
|
33
|
+
arrayAgg: (col) => sqlExpr(`ARRAY_AGG(${resolveArg(col, quoteFn)})`),
|
|
27
34
|
stddevPop: (col) => sqlExpr(`STDDEV_POP(${quoteFn(col)})`),
|
|
28
35
|
stddevSamp: (col) => sqlExpr(`STDDEV_SAMP(${quoteFn(col)})`),
|
|
29
36
|
varPop: (col) => sqlExpr(`VAR_POP(${quoteFn(col)})`),
|
|
@@ -138,7 +145,7 @@ var postgresqlDialect = {
|
|
|
138
145
|
var postgresqlV6ContextFns = (quoteFn) => ({
|
|
139
146
|
...postgresqlContextFns(quoteFn),
|
|
140
147
|
countAll: () => sqlExpr("COUNT(*)"),
|
|
141
|
-
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${
|
|
148
|
+
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${resolveArg(col, quoteFn)})`),
|
|
142
149
|
countDistinct: (col) => sqlExpr(`COUNT(DISTINCT ${quoteFn(col)})`),
|
|
143
150
|
ceil: (col) => sqlExpr(`CEIL(${resolveArg(col, quoteFn)})`),
|
|
144
151
|
floor: (col) => sqlExpr(`FLOOR(${resolveArg(col, quoteFn)})`)
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import { ColName, FilterCols, FilterJsonCols } from './shared.js';
|
|
2
1
|
import * as _prisma_client_runtime_client from '@prisma/client/runtime/client';
|
|
3
2
|
import { Decimal } from '@prisma/client/runtime/client';
|
|
4
3
|
import { PgExtractField, PgDateTruncUnit } from './postgresql.js';
|
|
5
4
|
export { postgresqlDialect } from './postgresql.js';
|
|
6
5
|
import { J as JSONValue, a as JSONObject } from '../types-B0F8m0ok.js';
|
|
7
|
-
import { S as SQLExpr } from '../sql-expr-
|
|
6
|
+
import { S as SQLExpr, a as SQLDistinct } from '../sql-expr-BGSEwzCi.js';
|
|
7
|
+
import { ColName, FilterCols, ColTypeOf, FilterJsonCols } from './shared.js';
|
|
8
8
|
import './types.js';
|
|
9
9
|
|
|
10
10
|
declare const postgresqlV7ContextFns: <TColEntries extends [string, unknown] = never>(quoteFn: (ref: string) => string) => {
|
|
11
11
|
countAll: () => SQLExpr<bigint>;
|
|
12
|
-
count: (col: ColName<TColEntries> | "*") => SQLExpr<bigint>;
|
|
12
|
+
count: (col: ColName<TColEntries> | "*" | SQLExpr<unknown>) => SQLExpr<bigint>;
|
|
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
16
|
avg: (col: SQLExpr<number> | FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
17
17
|
sum: (col: SQLExpr<number> | FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
18
|
+
distinct: <Col extends ColName<TColEntries>>(col: Col) => SQLDistinct<NonNullable<ColTypeOf<TColEntries, Col>>>;
|
|
18
19
|
length: (col: SQLExpr<string> | FilterCols<TColEntries, string>) => SQLExpr<number>;
|
|
19
|
-
stringAgg: (col: ColName<TColEntries>, sep: string) => SQLExpr<string>;
|
|
20
|
-
arrayAgg: (col: ColName<TColEntries>) => SQLExpr<unknown[]>;
|
|
20
|
+
stringAgg: (col: SQLExpr<string> | ColName<TColEntries>, sep: string) => SQLExpr<string>;
|
|
21
|
+
arrayAgg: (col: SQLExpr<unknown> | ColName<TColEntries>) => SQLExpr<unknown[]>;
|
|
21
22
|
stddevPop: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
22
23
|
stddevSamp: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
23
24
|
varPop: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
@@ -4,6 +4,12 @@ function sqlExpr(sql) {
|
|
|
4
4
|
return sql;
|
|
5
5
|
} };
|
|
6
6
|
}
|
|
7
|
+
var DISTINCT_BRAND = Symbol("sqlDistinct");
|
|
8
|
+
function sqlDistinct(sql) {
|
|
9
|
+
return { sql, [DISTINCT_BRAND]: true, toString() {
|
|
10
|
+
return sql;
|
|
11
|
+
} };
|
|
12
|
+
}
|
|
7
13
|
function resolveArg(arg, quoteFn) {
|
|
8
14
|
if (typeof arg !== "string") return arg.sql;
|
|
9
15
|
return quoteFn(arg);
|
|
@@ -19,11 +25,12 @@ var postgresqlContextFns = (quoteFn) => ({
|
|
|
19
25
|
avg: (col) => sqlExpr(`AVG(${resolveArg(col, quoteFn)})`),
|
|
20
26
|
sum: (col) => sqlExpr(`SUM(${resolveArg(col, quoteFn)})`),
|
|
21
27
|
countAll: () => sqlExpr("COUNT(*)"),
|
|
22
|
-
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${
|
|
28
|
+
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${resolveArg(col, quoteFn)})`),
|
|
23
29
|
countDistinct: (col) => sqlExpr(`COUNT(DISTINCT ${quoteFn(col)})`),
|
|
30
|
+
distinct: (col) => sqlDistinct(`DISTINCT ${quoteFn(col)}`),
|
|
24
31
|
length: (col) => sqlExpr(`LENGTH(${resolveArg(col, quoteFn)})`),
|
|
25
|
-
stringAgg: (col, sep) => sqlExpr(`STRING_AGG(${
|
|
26
|
-
arrayAgg: (col) => sqlExpr(`ARRAY_AGG(${
|
|
32
|
+
stringAgg: (col, sep) => sqlExpr(`STRING_AGG(${resolveArg(col, quoteFn)}, '${esc(sep)}')`),
|
|
33
|
+
arrayAgg: (col) => sqlExpr(`ARRAY_AGG(${resolveArg(col, quoteFn)})`),
|
|
27
34
|
stddevPop: (col) => sqlExpr(`STDDEV_POP(${quoteFn(col)})`),
|
|
28
35
|
stddevSamp: (col) => sqlExpr(`STDDEV_SAMP(${quoteFn(col)})`),
|
|
29
36
|
varPop: (col) => sqlExpr(`VAR_POP(${quoteFn(col)})`),
|
|
@@ -138,7 +145,7 @@ var postgresqlDialect = {
|
|
|
138
145
|
var postgresqlV7ContextFns = (quoteFn) => ({
|
|
139
146
|
...postgresqlContextFns(quoteFn),
|
|
140
147
|
countAll: () => sqlExpr("COUNT(*)"),
|
|
141
|
-
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${
|
|
148
|
+
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${resolveArg(col, quoteFn)})`),
|
|
142
149
|
countDistinct: (col) => sqlExpr(`COUNT(DISTINCT ${quoteFn(col)})`),
|
|
143
150
|
ceil: (col) => sqlExpr(`CEIL(${resolveArg(col, quoteFn)})`),
|
|
144
151
|
floor: (col) => sqlExpr(`FLOOR(${resolveArg(col, quoteFn)})`)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Dialect } from './types.js';
|
|
2
|
-
import { S as SQLExpr } from '../sql-expr-
|
|
2
|
+
import { S as SQLExpr, a as SQLDistinct } from '../sql-expr-BGSEwzCi.js';
|
|
3
3
|
import { J as JSONValue, a as JSONObject } from '../types-B0F8m0ok.js';
|
|
4
|
-
import { FilterCols, ColName, FilterJsonCols } from './shared.js';
|
|
4
|
+
import { FilterCols, ColName, ColTypeOf, FilterJsonCols } from './shared.js';
|
|
5
5
|
import '@prisma/client/runtime/client';
|
|
6
6
|
|
|
7
7
|
type PgCastTypeMap = {
|
|
@@ -22,11 +22,12 @@ declare const postgresqlContextFns: <TColEntries extends [string, unknown] = nev
|
|
|
22
22
|
avg: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<number>;
|
|
23
23
|
sum: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<number>;
|
|
24
24
|
countAll: () => SQLExpr<number>;
|
|
25
|
-
count: (col: ColName<TColEntries> | "*") => SQLExpr<number>;
|
|
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
28
|
length: (col: FilterCols<TColEntries, string> | SQLExpr<string>) => SQLExpr<number>;
|
|
28
|
-
stringAgg: (col: ColName<TColEntries>, sep: string) => SQLExpr<string>;
|
|
29
|
-
arrayAgg: (col: ColName<TColEntries>) => SQLExpr<unknown[]>;
|
|
29
|
+
stringAgg: (col: ColName<TColEntries> | SQLExpr<string>, sep: string) => SQLExpr<string>;
|
|
30
|
+
arrayAgg: (col: ColName<TColEntries> | SQLExpr<unknown>) => SQLExpr<unknown[]>;
|
|
30
31
|
stddevPop: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
31
32
|
stddevSamp: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
32
33
|
varPop: (col: FilterCols<TColEntries, number>) => SQLExpr<number>;
|
|
@@ -4,6 +4,12 @@ function sqlExpr(sql) {
|
|
|
4
4
|
return sql;
|
|
5
5
|
} };
|
|
6
6
|
}
|
|
7
|
+
var DISTINCT_BRAND = Symbol("sqlDistinct");
|
|
8
|
+
function sqlDistinct(sql) {
|
|
9
|
+
return { sql, [DISTINCT_BRAND]: true, toString() {
|
|
10
|
+
return sql;
|
|
11
|
+
} };
|
|
12
|
+
}
|
|
7
13
|
function resolveArg(arg, quoteFn) {
|
|
8
14
|
if (typeof arg !== "string") return arg.sql;
|
|
9
15
|
return quoteFn(arg);
|
|
@@ -19,11 +25,12 @@ var postgresqlContextFns = (quoteFn) => ({
|
|
|
19
25
|
avg: (col) => sqlExpr(`AVG(${resolveArg(col, quoteFn)})`),
|
|
20
26
|
sum: (col) => sqlExpr(`SUM(${resolveArg(col, quoteFn)})`),
|
|
21
27
|
countAll: () => sqlExpr("COUNT(*)"),
|
|
22
|
-
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${
|
|
28
|
+
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${resolveArg(col, quoteFn)})`),
|
|
23
29
|
countDistinct: (col) => sqlExpr(`COUNT(DISTINCT ${quoteFn(col)})`),
|
|
30
|
+
distinct: (col) => sqlDistinct(`DISTINCT ${quoteFn(col)}`),
|
|
24
31
|
length: (col) => sqlExpr(`LENGTH(${resolveArg(col, quoteFn)})`),
|
|
25
|
-
stringAgg: (col, sep) => sqlExpr(`STRING_AGG(${
|
|
26
|
-
arrayAgg: (col) => sqlExpr(`ARRAY_AGG(${
|
|
32
|
+
stringAgg: (col, sep) => sqlExpr(`STRING_AGG(${resolveArg(col, quoteFn)}, '${esc(sep)}')`),
|
|
33
|
+
arrayAgg: (col) => sqlExpr(`ARRAY_AGG(${resolveArg(col, quoteFn)})`),
|
|
27
34
|
stddevPop: (col) => sqlExpr(`STDDEV_POP(${quoteFn(col)})`),
|
|
28
35
|
stddevSamp: (col) => sqlExpr(`STDDEV_SAMP(${quoteFn(col)})`),
|
|
29
36
|
varPop: (col) => sqlExpr(`VAR_POP(${quoteFn(col)})`),
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { S as SQLExpr } from '../sql-expr-
|
|
1
|
+
import { S as SQLExpr } from '../sql-expr-BGSEwzCi.js';
|
|
2
2
|
|
|
3
3
|
declare const sharedFunctions: {};
|
|
4
4
|
declare const esc: (s: string) => string;
|
|
5
5
|
declare const flattenJsonObjectPairs: (pairs: [string, string | SQLExpr<unknown>][], quoteFn: (ref: string) => string) => string[];
|
|
6
6
|
type FilterCols<TEntries extends [string, unknown], T> = TEntries extends [infer N extends string, infer V] ? NonNullable<V> extends T ? N : never : never;
|
|
7
7
|
type ColName<TEntries extends [string, unknown]> = TEntries extends [infer N extends string, unknown] ? N : never;
|
|
8
|
+
type ColTypeOf<TEntries extends [string, unknown], Col extends string> = TEntries extends [Col, infer V] ? V : never;
|
|
8
9
|
type FilterJsonCols<TEntries extends [string, unknown]> = TEntries extends [infer N extends string, infer V] ? NonNullable<V> extends (string | number | boolean | Date | bigint | Buffer) ? never : N : never;
|
|
9
10
|
|
|
10
|
-
export { type ColName, type FilterCols, type FilterJsonCols, esc, flattenJsonObjectPairs, sharedFunctions };
|
|
11
|
+
export { type ColName, type ColTypeOf, type FilterCols, type FilterJsonCols, esc, flattenJsonObjectPairs, sharedFunctions };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Dialect } from './types.js';
|
|
2
|
-
import { S as SQLExpr } from '../sql-expr-
|
|
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
|
-
import { FilterCols, ColName, FilterJsonCols } from './shared.js';
|
|
4
|
+
import { FilterCols, ColName, ColTypeOf, FilterJsonCols } from './shared.js';
|
|
5
5
|
import '@prisma/client/runtime/client';
|
|
6
6
|
|
|
7
7
|
type SqliteMinMaxResult<TColEntries extends [string, unknown], Col extends string> = TColEntries extends [Col, infer V] ? NonNullable<V> extends number ? bigint | null : V | null : never;
|
|
@@ -16,10 +16,13 @@ declare const sqliteContextFns: <TColEntries extends [string, unknown] = never,
|
|
|
16
16
|
avg: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<number>;
|
|
17
17
|
sum: (col: FilterCols<TColEntries, number> | SQLExpr<number>) => SQLExpr<bigint | number>;
|
|
18
18
|
countAll: () => SQLExpr<bigint>;
|
|
19
|
-
count: (col: ColName<TColEntries> | "*") => SQLExpr<bigint>;
|
|
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
22
|
length: (col: FilterCols<TColEntries, string> | SQLExpr<string>) => SQLExpr<bigint>;
|
|
22
|
-
groupConcat: (col:
|
|
23
|
+
groupConcat: (((col: SQLDistinct<string>) => SQLExpr<string>) & ((col: ColName<TColEntries> | (SQLExpr<string> & {
|
|
24
|
+
readonly [DISTINCT_BRAND]?: never;
|
|
25
|
+
}), sep?: string) => SQLExpr<string>));
|
|
23
26
|
total: (col: ColName<TColEntries>) => SQLExpr<number>;
|
|
24
27
|
min: <Col extends ColName<TColEntries>>(col: Col) => SQLExpr<SqliteMinMaxResult<TColEntries, Col>>;
|
|
25
28
|
max: <Col extends ColName<TColEntries>>(col: Col) => SQLExpr<SqliteMinMaxResult<TColEntries, Col>>;
|
|
@@ -4,6 +4,15 @@ function sqlExpr(sql) {
|
|
|
4
4
|
return sql;
|
|
5
5
|
} };
|
|
6
6
|
}
|
|
7
|
+
var DISTINCT_BRAND = Symbol("sqlDistinct");
|
|
8
|
+
function sqlDistinct(sql) {
|
|
9
|
+
return { sql, [DISTINCT_BRAND]: true, toString() {
|
|
10
|
+
return sql;
|
|
11
|
+
} };
|
|
12
|
+
}
|
|
13
|
+
function isDistinct(val) {
|
|
14
|
+
return typeof val === "object" && val !== null && DISTINCT_BRAND in val;
|
|
15
|
+
}
|
|
7
16
|
function resolveArg(arg, quoteFn) {
|
|
8
17
|
if (typeof arg !== "string") return arg.sql;
|
|
9
18
|
return quoteFn(arg);
|
|
@@ -26,11 +35,18 @@ var sqliteContextFns = (quoteFn, condFn) => ({
|
|
|
26
35
|
sum: (col) => sqlExpr(`SUM(${resolveArg(col, quoteFn)})`),
|
|
27
36
|
// Aggregate integer-result fns — SQLite returns INTEGER → bigint
|
|
28
37
|
countAll: () => sqlExpr("COUNT(*)"),
|
|
29
|
-
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${
|
|
38
|
+
count: (col) => sqlExpr(col === "*" ? "COUNT(*)" : `COUNT(${resolveArg(col, quoteFn)})`),
|
|
30
39
|
countDistinct: (col) => sqlExpr(`COUNT(DISTINCT ${quoteFn(col)})`),
|
|
40
|
+
distinct: (col) => sqlDistinct(`DISTINCT ${quoteFn(col)}`),
|
|
31
41
|
// LENGTH returns INTEGER → bigint in SQLite
|
|
32
42
|
length: (col) => sqlExpr(`LENGTH(${resolveArg(col, quoteFn)})`),
|
|
33
|
-
groupConcat: (col, sep) =>
|
|
43
|
+
groupConcat: (col, sep) => {
|
|
44
|
+
const inner = resolveArg(col, quoteFn);
|
|
45
|
+
if (isDistinct(col) && sep !== void 0) {
|
|
46
|
+
throw new Error("SQLite does not support GROUP_CONCAT(DISTINCT col, sep) \u2014 omit the separator.");
|
|
47
|
+
}
|
|
48
|
+
return sqlExpr(`GROUP_CONCAT(${inner}${sep !== void 0 ? `, '${sep.replace(/'/g, "''")}'` : ""})`);
|
|
49
|
+
},
|
|
34
50
|
total: (col) => sqlExpr(`TOTAL(${quoteFn(col)})`),
|
|
35
51
|
// SQLite MIN/MAX return bigint for integer columns — override base (number) return types
|
|
36
52
|
min: (col) => sqlExpr(`MIN(${quoteFn(col)})`),
|
package/dist/extend/extend.d.ts
CHANGED
|
@@ -4,7 +4,11 @@ type SQLExpr<T> = {
|
|
|
4
4
|
readonly [_type]?: T;
|
|
5
5
|
toString(): string;
|
|
6
6
|
};
|
|
7
|
+
declare const DISTINCT_BRAND: unique symbol;
|
|
8
|
+
type SQLDistinct<T> = SQLExpr<T> & {
|
|
9
|
+
readonly [DISTINCT_BRAND]: true;
|
|
10
|
+
};
|
|
7
11
|
type LitValue = string | number | boolean | null;
|
|
8
12
|
type LitToType<T extends LitValue> = T extends string ? string : T extends number ? number : T extends boolean ? number : null;
|
|
9
13
|
|
|
10
|
-
export type
|
|
14
|
+
export { DISTINCT_BRAND as D, type LitToType as L, type SQLExpr as S, type SQLDistinct as a };
|
package/dist/generator.cjs
CHANGED
package/dist/generator.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import './chunk-
|
|
1
|
+
import './chunk-NFKUA5XM.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prisma-ts-select",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"prisma-ts-select": "dist/bin.cjs"
|
|
@@ -28,6 +28,30 @@
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"bp": "pnpm build && pnpm version patch && pnpm pack",
|
|
33
|
+
"build": "pnpm exec rimraf dist && tsup",
|
|
34
|
+
"reset": "rm -rf prisma/migrations/ && prisma migrate dev --name init && prisma generate",
|
|
35
|
+
"start": "tsx src/index.ts",
|
|
36
|
+
"prisma-upgrade": "pnpm i --save-dev prisma@latest && pnpm i @prisma/client@latest",
|
|
37
|
+
"lint:ts": "tsc --noEmit -p tsconfig.json",
|
|
38
|
+
"lint:tsw": "pnpm tsc -w",
|
|
39
|
+
"lint": "tsc --noEmit ; eslint \"scripts/**/*.{j,t}s{,x}\" --cache --max-warnings=0",
|
|
40
|
+
"lint:s": "eslint --config .eslintrc.style.json \"scripts/**/*.{j,t}s{,x}\" --cache --max-warnings=0",
|
|
41
|
+
"lint:fix": "eslint --config .eslintrc.style.json \"scripts/**/*.{j,t}s{,x}\" --cache --max-warnings=0 --fix",
|
|
42
|
+
"p:gen": "pnpm exec prisma generate",
|
|
43
|
+
"p:dbp": "pnpm exec prisma db push",
|
|
44
|
+
"p:migrate": "pnpm exec prisma migrate dev",
|
|
45
|
+
"p:update": "pnpm add -D prisma@latest && pnpm add @prisma/client@latest",
|
|
46
|
+
"test": "node --test tests/**/*.spec.ts",
|
|
47
|
+
"test:jest": "jest",
|
|
48
|
+
"2postinstall": "node src/scripts/postinstall.js",
|
|
49
|
+
"doc": "pnpm exec markdown-toc -i README.md",
|
|
50
|
+
"mdcode-ts": "pnpm exec mdcode",
|
|
51
|
+
"readme:extract": "pnpm mdcode extract README.md",
|
|
52
|
+
"readme:update": "pnpm mdcode update --transform ./transforms/readme-sql-clean.ts README.md",
|
|
53
|
+
"readme:test": "pnpm --filter usage-sqlite-v7 test -- tests/readme"
|
|
54
|
+
},
|
|
31
55
|
"dependencies": {
|
|
32
56
|
"@prisma/generator-helper": "^6.0.0",
|
|
33
57
|
"@prisma/internals": "^6.0.0",
|
|
@@ -151,29 +175,5 @@
|
|
|
151
175
|
"publishConfig": {
|
|
152
176
|
"access": "public",
|
|
153
177
|
"name": "prisma-ts-select"
|
|
154
|
-
},
|
|
155
|
-
"scripts": {
|
|
156
|
-
"bp": "pnpm build && pnpm version patch && pnpm pack",
|
|
157
|
-
"build": "pnpm exec rimraf dist && tsup",
|
|
158
|
-
"reset": "rm -rf prisma/migrations/ && prisma migrate dev --name init && prisma generate",
|
|
159
|
-
"start": "tsx src/index.ts",
|
|
160
|
-
"prisma-upgrade": "pnpm i --save-dev prisma@latest && pnpm i @prisma/client@latest",
|
|
161
|
-
"lint:ts": "tsc --noEmit -p tsconfig.json",
|
|
162
|
-
"lint:tsw": "pnpm tsc -w",
|
|
163
|
-
"lint": "tsc --noEmit ; eslint \"scripts/**/*.{j,t}s{,x}\" --cache --max-warnings=0",
|
|
164
|
-
"lint:s": "eslint --config .eslintrc.style.json \"scripts/**/*.{j,t}s{,x}\" --cache --max-warnings=0",
|
|
165
|
-
"lint:fix": "eslint --config .eslintrc.style.json \"scripts/**/*.{j,t}s{,x}\" --cache --max-warnings=0 --fix",
|
|
166
|
-
"p:gen": "pnpm exec prisma generate",
|
|
167
|
-
"p:dbp": "pnpm exec prisma db push",
|
|
168
|
-
"p:migrate": "pnpm exec prisma migrate dev",
|
|
169
|
-
"p:update": "pnpm add -D prisma@latest && pnpm add @prisma/client@latest",
|
|
170
|
-
"test": "node --test tests/**/*.spec.ts",
|
|
171
|
-
"test:jest": "jest",
|
|
172
|
-
"2postinstall": "node src/scripts/postinstall.js",
|
|
173
|
-
"doc": "pnpm exec markdown-toc -i README.md",
|
|
174
|
-
"mdcode-ts": "pnpm exec mdcode",
|
|
175
|
-
"readme:extract": "pnpm mdcode extract README.md",
|
|
176
|
-
"readme:update": "pnpm mdcode update --transform ./transforms/readme-sql-clean.ts README.md",
|
|
177
|
-
"readme:test": "pnpm --filter usage-sqlite-v7 test -- tests/readme"
|
|
178
178
|
}
|
|
179
|
-
}
|
|
179
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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.
|