prisma-ts-select 0.0.34 → 0.1.2
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 +21 -0
- package/README.md +1242 -315
- 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/whereNotNull.gif +0 -0
- package/assets/whereisNull.gif +0 -0
- package/dist/bin.cjs +1 -1
- package/dist/bin.js +1 -1
- package/dist/chunk-47KZVQLD.js +283 -0
- package/dist/chunk-54D2J5AR.cjs +291 -0
- package/dist/extend/dialects/index.d.ts +13 -0
- package/dist/extend/dialects/index.js +186 -0
- package/dist/extend/dialects/mysql-v6.d.ts +100 -0
- package/dist/extend/dialects/mysql-v6.js +152 -0
- package/dist/extend/dialects/mysql-v7.d.ts +6 -0
- package/dist/extend/dialects/mysql-v7.js +138 -0
- package/dist/extend/dialects/mysql.d.ts +90 -0
- package/dist/extend/dialects/mysql.js +156 -0
- package/dist/extend/dialects/postgresql-v6.d.ts +97 -0
- package/dist/extend/dialects/postgresql-v6.js +136 -0
- package/dist/extend/dialects/postgresql-v7.d.ts +97 -0
- package/dist/extend/dialects/postgresql-v7.js +136 -0
- package/dist/extend/dialects/postgresql.d.ts +89 -0
- package/dist/extend/dialects/postgresql.js +147 -0
- package/dist/extend/dialects/shared.d.ts +6 -0
- package/dist/extend/dialects/shared.js +5 -0
- package/dist/extend/dialects/sqlite.d.ts +63 -0
- package/dist/extend/dialects/sqlite.js +138 -0
- package/dist/extend/dialects/types.d.ts +12 -0
- package/dist/extend/dialects/types.js +4 -0
- package/dist/extend/extend.d.ts +286 -43
- package/dist/extend/extend.js +735 -163
- package/dist/extend/sql-expr-BaKWzJ-r.d.ts +10 -0
- package/dist/extend/types-D84lxYVc.d.ts +5 -0
- package/dist/generator.cjs +1 -1
- package/dist/generator.js +1 -1
- package/package.json +46 -42
- package/built/extend.cjs +0 -680
- package/built/extend.d.cts +0 -520
- package/built/extend.d.ts +0 -520
- package/built/extend.js +0 -678
- package/dist/chunk-TBO3MX7Q.cjs +0 -195
- package/dist/chunk-X3N5N5KQ.js +0 -187
- package/dist/extend/extend.cjs +0 -357
- package/dist/extend/extend.d.cts +0 -264
package/dist/extend/extend.cjs
DELETED
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var extension = require('@prisma/client/extension');
|
|
4
|
-
var tsPattern = require('ts-pattern');
|
|
5
|
-
|
|
6
|
-
const DB = {};
|
|
7
|
-
class DbSelect {
|
|
8
|
-
constructor(db) {
|
|
9
|
-
this.db = db;
|
|
10
|
-
}
|
|
11
|
-
from(baseTable, alias) {
|
|
12
|
-
return new _fJoin(this.db, {
|
|
13
|
-
tables: [{
|
|
14
|
-
table: baseTable,
|
|
15
|
-
alias
|
|
16
|
-
}],
|
|
17
|
-
selects: []
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
class _fRun {
|
|
22
|
-
constructor(db, values) {
|
|
23
|
-
this.db = db;
|
|
24
|
-
this.values = values;
|
|
25
|
-
this.values.limit = typeof this.values.limit === "number" ? this.values.limit : void 0;
|
|
26
|
-
this.values.offset = typeof this.values.offset === "number" ? this.values.offset : void 0;
|
|
27
|
-
}
|
|
28
|
-
run() {
|
|
29
|
-
return this.db.$queryRawUnsafe(
|
|
30
|
-
this.getSQL()
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
getTables() {
|
|
34
|
-
return {};
|
|
35
|
-
}
|
|
36
|
-
getFields() {
|
|
37
|
-
return {};
|
|
38
|
-
}
|
|
39
|
-
getResultType() {
|
|
40
|
-
return {};
|
|
41
|
-
}
|
|
42
|
-
getSQL(formatted = false) {
|
|
43
|
-
function processCondition(condition, formatted2) {
|
|
44
|
-
return "(" + Object.keys(condition).map((field) => {
|
|
45
|
-
const value = condition[field];
|
|
46
|
-
if (typeof value === "object" && value !== null && !Array.isArray(value) && "op" in value) {
|
|
47
|
-
switch (value.op) {
|
|
48
|
-
case "IN":
|
|
49
|
-
case "NOT IN":
|
|
50
|
-
const valuesList = value.values.map((v) => typeof v === "string" ? `'${v}'` : v).join(", ");
|
|
51
|
-
return `${String(field)} ${value.op} (${valuesList})`;
|
|
52
|
-
case "BETWEEN":
|
|
53
|
-
if (value.values.length > 2) throw new Error("Too many items supplied to op BETWEEN");
|
|
54
|
-
const [start, end] = value.values;
|
|
55
|
-
return `${String(field)} BETWEEN ${typeof start === "string" ? `'${start}'` : start} AND ${typeof end === "string" ? `'${end}'` : end}`;
|
|
56
|
-
case "LIKE":
|
|
57
|
-
case "NOT LIKE":
|
|
58
|
-
return `${String(field)} ${value.op} '${value.value}'`;
|
|
59
|
-
case "IS NULL":
|
|
60
|
-
case "IS NOT NULL":
|
|
61
|
-
return `${String(field)} ${value.op}`;
|
|
62
|
-
case ">":
|
|
63
|
-
case ">=":
|
|
64
|
-
case "<":
|
|
65
|
-
case "<=":
|
|
66
|
-
case "!=":
|
|
67
|
-
return `${String(field)} ${value.op} ${typeof value.value === "string" ? `'${value.value}'` : value.value}`;
|
|
68
|
-
default:
|
|
69
|
-
throw new Error(`Unsupported operation: ${value.op}`);
|
|
70
|
-
}
|
|
71
|
-
} else if (Array.isArray(value)) {
|
|
72
|
-
const valuesList = value.map((v) => typeof v === "string" ? `'${v}'` : v).join(", ");
|
|
73
|
-
return `${String(field)} IN (${valuesList})`;
|
|
74
|
-
} else if (value === null) {
|
|
75
|
-
return `${String(field)} IS NULL`;
|
|
76
|
-
} else {
|
|
77
|
-
return `${String(field)} = ${typeof value === "string" ? `'${value}'` : value}`;
|
|
78
|
-
}
|
|
79
|
-
}).join(" AND " + (" ")) + " )";
|
|
80
|
-
}
|
|
81
|
-
function processCriteria(main, joinType = "AND", formatted2 = false) {
|
|
82
|
-
const results = [];
|
|
83
|
-
for (const criteria of main) {
|
|
84
|
-
if (typeof criteria === "string") {
|
|
85
|
-
results.push(criteria);
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
for (const criterion in criteria) {
|
|
89
|
-
results.push(tsPattern.match(criterion).returnType().with("$AND", (criterion2) => {
|
|
90
|
-
return "(" + //@ts-expect-error criterion
|
|
91
|
-
processCriteria(criteria[criterion2], "AND", formatted2) + ")";
|
|
92
|
-
}).with("$OR", (criterion2) => {
|
|
93
|
-
return "(" + //@ts-expect-error criterion
|
|
94
|
-
processCriteria(criteria[criterion2], "OR", formatted2) + ")";
|
|
95
|
-
}).with("$NOT", (criterion2) => {
|
|
96
|
-
return "(NOT(" + //@ts-expect-error criterion
|
|
97
|
-
processCriteria(criteria[criterion2], "AND", formatted2) + "))";
|
|
98
|
-
}).with("$NOR", (criterion2) => {
|
|
99
|
-
return "(NOT(" + //@ts-expect-error criterion
|
|
100
|
-
processCriteria(criteria[criterion2], "OR", formatted2) + "))";
|
|
101
|
-
}).with(tsPattern.P.string, () => {
|
|
102
|
-
return processCondition(criteria);
|
|
103
|
-
}).exhaustive());
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return results.join((formatted2 ? "\n" : " ") + joinType + (formatted2 ? "\n" : " "));
|
|
107
|
-
}
|
|
108
|
-
const whereClause = this.values.where !== void 0 ? processCriteria(this.values.where, "AND", formatted) : void 0;
|
|
109
|
-
const havingClause = this.values.having !== void 0 ? processCriteria(this.values.having, "AND", formatted) : void 0;
|
|
110
|
-
const [base, ...joins] = this.values.tables;
|
|
111
|
-
const baseTable = base.alias ? `${base.table} AS \`${base.alias}\`` : base.table;
|
|
112
|
-
return [
|
|
113
|
-
this.values.selects.length === 0 ? "" : "SELECT " + (this.values.selectDistinct === true ? "DISTINCT " : "") + this.values.selects.join(", "),
|
|
114
|
-
`FROM ${baseTable}`,
|
|
115
|
-
joins.map(({
|
|
116
|
-
table,
|
|
117
|
-
local,
|
|
118
|
-
remote,
|
|
119
|
-
alias
|
|
120
|
-
}) => {
|
|
121
|
-
const tLocal = (alias || table) + "." + local;
|
|
122
|
-
return `JOIN ${!!alias ? table + " AS `" + alias + "`" : table} ON ${tLocal} = ${remote}`;
|
|
123
|
-
}).join(formatted ? "\n" : " ") ?? "",
|
|
124
|
-
!whereClause ? "" : `WHERE ${whereClause}`,
|
|
125
|
-
!this.values.groupBy?.length ? "" : `GROUP BY ${this.values.groupBy.join(", ")}`,
|
|
126
|
-
!havingClause ? "" : `HAVING ${havingClause}`,
|
|
127
|
-
!(this.values.orderBy && this.values.orderBy.length > 0) ? "" : "ORDER BY " + this.values.orderBy.join(", "),
|
|
128
|
-
!this.values.limit ? "" : `LIMIT ${this.values.limit}`,
|
|
129
|
-
!this.values.offset ? "" : `OFFSET ${this.values.offset}`
|
|
130
|
-
].filter(Boolean).join(formatted ? "\n" : " ").trim() + ";";
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
class _fOffset extends _fRun {
|
|
134
|
-
offset(offset) {
|
|
135
|
-
return new _fRun(this.db, { ...this.values, offset });
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
class _fLimit extends _fRun {
|
|
139
|
-
limit(limit) {
|
|
140
|
-
return new _fOffset(this.db, { ...this.values, limit });
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
class _fOrderBy extends _fLimit {
|
|
144
|
-
orderBy(orderBy) {
|
|
145
|
-
return new _fLimit(this.db, { ...this.values, orderBy });
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
class _fSelect extends _fOrderBy {
|
|
149
|
-
select(select, alias) {
|
|
150
|
-
const tableColMatch = select.match(/^(\w+)\.(.*?)$/);
|
|
151
|
-
if (tableColMatch) {
|
|
152
|
-
const [, tableName, colName] = tableColMatch;
|
|
153
|
-
const tableObject = this.values.tables.find((t) => (t.alias || t.table) === tableName);
|
|
154
|
-
if (!tableObject) throw new Error(`Table "${tableName}" not found in query`);
|
|
155
|
-
const tableFields = DB[tableObject.table];
|
|
156
|
-
if (!tableFields) {
|
|
157
|
-
throw new Error(`Table "${tableName}" not found in database schema`);
|
|
158
|
-
}
|
|
159
|
-
if (colName === "*") {
|
|
160
|
-
const hasMultipleTables = this.values.tables && this.values.tables.length > 1 || false;
|
|
161
|
-
const expandedSelects = Object.keys(tableFields.fields).map((field) => {
|
|
162
|
-
if (hasMultipleTables) {
|
|
163
|
-
return `${tableName}.${field} AS \`${tableName}.${field}\``;
|
|
164
|
-
}
|
|
165
|
-
return `${field}`;
|
|
166
|
-
});
|
|
167
|
-
return new _fSelect(this.db, {
|
|
168
|
-
...this.values,
|
|
169
|
-
selects: [...this.values.selects, ...expandedSelects]
|
|
170
|
-
});
|
|
171
|
-
} else if (!alias && !!colName) {
|
|
172
|
-
const currentTablesWithFields = this.values.tables.reduce((acc, table) => {
|
|
173
|
-
const { table: real } = table;
|
|
174
|
-
for (const col in DB[real].fields) {
|
|
175
|
-
acc[col] = acc[col] ? acc[col] + 1 : 1;
|
|
176
|
-
}
|
|
177
|
-
return acc;
|
|
178
|
-
}, {});
|
|
179
|
-
if (!currentTablesWithFields[colName]) {
|
|
180
|
-
throw new Error(`Column "${colName}" not found in database schema`);
|
|
181
|
-
}
|
|
182
|
-
if (currentTablesWithFields[colName] > 1) {
|
|
183
|
-
return new _fSelect(this.db, {
|
|
184
|
-
...this.values,
|
|
185
|
-
selects: [...this.values.selects, `${select} AS \`${select}\``]
|
|
186
|
-
});
|
|
187
|
-
} else {
|
|
188
|
-
return new _fSelect(this.db, {
|
|
189
|
-
...this.values,
|
|
190
|
-
selects: [...this.values.selects, `${colName}`]
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
if (alias !== void 0) {
|
|
196
|
-
return new _fSelect(this.db, {
|
|
197
|
-
...this.values,
|
|
198
|
-
selects: [...this.values.selects, `${select} AS \`${alias}\``]
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
return new _fSelect(this.db, {
|
|
202
|
-
...this.values,
|
|
203
|
-
selects: [...this.values.selects, select]
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
class _fSelectDistinct extends _fSelect {
|
|
208
|
-
selectDistinct() {
|
|
209
|
-
return new _fSelect(this.db, { ...this.values, selectDistinct: true });
|
|
210
|
-
}
|
|
211
|
-
selectAll() {
|
|
212
|
-
const selects = function(values) {
|
|
213
|
-
if (values.tables && values.tables.length > 1) {
|
|
214
|
-
return [
|
|
215
|
-
/*values.baseTable,*/
|
|
216
|
-
...values.tables.map((t) => t.table)
|
|
217
|
-
].reduce((acc, table) => {
|
|
218
|
-
return acc.concat(Object.keys(DB[table].fields).map((field) => `${table}.${field} AS \`${table}.${field}\``));
|
|
219
|
-
}, []);
|
|
220
|
-
}
|
|
221
|
-
return Object.keys(DB[values.tables[0].table].fields);
|
|
222
|
-
}(this.values);
|
|
223
|
-
return new _fOrderBy(this.db, {
|
|
224
|
-
...this.values,
|
|
225
|
-
selects
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
//TODO
|
|
229
|
-
// selectAllOmit() {
|
|
230
|
-
// throw new Error("Not implemented yet")
|
|
231
|
-
// }
|
|
232
|
-
}
|
|
233
|
-
class _fHaving extends _fSelectDistinct {
|
|
234
|
-
// TODO Allowed Fields
|
|
235
|
-
// - specified in groupBy
|
|
236
|
-
having(criteria) {
|
|
237
|
-
return new _fSelectDistinct(this.db, {
|
|
238
|
-
...this.values,
|
|
239
|
-
having: [criteria]
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
class _fGroupBy extends _fHaving {
|
|
244
|
-
//TODO this should only accept columns for tables in play
|
|
245
|
-
groupBy(groupBy) {
|
|
246
|
-
return new _fHaving(this.db, { ...this.values, groupBy });
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
class _fWhere extends _fGroupBy {
|
|
250
|
-
whereNotNull(col) {
|
|
251
|
-
return new _fWhere(this.db, {
|
|
252
|
-
...this.values,
|
|
253
|
-
where: [
|
|
254
|
-
...this.values.where || [],
|
|
255
|
-
{
|
|
256
|
-
$AND: (
|
|
257
|
-
//@ts-expect-error todo comeback to, col is a string or never
|
|
258
|
-
[{ [col]: { op: "IS NOT NULL" } }]
|
|
259
|
-
)
|
|
260
|
-
}
|
|
261
|
-
]
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
whereIsNull(col) {
|
|
265
|
-
return new _fWhere(this.db, {
|
|
266
|
-
...this.values,
|
|
267
|
-
where: [
|
|
268
|
-
...this.values.where || [],
|
|
269
|
-
{
|
|
270
|
-
$AND: (
|
|
271
|
-
//@ts-expect-error todo comeback to, col is a string or never
|
|
272
|
-
[{ [col]: { op: "IS NULL" } }]
|
|
273
|
-
)
|
|
274
|
-
}
|
|
275
|
-
]
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
where(criteria) {
|
|
279
|
-
return new _fGroupBy(this.db, {
|
|
280
|
-
...this.values,
|
|
281
|
-
where: [...this.values.where || [], criteria]
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
whereRaw(where) {
|
|
285
|
-
return new _fGroupBy(this.db, {
|
|
286
|
-
...this.values,
|
|
287
|
-
where: [...this.values.where || [], where.replace(/^\s*where\s*/i, "").trim()]
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
class _fJoin extends _fWhere {
|
|
292
|
-
// Implementation
|
|
293
|
-
join(tableOrOptions, field, reference) {
|
|
294
|
-
let table;
|
|
295
|
-
let local;
|
|
296
|
-
let remote;
|
|
297
|
-
let tableAlias;
|
|
298
|
-
if (typeof tableOrOptions === "object" && "table" in tableOrOptions) {
|
|
299
|
-
table = tableOrOptions.table.trim();
|
|
300
|
-
local = tableOrOptions.src;
|
|
301
|
-
remote = tableOrOptions.on;
|
|
302
|
-
tableAlias = tableOrOptions.alias?.trim();
|
|
303
|
-
} else {
|
|
304
|
-
const parts = tableOrOptions.split(" ");
|
|
305
|
-
table = parts[0];
|
|
306
|
-
tableAlias = parts[1]?.trim();
|
|
307
|
-
local = field;
|
|
308
|
-
remote = reference;
|
|
309
|
-
}
|
|
310
|
-
return new _fJoin(this.db, {
|
|
311
|
-
...this.values,
|
|
312
|
-
tables: [...this.values.tables || [], {
|
|
313
|
-
table,
|
|
314
|
-
local,
|
|
315
|
-
remote,
|
|
316
|
-
alias: tableAlias
|
|
317
|
-
}]
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
// Implementation
|
|
321
|
-
joinUnsafeTypeEnforced(tableOrOptions, field, reference) {
|
|
322
|
-
return this.join(tableOrOptions, field, reference);
|
|
323
|
-
}
|
|
324
|
-
// Implementation
|
|
325
|
-
joinUnsafeIgnoreType(tableOrOptions, field, reference) {
|
|
326
|
-
return this.join(tableOrOptions, field, reference);
|
|
327
|
-
}
|
|
328
|
-
// innerJoin(table: TTableSources, col1:string, col2:string){
|
|
329
|
-
// return new _fJoin<TDBBase>(this.db, {...this.values, tables: [...this.values.tables || [], table]});
|
|
330
|
-
// }
|
|
331
|
-
// leftJoin(table: TTableSources, col1:string, col2:string){
|
|
332
|
-
// return new _fJoin<TDBBase>(this.db, {...this.values, tables: [...this.values.tables || [], table]});
|
|
333
|
-
// }
|
|
334
|
-
// rightJoin(table: TTableSources, col1:string, col2:string){
|
|
335
|
-
// return new _fJoin<TDBBase>(this.db, {...this.values, tables: [...this.values.tables || [], table]});
|
|
336
|
-
// }
|
|
337
|
-
// fullJoin(table: TTableSources, col1:string, col2:string){
|
|
338
|
-
// return new _fJoin<TDBBase>(this.db, {...this.values, tables: [...this.values.tables || [], table]});
|
|
339
|
-
// }
|
|
340
|
-
// crossJoin(table: TTableSources, col1:string, col2:string){
|
|
341
|
-
// return new _fJoin<TDBBase>(this.db, {...this.values, tables: [...this.values.tables || [], table]});
|
|
342
|
-
// }
|
|
343
|
-
// outerJoin(table: TTableSources, col1:string, col2:string){
|
|
344
|
-
// return new _fJoin<TDBBase>(this.db, {...this.values, tables: [...this.values.tables || [], table]});
|
|
345
|
-
// }
|
|
346
|
-
}
|
|
347
|
-
var extend_default = {
|
|
348
|
-
client: {
|
|
349
|
-
$from(table) {
|
|
350
|
-
const client = extension.Prisma.getExtensionContext(this);
|
|
351
|
-
const [base, ...aliases] = table.split(" ");
|
|
352
|
-
return new DbSelect(client).from(base.trim(), aliases.join().trim() || void 0);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
module.exports = extend_default;
|
package/dist/extend/extend.d.cts
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import { Prisma } from '@prisma/client/extension';
|
|
2
|
-
import { PrismaClient } from '@prisma/client';
|
|
3
|
-
|
|
4
|
-
declare const DB: DBType;
|
|
5
|
-
type TDB = typeof DB;
|
|
6
|
-
type DeepWriteable<T> = {
|
|
7
|
-
-readonly [P in keyof T]: DeepWriteable<T[P]>;
|
|
8
|
-
};
|
|
9
|
-
type _db = DeepWriteable<TDB>;
|
|
10
|
-
type DATABASE = {
|
|
11
|
-
[k in keyof _db]: {
|
|
12
|
-
table: k;
|
|
13
|
-
fields: {
|
|
14
|
-
[f in keyof _db[k]["fields"]]: StrTypeToTSType<_db[k]["fields"][f]>;
|
|
15
|
-
};
|
|
16
|
-
relations: _db[k]["relations"];
|
|
17
|
-
};
|
|
18
|
-
}[keyof TDB];
|
|
19
|
-
type JSONPrimitive = string | number | boolean | null;
|
|
20
|
-
type JSONValue = JSONPrimitive | JSONObject | JSONArray;
|
|
21
|
-
type JSONObject = {
|
|
22
|
-
[member: string]: JSONValue;
|
|
23
|
-
};
|
|
24
|
-
type JSONArray = Array<JSONValue>;
|
|
25
|
-
type StrTypeToTSType<str> = str extends string ? (GetTSType<RemoveNullChar<str>> | IsNullable<str>) : never;
|
|
26
|
-
type GetTSType<str extends string> = str extends `String` ? string : str extends `BigInt` ? bigint : str extends `Int` ? number : str extends `Float` ? number : str extends `Decimal` ? number : str extends `Boolean` ? boolean : str extends `DateTime` ? Date : str extends `Bytes` ? Buffer : str extends `Json` ? JSONValue : "Unknown type";
|
|
27
|
-
type IsNullable<str extends string> = str extends `?${string}` ? null : never;
|
|
28
|
-
type RemoveNullChar<str extends string> = str extends `?${infer s}` ? s : str;
|
|
29
|
-
type DBType = Record<string, {
|
|
30
|
-
fields: Record<string, string>;
|
|
31
|
-
relations: Record<string, Record<string, Array<string>>>;
|
|
32
|
-
}>;
|
|
33
|
-
type Filter<a, b> = a extends b ? a : never;
|
|
34
|
-
type IsString<T> = T extends string ? T : never;
|
|
35
|
-
type ValidSelect<Tables extends TArrSources> = "*" | GetOtherColumns<Tables> | GetTableStar<Tables>;
|
|
36
|
-
type GetTableStar<Tables extends TArrSources> = Tables extends [infer T extends TTableSources, ...Array<TTableSources>] ? T extends string ? `${T}.*` | GetTableStarJoined<Tables[number]> : `${T[1]}.*` | GetTableStarJoined<Tables[number]> : never;
|
|
37
|
-
type GetTableStarJoined<T extends TTableSources> = T extends string ? `${T}.*` : `${T[1]}.*`;
|
|
38
|
-
type ExtractColumnType<Column extends string, TSources extends TArrSources, TFields extends TFieldsType> = Column extends `${infer T}.${infer F}` ? T extends keyof TFields ? F extends keyof TFields[T] ? TFields[T][F] : never : never : Column extends keyof TFields[TSources[0] extends string ? TSources[0] : `Come back to 1`] ? TFields[TSources[0] extends string ? TSources[0] : `Come back To 2`][Column] : never;
|
|
39
|
-
type TTables = DATABASE["table"];
|
|
40
|
-
type TTableSources = DATABASE["table"] | [table: DATABASE["table"], alias: string];
|
|
41
|
-
type TArrSources = [TTableSources, ...Array<TTableSources>];
|
|
42
|
-
type ClauseType = Array<string | WhereCriteria<TArrSources, Record<string, any>>>;
|
|
43
|
-
type Values = {
|
|
44
|
-
selectDistinct?: true;
|
|
45
|
-
selects: Array<string>;
|
|
46
|
-
tables: [{
|
|
47
|
-
table: TTables;
|
|
48
|
-
alias?: string;
|
|
49
|
-
}, ...Array<{
|
|
50
|
-
table: TTables;
|
|
51
|
-
local: string;
|
|
52
|
-
remote: string;
|
|
53
|
-
alias?: string;
|
|
54
|
-
}>];
|
|
55
|
-
limit?: number;
|
|
56
|
-
offset?: number;
|
|
57
|
-
where?: ClauseType;
|
|
58
|
-
having?: ClauseType;
|
|
59
|
-
groupBy?: Array<string>;
|
|
60
|
-
orderBy?: Array<`${string}${"" | " DESC" | " ASC"}`>;
|
|
61
|
-
};
|
|
62
|
-
declare class _fRun<TSources extends TArrSources, TFields extends TFieldsType, TSelectRT extends Record<string, any> = {}> {
|
|
63
|
-
protected db: PrismaClient;
|
|
64
|
-
protected values: Values;
|
|
65
|
-
constructor(db: PrismaClient, values: Values);
|
|
66
|
-
run(): Prisma.PrismaPromise<Array<TSelectRT>>;
|
|
67
|
-
getTables(): TSources;
|
|
68
|
-
getFields(): TFields;
|
|
69
|
-
getResultType(): Array<TSelectRT>;
|
|
70
|
-
getSQL(formatted?: boolean): string;
|
|
71
|
-
}
|
|
72
|
-
declare class _fOffset<TSources extends TArrSources, TFields extends TFieldsType, TSelectRT extends Record<string, any> = {}> extends _fRun<TSources, TFields, TSelectRT> {
|
|
73
|
-
offset(offset: number): _fRun<TSources, TFields, TSelectRT>;
|
|
74
|
-
}
|
|
75
|
-
declare class _fLimit<TSources extends TArrSources, TFields extends TFieldsType, TSelectRT extends Record<string, any> = {}> extends _fRun<TSources, TFields, TSelectRT> {
|
|
76
|
-
limit(limit: number): _fOffset<TSources, TFields, TSelectRT>;
|
|
77
|
-
}
|
|
78
|
-
type OrderBy<Tables extends TArrSources, TSelectRT extends Record<string, any> = {}> = Tables extends [infer T extends TTableSources, ...Array<TTableSources>] ? GetColsBaseTable<T> | GetJoinCols<Tables[number]> | (keyof TSelectRT & string) : never;
|
|
79
|
-
declare class _fOrderBy<TSources extends TArrSources, TFields extends TFieldsType, TSelectRT extends Record<string, any> = {}> extends _fLimit<TSources, TFields, TSelectRT> {
|
|
80
|
-
orderBy(orderBy: Array<`${OrderBy<TSources, TSelectRT>}${"" | " DESC" | " ASC"}`>): _fLimit<TSources, TFields, TSelectRT>;
|
|
81
|
-
}
|
|
82
|
-
type MergeItems<Field extends string, TSources extends TArrSources, TFields extends TFieldsType, IncTName extends boolean = false, TLTables extends string = TablesArray2Name<TSources>[number]> = Field extends "*" ? Prettify<IterateTables<TSources, TFields, IncTName>> : Field extends `${infer T}.*` ? T extends keyof TFields ? [TSources] extends [[T]] ? TFields[T] : T extends string ? IterateTablesFromFields<T, TFields[T], true> : never : never : Field extends `${infer T extends TLTables}.${infer F extends string}` ? T extends keyof TFields ? F extends keyof TFields[T] ? IsColumnUnique<F, TSources> extends true ? Prettify<Pick<TFields[T], F>> : Prettify<{
|
|
83
|
-
[K in Field]: TFields[T][F];
|
|
84
|
-
}> : never : never : FindColumnInFields<Field, TFields>;
|
|
85
|
-
type FindColumnInFields<Column extends string, TFields extends TFieldsType, Tables extends keyof TFields = keyof TFields> = Tables extends keyof TFields ? TFields[Tables] extends Record<Column, any> ? Pick<TFields[Tables], Column> : never : never;
|
|
86
|
-
type IterateTables<Tables extends Array<TTableSources>, TFields extends TFieldsType, IncTName extends boolean, acc extends Record<string, any> = {}> = Tables extends [infer T extends TTableSources, ...infer Rest extends Array<TTableSources>] ? [IncTName] extends [false] ? IterateTables<Rest, TFields, IncTName, acc & TFields[T extends string ? T : T[1]]> : IterateTables<Rest, TFields, IncTName, acc & IterateTablesFromFields<T, TFields[T extends string ? T : T[1]], IncTName>> : acc;
|
|
87
|
-
type GenName<T extends string, F extends unknown, IncName extends boolean> = F extends string ? [IncName] extends [false] ? F : `${T}.${F}` : never;
|
|
88
|
-
type IterateTablesFromFields<Table extends TTableSources, TFields extends Record<string, string>, IncTName extends boolean> = {
|
|
89
|
-
[f in keyof TFields as GenName<Table extends string ? Table : `Come back to 6`, f, IncTName>]: TFields[f];
|
|
90
|
-
};
|
|
91
|
-
type TablesArray2Name<TSources extends Array<TTableSources>, acc extends Array<string> = []> = TSources extends [infer T extends TTableSources, ...infer Rest extends Array<TTableSources>] ? TablesArray2Name<Rest, [...acc, GetAliasTableNames<T>]> : acc;
|
|
92
|
-
type GetColumnNamesFromTable<TDBBase extends TTableSources> = keyof GetFieldsFromTable<GetRealTableNames<TDBBase>>;
|
|
93
|
-
type GetColumnsFromTables<Tables extends Array<TTableSources>> = Tables extends [infer T extends TTableSources, ...infer Rest extends Array<TTableSources>] ? GetColumnNamesFromTable<T> | GetColumnsFromTables<Rest> : never;
|
|
94
|
-
type GetDuplicateColumnsPairwise<Tables extends TArrSources> = Tables extends [infer T1 extends TTableSources, infer T2 extends TTableSources, ...infer Rest extends Array<TTableSources>] ? (GetColumnNamesFromTable<T1> & GetColumnNamesFromTable<T2>) | GetDuplicateColumnsPairwise<[T1, ...Rest]> | GetDuplicateColumnsPairwise<[T2, ...Rest]> : never;
|
|
95
|
-
type IsColumnUnique<Col extends string, Tables extends TArrSources> = Col extends GetDuplicateColumnsPairwise<Tables> ? false : true;
|
|
96
|
-
type GetOtherColumns<Tables extends TArrSources> = Exclude<GetColumnsFromTables<Tables>, GetDuplicateColumnsPairwise<Tables>> | GetJoinCols<Tables[number]>;
|
|
97
|
-
declare class _fSelect<TSources extends TArrSources, TFields extends TFieldsType, TSelectRT extends Record<string, any> = {}> extends _fOrderBy<TSources, TFields, TSelectRT> {
|
|
98
|
-
select<const TSelect extends ValidSelect<TSources>, TAlias extends string = never>(select: TSelect, alias?: TAlias): [TAlias] extends [never] ? _fSelect<TSources, TFields, Prettify<TSelectRT & MergeItems<TSelect, TSources, TFields>>> : _fSelect<TSources, TFields, Prettify<TSelectRT & Record<TAlias, ExtractColumnType<TSelect, TSources, TFields>>>>;
|
|
99
|
-
}
|
|
100
|
-
type CountKeys<T extends Array<TTableSources>, acc extends Array<true> = []> = T extends [string, ...infer R extends Array<string>] ? CountKeys<R, [...acc, true]> : acc["length"];
|
|
101
|
-
declare class _fSelectDistinct<TSources extends TArrSources, TFields extends TFieldsType, TSelectRT extends Record<string, any> = {}> extends _fSelect<TSources, TFields, TSelectRT> {
|
|
102
|
-
selectDistinct(): _fSelect<TSources, TFields, TSelectRT>;
|
|
103
|
-
selectAll<TableCount = CountKeys<TSources>>(): _fOrderBy<TSources, TFields, IterateTables<TSources, TFields, TableCount extends 1 ? false : true, {}> extends infer T ? { [K in keyof T]: IterateTables<TSources, TFields, TableCount extends 1 ? false : true, {}>[K]; } : never>;
|
|
104
|
-
}
|
|
105
|
-
declare class _fHaving<TSources extends TArrSources, TFields extends TFieldsType> extends _fSelectDistinct<TSources, TFields> {
|
|
106
|
-
having<const TCriteria extends WhereCriteria<TSources, TFields>>(criteria: TCriteria): _fSelectDistinct<TSources, TFields, {}>;
|
|
107
|
-
}
|
|
108
|
-
declare class _fGroupBy<TSources extends TArrSources, TFields extends TFieldsType> extends _fHaving<TSources, TFields> {
|
|
109
|
-
groupBy<TSelect extends GetOtherColumns<TSources>>(groupBy: Array<TSelect>): _fHaving<TSources, TFields>;
|
|
110
|
-
}
|
|
111
|
-
type OptionalRecord<K extends PropertyKey, V> = {
|
|
112
|
-
[key in K]?: V;
|
|
113
|
-
};
|
|
114
|
-
type OptionalObject<K extends Record<PropertyKey, unknown>> = {
|
|
115
|
-
[key in keyof K]?: K[key];
|
|
116
|
-
};
|
|
117
|
-
type COND_NUMERIC<key extends PropertyKey, keyType> = OptionalRecord<key, keyType> | OptionalRecord<key, {
|
|
118
|
-
op: 'IN' | 'NOT IN';
|
|
119
|
-
values: Array<keyType>;
|
|
120
|
-
}> | OptionalRecord<key, {
|
|
121
|
-
op: 'BETWEEN';
|
|
122
|
-
values: [keyType, keyType];
|
|
123
|
-
}> | OptionalRecord<key, {
|
|
124
|
-
op: '>' | '>=' | '<' | '<=' | '!=';
|
|
125
|
-
value: keyType;
|
|
126
|
-
}>;
|
|
127
|
-
type COND_STRING<key extends PropertyKey> = OptionalRecord<key, string> | OptionalRecord<key, {
|
|
128
|
-
op: 'IN' | 'NOT IN';
|
|
129
|
-
values: Array<string>;
|
|
130
|
-
}> | OptionalRecord<key, {
|
|
131
|
-
op: 'LIKE' | 'NOT LIKE';
|
|
132
|
-
value: string;
|
|
133
|
-
}> | OptionalRecord<key, {
|
|
134
|
-
op: '!=';
|
|
135
|
-
value: string;
|
|
136
|
-
}>;
|
|
137
|
-
type COND_DATETIME<key extends PropertyKey, keyType> = OptionalRecord<key, keyType> | OptionalRecord<key, {
|
|
138
|
-
op: 'IN' | 'NOT IN';
|
|
139
|
-
values: Array<keyType>;
|
|
140
|
-
}> | OptionalRecord<key, {
|
|
141
|
-
op: 'BETWEEN';
|
|
142
|
-
values: [keyType, keyType];
|
|
143
|
-
}> | OptionalRecord<key, {
|
|
144
|
-
op: '>' | '>=' | '<' | '<=' | '!=';
|
|
145
|
-
value: keyType;
|
|
146
|
-
}>;
|
|
147
|
-
type COND_BOOLEAN<key extends PropertyKey, keyType> = OptionalRecord<key, keyType> | OptionalRecord<key, {
|
|
148
|
-
op: '!=';
|
|
149
|
-
value: keyType;
|
|
150
|
-
}>;
|
|
151
|
-
type COND_NULL<key extends PropertyKey, keyType> = keyType extends null ? OptionalRecord<key, {
|
|
152
|
-
op: 'IS NULL' | 'IS NOT NULL';
|
|
153
|
-
}> : never;
|
|
154
|
-
type SQLCondition<T> = Prettify<{
|
|
155
|
-
[K in keyof T]?: (Exclude<T[K], null> extends number ? COND_NUMERIC<K, Exclude<T[K], null>> : Exclude<T[K], null> extends bigint ? COND_NUMERIC<K, Exclude<T[K], null>> : Exclude<T[K], null> extends string ? COND_STRING<K> : Exclude<T[K], null> extends boolean ? COND_BOOLEAN<K, Exclude<T[K], null>> : Exclude<T[K], null> extends Date ? COND_DATETIME<K, Exclude<T[K], null>> : "Unsupported Data Type") | COND_NULL<K, T[K]>;
|
|
156
|
-
}[keyof T]>;
|
|
157
|
-
type TableFieldType<Table extends string, Fields extends Record<string, any>> = {
|
|
158
|
-
[f in keyof Fields as CombineToString<f, Table>]: Fields[f];
|
|
159
|
-
};
|
|
160
|
-
type LogicalOperator = '$AND' | '$OR' | '$NOT' | "$NOR";
|
|
161
|
-
type WhereCriteria<T extends TArrSources, TFields extends TFieldsType, F = WhereCriteria_Fields<T, TFields>> = F & {
|
|
162
|
-
[k in LogicalOperator]?: [WhereCriteria<T, TFields, F>, ...Array<WhereCriteria<T, TFields, F>>];
|
|
163
|
-
};
|
|
164
|
-
type WhereCriteria_Fields<T extends Array<TTableSources>, TFields extends TFieldsType, acc = {}> = T extends readonly [infer HEAD, ...infer Rest] ? HEAD extends string ? Rest extends Array<TTableSources> ? WhereCriteria_Fields<Rest, TFields, OptionalObject<acc & (TableFieldType<HEAD, TFields[HEAD]> | SQLCondition<TableFieldType<HEAD, TFields[HEAD]>>)>> : WhereCriteria_Fields<[], TFields, OptionalObject<acc & (TableFieldType<HEAD, TFields[HEAD]> | SQLCondition<TableFieldType<HEAD, TFields[HEAD]>>)>> : HEAD extends [infer R_NAME extends string, infer A_NAME extends string] ? Rest extends Array<TTableSources> ? WhereCriteria_Fields<Rest, TFields, OptionalObject<acc & (TableFieldType<A_NAME, TFields[R_NAME]> | SQLCondition<TableFieldType<A_NAME, TFields[R_NAME]>>)>> : WhereCriteria_Fields<[], TFields, OptionalObject<acc & (TableFieldType<A_NAME, TFields[R_NAME]> | SQLCondition<TableFieldType<A_NAME, TFields[R_NAME]>>)>> : never : acc;
|
|
165
|
-
type OnlyNull<T, R> = T extends null ? R : never;
|
|
166
|
-
type FindColsWithNull<TFields extends TFieldsType> = Prettify<{
|
|
167
|
-
[Table in keyof TFields]: {
|
|
168
|
-
[Field in keyof TFields[Table]]: OnlyNull<TFields[Table][Field], CombineToString<Field, Table>>;
|
|
169
|
-
}[keyof TFields[Table]];
|
|
170
|
-
}[keyof TFields]>;
|
|
171
|
-
type NO_START_WITH_WHERE<RAW extends string> = Uppercase<TRIM<RAW>> extends `WHERE ${string}` ? "Please do not start with `WHERE`" : RAW;
|
|
172
|
-
type TRIM<S extends string> = S extends ` ${infer S2}` ? TRIM<S2> : S;
|
|
173
|
-
declare class _fWhere<TSources extends TArrSources, TFields extends TFieldsType> extends _fGroupBy<TSources, TFields> {
|
|
174
|
-
whereNotNull<const TColWithNull extends FindColsWithNull<TFields>>(col: TColWithNull): _fWhere<TSources, TColWithNull extends `${infer table}.${infer col}` ? Omit<TFields, table> & (Record<table, Omit<Pick<TFields, table>[table], col> & Record<col, Exclude<Pick<TFields, table>[table][col], null>>> extends infer T_1 ? { [K_1 in keyof T_1]: Record<table, Omit<Pick<TFields, table>[table], col> & Record<col, Exclude<Pick<TFields, table>[table][col], null>>>[K_1]; } : never) extends infer T ? { [K in keyof T]: (Omit<TFields, table> & (Record<table, Omit<Pick<TFields, table>[table], col> & Record<col, Exclude<Pick<TFields, table>[table][col], null>>> extends infer T_1 ? { [K_1 in keyof T_1]: Record<table, Omit<Pick<TFields, table>[table], col> & Record<col, Exclude<Pick<TFields, table>[table][col], null>>>[K_1]; } : never))[K]; } : never : never>;
|
|
175
|
-
whereIsNull<const TColWithNull extends FindColsWithNull<TFields>>(col: TColWithNull): _fWhere<TSources, TColWithNull extends `${infer table}.${infer col}` ? Omit<TFields, table> & (Record<table, Omit<Pick<TFields, table>[table], col> & Record<col, null>> extends infer T_1 ? { [K_1 in keyof T_1]: Record<table, Omit<Pick<TFields, table>[table], col> & Record<col, null>>[K_1]; } : never) extends infer T ? { [K in keyof T]: (Omit<TFields, table> & (Record<table, Omit<Pick<TFields, table>[table], col> & Record<col, null>> extends infer T_1 ? { [K_1 in keyof T_1]: Record<table, Omit<Pick<TFields, table>[table], col> & Record<col, null>>[K_1]; } : never))[K]; } : never : never>;
|
|
176
|
-
where<const TCriteria extends WhereCriteria<TSources, TFields>>(criteria: TCriteria): _fGroupBy<TSources, TFields>;
|
|
177
|
-
whereRaw<RAW extends string>(where: NO_START_WITH_WHERE<RAW>): _fGroupBy<TSources, TFields>;
|
|
178
|
-
}
|
|
179
|
-
type GetFieldsFromTable<TDBBase extends TTableSources> = Extract<DATABASE, {
|
|
180
|
-
table: GetRealTableNames<TDBBase>;
|
|
181
|
-
}>["fields"];
|
|
182
|
-
type GetColsBaseTable<TDBBase extends TTableSources> = TDBBase extends string ? keyof GetFieldsFromTable<TDBBase> : keyof GetFieldsFromTable<TDBBase[0]>;
|
|
183
|
-
type GetJoinCols<TDBBase extends TTableSources> = TDBBase extends string ? IterateFields<TDBBase, IsString<GetColsBaseTable<TDBBase>>> : IterateFields<TDBBase[1], IsString<GetColsBaseTable<TDBBase[0]>>>;
|
|
184
|
-
type IterateFields<TDBBase extends TTableSources, F extends string> = `${TDBBase extends string ? TDBBase : TDBBase[1]}.${F}`;
|
|
185
|
-
type Relations<Table extends TTableSources> = Extract<DATABASE, {
|
|
186
|
-
table: GetRealTableNames<Table>;
|
|
187
|
-
}>["relations"];
|
|
188
|
-
type AvailableJoins<Tables extends Array<TTableSources>, acc extends TTableSources = never> = Tables extends [infer T extends TTableSources, ...infer Rest extends Array<TTableSources>] ? AvailableJoins<Rest, acc | keyof Relations<T>> : acc;
|
|
189
|
-
type GetRealTableNames<Tables extends TTableSources> = Tables extends any ? Tables extends string ? Tables : Tables[0] : never;
|
|
190
|
-
type GetAliasTableNames<Tables extends TTableSources> = Tables extends any ? Tables extends string ? Tables : Tables[1] : never;
|
|
191
|
-
type SafeJoins<TNewJoin extends TTables, TJoins extends TArrSources, TRelations = Relations<TNewJoin>> = {
|
|
192
|
-
[k in keyof TRelations as Filter<k, GetRealTableNames<TJoins[number]>>]: TRelations[k];
|
|
193
|
-
};
|
|
194
|
-
type ToUnion<TJoins extends TArrSources> = TJoins[number];
|
|
195
|
-
type MapJoinsToKnownTables<TSafeJoins extends Record<string, unknown>, TJoins extends TArrSources> = {
|
|
196
|
-
[k in ToUnion<TJoins> as GetAliasTableNames<k>]: TSafeJoins[GetRealTableNames<k>];
|
|
197
|
-
};
|
|
198
|
-
type CombineToString<A extends unknown, T extends unknown> = A extends string ? T extends string ? `${T}.${A}` : never : never;
|
|
199
|
-
type GetUnionOfRelations<TSafe> = {
|
|
200
|
-
[T in keyof TSafe]: {
|
|
201
|
-
[TLocal in keyof TSafe[T]]: [
|
|
202
|
-
TLocal,
|
|
203
|
-
T extends string ? TSafe[T][TLocal] extends Array<string> ? CombineToString<TSafe[T][TLocal][number], T> : never : never
|
|
204
|
-
];
|
|
205
|
-
}[keyof TSafe[T]];
|
|
206
|
-
}[keyof TSafe];
|
|
207
|
-
type ValidStringTuple<T> = T extends [string, string] ? T : never;
|
|
208
|
-
type find<TJoinCols extends [string, string], toFind extends string> = TJoinCols extends [infer col1, infer col2] ? col1 extends toFind ? col2 : never : never;
|
|
209
|
-
type RemoveNullable<T extends string> = T extends `?${infer R}` ? R : T;
|
|
210
|
-
type SwapKeysAndValues<T extends Record<string, any>> = {
|
|
211
|
-
[K in keyof T as RemoveNullable<T[K]>]: K;
|
|
212
|
-
};
|
|
213
|
-
type Prettify<T> = {
|
|
214
|
-
[K in keyof T]: T[K];
|
|
215
|
-
} & {};
|
|
216
|
-
type ExtractTableName<T extends string> = T extends `${infer Table} ${string}` ? Table : T;
|
|
217
|
-
type ExtractAlias<T extends string> = T extends `${string} ${infer Alias}` ? Alias : never;
|
|
218
|
-
type FieldsByTableByType = Prettify<{
|
|
219
|
-
[Table in TTables]: SwapKeysAndValues<_db[Table]["fields"]>;
|
|
220
|
-
}>;
|
|
221
|
-
type GetTypes = {
|
|
222
|
-
[Type in keyof FieldsByTableByType as keyof FieldsByTableByType[Type]]: {};
|
|
223
|
-
};
|
|
224
|
-
type FieldsByTypeByTable = Prettify<{
|
|
225
|
-
[Type in keyof GetTypes]: {
|
|
226
|
-
[Table in keyof FieldsByTableByType as [FieldsByTableByType[Table][Filter<keyof FieldsByTableByType[Table], Type>]] extends [never] ? never : Table]: FieldsByTableByType[Table][Filter<keyof FieldsByTableByType[Table], Type>];
|
|
227
|
-
};
|
|
228
|
-
}>;
|
|
229
|
-
type GetColumnType<Table extends TTableSources, Col1 extends keyof _db[Table extends string ? Table : `Come back to 8`]["fields"]> = RemoveNullChar<IsString<_db[Table extends string ? Table : `Come back to 9`]["fields"][Col1]>>;
|
|
230
|
-
type GetJoinOnColsType<Type extends string, TSources extends TArrSources> = GetJoinColsType<TSources[number], Type>;
|
|
231
|
-
type GetColsFromTableType<TDBBase extends TTableSources, Type extends string> = FieldsByTypeByTable[Loop<keyof FieldsByTypeByTable, Type>][GetRealTableNames<TDBBase>];
|
|
232
|
-
type Loop<Keys extends string, Type extends string> = Keys extends Type ? Type : never;
|
|
233
|
-
type GetJoinColsType<TDBBase extends TTableSources, Type extends string> = IterateFields<TDBBase, IsString<GetColsFromTableType<TDBBase, Type>>>;
|
|
234
|
-
type TFieldsType = Record<string, Record<string, any>>;
|
|
235
|
-
declare class _fJoin<TSources extends TArrSources, TFields extends TFieldsType> extends _fWhere<TSources, TFields> {
|
|
236
|
-
join<const Table extends AvailableJoins<TSources>, TJoinCols extends [string, string] = ValidStringTuple<GetUnionOfRelations<MapJoinsToKnownTables<SafeJoins<Table, TSources>, TSources>>>, TCol1 extends TJoinCols[0] = never, TAlias extends string = never>(options: {
|
|
237
|
-
table: Table;
|
|
238
|
-
src: TCol1;
|
|
239
|
-
on: find<TJoinCols, TCol1>;
|
|
240
|
-
alias?: TAlias;
|
|
241
|
-
}): _fJoin<[...TSources, [TAlias] extends [undefined] ? Table : [Table, TAlias]], Prettify<TFields & Record<[TAlias] extends [undefined] ? Table : TAlias, GetFieldsFromTable<Table>>>>;
|
|
242
|
-
join<const TableInput extends `${AvailableJoins<TSources>}` | `${AvailableJoins<TSources>} ${string}`, Table extends AvailableJoins<TSources> = ExtractTableName<TableInput> & AvailableJoins<TSources>, TAlias extends string | never = ExtractAlias<TableInput>, TJoinCols extends [string, string] = ValidStringTuple<GetUnionOfRelations<MapJoinsToKnownTables<SafeJoins<Table, TSources>, TSources>>>, TCol1 extends TJoinCols[0] = never>(table: TableInput, field: TCol1, reference: find<TJoinCols, TCol1>): _fJoin<[...TSources, [TAlias] extends [never] ? Table : [Table, TAlias]], Prettify<TFields & Record<[TAlias] extends [never] ? Table : TAlias, GetFieldsFromTable<Table>>>>;
|
|
243
|
-
joinUnsafeTypeEnforced<const Table extends AvailableJoins<TSources>, TCol1 extends GetColsBaseTable<Table>, TCol2 extends GetJoinOnColsType<GetColumnType<Table, TCol1>, [...TSources, Table]>, TAlias extends string = never>(options: {
|
|
244
|
-
table: Table;
|
|
245
|
-
src: TCol1;
|
|
246
|
-
on: TCol2;
|
|
247
|
-
alias?: TAlias;
|
|
248
|
-
}): _fJoin<[...TSources, [TAlias] extends [undefined] ? Table : [Table, TAlias]], Prettify<TFields & Record<[TAlias] extends [undefined] ? Table : TAlias, GetFieldsFromTable<Table>>>>;
|
|
249
|
-
joinUnsafeTypeEnforced<const TableInput extends `${AvailableJoins<TSources>}` | `${AvailableJoins<TSources>} ${string}`, Table extends AvailableJoins<TSources> = ExtractTableName<TableInput> & AvailableJoins<TSources>, TAlias extends string | never = ExtractAlias<TableInput>, TCol1 extends GetColsBaseTable<Table> = GetColsBaseTable<Table>, TCol2 extends GetJoinOnColsType<GetColumnType<Table, TCol1>, [...TSources, Table]> = GetJoinOnColsType<GetColumnType<Table, TCol1>, [...TSources, Table]>>(table: TableInput, field: TCol1, reference: TCol2): _fJoin<[...TSources, [TAlias] extends [never] ? Table : [Table, TAlias]], Prettify<TFields & Record<[TAlias] extends [undefined] ? Table : TAlias, GetFieldsFromTable<Table>>>>;
|
|
250
|
-
joinUnsafeIgnoreType<const Table extends AvailableJoins<TSources>, TCol1 extends GetColsBaseTable<Table>, TCol2 extends GetJoinCols<TSources[number]>, TAlias extends string = never>(options: {
|
|
251
|
-
table: Table;
|
|
252
|
-
src: TCol1;
|
|
253
|
-
on: TCol2;
|
|
254
|
-
alias?: TAlias;
|
|
255
|
-
}): _fJoin<[...TSources, [TAlias] extends [never] ? Table : [Table, TAlias]], TFields & Record<Table, GetFieldsFromTable<Table>>>;
|
|
256
|
-
joinUnsafeIgnoreType<const TableInput extends `${AvailableJoins<TSources>}` | `${AvailableJoins<TSources>} ${string}`, Table extends AvailableJoins<TSources> = ExtractTableName<TableInput> & AvailableJoins<TSources>, TAlias extends string | never = ExtractAlias<TableInput>, TCol1 extends GetColsBaseTable<Table> = GetColsBaseTable<Table>, TCol2 extends GetJoinCols<TSources[number]> = GetJoinCols<TSources[number]>>(table: TableInput, field: TCol1, reference: TCol2): _fJoin<[...TSources, [TAlias] extends [never] ? Table : [Table, TAlias]], TFields & Record<Table, GetFieldsFromTable<Table>>>;
|
|
257
|
-
}
|
|
258
|
-
declare const _default: {
|
|
259
|
-
client: {
|
|
260
|
-
$from<const T extends TTables | `${TTables} ${string}`, Table extends TTables = ExtractTableName<T>, TAlias extends string | never = ExtractAlias<T>>(table: T): _fJoin<[TAlias] extends [never] ? [Table] : [[Table, TAlias]], Record<GetAliasTableNames<([TAlias] extends [never] ? [Table] : [[Table, TAlias]])[0]>, GetFieldsFromTable<Table>>>;
|
|
261
|
-
};
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
export { type DBType, type GetUnionOfRelations, type JSONArray, type JSONObject, type JSONPrimitive, type JSONValue, type MapJoinsToKnownTables, type RemoveNullChar, type SafeJoins, type TTableSources, type TTables, _default as default };
|