tempest.games 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/CHANGELOG.md +6 -0
- package/bin/backend.bun.js +1 -1
- package/bin/backend.worker.tribunal.bun.js +38 -0
- package/bin/setup-db.bun.js +3195 -8
- package/drizzle/0000_fine_hardball.sql +33 -0
- package/drizzle/0001_public_greymalkin.sql +101 -0
- package/drizzle/0002_loud_stature.sql +33 -0
- package/drizzle/0003_lyrical_malice.sql +2 -0
- package/drizzle/0004_funny_tana_nile.sql +1 -0
- package/drizzle/0005_reflective_warstar.sql +1 -0
- package/drizzle/0006_mushy_young_avengers.sql +2 -0
- package/drizzle/0007_charming_strong_guy.sql +8 -0
- package/drizzle/meta/0000_snapshot.json +168 -0
- package/drizzle/meta/0001_snapshot.json +471 -0
- package/drizzle/meta/0002_snapshot.json +471 -0
- package/drizzle/meta/0003_snapshot.json +471 -0
- package/drizzle/meta/0004_snapshot.json +465 -0
- package/drizzle/meta/0005_snapshot.json +465 -0
- package/drizzle/meta/0006_snapshot.json +465 -0
- package/drizzle/meta/0007_snapshot.json +465 -0
- package/drizzle/meta/_journal.json +62 -0
- package/package.json +6 -5
- package/__scripts__/destroy-db.bun.ts +0 -29
- package/__scripts__/setup-db.bun.ts +0 -57
- package/__scripts__/setup.vitest.ts +0 -5
package/bin/setup-db.bun.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
// __scripts__/setup-db.bun.ts
|
|
5
5
|
import * as os2 from "os";
|
|
6
|
+
import { resolve } from "path";
|
|
6
7
|
|
|
7
8
|
// /home/runner/work/wayforge/wayforge/apps/tempest.games/node_modules/postgres/src/index.js
|
|
8
9
|
import os from "os";
|
|
@@ -1954,6 +1955,3172 @@ Object.assign(Postgres, {
|
|
|
1954
1955
|
});
|
|
1955
1956
|
var src_default = Postgres;
|
|
1956
1957
|
|
|
1958
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/entity.js
|
|
1959
|
+
function is(value, type) {
|
|
1960
|
+
if (!value || typeof value !== "object") {
|
|
1961
|
+
return false;
|
|
1962
|
+
}
|
|
1963
|
+
if (value instanceof type) {
|
|
1964
|
+
return true;
|
|
1965
|
+
}
|
|
1966
|
+
if (!Object.prototype.hasOwnProperty.call(type, entityKind)) {
|
|
1967
|
+
throw new Error(`Class "${type.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`);
|
|
1968
|
+
}
|
|
1969
|
+
let cls = Object.getPrototypeOf(value).constructor;
|
|
1970
|
+
if (cls) {
|
|
1971
|
+
while (cls) {
|
|
1972
|
+
if (entityKind in cls && cls[entityKind] === type[entityKind]) {
|
|
1973
|
+
return true;
|
|
1974
|
+
}
|
|
1975
|
+
cls = Object.getPrototypeOf(cls);
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
return false;
|
|
1979
|
+
}
|
|
1980
|
+
var entityKind = Symbol.for("drizzle:entityKind");
|
|
1981
|
+
var hasOwnEntityKind = Symbol.for("drizzle:hasOwnEntityKind");
|
|
1982
|
+
|
|
1983
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/logger.js
|
|
1984
|
+
class ConsoleLogWriter {
|
|
1985
|
+
static [entityKind] = "ConsoleLogWriter";
|
|
1986
|
+
write(message) {
|
|
1987
|
+
console.log(message);
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
class DefaultLogger {
|
|
1992
|
+
static [entityKind] = "DefaultLogger";
|
|
1993
|
+
writer;
|
|
1994
|
+
constructor(config) {
|
|
1995
|
+
this.writer = config?.writer ?? new ConsoleLogWriter;
|
|
1996
|
+
}
|
|
1997
|
+
logQuery(query, params) {
|
|
1998
|
+
const stringifiedParams = params.map((p) => {
|
|
1999
|
+
try {
|
|
2000
|
+
return JSON.stringify(p);
|
|
2001
|
+
} catch {
|
|
2002
|
+
return String(p);
|
|
2003
|
+
}
|
|
2004
|
+
});
|
|
2005
|
+
const paramsStr = stringifiedParams.length ? ` -- params: [${stringifiedParams.join(", ")}]` : "";
|
|
2006
|
+
this.writer.write(`Query: ${query}${paramsStr}`);
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
class NoopLogger {
|
|
2011
|
+
static [entityKind] = "NoopLogger";
|
|
2012
|
+
logQuery() {
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/query-promise.js
|
|
2017
|
+
class QueryPromise {
|
|
2018
|
+
static [entityKind] = "QueryPromise";
|
|
2019
|
+
[Symbol.toStringTag] = "QueryPromise";
|
|
2020
|
+
catch(onRejected) {
|
|
2021
|
+
return this.then(undefined, onRejected);
|
|
2022
|
+
}
|
|
2023
|
+
finally(onFinally) {
|
|
2024
|
+
return this.then((value) => {
|
|
2025
|
+
onFinally?.();
|
|
2026
|
+
return value;
|
|
2027
|
+
}, (reason) => {
|
|
2028
|
+
onFinally?.();
|
|
2029
|
+
throw reason;
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2032
|
+
then(onFulfilled, onRejected) {
|
|
2033
|
+
return this.execute().then(onFulfilled, onRejected);
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/table.utils.js
|
|
2038
|
+
var TableName = Symbol.for("drizzle:Name");
|
|
2039
|
+
|
|
2040
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/table.js
|
|
2041
|
+
function getTableName(table) {
|
|
2042
|
+
return table[TableName];
|
|
2043
|
+
}
|
|
2044
|
+
function getTableUniqueName(table) {
|
|
2045
|
+
return `${table[Schema] ?? "public"}.${table[TableName]}`;
|
|
2046
|
+
}
|
|
2047
|
+
var Schema = Symbol.for("drizzle:Schema");
|
|
2048
|
+
var Columns = Symbol.for("drizzle:Columns");
|
|
2049
|
+
var ExtraConfigColumns = Symbol.for("drizzle:ExtraConfigColumns");
|
|
2050
|
+
var OriginalName = Symbol.for("drizzle:OriginalName");
|
|
2051
|
+
var BaseName = Symbol.for("drizzle:BaseName");
|
|
2052
|
+
var IsAlias = Symbol.for("drizzle:IsAlias");
|
|
2053
|
+
var ExtraConfigBuilder = Symbol.for("drizzle:ExtraConfigBuilder");
|
|
2054
|
+
var IsDrizzleTable = Symbol.for("drizzle:IsDrizzleTable");
|
|
2055
|
+
|
|
2056
|
+
class Table {
|
|
2057
|
+
static [entityKind] = "Table";
|
|
2058
|
+
static Symbol = {
|
|
2059
|
+
Name: TableName,
|
|
2060
|
+
Schema,
|
|
2061
|
+
OriginalName,
|
|
2062
|
+
Columns,
|
|
2063
|
+
ExtraConfigColumns,
|
|
2064
|
+
BaseName,
|
|
2065
|
+
IsAlias,
|
|
2066
|
+
ExtraConfigBuilder
|
|
2067
|
+
};
|
|
2068
|
+
[TableName];
|
|
2069
|
+
[OriginalName];
|
|
2070
|
+
[Schema];
|
|
2071
|
+
[Columns];
|
|
2072
|
+
[ExtraConfigColumns];
|
|
2073
|
+
[BaseName];
|
|
2074
|
+
[IsAlias] = false;
|
|
2075
|
+
[IsDrizzleTable] = true;
|
|
2076
|
+
[ExtraConfigBuilder] = undefined;
|
|
2077
|
+
constructor(name, schema, baseName) {
|
|
2078
|
+
this[TableName] = this[OriginalName] = name;
|
|
2079
|
+
this[Schema] = schema;
|
|
2080
|
+
this[BaseName] = baseName;
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/tracing-utils.js
|
|
2085
|
+
function iife(fn, ...args) {
|
|
2086
|
+
return fn(...args);
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/version.js
|
|
2090
|
+
var version = "0.35.1";
|
|
2091
|
+
|
|
2092
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/tracing.js
|
|
2093
|
+
var otel;
|
|
2094
|
+
var rawTracer;
|
|
2095
|
+
var tracer = {
|
|
2096
|
+
startActiveSpan(name, fn) {
|
|
2097
|
+
if (!otel) {
|
|
2098
|
+
return fn();
|
|
2099
|
+
}
|
|
2100
|
+
if (!rawTracer) {
|
|
2101
|
+
rawTracer = otel.trace.getTracer("drizzle-orm", version);
|
|
2102
|
+
}
|
|
2103
|
+
return iife((otel2, rawTracer2) => rawTracer2.startActiveSpan(name, (span) => {
|
|
2104
|
+
try {
|
|
2105
|
+
return fn(span);
|
|
2106
|
+
} catch (e) {
|
|
2107
|
+
span.setStatus({
|
|
2108
|
+
code: otel2.SpanStatusCode.ERROR,
|
|
2109
|
+
message: e instanceof Error ? e.message : "Unknown error"
|
|
2110
|
+
});
|
|
2111
|
+
throw e;
|
|
2112
|
+
} finally {
|
|
2113
|
+
span.end();
|
|
2114
|
+
}
|
|
2115
|
+
}), otel, rawTracer);
|
|
2116
|
+
}
|
|
2117
|
+
};
|
|
2118
|
+
|
|
2119
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/column.js
|
|
2120
|
+
class Column {
|
|
2121
|
+
constructor(table, config) {
|
|
2122
|
+
this.table = table;
|
|
2123
|
+
this.config = config;
|
|
2124
|
+
this.name = config.name;
|
|
2125
|
+
this.keyAsName = config.keyAsName;
|
|
2126
|
+
this.notNull = config.notNull;
|
|
2127
|
+
this.default = config.default;
|
|
2128
|
+
this.defaultFn = config.defaultFn;
|
|
2129
|
+
this.onUpdateFn = config.onUpdateFn;
|
|
2130
|
+
this.hasDefault = config.hasDefault;
|
|
2131
|
+
this.primary = config.primaryKey;
|
|
2132
|
+
this.isUnique = config.isUnique;
|
|
2133
|
+
this.uniqueName = config.uniqueName;
|
|
2134
|
+
this.uniqueType = config.uniqueType;
|
|
2135
|
+
this.dataType = config.dataType;
|
|
2136
|
+
this.columnType = config.columnType;
|
|
2137
|
+
this.generated = config.generated;
|
|
2138
|
+
this.generatedIdentity = config.generatedIdentity;
|
|
2139
|
+
}
|
|
2140
|
+
static [entityKind] = "Column";
|
|
2141
|
+
name;
|
|
2142
|
+
keyAsName;
|
|
2143
|
+
primary;
|
|
2144
|
+
notNull;
|
|
2145
|
+
default;
|
|
2146
|
+
defaultFn;
|
|
2147
|
+
onUpdateFn;
|
|
2148
|
+
hasDefault;
|
|
2149
|
+
isUnique;
|
|
2150
|
+
uniqueName;
|
|
2151
|
+
uniqueType;
|
|
2152
|
+
dataType;
|
|
2153
|
+
columnType;
|
|
2154
|
+
enumValues = undefined;
|
|
2155
|
+
generated = undefined;
|
|
2156
|
+
generatedIdentity = undefined;
|
|
2157
|
+
config;
|
|
2158
|
+
mapFromDriverValue(value) {
|
|
2159
|
+
return value;
|
|
2160
|
+
}
|
|
2161
|
+
mapToDriverValue(value) {
|
|
2162
|
+
return value;
|
|
2163
|
+
}
|
|
2164
|
+
shouldDisableInsert() {
|
|
2165
|
+
return this.config.generated !== undefined && this.config.generated.type !== "byDefault";
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/unique-constraint.js
|
|
2170
|
+
function uniqueKeyName(table, columns) {
|
|
2171
|
+
return `${table[TableName]}_${columns.join("_")}_unique`;
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2174
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/columns/common.js
|
|
2175
|
+
class PgColumn extends Column {
|
|
2176
|
+
constructor(table, config) {
|
|
2177
|
+
if (!config.uniqueName) {
|
|
2178
|
+
config.uniqueName = uniqueKeyName(table, [config.name]);
|
|
2179
|
+
}
|
|
2180
|
+
super(table, config);
|
|
2181
|
+
this.table = table;
|
|
2182
|
+
}
|
|
2183
|
+
static [entityKind] = "PgColumn";
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2186
|
+
class ExtraConfigColumn extends PgColumn {
|
|
2187
|
+
static [entityKind] = "ExtraConfigColumn";
|
|
2188
|
+
getSQLType() {
|
|
2189
|
+
return this.getSQLType();
|
|
2190
|
+
}
|
|
2191
|
+
indexConfig = {
|
|
2192
|
+
order: this.config.order ?? "asc",
|
|
2193
|
+
nulls: this.config.nulls ?? "last",
|
|
2194
|
+
opClass: this.config.opClass
|
|
2195
|
+
};
|
|
2196
|
+
defaultConfig = {
|
|
2197
|
+
order: "asc",
|
|
2198
|
+
nulls: "last",
|
|
2199
|
+
opClass: undefined
|
|
2200
|
+
};
|
|
2201
|
+
asc() {
|
|
2202
|
+
this.indexConfig.order = "asc";
|
|
2203
|
+
return this;
|
|
2204
|
+
}
|
|
2205
|
+
desc() {
|
|
2206
|
+
this.indexConfig.order = "desc";
|
|
2207
|
+
return this;
|
|
2208
|
+
}
|
|
2209
|
+
nullsFirst() {
|
|
2210
|
+
this.indexConfig.nulls = "first";
|
|
2211
|
+
return this;
|
|
2212
|
+
}
|
|
2213
|
+
nullsLast() {
|
|
2214
|
+
this.indexConfig.nulls = "last";
|
|
2215
|
+
return this;
|
|
2216
|
+
}
|
|
2217
|
+
op(opClass) {
|
|
2218
|
+
this.indexConfig.opClass = opClass;
|
|
2219
|
+
return this;
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/columns/enum.js
|
|
2224
|
+
function isPgEnum(obj) {
|
|
2225
|
+
return !!obj && typeof obj === "function" && isPgEnumSym in obj && obj[isPgEnumSym] === true;
|
|
2226
|
+
}
|
|
2227
|
+
var isPgEnumSym = Symbol.for("drizzle:isPgEnum");
|
|
2228
|
+
class PgEnumColumn extends PgColumn {
|
|
2229
|
+
static [entityKind] = "PgEnumColumn";
|
|
2230
|
+
enum = this.config.enum;
|
|
2231
|
+
enumValues = this.config.enum.enumValues;
|
|
2232
|
+
constructor(table, config) {
|
|
2233
|
+
super(table, config);
|
|
2234
|
+
this.enum = config.enum;
|
|
2235
|
+
}
|
|
2236
|
+
getSQLType() {
|
|
2237
|
+
return this.enum.enumName;
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/subquery.js
|
|
2242
|
+
class Subquery {
|
|
2243
|
+
static [entityKind] = "Subquery";
|
|
2244
|
+
constructor(sql, selection, alias, isWith = false) {
|
|
2245
|
+
this._ = {
|
|
2246
|
+
brand: "Subquery",
|
|
2247
|
+
sql,
|
|
2248
|
+
selectedFields: selection,
|
|
2249
|
+
alias,
|
|
2250
|
+
isWith
|
|
2251
|
+
};
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
class WithSubquery extends Subquery {
|
|
2256
|
+
static [entityKind] = "WithSubquery";
|
|
2257
|
+
}
|
|
2258
|
+
|
|
2259
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/view-common.js
|
|
2260
|
+
var ViewBaseConfig = Symbol.for("drizzle:ViewBaseConfig");
|
|
2261
|
+
|
|
2262
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/sql/sql.js
|
|
2263
|
+
function isSQLWrapper(value) {
|
|
2264
|
+
return value !== null && value !== undefined && typeof value.getSQL === "function";
|
|
2265
|
+
}
|
|
2266
|
+
function mergeQueries(queries) {
|
|
2267
|
+
const result = { sql: "", params: [] };
|
|
2268
|
+
for (const query of queries) {
|
|
2269
|
+
result.sql += query.sql;
|
|
2270
|
+
result.params.push(...query.params);
|
|
2271
|
+
if (query.typings?.length) {
|
|
2272
|
+
if (!result.typings) {
|
|
2273
|
+
result.typings = [];
|
|
2274
|
+
}
|
|
2275
|
+
result.typings.push(...query.typings);
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
return result;
|
|
2279
|
+
}
|
|
2280
|
+
function isDriverValueEncoder(value) {
|
|
2281
|
+
return typeof value === "object" && value !== null && "mapToDriverValue" in value && typeof value.mapToDriverValue === "function";
|
|
2282
|
+
}
|
|
2283
|
+
function sql(strings, ...params) {
|
|
2284
|
+
const queryChunks = [];
|
|
2285
|
+
if (params.length > 0 || strings.length > 0 && strings[0] !== "") {
|
|
2286
|
+
queryChunks.push(new StringChunk(strings[0]));
|
|
2287
|
+
}
|
|
2288
|
+
for (const [paramIndex, param2] of params.entries()) {
|
|
2289
|
+
queryChunks.push(param2, new StringChunk(strings[paramIndex + 1]));
|
|
2290
|
+
}
|
|
2291
|
+
return new SQL(queryChunks);
|
|
2292
|
+
}
|
|
2293
|
+
function fillPlaceholders(params, values2) {
|
|
2294
|
+
return params.map((p) => {
|
|
2295
|
+
if (is(p, Placeholder)) {
|
|
2296
|
+
if (!(p.name in values2)) {
|
|
2297
|
+
throw new Error(`No value for placeholder "${p.name}" was provided`);
|
|
2298
|
+
}
|
|
2299
|
+
return values2[p.name];
|
|
2300
|
+
}
|
|
2301
|
+
if (is(p, Param) && is(p.value, Placeholder)) {
|
|
2302
|
+
if (!(p.value.name in values2)) {
|
|
2303
|
+
throw new Error(`No value for placeholder "${p.value.name}" was provided`);
|
|
2304
|
+
}
|
|
2305
|
+
return p.encoder.mapToDriverValue(values2[p.value.name]);
|
|
2306
|
+
}
|
|
2307
|
+
return p;
|
|
2308
|
+
});
|
|
2309
|
+
}
|
|
2310
|
+
class StringChunk {
|
|
2311
|
+
static [entityKind] = "StringChunk";
|
|
2312
|
+
value;
|
|
2313
|
+
constructor(value) {
|
|
2314
|
+
this.value = Array.isArray(value) ? value : [value];
|
|
2315
|
+
}
|
|
2316
|
+
getSQL() {
|
|
2317
|
+
return new SQL([this]);
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
class SQL {
|
|
2322
|
+
constructor(queryChunks) {
|
|
2323
|
+
this.queryChunks = queryChunks;
|
|
2324
|
+
}
|
|
2325
|
+
static [entityKind] = "SQL";
|
|
2326
|
+
decoder = noopDecoder;
|
|
2327
|
+
shouldInlineParams = false;
|
|
2328
|
+
append(query) {
|
|
2329
|
+
this.queryChunks.push(...query.queryChunks);
|
|
2330
|
+
return this;
|
|
2331
|
+
}
|
|
2332
|
+
toQuery(config) {
|
|
2333
|
+
return tracer.startActiveSpan("drizzle.buildSQL", (span) => {
|
|
2334
|
+
const query = this.buildQueryFromSourceParams(this.queryChunks, config);
|
|
2335
|
+
span?.setAttributes({
|
|
2336
|
+
"drizzle.query.text": query.sql,
|
|
2337
|
+
"drizzle.query.params": JSON.stringify(query.params)
|
|
2338
|
+
});
|
|
2339
|
+
return query;
|
|
2340
|
+
});
|
|
2341
|
+
}
|
|
2342
|
+
buildQueryFromSourceParams(chunks, _config) {
|
|
2343
|
+
const config = Object.assign({}, _config, {
|
|
2344
|
+
inlineParams: _config.inlineParams || this.shouldInlineParams,
|
|
2345
|
+
paramStartIndex: _config.paramStartIndex || { value: 0 }
|
|
2346
|
+
});
|
|
2347
|
+
const {
|
|
2348
|
+
casing,
|
|
2349
|
+
escapeName,
|
|
2350
|
+
escapeParam,
|
|
2351
|
+
prepareTyping,
|
|
2352
|
+
inlineParams,
|
|
2353
|
+
paramStartIndex
|
|
2354
|
+
} = config;
|
|
2355
|
+
return mergeQueries(chunks.map((chunk) => {
|
|
2356
|
+
if (is(chunk, StringChunk)) {
|
|
2357
|
+
return { sql: chunk.value.join(""), params: [] };
|
|
2358
|
+
}
|
|
2359
|
+
if (is(chunk, Name)) {
|
|
2360
|
+
return { sql: escapeName(chunk.value), params: [] };
|
|
2361
|
+
}
|
|
2362
|
+
if (chunk === undefined) {
|
|
2363
|
+
return { sql: "", params: [] };
|
|
2364
|
+
}
|
|
2365
|
+
if (Array.isArray(chunk)) {
|
|
2366
|
+
const result = [new StringChunk("(")];
|
|
2367
|
+
for (const [i, p] of chunk.entries()) {
|
|
2368
|
+
result.push(p);
|
|
2369
|
+
if (i < chunk.length - 1) {
|
|
2370
|
+
result.push(new StringChunk(", "));
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
result.push(new StringChunk(")"));
|
|
2374
|
+
return this.buildQueryFromSourceParams(result, config);
|
|
2375
|
+
}
|
|
2376
|
+
if (is(chunk, SQL)) {
|
|
2377
|
+
return this.buildQueryFromSourceParams(chunk.queryChunks, {
|
|
2378
|
+
...config,
|
|
2379
|
+
inlineParams: inlineParams || chunk.shouldInlineParams
|
|
2380
|
+
});
|
|
2381
|
+
}
|
|
2382
|
+
if (is(chunk, Table)) {
|
|
2383
|
+
const schemaName = chunk[Table.Symbol.Schema];
|
|
2384
|
+
const tableName = chunk[Table.Symbol.Name];
|
|
2385
|
+
return {
|
|
2386
|
+
sql: schemaName === undefined ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
|
|
2387
|
+
params: []
|
|
2388
|
+
};
|
|
2389
|
+
}
|
|
2390
|
+
if (is(chunk, Column)) {
|
|
2391
|
+
const columnName = casing.getColumnCasing(chunk);
|
|
2392
|
+
if (_config.invokeSource === "indexes") {
|
|
2393
|
+
return { sql: escapeName(columnName), params: [] };
|
|
2394
|
+
}
|
|
2395
|
+
return { sql: escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName), params: [] };
|
|
2396
|
+
}
|
|
2397
|
+
if (is(chunk, View)) {
|
|
2398
|
+
const schemaName = chunk[ViewBaseConfig].schema;
|
|
2399
|
+
const viewName = chunk[ViewBaseConfig].name;
|
|
2400
|
+
return {
|
|
2401
|
+
sql: schemaName === undefined ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
|
|
2402
|
+
params: []
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2405
|
+
if (is(chunk, Param)) {
|
|
2406
|
+
if (is(chunk.value, Placeholder)) {
|
|
2407
|
+
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
|
|
2408
|
+
}
|
|
2409
|
+
const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
|
|
2410
|
+
if (is(mappedValue, SQL)) {
|
|
2411
|
+
return this.buildQueryFromSourceParams([mappedValue], config);
|
|
2412
|
+
}
|
|
2413
|
+
if (inlineParams) {
|
|
2414
|
+
return { sql: this.mapInlineParam(mappedValue, config), params: [] };
|
|
2415
|
+
}
|
|
2416
|
+
let typings = ["none"];
|
|
2417
|
+
if (prepareTyping) {
|
|
2418
|
+
typings = [prepareTyping(chunk.encoder)];
|
|
2419
|
+
}
|
|
2420
|
+
return { sql: escapeParam(paramStartIndex.value++, mappedValue), params: [mappedValue], typings };
|
|
2421
|
+
}
|
|
2422
|
+
if (is(chunk, Placeholder)) {
|
|
2423
|
+
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
|
|
2424
|
+
}
|
|
2425
|
+
if (is(chunk, SQL.Aliased) && chunk.fieldAlias !== undefined) {
|
|
2426
|
+
return { sql: escapeName(chunk.fieldAlias), params: [] };
|
|
2427
|
+
}
|
|
2428
|
+
if (is(chunk, Subquery)) {
|
|
2429
|
+
if (chunk._.isWith) {
|
|
2430
|
+
return { sql: escapeName(chunk._.alias), params: [] };
|
|
2431
|
+
}
|
|
2432
|
+
return this.buildQueryFromSourceParams([
|
|
2433
|
+
new StringChunk("("),
|
|
2434
|
+
chunk._.sql,
|
|
2435
|
+
new StringChunk(") "),
|
|
2436
|
+
new Name(chunk._.alias)
|
|
2437
|
+
], config);
|
|
2438
|
+
}
|
|
2439
|
+
if (isPgEnum(chunk)) {
|
|
2440
|
+
if (chunk.schema) {
|
|
2441
|
+
return { sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName), params: [] };
|
|
2442
|
+
}
|
|
2443
|
+
return { sql: escapeName(chunk.enumName), params: [] };
|
|
2444
|
+
}
|
|
2445
|
+
if (isSQLWrapper(chunk)) {
|
|
2446
|
+
if (chunk.shouldOmitSQLParens?.()) {
|
|
2447
|
+
return this.buildQueryFromSourceParams([chunk.getSQL()], config);
|
|
2448
|
+
}
|
|
2449
|
+
return this.buildQueryFromSourceParams([
|
|
2450
|
+
new StringChunk("("),
|
|
2451
|
+
chunk.getSQL(),
|
|
2452
|
+
new StringChunk(")")
|
|
2453
|
+
], config);
|
|
2454
|
+
}
|
|
2455
|
+
if (inlineParams) {
|
|
2456
|
+
return { sql: this.mapInlineParam(chunk, config), params: [] };
|
|
2457
|
+
}
|
|
2458
|
+
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
|
|
2459
|
+
}));
|
|
2460
|
+
}
|
|
2461
|
+
mapInlineParam(chunk, { escapeString }) {
|
|
2462
|
+
if (chunk === null) {
|
|
2463
|
+
return "null";
|
|
2464
|
+
}
|
|
2465
|
+
if (typeof chunk === "number" || typeof chunk === "boolean") {
|
|
2466
|
+
return chunk.toString();
|
|
2467
|
+
}
|
|
2468
|
+
if (typeof chunk === "string") {
|
|
2469
|
+
return escapeString(chunk);
|
|
2470
|
+
}
|
|
2471
|
+
if (typeof chunk === "object") {
|
|
2472
|
+
const mappedValueAsString = chunk.toString();
|
|
2473
|
+
if (mappedValueAsString === "[object Object]") {
|
|
2474
|
+
return escapeString(JSON.stringify(chunk));
|
|
2475
|
+
}
|
|
2476
|
+
return escapeString(mappedValueAsString);
|
|
2477
|
+
}
|
|
2478
|
+
throw new Error("Unexpected param value: " + chunk);
|
|
2479
|
+
}
|
|
2480
|
+
getSQL() {
|
|
2481
|
+
return this;
|
|
2482
|
+
}
|
|
2483
|
+
as(alias) {
|
|
2484
|
+
if (alias === undefined) {
|
|
2485
|
+
return this;
|
|
2486
|
+
}
|
|
2487
|
+
return new SQL.Aliased(this, alias);
|
|
2488
|
+
}
|
|
2489
|
+
mapWith(decoder) {
|
|
2490
|
+
this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
|
|
2491
|
+
return this;
|
|
2492
|
+
}
|
|
2493
|
+
inlineParams() {
|
|
2494
|
+
this.shouldInlineParams = true;
|
|
2495
|
+
return this;
|
|
2496
|
+
}
|
|
2497
|
+
if(condition) {
|
|
2498
|
+
return condition ? this : undefined;
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2502
|
+
class Name {
|
|
2503
|
+
constructor(value) {
|
|
2504
|
+
this.value = value;
|
|
2505
|
+
}
|
|
2506
|
+
static [entityKind] = "Name";
|
|
2507
|
+
brand;
|
|
2508
|
+
getSQL() {
|
|
2509
|
+
return new SQL([this]);
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
var noopDecoder = {
|
|
2513
|
+
mapFromDriverValue: (value) => value
|
|
2514
|
+
};
|
|
2515
|
+
var noopEncoder = {
|
|
2516
|
+
mapToDriverValue: (value) => value
|
|
2517
|
+
};
|
|
2518
|
+
var noopMapper = {
|
|
2519
|
+
...noopDecoder,
|
|
2520
|
+
...noopEncoder
|
|
2521
|
+
};
|
|
2522
|
+
|
|
2523
|
+
class Param {
|
|
2524
|
+
constructor(value, encoder = noopEncoder) {
|
|
2525
|
+
this.value = value;
|
|
2526
|
+
this.encoder = encoder;
|
|
2527
|
+
}
|
|
2528
|
+
static [entityKind] = "Param";
|
|
2529
|
+
brand;
|
|
2530
|
+
getSQL() {
|
|
2531
|
+
return new SQL([this]);
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
((sql2) => {
|
|
2535
|
+
function empty() {
|
|
2536
|
+
return new SQL([]);
|
|
2537
|
+
}
|
|
2538
|
+
sql2.empty = empty;
|
|
2539
|
+
function fromList(list) {
|
|
2540
|
+
return new SQL(list);
|
|
2541
|
+
}
|
|
2542
|
+
sql2.fromList = fromList;
|
|
2543
|
+
function raw(str) {
|
|
2544
|
+
return new SQL([new StringChunk(str)]);
|
|
2545
|
+
}
|
|
2546
|
+
sql2.raw = raw;
|
|
2547
|
+
function join(chunks, separator) {
|
|
2548
|
+
const result = [];
|
|
2549
|
+
for (const [i, chunk] of chunks.entries()) {
|
|
2550
|
+
if (i > 0 && separator !== undefined) {
|
|
2551
|
+
result.push(separator);
|
|
2552
|
+
}
|
|
2553
|
+
result.push(chunk);
|
|
2554
|
+
}
|
|
2555
|
+
return new SQL(result);
|
|
2556
|
+
}
|
|
2557
|
+
sql2.join = join;
|
|
2558
|
+
function identifier(value) {
|
|
2559
|
+
return new Name(value);
|
|
2560
|
+
}
|
|
2561
|
+
sql2.identifier = identifier;
|
|
2562
|
+
function placeholder2(name2) {
|
|
2563
|
+
return new Placeholder(name2);
|
|
2564
|
+
}
|
|
2565
|
+
sql2.placeholder = placeholder2;
|
|
2566
|
+
function param2(value, encoder) {
|
|
2567
|
+
return new Param(value, encoder);
|
|
2568
|
+
}
|
|
2569
|
+
sql2.param = param2;
|
|
2570
|
+
})(sql || (sql = {}));
|
|
2571
|
+
((SQL2) => {
|
|
2572
|
+
|
|
2573
|
+
class Aliased {
|
|
2574
|
+
constructor(sql2, fieldAlias) {
|
|
2575
|
+
this.sql = sql2;
|
|
2576
|
+
this.fieldAlias = fieldAlias;
|
|
2577
|
+
}
|
|
2578
|
+
static [entityKind] = "SQL.Aliased";
|
|
2579
|
+
isSelectionField = false;
|
|
2580
|
+
getSQL() {
|
|
2581
|
+
return this.sql;
|
|
2582
|
+
}
|
|
2583
|
+
clone() {
|
|
2584
|
+
return new Aliased(this.sql, this.fieldAlias);
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
SQL2.Aliased = Aliased;
|
|
2588
|
+
})(SQL || (SQL = {}));
|
|
2589
|
+
|
|
2590
|
+
class Placeholder {
|
|
2591
|
+
constructor(name2) {
|
|
2592
|
+
this.name = name2;
|
|
2593
|
+
}
|
|
2594
|
+
static [entityKind] = "Placeholder";
|
|
2595
|
+
getSQL() {
|
|
2596
|
+
return new SQL([this]);
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
|
|
2600
|
+
class View {
|
|
2601
|
+
static [entityKind] = "View";
|
|
2602
|
+
[ViewBaseConfig];
|
|
2603
|
+
constructor({ name: name2, schema, selectedFields, query }) {
|
|
2604
|
+
this[ViewBaseConfig] = {
|
|
2605
|
+
name: name2,
|
|
2606
|
+
originalName: name2,
|
|
2607
|
+
schema,
|
|
2608
|
+
selectedFields,
|
|
2609
|
+
query,
|
|
2610
|
+
isExisting: !query,
|
|
2611
|
+
isAlias: false
|
|
2612
|
+
};
|
|
2613
|
+
}
|
|
2614
|
+
getSQL() {
|
|
2615
|
+
return new SQL([this]);
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
Column.prototype.getSQL = function() {
|
|
2619
|
+
return new SQL([this]);
|
|
2620
|
+
};
|
|
2621
|
+
Table.prototype.getSQL = function() {
|
|
2622
|
+
return new SQL([this]);
|
|
2623
|
+
};
|
|
2624
|
+
Subquery.prototype.getSQL = function() {
|
|
2625
|
+
return new SQL([this]);
|
|
2626
|
+
};
|
|
2627
|
+
|
|
2628
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/utils.js
|
|
2629
|
+
function mapResultRow(columns, row, joinsNotNullableMap) {
|
|
2630
|
+
const nullifyMap = {};
|
|
2631
|
+
const result = columns.reduce((result2, { path, field }, columnIndex) => {
|
|
2632
|
+
let decoder;
|
|
2633
|
+
if (is(field, Column)) {
|
|
2634
|
+
decoder = field;
|
|
2635
|
+
} else if (is(field, SQL)) {
|
|
2636
|
+
decoder = field.decoder;
|
|
2637
|
+
} else {
|
|
2638
|
+
decoder = field.sql.decoder;
|
|
2639
|
+
}
|
|
2640
|
+
let node = result2;
|
|
2641
|
+
for (const [pathChunkIndex, pathChunk] of path.entries()) {
|
|
2642
|
+
if (pathChunkIndex < path.length - 1) {
|
|
2643
|
+
if (!(pathChunk in node)) {
|
|
2644
|
+
node[pathChunk] = {};
|
|
2645
|
+
}
|
|
2646
|
+
node = node[pathChunk];
|
|
2647
|
+
} else {
|
|
2648
|
+
const rawValue = row[columnIndex];
|
|
2649
|
+
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
|
|
2650
|
+
if (joinsNotNullableMap && is(field, Column) && path.length === 2) {
|
|
2651
|
+
const objectName = path[0];
|
|
2652
|
+
if (!(objectName in nullifyMap)) {
|
|
2653
|
+
nullifyMap[objectName] = value === null ? getTableName(field.table) : false;
|
|
2654
|
+
} else if (typeof nullifyMap[objectName] === "string" && nullifyMap[objectName] !== getTableName(field.table)) {
|
|
2655
|
+
nullifyMap[objectName] = false;
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
return result2;
|
|
2661
|
+
}, {});
|
|
2662
|
+
if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {
|
|
2663
|
+
for (const [objectName, tableName] of Object.entries(nullifyMap)) {
|
|
2664
|
+
if (typeof tableName === "string" && !joinsNotNullableMap[tableName]) {
|
|
2665
|
+
result[objectName] = null;
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
return result;
|
|
2670
|
+
}
|
|
2671
|
+
function orderSelectedFields(fields, pathPrefix) {
|
|
2672
|
+
return Object.entries(fields).reduce((result, [name, field]) => {
|
|
2673
|
+
if (typeof name !== "string") {
|
|
2674
|
+
return result;
|
|
2675
|
+
}
|
|
2676
|
+
const newPath = pathPrefix ? [...pathPrefix, name] : [name];
|
|
2677
|
+
if (is(field, Column) || is(field, SQL) || is(field, SQL.Aliased)) {
|
|
2678
|
+
result.push({ path: newPath, field });
|
|
2679
|
+
} else if (is(field, Table)) {
|
|
2680
|
+
result.push(...orderSelectedFields(field[Table.Symbol.Columns], newPath));
|
|
2681
|
+
} else {
|
|
2682
|
+
result.push(...orderSelectedFields(field, newPath));
|
|
2683
|
+
}
|
|
2684
|
+
return result;
|
|
2685
|
+
}, []);
|
|
2686
|
+
}
|
|
2687
|
+
function haveSameKeys(left, right) {
|
|
2688
|
+
const leftKeys = Object.keys(left);
|
|
2689
|
+
const rightKeys = Object.keys(right);
|
|
2690
|
+
if (leftKeys.length !== rightKeys.length) {
|
|
2691
|
+
return false;
|
|
2692
|
+
}
|
|
2693
|
+
for (const [index, key] of leftKeys.entries()) {
|
|
2694
|
+
if (key !== rightKeys[index]) {
|
|
2695
|
+
return false;
|
|
2696
|
+
}
|
|
2697
|
+
}
|
|
2698
|
+
return true;
|
|
2699
|
+
}
|
|
2700
|
+
function mapUpdateSet(table, values2) {
|
|
2701
|
+
const entries = Object.entries(values2).filter(([, value]) => value !== undefined).map(([key, value]) => {
|
|
2702
|
+
if (is(value, SQL)) {
|
|
2703
|
+
return [key, value];
|
|
2704
|
+
} else {
|
|
2705
|
+
return [key, new Param(value, table[Table.Symbol.Columns][key])];
|
|
2706
|
+
}
|
|
2707
|
+
});
|
|
2708
|
+
if (entries.length === 0) {
|
|
2709
|
+
throw new Error("No values to set");
|
|
2710
|
+
}
|
|
2711
|
+
return Object.fromEntries(entries);
|
|
2712
|
+
}
|
|
2713
|
+
function applyMixins(baseClass, extendedClasses) {
|
|
2714
|
+
for (const extendedClass of extendedClasses) {
|
|
2715
|
+
for (const name of Object.getOwnPropertyNames(extendedClass.prototype)) {
|
|
2716
|
+
if (name === "constructor")
|
|
2717
|
+
continue;
|
|
2718
|
+
Object.defineProperty(baseClass.prototype, name, Object.getOwnPropertyDescriptor(extendedClass.prototype, name) || /* @__PURE__ */ Object.create(null));
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
function getTableColumns(table) {
|
|
2723
|
+
return table[Table.Symbol.Columns];
|
|
2724
|
+
}
|
|
2725
|
+
function getTableLikeName(table) {
|
|
2726
|
+
return is(table, Subquery) ? table._.alias : is(table, View) ? table[ViewBaseConfig].name : is(table, SQL) ? undefined : table[Table.Symbol.IsAlias] ? table[Table.Symbol.Name] : table[Table.Symbol.BaseName];
|
|
2727
|
+
}
|
|
2728
|
+
|
|
2729
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/query-builders/delete.js
|
|
2730
|
+
class PgDeleteBase extends QueryPromise {
|
|
2731
|
+
constructor(table, session, dialect, withList) {
|
|
2732
|
+
super();
|
|
2733
|
+
this.session = session;
|
|
2734
|
+
this.dialect = dialect;
|
|
2735
|
+
this.config = { table, withList };
|
|
2736
|
+
}
|
|
2737
|
+
static [entityKind] = "PgDelete";
|
|
2738
|
+
config;
|
|
2739
|
+
where(where) {
|
|
2740
|
+
this.config.where = where;
|
|
2741
|
+
return this;
|
|
2742
|
+
}
|
|
2743
|
+
returning(fields = this.config.table[Table.Symbol.Columns]) {
|
|
2744
|
+
this.config.returning = orderSelectedFields(fields);
|
|
2745
|
+
return this;
|
|
2746
|
+
}
|
|
2747
|
+
getSQL() {
|
|
2748
|
+
return this.dialect.buildDeleteQuery(this.config);
|
|
2749
|
+
}
|
|
2750
|
+
toSQL() {
|
|
2751
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
2752
|
+
return rest;
|
|
2753
|
+
}
|
|
2754
|
+
_prepare(name) {
|
|
2755
|
+
return tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
|
2756
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true);
|
|
2757
|
+
});
|
|
2758
|
+
}
|
|
2759
|
+
prepare(name) {
|
|
2760
|
+
return this._prepare(name);
|
|
2761
|
+
}
|
|
2762
|
+
execute = (placeholderValues) => {
|
|
2763
|
+
return tracer.startActiveSpan("drizzle.operation", () => {
|
|
2764
|
+
return this._prepare().execute(placeholderValues);
|
|
2765
|
+
});
|
|
2766
|
+
};
|
|
2767
|
+
$dynamic() {
|
|
2768
|
+
return this;
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
|
|
2772
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/query-builders/insert.js
|
|
2773
|
+
class PgInsertBuilder {
|
|
2774
|
+
constructor(table, session, dialect, withList) {
|
|
2775
|
+
this.table = table;
|
|
2776
|
+
this.session = session;
|
|
2777
|
+
this.dialect = dialect;
|
|
2778
|
+
this.withList = withList;
|
|
2779
|
+
}
|
|
2780
|
+
static [entityKind] = "PgInsertBuilder";
|
|
2781
|
+
values(values2) {
|
|
2782
|
+
values2 = Array.isArray(values2) ? values2 : [values2];
|
|
2783
|
+
if (values2.length === 0) {
|
|
2784
|
+
throw new Error("values() must be called with at least one value");
|
|
2785
|
+
}
|
|
2786
|
+
const mappedValues = values2.map((entry) => {
|
|
2787
|
+
const result = {};
|
|
2788
|
+
const cols = this.table[Table.Symbol.Columns];
|
|
2789
|
+
for (const colKey of Object.keys(entry)) {
|
|
2790
|
+
const colValue = entry[colKey];
|
|
2791
|
+
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
|
2792
|
+
}
|
|
2793
|
+
return result;
|
|
2794
|
+
});
|
|
2795
|
+
return new PgInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
|
|
2799
|
+
class PgInsertBase extends QueryPromise {
|
|
2800
|
+
constructor(table, values2, session, dialect, withList) {
|
|
2801
|
+
super();
|
|
2802
|
+
this.session = session;
|
|
2803
|
+
this.dialect = dialect;
|
|
2804
|
+
this.config = { table, values: values2, withList };
|
|
2805
|
+
}
|
|
2806
|
+
static [entityKind] = "PgInsert";
|
|
2807
|
+
config;
|
|
2808
|
+
returning(fields = this.config.table[Table.Symbol.Columns]) {
|
|
2809
|
+
this.config.returning = orderSelectedFields(fields);
|
|
2810
|
+
return this;
|
|
2811
|
+
}
|
|
2812
|
+
onConflictDoNothing(config = {}) {
|
|
2813
|
+
if (config.target === undefined) {
|
|
2814
|
+
this.config.onConflict = sql`do nothing`;
|
|
2815
|
+
} else {
|
|
2816
|
+
let targetColumn = "";
|
|
2817
|
+
targetColumn = Array.isArray(config.target) ? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(",") : this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));
|
|
2818
|
+
const whereSql = config.where ? sql` where ${config.where}` : undefined;
|
|
2819
|
+
this.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;
|
|
2820
|
+
}
|
|
2821
|
+
return this;
|
|
2822
|
+
}
|
|
2823
|
+
onConflictDoUpdate(config) {
|
|
2824
|
+
if (config.where && (config.targetWhere || config.setWhere)) {
|
|
2825
|
+
throw new Error('You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.');
|
|
2826
|
+
}
|
|
2827
|
+
const whereSql = config.where ? sql` where ${config.where}` : undefined;
|
|
2828
|
+
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : undefined;
|
|
2829
|
+
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : undefined;
|
|
2830
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
|
2831
|
+
let targetColumn = "";
|
|
2832
|
+
targetColumn = Array.isArray(config.target) ? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(",") : this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));
|
|
2833
|
+
this.config.onConflict = sql`(${sql.raw(targetColumn)})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
|
2834
|
+
return this;
|
|
2835
|
+
}
|
|
2836
|
+
getSQL() {
|
|
2837
|
+
return this.dialect.buildInsertQuery(this.config);
|
|
2838
|
+
}
|
|
2839
|
+
toSQL() {
|
|
2840
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
2841
|
+
return rest;
|
|
2842
|
+
}
|
|
2843
|
+
_prepare(name) {
|
|
2844
|
+
return tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
|
2845
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true);
|
|
2846
|
+
});
|
|
2847
|
+
}
|
|
2848
|
+
prepare(name) {
|
|
2849
|
+
return this._prepare(name);
|
|
2850
|
+
}
|
|
2851
|
+
execute = (placeholderValues) => {
|
|
2852
|
+
return tracer.startActiveSpan("drizzle.operation", () => {
|
|
2853
|
+
return this._prepare().execute(placeholderValues);
|
|
2854
|
+
});
|
|
2855
|
+
};
|
|
2856
|
+
$dynamic() {
|
|
2857
|
+
return this;
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/alias.js
|
|
2862
|
+
function aliasedTable(table, tableAlias) {
|
|
2863
|
+
return new Proxy(table, new TableAliasProxyHandler(tableAlias, false));
|
|
2864
|
+
}
|
|
2865
|
+
function aliasedTableColumn(column, tableAlias) {
|
|
2866
|
+
return new Proxy(column, new ColumnAliasProxyHandler(new Proxy(column.table, new TableAliasProxyHandler(tableAlias, false))));
|
|
2867
|
+
}
|
|
2868
|
+
function mapColumnsInAliasedSQLToAlias(query, alias) {
|
|
2869
|
+
return new SQL.Aliased(mapColumnsInSQLToAlias(query.sql, alias), query.fieldAlias);
|
|
2870
|
+
}
|
|
2871
|
+
function mapColumnsInSQLToAlias(query, alias) {
|
|
2872
|
+
return sql.join(query.queryChunks.map((c) => {
|
|
2873
|
+
if (is(c, Column)) {
|
|
2874
|
+
return aliasedTableColumn(c, alias);
|
|
2875
|
+
}
|
|
2876
|
+
if (is(c, SQL)) {
|
|
2877
|
+
return mapColumnsInSQLToAlias(c, alias);
|
|
2878
|
+
}
|
|
2879
|
+
if (is(c, SQL.Aliased)) {
|
|
2880
|
+
return mapColumnsInAliasedSQLToAlias(c, alias);
|
|
2881
|
+
}
|
|
2882
|
+
return c;
|
|
2883
|
+
}));
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2886
|
+
class ColumnAliasProxyHandler {
|
|
2887
|
+
constructor(table) {
|
|
2888
|
+
this.table = table;
|
|
2889
|
+
}
|
|
2890
|
+
static [entityKind] = "ColumnAliasProxyHandler";
|
|
2891
|
+
get(columnObj, prop) {
|
|
2892
|
+
if (prop === "table") {
|
|
2893
|
+
return this.table;
|
|
2894
|
+
}
|
|
2895
|
+
return columnObj[prop];
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
|
|
2899
|
+
class TableAliasProxyHandler {
|
|
2900
|
+
constructor(alias, replaceOriginalName) {
|
|
2901
|
+
this.alias = alias;
|
|
2902
|
+
this.replaceOriginalName = replaceOriginalName;
|
|
2903
|
+
}
|
|
2904
|
+
static [entityKind] = "TableAliasProxyHandler";
|
|
2905
|
+
get(target, prop) {
|
|
2906
|
+
if (prop === Table.Symbol.IsAlias) {
|
|
2907
|
+
return true;
|
|
2908
|
+
}
|
|
2909
|
+
if (prop === Table.Symbol.Name) {
|
|
2910
|
+
return this.alias;
|
|
2911
|
+
}
|
|
2912
|
+
if (this.replaceOriginalName && prop === Table.Symbol.OriginalName) {
|
|
2913
|
+
return this.alias;
|
|
2914
|
+
}
|
|
2915
|
+
if (prop === ViewBaseConfig) {
|
|
2916
|
+
return {
|
|
2917
|
+
...target[ViewBaseConfig],
|
|
2918
|
+
name: this.alias,
|
|
2919
|
+
isAlias: true
|
|
2920
|
+
};
|
|
2921
|
+
}
|
|
2922
|
+
if (prop === Table.Symbol.Columns) {
|
|
2923
|
+
const columns = target[Table.Symbol.Columns];
|
|
2924
|
+
if (!columns) {
|
|
2925
|
+
return columns;
|
|
2926
|
+
}
|
|
2927
|
+
const proxiedColumns = {};
|
|
2928
|
+
Object.keys(columns).map((key) => {
|
|
2929
|
+
proxiedColumns[key] = new Proxy(columns[key], new ColumnAliasProxyHandler(new Proxy(target, this)));
|
|
2930
|
+
});
|
|
2931
|
+
return proxiedColumns;
|
|
2932
|
+
}
|
|
2933
|
+
const value = target[prop];
|
|
2934
|
+
if (is(value, Column)) {
|
|
2935
|
+
return new Proxy(value, new ColumnAliasProxyHandler(new Proxy(target, this)));
|
|
2936
|
+
}
|
|
2937
|
+
return value;
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
|
|
2941
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/casing.js
|
|
2942
|
+
function toSnakeCase(input) {
|
|
2943
|
+
const words = input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? [];
|
|
2944
|
+
return words.map((word) => word.toLowerCase()).join("_");
|
|
2945
|
+
}
|
|
2946
|
+
function toCamelCase(input) {
|
|
2947
|
+
const words = input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? [];
|
|
2948
|
+
return words.reduce((acc, word, i) => {
|
|
2949
|
+
const formattedWord = i === 0 ? word.toLowerCase() : `${word[0].toUpperCase()}${word.slice(1)}`;
|
|
2950
|
+
return acc + formattedWord;
|
|
2951
|
+
}, "");
|
|
2952
|
+
}
|
|
2953
|
+
function noopCase(input) {
|
|
2954
|
+
return input;
|
|
2955
|
+
}
|
|
2956
|
+
|
|
2957
|
+
class CasingCache {
|
|
2958
|
+
static [entityKind] = "CasingCache";
|
|
2959
|
+
cache = {};
|
|
2960
|
+
cachedTables = {};
|
|
2961
|
+
convert;
|
|
2962
|
+
constructor(casing) {
|
|
2963
|
+
this.convert = casing === "snake_case" ? toSnakeCase : casing === "camelCase" ? toCamelCase : noopCase;
|
|
2964
|
+
}
|
|
2965
|
+
getColumnCasing(column) {
|
|
2966
|
+
if (!column.keyAsName)
|
|
2967
|
+
return column.name;
|
|
2968
|
+
const schema = column.table[Table.Symbol.Schema] ?? "public";
|
|
2969
|
+
const tableName = column.table[Table.Symbol.OriginalName];
|
|
2970
|
+
const key = `${schema}.${tableName}.${column.name}`;
|
|
2971
|
+
if (!this.cache[key]) {
|
|
2972
|
+
this.cacheTable(column.table);
|
|
2973
|
+
}
|
|
2974
|
+
return this.cache[key];
|
|
2975
|
+
}
|
|
2976
|
+
cacheTable(table) {
|
|
2977
|
+
const schema = table[Table.Symbol.Schema] ?? "public";
|
|
2978
|
+
const tableName = table[Table.Symbol.OriginalName];
|
|
2979
|
+
const tableKey = `${schema}.${tableName}`;
|
|
2980
|
+
if (!this.cachedTables[tableKey]) {
|
|
2981
|
+
for (const column of Object.values(table[Table.Symbol.Columns])) {
|
|
2982
|
+
const columnKey = `${tableKey}.${column.name}`;
|
|
2983
|
+
this.cache[columnKey] = this.convert(column.name);
|
|
2984
|
+
}
|
|
2985
|
+
this.cachedTables[tableKey] = true;
|
|
2986
|
+
}
|
|
2987
|
+
}
|
|
2988
|
+
clearCache() {
|
|
2989
|
+
this.cache = {};
|
|
2990
|
+
this.cachedTables = {};
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
|
|
2994
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/errors.js
|
|
2995
|
+
class DrizzleError extends Error {
|
|
2996
|
+
static [entityKind] = "DrizzleError";
|
|
2997
|
+
constructor({ message, cause }) {
|
|
2998
|
+
super(message);
|
|
2999
|
+
this.name = "DrizzleError";
|
|
3000
|
+
this.cause = cause;
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
|
|
3004
|
+
class TransactionRollbackError extends DrizzleError {
|
|
3005
|
+
static [entityKind] = "TransactionRollbackError";
|
|
3006
|
+
constructor() {
|
|
3007
|
+
super({ message: "Rollback" });
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
|
|
3011
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/columns/date.js
|
|
3012
|
+
class PgDate extends PgColumn {
|
|
3013
|
+
static [entityKind] = "PgDate";
|
|
3014
|
+
getSQLType() {
|
|
3015
|
+
return "date";
|
|
3016
|
+
}
|
|
3017
|
+
mapFromDriverValue(value) {
|
|
3018
|
+
return new Date(value);
|
|
3019
|
+
}
|
|
3020
|
+
mapToDriverValue(value) {
|
|
3021
|
+
return value.toISOString();
|
|
3022
|
+
}
|
|
3023
|
+
}
|
|
3024
|
+
class PgDateString extends PgColumn {
|
|
3025
|
+
static [entityKind] = "PgDateString";
|
|
3026
|
+
getSQLType() {
|
|
3027
|
+
return "date";
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
3030
|
+
|
|
3031
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/columns/json.js
|
|
3032
|
+
class PgJson extends PgColumn {
|
|
3033
|
+
static [entityKind] = "PgJson";
|
|
3034
|
+
constructor(table, config) {
|
|
3035
|
+
super(table, config);
|
|
3036
|
+
}
|
|
3037
|
+
getSQLType() {
|
|
3038
|
+
return "json";
|
|
3039
|
+
}
|
|
3040
|
+
mapToDriverValue(value) {
|
|
3041
|
+
return JSON.stringify(value);
|
|
3042
|
+
}
|
|
3043
|
+
mapFromDriverValue(value) {
|
|
3044
|
+
if (typeof value === "string") {
|
|
3045
|
+
try {
|
|
3046
|
+
return JSON.parse(value);
|
|
3047
|
+
} catch {
|
|
3048
|
+
return value;
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
return value;
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
|
|
3055
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/columns/jsonb.js
|
|
3056
|
+
class PgJsonb extends PgColumn {
|
|
3057
|
+
static [entityKind] = "PgJsonb";
|
|
3058
|
+
constructor(table, config) {
|
|
3059
|
+
super(table, config);
|
|
3060
|
+
}
|
|
3061
|
+
getSQLType() {
|
|
3062
|
+
return "jsonb";
|
|
3063
|
+
}
|
|
3064
|
+
mapToDriverValue(value) {
|
|
3065
|
+
return JSON.stringify(value);
|
|
3066
|
+
}
|
|
3067
|
+
mapFromDriverValue(value) {
|
|
3068
|
+
if (typeof value === "string") {
|
|
3069
|
+
try {
|
|
3070
|
+
return JSON.parse(value);
|
|
3071
|
+
} catch {
|
|
3072
|
+
return value;
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
return value;
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
|
|
3079
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/columns/numeric.js
|
|
3080
|
+
class PgNumeric extends PgColumn {
|
|
3081
|
+
static [entityKind] = "PgNumeric";
|
|
3082
|
+
precision;
|
|
3083
|
+
scale;
|
|
3084
|
+
constructor(table, config) {
|
|
3085
|
+
super(table, config);
|
|
3086
|
+
this.precision = config.precision;
|
|
3087
|
+
this.scale = config.scale;
|
|
3088
|
+
}
|
|
3089
|
+
getSQLType() {
|
|
3090
|
+
if (this.precision !== undefined && this.scale !== undefined) {
|
|
3091
|
+
return `numeric(${this.precision}, ${this.scale})`;
|
|
3092
|
+
} else if (this.precision === undefined) {
|
|
3093
|
+
return "numeric";
|
|
3094
|
+
} else {
|
|
3095
|
+
return `numeric(${this.precision})`;
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
|
|
3100
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/columns/time.js
|
|
3101
|
+
class PgTime extends PgColumn {
|
|
3102
|
+
static [entityKind] = "PgTime";
|
|
3103
|
+
withTimezone;
|
|
3104
|
+
precision;
|
|
3105
|
+
constructor(table, config) {
|
|
3106
|
+
super(table, config);
|
|
3107
|
+
this.withTimezone = config.withTimezone;
|
|
3108
|
+
this.precision = config.precision;
|
|
3109
|
+
}
|
|
3110
|
+
getSQLType() {
|
|
3111
|
+
const precision = this.precision === undefined ? "" : `(${this.precision})`;
|
|
3112
|
+
return `time${precision}${this.withTimezone ? " with time zone" : ""}`;
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
|
|
3116
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/columns/timestamp.js
|
|
3117
|
+
class PgTimestamp extends PgColumn {
|
|
3118
|
+
static [entityKind] = "PgTimestamp";
|
|
3119
|
+
withTimezone;
|
|
3120
|
+
precision;
|
|
3121
|
+
constructor(table, config) {
|
|
3122
|
+
super(table, config);
|
|
3123
|
+
this.withTimezone = config.withTimezone;
|
|
3124
|
+
this.precision = config.precision;
|
|
3125
|
+
}
|
|
3126
|
+
getSQLType() {
|
|
3127
|
+
const precision = this.precision === undefined ? "" : ` (${this.precision})`;
|
|
3128
|
+
return `timestamp${precision}${this.withTimezone ? " with time zone" : ""}`;
|
|
3129
|
+
}
|
|
3130
|
+
mapFromDriverValue = (value) => {
|
|
3131
|
+
return new Date(this.withTimezone ? value : value + "+0000");
|
|
3132
|
+
};
|
|
3133
|
+
mapToDriverValue = (value) => {
|
|
3134
|
+
return value.toISOString();
|
|
3135
|
+
};
|
|
3136
|
+
}
|
|
3137
|
+
class PgTimestampString extends PgColumn {
|
|
3138
|
+
static [entityKind] = "PgTimestampString";
|
|
3139
|
+
withTimezone;
|
|
3140
|
+
precision;
|
|
3141
|
+
constructor(table, config) {
|
|
3142
|
+
super(table, config);
|
|
3143
|
+
this.withTimezone = config.withTimezone;
|
|
3144
|
+
this.precision = config.precision;
|
|
3145
|
+
}
|
|
3146
|
+
getSQLType() {
|
|
3147
|
+
const precision = this.precision === undefined ? "" : `(${this.precision})`;
|
|
3148
|
+
return `timestamp${precision}${this.withTimezone ? " with time zone" : ""}`;
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
|
|
3152
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/columns/uuid.js
|
|
3153
|
+
class PgUUID extends PgColumn {
|
|
3154
|
+
static [entityKind] = "PgUUID";
|
|
3155
|
+
getSQLType() {
|
|
3156
|
+
return "uuid";
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
|
|
3160
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/table.js
|
|
3161
|
+
var InlineForeignKeys = Symbol.for("drizzle:PgInlineForeignKeys");
|
|
3162
|
+
|
|
3163
|
+
class PgTable extends Table {
|
|
3164
|
+
static [entityKind] = "PgTable";
|
|
3165
|
+
static Symbol = Object.assign({}, Table.Symbol, {
|
|
3166
|
+
InlineForeignKeys
|
|
3167
|
+
});
|
|
3168
|
+
[InlineForeignKeys] = [];
|
|
3169
|
+
[Table.Symbol.ExtraConfigBuilder] = undefined;
|
|
3170
|
+
}
|
|
3171
|
+
|
|
3172
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/primary-keys.js
|
|
3173
|
+
class PrimaryKeyBuilder {
|
|
3174
|
+
static [entityKind] = "PgPrimaryKeyBuilder";
|
|
3175
|
+
columns;
|
|
3176
|
+
name;
|
|
3177
|
+
constructor(columns, name) {
|
|
3178
|
+
this.columns = columns;
|
|
3179
|
+
this.name = name;
|
|
3180
|
+
}
|
|
3181
|
+
build(table) {
|
|
3182
|
+
return new PrimaryKey(table, this.columns, this.name);
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
|
|
3186
|
+
class PrimaryKey {
|
|
3187
|
+
constructor(table, columns, name) {
|
|
3188
|
+
this.table = table;
|
|
3189
|
+
this.columns = columns;
|
|
3190
|
+
this.name = name;
|
|
3191
|
+
}
|
|
3192
|
+
static [entityKind] = "PgPrimaryKey";
|
|
3193
|
+
columns;
|
|
3194
|
+
name;
|
|
3195
|
+
getName() {
|
|
3196
|
+
return this.name ?? `${this.table[PgTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
|
|
3197
|
+
}
|
|
3198
|
+
}
|
|
3199
|
+
|
|
3200
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/sql/expressions/conditions.js
|
|
3201
|
+
function bindIfParam(value, column) {
|
|
3202
|
+
if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) {
|
|
3203
|
+
return new Param(value, column);
|
|
3204
|
+
}
|
|
3205
|
+
return value;
|
|
3206
|
+
}
|
|
3207
|
+
function and(...unfilteredConditions) {
|
|
3208
|
+
const conditions = unfilteredConditions.filter((c) => c !== undefined);
|
|
3209
|
+
if (conditions.length === 0) {
|
|
3210
|
+
return;
|
|
3211
|
+
}
|
|
3212
|
+
if (conditions.length === 1) {
|
|
3213
|
+
return new SQL(conditions);
|
|
3214
|
+
}
|
|
3215
|
+
return new SQL([
|
|
3216
|
+
new StringChunk("("),
|
|
3217
|
+
sql.join(conditions, new StringChunk(" and ")),
|
|
3218
|
+
new StringChunk(")")
|
|
3219
|
+
]);
|
|
3220
|
+
}
|
|
3221
|
+
function or(...unfilteredConditions) {
|
|
3222
|
+
const conditions = unfilteredConditions.filter((c) => c !== undefined);
|
|
3223
|
+
if (conditions.length === 0) {
|
|
3224
|
+
return;
|
|
3225
|
+
}
|
|
3226
|
+
if (conditions.length === 1) {
|
|
3227
|
+
return new SQL(conditions);
|
|
3228
|
+
}
|
|
3229
|
+
return new SQL([
|
|
3230
|
+
new StringChunk("("),
|
|
3231
|
+
sql.join(conditions, new StringChunk(" or ")),
|
|
3232
|
+
new StringChunk(")")
|
|
3233
|
+
]);
|
|
3234
|
+
}
|
|
3235
|
+
function not(condition) {
|
|
3236
|
+
return sql`not ${condition}`;
|
|
3237
|
+
}
|
|
3238
|
+
function inArray(column, values2) {
|
|
3239
|
+
if (Array.isArray(values2)) {
|
|
3240
|
+
if (values2.length === 0) {
|
|
3241
|
+
return sql`false`;
|
|
3242
|
+
}
|
|
3243
|
+
return sql`${column} in ${values2.map((v) => bindIfParam(v, column))}`;
|
|
3244
|
+
}
|
|
3245
|
+
return sql`${column} in ${bindIfParam(values2, column)}`;
|
|
3246
|
+
}
|
|
3247
|
+
function notInArray(column, values2) {
|
|
3248
|
+
if (Array.isArray(values2)) {
|
|
3249
|
+
if (values2.length === 0) {
|
|
3250
|
+
return sql`true`;
|
|
3251
|
+
}
|
|
3252
|
+
return sql`${column} not in ${values2.map((v) => bindIfParam(v, column))}`;
|
|
3253
|
+
}
|
|
3254
|
+
return sql`${column} not in ${bindIfParam(values2, column)}`;
|
|
3255
|
+
}
|
|
3256
|
+
function isNull(value) {
|
|
3257
|
+
return sql`${value} is null`;
|
|
3258
|
+
}
|
|
3259
|
+
function isNotNull(value) {
|
|
3260
|
+
return sql`${value} is not null`;
|
|
3261
|
+
}
|
|
3262
|
+
function exists(subquery) {
|
|
3263
|
+
return sql`exists ${subquery}`;
|
|
3264
|
+
}
|
|
3265
|
+
function notExists(subquery) {
|
|
3266
|
+
return sql`not exists ${subquery}`;
|
|
3267
|
+
}
|
|
3268
|
+
function between(column, min, max) {
|
|
3269
|
+
return sql`${column} between ${bindIfParam(min, column)} and ${bindIfParam(max, column)}`;
|
|
3270
|
+
}
|
|
3271
|
+
function notBetween(column, min, max) {
|
|
3272
|
+
return sql`${column} not between ${bindIfParam(min, column)} and ${bindIfParam(max, column)}`;
|
|
3273
|
+
}
|
|
3274
|
+
function like(column, value) {
|
|
3275
|
+
return sql`${column} like ${value}`;
|
|
3276
|
+
}
|
|
3277
|
+
function notLike(column, value) {
|
|
3278
|
+
return sql`${column} not like ${value}`;
|
|
3279
|
+
}
|
|
3280
|
+
function ilike(column, value) {
|
|
3281
|
+
return sql`${column} ilike ${value}`;
|
|
3282
|
+
}
|
|
3283
|
+
function notIlike(column, value) {
|
|
3284
|
+
return sql`${column} not ilike ${value}`;
|
|
3285
|
+
}
|
|
3286
|
+
var eq = (left, right) => {
|
|
3287
|
+
return sql`${left} = ${bindIfParam(right, left)}`;
|
|
3288
|
+
};
|
|
3289
|
+
var ne = (left, right) => {
|
|
3290
|
+
return sql`${left} <> ${bindIfParam(right, left)}`;
|
|
3291
|
+
};
|
|
3292
|
+
var gt = (left, right) => {
|
|
3293
|
+
return sql`${left} > ${bindIfParam(right, left)}`;
|
|
3294
|
+
};
|
|
3295
|
+
var gte = (left, right) => {
|
|
3296
|
+
return sql`${left} >= ${bindIfParam(right, left)}`;
|
|
3297
|
+
};
|
|
3298
|
+
var lt = (left, right) => {
|
|
3299
|
+
return sql`${left} < ${bindIfParam(right, left)}`;
|
|
3300
|
+
};
|
|
3301
|
+
var lte = (left, right) => {
|
|
3302
|
+
return sql`${left} <= ${bindIfParam(right, left)}`;
|
|
3303
|
+
};
|
|
3304
|
+
|
|
3305
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/sql/expressions/select.js
|
|
3306
|
+
function asc(column) {
|
|
3307
|
+
return sql`${column} asc`;
|
|
3308
|
+
}
|
|
3309
|
+
function desc(column) {
|
|
3310
|
+
return sql`${column} desc`;
|
|
3311
|
+
}
|
|
3312
|
+
|
|
3313
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/relations.js
|
|
3314
|
+
function getOperators() {
|
|
3315
|
+
return {
|
|
3316
|
+
and,
|
|
3317
|
+
between,
|
|
3318
|
+
eq,
|
|
3319
|
+
exists,
|
|
3320
|
+
gt,
|
|
3321
|
+
gte,
|
|
3322
|
+
ilike,
|
|
3323
|
+
inArray,
|
|
3324
|
+
isNull,
|
|
3325
|
+
isNotNull,
|
|
3326
|
+
like,
|
|
3327
|
+
lt,
|
|
3328
|
+
lte,
|
|
3329
|
+
ne,
|
|
3330
|
+
not,
|
|
3331
|
+
notBetween,
|
|
3332
|
+
notExists,
|
|
3333
|
+
notLike,
|
|
3334
|
+
notIlike,
|
|
3335
|
+
notInArray,
|
|
3336
|
+
or,
|
|
3337
|
+
sql
|
|
3338
|
+
};
|
|
3339
|
+
}
|
|
3340
|
+
function getOrderByOperators() {
|
|
3341
|
+
return {
|
|
3342
|
+
sql,
|
|
3343
|
+
asc,
|
|
3344
|
+
desc
|
|
3345
|
+
};
|
|
3346
|
+
}
|
|
3347
|
+
function extractTablesRelationalConfig(schema, configHelpers) {
|
|
3348
|
+
if (Object.keys(schema).length === 1 && "default" in schema && !is(schema["default"], Table)) {
|
|
3349
|
+
schema = schema["default"];
|
|
3350
|
+
}
|
|
3351
|
+
const tableNamesMap = {};
|
|
3352
|
+
const relationsBuffer = {};
|
|
3353
|
+
const tablesConfig = {};
|
|
3354
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
3355
|
+
if (is(value, Table)) {
|
|
3356
|
+
const dbName = getTableUniqueName(value);
|
|
3357
|
+
const bufferedRelations = relationsBuffer[dbName];
|
|
3358
|
+
tableNamesMap[dbName] = key;
|
|
3359
|
+
tablesConfig[key] = {
|
|
3360
|
+
tsName: key,
|
|
3361
|
+
dbName: value[Table.Symbol.Name],
|
|
3362
|
+
schema: value[Table.Symbol.Schema],
|
|
3363
|
+
columns: value[Table.Symbol.Columns],
|
|
3364
|
+
relations: bufferedRelations?.relations ?? {},
|
|
3365
|
+
primaryKey: bufferedRelations?.primaryKey ?? []
|
|
3366
|
+
};
|
|
3367
|
+
for (const column of Object.values(value[Table.Symbol.Columns])) {
|
|
3368
|
+
if (column.primary) {
|
|
3369
|
+
tablesConfig[key].primaryKey.push(column);
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
const extraConfig = value[Table.Symbol.ExtraConfigBuilder]?.(value[Table.Symbol.ExtraConfigColumns]);
|
|
3373
|
+
if (extraConfig) {
|
|
3374
|
+
for (const configEntry of Object.values(extraConfig)) {
|
|
3375
|
+
if (is(configEntry, PrimaryKeyBuilder)) {
|
|
3376
|
+
tablesConfig[key].primaryKey.push(...configEntry.columns);
|
|
3377
|
+
}
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3380
|
+
} else if (is(value, Relations)) {
|
|
3381
|
+
const dbName = getTableUniqueName(value.table);
|
|
3382
|
+
const tableName = tableNamesMap[dbName];
|
|
3383
|
+
const relations2 = value.config(configHelpers(value.table));
|
|
3384
|
+
let primaryKey;
|
|
3385
|
+
for (const [relationName, relation] of Object.entries(relations2)) {
|
|
3386
|
+
if (tableName) {
|
|
3387
|
+
const tableConfig = tablesConfig[tableName];
|
|
3388
|
+
tableConfig.relations[relationName] = relation;
|
|
3389
|
+
if (primaryKey) {
|
|
3390
|
+
tableConfig.primaryKey.push(...primaryKey);
|
|
3391
|
+
}
|
|
3392
|
+
} else {
|
|
3393
|
+
if (!(dbName in relationsBuffer)) {
|
|
3394
|
+
relationsBuffer[dbName] = {
|
|
3395
|
+
relations: {},
|
|
3396
|
+
primaryKey
|
|
3397
|
+
};
|
|
3398
|
+
}
|
|
3399
|
+
relationsBuffer[dbName].relations[relationName] = relation;
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
return { tables: tablesConfig, tableNamesMap };
|
|
3405
|
+
}
|
|
3406
|
+
function createOne(sourceTable) {
|
|
3407
|
+
return function one(table, config) {
|
|
3408
|
+
return new One(sourceTable, table, config, config?.fields.reduce((res, f) => res && f.notNull, true) ?? false);
|
|
3409
|
+
};
|
|
3410
|
+
}
|
|
3411
|
+
function createMany(sourceTable) {
|
|
3412
|
+
return function many(referencedTable, config) {
|
|
3413
|
+
return new Many(sourceTable, referencedTable, config);
|
|
3414
|
+
};
|
|
3415
|
+
}
|
|
3416
|
+
function normalizeRelation(schema, tableNamesMap, relation) {
|
|
3417
|
+
if (is(relation, One) && relation.config) {
|
|
3418
|
+
return {
|
|
3419
|
+
fields: relation.config.fields,
|
|
3420
|
+
references: relation.config.references
|
|
3421
|
+
};
|
|
3422
|
+
}
|
|
3423
|
+
const referencedTableTsName = tableNamesMap[getTableUniqueName(relation.referencedTable)];
|
|
3424
|
+
if (!referencedTableTsName) {
|
|
3425
|
+
throw new Error(`Table "${relation.referencedTable[Table.Symbol.Name]}" not found in schema`);
|
|
3426
|
+
}
|
|
3427
|
+
const referencedTableConfig = schema[referencedTableTsName];
|
|
3428
|
+
if (!referencedTableConfig) {
|
|
3429
|
+
throw new Error(`Table "${referencedTableTsName}" not found in schema`);
|
|
3430
|
+
}
|
|
3431
|
+
const sourceTable = relation.sourceTable;
|
|
3432
|
+
const sourceTableTsName = tableNamesMap[getTableUniqueName(sourceTable)];
|
|
3433
|
+
if (!sourceTableTsName) {
|
|
3434
|
+
throw new Error(`Table "${sourceTable[Table.Symbol.Name]}" not found in schema`);
|
|
3435
|
+
}
|
|
3436
|
+
const reverseRelations = [];
|
|
3437
|
+
for (const referencedTableRelation of Object.values(referencedTableConfig.relations)) {
|
|
3438
|
+
if (relation.relationName && relation !== referencedTableRelation && referencedTableRelation.relationName === relation.relationName || !relation.relationName && referencedTableRelation.referencedTable === relation.sourceTable) {
|
|
3439
|
+
reverseRelations.push(referencedTableRelation);
|
|
3440
|
+
}
|
|
3441
|
+
}
|
|
3442
|
+
if (reverseRelations.length > 1) {
|
|
3443
|
+
throw relation.relationName ? new Error(`There are multiple relations with name "${relation.relationName}" in table "${referencedTableTsName}"`) : new Error(`There are multiple relations between "${referencedTableTsName}" and "${relation.sourceTable[Table.Symbol.Name]}". Please specify relation name`);
|
|
3444
|
+
}
|
|
3445
|
+
if (reverseRelations[0] && is(reverseRelations[0], One) && reverseRelations[0].config) {
|
|
3446
|
+
return {
|
|
3447
|
+
fields: reverseRelations[0].config.references,
|
|
3448
|
+
references: reverseRelations[0].config.fields
|
|
3449
|
+
};
|
|
3450
|
+
}
|
|
3451
|
+
throw new Error(`There is not enough information to infer relation "${sourceTableTsName}.${relation.fieldName}"`);
|
|
3452
|
+
}
|
|
3453
|
+
function createTableRelationsHelpers(sourceTable) {
|
|
3454
|
+
return {
|
|
3455
|
+
one: createOne(sourceTable),
|
|
3456
|
+
many: createMany(sourceTable)
|
|
3457
|
+
};
|
|
3458
|
+
}
|
|
3459
|
+
function mapRelationalRow(tablesConfig, tableConfig, row, buildQueryResultSelection, mapColumnValue = (value) => value) {
|
|
3460
|
+
const result = {};
|
|
3461
|
+
for (const [
|
|
3462
|
+
selectionItemIndex,
|
|
3463
|
+
selectionItem
|
|
3464
|
+
] of buildQueryResultSelection.entries()) {
|
|
3465
|
+
if (selectionItem.isJson) {
|
|
3466
|
+
const relation = tableConfig.relations[selectionItem.tsKey];
|
|
3467
|
+
const rawSubRows = row[selectionItemIndex];
|
|
3468
|
+
const subRows = typeof rawSubRows === "string" ? JSON.parse(rawSubRows) : rawSubRows;
|
|
3469
|
+
result[selectionItem.tsKey] = is(relation, One) ? subRows && mapRelationalRow(tablesConfig, tablesConfig[selectionItem.relationTableTsKey], subRows, selectionItem.selection, mapColumnValue) : subRows.map((subRow) => mapRelationalRow(tablesConfig, tablesConfig[selectionItem.relationTableTsKey], subRow, selectionItem.selection, mapColumnValue));
|
|
3470
|
+
} else {
|
|
3471
|
+
const value = mapColumnValue(row[selectionItemIndex]);
|
|
3472
|
+
const field = selectionItem.field;
|
|
3473
|
+
let decoder;
|
|
3474
|
+
if (is(field, Column)) {
|
|
3475
|
+
decoder = field;
|
|
3476
|
+
} else if (is(field, SQL)) {
|
|
3477
|
+
decoder = field.decoder;
|
|
3478
|
+
} else {
|
|
3479
|
+
decoder = field.sql.decoder;
|
|
3480
|
+
}
|
|
3481
|
+
result[selectionItem.tsKey] = value === null ? null : decoder.mapFromDriverValue(value);
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
return result;
|
|
3485
|
+
}
|
|
3486
|
+
|
|
3487
|
+
class Relation {
|
|
3488
|
+
constructor(sourceTable, referencedTable, relationName) {
|
|
3489
|
+
this.sourceTable = sourceTable;
|
|
3490
|
+
this.referencedTable = referencedTable;
|
|
3491
|
+
this.relationName = relationName;
|
|
3492
|
+
this.referencedTableName = referencedTable[Table.Symbol.Name];
|
|
3493
|
+
}
|
|
3494
|
+
static [entityKind] = "Relation";
|
|
3495
|
+
referencedTableName;
|
|
3496
|
+
fieldName;
|
|
3497
|
+
}
|
|
3498
|
+
|
|
3499
|
+
class Relations {
|
|
3500
|
+
constructor(table, config) {
|
|
3501
|
+
this.table = table;
|
|
3502
|
+
this.config = config;
|
|
3503
|
+
}
|
|
3504
|
+
static [entityKind] = "Relations";
|
|
3505
|
+
}
|
|
3506
|
+
|
|
3507
|
+
class One extends Relation {
|
|
3508
|
+
constructor(sourceTable, referencedTable, config, isNullable) {
|
|
3509
|
+
super(sourceTable, referencedTable, config?.relationName);
|
|
3510
|
+
this.config = config;
|
|
3511
|
+
this.isNullable = isNullable;
|
|
3512
|
+
}
|
|
3513
|
+
static [entityKind] = "One";
|
|
3514
|
+
withFieldName(fieldName) {
|
|
3515
|
+
const relation = new One(this.sourceTable, this.referencedTable, this.config, this.isNullable);
|
|
3516
|
+
relation.fieldName = fieldName;
|
|
3517
|
+
return relation;
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
|
|
3521
|
+
class Many extends Relation {
|
|
3522
|
+
constructor(sourceTable, referencedTable, config) {
|
|
3523
|
+
super(sourceTable, referencedTable, config?.relationName);
|
|
3524
|
+
this.config = config;
|
|
3525
|
+
}
|
|
3526
|
+
static [entityKind] = "Many";
|
|
3527
|
+
withFieldName(fieldName) {
|
|
3528
|
+
const relation = new Many(this.sourceTable, this.referencedTable, this.config);
|
|
3529
|
+
relation.fieldName = fieldName;
|
|
3530
|
+
return relation;
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
|
|
3534
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/view-base.js
|
|
3535
|
+
class PgViewBase extends View {
|
|
3536
|
+
static [entityKind] = "PgViewBase";
|
|
3537
|
+
}
|
|
3538
|
+
|
|
3539
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/dialect.js
|
|
3540
|
+
class PgDialect {
|
|
3541
|
+
static [entityKind] = "PgDialect";
|
|
3542
|
+
casing;
|
|
3543
|
+
constructor(config) {
|
|
3544
|
+
this.casing = new CasingCache(config?.casing);
|
|
3545
|
+
}
|
|
3546
|
+
async migrate(migrations, session, config) {
|
|
3547
|
+
const migrationsTable = typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
|
3548
|
+
const migrationsSchema = typeof config === "string" ? "drizzle" : config.migrationsSchema ?? "drizzle";
|
|
3549
|
+
const migrationTableCreate = sql`
|
|
3550
|
+
CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)} (
|
|
3551
|
+
id SERIAL PRIMARY KEY,
|
|
3552
|
+
hash text NOT NULL,
|
|
3553
|
+
created_at bigint
|
|
3554
|
+
)
|
|
3555
|
+
`;
|
|
3556
|
+
await session.execute(sql`CREATE SCHEMA IF NOT EXISTS ${sql.identifier(migrationsSchema)}`);
|
|
3557
|
+
await session.execute(migrationTableCreate);
|
|
3558
|
+
const dbMigrations = await session.all(sql`select id, hash, created_at from ${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)} order by created_at desc limit 1`);
|
|
3559
|
+
const lastDbMigration = dbMigrations[0];
|
|
3560
|
+
await session.transaction(async (tx) => {
|
|
3561
|
+
for await (const migration of migrations) {
|
|
3562
|
+
if (!lastDbMigration || Number(lastDbMigration.created_at) < migration.folderMillis) {
|
|
3563
|
+
for (const stmt of migration.sql) {
|
|
3564
|
+
await tx.execute(sql.raw(stmt));
|
|
3565
|
+
}
|
|
3566
|
+
await tx.execute(sql`insert into ${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)} ("hash", "created_at") values(${migration.hash}, ${migration.folderMillis})`);
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
});
|
|
3570
|
+
}
|
|
3571
|
+
escapeName(name) {
|
|
3572
|
+
return `"${name}"`;
|
|
3573
|
+
}
|
|
3574
|
+
escapeParam(num) {
|
|
3575
|
+
return `\$${num + 1}`;
|
|
3576
|
+
}
|
|
3577
|
+
escapeString(str) {
|
|
3578
|
+
return `'${str.replace(/'/g, "''")}'`;
|
|
3579
|
+
}
|
|
3580
|
+
buildWithCTE(queries) {
|
|
3581
|
+
if (!queries?.length)
|
|
3582
|
+
return;
|
|
3583
|
+
const withSqlChunks = [sql`with `];
|
|
3584
|
+
for (const [i, w] of queries.entries()) {
|
|
3585
|
+
withSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);
|
|
3586
|
+
if (i < queries.length - 1) {
|
|
3587
|
+
withSqlChunks.push(sql`, `);
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
withSqlChunks.push(sql` `);
|
|
3591
|
+
return sql.join(withSqlChunks);
|
|
3592
|
+
}
|
|
3593
|
+
buildDeleteQuery({ table, where, returning, withList }) {
|
|
3594
|
+
const withSql = this.buildWithCTE(withList);
|
|
3595
|
+
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : undefined;
|
|
3596
|
+
const whereSql = where ? sql` where ${where}` : undefined;
|
|
3597
|
+
return sql`${withSql}delete from ${table}${whereSql}${returningSql}`;
|
|
3598
|
+
}
|
|
3599
|
+
buildUpdateSet(table, set) {
|
|
3600
|
+
const tableColumns = table[Table.Symbol.Columns];
|
|
3601
|
+
const columnNames = Object.keys(tableColumns).filter((colName) => set[colName] !== undefined || tableColumns[colName]?.onUpdateFn !== undefined);
|
|
3602
|
+
const setSize = columnNames.length;
|
|
3603
|
+
return sql.join(columnNames.flatMap((colName, i) => {
|
|
3604
|
+
const col = tableColumns[colName];
|
|
3605
|
+
const value = set[colName] ?? sql.param(col.onUpdateFn(), col);
|
|
3606
|
+
const res = sql`${sql.identifier(this.casing.getColumnCasing(col))} = ${value}`;
|
|
3607
|
+
if (i < setSize - 1) {
|
|
3608
|
+
return [res, sql.raw(", ")];
|
|
3609
|
+
}
|
|
3610
|
+
return [res];
|
|
3611
|
+
}));
|
|
3612
|
+
}
|
|
3613
|
+
buildUpdateQuery({ table, set, where, returning, withList }) {
|
|
3614
|
+
const withSql = this.buildWithCTE(withList);
|
|
3615
|
+
const setSql = this.buildUpdateSet(table, set);
|
|
3616
|
+
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : undefined;
|
|
3617
|
+
const whereSql = where ? sql` where ${where}` : undefined;
|
|
3618
|
+
return sql`${withSql}update ${table} set ${setSql}${whereSql}${returningSql}`;
|
|
3619
|
+
}
|
|
3620
|
+
buildSelection(fields, { isSingleTable = false } = {}) {
|
|
3621
|
+
const columnsLen = fields.length;
|
|
3622
|
+
const chunks = fields.flatMap(({ field }, i) => {
|
|
3623
|
+
const chunk = [];
|
|
3624
|
+
if (is(field, SQL.Aliased) && field.isSelectionField) {
|
|
3625
|
+
chunk.push(sql.identifier(field.fieldAlias));
|
|
3626
|
+
} else if (is(field, SQL.Aliased) || is(field, SQL)) {
|
|
3627
|
+
const query = is(field, SQL.Aliased) ? field.sql : field;
|
|
3628
|
+
if (isSingleTable) {
|
|
3629
|
+
chunk.push(new SQL(query.queryChunks.map((c) => {
|
|
3630
|
+
if (is(c, PgColumn)) {
|
|
3631
|
+
return sql.identifier(this.casing.getColumnCasing(c));
|
|
3632
|
+
}
|
|
3633
|
+
return c;
|
|
3634
|
+
})));
|
|
3635
|
+
} else {
|
|
3636
|
+
chunk.push(query);
|
|
3637
|
+
}
|
|
3638
|
+
if (is(field, SQL.Aliased)) {
|
|
3639
|
+
chunk.push(sql` as ${sql.identifier(field.fieldAlias)}`);
|
|
3640
|
+
}
|
|
3641
|
+
} else if (is(field, Column)) {
|
|
3642
|
+
if (isSingleTable) {
|
|
3643
|
+
chunk.push(sql.identifier(this.casing.getColumnCasing(field)));
|
|
3644
|
+
} else {
|
|
3645
|
+
chunk.push(field);
|
|
3646
|
+
}
|
|
3647
|
+
}
|
|
3648
|
+
if (i < columnsLen - 1) {
|
|
3649
|
+
chunk.push(sql`, `);
|
|
3650
|
+
}
|
|
3651
|
+
return chunk;
|
|
3652
|
+
});
|
|
3653
|
+
return sql.join(chunks);
|
|
3654
|
+
}
|
|
3655
|
+
buildSelectQuery({
|
|
3656
|
+
withList,
|
|
3657
|
+
fields,
|
|
3658
|
+
fieldsFlat,
|
|
3659
|
+
where,
|
|
3660
|
+
having,
|
|
3661
|
+
table,
|
|
3662
|
+
joins,
|
|
3663
|
+
orderBy,
|
|
3664
|
+
groupBy,
|
|
3665
|
+
limit,
|
|
3666
|
+
offset,
|
|
3667
|
+
lockingClause,
|
|
3668
|
+
distinct,
|
|
3669
|
+
setOperators
|
|
3670
|
+
}) {
|
|
3671
|
+
const fieldsList = fieldsFlat ?? orderSelectedFields(fields);
|
|
3672
|
+
for (const f of fieldsList) {
|
|
3673
|
+
if (is(f.field, Column) && getTableName(f.field.table) !== (is(table, Subquery) ? table._.alias : is(table, PgViewBase) ? table[ViewBaseConfig].name : is(table, SQL) ? undefined : getTableName(table)) && !((table2) => joins?.some(({ alias }) => alias === (table2[Table.Symbol.IsAlias] ? getTableName(table2) : table2[Table.Symbol.BaseName])))(f.field.table)) {
|
|
3674
|
+
const tableName = getTableName(f.field.table);
|
|
3675
|
+
throw new Error(`Your "${f.path.join("->")}" field references a column "${tableName}"."${f.field.name}", but the table "${tableName}" is not part of the query! Did you forget to join it?`);
|
|
3676
|
+
}
|
|
3677
|
+
}
|
|
3678
|
+
const isSingleTable = !joins || joins.length === 0;
|
|
3679
|
+
const withSql = this.buildWithCTE(withList);
|
|
3680
|
+
let distinctSql;
|
|
3681
|
+
if (distinct) {
|
|
3682
|
+
distinctSql = distinct === true ? sql` distinct` : sql` distinct on (${sql.join(distinct.on, sql`, `)})`;
|
|
3683
|
+
}
|
|
3684
|
+
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
|
3685
|
+
const tableSql = (() => {
|
|
3686
|
+
if (is(table, Table) && table[Table.Symbol.OriginalName] !== table[Table.Symbol.Name]) {
|
|
3687
|
+
let fullName = sql`${sql.identifier(table[Table.Symbol.OriginalName])}`;
|
|
3688
|
+
if (table[Table.Symbol.Schema]) {
|
|
3689
|
+
fullName = sql`${sql.identifier(table[Table.Symbol.Schema])}.${fullName}`;
|
|
3690
|
+
}
|
|
3691
|
+
return sql`${fullName} ${sql.identifier(table[Table.Symbol.Name])}`;
|
|
3692
|
+
}
|
|
3693
|
+
return table;
|
|
3694
|
+
})();
|
|
3695
|
+
const joinsArray = [];
|
|
3696
|
+
if (joins) {
|
|
3697
|
+
for (const [index, joinMeta] of joins.entries()) {
|
|
3698
|
+
if (index === 0) {
|
|
3699
|
+
joinsArray.push(sql` `);
|
|
3700
|
+
}
|
|
3701
|
+
const table2 = joinMeta.table;
|
|
3702
|
+
const lateralSql = joinMeta.lateral ? sql` lateral` : undefined;
|
|
3703
|
+
if (is(table2, PgTable)) {
|
|
3704
|
+
const tableName = table2[PgTable.Symbol.Name];
|
|
3705
|
+
const tableSchema = table2[PgTable.Symbol.Schema];
|
|
3706
|
+
const origTableName = table2[PgTable.Symbol.OriginalName];
|
|
3707
|
+
const alias = tableName === origTableName ? undefined : joinMeta.alias;
|
|
3708
|
+
joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : undefined}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`);
|
|
3709
|
+
} else if (is(table2, View)) {
|
|
3710
|
+
const viewName = table2[ViewBaseConfig].name;
|
|
3711
|
+
const viewSchema = table2[ViewBaseConfig].schema;
|
|
3712
|
+
const origViewName = table2[ViewBaseConfig].originalName;
|
|
3713
|
+
const alias = viewName === origViewName ? undefined : joinMeta.alias;
|
|
3714
|
+
joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${viewSchema ? sql`${sql.identifier(viewSchema)}.` : undefined}${sql.identifier(origViewName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`);
|
|
3715
|
+
} else {
|
|
3716
|
+
joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table2} on ${joinMeta.on}`);
|
|
3717
|
+
}
|
|
3718
|
+
if (index < joins.length - 1) {
|
|
3719
|
+
joinsArray.push(sql` `);
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
}
|
|
3723
|
+
const joinsSql = sql.join(joinsArray);
|
|
3724
|
+
const whereSql = where ? sql` where ${where}` : undefined;
|
|
3725
|
+
const havingSql = having ? sql` having ${having}` : undefined;
|
|
3726
|
+
let orderBySql;
|
|
3727
|
+
if (orderBy && orderBy.length > 0) {
|
|
3728
|
+
orderBySql = sql` order by ${sql.join(orderBy, sql`, `)}`;
|
|
3729
|
+
}
|
|
3730
|
+
let groupBySql;
|
|
3731
|
+
if (groupBy && groupBy.length > 0) {
|
|
3732
|
+
groupBySql = sql` group by ${sql.join(groupBy, sql`, `)}`;
|
|
3733
|
+
}
|
|
3734
|
+
const limitSql = typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : undefined;
|
|
3735
|
+
const offsetSql = offset ? sql` offset ${offset}` : undefined;
|
|
3736
|
+
const lockingClauseSql = sql.empty();
|
|
3737
|
+
if (lockingClause) {
|
|
3738
|
+
const clauseSql = sql` for ${sql.raw(lockingClause.strength)}`;
|
|
3739
|
+
if (lockingClause.config.of) {
|
|
3740
|
+
clauseSql.append(sql` of ${sql.join(Array.isArray(lockingClause.config.of) ? lockingClause.config.of : [lockingClause.config.of], sql`, `)}`);
|
|
3741
|
+
}
|
|
3742
|
+
if (lockingClause.config.noWait) {
|
|
3743
|
+
clauseSql.append(sql` no wait`);
|
|
3744
|
+
} else if (lockingClause.config.skipLocked) {
|
|
3745
|
+
clauseSql.append(sql` skip locked`);
|
|
3746
|
+
}
|
|
3747
|
+
lockingClauseSql.append(clauseSql);
|
|
3748
|
+
}
|
|
3749
|
+
const finalQuery = sql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClauseSql}`;
|
|
3750
|
+
if (setOperators.length > 0) {
|
|
3751
|
+
return this.buildSetOperations(finalQuery, setOperators);
|
|
3752
|
+
}
|
|
3753
|
+
return finalQuery;
|
|
3754
|
+
}
|
|
3755
|
+
buildSetOperations(leftSelect, setOperators) {
|
|
3756
|
+
const [setOperator, ...rest] = setOperators;
|
|
3757
|
+
if (!setOperator) {
|
|
3758
|
+
throw new Error("Cannot pass undefined values to any set operator");
|
|
3759
|
+
}
|
|
3760
|
+
if (rest.length === 0) {
|
|
3761
|
+
return this.buildSetOperationQuery({ leftSelect, setOperator });
|
|
3762
|
+
}
|
|
3763
|
+
return this.buildSetOperations(this.buildSetOperationQuery({ leftSelect, setOperator }), rest);
|
|
3764
|
+
}
|
|
3765
|
+
buildSetOperationQuery({
|
|
3766
|
+
leftSelect,
|
|
3767
|
+
setOperator: { type, isAll, rightSelect, limit, orderBy, offset }
|
|
3768
|
+
}) {
|
|
3769
|
+
const leftChunk = sql`(${leftSelect.getSQL()}) `;
|
|
3770
|
+
const rightChunk = sql`(${rightSelect.getSQL()})`;
|
|
3771
|
+
let orderBySql;
|
|
3772
|
+
if (orderBy && orderBy.length > 0) {
|
|
3773
|
+
const orderByValues = [];
|
|
3774
|
+
for (const singleOrderBy of orderBy) {
|
|
3775
|
+
if (is(singleOrderBy, PgColumn)) {
|
|
3776
|
+
orderByValues.push(sql.identifier(singleOrderBy.name));
|
|
3777
|
+
} else if (is(singleOrderBy, SQL)) {
|
|
3778
|
+
for (let i = 0;i < singleOrderBy.queryChunks.length; i++) {
|
|
3779
|
+
const chunk = singleOrderBy.queryChunks[i];
|
|
3780
|
+
if (is(chunk, PgColumn)) {
|
|
3781
|
+
singleOrderBy.queryChunks[i] = sql.identifier(chunk.name);
|
|
3782
|
+
}
|
|
3783
|
+
}
|
|
3784
|
+
orderByValues.push(sql`${singleOrderBy}`);
|
|
3785
|
+
} else {
|
|
3786
|
+
orderByValues.push(sql`${singleOrderBy}`);
|
|
3787
|
+
}
|
|
3788
|
+
}
|
|
3789
|
+
orderBySql = sql` order by ${sql.join(orderByValues, sql`, `)} `;
|
|
3790
|
+
}
|
|
3791
|
+
const limitSql = typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : undefined;
|
|
3792
|
+
const operatorChunk = sql.raw(`${type} ${isAll ? "all " : ""}`);
|
|
3793
|
+
const offsetSql = offset ? sql` offset ${offset}` : undefined;
|
|
3794
|
+
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
|
3795
|
+
}
|
|
3796
|
+
buildInsertQuery({ table, values: values2, onConflict, returning, withList }) {
|
|
3797
|
+
const valuesSqlList = [];
|
|
3798
|
+
const columns = table[Table.Symbol.Columns];
|
|
3799
|
+
const colEntries = Object.entries(columns).filter(([_, col]) => !col.shouldDisableInsert());
|
|
3800
|
+
const insertOrder = colEntries.map(([, column]) => sql.identifier(this.casing.getColumnCasing(column)));
|
|
3801
|
+
for (const [valueIndex, value] of values2.entries()) {
|
|
3802
|
+
const valueList = [];
|
|
3803
|
+
for (const [fieldName, col] of colEntries) {
|
|
3804
|
+
const colValue = value[fieldName];
|
|
3805
|
+
if (colValue === undefined || is(colValue, Param) && colValue.value === undefined) {
|
|
3806
|
+
if (col.defaultFn !== undefined) {
|
|
3807
|
+
const defaultFnResult = col.defaultFn();
|
|
3808
|
+
const defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
|
3809
|
+
valueList.push(defaultValue);
|
|
3810
|
+
} else if (!col.default && col.onUpdateFn !== undefined) {
|
|
3811
|
+
const onUpdateFnResult = col.onUpdateFn();
|
|
3812
|
+
const newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
|
3813
|
+
valueList.push(newValue);
|
|
3814
|
+
} else {
|
|
3815
|
+
valueList.push(sql`default`);
|
|
3816
|
+
}
|
|
3817
|
+
} else {
|
|
3818
|
+
valueList.push(colValue);
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
valuesSqlList.push(valueList);
|
|
3822
|
+
if (valueIndex < values2.length - 1) {
|
|
3823
|
+
valuesSqlList.push(sql`, `);
|
|
3824
|
+
}
|
|
3825
|
+
}
|
|
3826
|
+
const withSql = this.buildWithCTE(withList);
|
|
3827
|
+
const valuesSql = sql.join(valuesSqlList);
|
|
3828
|
+
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : undefined;
|
|
3829
|
+
const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : undefined;
|
|
3830
|
+
return sql`${withSql}insert into ${table} ${insertOrder} values ${valuesSql}${onConflictSql}${returningSql}`;
|
|
3831
|
+
}
|
|
3832
|
+
buildRefreshMaterializedViewQuery({ view, concurrently, withNoData }) {
|
|
3833
|
+
const concurrentlySql = concurrently ? sql` concurrently` : undefined;
|
|
3834
|
+
const withNoDataSql = withNoData ? sql` with no data` : undefined;
|
|
3835
|
+
return sql`refresh materialized view${concurrentlySql} ${view}${withNoDataSql}`;
|
|
3836
|
+
}
|
|
3837
|
+
prepareTyping(encoder) {
|
|
3838
|
+
if (is(encoder, PgJsonb) || is(encoder, PgJson)) {
|
|
3839
|
+
return "json";
|
|
3840
|
+
} else if (is(encoder, PgNumeric)) {
|
|
3841
|
+
return "decimal";
|
|
3842
|
+
} else if (is(encoder, PgTime)) {
|
|
3843
|
+
return "time";
|
|
3844
|
+
} else if (is(encoder, PgTimestamp) || is(encoder, PgTimestampString)) {
|
|
3845
|
+
return "timestamp";
|
|
3846
|
+
} else if (is(encoder, PgDate) || is(encoder, PgDateString)) {
|
|
3847
|
+
return "date";
|
|
3848
|
+
} else if (is(encoder, PgUUID)) {
|
|
3849
|
+
return "uuid";
|
|
3850
|
+
} else {
|
|
3851
|
+
return "none";
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3854
|
+
sqlToQuery(sql2, invokeSource) {
|
|
3855
|
+
return sql2.toQuery({
|
|
3856
|
+
casing: this.casing,
|
|
3857
|
+
escapeName: this.escapeName,
|
|
3858
|
+
escapeParam: this.escapeParam,
|
|
3859
|
+
escapeString: this.escapeString,
|
|
3860
|
+
prepareTyping: this.prepareTyping,
|
|
3861
|
+
invokeSource
|
|
3862
|
+
});
|
|
3863
|
+
}
|
|
3864
|
+
buildRelationalQueryWithoutPK({
|
|
3865
|
+
fullSchema,
|
|
3866
|
+
schema,
|
|
3867
|
+
tableNamesMap,
|
|
3868
|
+
table,
|
|
3869
|
+
tableConfig,
|
|
3870
|
+
queryConfig: config,
|
|
3871
|
+
tableAlias,
|
|
3872
|
+
nestedQueryRelation,
|
|
3873
|
+
joinOn
|
|
3874
|
+
}) {
|
|
3875
|
+
let selection = [];
|
|
3876
|
+
let limit, offset, orderBy = [], where;
|
|
3877
|
+
const joins = [];
|
|
3878
|
+
if (config === true) {
|
|
3879
|
+
const selectionEntries = Object.entries(tableConfig.columns);
|
|
3880
|
+
selection = selectionEntries.map(([key, value]) => ({
|
|
3881
|
+
dbKey: value.name,
|
|
3882
|
+
tsKey: key,
|
|
3883
|
+
field: aliasedTableColumn(value, tableAlias),
|
|
3884
|
+
relationTableTsKey: undefined,
|
|
3885
|
+
isJson: false,
|
|
3886
|
+
selection: []
|
|
3887
|
+
}));
|
|
3888
|
+
} else {
|
|
3889
|
+
const aliasedColumns = Object.fromEntries(Object.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)]));
|
|
3890
|
+
if (config.where) {
|
|
3891
|
+
const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, getOperators()) : config.where;
|
|
3892
|
+
where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
|
|
3893
|
+
}
|
|
3894
|
+
const fieldsSelection = [];
|
|
3895
|
+
let selectedColumns = [];
|
|
3896
|
+
if (config.columns) {
|
|
3897
|
+
let isIncludeMode = false;
|
|
3898
|
+
for (const [field, value] of Object.entries(config.columns)) {
|
|
3899
|
+
if (value === undefined) {
|
|
3900
|
+
continue;
|
|
3901
|
+
}
|
|
3902
|
+
if (field in tableConfig.columns) {
|
|
3903
|
+
if (!isIncludeMode && value === true) {
|
|
3904
|
+
isIncludeMode = true;
|
|
3905
|
+
}
|
|
3906
|
+
selectedColumns.push(field);
|
|
3907
|
+
}
|
|
3908
|
+
}
|
|
3909
|
+
if (selectedColumns.length > 0) {
|
|
3910
|
+
selectedColumns = isIncludeMode ? selectedColumns.filter((c) => config.columns?.[c] === true) : Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));
|
|
3911
|
+
}
|
|
3912
|
+
} else {
|
|
3913
|
+
selectedColumns = Object.keys(tableConfig.columns);
|
|
3914
|
+
}
|
|
3915
|
+
for (const field of selectedColumns) {
|
|
3916
|
+
const column = tableConfig.columns[field];
|
|
3917
|
+
fieldsSelection.push({ tsKey: field, value: column });
|
|
3918
|
+
}
|
|
3919
|
+
let selectedRelations = [];
|
|
3920
|
+
if (config.with) {
|
|
3921
|
+
selectedRelations = Object.entries(config.with).filter((entry) => !!entry[1]).map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey] }));
|
|
3922
|
+
}
|
|
3923
|
+
let extras;
|
|
3924
|
+
if (config.extras) {
|
|
3925
|
+
extras = typeof config.extras === "function" ? config.extras(aliasedColumns, { sql }) : config.extras;
|
|
3926
|
+
for (const [tsKey, value] of Object.entries(extras)) {
|
|
3927
|
+
fieldsSelection.push({
|
|
3928
|
+
tsKey,
|
|
3929
|
+
value: mapColumnsInAliasedSQLToAlias(value, tableAlias)
|
|
3930
|
+
});
|
|
3931
|
+
}
|
|
3932
|
+
}
|
|
3933
|
+
for (const { tsKey, value } of fieldsSelection) {
|
|
3934
|
+
selection.push({
|
|
3935
|
+
dbKey: is(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey].name,
|
|
3936
|
+
tsKey,
|
|
3937
|
+
field: is(value, Column) ? aliasedTableColumn(value, tableAlias) : value,
|
|
3938
|
+
relationTableTsKey: undefined,
|
|
3939
|
+
isJson: false,
|
|
3940
|
+
selection: []
|
|
3941
|
+
});
|
|
3942
|
+
}
|
|
3943
|
+
let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, getOrderByOperators()) : config.orderBy ?? [];
|
|
3944
|
+
if (!Array.isArray(orderByOrig)) {
|
|
3945
|
+
orderByOrig = [orderByOrig];
|
|
3946
|
+
}
|
|
3947
|
+
orderBy = orderByOrig.map((orderByValue) => {
|
|
3948
|
+
if (is(orderByValue, Column)) {
|
|
3949
|
+
return aliasedTableColumn(orderByValue, tableAlias);
|
|
3950
|
+
}
|
|
3951
|
+
return mapColumnsInSQLToAlias(orderByValue, tableAlias);
|
|
3952
|
+
});
|
|
3953
|
+
limit = config.limit;
|
|
3954
|
+
offset = config.offset;
|
|
3955
|
+
for (const {
|
|
3956
|
+
tsKey: selectedRelationTsKey,
|
|
3957
|
+
queryConfig: selectedRelationConfigValue,
|
|
3958
|
+
relation
|
|
3959
|
+
} of selectedRelations) {
|
|
3960
|
+
const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
|
|
3961
|
+
const relationTableName = getTableUniqueName(relation.referencedTable);
|
|
3962
|
+
const relationTableTsName = tableNamesMap[relationTableName];
|
|
3963
|
+
const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
|
|
3964
|
+
const joinOn2 = and(...normalizedRelation.fields.map((field2, i) => eq(aliasedTableColumn(normalizedRelation.references[i], relationTableAlias), aliasedTableColumn(field2, tableAlias))));
|
|
3965
|
+
const builtRelation = this.buildRelationalQueryWithoutPK({
|
|
3966
|
+
fullSchema,
|
|
3967
|
+
schema,
|
|
3968
|
+
tableNamesMap,
|
|
3969
|
+
table: fullSchema[relationTableTsName],
|
|
3970
|
+
tableConfig: schema[relationTableTsName],
|
|
3971
|
+
queryConfig: is(relation, One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
|
|
3972
|
+
tableAlias: relationTableAlias,
|
|
3973
|
+
joinOn: joinOn2,
|
|
3974
|
+
nestedQueryRelation: relation
|
|
3975
|
+
});
|
|
3976
|
+
const field = sql`${sql.identifier(relationTableAlias)}.${sql.identifier("data")}`.as(selectedRelationTsKey);
|
|
3977
|
+
joins.push({
|
|
3978
|
+
on: sql`true`,
|
|
3979
|
+
table: new Subquery(builtRelation.sql, {}, relationTableAlias),
|
|
3980
|
+
alias: relationTableAlias,
|
|
3981
|
+
joinType: "left",
|
|
3982
|
+
lateral: true
|
|
3983
|
+
});
|
|
3984
|
+
selection.push({
|
|
3985
|
+
dbKey: selectedRelationTsKey,
|
|
3986
|
+
tsKey: selectedRelationTsKey,
|
|
3987
|
+
field,
|
|
3988
|
+
relationTableTsKey: relationTableTsName,
|
|
3989
|
+
isJson: true,
|
|
3990
|
+
selection: builtRelation.selection
|
|
3991
|
+
});
|
|
3992
|
+
}
|
|
3993
|
+
}
|
|
3994
|
+
if (selection.length === 0) {
|
|
3995
|
+
throw new DrizzleError({ message: `No fields selected for table "${tableConfig.tsName}" ("${tableAlias}")` });
|
|
3996
|
+
}
|
|
3997
|
+
let result;
|
|
3998
|
+
where = and(joinOn, where);
|
|
3999
|
+
if (nestedQueryRelation) {
|
|
4000
|
+
let field = sql`json_build_array(${sql.join(selection.map(({ field: field2, tsKey, isJson }) => isJson ? sql`${sql.identifier(`${tableAlias}_${tsKey}`)}.${sql.identifier("data")}` : is(field2, SQL.Aliased) ? field2.sql : field2), sql`, `)})`;
|
|
4001
|
+
if (is(nestedQueryRelation, Many)) {
|
|
4002
|
+
field = sql`coalesce(json_agg(${field}${orderBy.length > 0 ? sql` order by ${sql.join(orderBy, sql`, `)}` : undefined}), '[]'::json)`;
|
|
4003
|
+
}
|
|
4004
|
+
const nestedSelection = [{
|
|
4005
|
+
dbKey: "data",
|
|
4006
|
+
tsKey: "data",
|
|
4007
|
+
field: field.as("data"),
|
|
4008
|
+
isJson: true,
|
|
4009
|
+
relationTableTsKey: tableConfig.tsName,
|
|
4010
|
+
selection
|
|
4011
|
+
}];
|
|
4012
|
+
const needsSubquery = limit !== undefined || offset !== undefined || orderBy.length > 0;
|
|
4013
|
+
if (needsSubquery) {
|
|
4014
|
+
result = this.buildSelectQuery({
|
|
4015
|
+
table: aliasedTable(table, tableAlias),
|
|
4016
|
+
fields: {},
|
|
4017
|
+
fieldsFlat: [{
|
|
4018
|
+
path: [],
|
|
4019
|
+
field: sql.raw("*")
|
|
4020
|
+
}],
|
|
4021
|
+
where,
|
|
4022
|
+
limit,
|
|
4023
|
+
offset,
|
|
4024
|
+
orderBy,
|
|
4025
|
+
setOperators: []
|
|
4026
|
+
});
|
|
4027
|
+
where = undefined;
|
|
4028
|
+
limit = undefined;
|
|
4029
|
+
offset = undefined;
|
|
4030
|
+
orderBy = [];
|
|
4031
|
+
} else {
|
|
4032
|
+
result = aliasedTable(table, tableAlias);
|
|
4033
|
+
}
|
|
4034
|
+
result = this.buildSelectQuery({
|
|
4035
|
+
table: is(result, PgTable) ? result : new Subquery(result, {}, tableAlias),
|
|
4036
|
+
fields: {},
|
|
4037
|
+
fieldsFlat: nestedSelection.map(({ field: field2 }) => ({
|
|
4038
|
+
path: [],
|
|
4039
|
+
field: is(field2, Column) ? aliasedTableColumn(field2, tableAlias) : field2
|
|
4040
|
+
})),
|
|
4041
|
+
joins,
|
|
4042
|
+
where,
|
|
4043
|
+
limit,
|
|
4044
|
+
offset,
|
|
4045
|
+
orderBy,
|
|
4046
|
+
setOperators: []
|
|
4047
|
+
});
|
|
4048
|
+
} else {
|
|
4049
|
+
result = this.buildSelectQuery({
|
|
4050
|
+
table: aliasedTable(table, tableAlias),
|
|
4051
|
+
fields: {},
|
|
4052
|
+
fieldsFlat: selection.map(({ field }) => ({
|
|
4053
|
+
path: [],
|
|
4054
|
+
field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field
|
|
4055
|
+
})),
|
|
4056
|
+
joins,
|
|
4057
|
+
where,
|
|
4058
|
+
limit,
|
|
4059
|
+
offset,
|
|
4060
|
+
orderBy,
|
|
4061
|
+
setOperators: []
|
|
4062
|
+
});
|
|
4063
|
+
}
|
|
4064
|
+
return {
|
|
4065
|
+
tableTsKey: tableConfig.tsName,
|
|
4066
|
+
sql: result,
|
|
4067
|
+
selection
|
|
4068
|
+
};
|
|
4069
|
+
}
|
|
4070
|
+
}
|
|
4071
|
+
|
|
4072
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/selection-proxy.js
|
|
4073
|
+
class SelectionProxyHandler {
|
|
4074
|
+
static [entityKind] = "SelectionProxyHandler";
|
|
4075
|
+
config;
|
|
4076
|
+
constructor(config) {
|
|
4077
|
+
this.config = { ...config };
|
|
4078
|
+
}
|
|
4079
|
+
get(subquery, prop) {
|
|
4080
|
+
if (prop === "_") {
|
|
4081
|
+
return {
|
|
4082
|
+
...subquery["_"],
|
|
4083
|
+
selectedFields: new Proxy(subquery._.selectedFields, this)
|
|
4084
|
+
};
|
|
4085
|
+
}
|
|
4086
|
+
if (prop === ViewBaseConfig) {
|
|
4087
|
+
return {
|
|
4088
|
+
...subquery[ViewBaseConfig],
|
|
4089
|
+
selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
|
|
4090
|
+
};
|
|
4091
|
+
}
|
|
4092
|
+
if (typeof prop === "symbol") {
|
|
4093
|
+
return subquery[prop];
|
|
4094
|
+
}
|
|
4095
|
+
const columns = is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery;
|
|
4096
|
+
const value = columns[prop];
|
|
4097
|
+
if (is(value, SQL.Aliased)) {
|
|
4098
|
+
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) {
|
|
4099
|
+
return value.sql;
|
|
4100
|
+
}
|
|
4101
|
+
const newValue = value.clone();
|
|
4102
|
+
newValue.isSelectionField = true;
|
|
4103
|
+
return newValue;
|
|
4104
|
+
}
|
|
4105
|
+
if (is(value, SQL)) {
|
|
4106
|
+
if (this.config.sqlBehavior === "sql") {
|
|
4107
|
+
return value;
|
|
4108
|
+
}
|
|
4109
|
+
throw new Error(`You tried to reference "${prop}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`);
|
|
4110
|
+
}
|
|
4111
|
+
if (is(value, Column)) {
|
|
4112
|
+
if (this.config.alias) {
|
|
4113
|
+
return new Proxy(value, new ColumnAliasProxyHandler(new Proxy(value.table, new TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false))));
|
|
4114
|
+
}
|
|
4115
|
+
return value;
|
|
4116
|
+
}
|
|
4117
|
+
if (typeof value !== "object" || value === null) {
|
|
4118
|
+
return value;
|
|
4119
|
+
}
|
|
4120
|
+
return new Proxy(value, new SelectionProxyHandler(this.config));
|
|
4121
|
+
}
|
|
4122
|
+
}
|
|
4123
|
+
|
|
4124
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/query-builders/query-builder.js
|
|
4125
|
+
class TypedQueryBuilder {
|
|
4126
|
+
static [entityKind] = "TypedQueryBuilder";
|
|
4127
|
+
getSelectedFields() {
|
|
4128
|
+
return this._.selectedFields;
|
|
4129
|
+
}
|
|
4130
|
+
}
|
|
4131
|
+
|
|
4132
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/query-builders/select.js
|
|
4133
|
+
function createSetOperator(type, isAll) {
|
|
4134
|
+
return (leftSelect, rightSelect, ...restSelects) => {
|
|
4135
|
+
const setOperators = [rightSelect, ...restSelects].map((select2) => ({
|
|
4136
|
+
type,
|
|
4137
|
+
isAll,
|
|
4138
|
+
rightSelect: select2
|
|
4139
|
+
}));
|
|
4140
|
+
for (const setOperator of setOperators) {
|
|
4141
|
+
if (!haveSameKeys(leftSelect.getSelectedFields(), setOperator.rightSelect.getSelectedFields())) {
|
|
4142
|
+
throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");
|
|
4143
|
+
}
|
|
4144
|
+
}
|
|
4145
|
+
return leftSelect.addSetOperators(setOperators);
|
|
4146
|
+
};
|
|
4147
|
+
}
|
|
4148
|
+
|
|
4149
|
+
class PgSelectBuilder {
|
|
4150
|
+
static [entityKind] = "PgSelectBuilder";
|
|
4151
|
+
fields;
|
|
4152
|
+
session;
|
|
4153
|
+
dialect;
|
|
4154
|
+
withList = [];
|
|
4155
|
+
distinct;
|
|
4156
|
+
constructor(config) {
|
|
4157
|
+
this.fields = config.fields;
|
|
4158
|
+
this.session = config.session;
|
|
4159
|
+
this.dialect = config.dialect;
|
|
4160
|
+
if (config.withList) {
|
|
4161
|
+
this.withList = config.withList;
|
|
4162
|
+
}
|
|
4163
|
+
this.distinct = config.distinct;
|
|
4164
|
+
}
|
|
4165
|
+
from(source) {
|
|
4166
|
+
const isPartialSelect = !!this.fields;
|
|
4167
|
+
let fields;
|
|
4168
|
+
if (this.fields) {
|
|
4169
|
+
fields = this.fields;
|
|
4170
|
+
} else if (is(source, Subquery)) {
|
|
4171
|
+
fields = Object.fromEntries(Object.keys(source._.selectedFields).map((key) => [key, source[key]]));
|
|
4172
|
+
} else if (is(source, PgViewBase)) {
|
|
4173
|
+
fields = source[ViewBaseConfig].selectedFields;
|
|
4174
|
+
} else if (is(source, SQL)) {
|
|
4175
|
+
fields = {};
|
|
4176
|
+
} else {
|
|
4177
|
+
fields = getTableColumns(source);
|
|
4178
|
+
}
|
|
4179
|
+
return new PgSelectBase({
|
|
4180
|
+
table: source,
|
|
4181
|
+
fields,
|
|
4182
|
+
isPartialSelect,
|
|
4183
|
+
session: this.session,
|
|
4184
|
+
dialect: this.dialect,
|
|
4185
|
+
withList: this.withList,
|
|
4186
|
+
distinct: this.distinct
|
|
4187
|
+
});
|
|
4188
|
+
}
|
|
4189
|
+
}
|
|
4190
|
+
|
|
4191
|
+
class PgSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
4192
|
+
static [entityKind] = "PgSelectQueryBuilder";
|
|
4193
|
+
_;
|
|
4194
|
+
config;
|
|
4195
|
+
joinsNotNullableMap;
|
|
4196
|
+
tableName;
|
|
4197
|
+
isPartialSelect;
|
|
4198
|
+
session;
|
|
4199
|
+
dialect;
|
|
4200
|
+
constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }) {
|
|
4201
|
+
super();
|
|
4202
|
+
this.config = {
|
|
4203
|
+
withList,
|
|
4204
|
+
table,
|
|
4205
|
+
fields: { ...fields },
|
|
4206
|
+
distinct,
|
|
4207
|
+
setOperators: []
|
|
4208
|
+
};
|
|
4209
|
+
this.isPartialSelect = isPartialSelect;
|
|
4210
|
+
this.session = session;
|
|
4211
|
+
this.dialect = dialect;
|
|
4212
|
+
this._ = {
|
|
4213
|
+
selectedFields: fields
|
|
4214
|
+
};
|
|
4215
|
+
this.tableName = getTableLikeName(table);
|
|
4216
|
+
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
|
4217
|
+
}
|
|
4218
|
+
createJoin(joinType) {
|
|
4219
|
+
return (table, on) => {
|
|
4220
|
+
const baseTableName = this.tableName;
|
|
4221
|
+
const tableName = getTableLikeName(table);
|
|
4222
|
+
if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) {
|
|
4223
|
+
throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
4224
|
+
}
|
|
4225
|
+
if (!this.isPartialSelect) {
|
|
4226
|
+
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") {
|
|
4227
|
+
this.config.fields = {
|
|
4228
|
+
[baseTableName]: this.config.fields
|
|
4229
|
+
};
|
|
4230
|
+
}
|
|
4231
|
+
if (typeof tableName === "string" && !is(table, SQL)) {
|
|
4232
|
+
const selection = is(table, Subquery) ? table._.selectedFields : is(table, View) ? table[ViewBaseConfig].selectedFields : table[Table.Symbol.Columns];
|
|
4233
|
+
this.config.fields[tableName] = selection;
|
|
4234
|
+
}
|
|
4235
|
+
}
|
|
4236
|
+
if (typeof on === "function") {
|
|
4237
|
+
on = on(new Proxy(this.config.fields, new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })));
|
|
4238
|
+
}
|
|
4239
|
+
if (!this.config.joins) {
|
|
4240
|
+
this.config.joins = [];
|
|
4241
|
+
}
|
|
4242
|
+
this.config.joins.push({ on, table, joinType, alias: tableName });
|
|
4243
|
+
if (typeof tableName === "string") {
|
|
4244
|
+
switch (joinType) {
|
|
4245
|
+
case "left": {
|
|
4246
|
+
this.joinsNotNullableMap[tableName] = false;
|
|
4247
|
+
break;
|
|
4248
|
+
}
|
|
4249
|
+
case "right": {
|
|
4250
|
+
this.joinsNotNullableMap = Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]));
|
|
4251
|
+
this.joinsNotNullableMap[tableName] = true;
|
|
4252
|
+
break;
|
|
4253
|
+
}
|
|
4254
|
+
case "inner": {
|
|
4255
|
+
this.joinsNotNullableMap[tableName] = true;
|
|
4256
|
+
break;
|
|
4257
|
+
}
|
|
4258
|
+
case "full": {
|
|
4259
|
+
this.joinsNotNullableMap = Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]));
|
|
4260
|
+
this.joinsNotNullableMap[tableName] = false;
|
|
4261
|
+
break;
|
|
4262
|
+
}
|
|
4263
|
+
}
|
|
4264
|
+
}
|
|
4265
|
+
return this;
|
|
4266
|
+
};
|
|
4267
|
+
}
|
|
4268
|
+
leftJoin = this.createJoin("left");
|
|
4269
|
+
rightJoin = this.createJoin("right");
|
|
4270
|
+
innerJoin = this.createJoin("inner");
|
|
4271
|
+
fullJoin = this.createJoin("full");
|
|
4272
|
+
createSetOperator(type, isAll) {
|
|
4273
|
+
return (rightSelection) => {
|
|
4274
|
+
const rightSelect = typeof rightSelection === "function" ? rightSelection(getPgSetOperators()) : rightSelection;
|
|
4275
|
+
if (!haveSameKeys(this.getSelectedFields(), rightSelect.getSelectedFields())) {
|
|
4276
|
+
throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");
|
|
4277
|
+
}
|
|
4278
|
+
this.config.setOperators.push({ type, isAll, rightSelect });
|
|
4279
|
+
return this;
|
|
4280
|
+
};
|
|
4281
|
+
}
|
|
4282
|
+
union = this.createSetOperator("union", false);
|
|
4283
|
+
unionAll = this.createSetOperator("union", true);
|
|
4284
|
+
intersect = this.createSetOperator("intersect", false);
|
|
4285
|
+
intersectAll = this.createSetOperator("intersect", true);
|
|
4286
|
+
except = this.createSetOperator("except", false);
|
|
4287
|
+
exceptAll = this.createSetOperator("except", true);
|
|
4288
|
+
addSetOperators(setOperators) {
|
|
4289
|
+
this.config.setOperators.push(...setOperators);
|
|
4290
|
+
return this;
|
|
4291
|
+
}
|
|
4292
|
+
where(where) {
|
|
4293
|
+
if (typeof where === "function") {
|
|
4294
|
+
where = where(new Proxy(this.config.fields, new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })));
|
|
4295
|
+
}
|
|
4296
|
+
this.config.where = where;
|
|
4297
|
+
return this;
|
|
4298
|
+
}
|
|
4299
|
+
having(having) {
|
|
4300
|
+
if (typeof having === "function") {
|
|
4301
|
+
having = having(new Proxy(this.config.fields, new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })));
|
|
4302
|
+
}
|
|
4303
|
+
this.config.having = having;
|
|
4304
|
+
return this;
|
|
4305
|
+
}
|
|
4306
|
+
groupBy(...columns) {
|
|
4307
|
+
if (typeof columns[0] === "function") {
|
|
4308
|
+
const groupBy = columns[0](new Proxy(this.config.fields, new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })));
|
|
4309
|
+
this.config.groupBy = Array.isArray(groupBy) ? groupBy : [groupBy];
|
|
4310
|
+
} else {
|
|
4311
|
+
this.config.groupBy = columns;
|
|
4312
|
+
}
|
|
4313
|
+
return this;
|
|
4314
|
+
}
|
|
4315
|
+
orderBy(...columns) {
|
|
4316
|
+
if (typeof columns[0] === "function") {
|
|
4317
|
+
const orderBy = columns[0](new Proxy(this.config.fields, new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })));
|
|
4318
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
4319
|
+
if (this.config.setOperators.length > 0) {
|
|
4320
|
+
this.config.setOperators.at(-1).orderBy = orderByArray;
|
|
4321
|
+
} else {
|
|
4322
|
+
this.config.orderBy = orderByArray;
|
|
4323
|
+
}
|
|
4324
|
+
} else {
|
|
4325
|
+
const orderByArray = columns;
|
|
4326
|
+
if (this.config.setOperators.length > 0) {
|
|
4327
|
+
this.config.setOperators.at(-1).orderBy = orderByArray;
|
|
4328
|
+
} else {
|
|
4329
|
+
this.config.orderBy = orderByArray;
|
|
4330
|
+
}
|
|
4331
|
+
}
|
|
4332
|
+
return this;
|
|
4333
|
+
}
|
|
4334
|
+
limit(limit) {
|
|
4335
|
+
if (this.config.setOperators.length > 0) {
|
|
4336
|
+
this.config.setOperators.at(-1).limit = limit;
|
|
4337
|
+
} else {
|
|
4338
|
+
this.config.limit = limit;
|
|
4339
|
+
}
|
|
4340
|
+
return this;
|
|
4341
|
+
}
|
|
4342
|
+
offset(offset) {
|
|
4343
|
+
if (this.config.setOperators.length > 0) {
|
|
4344
|
+
this.config.setOperators.at(-1).offset = offset;
|
|
4345
|
+
} else {
|
|
4346
|
+
this.config.offset = offset;
|
|
4347
|
+
}
|
|
4348
|
+
return this;
|
|
4349
|
+
}
|
|
4350
|
+
for(strength, config = {}) {
|
|
4351
|
+
this.config.lockingClause = { strength, config };
|
|
4352
|
+
return this;
|
|
4353
|
+
}
|
|
4354
|
+
getSQL() {
|
|
4355
|
+
return this.dialect.buildSelectQuery(this.config);
|
|
4356
|
+
}
|
|
4357
|
+
toSQL() {
|
|
4358
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
4359
|
+
return rest;
|
|
4360
|
+
}
|
|
4361
|
+
as(alias) {
|
|
4362
|
+
return new Proxy(new Subquery(this.getSQL(), this.config.fields, alias), new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" }));
|
|
4363
|
+
}
|
|
4364
|
+
getSelectedFields() {
|
|
4365
|
+
return new Proxy(this.config.fields, new SelectionProxyHandler({ alias: this.tableName, sqlAliasedBehavior: "alias", sqlBehavior: "error" }));
|
|
4366
|
+
}
|
|
4367
|
+
$dynamic() {
|
|
4368
|
+
return this;
|
|
4369
|
+
}
|
|
4370
|
+
}
|
|
4371
|
+
|
|
4372
|
+
class PgSelectBase extends PgSelectQueryBuilderBase {
|
|
4373
|
+
static [entityKind] = "PgSelect";
|
|
4374
|
+
_prepare(name) {
|
|
4375
|
+
const { session, config, dialect, joinsNotNullableMap } = this;
|
|
4376
|
+
if (!session) {
|
|
4377
|
+
throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
|
|
4378
|
+
}
|
|
4379
|
+
return tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
|
4380
|
+
const fieldsList = orderSelectedFields(config.fields);
|
|
4381
|
+
const query = session.prepareQuery(dialect.sqlToQuery(this.getSQL()), fieldsList, name, true);
|
|
4382
|
+
query.joinsNotNullableMap = joinsNotNullableMap;
|
|
4383
|
+
return query;
|
|
4384
|
+
});
|
|
4385
|
+
}
|
|
4386
|
+
prepare(name) {
|
|
4387
|
+
return this._prepare(name);
|
|
4388
|
+
}
|
|
4389
|
+
execute = (placeholderValues) => {
|
|
4390
|
+
return tracer.startActiveSpan("drizzle.operation", () => {
|
|
4391
|
+
return this._prepare().execute(placeholderValues);
|
|
4392
|
+
});
|
|
4393
|
+
};
|
|
4394
|
+
}
|
|
4395
|
+
applyMixins(PgSelectBase, [QueryPromise]);
|
|
4396
|
+
var getPgSetOperators = () => ({
|
|
4397
|
+
union,
|
|
4398
|
+
unionAll,
|
|
4399
|
+
intersect,
|
|
4400
|
+
intersectAll,
|
|
4401
|
+
except,
|
|
4402
|
+
exceptAll
|
|
4403
|
+
});
|
|
4404
|
+
var union = createSetOperator("union", false);
|
|
4405
|
+
var unionAll = createSetOperator("union", true);
|
|
4406
|
+
var intersect = createSetOperator("intersect", false);
|
|
4407
|
+
var intersectAll = createSetOperator("intersect", true);
|
|
4408
|
+
var except = createSetOperator("except", false);
|
|
4409
|
+
var exceptAll = createSetOperator("except", true);
|
|
4410
|
+
|
|
4411
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/query-builders/query-builder.js
|
|
4412
|
+
class QueryBuilder {
|
|
4413
|
+
static [entityKind] = "PgQueryBuilder";
|
|
4414
|
+
dialect;
|
|
4415
|
+
dialectConfig;
|
|
4416
|
+
constructor(dialect) {
|
|
4417
|
+
this.dialect = is(dialect, PgDialect) ? dialect : undefined;
|
|
4418
|
+
this.dialectConfig = is(dialect, PgDialect) ? undefined : dialect;
|
|
4419
|
+
}
|
|
4420
|
+
$with(alias) {
|
|
4421
|
+
const queryBuilder = this;
|
|
4422
|
+
return {
|
|
4423
|
+
as(qb) {
|
|
4424
|
+
if (typeof qb === "function") {
|
|
4425
|
+
qb = qb(queryBuilder);
|
|
4426
|
+
}
|
|
4427
|
+
return new Proxy(new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true), new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" }));
|
|
4428
|
+
}
|
|
4429
|
+
};
|
|
4430
|
+
}
|
|
4431
|
+
with(...queries) {
|
|
4432
|
+
const self = this;
|
|
4433
|
+
function select2(fields) {
|
|
4434
|
+
return new PgSelectBuilder({
|
|
4435
|
+
fields: fields ?? undefined,
|
|
4436
|
+
session: undefined,
|
|
4437
|
+
dialect: self.getDialect(),
|
|
4438
|
+
withList: queries
|
|
4439
|
+
});
|
|
4440
|
+
}
|
|
4441
|
+
function selectDistinct(fields) {
|
|
4442
|
+
return new PgSelectBuilder({
|
|
4443
|
+
fields: fields ?? undefined,
|
|
4444
|
+
session: undefined,
|
|
4445
|
+
dialect: self.getDialect(),
|
|
4446
|
+
distinct: true
|
|
4447
|
+
});
|
|
4448
|
+
}
|
|
4449
|
+
function selectDistinctOn(on, fields) {
|
|
4450
|
+
return new PgSelectBuilder({
|
|
4451
|
+
fields: fields ?? undefined,
|
|
4452
|
+
session: undefined,
|
|
4453
|
+
dialect: self.getDialect(),
|
|
4454
|
+
distinct: { on }
|
|
4455
|
+
});
|
|
4456
|
+
}
|
|
4457
|
+
return { select: select2, selectDistinct, selectDistinctOn };
|
|
4458
|
+
}
|
|
4459
|
+
select(fields) {
|
|
4460
|
+
return new PgSelectBuilder({
|
|
4461
|
+
fields: fields ?? undefined,
|
|
4462
|
+
session: undefined,
|
|
4463
|
+
dialect: this.getDialect()
|
|
4464
|
+
});
|
|
4465
|
+
}
|
|
4466
|
+
selectDistinct(fields) {
|
|
4467
|
+
return new PgSelectBuilder({
|
|
4468
|
+
fields: fields ?? undefined,
|
|
4469
|
+
session: undefined,
|
|
4470
|
+
dialect: this.getDialect(),
|
|
4471
|
+
distinct: true
|
|
4472
|
+
});
|
|
4473
|
+
}
|
|
4474
|
+
selectDistinctOn(on, fields) {
|
|
4475
|
+
return new PgSelectBuilder({
|
|
4476
|
+
fields: fields ?? undefined,
|
|
4477
|
+
session: undefined,
|
|
4478
|
+
dialect: this.getDialect(),
|
|
4479
|
+
distinct: { on }
|
|
4480
|
+
});
|
|
4481
|
+
}
|
|
4482
|
+
getDialect() {
|
|
4483
|
+
if (!this.dialect) {
|
|
4484
|
+
this.dialect = new PgDialect(this.dialectConfig);
|
|
4485
|
+
}
|
|
4486
|
+
return this.dialect;
|
|
4487
|
+
}
|
|
4488
|
+
}
|
|
4489
|
+
|
|
4490
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/query-builders/refresh-materialized-view.js
|
|
4491
|
+
class PgRefreshMaterializedView extends QueryPromise {
|
|
4492
|
+
constructor(view, session, dialect) {
|
|
4493
|
+
super();
|
|
4494
|
+
this.session = session;
|
|
4495
|
+
this.dialect = dialect;
|
|
4496
|
+
this.config = { view };
|
|
4497
|
+
}
|
|
4498
|
+
static [entityKind] = "PgRefreshMaterializedView";
|
|
4499
|
+
config;
|
|
4500
|
+
concurrently() {
|
|
4501
|
+
if (this.config.withNoData !== undefined) {
|
|
4502
|
+
throw new Error("Cannot use concurrently and withNoData together");
|
|
4503
|
+
}
|
|
4504
|
+
this.config.concurrently = true;
|
|
4505
|
+
return this;
|
|
4506
|
+
}
|
|
4507
|
+
withNoData() {
|
|
4508
|
+
if (this.config.concurrently !== undefined) {
|
|
4509
|
+
throw new Error("Cannot use concurrently and withNoData together");
|
|
4510
|
+
}
|
|
4511
|
+
this.config.withNoData = true;
|
|
4512
|
+
return this;
|
|
4513
|
+
}
|
|
4514
|
+
getSQL() {
|
|
4515
|
+
return this.dialect.buildRefreshMaterializedViewQuery(this.config);
|
|
4516
|
+
}
|
|
4517
|
+
toSQL() {
|
|
4518
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
4519
|
+
return rest;
|
|
4520
|
+
}
|
|
4521
|
+
_prepare(name) {
|
|
4522
|
+
return tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
|
4523
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), undefined, name, true);
|
|
4524
|
+
});
|
|
4525
|
+
}
|
|
4526
|
+
prepare(name) {
|
|
4527
|
+
return this._prepare(name);
|
|
4528
|
+
}
|
|
4529
|
+
execute = (placeholderValues) => {
|
|
4530
|
+
return tracer.startActiveSpan("drizzle.operation", () => {
|
|
4531
|
+
return this._prepare().execute(placeholderValues);
|
|
4532
|
+
});
|
|
4533
|
+
};
|
|
4534
|
+
}
|
|
4535
|
+
|
|
4536
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/query-builders/update.js
|
|
4537
|
+
class PgUpdateBuilder {
|
|
4538
|
+
constructor(table, session, dialect, withList) {
|
|
4539
|
+
this.table = table;
|
|
4540
|
+
this.session = session;
|
|
4541
|
+
this.dialect = dialect;
|
|
4542
|
+
this.withList = withList;
|
|
4543
|
+
}
|
|
4544
|
+
static [entityKind] = "PgUpdateBuilder";
|
|
4545
|
+
set(values2) {
|
|
4546
|
+
return new PgUpdateBase(this.table, mapUpdateSet(this.table, values2), this.session, this.dialect, this.withList);
|
|
4547
|
+
}
|
|
4548
|
+
}
|
|
4549
|
+
|
|
4550
|
+
class PgUpdateBase extends QueryPromise {
|
|
4551
|
+
constructor(table, set, session, dialect, withList) {
|
|
4552
|
+
super();
|
|
4553
|
+
this.session = session;
|
|
4554
|
+
this.dialect = dialect;
|
|
4555
|
+
this.config = { set, table, withList };
|
|
4556
|
+
}
|
|
4557
|
+
static [entityKind] = "PgUpdate";
|
|
4558
|
+
config;
|
|
4559
|
+
where(where) {
|
|
4560
|
+
this.config.where = where;
|
|
4561
|
+
return this;
|
|
4562
|
+
}
|
|
4563
|
+
returning(fields = this.config.table[Table.Symbol.Columns]) {
|
|
4564
|
+
this.config.returning = orderSelectedFields(fields);
|
|
4565
|
+
return this;
|
|
4566
|
+
}
|
|
4567
|
+
getSQL() {
|
|
4568
|
+
return this.dialect.buildUpdateQuery(this.config);
|
|
4569
|
+
}
|
|
4570
|
+
toSQL() {
|
|
4571
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
4572
|
+
return rest;
|
|
4573
|
+
}
|
|
4574
|
+
_prepare(name) {
|
|
4575
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true);
|
|
4576
|
+
}
|
|
4577
|
+
prepare(name) {
|
|
4578
|
+
return this._prepare(name);
|
|
4579
|
+
}
|
|
4580
|
+
execute = (placeholderValues) => {
|
|
4581
|
+
return this._prepare().execute(placeholderValues);
|
|
4582
|
+
};
|
|
4583
|
+
$dynamic() {
|
|
4584
|
+
return this;
|
|
4585
|
+
}
|
|
4586
|
+
}
|
|
4587
|
+
|
|
4588
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/query-builders/count.js
|
|
4589
|
+
class PgCountBuilder extends SQL {
|
|
4590
|
+
constructor(params) {
|
|
4591
|
+
super(PgCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
|
|
4592
|
+
this.params = params;
|
|
4593
|
+
this.mapWith(Number);
|
|
4594
|
+
this.session = params.session;
|
|
4595
|
+
this.sql = PgCountBuilder.buildCount(params.source, params.filters);
|
|
4596
|
+
}
|
|
4597
|
+
sql;
|
|
4598
|
+
static [entityKind] = "PgCountBuilder";
|
|
4599
|
+
[Symbol.toStringTag] = "PgCountBuilder";
|
|
4600
|
+
session;
|
|
4601
|
+
static buildEmbeddedCount(source, filters) {
|
|
4602
|
+
return sql`(select count(*) from ${source}${sql.raw(" where ").if(filters)}${filters})`;
|
|
4603
|
+
}
|
|
4604
|
+
static buildCount(source, filters) {
|
|
4605
|
+
return sql`select count(*) as count from ${source}${sql.raw(" where ").if(filters)}${filters};`;
|
|
4606
|
+
}
|
|
4607
|
+
then(onfulfilled, onrejected) {
|
|
4608
|
+
return Promise.resolve(this.session.count(this.sql)).then(onfulfilled, onrejected);
|
|
4609
|
+
}
|
|
4610
|
+
catch(onRejected) {
|
|
4611
|
+
return this.then(undefined, onRejected);
|
|
4612
|
+
}
|
|
4613
|
+
finally(onFinally) {
|
|
4614
|
+
return this.then((value) => {
|
|
4615
|
+
onFinally?.();
|
|
4616
|
+
return value;
|
|
4617
|
+
}, (reason) => {
|
|
4618
|
+
onFinally?.();
|
|
4619
|
+
throw reason;
|
|
4620
|
+
});
|
|
4621
|
+
}
|
|
4622
|
+
}
|
|
4623
|
+
|
|
4624
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/query-builders/query.js
|
|
4625
|
+
class RelationalQueryBuilder {
|
|
4626
|
+
constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session) {
|
|
4627
|
+
this.fullSchema = fullSchema;
|
|
4628
|
+
this.schema = schema;
|
|
4629
|
+
this.tableNamesMap = tableNamesMap;
|
|
4630
|
+
this.table = table;
|
|
4631
|
+
this.tableConfig = tableConfig;
|
|
4632
|
+
this.dialect = dialect;
|
|
4633
|
+
this.session = session;
|
|
4634
|
+
}
|
|
4635
|
+
static [entityKind] = "PgRelationalQueryBuilder";
|
|
4636
|
+
findMany(config) {
|
|
4637
|
+
return new PgRelationalQuery(this.fullSchema, this.schema, this.tableNamesMap, this.table, this.tableConfig, this.dialect, this.session, config ? config : {}, "many");
|
|
4638
|
+
}
|
|
4639
|
+
findFirst(config) {
|
|
4640
|
+
return new PgRelationalQuery(this.fullSchema, this.schema, this.tableNamesMap, this.table, this.tableConfig, this.dialect, this.session, config ? { ...config, limit: 1 } : { limit: 1 }, "first");
|
|
4641
|
+
}
|
|
4642
|
+
}
|
|
4643
|
+
|
|
4644
|
+
class PgRelationalQuery extends QueryPromise {
|
|
4645
|
+
constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session, config, mode) {
|
|
4646
|
+
super();
|
|
4647
|
+
this.fullSchema = fullSchema;
|
|
4648
|
+
this.schema = schema;
|
|
4649
|
+
this.tableNamesMap = tableNamesMap;
|
|
4650
|
+
this.table = table;
|
|
4651
|
+
this.tableConfig = tableConfig;
|
|
4652
|
+
this.dialect = dialect;
|
|
4653
|
+
this.session = session;
|
|
4654
|
+
this.config = config;
|
|
4655
|
+
this.mode = mode;
|
|
4656
|
+
}
|
|
4657
|
+
static [entityKind] = "PgRelationalQuery";
|
|
4658
|
+
_prepare(name) {
|
|
4659
|
+
return tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
|
4660
|
+
const { query, builtQuery } = this._toSQL();
|
|
4661
|
+
return this.session.prepareQuery(builtQuery, undefined, name, true, (rawRows, mapColumnValue) => {
|
|
4662
|
+
const rows = rawRows.map((row) => mapRelationalRow(this.schema, this.tableConfig, row, query.selection, mapColumnValue));
|
|
4663
|
+
if (this.mode === "first") {
|
|
4664
|
+
return rows[0];
|
|
4665
|
+
}
|
|
4666
|
+
return rows;
|
|
4667
|
+
});
|
|
4668
|
+
});
|
|
4669
|
+
}
|
|
4670
|
+
prepare(name) {
|
|
4671
|
+
return this._prepare(name);
|
|
4672
|
+
}
|
|
4673
|
+
_getQuery() {
|
|
4674
|
+
return this.dialect.buildRelationalQueryWithoutPK({
|
|
4675
|
+
fullSchema: this.fullSchema,
|
|
4676
|
+
schema: this.schema,
|
|
4677
|
+
tableNamesMap: this.tableNamesMap,
|
|
4678
|
+
table: this.table,
|
|
4679
|
+
tableConfig: this.tableConfig,
|
|
4680
|
+
queryConfig: this.config,
|
|
4681
|
+
tableAlias: this.tableConfig.tsName
|
|
4682
|
+
});
|
|
4683
|
+
}
|
|
4684
|
+
getSQL() {
|
|
4685
|
+
return this._getQuery().sql;
|
|
4686
|
+
}
|
|
4687
|
+
_toSQL() {
|
|
4688
|
+
const query = this._getQuery();
|
|
4689
|
+
const builtQuery = this.dialect.sqlToQuery(query.sql);
|
|
4690
|
+
return { query, builtQuery };
|
|
4691
|
+
}
|
|
4692
|
+
toSQL() {
|
|
4693
|
+
return this._toSQL().builtQuery;
|
|
4694
|
+
}
|
|
4695
|
+
execute() {
|
|
4696
|
+
return tracer.startActiveSpan("drizzle.operation", () => {
|
|
4697
|
+
return this._prepare().execute();
|
|
4698
|
+
});
|
|
4699
|
+
}
|
|
4700
|
+
}
|
|
4701
|
+
|
|
4702
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/query-builders/raw.js
|
|
4703
|
+
class PgRaw extends QueryPromise {
|
|
4704
|
+
constructor(execute, sql2, query, mapBatchResult) {
|
|
4705
|
+
super();
|
|
4706
|
+
this.execute = execute;
|
|
4707
|
+
this.sql = sql2;
|
|
4708
|
+
this.query = query;
|
|
4709
|
+
this.mapBatchResult = mapBatchResult;
|
|
4710
|
+
}
|
|
4711
|
+
static [entityKind] = "PgRaw";
|
|
4712
|
+
getSQL() {
|
|
4713
|
+
return this.sql;
|
|
4714
|
+
}
|
|
4715
|
+
getQuery() {
|
|
4716
|
+
return this.query;
|
|
4717
|
+
}
|
|
4718
|
+
mapResult(result, isFromBatch) {
|
|
4719
|
+
return isFromBatch ? this.mapBatchResult(result) : result;
|
|
4720
|
+
}
|
|
4721
|
+
_prepare() {
|
|
4722
|
+
return this;
|
|
4723
|
+
}
|
|
4724
|
+
isResponseInArrayMode() {
|
|
4725
|
+
return false;
|
|
4726
|
+
}
|
|
4727
|
+
}
|
|
4728
|
+
|
|
4729
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/db.js
|
|
4730
|
+
class PgDatabase {
|
|
4731
|
+
constructor(dialect, session, schema) {
|
|
4732
|
+
this.dialect = dialect;
|
|
4733
|
+
this.session = session;
|
|
4734
|
+
this._ = schema ? {
|
|
4735
|
+
schema: schema.schema,
|
|
4736
|
+
fullSchema: schema.fullSchema,
|
|
4737
|
+
tableNamesMap: schema.tableNamesMap,
|
|
4738
|
+
session
|
|
4739
|
+
} : {
|
|
4740
|
+
schema: undefined,
|
|
4741
|
+
fullSchema: {},
|
|
4742
|
+
tableNamesMap: {},
|
|
4743
|
+
session
|
|
4744
|
+
};
|
|
4745
|
+
this.query = {};
|
|
4746
|
+
if (this._.schema) {
|
|
4747
|
+
for (const [tableName, columns] of Object.entries(this._.schema)) {
|
|
4748
|
+
this.query[tableName] = new RelationalQueryBuilder(schema.fullSchema, this._.schema, this._.tableNamesMap, schema.fullSchema[tableName], columns, dialect, session);
|
|
4749
|
+
}
|
|
4750
|
+
}
|
|
4751
|
+
}
|
|
4752
|
+
static [entityKind] = "PgDatabase";
|
|
4753
|
+
query;
|
|
4754
|
+
$with(alias) {
|
|
4755
|
+
const self = this;
|
|
4756
|
+
return {
|
|
4757
|
+
as(qb) {
|
|
4758
|
+
if (typeof qb === "function") {
|
|
4759
|
+
qb = qb(new QueryBuilder(self.dialect));
|
|
4760
|
+
}
|
|
4761
|
+
return new Proxy(new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true), new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" }));
|
|
4762
|
+
}
|
|
4763
|
+
};
|
|
4764
|
+
}
|
|
4765
|
+
$count(source, filters) {
|
|
4766
|
+
return new PgCountBuilder({ source, filters, session: this.session });
|
|
4767
|
+
}
|
|
4768
|
+
with(...queries) {
|
|
4769
|
+
const self = this;
|
|
4770
|
+
function select2(fields) {
|
|
4771
|
+
return new PgSelectBuilder({
|
|
4772
|
+
fields: fields ?? undefined,
|
|
4773
|
+
session: self.session,
|
|
4774
|
+
dialect: self.dialect,
|
|
4775
|
+
withList: queries
|
|
4776
|
+
});
|
|
4777
|
+
}
|
|
4778
|
+
function selectDistinct(fields) {
|
|
4779
|
+
return new PgSelectBuilder({
|
|
4780
|
+
fields: fields ?? undefined,
|
|
4781
|
+
session: self.session,
|
|
4782
|
+
dialect: self.dialect,
|
|
4783
|
+
withList: queries,
|
|
4784
|
+
distinct: true
|
|
4785
|
+
});
|
|
4786
|
+
}
|
|
4787
|
+
function selectDistinctOn(on, fields) {
|
|
4788
|
+
return new PgSelectBuilder({
|
|
4789
|
+
fields: fields ?? undefined,
|
|
4790
|
+
session: self.session,
|
|
4791
|
+
dialect: self.dialect,
|
|
4792
|
+
withList: queries,
|
|
4793
|
+
distinct: { on }
|
|
4794
|
+
});
|
|
4795
|
+
}
|
|
4796
|
+
function update(table) {
|
|
4797
|
+
return new PgUpdateBuilder(table, self.session, self.dialect, queries);
|
|
4798
|
+
}
|
|
4799
|
+
function insert(table) {
|
|
4800
|
+
return new PgInsertBuilder(table, self.session, self.dialect, queries);
|
|
4801
|
+
}
|
|
4802
|
+
function delete_(table) {
|
|
4803
|
+
return new PgDeleteBase(table, self.session, self.dialect, queries);
|
|
4804
|
+
}
|
|
4805
|
+
return { select: select2, selectDistinct, selectDistinctOn, update, insert, delete: delete_ };
|
|
4806
|
+
}
|
|
4807
|
+
select(fields) {
|
|
4808
|
+
return new PgSelectBuilder({
|
|
4809
|
+
fields: fields ?? undefined,
|
|
4810
|
+
session: this.session,
|
|
4811
|
+
dialect: this.dialect
|
|
4812
|
+
});
|
|
4813
|
+
}
|
|
4814
|
+
selectDistinct(fields) {
|
|
4815
|
+
return new PgSelectBuilder({
|
|
4816
|
+
fields: fields ?? undefined,
|
|
4817
|
+
session: this.session,
|
|
4818
|
+
dialect: this.dialect,
|
|
4819
|
+
distinct: true
|
|
4820
|
+
});
|
|
4821
|
+
}
|
|
4822
|
+
selectDistinctOn(on, fields) {
|
|
4823
|
+
return new PgSelectBuilder({
|
|
4824
|
+
fields: fields ?? undefined,
|
|
4825
|
+
session: this.session,
|
|
4826
|
+
dialect: this.dialect,
|
|
4827
|
+
distinct: { on }
|
|
4828
|
+
});
|
|
4829
|
+
}
|
|
4830
|
+
update(table) {
|
|
4831
|
+
return new PgUpdateBuilder(table, this.session, this.dialect);
|
|
4832
|
+
}
|
|
4833
|
+
insert(table) {
|
|
4834
|
+
return new PgInsertBuilder(table, this.session, this.dialect);
|
|
4835
|
+
}
|
|
4836
|
+
delete(table) {
|
|
4837
|
+
return new PgDeleteBase(table, this.session, this.dialect);
|
|
4838
|
+
}
|
|
4839
|
+
refreshMaterializedView(view) {
|
|
4840
|
+
return new PgRefreshMaterializedView(view, this.session, this.dialect);
|
|
4841
|
+
}
|
|
4842
|
+
execute(query) {
|
|
4843
|
+
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
|
4844
|
+
const builtQuery = this.dialect.sqlToQuery(sequel);
|
|
4845
|
+
const prepared = this.session.prepareQuery(builtQuery, undefined, undefined, false);
|
|
4846
|
+
return new PgRaw(() => prepared.execute(), sequel, builtQuery, (result) => prepared.mapResult(result, true));
|
|
4847
|
+
}
|
|
4848
|
+
transaction(transaction, config) {
|
|
4849
|
+
return this.session.transaction(transaction, config);
|
|
4850
|
+
}
|
|
4851
|
+
}
|
|
4852
|
+
|
|
4853
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/pg-core/session.js
|
|
4854
|
+
class PgPreparedQuery {
|
|
4855
|
+
constructor(query) {
|
|
4856
|
+
this.query = query;
|
|
4857
|
+
}
|
|
4858
|
+
getQuery() {
|
|
4859
|
+
return this.query;
|
|
4860
|
+
}
|
|
4861
|
+
mapResult(response, _isFromBatch) {
|
|
4862
|
+
return response;
|
|
4863
|
+
}
|
|
4864
|
+
static [entityKind] = "PgPreparedQuery";
|
|
4865
|
+
joinsNotNullableMap;
|
|
4866
|
+
}
|
|
4867
|
+
|
|
4868
|
+
class PgSession {
|
|
4869
|
+
constructor(dialect) {
|
|
4870
|
+
this.dialect = dialect;
|
|
4871
|
+
}
|
|
4872
|
+
static [entityKind] = "PgSession";
|
|
4873
|
+
execute(query) {
|
|
4874
|
+
return tracer.startActiveSpan("drizzle.operation", () => {
|
|
4875
|
+
const prepared = tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
|
4876
|
+
return this.prepareQuery(this.dialect.sqlToQuery(query), undefined, undefined, false);
|
|
4877
|
+
});
|
|
4878
|
+
return prepared.execute();
|
|
4879
|
+
});
|
|
4880
|
+
}
|
|
4881
|
+
all(query) {
|
|
4882
|
+
return this.prepareQuery(this.dialect.sqlToQuery(query), undefined, undefined, false).all();
|
|
4883
|
+
}
|
|
4884
|
+
async count(sql2) {
|
|
4885
|
+
const res = await this.execute(sql2);
|
|
4886
|
+
return Number(res[0]["count"]);
|
|
4887
|
+
}
|
|
4888
|
+
}
|
|
4889
|
+
|
|
4890
|
+
class PgTransaction extends PgDatabase {
|
|
4891
|
+
constructor(dialect, session, schema, nestedIndex = 0) {
|
|
4892
|
+
super(dialect, session, schema);
|
|
4893
|
+
this.schema = schema;
|
|
4894
|
+
this.nestedIndex = nestedIndex;
|
|
4895
|
+
}
|
|
4896
|
+
static [entityKind] = "PgTransaction";
|
|
4897
|
+
rollback() {
|
|
4898
|
+
throw new TransactionRollbackError;
|
|
4899
|
+
}
|
|
4900
|
+
getTransactionConfigSQL(config) {
|
|
4901
|
+
const chunks = [];
|
|
4902
|
+
if (config.isolationLevel) {
|
|
4903
|
+
chunks.push(`isolation level ${config.isolationLevel}`);
|
|
4904
|
+
}
|
|
4905
|
+
if (config.accessMode) {
|
|
4906
|
+
chunks.push(config.accessMode);
|
|
4907
|
+
}
|
|
4908
|
+
if (typeof config.deferrable === "boolean") {
|
|
4909
|
+
chunks.push(config.deferrable ? "deferrable" : "not deferrable");
|
|
4910
|
+
}
|
|
4911
|
+
return sql.raw(chunks.join(" "));
|
|
4912
|
+
}
|
|
4913
|
+
setTransaction(config) {
|
|
4914
|
+
return this.session.execute(sql`set transaction ${this.getTransactionConfigSQL(config)}`);
|
|
4915
|
+
}
|
|
4916
|
+
}
|
|
4917
|
+
|
|
4918
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/postgres-js/session.js
|
|
4919
|
+
class PostgresJsPreparedQuery extends PgPreparedQuery {
|
|
4920
|
+
constructor(client, queryString, params, logger, fields, _isResponseInArrayMode, customResultMapper) {
|
|
4921
|
+
super({ sql: queryString, params });
|
|
4922
|
+
this.client = client;
|
|
4923
|
+
this.queryString = queryString;
|
|
4924
|
+
this.params = params;
|
|
4925
|
+
this.logger = logger;
|
|
4926
|
+
this.fields = fields;
|
|
4927
|
+
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
4928
|
+
this.customResultMapper = customResultMapper;
|
|
4929
|
+
}
|
|
4930
|
+
static [entityKind] = "PostgresJsPreparedQuery";
|
|
4931
|
+
async execute(placeholderValues = {}) {
|
|
4932
|
+
return tracer.startActiveSpan("drizzle.execute", async (span) => {
|
|
4933
|
+
const params = fillPlaceholders(this.params, placeholderValues);
|
|
4934
|
+
span?.setAttributes({
|
|
4935
|
+
"drizzle.query.text": this.queryString,
|
|
4936
|
+
"drizzle.query.params": JSON.stringify(params)
|
|
4937
|
+
});
|
|
4938
|
+
this.logger.logQuery(this.queryString, params);
|
|
4939
|
+
const { fields, queryString: query, client, joinsNotNullableMap, customResultMapper } = this;
|
|
4940
|
+
if (!fields && !customResultMapper) {
|
|
4941
|
+
return tracer.startActiveSpan("drizzle.driver.execute", () => {
|
|
4942
|
+
return client.unsafe(query, params);
|
|
4943
|
+
});
|
|
4944
|
+
}
|
|
4945
|
+
const rows = await tracer.startActiveSpan("drizzle.driver.execute", () => {
|
|
4946
|
+
span?.setAttributes({
|
|
4947
|
+
"drizzle.query.text": query,
|
|
4948
|
+
"drizzle.query.params": JSON.stringify(params)
|
|
4949
|
+
});
|
|
4950
|
+
return client.unsafe(query, params).values();
|
|
4951
|
+
});
|
|
4952
|
+
return tracer.startActiveSpan("drizzle.mapResponse", () => {
|
|
4953
|
+
return customResultMapper ? customResultMapper(rows) : rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
|
|
4954
|
+
});
|
|
4955
|
+
});
|
|
4956
|
+
}
|
|
4957
|
+
all(placeholderValues = {}) {
|
|
4958
|
+
return tracer.startActiveSpan("drizzle.execute", async (span) => {
|
|
4959
|
+
const params = fillPlaceholders(this.params, placeholderValues);
|
|
4960
|
+
span?.setAttributes({
|
|
4961
|
+
"drizzle.query.text": this.queryString,
|
|
4962
|
+
"drizzle.query.params": JSON.stringify(params)
|
|
4963
|
+
});
|
|
4964
|
+
this.logger.logQuery(this.queryString, params);
|
|
4965
|
+
return tracer.startActiveSpan("drizzle.driver.execute", () => {
|
|
4966
|
+
span?.setAttributes({
|
|
4967
|
+
"drizzle.query.text": this.queryString,
|
|
4968
|
+
"drizzle.query.params": JSON.stringify(params)
|
|
4969
|
+
});
|
|
4970
|
+
return this.client.unsafe(this.queryString, params);
|
|
4971
|
+
});
|
|
4972
|
+
});
|
|
4973
|
+
}
|
|
4974
|
+
isResponseInArrayMode() {
|
|
4975
|
+
return this._isResponseInArrayMode;
|
|
4976
|
+
}
|
|
4977
|
+
}
|
|
4978
|
+
|
|
4979
|
+
class PostgresJsSession extends PgSession {
|
|
4980
|
+
constructor(client, dialect, schema, options = {}) {
|
|
4981
|
+
super(dialect);
|
|
4982
|
+
this.client = client;
|
|
4983
|
+
this.schema = schema;
|
|
4984
|
+
this.options = options;
|
|
4985
|
+
this.logger = options.logger ?? new NoopLogger;
|
|
4986
|
+
}
|
|
4987
|
+
static [entityKind] = "PostgresJsSession";
|
|
4988
|
+
logger;
|
|
4989
|
+
prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper) {
|
|
4990
|
+
return new PostgresJsPreparedQuery(this.client, query.sql, query.params, this.logger, fields, isResponseInArrayMode, customResultMapper);
|
|
4991
|
+
}
|
|
4992
|
+
query(query, params) {
|
|
4993
|
+
this.logger.logQuery(query, params);
|
|
4994
|
+
return this.client.unsafe(query, params).values();
|
|
4995
|
+
}
|
|
4996
|
+
queryObjects(query, params) {
|
|
4997
|
+
return this.client.unsafe(query, params);
|
|
4998
|
+
}
|
|
4999
|
+
transaction(transaction, config) {
|
|
5000
|
+
return this.client.begin(async (client) => {
|
|
5001
|
+
const session = new PostgresJsSession(client, this.dialect, this.schema, this.options);
|
|
5002
|
+
const tx = new PostgresJsTransaction(this.dialect, session, this.schema);
|
|
5003
|
+
if (config) {
|
|
5004
|
+
await tx.setTransaction(config);
|
|
5005
|
+
}
|
|
5006
|
+
return transaction(tx);
|
|
5007
|
+
});
|
|
5008
|
+
}
|
|
5009
|
+
}
|
|
5010
|
+
|
|
5011
|
+
class PostgresJsTransaction extends PgTransaction {
|
|
5012
|
+
constructor(dialect, session, schema, nestedIndex = 0) {
|
|
5013
|
+
super(dialect, session, schema, nestedIndex);
|
|
5014
|
+
this.session = session;
|
|
5015
|
+
}
|
|
5016
|
+
static [entityKind] = "PostgresJsTransaction";
|
|
5017
|
+
transaction(transaction) {
|
|
5018
|
+
return this.session.client.savepoint((client) => {
|
|
5019
|
+
const session = new PostgresJsSession(client, this.dialect, this.schema, this.session.options);
|
|
5020
|
+
const tx = new PostgresJsTransaction(this.dialect, session, this.schema);
|
|
5021
|
+
return transaction(tx);
|
|
5022
|
+
});
|
|
5023
|
+
}
|
|
5024
|
+
}
|
|
5025
|
+
|
|
5026
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/postgres-js/driver.js
|
|
5027
|
+
function construct(client, config = {}) {
|
|
5028
|
+
const transparentParser = (val) => val;
|
|
5029
|
+
for (const type of ["1184", "1082", "1083", "1114"]) {
|
|
5030
|
+
client.options.parsers[type] = transparentParser;
|
|
5031
|
+
client.options.serializers[type] = transparentParser;
|
|
5032
|
+
}
|
|
5033
|
+
client.options.serializers["114"] = transparentParser;
|
|
5034
|
+
client.options.serializers["3802"] = transparentParser;
|
|
5035
|
+
const dialect = new PgDialect({ casing: config.casing });
|
|
5036
|
+
let logger;
|
|
5037
|
+
if (config.logger === true) {
|
|
5038
|
+
logger = new DefaultLogger;
|
|
5039
|
+
} else if (config.logger !== false) {
|
|
5040
|
+
logger = config.logger;
|
|
5041
|
+
}
|
|
5042
|
+
let schema;
|
|
5043
|
+
if (config.schema) {
|
|
5044
|
+
const tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);
|
|
5045
|
+
schema = {
|
|
5046
|
+
fullSchema: config.schema,
|
|
5047
|
+
schema: tablesConfig.tables,
|
|
5048
|
+
tableNamesMap: tablesConfig.tableNamesMap
|
|
5049
|
+
};
|
|
5050
|
+
}
|
|
5051
|
+
const session = new PostgresJsSession(client, dialect, schema, { logger });
|
|
5052
|
+
const db = new PostgresJsDatabase(dialect, session, schema);
|
|
5053
|
+
db.$client = client;
|
|
5054
|
+
return db;
|
|
5055
|
+
}
|
|
5056
|
+
function drizzle(...params) {
|
|
5057
|
+
if (typeof params[0] === "function") {
|
|
5058
|
+
return construct(params[0], params[1]);
|
|
5059
|
+
}
|
|
5060
|
+
if (typeof params[0] === "object") {
|
|
5061
|
+
const { connection: connection2, client, ...drizzleConfig } = params[0];
|
|
5062
|
+
if (client)
|
|
5063
|
+
return construct(client, drizzleConfig);
|
|
5064
|
+
if (typeof connection2 === "object" && connection2.url !== undefined) {
|
|
5065
|
+
const { url, ...config } = connection2;
|
|
5066
|
+
const instance3 = src_default(url, config);
|
|
5067
|
+
return construct(instance3, drizzleConfig);
|
|
5068
|
+
}
|
|
5069
|
+
const instance2 = src_default(connection2);
|
|
5070
|
+
return construct(instance2, drizzleConfig);
|
|
5071
|
+
}
|
|
5072
|
+
const instance = src_default(params[0]);
|
|
5073
|
+
return construct(instance, params[1]);
|
|
5074
|
+
}
|
|
5075
|
+
|
|
5076
|
+
class PostgresJsDatabase extends PgDatabase {
|
|
5077
|
+
static [entityKind] = "PostgresJsDatabase";
|
|
5078
|
+
}
|
|
5079
|
+
((drizzle2) => {
|
|
5080
|
+
function mock(config) {
|
|
5081
|
+
return construct({}, config);
|
|
5082
|
+
}
|
|
5083
|
+
drizzle2.mock = mock;
|
|
5084
|
+
})(drizzle || (drizzle = {}));
|
|
5085
|
+
|
|
5086
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.35.1_@types+react@18.3.11_bun-types@1.1.30_postgres@3.4.4_react@18.3.1/node_modules/drizzle-orm/migrator.js
|
|
5087
|
+
import crypto2 from "crypto";
|
|
5088
|
+
import fs2 from "fs";
|
|
5089
|
+
function readMigrationFiles(config) {
|
|
5090
|
+
const migrationFolderTo = config.migrationsFolder;
|
|
5091
|
+
const migrationQueries = [];
|
|
5092
|
+
const journalPath = `${migrationFolderTo}/meta/_journal.json`;
|
|
5093
|
+
if (!fs2.existsSync(journalPath)) {
|
|
5094
|
+
throw new Error(`Can't find meta/_journal.json file`);
|
|
5095
|
+
}
|
|
5096
|
+
const journalAsString = fs2.readFileSync(`${migrationFolderTo}/meta/_journal.json`).toString();
|
|
5097
|
+
const journal = JSON.parse(journalAsString);
|
|
5098
|
+
for (const journalEntry of journal.entries) {
|
|
5099
|
+
const migrationPath = `${migrationFolderTo}/${journalEntry.tag}.sql`;
|
|
5100
|
+
try {
|
|
5101
|
+
const query = fs2.readFileSync(`${migrationFolderTo}/${journalEntry.tag}.sql`).toString();
|
|
5102
|
+
const result = query.split("--> statement-breakpoint").map((it) => {
|
|
5103
|
+
return it;
|
|
5104
|
+
});
|
|
5105
|
+
migrationQueries.push({
|
|
5106
|
+
sql: result,
|
|
5107
|
+
bps: journalEntry.breakpoints,
|
|
5108
|
+
folderMillis: journalEntry.when,
|
|
5109
|
+
hash: crypto2.createHash("sha256").update(query).digest("hex")
|
|
5110
|
+
});
|
|
5111
|
+
} catch {
|
|
5112
|
+
throw new Error(`No file ${migrationPath} found in ${migrationFolderTo} folder`);
|
|
5113
|
+
}
|
|
5114
|
+
}
|
|
5115
|
+
return migrationQueries;
|
|
5116
|
+
}
|
|
5117
|
+
|
|
5118
|
+
// /home/runner/work/wayforge/wayforge/apps/tempest.games/node_modules/drizzle-orm/postgres-js/migrator.js
|
|
5119
|
+
async function migrate(db, config) {
|
|
5120
|
+
const migrations = readMigrationFiles(config);
|
|
5121
|
+
await db.dialect.migrate(migrations, db.session, config);
|
|
5122
|
+
}
|
|
5123
|
+
|
|
1957
5124
|
// /home/runner/work/wayforge/wayforge/apps/tempest.games/node_modules/zod/lib/index.mjs
|
|
1958
5125
|
function setErrorMap(map) {
|
|
1959
5126
|
overrideErrorMap = map;
|
|
@@ -2037,11 +5204,11 @@ function datetimeRegex(args) {
|
|
|
2037
5204
|
regex = `${regex}(${opts.join("|")})`;
|
|
2038
5205
|
return new RegExp(`^${regex}\$`);
|
|
2039
5206
|
}
|
|
2040
|
-
function isValidIP(ip,
|
|
2041
|
-
if ((
|
|
5207
|
+
function isValidIP(ip, version2) {
|
|
5208
|
+
if ((version2 === "v4" || !version2) && ipv4Regex.test(ip)) {
|
|
2042
5209
|
return true;
|
|
2043
5210
|
}
|
|
2044
|
-
if ((
|
|
5211
|
+
if ((version2 === "v6" || !version2) && ipv6Regex.test(ip)) {
|
|
2045
5212
|
return true;
|
|
2046
5213
|
}
|
|
2047
5214
|
return false;
|
|
@@ -5905,7 +9072,7 @@ var env = createEnv({
|
|
|
5905
9072
|
// __scripts__/setup-db.bun.ts
|
|
5906
9073
|
var osUser = os2.userInfo().username;
|
|
5907
9074
|
var user = osUser === `unknown` ? `postgres` : osUser;
|
|
5908
|
-
var
|
|
9075
|
+
var sql2 = src_default({
|
|
5909
9076
|
user,
|
|
5910
9077
|
password: env.POSTGRES_PASSWORD,
|
|
5911
9078
|
database: `postgres`,
|
|
@@ -5914,7 +9081,7 @@ var sql = src_default({
|
|
|
5914
9081
|
});
|
|
5915
9082
|
try {
|
|
5916
9083
|
process.stdout.write(`\uD83D\uDE80 Creating database ${env.POSTGRES_DATABASE}... `);
|
|
5917
|
-
await
|
|
9084
|
+
await sql2`CREATE DATABASE ${sql2(env.POSTGRES_DATABASE)}`;
|
|
5918
9085
|
console.log(`Done!`);
|
|
5919
9086
|
} catch (thrown) {
|
|
5920
9087
|
if (thrown instanceof Error) {
|
|
@@ -5923,7 +9090,7 @@ try {
|
|
|
5923
9090
|
}
|
|
5924
9091
|
try {
|
|
5925
9092
|
process.stdout.write(`\uD83D\uDE80 Creating user ${env.POSTGRES_USER}... `);
|
|
5926
|
-
await
|
|
9093
|
+
await sql2.unsafe(`CREATE USER ${env.POSTGRES_USER} WITH PASSWORD '${env.POSTGRES_PASSWORD}'`);
|
|
5927
9094
|
console.log(`Done!`);
|
|
5928
9095
|
} catch (thrown) {
|
|
5929
9096
|
if (thrown instanceof Error) {
|
|
@@ -5932,12 +9099,32 @@ try {
|
|
|
5932
9099
|
}
|
|
5933
9100
|
try {
|
|
5934
9101
|
process.stdout.write(`\uD83D\uDE80 Granting privileges to ${env.POSTGRES_USER} on ${env.POSTGRES_DATABASE}... `);
|
|
5935
|
-
await
|
|
9102
|
+
await sql2`GRANT ALL PRIVILEGES ON DATABASE ${sql2(env.POSTGRES_DATABASE)} TO ${sql2(env.POSTGRES_USER)}`;
|
|
9103
|
+
console.log(`Done!`);
|
|
9104
|
+
} catch (thrown) {
|
|
9105
|
+
if (thrown instanceof Error) {
|
|
9106
|
+
console.error(`\uD83D\uDCA5 Failed:`, thrown.message);
|
|
9107
|
+
}
|
|
9108
|
+
}
|
|
9109
|
+
await sql2.end();
|
|
9110
|
+
var tempest = src_default({
|
|
9111
|
+
user: env.POSTGRES_USER,
|
|
9112
|
+
password: env.POSTGRES_PASSWORD,
|
|
9113
|
+
database: env.POSTGRES_DATABASE,
|
|
9114
|
+
host: env.POSTGRES_HOST,
|
|
9115
|
+
port: env.POSTGRES_PORT
|
|
9116
|
+
});
|
|
9117
|
+
try {
|
|
9118
|
+
process.stdout.write(`\uD83D\uDE80 Migrating database ${env.POSTGRES_DATABASE}... `);
|
|
9119
|
+
const db = drizzle(tempest);
|
|
9120
|
+
await migrate(db, {
|
|
9121
|
+
migrationsFolder: resolve(import.meta.dir, `../drizzle`)
|
|
9122
|
+
});
|
|
5936
9123
|
console.log(`Done!`);
|
|
5937
9124
|
} catch (thrown) {
|
|
5938
9125
|
if (thrown instanceof Error) {
|
|
5939
9126
|
console.error(`\uD83D\uDCA5 Failed:`, thrown.message);
|
|
5940
9127
|
}
|
|
5941
9128
|
}
|
|
5942
|
-
await
|
|
9129
|
+
await tempest.end();
|
|
5943
9130
|
console.log(`\uD83D\uDE80 Database connection closed`);
|