Initial commit
This commit is contained in:
72
node_modules/drizzle-orm/sqlite-core/query-builders/count.cjs
generated
vendored
Normal file
72
node_modules/drizzle-orm/sqlite-core/query-builders/count.cjs
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var count_exports = {};
|
||||
__export(count_exports, {
|
||||
SQLiteCountBuilder: () => SQLiteCountBuilder
|
||||
});
|
||||
module.exports = __toCommonJS(count_exports);
|
||||
var import_entity = require("../../entity.cjs");
|
||||
var import_sql = require("../../sql/sql.cjs");
|
||||
class SQLiteCountBuilder extends import_sql.SQL {
|
||||
constructor(params) {
|
||||
super(SQLiteCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
|
||||
this.params = params;
|
||||
this.session = params.session;
|
||||
this.sql = SQLiteCountBuilder.buildCount(
|
||||
params.source,
|
||||
params.filters
|
||||
);
|
||||
}
|
||||
sql;
|
||||
static [import_entity.entityKind] = "SQLiteCountBuilderAsync";
|
||||
[Symbol.toStringTag] = "SQLiteCountBuilderAsync";
|
||||
session;
|
||||
static buildEmbeddedCount(source, filters) {
|
||||
return import_sql.sql`(select count(*) from ${source}${import_sql.sql.raw(" where ").if(filters)}${filters})`;
|
||||
}
|
||||
static buildCount(source, filters) {
|
||||
return import_sql.sql`select count(*) from ${source}${import_sql.sql.raw(" where ").if(filters)}${filters}`;
|
||||
}
|
||||
then(onfulfilled, onrejected) {
|
||||
return Promise.resolve(this.session.count(this.sql)).then(
|
||||
onfulfilled,
|
||||
onrejected
|
||||
);
|
||||
}
|
||||
catch(onRejected) {
|
||||
return this.then(void 0, onRejected);
|
||||
}
|
||||
finally(onFinally) {
|
||||
return this.then(
|
||||
(value) => {
|
||||
onFinally?.();
|
||||
return value;
|
||||
},
|
||||
(reason) => {
|
||||
onFinally?.();
|
||||
throw reason;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
SQLiteCountBuilder
|
||||
});
|
||||
//# sourceMappingURL=count.cjs.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/count.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/count.cjs.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/sqlite-core/query-builders/count.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport { SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport type { SQLiteSession } from '../session.ts';\nimport type { SQLiteTable } from '../table.ts';\nimport type { SQLiteView } from '../view.ts';\n\nexport class SQLiteCountBuilder<\n\tTSession extends SQLiteSession<any, any, any, any>,\n> extends SQL<number> implements Promise<number>, SQLWrapper {\n\tprivate sql: SQL<number>;\n\n\tstatic override readonly [entityKind] = 'SQLiteCountBuilderAsync';\n\t[Symbol.toStringTag] = 'SQLiteCountBuilderAsync';\n\n\tprivate session: TSession;\n\n\tprivate static buildEmbeddedCount(\n\t\tsource: SQLiteTable | SQLiteView | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t): SQL<number> {\n\t\treturn sql<number>`(select count(*) from ${source}${sql.raw(' where ').if(filters)}${filters})`;\n\t}\n\n\tprivate static buildCount(\n\t\tsource: SQLiteTable | SQLiteView | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t): SQL<number> {\n\t\treturn sql<number>`select count(*) from ${source}${sql.raw(' where ').if(filters)}${filters}`;\n\t}\n\n\tconstructor(\n\t\treadonly params: {\n\t\t\tsource: SQLiteTable | SQLiteView | SQL | SQLWrapper;\n\t\t\tfilters?: SQL<unknown>;\n\t\t\tsession: TSession;\n\t\t},\n\t) {\n\t\tsuper(SQLiteCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);\n\n\t\tthis.session = params.session;\n\n\t\tthis.sql = SQLiteCountBuilder.buildCount(\n\t\t\tparams.source,\n\t\t\tparams.filters,\n\t\t);\n\t}\n\n\tthen<TResult1 = number, TResult2 = never>(\n\t\tonfulfilled?: ((value: number) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n\t\tonrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n\t): Promise<TResult1 | TResult2> {\n\t\treturn Promise.resolve(this.session.count(this.sql)).then(\n\t\t\tonfulfilled,\n\t\t\tonrejected,\n\t\t);\n\t}\n\n\tcatch(\n\t\tonRejected?: ((reason: any) => never | PromiseLike<never>) | null | undefined,\n\t): Promise<number> {\n\t\treturn this.then(undefined, onRejected);\n\t}\n\n\tfinally(onFinally?: (() => void) | null | undefined): Promise<number> {\n\t\treturn this.then(\n\t\t\t(value) => {\n\t\t\t\tonFinally?.();\n\t\t\t\treturn value;\n\t\t\t},\n\t\t\t(reason) => {\n\t\t\t\tonFinally?.();\n\t\t\t\tthrow reason;\n\t\t\t},\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAC3B,iBAA0C;AAKnC,MAAM,2BAEH,eAAmD;AAAA,EAsB5D,YACU,QAKR;AACD,UAAM,mBAAmB,mBAAmB,OAAO,QAAQ,OAAO,OAAO,EAAE,WAAW;AAN7E;AAQT,SAAK,UAAU,OAAO;AAEtB,SAAK,MAAM,mBAAmB;AAAA,MAC7B,OAAO;AAAA,MACP,OAAO;AAAA,IACR;AAAA,EACD;AAAA,EApCQ;AAAA,EAER,QAA0B,wBAAU,IAAI;AAAA,EACxC,CAAC,OAAO,WAAW,IAAI;AAAA,EAEf;AAAA,EAER,OAAe,mBACd,QACA,SACc;AACd,WAAO,uCAAoC,MAAM,GAAG,eAAI,IAAI,SAAS,EAAE,GAAG,OAAO,CAAC,GAAG,OAAO;AAAA,EAC7F;AAAA,EAEA,OAAe,WACd,QACA,SACc;AACd,WAAO,sCAAmC,MAAM,GAAG,eAAI,IAAI,SAAS,EAAE,GAAG,OAAO,CAAC,GAAG,OAAO;AAAA,EAC5F;AAAA,EAmBA,KACC,aACA,YAC+B;AAC/B,WAAO,QAAQ,QAAQ,KAAK,QAAQ,MAAM,KAAK,GAAG,CAAC,EAAE;AAAA,MACpD;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MACC,YACkB;AAClB,WAAO,KAAK,KAAK,QAAW,UAAU;AAAA,EACvC;AAAA,EAEA,QAAQ,WAA8D;AACrE,WAAO,KAAK;AAAA,MACX,CAAC,UAAU;AACV,oBAAY;AACZ,eAAO;AAAA,MACR;AAAA,MACA,CAAC,WAAW;AACX,oBAAY;AACZ,cAAM;AAAA,MACP;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
||||
26
node_modules/drizzle-orm/sqlite-core/query-builders/count.d.cts
generated
vendored
Normal file
26
node_modules/drizzle-orm/sqlite-core/query-builders/count.d.cts
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
import { entityKind } from "../../entity.cjs";
|
||||
import { SQL, type SQLWrapper } from "../../sql/sql.cjs";
|
||||
import type { SQLiteSession } from "../session.cjs";
|
||||
import type { SQLiteTable } from "../table.cjs";
|
||||
import type { SQLiteView } from "../view.cjs";
|
||||
export declare class SQLiteCountBuilder<TSession extends SQLiteSession<any, any, any, any>> extends SQL<number> implements Promise<number>, SQLWrapper {
|
||||
readonly params: {
|
||||
source: SQLiteTable | SQLiteView | SQL | SQLWrapper;
|
||||
filters?: SQL<unknown>;
|
||||
session: TSession;
|
||||
};
|
||||
private sql;
|
||||
static readonly [entityKind] = "SQLiteCountBuilderAsync";
|
||||
[Symbol.toStringTag]: string;
|
||||
private session;
|
||||
private static buildEmbeddedCount;
|
||||
private static buildCount;
|
||||
constructor(params: {
|
||||
source: SQLiteTable | SQLiteView | SQL | SQLWrapper;
|
||||
filters?: SQL<unknown>;
|
||||
session: TSession;
|
||||
});
|
||||
then<TResult1 = number, TResult2 = never>(onfulfilled?: ((value: number) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
|
||||
catch(onRejected?: ((reason: any) => never | PromiseLike<never>) | null | undefined): Promise<number>;
|
||||
finally(onFinally?: (() => void) | null | undefined): Promise<number>;
|
||||
}
|
||||
26
node_modules/drizzle-orm/sqlite-core/query-builders/count.d.ts
generated
vendored
Normal file
26
node_modules/drizzle-orm/sqlite-core/query-builders/count.d.ts
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
import { entityKind } from "../../entity.js";
|
||||
import { SQL, type SQLWrapper } from "../../sql/sql.js";
|
||||
import type { SQLiteSession } from "../session.js";
|
||||
import type { SQLiteTable } from "../table.js";
|
||||
import type { SQLiteView } from "../view.js";
|
||||
export declare class SQLiteCountBuilder<TSession extends SQLiteSession<any, any, any, any>> extends SQL<number> implements Promise<number>, SQLWrapper {
|
||||
readonly params: {
|
||||
source: SQLiteTable | SQLiteView | SQL | SQLWrapper;
|
||||
filters?: SQL<unknown>;
|
||||
session: TSession;
|
||||
};
|
||||
private sql;
|
||||
static readonly [entityKind] = "SQLiteCountBuilderAsync";
|
||||
[Symbol.toStringTag]: string;
|
||||
private session;
|
||||
private static buildEmbeddedCount;
|
||||
private static buildCount;
|
||||
constructor(params: {
|
||||
source: SQLiteTable | SQLiteView | SQL | SQLWrapper;
|
||||
filters?: SQL<unknown>;
|
||||
session: TSession;
|
||||
});
|
||||
then<TResult1 = number, TResult2 = never>(onfulfilled?: ((value: number) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
|
||||
catch(onRejected?: ((reason: any) => never | PromiseLike<never>) | null | undefined): Promise<number>;
|
||||
finally(onFinally?: (() => void) | null | undefined): Promise<number>;
|
||||
}
|
||||
48
node_modules/drizzle-orm/sqlite-core/query-builders/count.js
generated
vendored
Normal file
48
node_modules/drizzle-orm/sqlite-core/query-builders/count.js
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
import { entityKind } from "../../entity.js";
|
||||
import { SQL, sql } from "../../sql/sql.js";
|
||||
class SQLiteCountBuilder extends SQL {
|
||||
constructor(params) {
|
||||
super(SQLiteCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
|
||||
this.params = params;
|
||||
this.session = params.session;
|
||||
this.sql = SQLiteCountBuilder.buildCount(
|
||||
params.source,
|
||||
params.filters
|
||||
);
|
||||
}
|
||||
sql;
|
||||
static [entityKind] = "SQLiteCountBuilderAsync";
|
||||
[Symbol.toStringTag] = "SQLiteCountBuilderAsync";
|
||||
session;
|
||||
static buildEmbeddedCount(source, filters) {
|
||||
return sql`(select count(*) from ${source}${sql.raw(" where ").if(filters)}${filters})`;
|
||||
}
|
||||
static buildCount(source, filters) {
|
||||
return sql`select count(*) from ${source}${sql.raw(" where ").if(filters)}${filters}`;
|
||||
}
|
||||
then(onfulfilled, onrejected) {
|
||||
return Promise.resolve(this.session.count(this.sql)).then(
|
||||
onfulfilled,
|
||||
onrejected
|
||||
);
|
||||
}
|
||||
catch(onRejected) {
|
||||
return this.then(void 0, onRejected);
|
||||
}
|
||||
finally(onFinally) {
|
||||
return this.then(
|
||||
(value) => {
|
||||
onFinally?.();
|
||||
return value;
|
||||
},
|
||||
(reason) => {
|
||||
onFinally?.();
|
||||
throw reason;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
export {
|
||||
SQLiteCountBuilder
|
||||
};
|
||||
//# sourceMappingURL=count.js.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/count.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/count.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/sqlite-core/query-builders/count.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport { SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport type { SQLiteSession } from '../session.ts';\nimport type { SQLiteTable } from '../table.ts';\nimport type { SQLiteView } from '../view.ts';\n\nexport class SQLiteCountBuilder<\n\tTSession extends SQLiteSession<any, any, any, any>,\n> extends SQL<number> implements Promise<number>, SQLWrapper {\n\tprivate sql: SQL<number>;\n\n\tstatic override readonly [entityKind] = 'SQLiteCountBuilderAsync';\n\t[Symbol.toStringTag] = 'SQLiteCountBuilderAsync';\n\n\tprivate session: TSession;\n\n\tprivate static buildEmbeddedCount(\n\t\tsource: SQLiteTable | SQLiteView | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t): SQL<number> {\n\t\treturn sql<number>`(select count(*) from ${source}${sql.raw(' where ').if(filters)}${filters})`;\n\t}\n\n\tprivate static buildCount(\n\t\tsource: SQLiteTable | SQLiteView | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t): SQL<number> {\n\t\treturn sql<number>`select count(*) from ${source}${sql.raw(' where ').if(filters)}${filters}`;\n\t}\n\n\tconstructor(\n\t\treadonly params: {\n\t\t\tsource: SQLiteTable | SQLiteView | SQL | SQLWrapper;\n\t\t\tfilters?: SQL<unknown>;\n\t\t\tsession: TSession;\n\t\t},\n\t) {\n\t\tsuper(SQLiteCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);\n\n\t\tthis.session = params.session;\n\n\t\tthis.sql = SQLiteCountBuilder.buildCount(\n\t\t\tparams.source,\n\t\t\tparams.filters,\n\t\t);\n\t}\n\n\tthen<TResult1 = number, TResult2 = never>(\n\t\tonfulfilled?: ((value: number) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n\t\tonrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n\t): Promise<TResult1 | TResult2> {\n\t\treturn Promise.resolve(this.session.count(this.sql)).then(\n\t\t\tonfulfilled,\n\t\t\tonrejected,\n\t\t);\n\t}\n\n\tcatch(\n\t\tonRejected?: ((reason: any) => never | PromiseLike<never>) | null | undefined,\n\t): Promise<number> {\n\t\treturn this.then(undefined, onRejected);\n\t}\n\n\tfinally(onFinally?: (() => void) | null | undefined): Promise<number> {\n\t\treturn this.then(\n\t\t\t(value) => {\n\t\t\t\tonFinally?.();\n\t\t\t\treturn value;\n\t\t\t},\n\t\t\t(reason) => {\n\t\t\t\tonFinally?.();\n\t\t\t\tthrow reason;\n\t\t\t},\n\t\t);\n\t}\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,KAAK,WAA4B;AAKnC,MAAM,2BAEH,IAAmD;AAAA,EAsB5D,YACU,QAKR;AACD,UAAM,mBAAmB,mBAAmB,OAAO,QAAQ,OAAO,OAAO,EAAE,WAAW;AAN7E;AAQT,SAAK,UAAU,OAAO;AAEtB,SAAK,MAAM,mBAAmB;AAAA,MAC7B,OAAO;AAAA,MACP,OAAO;AAAA,IACR;AAAA,EACD;AAAA,EApCQ;AAAA,EAER,QAA0B,UAAU,IAAI;AAAA,EACxC,CAAC,OAAO,WAAW,IAAI;AAAA,EAEf;AAAA,EAER,OAAe,mBACd,QACA,SACc;AACd,WAAO,4BAAoC,MAAM,GAAG,IAAI,IAAI,SAAS,EAAE,GAAG,OAAO,CAAC,GAAG,OAAO;AAAA,EAC7F;AAAA,EAEA,OAAe,WACd,QACA,SACc;AACd,WAAO,2BAAmC,MAAM,GAAG,IAAI,IAAI,SAAS,EAAE,GAAG,OAAO,CAAC,GAAG,OAAO;AAAA,EAC5F;AAAA,EAmBA,KACC,aACA,YAC+B;AAC/B,WAAO,QAAQ,QAAQ,KAAK,QAAQ,MAAM,KAAK,GAAG,CAAC,EAAE;AAAA,MACpD;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MACC,YACkB;AAClB,WAAO,KAAK,KAAK,QAAW,UAAU;AAAA,EACvC;AAAA,EAEA,QAAQ,WAA8D;AACrE,WAAO,KAAK;AAAA,MACX,CAAC,UAAU;AACV,oBAAY;AACZ,eAAO;AAAA,MACR;AAAA,MACA,CAAC,WAAW;AACX,oBAAY;AACZ,cAAM;AAAA,MACP;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
||||
141
node_modules/drizzle-orm/sqlite-core/query-builders/delete.cjs
generated
vendored
Normal file
141
node_modules/drizzle-orm/sqlite-core/query-builders/delete.cjs
generated
vendored
Normal file
@ -0,0 +1,141 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var delete_exports = {};
|
||||
__export(delete_exports, {
|
||||
SQLiteDeleteBase: () => SQLiteDeleteBase
|
||||
});
|
||||
module.exports = __toCommonJS(delete_exports);
|
||||
var import_entity = require("../../entity.cjs");
|
||||
var import_query_promise = require("../../query-promise.cjs");
|
||||
var import_selection_proxy = require("../../selection-proxy.cjs");
|
||||
var import_table = require("../table.cjs");
|
||||
var import_table2 = require("../../table.cjs");
|
||||
var import_utils = require("../../utils.cjs");
|
||||
class SQLiteDeleteBase extends import_query_promise.QueryPromise {
|
||||
constructor(table, session, dialect, withList) {
|
||||
super();
|
||||
this.table = table;
|
||||
this.session = session;
|
||||
this.dialect = dialect;
|
||||
this.config = { table, withList };
|
||||
}
|
||||
static [import_entity.entityKind] = "SQLiteDelete";
|
||||
/** @internal */
|
||||
config;
|
||||
/**
|
||||
* Adds a `where` clause to the query.
|
||||
*
|
||||
* Calling this method will delete only those rows that fulfill a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
||||
*
|
||||
* @param where the `where` clause.
|
||||
*
|
||||
* @example
|
||||
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
||||
*
|
||||
* ```ts
|
||||
* // Delete all cars with green color
|
||||
* db.delete(cars).where(eq(cars.color, 'green'));
|
||||
* // or
|
||||
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
||||
* ```
|
||||
*
|
||||
* You can logically combine conditional operators with `and()` and `or()` operators:
|
||||
*
|
||||
* ```ts
|
||||
* // Delete all BMW cars with a green color
|
||||
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
||||
*
|
||||
* // Delete all cars with the green or blue color
|
||||
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
||||
* ```
|
||||
*/
|
||||
where(where) {
|
||||
this.config.where = where;
|
||||
return this;
|
||||
}
|
||||
orderBy(...columns) {
|
||||
if (typeof columns[0] === "function") {
|
||||
const orderBy = columns[0](
|
||||
new Proxy(
|
||||
this.config.table[import_table2.Table.Symbol.Columns],
|
||||
new import_selection_proxy.SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
||||
this.config.orderBy = orderByArray;
|
||||
} else {
|
||||
const orderByArray = columns;
|
||||
this.config.orderBy = orderByArray;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
limit(limit) {
|
||||
this.config.limit = limit;
|
||||
return this;
|
||||
}
|
||||
returning(fields = this.table[import_table.SQLiteTable.Symbol.Columns]) {
|
||||
this.config.returning = (0, import_utils.orderSelectedFields)(fields);
|
||||
return this;
|
||||
}
|
||||
/** @internal */
|
||||
getSQL() {
|
||||
return this.dialect.buildDeleteQuery(this.config);
|
||||
}
|
||||
toSQL() {
|
||||
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
||||
return rest;
|
||||
}
|
||||
/** @internal */
|
||||
_prepare(isOneTimeQuery = true) {
|
||||
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
||||
this.dialect.sqlToQuery(this.getSQL()),
|
||||
this.config.returning,
|
||||
this.config.returning ? "all" : "run",
|
||||
true
|
||||
);
|
||||
}
|
||||
prepare() {
|
||||
return this._prepare(false);
|
||||
}
|
||||
run = (placeholderValues) => {
|
||||
return this._prepare().run(placeholderValues);
|
||||
};
|
||||
all = (placeholderValues) => {
|
||||
return this._prepare().all(placeholderValues);
|
||||
};
|
||||
get = (placeholderValues) => {
|
||||
return this._prepare().get(placeholderValues);
|
||||
};
|
||||
values = (placeholderValues) => {
|
||||
return this._prepare().values(placeholderValues);
|
||||
};
|
||||
async execute(placeholderValues) {
|
||||
return this._prepare().execute(placeholderValues);
|
||||
}
|
||||
$dynamic() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
SQLiteDeleteBase
|
||||
});
|
||||
//# sourceMappingURL=delete.cjs.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/delete.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/delete.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
117
node_modules/drizzle-orm/sqlite-core/query-builders/delete.d.cts
generated
vendored
Normal file
117
node_modules/drizzle-orm/sqlite-core/query-builders/delete.d.cts
generated
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
import { entityKind } from "../../entity.cjs";
|
||||
import type { SelectResultFields } from "../../query-builders/select.types.cjs";
|
||||
import { QueryPromise } from "../../query-promise.cjs";
|
||||
import type { RunnableQuery } from "../../runnable-query.cjs";
|
||||
import type { Placeholder, Query, SQL, SQLWrapper } from "../../sql/sql.cjs";
|
||||
import type { SQLiteDialect } from "../dialect.cjs";
|
||||
import type { SQLitePreparedQuery, SQLiteSession } from "../session.cjs";
|
||||
import { SQLiteTable } from "../table.cjs";
|
||||
import type { Subquery } from "../../subquery.cjs";
|
||||
import { type DrizzleTypeError, type ValueOrArray } from "../../utils.cjs";
|
||||
import type { SQLiteColumn } from "../columns/common.cjs";
|
||||
import type { SelectedFieldsFlat, SelectedFieldsOrdered } from "./select.types.cjs";
|
||||
export type SQLiteDeleteWithout<T extends AnySQLiteDeleteBase, TDynamic extends boolean, K extends keyof T & string> = TDynamic extends true ? T : Omit<SQLiteDeleteBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['returning'], TDynamic, T['_']['excludedMethods'] | K>, T['_']['excludedMethods'] | K>;
|
||||
export type SQLiteDelete<TTable extends SQLiteTable = SQLiteTable, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = unknown, TReturning extends Record<string, unknown> | undefined = undefined> = SQLiteDeleteBase<TTable, TResultType, TRunResult, TReturning, true, never>;
|
||||
export interface SQLiteDeleteConfig {
|
||||
where?: SQL | undefined;
|
||||
limit?: number | Placeholder;
|
||||
orderBy?: (SQLiteColumn | SQL | SQL.Aliased)[];
|
||||
table: SQLiteTable;
|
||||
returning?: SelectedFieldsOrdered;
|
||||
withList?: Subquery[];
|
||||
}
|
||||
export type SQLiteDeleteReturningAll<T extends AnySQLiteDeleteBase, TDynamic extends boolean> = SQLiteDeleteWithout<SQLiteDeleteBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['table']['$inferSelect'], T['_']['dynamic'], T['_']['excludedMethods']>, TDynamic, 'returning'>;
|
||||
export type SQLiteDeleteReturning<T extends AnySQLiteDeleteBase, TDynamic extends boolean, TSelectedFields extends SelectedFieldsFlat> = SQLiteDeleteWithout<SQLiteDeleteBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], SelectResultFields<TSelectedFields>, T['_']['dynamic'], T['_']['excludedMethods']>, TDynamic, 'returning'>;
|
||||
export type SQLiteDeleteExecute<T extends AnySQLiteDeleteBase> = T['_']['returning'] extends undefined ? T['_']['runResult'] : T['_']['returning'][];
|
||||
export type SQLiteDeletePrepare<T extends AnySQLiteDeleteBase> = SQLitePreparedQuery<{
|
||||
type: T['_']['resultType'];
|
||||
run: T['_']['runResult'];
|
||||
all: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'> : T['_']['returning'][];
|
||||
get: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'> : T['_']['returning'] | undefined;
|
||||
values: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'> : any[][];
|
||||
execute: SQLiteDeleteExecute<T>;
|
||||
}>;
|
||||
export type SQLiteDeleteDynamic<T extends AnySQLiteDeleteBase> = SQLiteDelete<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['returning']>;
|
||||
export type AnySQLiteDeleteBase = SQLiteDeleteBase<any, any, any, any, any, any>;
|
||||
export interface SQLiteDeleteBase<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult, TReturning extends Record<string, unknown> | undefined = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>, RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper {
|
||||
readonly _: {
|
||||
dialect: 'sqlite';
|
||||
readonly table: TTable;
|
||||
readonly resultType: TResultType;
|
||||
readonly runResult: TRunResult;
|
||||
readonly returning: TReturning;
|
||||
readonly dynamic: TDynamic;
|
||||
readonly excludedMethods: TExcludedMethods;
|
||||
readonly result: TReturning extends undefined ? TRunResult : TReturning[];
|
||||
};
|
||||
}
|
||||
export declare class SQLiteDeleteBase<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult, TReturning extends Record<string, unknown> | undefined = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]> implements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper {
|
||||
private table;
|
||||
private session;
|
||||
private dialect;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(table: TTable, session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[]);
|
||||
/**
|
||||
* Adds a `where` clause to the query.
|
||||
*
|
||||
* Calling this method will delete only those rows that fulfill a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
||||
*
|
||||
* @param where the `where` clause.
|
||||
*
|
||||
* @example
|
||||
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
||||
*
|
||||
* ```ts
|
||||
* // Delete all cars with green color
|
||||
* db.delete(cars).where(eq(cars.color, 'green'));
|
||||
* // or
|
||||
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
||||
* ```
|
||||
*
|
||||
* You can logically combine conditional operators with `and()` and `or()` operators:
|
||||
*
|
||||
* ```ts
|
||||
* // Delete all BMW cars with a green color
|
||||
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
||||
*
|
||||
* // Delete all cars with the green or blue color
|
||||
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
||||
* ```
|
||||
*/
|
||||
where(where: SQL | undefined): SQLiteDeleteWithout<this, TDynamic, 'where'>;
|
||||
orderBy(builder: (deleteTable: TTable) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>): SQLiteDeleteWithout<this, TDynamic, 'orderBy'>;
|
||||
orderBy(...columns: (SQLiteColumn | SQL | SQL.Aliased)[]): SQLiteDeleteWithout<this, TDynamic, 'orderBy'>;
|
||||
limit(limit: number | Placeholder): SQLiteDeleteWithout<this, TDynamic, 'limit'>;
|
||||
/**
|
||||
* Adds a `returning` clause to the query.
|
||||
*
|
||||
* Calling this method will return the specified fields of the deleted rows. If no fields are specified, all fields will be returned.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/delete#delete-with-return}
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Delete all cars with the green color and return all fields
|
||||
* const deletedCars: Car[] = await db.delete(cars)
|
||||
* .where(eq(cars.color, 'green'))
|
||||
* .returning();
|
||||
*
|
||||
* // Delete all cars with the green color and return only their id and brand fields
|
||||
* const deletedCarsIdsAndBrands: { id: number, brand: string }[] = await db.delete(cars)
|
||||
* .where(eq(cars.color, 'green'))
|
||||
* .returning({ id: cars.id, brand: cars.brand });
|
||||
* ```
|
||||
*/
|
||||
returning(): SQLiteDeleteReturningAll<this, TDynamic>;
|
||||
returning<TSelectedFields extends SelectedFieldsFlat>(fields: TSelectedFields): SQLiteDeleteReturning<this, TDynamic, TSelectedFields>;
|
||||
toSQL(): Query;
|
||||
prepare(): SQLiteDeletePrepare<this>;
|
||||
run: ReturnType<this['prepare']>['run'];
|
||||
all: ReturnType<this['prepare']>['all'];
|
||||
get: ReturnType<this['prepare']>['get'];
|
||||
values: ReturnType<this['prepare']>['values'];
|
||||
execute(placeholderValues?: Record<string, unknown>): Promise<SQLiteDeleteExecute<this>>;
|
||||
$dynamic(): SQLiteDeleteDynamic<this>;
|
||||
}
|
||||
117
node_modules/drizzle-orm/sqlite-core/query-builders/delete.d.ts
generated
vendored
Normal file
117
node_modules/drizzle-orm/sqlite-core/query-builders/delete.d.ts
generated
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
import { entityKind } from "../../entity.js";
|
||||
import type { SelectResultFields } from "../../query-builders/select.types.js";
|
||||
import { QueryPromise } from "../../query-promise.js";
|
||||
import type { RunnableQuery } from "../../runnable-query.js";
|
||||
import type { Placeholder, Query, SQL, SQLWrapper } from "../../sql/sql.js";
|
||||
import type { SQLiteDialect } from "../dialect.js";
|
||||
import type { SQLitePreparedQuery, SQLiteSession } from "../session.js";
|
||||
import { SQLiteTable } from "../table.js";
|
||||
import type { Subquery } from "../../subquery.js";
|
||||
import { type DrizzleTypeError, type ValueOrArray } from "../../utils.js";
|
||||
import type { SQLiteColumn } from "../columns/common.js";
|
||||
import type { SelectedFieldsFlat, SelectedFieldsOrdered } from "./select.types.js";
|
||||
export type SQLiteDeleteWithout<T extends AnySQLiteDeleteBase, TDynamic extends boolean, K extends keyof T & string> = TDynamic extends true ? T : Omit<SQLiteDeleteBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['returning'], TDynamic, T['_']['excludedMethods'] | K>, T['_']['excludedMethods'] | K>;
|
||||
export type SQLiteDelete<TTable extends SQLiteTable = SQLiteTable, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = unknown, TReturning extends Record<string, unknown> | undefined = undefined> = SQLiteDeleteBase<TTable, TResultType, TRunResult, TReturning, true, never>;
|
||||
export interface SQLiteDeleteConfig {
|
||||
where?: SQL | undefined;
|
||||
limit?: number | Placeholder;
|
||||
orderBy?: (SQLiteColumn | SQL | SQL.Aliased)[];
|
||||
table: SQLiteTable;
|
||||
returning?: SelectedFieldsOrdered;
|
||||
withList?: Subquery[];
|
||||
}
|
||||
export type SQLiteDeleteReturningAll<T extends AnySQLiteDeleteBase, TDynamic extends boolean> = SQLiteDeleteWithout<SQLiteDeleteBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['table']['$inferSelect'], T['_']['dynamic'], T['_']['excludedMethods']>, TDynamic, 'returning'>;
|
||||
export type SQLiteDeleteReturning<T extends AnySQLiteDeleteBase, TDynamic extends boolean, TSelectedFields extends SelectedFieldsFlat> = SQLiteDeleteWithout<SQLiteDeleteBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], SelectResultFields<TSelectedFields>, T['_']['dynamic'], T['_']['excludedMethods']>, TDynamic, 'returning'>;
|
||||
export type SQLiteDeleteExecute<T extends AnySQLiteDeleteBase> = T['_']['returning'] extends undefined ? T['_']['runResult'] : T['_']['returning'][];
|
||||
export type SQLiteDeletePrepare<T extends AnySQLiteDeleteBase> = SQLitePreparedQuery<{
|
||||
type: T['_']['resultType'];
|
||||
run: T['_']['runResult'];
|
||||
all: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'> : T['_']['returning'][];
|
||||
get: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'> : T['_']['returning'] | undefined;
|
||||
values: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'> : any[][];
|
||||
execute: SQLiteDeleteExecute<T>;
|
||||
}>;
|
||||
export type SQLiteDeleteDynamic<T extends AnySQLiteDeleteBase> = SQLiteDelete<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['returning']>;
|
||||
export type AnySQLiteDeleteBase = SQLiteDeleteBase<any, any, any, any, any, any>;
|
||||
export interface SQLiteDeleteBase<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult, TReturning extends Record<string, unknown> | undefined = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>, RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper {
|
||||
readonly _: {
|
||||
dialect: 'sqlite';
|
||||
readonly table: TTable;
|
||||
readonly resultType: TResultType;
|
||||
readonly runResult: TRunResult;
|
||||
readonly returning: TReturning;
|
||||
readonly dynamic: TDynamic;
|
||||
readonly excludedMethods: TExcludedMethods;
|
||||
readonly result: TReturning extends undefined ? TRunResult : TReturning[];
|
||||
};
|
||||
}
|
||||
export declare class SQLiteDeleteBase<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult, TReturning extends Record<string, unknown> | undefined = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]> implements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper {
|
||||
private table;
|
||||
private session;
|
||||
private dialect;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(table: TTable, session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[]);
|
||||
/**
|
||||
* Adds a `where` clause to the query.
|
||||
*
|
||||
* Calling this method will delete only those rows that fulfill a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
||||
*
|
||||
* @param where the `where` clause.
|
||||
*
|
||||
* @example
|
||||
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
||||
*
|
||||
* ```ts
|
||||
* // Delete all cars with green color
|
||||
* db.delete(cars).where(eq(cars.color, 'green'));
|
||||
* // or
|
||||
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
||||
* ```
|
||||
*
|
||||
* You can logically combine conditional operators with `and()` and `or()` operators:
|
||||
*
|
||||
* ```ts
|
||||
* // Delete all BMW cars with a green color
|
||||
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
||||
*
|
||||
* // Delete all cars with the green or blue color
|
||||
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
||||
* ```
|
||||
*/
|
||||
where(where: SQL | undefined): SQLiteDeleteWithout<this, TDynamic, 'where'>;
|
||||
orderBy(builder: (deleteTable: TTable) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>): SQLiteDeleteWithout<this, TDynamic, 'orderBy'>;
|
||||
orderBy(...columns: (SQLiteColumn | SQL | SQL.Aliased)[]): SQLiteDeleteWithout<this, TDynamic, 'orderBy'>;
|
||||
limit(limit: number | Placeholder): SQLiteDeleteWithout<this, TDynamic, 'limit'>;
|
||||
/**
|
||||
* Adds a `returning` clause to the query.
|
||||
*
|
||||
* Calling this method will return the specified fields of the deleted rows. If no fields are specified, all fields will be returned.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/delete#delete-with-return}
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Delete all cars with the green color and return all fields
|
||||
* const deletedCars: Car[] = await db.delete(cars)
|
||||
* .where(eq(cars.color, 'green'))
|
||||
* .returning();
|
||||
*
|
||||
* // Delete all cars with the green color and return only their id and brand fields
|
||||
* const deletedCarsIdsAndBrands: { id: number, brand: string }[] = await db.delete(cars)
|
||||
* .where(eq(cars.color, 'green'))
|
||||
* .returning({ id: cars.id, brand: cars.brand });
|
||||
* ```
|
||||
*/
|
||||
returning(): SQLiteDeleteReturningAll<this, TDynamic>;
|
||||
returning<TSelectedFields extends SelectedFieldsFlat>(fields: TSelectedFields): SQLiteDeleteReturning<this, TDynamic, TSelectedFields>;
|
||||
toSQL(): Query;
|
||||
prepare(): SQLiteDeletePrepare<this>;
|
||||
run: ReturnType<this['prepare']>['run'];
|
||||
all: ReturnType<this['prepare']>['all'];
|
||||
get: ReturnType<this['prepare']>['get'];
|
||||
values: ReturnType<this['prepare']>['values'];
|
||||
execute(placeholderValues?: Record<string, unknown>): Promise<SQLiteDeleteExecute<this>>;
|
||||
$dynamic(): SQLiteDeleteDynamic<this>;
|
||||
}
|
||||
117
node_modules/drizzle-orm/sqlite-core/query-builders/delete.js
generated
vendored
Normal file
117
node_modules/drizzle-orm/sqlite-core/query-builders/delete.js
generated
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
import { entityKind } from "../../entity.js";
|
||||
import { QueryPromise } from "../../query-promise.js";
|
||||
import { SelectionProxyHandler } from "../../selection-proxy.js";
|
||||
import { SQLiteTable } from "../table.js";
|
||||
import { Table } from "../../table.js";
|
||||
import { orderSelectedFields } from "../../utils.js";
|
||||
class SQLiteDeleteBase extends QueryPromise {
|
||||
constructor(table, session, dialect, withList) {
|
||||
super();
|
||||
this.table = table;
|
||||
this.session = session;
|
||||
this.dialect = dialect;
|
||||
this.config = { table, withList };
|
||||
}
|
||||
static [entityKind] = "SQLiteDelete";
|
||||
/** @internal */
|
||||
config;
|
||||
/**
|
||||
* Adds a `where` clause to the query.
|
||||
*
|
||||
* Calling this method will delete only those rows that fulfill a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
||||
*
|
||||
* @param where the `where` clause.
|
||||
*
|
||||
* @example
|
||||
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
||||
*
|
||||
* ```ts
|
||||
* // Delete all cars with green color
|
||||
* db.delete(cars).where(eq(cars.color, 'green'));
|
||||
* // or
|
||||
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
||||
* ```
|
||||
*
|
||||
* You can logically combine conditional operators with `and()` and `or()` operators:
|
||||
*
|
||||
* ```ts
|
||||
* // Delete all BMW cars with a green color
|
||||
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
||||
*
|
||||
* // Delete all cars with the green or blue color
|
||||
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
||||
* ```
|
||||
*/
|
||||
where(where) {
|
||||
this.config.where = where;
|
||||
return this;
|
||||
}
|
||||
orderBy(...columns) {
|
||||
if (typeof columns[0] === "function") {
|
||||
const orderBy = columns[0](
|
||||
new Proxy(
|
||||
this.config.table[Table.Symbol.Columns],
|
||||
new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
||||
this.config.orderBy = orderByArray;
|
||||
} else {
|
||||
const orderByArray = columns;
|
||||
this.config.orderBy = orderByArray;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
limit(limit) {
|
||||
this.config.limit = limit;
|
||||
return this;
|
||||
}
|
||||
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
||||
this.config.returning = orderSelectedFields(fields);
|
||||
return this;
|
||||
}
|
||||
/** @internal */
|
||||
getSQL() {
|
||||
return this.dialect.buildDeleteQuery(this.config);
|
||||
}
|
||||
toSQL() {
|
||||
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
||||
return rest;
|
||||
}
|
||||
/** @internal */
|
||||
_prepare(isOneTimeQuery = true) {
|
||||
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
||||
this.dialect.sqlToQuery(this.getSQL()),
|
||||
this.config.returning,
|
||||
this.config.returning ? "all" : "run",
|
||||
true
|
||||
);
|
||||
}
|
||||
prepare() {
|
||||
return this._prepare(false);
|
||||
}
|
||||
run = (placeholderValues) => {
|
||||
return this._prepare().run(placeholderValues);
|
||||
};
|
||||
all = (placeholderValues) => {
|
||||
return this._prepare().all(placeholderValues);
|
||||
};
|
||||
get = (placeholderValues) => {
|
||||
return this._prepare().get(placeholderValues);
|
||||
};
|
||||
values = (placeholderValues) => {
|
||||
return this._prepare().values(placeholderValues);
|
||||
};
|
||||
async execute(placeholderValues) {
|
||||
return this._prepare().execute(placeholderValues);
|
||||
}
|
||||
$dynamic() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
export {
|
||||
SQLiteDeleteBase
|
||||
};
|
||||
//# sourceMappingURL=delete.js.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/delete.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/delete.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
33
node_modules/drizzle-orm/sqlite-core/query-builders/index.cjs
generated
vendored
Normal file
33
node_modules/drizzle-orm/sqlite-core/query-builders/index.cjs
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var query_builders_exports = {};
|
||||
module.exports = __toCommonJS(query_builders_exports);
|
||||
__reExport(query_builders_exports, require("./delete.cjs"), module.exports);
|
||||
__reExport(query_builders_exports, require("./insert.cjs"), module.exports);
|
||||
__reExport(query_builders_exports, require("./query-builder.cjs"), module.exports);
|
||||
__reExport(query_builders_exports, require("./select.cjs"), module.exports);
|
||||
__reExport(query_builders_exports, require("./select.types.cjs"), module.exports);
|
||||
__reExport(query_builders_exports, require("./update.cjs"), module.exports);
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
...require("./delete.cjs"),
|
||||
...require("./insert.cjs"),
|
||||
...require("./query-builder.cjs"),
|
||||
...require("./select.cjs"),
|
||||
...require("./select.types.cjs"),
|
||||
...require("./update.cjs")
|
||||
});
|
||||
//# sourceMappingURL=index.cjs.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/index.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/index.cjs.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/sqlite-core/query-builders/index.ts"],"sourcesContent":["export * from './delete.ts';\nexport * from './insert.ts';\nexport * from './query-builder.ts';\nexport * from './select.ts';\nexport * from './select.types.ts';\nexport * from './update.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,mCAAc,wBAAd;AACA,mCAAc,wBADd;AAEA,mCAAc,+BAFd;AAGA,mCAAc,wBAHd;AAIA,mCAAc,8BAJd;AAKA,mCAAc,wBALd;","names":[]}
|
||||
6
node_modules/drizzle-orm/sqlite-core/query-builders/index.d.cts
generated
vendored
Normal file
6
node_modules/drizzle-orm/sqlite-core/query-builders/index.d.cts
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
export * from "./delete.cjs";
|
||||
export * from "./insert.cjs";
|
||||
export * from "./query-builder.cjs";
|
||||
export * from "./select.cjs";
|
||||
export * from "./select.types.cjs";
|
||||
export * from "./update.cjs";
|
||||
6
node_modules/drizzle-orm/sqlite-core/query-builders/index.d.ts
generated
vendored
Normal file
6
node_modules/drizzle-orm/sqlite-core/query-builders/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
export * from "./delete.js";
|
||||
export * from "./insert.js";
|
||||
export * from "./query-builder.js";
|
||||
export * from "./select.js";
|
||||
export * from "./select.types.js";
|
||||
export * from "./update.js";
|
||||
7
node_modules/drizzle-orm/sqlite-core/query-builders/index.js
generated
vendored
Normal file
7
node_modules/drizzle-orm/sqlite-core/query-builders/index.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
export * from "./delete.js";
|
||||
export * from "./insert.js";
|
||||
export * from "./query-builder.js";
|
||||
export * from "./select.js";
|
||||
export * from "./select.types.js";
|
||||
export * from "./update.js";
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/index.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/index.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/sqlite-core/query-builders/index.ts"],"sourcesContent":["export * from './delete.ts';\nexport * from './insert.ts';\nexport * from './query-builder.ts';\nexport * from './select.ts';\nexport * from './select.types.ts';\nexport * from './update.ts';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
||||
199
node_modules/drizzle-orm/sqlite-core/query-builders/insert.cjs
generated
vendored
Normal file
199
node_modules/drizzle-orm/sqlite-core/query-builders/insert.cjs
generated
vendored
Normal file
@ -0,0 +1,199 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var insert_exports = {};
|
||||
__export(insert_exports, {
|
||||
SQLiteInsertBase: () => SQLiteInsertBase,
|
||||
SQLiteInsertBuilder: () => SQLiteInsertBuilder
|
||||
});
|
||||
module.exports = __toCommonJS(insert_exports);
|
||||
var import_entity = require("../../entity.cjs");
|
||||
var import_query_promise = require("../../query-promise.cjs");
|
||||
var import_sql = require("../../sql/sql.cjs");
|
||||
var import_table = require("../table.cjs");
|
||||
var import_table2 = require("../../table.cjs");
|
||||
var import_utils = require("../../utils.cjs");
|
||||
var import_query_builder = require("./query-builder.cjs");
|
||||
class SQLiteInsertBuilder {
|
||||
constructor(table, session, dialect, withList) {
|
||||
this.table = table;
|
||||
this.session = session;
|
||||
this.dialect = dialect;
|
||||
this.withList = withList;
|
||||
}
|
||||
static [import_entity.entityKind] = "SQLiteInsertBuilder";
|
||||
values(values) {
|
||||
values = Array.isArray(values) ? values : [values];
|
||||
if (values.length === 0) {
|
||||
throw new Error("values() must be called with at least one value");
|
||||
}
|
||||
const mappedValues = values.map((entry) => {
|
||||
const result = {};
|
||||
const cols = this.table[import_table2.Table.Symbol.Columns];
|
||||
for (const colKey of Object.keys(entry)) {
|
||||
const colValue = entry[colKey];
|
||||
result[colKey] = (0, import_entity.is)(colValue, import_sql.SQL) ? colValue : new import_sql.Param(colValue, cols[colKey]);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
return new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
||||
}
|
||||
select(selectQuery) {
|
||||
const select = typeof selectQuery === "function" ? selectQuery(new import_query_builder.QueryBuilder()) : selectQuery;
|
||||
if (!(0, import_entity.is)(select, import_sql.SQL) && !(0, import_utils.haveSameKeys)(this.table[import_table2.Columns], select._.selectedFields)) {
|
||||
throw new Error(
|
||||
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
||||
);
|
||||
}
|
||||
return new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
|
||||
}
|
||||
}
|
||||
class SQLiteInsertBase extends import_query_promise.QueryPromise {
|
||||
constructor(table, values, session, dialect, withList, select) {
|
||||
super();
|
||||
this.session = session;
|
||||
this.dialect = dialect;
|
||||
this.config = { table, values, withList, select };
|
||||
}
|
||||
static [import_entity.entityKind] = "SQLiteInsert";
|
||||
/** @internal */
|
||||
config;
|
||||
returning(fields = this.config.table[import_table.SQLiteTable.Symbol.Columns]) {
|
||||
this.config.returning = (0, import_utils.orderSelectedFields)(fields);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds an `on conflict do nothing` clause to the query.
|
||||
*
|
||||
* Calling this method simply avoids inserting a row as its alternative action.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
||||
*
|
||||
* @param config The `target` and `where` clauses.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Insert one row and cancel the insert if there's a conflict
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoNothing();
|
||||
*
|
||||
* // Explicitly specify conflict target
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoNothing({ target: cars.id });
|
||||
* ```
|
||||
*/
|
||||
onConflictDoNothing(config = {}) {
|
||||
if (config.target === void 0) {
|
||||
this.config.onConflict = import_sql.sql`do nothing`;
|
||||
} else {
|
||||
const targetSql = Array.isArray(config.target) ? import_sql.sql`${config.target}` : import_sql.sql`${[config.target]}`;
|
||||
const whereSql = config.where ? import_sql.sql` where ${config.where}` : import_sql.sql``;
|
||||
this.config.onConflict = import_sql.sql`${targetSql} do nothing${whereSql}`;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds an `on conflict do update` clause to the query.
|
||||
*
|
||||
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
||||
*
|
||||
* @param config The `target`, `set` and `where` clauses.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Update the row if there's a conflict
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoUpdate({
|
||||
* target: cars.id,
|
||||
* set: { brand: 'Porsche' }
|
||||
* });
|
||||
*
|
||||
* // Upsert with 'where' clause
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoUpdate({
|
||||
* target: cars.id,
|
||||
* set: { brand: 'newBMW' },
|
||||
* where: sql`${cars.createdAt} > '2023-01-01'::date`,
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
onConflictDoUpdate(config) {
|
||||
if (config.where && (config.targetWhere || config.setWhere)) {
|
||||
throw new Error(
|
||||
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
||||
);
|
||||
}
|
||||
const whereSql = config.where ? import_sql.sql` where ${config.where}` : void 0;
|
||||
const targetWhereSql = config.targetWhere ? import_sql.sql` where ${config.targetWhere}` : void 0;
|
||||
const setWhereSql = config.setWhere ? import_sql.sql` where ${config.setWhere}` : void 0;
|
||||
const targetSql = Array.isArray(config.target) ? import_sql.sql`${config.target}` : import_sql.sql`${[config.target]}`;
|
||||
const setSql = this.dialect.buildUpdateSet(this.config.table, (0, import_utils.mapUpdateSet)(this.config.table, config.set));
|
||||
this.config.onConflict = import_sql.sql`${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
||||
return this;
|
||||
}
|
||||
/** @internal */
|
||||
getSQL() {
|
||||
return this.dialect.buildInsertQuery(this.config);
|
||||
}
|
||||
toSQL() {
|
||||
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
||||
return rest;
|
||||
}
|
||||
/** @internal */
|
||||
_prepare(isOneTimeQuery = true) {
|
||||
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
||||
this.dialect.sqlToQuery(this.getSQL()),
|
||||
this.config.returning,
|
||||
this.config.returning ? "all" : "run",
|
||||
true
|
||||
);
|
||||
}
|
||||
prepare() {
|
||||
return this._prepare(false);
|
||||
}
|
||||
run = (placeholderValues) => {
|
||||
return this._prepare().run(placeholderValues);
|
||||
};
|
||||
all = (placeholderValues) => {
|
||||
return this._prepare().all(placeholderValues);
|
||||
};
|
||||
get = (placeholderValues) => {
|
||||
return this._prepare().get(placeholderValues);
|
||||
};
|
||||
values = (placeholderValues) => {
|
||||
return this._prepare().values(placeholderValues);
|
||||
};
|
||||
async execute() {
|
||||
return this.config.returning ? this.all() : this.run();
|
||||
}
|
||||
$dynamic() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
SQLiteInsertBase,
|
||||
SQLiteInsertBuilder
|
||||
});
|
||||
//# sourceMappingURL=insert.cjs.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/insert.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/insert.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
172
node_modules/drizzle-orm/sqlite-core/query-builders/insert.d.cts
generated
vendored
Normal file
172
node_modules/drizzle-orm/sqlite-core/query-builders/insert.d.cts
generated
vendored
Normal file
@ -0,0 +1,172 @@
|
||||
import { entityKind } from "../../entity.cjs";
|
||||
import type { TypedQueryBuilder } from "../../query-builders/query-builder.cjs";
|
||||
import type { SelectResultFields } from "../../query-builders/select.types.cjs";
|
||||
import { QueryPromise } from "../../query-promise.cjs";
|
||||
import type { RunnableQuery } from "../../runnable-query.cjs";
|
||||
import type { Placeholder, Query, SQLWrapper } from "../../sql/sql.cjs";
|
||||
import { Param, SQL } from "../../sql/sql.cjs";
|
||||
import type { SQLiteDialect } from "../dialect.cjs";
|
||||
import type { IndexColumn } from "../indexes.cjs";
|
||||
import type { SQLitePreparedQuery, SQLiteSession } from "../session.cjs";
|
||||
import { SQLiteTable } from "../table.cjs";
|
||||
import type { Subquery } from "../../subquery.cjs";
|
||||
import { type DrizzleTypeError, type Simplify } from "../../utils.cjs";
|
||||
import type { AnySQLiteColumn } from "../columns/common.cjs";
|
||||
import { QueryBuilder } from "./query-builder.cjs";
|
||||
import type { SelectedFieldsFlat, SelectedFieldsOrdered } from "./select.types.cjs";
|
||||
import type { SQLiteUpdateSetSource } from "./update.cjs";
|
||||
export interface SQLiteInsertConfig<TTable extends SQLiteTable = SQLiteTable> {
|
||||
table: TTable;
|
||||
values: Record<string, Param | SQL>[] | SQLiteInsertSelectQueryBuilder<TTable> | SQL;
|
||||
withList?: Subquery[];
|
||||
onConflict?: SQL;
|
||||
returning?: SelectedFieldsOrdered;
|
||||
select?: boolean;
|
||||
}
|
||||
export type SQLiteInsertValue<TTable extends SQLiteTable> = Simplify<{
|
||||
[Key in keyof TTable['$inferInsert']]: TTable['$inferInsert'][Key] | SQL | Placeholder;
|
||||
}>;
|
||||
export type SQLiteInsertSelectQueryBuilder<TTable extends SQLiteTable> = TypedQueryBuilder<{
|
||||
[K in keyof TTable['$inferInsert']]: AnySQLiteColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K];
|
||||
}>;
|
||||
export declare class SQLiteInsertBuilder<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult> {
|
||||
protected table: TTable;
|
||||
protected session: SQLiteSession<any, any, any, any>;
|
||||
protected dialect: SQLiteDialect;
|
||||
private withList?;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(table: TTable, session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[] | undefined);
|
||||
values(value: SQLiteInsertValue<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;
|
||||
values(values: SQLiteInsertValue<TTable>[]): SQLiteInsertBase<TTable, TResultType, TRunResult>;
|
||||
select(selectQuery: (qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;
|
||||
select(selectQuery: (qb: QueryBuilder) => SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;
|
||||
select(selectQuery: SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;
|
||||
select(selectQuery: SQLiteInsertSelectQueryBuilder<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;
|
||||
}
|
||||
export type SQLiteInsertWithout<T extends AnySQLiteInsert, TDynamic extends boolean, K extends keyof T & string> = TDynamic extends true ? T : Omit<SQLiteInsertBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['returning'], TDynamic, T['_']['excludedMethods'] | K>, T['_']['excludedMethods'] | K>;
|
||||
export type SQLiteInsertReturning<T extends AnySQLiteInsert, TDynamic extends boolean, TSelectedFields extends SelectedFieldsFlat> = SQLiteInsertWithout<SQLiteInsertBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], SelectResultFields<TSelectedFields>, TDynamic, T['_']['excludedMethods']>, TDynamic, 'returning'>;
|
||||
export type SQLiteInsertReturningAll<T extends AnySQLiteInsert, TDynamic extends boolean> = SQLiteInsertWithout<SQLiteInsertBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['table']['$inferSelect'], TDynamic, T['_']['excludedMethods']>, TDynamic, 'returning'>;
|
||||
export type SQLiteInsertOnConflictDoUpdateConfig<T extends AnySQLiteInsert> = {
|
||||
target: IndexColumn | IndexColumn[];
|
||||
/** @deprecated - use either `targetWhere` or `setWhere` */
|
||||
where?: SQL;
|
||||
targetWhere?: SQL;
|
||||
setWhere?: SQL;
|
||||
set: SQLiteUpdateSetSource<T['_']['table']>;
|
||||
};
|
||||
export type SQLiteInsertDynamic<T extends AnySQLiteInsert> = SQLiteInsert<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['returning']>;
|
||||
export type SQLiteInsertExecute<T extends AnySQLiteInsert> = T['_']['returning'] extends undefined ? T['_']['runResult'] : T['_']['returning'][];
|
||||
export type SQLiteInsertPrepare<T extends AnySQLiteInsert> = SQLitePreparedQuery<{
|
||||
type: T['_']['resultType'];
|
||||
run: T['_']['runResult'];
|
||||
all: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'> : T['_']['returning'][];
|
||||
get: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'> : T['_']['returning'];
|
||||
values: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'> : any[][];
|
||||
execute: SQLiteInsertExecute<T>;
|
||||
}>;
|
||||
export type AnySQLiteInsert = SQLiteInsertBase<any, any, any, any, any, any>;
|
||||
export type SQLiteInsert<TTable extends SQLiteTable = SQLiteTable, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = unknown, TReturning = any> = SQLiteInsertBase<TTable, TResultType, TRunResult, TReturning, true, never>;
|
||||
export interface SQLiteInsertBase<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult, TReturning = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends SQLWrapper, QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>, RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'> {
|
||||
readonly _: {
|
||||
readonly dialect: 'sqlite';
|
||||
readonly table: TTable;
|
||||
readonly resultType: TResultType;
|
||||
readonly runResult: TRunResult;
|
||||
readonly returning: TReturning;
|
||||
readonly dynamic: TDynamic;
|
||||
readonly excludedMethods: TExcludedMethods;
|
||||
readonly result: TReturning extends undefined ? TRunResult : TReturning[];
|
||||
};
|
||||
}
|
||||
export declare class SQLiteInsertBase<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult, TReturning = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]> implements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper {
|
||||
private session;
|
||||
private dialect;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(table: TTable, values: SQLiteInsertConfig['values'], session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[], select?: boolean);
|
||||
/**
|
||||
* Adds a `returning` clause to the query.
|
||||
*
|
||||
* Calling this method will return the specified fields of the inserted rows. If no fields are specified, all fields will be returned.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/insert#insert-returning}
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Insert one row and return all fields
|
||||
* const insertedCar: Car[] = await db.insert(cars)
|
||||
* .values({ brand: 'BMW' })
|
||||
* .returning();
|
||||
*
|
||||
* // Insert one row and return only the id
|
||||
* const insertedCarId: { id: number }[] = await db.insert(cars)
|
||||
* .values({ brand: 'BMW' })
|
||||
* .returning({ id: cars.id });
|
||||
* ```
|
||||
*/
|
||||
returning(): SQLiteInsertReturningAll<this, TDynamic>;
|
||||
returning<TSelectedFields extends SelectedFieldsFlat>(fields: TSelectedFields): SQLiteInsertReturning<this, TDynamic, TSelectedFields>;
|
||||
/**
|
||||
* Adds an `on conflict do nothing` clause to the query.
|
||||
*
|
||||
* Calling this method simply avoids inserting a row as its alternative action.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
||||
*
|
||||
* @param config The `target` and `where` clauses.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Insert one row and cancel the insert if there's a conflict
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoNothing();
|
||||
*
|
||||
* // Explicitly specify conflict target
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoNothing({ target: cars.id });
|
||||
* ```
|
||||
*/
|
||||
onConflictDoNothing(config?: {
|
||||
target?: IndexColumn | IndexColumn[];
|
||||
where?: SQL;
|
||||
}): this;
|
||||
/**
|
||||
* Adds an `on conflict do update` clause to the query.
|
||||
*
|
||||
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
||||
*
|
||||
* @param config The `target`, `set` and `where` clauses.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Update the row if there's a conflict
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoUpdate({
|
||||
* target: cars.id,
|
||||
* set: { brand: 'Porsche' }
|
||||
* });
|
||||
*
|
||||
* // Upsert with 'where' clause
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoUpdate({
|
||||
* target: cars.id,
|
||||
* set: { brand: 'newBMW' },
|
||||
* where: sql`${cars.createdAt} > '2023-01-01'::date`,
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
onConflictDoUpdate(config: SQLiteInsertOnConflictDoUpdateConfig<this>): this;
|
||||
toSQL(): Query;
|
||||
prepare(): SQLiteInsertPrepare<this>;
|
||||
run: ReturnType<this['prepare']>['run'];
|
||||
all: ReturnType<this['prepare']>['all'];
|
||||
get: ReturnType<this['prepare']>['get'];
|
||||
values: ReturnType<this['prepare']>['values'];
|
||||
execute(): Promise<SQLiteInsertExecute<this>>;
|
||||
$dynamic(): SQLiteInsertDynamic<this>;
|
||||
}
|
||||
172
node_modules/drizzle-orm/sqlite-core/query-builders/insert.d.ts
generated
vendored
Normal file
172
node_modules/drizzle-orm/sqlite-core/query-builders/insert.d.ts
generated
vendored
Normal file
@ -0,0 +1,172 @@
|
||||
import { entityKind } from "../../entity.js";
|
||||
import type { TypedQueryBuilder } from "../../query-builders/query-builder.js";
|
||||
import type { SelectResultFields } from "../../query-builders/select.types.js";
|
||||
import { QueryPromise } from "../../query-promise.js";
|
||||
import type { RunnableQuery } from "../../runnable-query.js";
|
||||
import type { Placeholder, Query, SQLWrapper } from "../../sql/sql.js";
|
||||
import { Param, SQL } from "../../sql/sql.js";
|
||||
import type { SQLiteDialect } from "../dialect.js";
|
||||
import type { IndexColumn } from "../indexes.js";
|
||||
import type { SQLitePreparedQuery, SQLiteSession } from "../session.js";
|
||||
import { SQLiteTable } from "../table.js";
|
||||
import type { Subquery } from "../../subquery.js";
|
||||
import { type DrizzleTypeError, type Simplify } from "../../utils.js";
|
||||
import type { AnySQLiteColumn } from "../columns/common.js";
|
||||
import { QueryBuilder } from "./query-builder.js";
|
||||
import type { SelectedFieldsFlat, SelectedFieldsOrdered } from "./select.types.js";
|
||||
import type { SQLiteUpdateSetSource } from "./update.js";
|
||||
export interface SQLiteInsertConfig<TTable extends SQLiteTable = SQLiteTable> {
|
||||
table: TTable;
|
||||
values: Record<string, Param | SQL>[] | SQLiteInsertSelectQueryBuilder<TTable> | SQL;
|
||||
withList?: Subquery[];
|
||||
onConflict?: SQL;
|
||||
returning?: SelectedFieldsOrdered;
|
||||
select?: boolean;
|
||||
}
|
||||
export type SQLiteInsertValue<TTable extends SQLiteTable> = Simplify<{
|
||||
[Key in keyof TTable['$inferInsert']]: TTable['$inferInsert'][Key] | SQL | Placeholder;
|
||||
}>;
|
||||
export type SQLiteInsertSelectQueryBuilder<TTable extends SQLiteTable> = TypedQueryBuilder<{
|
||||
[K in keyof TTable['$inferInsert']]: AnySQLiteColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K];
|
||||
}>;
|
||||
export declare class SQLiteInsertBuilder<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult> {
|
||||
protected table: TTable;
|
||||
protected session: SQLiteSession<any, any, any, any>;
|
||||
protected dialect: SQLiteDialect;
|
||||
private withList?;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(table: TTable, session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[] | undefined);
|
||||
values(value: SQLiteInsertValue<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;
|
||||
values(values: SQLiteInsertValue<TTable>[]): SQLiteInsertBase<TTable, TResultType, TRunResult>;
|
||||
select(selectQuery: (qb: QueryBuilder) => SQLiteInsertSelectQueryBuilder<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;
|
||||
select(selectQuery: (qb: QueryBuilder) => SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;
|
||||
select(selectQuery: SQL): SQLiteInsertBase<TTable, TResultType, TRunResult>;
|
||||
select(selectQuery: SQLiteInsertSelectQueryBuilder<TTable>): SQLiteInsertBase<TTable, TResultType, TRunResult>;
|
||||
}
|
||||
export type SQLiteInsertWithout<T extends AnySQLiteInsert, TDynamic extends boolean, K extends keyof T & string> = TDynamic extends true ? T : Omit<SQLiteInsertBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['returning'], TDynamic, T['_']['excludedMethods'] | K>, T['_']['excludedMethods'] | K>;
|
||||
export type SQLiteInsertReturning<T extends AnySQLiteInsert, TDynamic extends boolean, TSelectedFields extends SelectedFieldsFlat> = SQLiteInsertWithout<SQLiteInsertBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], SelectResultFields<TSelectedFields>, TDynamic, T['_']['excludedMethods']>, TDynamic, 'returning'>;
|
||||
export type SQLiteInsertReturningAll<T extends AnySQLiteInsert, TDynamic extends boolean> = SQLiteInsertWithout<SQLiteInsertBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['table']['$inferSelect'], TDynamic, T['_']['excludedMethods']>, TDynamic, 'returning'>;
|
||||
export type SQLiteInsertOnConflictDoUpdateConfig<T extends AnySQLiteInsert> = {
|
||||
target: IndexColumn | IndexColumn[];
|
||||
/** @deprecated - use either `targetWhere` or `setWhere` */
|
||||
where?: SQL;
|
||||
targetWhere?: SQL;
|
||||
setWhere?: SQL;
|
||||
set: SQLiteUpdateSetSource<T['_']['table']>;
|
||||
};
|
||||
export type SQLiteInsertDynamic<T extends AnySQLiteInsert> = SQLiteInsert<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['returning']>;
|
||||
export type SQLiteInsertExecute<T extends AnySQLiteInsert> = T['_']['returning'] extends undefined ? T['_']['runResult'] : T['_']['returning'][];
|
||||
export type SQLiteInsertPrepare<T extends AnySQLiteInsert> = SQLitePreparedQuery<{
|
||||
type: T['_']['resultType'];
|
||||
run: T['_']['runResult'];
|
||||
all: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'> : T['_']['returning'][];
|
||||
get: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'> : T['_']['returning'];
|
||||
values: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'> : any[][];
|
||||
execute: SQLiteInsertExecute<T>;
|
||||
}>;
|
||||
export type AnySQLiteInsert = SQLiteInsertBase<any, any, any, any, any, any>;
|
||||
export type SQLiteInsert<TTable extends SQLiteTable = SQLiteTable, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = unknown, TReturning = any> = SQLiteInsertBase<TTable, TResultType, TRunResult, TReturning, true, never>;
|
||||
export interface SQLiteInsertBase<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult, TReturning = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends SQLWrapper, QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>, RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'> {
|
||||
readonly _: {
|
||||
readonly dialect: 'sqlite';
|
||||
readonly table: TTable;
|
||||
readonly resultType: TResultType;
|
||||
readonly runResult: TRunResult;
|
||||
readonly returning: TReturning;
|
||||
readonly dynamic: TDynamic;
|
||||
readonly excludedMethods: TExcludedMethods;
|
||||
readonly result: TReturning extends undefined ? TRunResult : TReturning[];
|
||||
};
|
||||
}
|
||||
export declare class SQLiteInsertBase<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult, TReturning = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]> implements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper {
|
||||
private session;
|
||||
private dialect;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(table: TTable, values: SQLiteInsertConfig['values'], session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[], select?: boolean);
|
||||
/**
|
||||
* Adds a `returning` clause to the query.
|
||||
*
|
||||
* Calling this method will return the specified fields of the inserted rows. If no fields are specified, all fields will be returned.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/insert#insert-returning}
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Insert one row and return all fields
|
||||
* const insertedCar: Car[] = await db.insert(cars)
|
||||
* .values({ brand: 'BMW' })
|
||||
* .returning();
|
||||
*
|
||||
* // Insert one row and return only the id
|
||||
* const insertedCarId: { id: number }[] = await db.insert(cars)
|
||||
* .values({ brand: 'BMW' })
|
||||
* .returning({ id: cars.id });
|
||||
* ```
|
||||
*/
|
||||
returning(): SQLiteInsertReturningAll<this, TDynamic>;
|
||||
returning<TSelectedFields extends SelectedFieldsFlat>(fields: TSelectedFields): SQLiteInsertReturning<this, TDynamic, TSelectedFields>;
|
||||
/**
|
||||
* Adds an `on conflict do nothing` clause to the query.
|
||||
*
|
||||
* Calling this method simply avoids inserting a row as its alternative action.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
||||
*
|
||||
* @param config The `target` and `where` clauses.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Insert one row and cancel the insert if there's a conflict
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoNothing();
|
||||
*
|
||||
* // Explicitly specify conflict target
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoNothing({ target: cars.id });
|
||||
* ```
|
||||
*/
|
||||
onConflictDoNothing(config?: {
|
||||
target?: IndexColumn | IndexColumn[];
|
||||
where?: SQL;
|
||||
}): this;
|
||||
/**
|
||||
* Adds an `on conflict do update` clause to the query.
|
||||
*
|
||||
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
||||
*
|
||||
* @param config The `target`, `set` and `where` clauses.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Update the row if there's a conflict
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoUpdate({
|
||||
* target: cars.id,
|
||||
* set: { brand: 'Porsche' }
|
||||
* });
|
||||
*
|
||||
* // Upsert with 'where' clause
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoUpdate({
|
||||
* target: cars.id,
|
||||
* set: { brand: 'newBMW' },
|
||||
* where: sql`${cars.createdAt} > '2023-01-01'::date`,
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
onConflictDoUpdate(config: SQLiteInsertOnConflictDoUpdateConfig<this>): this;
|
||||
toSQL(): Query;
|
||||
prepare(): SQLiteInsertPrepare<this>;
|
||||
run: ReturnType<this['prepare']>['run'];
|
||||
all: ReturnType<this['prepare']>['all'];
|
||||
get: ReturnType<this['prepare']>['get'];
|
||||
values: ReturnType<this['prepare']>['values'];
|
||||
execute(): Promise<SQLiteInsertExecute<this>>;
|
||||
$dynamic(): SQLiteInsertDynamic<this>;
|
||||
}
|
||||
174
node_modules/drizzle-orm/sqlite-core/query-builders/insert.js
generated
vendored
Normal file
174
node_modules/drizzle-orm/sqlite-core/query-builders/insert.js
generated
vendored
Normal file
@ -0,0 +1,174 @@
|
||||
import { entityKind, is } from "../../entity.js";
|
||||
import { QueryPromise } from "../../query-promise.js";
|
||||
import { Param, SQL, sql } from "../../sql/sql.js";
|
||||
import { SQLiteTable } from "../table.js";
|
||||
import { Columns, Table } from "../../table.js";
|
||||
import { haveSameKeys, mapUpdateSet, orderSelectedFields } from "../../utils.js";
|
||||
import { QueryBuilder } from "./query-builder.js";
|
||||
class SQLiteInsertBuilder {
|
||||
constructor(table, session, dialect, withList) {
|
||||
this.table = table;
|
||||
this.session = session;
|
||||
this.dialect = dialect;
|
||||
this.withList = withList;
|
||||
}
|
||||
static [entityKind] = "SQLiteInsertBuilder";
|
||||
values(values) {
|
||||
values = Array.isArray(values) ? values : [values];
|
||||
if (values.length === 0) {
|
||||
throw new Error("values() must be called with at least one value");
|
||||
}
|
||||
const mappedValues = values.map((entry) => {
|
||||
const result = {};
|
||||
const cols = this.table[Table.Symbol.Columns];
|
||||
for (const colKey of Object.keys(entry)) {
|
||||
const colValue = entry[colKey];
|
||||
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
return new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
||||
}
|
||||
select(selectQuery) {
|
||||
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
|
||||
if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
|
||||
throw new Error(
|
||||
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
||||
);
|
||||
}
|
||||
return new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
|
||||
}
|
||||
}
|
||||
class SQLiteInsertBase extends QueryPromise {
|
||||
constructor(table, values, session, dialect, withList, select) {
|
||||
super();
|
||||
this.session = session;
|
||||
this.dialect = dialect;
|
||||
this.config = { table, values, withList, select };
|
||||
}
|
||||
static [entityKind] = "SQLiteInsert";
|
||||
/** @internal */
|
||||
config;
|
||||
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
||||
this.config.returning = orderSelectedFields(fields);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds an `on conflict do nothing` clause to the query.
|
||||
*
|
||||
* Calling this method simply avoids inserting a row as its alternative action.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
||||
*
|
||||
* @param config The `target` and `where` clauses.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Insert one row and cancel the insert if there's a conflict
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoNothing();
|
||||
*
|
||||
* // Explicitly specify conflict target
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoNothing({ target: cars.id });
|
||||
* ```
|
||||
*/
|
||||
onConflictDoNothing(config = {}) {
|
||||
if (config.target === void 0) {
|
||||
this.config.onConflict = sql`do nothing`;
|
||||
} else {
|
||||
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
||||
const whereSql = config.where ? sql` where ${config.where}` : sql``;
|
||||
this.config.onConflict = sql`${targetSql} do nothing${whereSql}`;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds an `on conflict do update` clause to the query.
|
||||
*
|
||||
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
||||
*
|
||||
* @param config The `target`, `set` and `where` clauses.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Update the row if there's a conflict
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoUpdate({
|
||||
* target: cars.id,
|
||||
* set: { brand: 'Porsche' }
|
||||
* });
|
||||
*
|
||||
* // Upsert with 'where' clause
|
||||
* await db.insert(cars)
|
||||
* .values({ id: 1, brand: 'BMW' })
|
||||
* .onConflictDoUpdate({
|
||||
* target: cars.id,
|
||||
* set: { brand: 'newBMW' },
|
||||
* where: sql`${cars.createdAt} > '2023-01-01'::date`,
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
onConflictDoUpdate(config) {
|
||||
if (config.where && (config.targetWhere || config.setWhere)) {
|
||||
throw new Error(
|
||||
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
||||
);
|
||||
}
|
||||
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
||||
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
||||
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
||||
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
||||
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
||||
this.config.onConflict = sql`${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
||||
return this;
|
||||
}
|
||||
/** @internal */
|
||||
getSQL() {
|
||||
return this.dialect.buildInsertQuery(this.config);
|
||||
}
|
||||
toSQL() {
|
||||
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
||||
return rest;
|
||||
}
|
||||
/** @internal */
|
||||
_prepare(isOneTimeQuery = true) {
|
||||
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
||||
this.dialect.sqlToQuery(this.getSQL()),
|
||||
this.config.returning,
|
||||
this.config.returning ? "all" : "run",
|
||||
true
|
||||
);
|
||||
}
|
||||
prepare() {
|
||||
return this._prepare(false);
|
||||
}
|
||||
run = (placeholderValues) => {
|
||||
return this._prepare().run(placeholderValues);
|
||||
};
|
||||
all = (placeholderValues) => {
|
||||
return this._prepare().all(placeholderValues);
|
||||
};
|
||||
get = (placeholderValues) => {
|
||||
return this._prepare().get(placeholderValues);
|
||||
};
|
||||
values = (placeholderValues) => {
|
||||
return this._prepare().values(placeholderValues);
|
||||
};
|
||||
async execute() {
|
||||
return this.config.returning ? this.all() : this.run();
|
||||
}
|
||||
$dynamic() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
export {
|
||||
SQLiteInsertBase,
|
||||
SQLiteInsertBuilder
|
||||
};
|
||||
//# sourceMappingURL=insert.js.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/insert.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/insert.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
95
node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.cjs
generated
vendored
Normal file
95
node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.cjs
generated
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var query_builder_exports = {};
|
||||
__export(query_builder_exports, {
|
||||
QueryBuilder: () => QueryBuilder
|
||||
});
|
||||
module.exports = __toCommonJS(query_builder_exports);
|
||||
var import_entity = require("../../entity.cjs");
|
||||
var import_selection_proxy = require("../../selection-proxy.cjs");
|
||||
var import_dialect = require("../dialect.cjs");
|
||||
var import_subquery = require("../../subquery.cjs");
|
||||
var import_select = require("./select.cjs");
|
||||
class QueryBuilder {
|
||||
static [import_entity.entityKind] = "SQLiteQueryBuilder";
|
||||
dialect;
|
||||
dialectConfig;
|
||||
constructor(dialect) {
|
||||
this.dialect = (0, import_entity.is)(dialect, import_dialect.SQLiteDialect) ? dialect : void 0;
|
||||
this.dialectConfig = (0, import_entity.is)(dialect, import_dialect.SQLiteDialect) ? void 0 : dialect;
|
||||
}
|
||||
$with(alias) {
|
||||
const queryBuilder = this;
|
||||
return {
|
||||
as(qb) {
|
||||
if (typeof qb === "function") {
|
||||
qb = qb(queryBuilder);
|
||||
}
|
||||
return new Proxy(
|
||||
new import_subquery.WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
|
||||
new import_selection_proxy.SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
with(...queries) {
|
||||
const self = this;
|
||||
function select(fields) {
|
||||
return new import_select.SQLiteSelectBuilder({
|
||||
fields: fields ?? void 0,
|
||||
session: void 0,
|
||||
dialect: self.getDialect(),
|
||||
withList: queries
|
||||
});
|
||||
}
|
||||
function selectDistinct(fields) {
|
||||
return new import_select.SQLiteSelectBuilder({
|
||||
fields: fields ?? void 0,
|
||||
session: void 0,
|
||||
dialect: self.getDialect(),
|
||||
withList: queries,
|
||||
distinct: true
|
||||
});
|
||||
}
|
||||
return { select, selectDistinct };
|
||||
}
|
||||
select(fields) {
|
||||
return new import_select.SQLiteSelectBuilder({ fields: fields ?? void 0, session: void 0, dialect: this.getDialect() });
|
||||
}
|
||||
selectDistinct(fields) {
|
||||
return new import_select.SQLiteSelectBuilder({
|
||||
fields: fields ?? void 0,
|
||||
session: void 0,
|
||||
dialect: this.getDialect(),
|
||||
distinct: true
|
||||
});
|
||||
}
|
||||
// Lazy load dialect to avoid circular dependency
|
||||
getDialect() {
|
||||
if (!this.dialect) {
|
||||
this.dialect = new import_dialect.SQLiteSyncDialect(this.dialectConfig);
|
||||
}
|
||||
return this.dialect;
|
||||
}
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
QueryBuilder
|
||||
});
|
||||
//# sourceMappingURL=query-builder.cjs.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
33
node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.d.cts
generated
vendored
Normal file
33
node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.d.cts
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
import { entityKind } from "../../entity.cjs";
|
||||
import type { TypedQueryBuilder } from "../../query-builders/query-builder.cjs";
|
||||
import type { ColumnsSelection } from "../../sql/sql.cjs";
|
||||
import type { SQLiteDialectConfig } from "../dialect.cjs";
|
||||
import { SQLiteDialect } from "../dialect.cjs";
|
||||
import type { WithSubqueryWithSelection } from "../subquery.cjs";
|
||||
import { WithSubquery } from "../../subquery.cjs";
|
||||
import { SQLiteSelectBuilder } from "./select.cjs";
|
||||
import type { SelectedFields } from "./select.types.cjs";
|
||||
export declare class QueryBuilder {
|
||||
static readonly [entityKind]: string;
|
||||
private dialect;
|
||||
private dialectConfig;
|
||||
constructor(dialect?: SQLiteDialect | SQLiteDialectConfig);
|
||||
$with<TAlias extends string>(alias: TAlias): {
|
||||
as<TSelection extends ColumnsSelection>(qb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>)): WithSubqueryWithSelection<TSelection, TAlias>;
|
||||
};
|
||||
with(...queries: WithSubquery[]): {
|
||||
select: {
|
||||
(): SQLiteSelectBuilder<undefined, "sync", void, "qb">;
|
||||
<TSelection extends SelectedFields>(fields: TSelection): SQLiteSelectBuilder<TSelection, "sync", void, "qb">;
|
||||
};
|
||||
selectDistinct: {
|
||||
(): SQLiteSelectBuilder<undefined, "sync", void, "qb">;
|
||||
<TSelection extends SelectedFields>(fields: TSelection): SQLiteSelectBuilder<TSelection, "sync", void, "qb">;
|
||||
};
|
||||
};
|
||||
select(): SQLiteSelectBuilder<undefined, 'sync', void, 'qb'>;
|
||||
select<TSelection extends SelectedFields>(fields: TSelection): SQLiteSelectBuilder<TSelection, 'sync', void, 'qb'>;
|
||||
selectDistinct(): SQLiteSelectBuilder<undefined, 'sync', void, 'qb'>;
|
||||
selectDistinct<TSelection extends SelectedFields>(fields: TSelection): SQLiteSelectBuilder<TSelection, 'sync', void, 'qb'>;
|
||||
private getDialect;
|
||||
}
|
||||
33
node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.d.ts
generated
vendored
Normal file
33
node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.d.ts
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
import { entityKind } from "../../entity.js";
|
||||
import type { TypedQueryBuilder } from "../../query-builders/query-builder.js";
|
||||
import type { ColumnsSelection } from "../../sql/sql.js";
|
||||
import type { SQLiteDialectConfig } from "../dialect.js";
|
||||
import { SQLiteDialect } from "../dialect.js";
|
||||
import type { WithSubqueryWithSelection } from "../subquery.js";
|
||||
import { WithSubquery } from "../../subquery.js";
|
||||
import { SQLiteSelectBuilder } from "./select.js";
|
||||
import type { SelectedFields } from "./select.types.js";
|
||||
export declare class QueryBuilder {
|
||||
static readonly [entityKind]: string;
|
||||
private dialect;
|
||||
private dialectConfig;
|
||||
constructor(dialect?: SQLiteDialect | SQLiteDialectConfig);
|
||||
$with<TAlias extends string>(alias: TAlias): {
|
||||
as<TSelection extends ColumnsSelection>(qb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>)): WithSubqueryWithSelection<TSelection, TAlias>;
|
||||
};
|
||||
with(...queries: WithSubquery[]): {
|
||||
select: {
|
||||
(): SQLiteSelectBuilder<undefined, "sync", void, "qb">;
|
||||
<TSelection extends SelectedFields>(fields: TSelection): SQLiteSelectBuilder<TSelection, "sync", void, "qb">;
|
||||
};
|
||||
selectDistinct: {
|
||||
(): SQLiteSelectBuilder<undefined, "sync", void, "qb">;
|
||||
<TSelection extends SelectedFields>(fields: TSelection): SQLiteSelectBuilder<TSelection, "sync", void, "qb">;
|
||||
};
|
||||
};
|
||||
select(): SQLiteSelectBuilder<undefined, 'sync', void, 'qb'>;
|
||||
select<TSelection extends SelectedFields>(fields: TSelection): SQLiteSelectBuilder<TSelection, 'sync', void, 'qb'>;
|
||||
selectDistinct(): SQLiteSelectBuilder<undefined, 'sync', void, 'qb'>;
|
||||
selectDistinct<TSelection extends SelectedFields>(fields: TSelection): SQLiteSelectBuilder<TSelection, 'sync', void, 'qb'>;
|
||||
private getDialect;
|
||||
}
|
||||
71
node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.js
generated
vendored
Normal file
71
node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.js
generated
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
import { entityKind, is } from "../../entity.js";
|
||||
import { SelectionProxyHandler } from "../../selection-proxy.js";
|
||||
import { SQLiteDialect, SQLiteSyncDialect } from "../dialect.js";
|
||||
import { WithSubquery } from "../../subquery.js";
|
||||
import { SQLiteSelectBuilder } from "./select.js";
|
||||
class QueryBuilder {
|
||||
static [entityKind] = "SQLiteQueryBuilder";
|
||||
dialect;
|
||||
dialectConfig;
|
||||
constructor(dialect) {
|
||||
this.dialect = is(dialect, SQLiteDialect) ? dialect : void 0;
|
||||
this.dialectConfig = is(dialect, SQLiteDialect) ? void 0 : dialect;
|
||||
}
|
||||
$with(alias) {
|
||||
const queryBuilder = this;
|
||||
return {
|
||||
as(qb) {
|
||||
if (typeof qb === "function") {
|
||||
qb = qb(queryBuilder);
|
||||
}
|
||||
return new Proxy(
|
||||
new WithSubquery(qb.getSQL(), qb.getSelectedFields(), alias, true),
|
||||
new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
with(...queries) {
|
||||
const self = this;
|
||||
function select(fields) {
|
||||
return new SQLiteSelectBuilder({
|
||||
fields: fields ?? void 0,
|
||||
session: void 0,
|
||||
dialect: self.getDialect(),
|
||||
withList: queries
|
||||
});
|
||||
}
|
||||
function selectDistinct(fields) {
|
||||
return new SQLiteSelectBuilder({
|
||||
fields: fields ?? void 0,
|
||||
session: void 0,
|
||||
dialect: self.getDialect(),
|
||||
withList: queries,
|
||||
distinct: true
|
||||
});
|
||||
}
|
||||
return { select, selectDistinct };
|
||||
}
|
||||
select(fields) {
|
||||
return new SQLiteSelectBuilder({ fields: fields ?? void 0, session: void 0, dialect: this.getDialect() });
|
||||
}
|
||||
selectDistinct(fields) {
|
||||
return new SQLiteSelectBuilder({
|
||||
fields: fields ?? void 0,
|
||||
session: void 0,
|
||||
dialect: this.getDialect(),
|
||||
distinct: true
|
||||
});
|
||||
}
|
||||
// Lazy load dialect to avoid circular dependency
|
||||
getDialect() {
|
||||
if (!this.dialect) {
|
||||
this.dialect = new SQLiteSyncDialect(this.dialectConfig);
|
||||
}
|
||||
return this.dialect;
|
||||
}
|
||||
}
|
||||
export {
|
||||
QueryBuilder
|
||||
};
|
||||
//# sourceMappingURL=query-builder.js.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/query-builder.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
177
node_modules/drizzle-orm/sqlite-core/query-builders/query.cjs
generated
vendored
Normal file
177
node_modules/drizzle-orm/sqlite-core/query-builders/query.cjs
generated
vendored
Normal file
@ -0,0 +1,177 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var query_exports = {};
|
||||
__export(query_exports, {
|
||||
RelationalQueryBuilder: () => RelationalQueryBuilder,
|
||||
SQLiteRelationalQuery: () => SQLiteRelationalQuery,
|
||||
SQLiteSyncRelationalQuery: () => SQLiteSyncRelationalQuery
|
||||
});
|
||||
module.exports = __toCommonJS(query_exports);
|
||||
var import_entity = require("../../entity.cjs");
|
||||
var import_query_promise = require("../../query-promise.cjs");
|
||||
var import_relations = require("../../relations.cjs");
|
||||
class RelationalQueryBuilder {
|
||||
constructor(mode, fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session) {
|
||||
this.mode = mode;
|
||||
this.fullSchema = fullSchema;
|
||||
this.schema = schema;
|
||||
this.tableNamesMap = tableNamesMap;
|
||||
this.table = table;
|
||||
this.tableConfig = tableConfig;
|
||||
this.dialect = dialect;
|
||||
this.session = session;
|
||||
}
|
||||
static [import_entity.entityKind] = "SQLiteAsyncRelationalQueryBuilder";
|
||||
findMany(config) {
|
||||
return this.mode === "sync" ? new SQLiteSyncRelationalQuery(
|
||||
this.fullSchema,
|
||||
this.schema,
|
||||
this.tableNamesMap,
|
||||
this.table,
|
||||
this.tableConfig,
|
||||
this.dialect,
|
||||
this.session,
|
||||
config ? config : {},
|
||||
"many"
|
||||
) : new SQLiteRelationalQuery(
|
||||
this.fullSchema,
|
||||
this.schema,
|
||||
this.tableNamesMap,
|
||||
this.table,
|
||||
this.tableConfig,
|
||||
this.dialect,
|
||||
this.session,
|
||||
config ? config : {},
|
||||
"many"
|
||||
);
|
||||
}
|
||||
findFirst(config) {
|
||||
return this.mode === "sync" ? new SQLiteSyncRelationalQuery(
|
||||
this.fullSchema,
|
||||
this.schema,
|
||||
this.tableNamesMap,
|
||||
this.table,
|
||||
this.tableConfig,
|
||||
this.dialect,
|
||||
this.session,
|
||||
config ? { ...config, limit: 1 } : { limit: 1 },
|
||||
"first"
|
||||
) : new SQLiteRelationalQuery(
|
||||
this.fullSchema,
|
||||
this.schema,
|
||||
this.tableNamesMap,
|
||||
this.table,
|
||||
this.tableConfig,
|
||||
this.dialect,
|
||||
this.session,
|
||||
config ? { ...config, limit: 1 } : { limit: 1 },
|
||||
"first"
|
||||
);
|
||||
}
|
||||
}
|
||||
class SQLiteRelationalQuery extends import_query_promise.QueryPromise {
|
||||
constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session, config, mode) {
|
||||
super();
|
||||
this.fullSchema = fullSchema;
|
||||
this.schema = schema;
|
||||
this.tableNamesMap = tableNamesMap;
|
||||
this.table = table;
|
||||
this.tableConfig = tableConfig;
|
||||
this.dialect = dialect;
|
||||
this.session = session;
|
||||
this.config = config;
|
||||
this.mode = mode;
|
||||
}
|
||||
static [import_entity.entityKind] = "SQLiteAsyncRelationalQuery";
|
||||
/** @internal */
|
||||
mode;
|
||||
/** @internal */
|
||||
getSQL() {
|
||||
return this.dialect.buildRelationalQuery({
|
||||
fullSchema: this.fullSchema,
|
||||
schema: this.schema,
|
||||
tableNamesMap: this.tableNamesMap,
|
||||
table: this.table,
|
||||
tableConfig: this.tableConfig,
|
||||
queryConfig: this.config,
|
||||
tableAlias: this.tableConfig.tsName
|
||||
}).sql;
|
||||
}
|
||||
/** @internal */
|
||||
_prepare(isOneTimeQuery = false) {
|
||||
const { query, builtQuery } = this._toSQL();
|
||||
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
||||
builtQuery,
|
||||
void 0,
|
||||
this.mode === "first" ? "get" : "all",
|
||||
true,
|
||||
(rawRows, mapColumnValue) => {
|
||||
const rows = rawRows.map(
|
||||
(row) => (0, import_relations.mapRelationalRow)(this.schema, this.tableConfig, row, query.selection, mapColumnValue)
|
||||
);
|
||||
if (this.mode === "first") {
|
||||
return rows[0];
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
);
|
||||
}
|
||||
prepare() {
|
||||
return this._prepare(false);
|
||||
}
|
||||
_toSQL() {
|
||||
const query = this.dialect.buildRelationalQuery({
|
||||
fullSchema: this.fullSchema,
|
||||
schema: this.schema,
|
||||
tableNamesMap: this.tableNamesMap,
|
||||
table: this.table,
|
||||
tableConfig: this.tableConfig,
|
||||
queryConfig: this.config,
|
||||
tableAlias: this.tableConfig.tsName
|
||||
});
|
||||
const builtQuery = this.dialect.sqlToQuery(query.sql);
|
||||
return { query, builtQuery };
|
||||
}
|
||||
toSQL() {
|
||||
return this._toSQL().builtQuery;
|
||||
}
|
||||
/** @internal */
|
||||
executeRaw() {
|
||||
if (this.mode === "first") {
|
||||
return this._prepare(false).get();
|
||||
}
|
||||
return this._prepare(false).all();
|
||||
}
|
||||
async execute() {
|
||||
return this.executeRaw();
|
||||
}
|
||||
}
|
||||
class SQLiteSyncRelationalQuery extends SQLiteRelationalQuery {
|
||||
static [import_entity.entityKind] = "SQLiteSyncRelationalQuery";
|
||||
sync() {
|
||||
return this.executeRaw();
|
||||
}
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
RelationalQueryBuilder,
|
||||
SQLiteRelationalQuery,
|
||||
SQLiteSyncRelationalQuery
|
||||
});
|
||||
//# sourceMappingURL=query.cjs.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/query.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/query.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
55
node_modules/drizzle-orm/sqlite-core/query-builders/query.d.cts
generated
vendored
Normal file
55
node_modules/drizzle-orm/sqlite-core/query-builders/query.d.cts
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
import { entityKind } from "../../entity.cjs";
|
||||
import { QueryPromise } from "../../query-promise.cjs";
|
||||
import { type BuildQueryResult, type DBQueryConfig, type TableRelationalConfig, type TablesRelationalConfig } from "../../relations.cjs";
|
||||
import type { RunnableQuery } from "../../runnable-query.cjs";
|
||||
import type { Query, SQLWrapper } from "../../sql/sql.cjs";
|
||||
import type { KnownKeysOnly } from "../../utils.cjs";
|
||||
import type { SQLiteDialect } from "../dialect.cjs";
|
||||
import type { PreparedQueryConfig, SQLitePreparedQuery, SQLiteSession } from "../session.cjs";
|
||||
import type { SQLiteTable } from "../table.cjs";
|
||||
export type SQLiteRelationalQueryKind<TMode extends 'sync' | 'async', TResult> = TMode extends 'async' ? SQLiteRelationalQuery<TMode, TResult> : SQLiteSyncRelationalQuery<TResult>;
|
||||
export declare class RelationalQueryBuilder<TMode extends 'sync' | 'async', TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig, TFields extends TableRelationalConfig> {
|
||||
protected mode: TMode;
|
||||
protected fullSchema: Record<string, unknown>;
|
||||
protected schema: TSchema;
|
||||
protected tableNamesMap: Record<string, string>;
|
||||
protected table: SQLiteTable;
|
||||
protected tableConfig: TableRelationalConfig;
|
||||
protected dialect: SQLiteDialect;
|
||||
protected session: SQLiteSession<'async', unknown, TFullSchema, TSchema>;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(mode: TMode, fullSchema: Record<string, unknown>, schema: TSchema, tableNamesMap: Record<string, string>, table: SQLiteTable, tableConfig: TableRelationalConfig, dialect: SQLiteDialect, session: SQLiteSession<'async', unknown, TFullSchema, TSchema>);
|
||||
findMany<TConfig extends DBQueryConfig<'many', true, TSchema, TFields>>(config?: KnownKeysOnly<TConfig, DBQueryConfig<'many', true, TSchema, TFields>>): SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig>[]>;
|
||||
findFirst<TSelection extends Omit<DBQueryConfig<'many', true, TSchema, TFields>, 'limit'>>(config?: KnownKeysOnly<TSelection, Omit<DBQueryConfig<'many', true, TSchema, TFields>, 'limit'>>): SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TSelection> | undefined>;
|
||||
}
|
||||
export declare class SQLiteRelationalQuery<TType extends 'sync' | 'async', TResult> extends QueryPromise<TResult> implements RunnableQuery<TResult, 'sqlite'>, SQLWrapper {
|
||||
private fullSchema;
|
||||
private schema;
|
||||
private tableNamesMap;
|
||||
private tableConfig;
|
||||
private dialect;
|
||||
private session;
|
||||
private config;
|
||||
static readonly [entityKind]: string;
|
||||
readonly _: {
|
||||
readonly dialect: 'sqlite';
|
||||
readonly type: TType;
|
||||
readonly result: TResult;
|
||||
};
|
||||
constructor(fullSchema: Record<string, unknown>, schema: TablesRelationalConfig, tableNamesMap: Record<string, string>,
|
||||
/** @internal */
|
||||
table: SQLiteTable, tableConfig: TableRelationalConfig, dialect: SQLiteDialect, session: SQLiteSession<'sync' | 'async', unknown, Record<string, unknown>, TablesRelationalConfig>, config: DBQueryConfig<'many', true> | true, mode: 'many' | 'first');
|
||||
prepare(): SQLitePreparedQuery<PreparedQueryConfig & {
|
||||
type: TType;
|
||||
all: TResult;
|
||||
get: TResult;
|
||||
execute: TResult;
|
||||
}>;
|
||||
private _toSQL;
|
||||
toSQL(): Query;
|
||||
execute(): Promise<TResult>;
|
||||
}
|
||||
export declare class SQLiteSyncRelationalQuery<TResult> extends SQLiteRelationalQuery<'sync', TResult> {
|
||||
static readonly [entityKind]: string;
|
||||
sync(): TResult;
|
||||
}
|
||||
55
node_modules/drizzle-orm/sqlite-core/query-builders/query.d.ts
generated
vendored
Normal file
55
node_modules/drizzle-orm/sqlite-core/query-builders/query.d.ts
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
import { entityKind } from "../../entity.js";
|
||||
import { QueryPromise } from "../../query-promise.js";
|
||||
import { type BuildQueryResult, type DBQueryConfig, type TableRelationalConfig, type TablesRelationalConfig } from "../../relations.js";
|
||||
import type { RunnableQuery } from "../../runnable-query.js";
|
||||
import type { Query, SQLWrapper } from "../../sql/sql.js";
|
||||
import type { KnownKeysOnly } from "../../utils.js";
|
||||
import type { SQLiteDialect } from "../dialect.js";
|
||||
import type { PreparedQueryConfig, SQLitePreparedQuery, SQLiteSession } from "../session.js";
|
||||
import type { SQLiteTable } from "../table.js";
|
||||
export type SQLiteRelationalQueryKind<TMode extends 'sync' | 'async', TResult> = TMode extends 'async' ? SQLiteRelationalQuery<TMode, TResult> : SQLiteSyncRelationalQuery<TResult>;
|
||||
export declare class RelationalQueryBuilder<TMode extends 'sync' | 'async', TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig, TFields extends TableRelationalConfig> {
|
||||
protected mode: TMode;
|
||||
protected fullSchema: Record<string, unknown>;
|
||||
protected schema: TSchema;
|
||||
protected tableNamesMap: Record<string, string>;
|
||||
protected table: SQLiteTable;
|
||||
protected tableConfig: TableRelationalConfig;
|
||||
protected dialect: SQLiteDialect;
|
||||
protected session: SQLiteSession<'async', unknown, TFullSchema, TSchema>;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(mode: TMode, fullSchema: Record<string, unknown>, schema: TSchema, tableNamesMap: Record<string, string>, table: SQLiteTable, tableConfig: TableRelationalConfig, dialect: SQLiteDialect, session: SQLiteSession<'async', unknown, TFullSchema, TSchema>);
|
||||
findMany<TConfig extends DBQueryConfig<'many', true, TSchema, TFields>>(config?: KnownKeysOnly<TConfig, DBQueryConfig<'many', true, TSchema, TFields>>): SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TConfig>[]>;
|
||||
findFirst<TSelection extends Omit<DBQueryConfig<'many', true, TSchema, TFields>, 'limit'>>(config?: KnownKeysOnly<TSelection, Omit<DBQueryConfig<'many', true, TSchema, TFields>, 'limit'>>): SQLiteRelationalQueryKind<TMode, BuildQueryResult<TSchema, TFields, TSelection> | undefined>;
|
||||
}
|
||||
export declare class SQLiteRelationalQuery<TType extends 'sync' | 'async', TResult> extends QueryPromise<TResult> implements RunnableQuery<TResult, 'sqlite'>, SQLWrapper {
|
||||
private fullSchema;
|
||||
private schema;
|
||||
private tableNamesMap;
|
||||
private tableConfig;
|
||||
private dialect;
|
||||
private session;
|
||||
private config;
|
||||
static readonly [entityKind]: string;
|
||||
readonly _: {
|
||||
readonly dialect: 'sqlite';
|
||||
readonly type: TType;
|
||||
readonly result: TResult;
|
||||
};
|
||||
constructor(fullSchema: Record<string, unknown>, schema: TablesRelationalConfig, tableNamesMap: Record<string, string>,
|
||||
/** @internal */
|
||||
table: SQLiteTable, tableConfig: TableRelationalConfig, dialect: SQLiteDialect, session: SQLiteSession<'sync' | 'async', unknown, Record<string, unknown>, TablesRelationalConfig>, config: DBQueryConfig<'many', true> | true, mode: 'many' | 'first');
|
||||
prepare(): SQLitePreparedQuery<PreparedQueryConfig & {
|
||||
type: TType;
|
||||
all: TResult;
|
||||
get: TResult;
|
||||
execute: TResult;
|
||||
}>;
|
||||
private _toSQL;
|
||||
toSQL(): Query;
|
||||
execute(): Promise<TResult>;
|
||||
}
|
||||
export declare class SQLiteSyncRelationalQuery<TResult> extends SQLiteRelationalQuery<'sync', TResult> {
|
||||
static readonly [entityKind]: string;
|
||||
sync(): TResult;
|
||||
}
|
||||
153
node_modules/drizzle-orm/sqlite-core/query-builders/query.js
generated
vendored
Normal file
153
node_modules/drizzle-orm/sqlite-core/query-builders/query.js
generated
vendored
Normal file
@ -0,0 +1,153 @@
|
||||
import { entityKind } from "../../entity.js";
|
||||
import { QueryPromise } from "../../query-promise.js";
|
||||
import {
|
||||
mapRelationalRow
|
||||
} from "../../relations.js";
|
||||
class RelationalQueryBuilder {
|
||||
constructor(mode, fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session) {
|
||||
this.mode = mode;
|
||||
this.fullSchema = fullSchema;
|
||||
this.schema = schema;
|
||||
this.tableNamesMap = tableNamesMap;
|
||||
this.table = table;
|
||||
this.tableConfig = tableConfig;
|
||||
this.dialect = dialect;
|
||||
this.session = session;
|
||||
}
|
||||
static [entityKind] = "SQLiteAsyncRelationalQueryBuilder";
|
||||
findMany(config) {
|
||||
return this.mode === "sync" ? new SQLiteSyncRelationalQuery(
|
||||
this.fullSchema,
|
||||
this.schema,
|
||||
this.tableNamesMap,
|
||||
this.table,
|
||||
this.tableConfig,
|
||||
this.dialect,
|
||||
this.session,
|
||||
config ? config : {},
|
||||
"many"
|
||||
) : new SQLiteRelationalQuery(
|
||||
this.fullSchema,
|
||||
this.schema,
|
||||
this.tableNamesMap,
|
||||
this.table,
|
||||
this.tableConfig,
|
||||
this.dialect,
|
||||
this.session,
|
||||
config ? config : {},
|
||||
"many"
|
||||
);
|
||||
}
|
||||
findFirst(config) {
|
||||
return this.mode === "sync" ? new SQLiteSyncRelationalQuery(
|
||||
this.fullSchema,
|
||||
this.schema,
|
||||
this.tableNamesMap,
|
||||
this.table,
|
||||
this.tableConfig,
|
||||
this.dialect,
|
||||
this.session,
|
||||
config ? { ...config, limit: 1 } : { limit: 1 },
|
||||
"first"
|
||||
) : new SQLiteRelationalQuery(
|
||||
this.fullSchema,
|
||||
this.schema,
|
||||
this.tableNamesMap,
|
||||
this.table,
|
||||
this.tableConfig,
|
||||
this.dialect,
|
||||
this.session,
|
||||
config ? { ...config, limit: 1 } : { limit: 1 },
|
||||
"first"
|
||||
);
|
||||
}
|
||||
}
|
||||
class SQLiteRelationalQuery extends QueryPromise {
|
||||
constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session, config, mode) {
|
||||
super();
|
||||
this.fullSchema = fullSchema;
|
||||
this.schema = schema;
|
||||
this.tableNamesMap = tableNamesMap;
|
||||
this.table = table;
|
||||
this.tableConfig = tableConfig;
|
||||
this.dialect = dialect;
|
||||
this.session = session;
|
||||
this.config = config;
|
||||
this.mode = mode;
|
||||
}
|
||||
static [entityKind] = "SQLiteAsyncRelationalQuery";
|
||||
/** @internal */
|
||||
mode;
|
||||
/** @internal */
|
||||
getSQL() {
|
||||
return this.dialect.buildRelationalQuery({
|
||||
fullSchema: this.fullSchema,
|
||||
schema: this.schema,
|
||||
tableNamesMap: this.tableNamesMap,
|
||||
table: this.table,
|
||||
tableConfig: this.tableConfig,
|
||||
queryConfig: this.config,
|
||||
tableAlias: this.tableConfig.tsName
|
||||
}).sql;
|
||||
}
|
||||
/** @internal */
|
||||
_prepare(isOneTimeQuery = false) {
|
||||
const { query, builtQuery } = this._toSQL();
|
||||
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
||||
builtQuery,
|
||||
void 0,
|
||||
this.mode === "first" ? "get" : "all",
|
||||
true,
|
||||
(rawRows, mapColumnValue) => {
|
||||
const rows = rawRows.map(
|
||||
(row) => mapRelationalRow(this.schema, this.tableConfig, row, query.selection, mapColumnValue)
|
||||
);
|
||||
if (this.mode === "first") {
|
||||
return rows[0];
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
);
|
||||
}
|
||||
prepare() {
|
||||
return this._prepare(false);
|
||||
}
|
||||
_toSQL() {
|
||||
const query = this.dialect.buildRelationalQuery({
|
||||
fullSchema: this.fullSchema,
|
||||
schema: this.schema,
|
||||
tableNamesMap: this.tableNamesMap,
|
||||
table: this.table,
|
||||
tableConfig: this.tableConfig,
|
||||
queryConfig: this.config,
|
||||
tableAlias: this.tableConfig.tsName
|
||||
});
|
||||
const builtQuery = this.dialect.sqlToQuery(query.sql);
|
||||
return { query, builtQuery };
|
||||
}
|
||||
toSQL() {
|
||||
return this._toSQL().builtQuery;
|
||||
}
|
||||
/** @internal */
|
||||
executeRaw() {
|
||||
if (this.mode === "first") {
|
||||
return this._prepare(false).get();
|
||||
}
|
||||
return this._prepare(false).all();
|
||||
}
|
||||
async execute() {
|
||||
return this.executeRaw();
|
||||
}
|
||||
}
|
||||
class SQLiteSyncRelationalQuery extends SQLiteRelationalQuery {
|
||||
static [entityKind] = "SQLiteSyncRelationalQuery";
|
||||
sync() {
|
||||
return this.executeRaw();
|
||||
}
|
||||
}
|
||||
export {
|
||||
RelationalQueryBuilder,
|
||||
SQLiteRelationalQuery,
|
||||
SQLiteSyncRelationalQuery
|
||||
};
|
||||
//# sourceMappingURL=query.js.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/query.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/query.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
56
node_modules/drizzle-orm/sqlite-core/query-builders/raw.cjs
generated
vendored
Normal file
56
node_modules/drizzle-orm/sqlite-core/query-builders/raw.cjs
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var raw_exports = {};
|
||||
__export(raw_exports, {
|
||||
SQLiteRaw: () => SQLiteRaw
|
||||
});
|
||||
module.exports = __toCommonJS(raw_exports);
|
||||
var import_entity = require("../../entity.cjs");
|
||||
var import_query_promise = require("../../query-promise.cjs");
|
||||
class SQLiteRaw extends import_query_promise.QueryPromise {
|
||||
constructor(execute, getSQL, action, dialect, mapBatchResult) {
|
||||
super();
|
||||
this.execute = execute;
|
||||
this.getSQL = getSQL;
|
||||
this.dialect = dialect;
|
||||
this.mapBatchResult = mapBatchResult;
|
||||
this.config = { action };
|
||||
}
|
||||
static [import_entity.entityKind] = "SQLiteRaw";
|
||||
/** @internal */
|
||||
config;
|
||||
getQuery() {
|
||||
return { ...this.dialect.sqlToQuery(this.getSQL()), method: this.config.action };
|
||||
}
|
||||
mapResult(result, isFromBatch) {
|
||||
return isFromBatch ? this.mapBatchResult(result) : result;
|
||||
}
|
||||
_prepare() {
|
||||
return this;
|
||||
}
|
||||
/** @internal */
|
||||
isResponseInArrayMode() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
SQLiteRaw
|
||||
});
|
||||
//# sourceMappingURL=raw.cjs.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/raw.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/raw.cjs.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/sqlite-core/query-builders/raw.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { PreparedQuery } from '~/session.ts';\nimport type { SQL, SQLWrapper } from '~/sql/sql.ts';\nimport type { SQLiteAsyncDialect } from '../dialect.ts';\n\ntype SQLiteRawAction = 'all' | 'get' | 'values' | 'run';\nexport interface SQLiteRawConfig {\n\taction: SQLiteRawAction;\n}\n\nexport interface SQLiteRaw<TResult> extends QueryPromise<TResult>, RunnableQuery<TResult, 'sqlite'>, SQLWrapper {}\n\nexport class SQLiteRaw<TResult> extends QueryPromise<TResult>\n\timplements RunnableQuery<TResult, 'sqlite'>, SQLWrapper, PreparedQuery\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteRaw';\n\n\tdeclare readonly _: {\n\t\treadonly dialect: 'sqlite';\n\t\treadonly result: TResult;\n\t};\n\n\t/** @internal */\n\tconfig: SQLiteRawConfig;\n\n\tconstructor(\n\t\tpublic execute: () => Promise<TResult>,\n\t\t/** @internal */\n\t\tpublic getSQL: () => SQL,\n\t\taction: SQLiteRawAction,\n\t\tprivate dialect: SQLiteAsyncDialect,\n\t\tprivate mapBatchResult: (result: unknown) => unknown,\n\t) {\n\t\tsuper();\n\t\tthis.config = { action };\n\t}\n\n\tgetQuery() {\n\t\treturn { ...this.dialect.sqlToQuery(this.getSQL()), method: this.config.action };\n\t}\n\n\tmapResult(result: unknown, isFromBatch?: boolean) {\n\t\treturn isFromBatch ? this.mapBatchResult(result) : result;\n\t}\n\n\t_prepare(): PreparedQuery {\n\t\treturn this;\n\t}\n\n\t/** @internal */\n\tisResponseInArrayMode(): boolean {\n\t\treturn false;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAC3B,2BAA6B;AAatB,MAAM,kBAA2B,kCAExC;AAAA,EAWC,YACQ,SAEA,QACP,QACQ,SACA,gBACP;AACD,UAAM;AAPC;AAEA;AAEC;AACA;AAGR,SAAK,SAAS,EAAE,OAAO;AAAA,EACxB;AAAA,EApBA,QAA0B,wBAAU,IAAY;AAAA;AAAA,EAQhD;AAAA,EAcA,WAAW;AACV,WAAO,EAAE,GAAG,KAAK,QAAQ,WAAW,KAAK,OAAO,CAAC,GAAG,QAAQ,KAAK,OAAO,OAAO;AAAA,EAChF;AAAA,EAEA,UAAU,QAAiB,aAAuB;AACjD,WAAO,cAAc,KAAK,eAAe,MAAM,IAAI;AAAA,EACpD;AAAA,EAEA,WAA0B;AACzB,WAAO;AAAA,EACR;AAAA;AAAA,EAGA,wBAAiC;AAChC,WAAO;AAAA,EACR;AACD;","names":[]}
|
||||
34
node_modules/drizzle-orm/sqlite-core/query-builders/raw.d.cts
generated
vendored
Normal file
34
node_modules/drizzle-orm/sqlite-core/query-builders/raw.d.cts
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
import { entityKind } from "../../entity.cjs";
|
||||
import { QueryPromise } from "../../query-promise.cjs";
|
||||
import type { RunnableQuery } from "../../runnable-query.cjs";
|
||||
import type { PreparedQuery } from "../../session.cjs";
|
||||
import type { SQL, SQLWrapper } from "../../sql/sql.cjs";
|
||||
import type { SQLiteAsyncDialect } from "../dialect.cjs";
|
||||
type SQLiteRawAction = 'all' | 'get' | 'values' | 'run';
|
||||
export interface SQLiteRawConfig {
|
||||
action: SQLiteRawAction;
|
||||
}
|
||||
export interface SQLiteRaw<TResult> extends QueryPromise<TResult>, RunnableQuery<TResult, 'sqlite'>, SQLWrapper {
|
||||
}
|
||||
export declare class SQLiteRaw<TResult> extends QueryPromise<TResult> implements RunnableQuery<TResult, 'sqlite'>, SQLWrapper, PreparedQuery {
|
||||
execute: () => Promise<TResult>;
|
||||
private dialect;
|
||||
private mapBatchResult;
|
||||
static readonly [entityKind]: string;
|
||||
readonly _: {
|
||||
readonly dialect: 'sqlite';
|
||||
readonly result: TResult;
|
||||
};
|
||||
constructor(execute: () => Promise<TResult>,
|
||||
/** @internal */
|
||||
getSQL: () => SQL, action: SQLiteRawAction, dialect: SQLiteAsyncDialect, mapBatchResult: (result: unknown) => unknown);
|
||||
getQuery(): {
|
||||
method: SQLiteRawAction;
|
||||
typings?: import("../../sql/sql.ts").QueryTypingsValue[];
|
||||
sql: string;
|
||||
params: unknown[];
|
||||
};
|
||||
mapResult(result: unknown, isFromBatch?: boolean): unknown;
|
||||
_prepare(): PreparedQuery;
|
||||
}
|
||||
export {};
|
||||
34
node_modules/drizzle-orm/sqlite-core/query-builders/raw.d.ts
generated
vendored
Normal file
34
node_modules/drizzle-orm/sqlite-core/query-builders/raw.d.ts
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
import { entityKind } from "../../entity.js";
|
||||
import { QueryPromise } from "../../query-promise.js";
|
||||
import type { RunnableQuery } from "../../runnable-query.js";
|
||||
import type { PreparedQuery } from "../../session.js";
|
||||
import type { SQL, SQLWrapper } from "../../sql/sql.js";
|
||||
import type { SQLiteAsyncDialect } from "../dialect.js";
|
||||
type SQLiteRawAction = 'all' | 'get' | 'values' | 'run';
|
||||
export interface SQLiteRawConfig {
|
||||
action: SQLiteRawAction;
|
||||
}
|
||||
export interface SQLiteRaw<TResult> extends QueryPromise<TResult>, RunnableQuery<TResult, 'sqlite'>, SQLWrapper {
|
||||
}
|
||||
export declare class SQLiteRaw<TResult> extends QueryPromise<TResult> implements RunnableQuery<TResult, 'sqlite'>, SQLWrapper, PreparedQuery {
|
||||
execute: () => Promise<TResult>;
|
||||
private dialect;
|
||||
private mapBatchResult;
|
||||
static readonly [entityKind]: string;
|
||||
readonly _: {
|
||||
readonly dialect: 'sqlite';
|
||||
readonly result: TResult;
|
||||
};
|
||||
constructor(execute: () => Promise<TResult>,
|
||||
/** @internal */
|
||||
getSQL: () => SQL, action: SQLiteRawAction, dialect: SQLiteAsyncDialect, mapBatchResult: (result: unknown) => unknown);
|
||||
getQuery(): {
|
||||
method: SQLiteRawAction;
|
||||
typings?: import("../../sql/sql.js").QueryTypingsValue[];
|
||||
sql: string;
|
||||
params: unknown[];
|
||||
};
|
||||
mapResult(result: unknown, isFromBatch?: boolean): unknown;
|
||||
_prepare(): PreparedQuery;
|
||||
}
|
||||
export {};
|
||||
32
node_modules/drizzle-orm/sqlite-core/query-builders/raw.js
generated
vendored
Normal file
32
node_modules/drizzle-orm/sqlite-core/query-builders/raw.js
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
import { entityKind } from "../../entity.js";
|
||||
import { QueryPromise } from "../../query-promise.js";
|
||||
class SQLiteRaw extends QueryPromise {
|
||||
constructor(execute, getSQL, action, dialect, mapBatchResult) {
|
||||
super();
|
||||
this.execute = execute;
|
||||
this.getSQL = getSQL;
|
||||
this.dialect = dialect;
|
||||
this.mapBatchResult = mapBatchResult;
|
||||
this.config = { action };
|
||||
}
|
||||
static [entityKind] = "SQLiteRaw";
|
||||
/** @internal */
|
||||
config;
|
||||
getQuery() {
|
||||
return { ...this.dialect.sqlToQuery(this.getSQL()), method: this.config.action };
|
||||
}
|
||||
mapResult(result, isFromBatch) {
|
||||
return isFromBatch ? this.mapBatchResult(result) : result;
|
||||
}
|
||||
_prepare() {
|
||||
return this;
|
||||
}
|
||||
/** @internal */
|
||||
isResponseInArrayMode() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export {
|
||||
SQLiteRaw
|
||||
};
|
||||
//# sourceMappingURL=raw.js.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/raw.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/raw.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/sqlite-core/query-builders/raw.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { PreparedQuery } from '~/session.ts';\nimport type { SQL, SQLWrapper } from '~/sql/sql.ts';\nimport type { SQLiteAsyncDialect } from '../dialect.ts';\n\ntype SQLiteRawAction = 'all' | 'get' | 'values' | 'run';\nexport interface SQLiteRawConfig {\n\taction: SQLiteRawAction;\n}\n\nexport interface SQLiteRaw<TResult> extends QueryPromise<TResult>, RunnableQuery<TResult, 'sqlite'>, SQLWrapper {}\n\nexport class SQLiteRaw<TResult> extends QueryPromise<TResult>\n\timplements RunnableQuery<TResult, 'sqlite'>, SQLWrapper, PreparedQuery\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteRaw';\n\n\tdeclare readonly _: {\n\t\treadonly dialect: 'sqlite';\n\t\treadonly result: TResult;\n\t};\n\n\t/** @internal */\n\tconfig: SQLiteRawConfig;\n\n\tconstructor(\n\t\tpublic execute: () => Promise<TResult>,\n\t\t/** @internal */\n\t\tpublic getSQL: () => SQL,\n\t\taction: SQLiteRawAction,\n\t\tprivate dialect: SQLiteAsyncDialect,\n\t\tprivate mapBatchResult: (result: unknown) => unknown,\n\t) {\n\t\tsuper();\n\t\tthis.config = { action };\n\t}\n\n\tgetQuery() {\n\t\treturn { ...this.dialect.sqlToQuery(this.getSQL()), method: this.config.action };\n\t}\n\n\tmapResult(result: unknown, isFromBatch?: boolean) {\n\t\treturn isFromBatch ? this.mapBatchResult(result) : result;\n\t}\n\n\t_prepare(): PreparedQuery {\n\t\treturn this;\n\t}\n\n\t/** @internal */\n\tisResponseInArrayMode(): boolean {\n\t\treturn false;\n\t}\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAatB,MAAM,kBAA2B,aAExC;AAAA,EAWC,YACQ,SAEA,QACP,QACQ,SACA,gBACP;AACD,UAAM;AAPC;AAEA;AAEC;AACA;AAGR,SAAK,SAAS,EAAE,OAAO;AAAA,EACxB;AAAA,EApBA,QAA0B,UAAU,IAAY;AAAA;AAAA,EAQhD;AAAA,EAcA,WAAW;AACV,WAAO,EAAE,GAAG,KAAK,QAAQ,WAAW,KAAK,OAAO,CAAC,GAAG,QAAQ,KAAK,OAAO,OAAO;AAAA,EAChF;AAAA,EAEA,UAAU,QAAiB,aAAuB;AACjD,WAAO,cAAc,KAAK,eAAe,MAAM,IAAI;AAAA,EACpD;AAAA,EAEA,WAA0B;AACzB,WAAO;AAAA,EACR;AAAA;AAAA,EAGA,wBAAiC;AAChC,WAAO;AAAA,EACR;AACD;","names":[]}
|
||||
661
node_modules/drizzle-orm/sqlite-core/query-builders/select.cjs
generated
vendored
Normal file
661
node_modules/drizzle-orm/sqlite-core/query-builders/select.cjs
generated
vendored
Normal file
@ -0,0 +1,661 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except2, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except2)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var select_exports = {};
|
||||
__export(select_exports, {
|
||||
SQLiteSelectBase: () => SQLiteSelectBase,
|
||||
SQLiteSelectBuilder: () => SQLiteSelectBuilder,
|
||||
SQLiteSelectQueryBuilderBase: () => SQLiteSelectQueryBuilderBase,
|
||||
except: () => except,
|
||||
intersect: () => intersect,
|
||||
union: () => union,
|
||||
unionAll: () => unionAll
|
||||
});
|
||||
module.exports = __toCommonJS(select_exports);
|
||||
var import_entity = require("../../entity.cjs");
|
||||
var import_query_builder = require("../../query-builders/query-builder.cjs");
|
||||
var import_query_promise = require("../../query-promise.cjs");
|
||||
var import_selection_proxy = require("../../selection-proxy.cjs");
|
||||
var import_sql = require("../../sql/sql.cjs");
|
||||
var import_subquery = require("../../subquery.cjs");
|
||||
var import_table = require("../../table.cjs");
|
||||
var import_utils = require("../../utils.cjs");
|
||||
var import_view_common = require("../../view-common.cjs");
|
||||
var import_view_base = require("../view-base.cjs");
|
||||
class SQLiteSelectBuilder {
|
||||
static [import_entity.entityKind] = "SQLiteSelectBuilder";
|
||||
fields;
|
||||
session;
|
||||
dialect;
|
||||
withList;
|
||||
distinct;
|
||||
constructor(config) {
|
||||
this.fields = config.fields;
|
||||
this.session = config.session;
|
||||
this.dialect = config.dialect;
|
||||
this.withList = config.withList;
|
||||
this.distinct = config.distinct;
|
||||
}
|
||||
from(source) {
|
||||
const isPartialSelect = !!this.fields;
|
||||
let fields;
|
||||
if (this.fields) {
|
||||
fields = this.fields;
|
||||
} else if ((0, import_entity.is)(source, import_subquery.Subquery)) {
|
||||
fields = Object.fromEntries(
|
||||
Object.keys(source._.selectedFields).map((key) => [key, source[key]])
|
||||
);
|
||||
} else if ((0, import_entity.is)(source, import_view_base.SQLiteViewBase)) {
|
||||
fields = source[import_view_common.ViewBaseConfig].selectedFields;
|
||||
} else if ((0, import_entity.is)(source, import_sql.SQL)) {
|
||||
fields = {};
|
||||
} else {
|
||||
fields = (0, import_utils.getTableColumns)(source);
|
||||
}
|
||||
return new SQLiteSelectBase({
|
||||
table: source,
|
||||
fields,
|
||||
isPartialSelect,
|
||||
session: this.session,
|
||||
dialect: this.dialect,
|
||||
withList: this.withList,
|
||||
distinct: this.distinct
|
||||
});
|
||||
}
|
||||
}
|
||||
class SQLiteSelectQueryBuilderBase extends import_query_builder.TypedQueryBuilder {
|
||||
static [import_entity.entityKind] = "SQLiteSelectQueryBuilder";
|
||||
_;
|
||||
/** @internal */
|
||||
config;
|
||||
joinsNotNullableMap;
|
||||
tableName;
|
||||
isPartialSelect;
|
||||
session;
|
||||
dialect;
|
||||
constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }) {
|
||||
super();
|
||||
this.config = {
|
||||
withList,
|
||||
table,
|
||||
fields: { ...fields },
|
||||
distinct,
|
||||
setOperators: []
|
||||
};
|
||||
this.isPartialSelect = isPartialSelect;
|
||||
this.session = session;
|
||||
this.dialect = dialect;
|
||||
this._ = {
|
||||
selectedFields: fields
|
||||
};
|
||||
this.tableName = (0, import_utils.getTableLikeName)(table);
|
||||
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
||||
}
|
||||
createJoin(joinType) {
|
||||
return (table, on) => {
|
||||
const baseTableName = this.tableName;
|
||||
const tableName = (0, import_utils.getTableLikeName)(table);
|
||||
if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) {
|
||||
throw new Error(`Alias "${tableName}" is already used in this query`);
|
||||
}
|
||||
if (!this.isPartialSelect) {
|
||||
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") {
|
||||
this.config.fields = {
|
||||
[baseTableName]: this.config.fields
|
||||
};
|
||||
}
|
||||
if (typeof tableName === "string" && !(0, import_entity.is)(table, import_sql.SQL)) {
|
||||
const selection = (0, import_entity.is)(table, import_subquery.Subquery) ? table._.selectedFields : (0, import_entity.is)(table, import_sql.View) ? table[import_view_common.ViewBaseConfig].selectedFields : table[import_table.Table.Symbol.Columns];
|
||||
this.config.fields[tableName] = selection;
|
||||
}
|
||||
}
|
||||
if (typeof on === "function") {
|
||||
on = on(
|
||||
new Proxy(
|
||||
this.config.fields,
|
||||
new import_selection_proxy.SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
}
|
||||
if (!this.config.joins) {
|
||||
this.config.joins = [];
|
||||
}
|
||||
this.config.joins.push({ on, table, joinType, alias: tableName });
|
||||
if (typeof tableName === "string") {
|
||||
switch (joinType) {
|
||||
case "left": {
|
||||
this.joinsNotNullableMap[tableName] = false;
|
||||
break;
|
||||
}
|
||||
case "right": {
|
||||
this.joinsNotNullableMap = Object.fromEntries(
|
||||
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
||||
);
|
||||
this.joinsNotNullableMap[tableName] = true;
|
||||
break;
|
||||
}
|
||||
case "inner": {
|
||||
this.joinsNotNullableMap[tableName] = true;
|
||||
break;
|
||||
}
|
||||
case "full": {
|
||||
this.joinsNotNullableMap = Object.fromEntries(
|
||||
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
||||
);
|
||||
this.joinsNotNullableMap[tableName] = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Executes a `left join` operation by adding another table to the current query.
|
||||
*
|
||||
* Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#left-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User; pets: Pet | null }[] = await db.select()
|
||||
* .from(users)
|
||||
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
leftJoin = this.createJoin("left");
|
||||
/**
|
||||
* Executes a `right join` operation by adding another table to the current query.
|
||||
*
|
||||
* Calling this method associates each row of the joined table with the corresponding row from the main table, if a match is found. If no matching row exists, it sets all columns of the main table to null.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#right-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User | null; pets: Pet }[] = await db.select()
|
||||
* .from(users)
|
||||
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number | null; petId: number }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
rightJoin = this.createJoin("right");
|
||||
/**
|
||||
* Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
|
||||
*
|
||||
* Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User; pets: Pet }[] = await db.select()
|
||||
* .from(users)
|
||||
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number; petId: number }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
innerJoin = this.createJoin("inner");
|
||||
/**
|
||||
* Executes a `full join` operation by combining rows from two tables into a new table.
|
||||
*
|
||||
* Calling this method retrieves all rows from both main and joined tables, merging rows with matching values and filling in `null` for non-matching columns.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#full-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User | null; pets: Pet | null }[] = await db.select()
|
||||
* .from(users)
|
||||
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number | null; petId: number | null }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
fullJoin = this.createJoin("full");
|
||||
createSetOperator(type, isAll) {
|
||||
return (rightSelection) => {
|
||||
const rightSelect = typeof rightSelection === "function" ? rightSelection(getSQLiteSetOperators()) : rightSelection;
|
||||
if (!(0, import_utils.haveSameKeys)(this.getSelectedFields(), rightSelect.getSelectedFields())) {
|
||||
throw new Error(
|
||||
"Set operator error (union / intersect / except): selected fields are not the same or are in a different order"
|
||||
);
|
||||
}
|
||||
this.config.setOperators.push({ type, isAll, rightSelect });
|
||||
return this;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Adds `union` set operator to the query.
|
||||
*
|
||||
* Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all unique names from customers and users tables
|
||||
* await db.select({ name: users.name })
|
||||
* .from(users)
|
||||
* .union(
|
||||
* db.select({ name: customers.name }).from(customers)
|
||||
* );
|
||||
* // or
|
||||
* import { union } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await union(
|
||||
* db.select({ name: users.name }).from(users),
|
||||
* db.select({ name: customers.name }).from(customers)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
union = this.createSetOperator("union", false);
|
||||
/**
|
||||
* Adds `union all` set operator to the query.
|
||||
*
|
||||
* Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all transaction ids from both online and in-store sales
|
||||
* await db.select({ transaction: onlineSales.transactionId })
|
||||
* .from(onlineSales)
|
||||
* .unionAll(
|
||||
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
||||
* );
|
||||
* // or
|
||||
* import { unionAll } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await unionAll(
|
||||
* db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
|
||||
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
unionAll = this.createSetOperator("union", true);
|
||||
/**
|
||||
* Adds `intersect` set operator to the query.
|
||||
*
|
||||
* Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select course names that are offered in both departments A and B
|
||||
* await db.select({ courseName: depA.courseName })
|
||||
* .from(depA)
|
||||
* .intersect(
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* // or
|
||||
* import { intersect } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await intersect(
|
||||
* db.select({ courseName: depA.courseName }).from(depA),
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
intersect = this.createSetOperator("intersect", false);
|
||||
/**
|
||||
* Adds `except` set operator to the query.
|
||||
*
|
||||
* Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all courses offered in department A but not in department B
|
||||
* await db.select({ courseName: depA.courseName })
|
||||
* .from(depA)
|
||||
* .except(
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* // or
|
||||
* import { except } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await except(
|
||||
* db.select({ courseName: depA.courseName }).from(depA),
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
except = this.createSetOperator("except", false);
|
||||
/** @internal */
|
||||
addSetOperators(setOperators) {
|
||||
this.config.setOperators.push(...setOperators);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds a `where` clause to the query.
|
||||
*
|
||||
* Calling this method will select only those rows that fulfill a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#filtering}
|
||||
*
|
||||
* @param where the `where` clause.
|
||||
*
|
||||
* @example
|
||||
* You can use conditional operators and `sql function` to filter the rows to be selected.
|
||||
*
|
||||
* ```ts
|
||||
* // Select all cars with green color
|
||||
* await db.select().from(cars).where(eq(cars.color, 'green'));
|
||||
* // or
|
||||
* await db.select().from(cars).where(sql`${cars.color} = 'green'`)
|
||||
* ```
|
||||
*
|
||||
* You can logically combine conditional operators with `and()` and `or()` operators:
|
||||
*
|
||||
* ```ts
|
||||
* // Select all BMW cars with a green color
|
||||
* await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
||||
*
|
||||
* // Select all cars with the green or blue color
|
||||
* await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
||||
* ```
|
||||
*/
|
||||
where(where) {
|
||||
if (typeof where === "function") {
|
||||
where = where(
|
||||
new Proxy(
|
||||
this.config.fields,
|
||||
new import_selection_proxy.SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
}
|
||||
this.config.where = where;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds a `having` clause to the query.
|
||||
*
|
||||
* Calling this method will select only those rows that fulfill a specified condition. It is typically used with aggregate functions to filter the aggregated data based on a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
|
||||
*
|
||||
* @param having the `having` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all brands with more than one car
|
||||
* await db.select({
|
||||
* brand: cars.brand,
|
||||
* count: sql<number>`cast(count(${cars.id}) as int)`,
|
||||
* })
|
||||
* .from(cars)
|
||||
* .groupBy(cars.brand)
|
||||
* .having(({ count }) => gt(count, 1));
|
||||
* ```
|
||||
*/
|
||||
having(having) {
|
||||
if (typeof having === "function") {
|
||||
having = having(
|
||||
new Proxy(
|
||||
this.config.fields,
|
||||
new import_selection_proxy.SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
}
|
||||
this.config.having = having;
|
||||
return this;
|
||||
}
|
||||
groupBy(...columns) {
|
||||
if (typeof columns[0] === "function") {
|
||||
const groupBy = columns[0](
|
||||
new Proxy(
|
||||
this.config.fields,
|
||||
new import_selection_proxy.SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
this.config.groupBy = Array.isArray(groupBy) ? groupBy : [groupBy];
|
||||
} else {
|
||||
this.config.groupBy = columns;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
orderBy(...columns) {
|
||||
if (typeof columns[0] === "function") {
|
||||
const orderBy = columns[0](
|
||||
new Proxy(
|
||||
this.config.fields,
|
||||
new import_selection_proxy.SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
||||
if (this.config.setOperators.length > 0) {
|
||||
this.config.setOperators.at(-1).orderBy = orderByArray;
|
||||
} else {
|
||||
this.config.orderBy = orderByArray;
|
||||
}
|
||||
} else {
|
||||
const orderByArray = columns;
|
||||
if (this.config.setOperators.length > 0) {
|
||||
this.config.setOperators.at(-1).orderBy = orderByArray;
|
||||
} else {
|
||||
this.config.orderBy = orderByArray;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds a `limit` clause to the query.
|
||||
*
|
||||
* Calling this method will set the maximum number of rows that will be returned by this query.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
||||
*
|
||||
* @param limit the `limit` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Get the first 10 people from this query.
|
||||
* await db.select().from(people).limit(10);
|
||||
* ```
|
||||
*/
|
||||
limit(limit) {
|
||||
if (this.config.setOperators.length > 0) {
|
||||
this.config.setOperators.at(-1).limit = limit;
|
||||
} else {
|
||||
this.config.limit = limit;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds an `offset` clause to the query.
|
||||
*
|
||||
* Calling this method will skip a number of rows when returning results from this query.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
||||
*
|
||||
* @param offset the `offset` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Get the 10th-20th people from this query.
|
||||
* await db.select().from(people).offset(10).limit(10);
|
||||
* ```
|
||||
*/
|
||||
offset(offset) {
|
||||
if (this.config.setOperators.length > 0) {
|
||||
this.config.setOperators.at(-1).offset = offset;
|
||||
} else {
|
||||
this.config.offset = offset;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/** @internal */
|
||||
getSQL() {
|
||||
return this.dialect.buildSelectQuery(this.config);
|
||||
}
|
||||
toSQL() {
|
||||
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
||||
return rest;
|
||||
}
|
||||
as(alias) {
|
||||
return new Proxy(
|
||||
new import_subquery.Subquery(this.getSQL(), this.config.fields, alias),
|
||||
new import_selection_proxy.SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
||||
);
|
||||
}
|
||||
/** @internal */
|
||||
getSelectedFields() {
|
||||
return new Proxy(
|
||||
this.config.fields,
|
||||
new import_selection_proxy.SelectionProxyHandler({ alias: this.tableName, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
||||
);
|
||||
}
|
||||
$dynamic() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class SQLiteSelectBase extends SQLiteSelectQueryBuilderBase {
|
||||
static [import_entity.entityKind] = "SQLiteSelect";
|
||||
/** @internal */
|
||||
_prepare(isOneTimeQuery = true) {
|
||||
if (!this.session) {
|
||||
throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
|
||||
}
|
||||
const fieldsList = (0, import_utils.orderSelectedFields)(this.config.fields);
|
||||
const query = this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
||||
this.dialect.sqlToQuery(this.getSQL()),
|
||||
fieldsList,
|
||||
"all",
|
||||
true
|
||||
);
|
||||
query.joinsNotNullableMap = this.joinsNotNullableMap;
|
||||
return query;
|
||||
}
|
||||
prepare() {
|
||||
return this._prepare(false);
|
||||
}
|
||||
run = (placeholderValues) => {
|
||||
return this._prepare().run(placeholderValues);
|
||||
};
|
||||
all = (placeholderValues) => {
|
||||
return this._prepare().all(placeholderValues);
|
||||
};
|
||||
get = (placeholderValues) => {
|
||||
return this._prepare().get(placeholderValues);
|
||||
};
|
||||
values = (placeholderValues) => {
|
||||
return this._prepare().values(placeholderValues);
|
||||
};
|
||||
async execute() {
|
||||
return this.all();
|
||||
}
|
||||
}
|
||||
(0, import_utils.applyMixins)(SQLiteSelectBase, [import_query_promise.QueryPromise]);
|
||||
function createSetOperator(type, isAll) {
|
||||
return (leftSelect, rightSelect, ...restSelects) => {
|
||||
const setOperators = [rightSelect, ...restSelects].map((select) => ({
|
||||
type,
|
||||
isAll,
|
||||
rightSelect: select
|
||||
}));
|
||||
for (const setOperator of setOperators) {
|
||||
if (!(0, import_utils.haveSameKeys)(leftSelect.getSelectedFields(), setOperator.rightSelect.getSelectedFields())) {
|
||||
throw new Error(
|
||||
"Set operator error (union / intersect / except): selected fields are not the same or are in a different order"
|
||||
);
|
||||
}
|
||||
}
|
||||
return leftSelect.addSetOperators(setOperators);
|
||||
};
|
||||
}
|
||||
const getSQLiteSetOperators = () => ({
|
||||
union,
|
||||
unionAll,
|
||||
intersect,
|
||||
except
|
||||
});
|
||||
const union = createSetOperator("union", false);
|
||||
const unionAll = createSetOperator("union", true);
|
||||
const intersect = createSetOperator("intersect", false);
|
||||
const except = createSetOperator("except", false);
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
SQLiteSelectBase,
|
||||
SQLiteSelectBuilder,
|
||||
SQLiteSelectQueryBuilderBase,
|
||||
except,
|
||||
intersect,
|
||||
union,
|
||||
unionAll
|
||||
});
|
||||
//# sourceMappingURL=select.cjs.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/select.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/select.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
533
node_modules/drizzle-orm/sqlite-core/query-builders/select.d.cts
generated
vendored
Normal file
533
node_modules/drizzle-orm/sqlite-core/query-builders/select.d.cts
generated
vendored
Normal file
@ -0,0 +1,533 @@
|
||||
import { entityKind } from "../../entity.cjs";
|
||||
import { TypedQueryBuilder } from "../../query-builders/query-builder.cjs";
|
||||
import type { BuildSubquerySelection, GetSelectTableName, GetSelectTableSelection, JoinNullability, SelectMode, SelectResult } from "../../query-builders/select.types.cjs";
|
||||
import { QueryPromise } from "../../query-promise.cjs";
|
||||
import type { RunnableQuery } from "../../runnable-query.cjs";
|
||||
import { SQL } from "../../sql/sql.cjs";
|
||||
import type { ColumnsSelection, Placeholder, Query, SQLWrapper } from "../../sql/sql.cjs";
|
||||
import type { SQLiteColumn } from "../columns/index.cjs";
|
||||
import type { SQLiteDialect } from "../dialect.cjs";
|
||||
import type { SQLiteSession } from "../session.cjs";
|
||||
import type { SubqueryWithSelection } from "../subquery.cjs";
|
||||
import type { SQLiteTable } from "../table.cjs";
|
||||
import { Subquery } from "../../subquery.cjs";
|
||||
import { type ValueOrArray } from "../../utils.cjs";
|
||||
import { SQLiteViewBase } from "../view-base.cjs";
|
||||
import type { CreateSQLiteSelectFromBuilderMode, GetSQLiteSetOperators, SelectedFields, SetOperatorRightSelect, SQLiteCreateSetOperatorFn, SQLiteSelectConfig, SQLiteSelectDynamic, SQLiteSelectExecute, SQLiteSelectHKT, SQLiteSelectHKTBase, SQLiteSelectJoinFn, SQLiteSelectPrepare, SQLiteSelectWithout, SQLiteSetOperatorExcludedMethods, SQLiteSetOperatorWithResult } from "./select.types.cjs";
|
||||
export declare class SQLiteSelectBuilder<TSelection extends SelectedFields | undefined, TResultType extends 'sync' | 'async', TRunResult, TBuilderMode extends 'db' | 'qb' = 'db'> {
|
||||
static readonly [entityKind]: string;
|
||||
private fields;
|
||||
private session;
|
||||
private dialect;
|
||||
private withList;
|
||||
private distinct;
|
||||
constructor(config: {
|
||||
fields: TSelection;
|
||||
session: SQLiteSession<any, any, any, any> | undefined;
|
||||
dialect: SQLiteDialect;
|
||||
withList?: Subquery[];
|
||||
distinct?: boolean;
|
||||
});
|
||||
from<TFrom extends SQLiteTable | Subquery | SQLiteViewBase | SQL>(source: TFrom): CreateSQLiteSelectFromBuilderMode<TBuilderMode, GetSelectTableName<TFrom>, TResultType, TRunResult, TSelection extends undefined ? GetSelectTableSelection<TFrom> : TSelection, TSelection extends undefined ? 'single' : 'partial'>;
|
||||
}
|
||||
export declare abstract class SQLiteSelectQueryBuilderBase<THKT extends SQLiteSelectHKTBase, TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection extends ColumnsSelection, TSelectMode extends SelectMode, TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>> extends TypedQueryBuilder<TSelectedFields, TResult> {
|
||||
static readonly [entityKind]: string;
|
||||
readonly _: {
|
||||
readonly dialect: 'sqlite';
|
||||
readonly hkt: THKT;
|
||||
readonly tableName: TTableName;
|
||||
readonly resultType: TResultType;
|
||||
readonly runResult: TRunResult;
|
||||
readonly selection: TSelection;
|
||||
readonly selectMode: TSelectMode;
|
||||
readonly nullabilityMap: TNullabilityMap;
|
||||
readonly dynamic: TDynamic;
|
||||
readonly excludedMethods: TExcludedMethods;
|
||||
readonly result: TResult;
|
||||
readonly selectedFields: TSelectedFields;
|
||||
};
|
||||
protected joinsNotNullableMap: Record<string, boolean>;
|
||||
private tableName;
|
||||
private isPartialSelect;
|
||||
protected session: SQLiteSession<any, any, any, any> | undefined;
|
||||
protected dialect: SQLiteDialect;
|
||||
constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }: {
|
||||
table: SQLiteSelectConfig['table'];
|
||||
fields: SQLiteSelectConfig['fields'];
|
||||
isPartialSelect: boolean;
|
||||
session: SQLiteSession<any, any, any, any> | undefined;
|
||||
dialect: SQLiteDialect;
|
||||
withList: Subquery[] | undefined;
|
||||
distinct: boolean | undefined;
|
||||
});
|
||||
private createJoin;
|
||||
/**
|
||||
* Executes a `left join` operation by adding another table to the current query.
|
||||
*
|
||||
* Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#left-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User; pets: Pet | null }[] = await db.select()
|
||||
* .from(users)
|
||||
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
leftJoin: SQLiteSelectJoinFn<this, TDynamic, "left">;
|
||||
/**
|
||||
* Executes a `right join` operation by adding another table to the current query.
|
||||
*
|
||||
* Calling this method associates each row of the joined table with the corresponding row from the main table, if a match is found. If no matching row exists, it sets all columns of the main table to null.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#right-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User | null; pets: Pet }[] = await db.select()
|
||||
* .from(users)
|
||||
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number | null; petId: number }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
rightJoin: SQLiteSelectJoinFn<this, TDynamic, "right">;
|
||||
/**
|
||||
* Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
|
||||
*
|
||||
* Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User; pets: Pet }[] = await db.select()
|
||||
* .from(users)
|
||||
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number; petId: number }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
innerJoin: SQLiteSelectJoinFn<this, TDynamic, "inner">;
|
||||
/**
|
||||
* Executes a `full join` operation by combining rows from two tables into a new table.
|
||||
*
|
||||
* Calling this method retrieves all rows from both main and joined tables, merging rows with matching values and filling in `null` for non-matching columns.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#full-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User | null; pets: Pet | null }[] = await db.select()
|
||||
* .from(users)
|
||||
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number | null; petId: number | null }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
fullJoin: SQLiteSelectJoinFn<this, TDynamic, "full">;
|
||||
private createSetOperator;
|
||||
/**
|
||||
* Adds `union` set operator to the query.
|
||||
*
|
||||
* Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all unique names from customers and users tables
|
||||
* await db.select({ name: users.name })
|
||||
* .from(users)
|
||||
* .union(
|
||||
* db.select({ name: customers.name }).from(customers)
|
||||
* );
|
||||
* // or
|
||||
* import { union } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await union(
|
||||
* db.select({ name: users.name }).from(users),
|
||||
* db.select({ name: customers.name }).from(customers)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
union: <TValue extends SQLiteSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetSQLiteSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => SQLiteSelectWithout<this, TDynamic, SQLiteSetOperatorExcludedMethods, true>;
|
||||
/**
|
||||
* Adds `union all` set operator to the query.
|
||||
*
|
||||
* Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all transaction ids from both online and in-store sales
|
||||
* await db.select({ transaction: onlineSales.transactionId })
|
||||
* .from(onlineSales)
|
||||
* .unionAll(
|
||||
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
||||
* );
|
||||
* // or
|
||||
* import { unionAll } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await unionAll(
|
||||
* db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
|
||||
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
unionAll: <TValue extends SQLiteSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetSQLiteSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => SQLiteSelectWithout<this, TDynamic, SQLiteSetOperatorExcludedMethods, true>;
|
||||
/**
|
||||
* Adds `intersect` set operator to the query.
|
||||
*
|
||||
* Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select course names that are offered in both departments A and B
|
||||
* await db.select({ courseName: depA.courseName })
|
||||
* .from(depA)
|
||||
* .intersect(
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* // or
|
||||
* import { intersect } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await intersect(
|
||||
* db.select({ courseName: depA.courseName }).from(depA),
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
intersect: <TValue extends SQLiteSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetSQLiteSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => SQLiteSelectWithout<this, TDynamic, SQLiteSetOperatorExcludedMethods, true>;
|
||||
/**
|
||||
* Adds `except` set operator to the query.
|
||||
*
|
||||
* Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all courses offered in department A but not in department B
|
||||
* await db.select({ courseName: depA.courseName })
|
||||
* .from(depA)
|
||||
* .except(
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* // or
|
||||
* import { except } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await except(
|
||||
* db.select({ courseName: depA.courseName }).from(depA),
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
except: <TValue extends SQLiteSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetSQLiteSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => SQLiteSelectWithout<this, TDynamic, SQLiteSetOperatorExcludedMethods, true>;
|
||||
/**
|
||||
* Adds a `where` clause to the query.
|
||||
*
|
||||
* Calling this method will select only those rows that fulfill a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#filtering}
|
||||
*
|
||||
* @param where the `where` clause.
|
||||
*
|
||||
* @example
|
||||
* You can use conditional operators and `sql function` to filter the rows to be selected.
|
||||
*
|
||||
* ```ts
|
||||
* // Select all cars with green color
|
||||
* await db.select().from(cars).where(eq(cars.color, 'green'));
|
||||
* // or
|
||||
* await db.select().from(cars).where(sql`${cars.color} = 'green'`)
|
||||
* ```
|
||||
*
|
||||
* You can logically combine conditional operators with `and()` and `or()` operators:
|
||||
*
|
||||
* ```ts
|
||||
* // Select all BMW cars with a green color
|
||||
* await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
||||
*
|
||||
* // Select all cars with the green or blue color
|
||||
* await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
||||
* ```
|
||||
*/
|
||||
where(where: ((aliases: TSelection) => SQL | undefined) | SQL | undefined): SQLiteSelectWithout<this, TDynamic, 'where'>;
|
||||
/**
|
||||
* Adds a `having` clause to the query.
|
||||
*
|
||||
* Calling this method will select only those rows that fulfill a specified condition. It is typically used with aggregate functions to filter the aggregated data based on a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
|
||||
*
|
||||
* @param having the `having` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all brands with more than one car
|
||||
* await db.select({
|
||||
* brand: cars.brand,
|
||||
* count: sql<number>`cast(count(${cars.id}) as int)`,
|
||||
* })
|
||||
* .from(cars)
|
||||
* .groupBy(cars.brand)
|
||||
* .having(({ count }) => gt(count, 1));
|
||||
* ```
|
||||
*/
|
||||
having(having: ((aliases: this['_']['selection']) => SQL | undefined) | SQL | undefined): SQLiteSelectWithout<this, TDynamic, 'having'>;
|
||||
/**
|
||||
* Adds a `group by` clause to the query.
|
||||
*
|
||||
* Calling this method will group rows that have the same values into summary rows, often used for aggregation purposes.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Group and count people by their last names
|
||||
* await db.select({
|
||||
* lastName: people.lastName,
|
||||
* count: sql<number>`cast(count(*) as int)`
|
||||
* })
|
||||
* .from(people)
|
||||
* .groupBy(people.lastName);
|
||||
* ```
|
||||
*/
|
||||
groupBy(builder: (aliases: this['_']['selection']) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>): SQLiteSelectWithout<this, TDynamic, 'groupBy'>;
|
||||
groupBy(...columns: (SQLiteColumn | SQL)[]): SQLiteSelectWithout<this, TDynamic, 'groupBy'>;
|
||||
/**
|
||||
* Adds an `order by` clause to the query.
|
||||
*
|
||||
* Calling this method will sort the result-set in ascending or descending order. By default, the sort order is ascending.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#order-by}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```
|
||||
* // Select cars ordered by year
|
||||
* await db.select().from(cars).orderBy(cars.year);
|
||||
* ```
|
||||
*
|
||||
* You can specify whether results are in ascending or descending order with the `asc()` and `desc()` operators.
|
||||
*
|
||||
* ```ts
|
||||
* // Select cars ordered by year in descending order
|
||||
* await db.select().from(cars).orderBy(desc(cars.year));
|
||||
*
|
||||
* // Select cars ordered by year and price
|
||||
* await db.select().from(cars).orderBy(asc(cars.year), desc(cars.price));
|
||||
* ```
|
||||
*/
|
||||
orderBy(builder: (aliases: this['_']['selection']) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>): SQLiteSelectWithout<this, TDynamic, 'orderBy'>;
|
||||
orderBy(...columns: (SQLiteColumn | SQL)[]): SQLiteSelectWithout<this, TDynamic, 'orderBy'>;
|
||||
/**
|
||||
* Adds a `limit` clause to the query.
|
||||
*
|
||||
* Calling this method will set the maximum number of rows that will be returned by this query.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
||||
*
|
||||
* @param limit the `limit` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Get the first 10 people from this query.
|
||||
* await db.select().from(people).limit(10);
|
||||
* ```
|
||||
*/
|
||||
limit(limit: number | Placeholder): SQLiteSelectWithout<this, TDynamic, 'limit'>;
|
||||
/**
|
||||
* Adds an `offset` clause to the query.
|
||||
*
|
||||
* Calling this method will skip a number of rows when returning results from this query.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
||||
*
|
||||
* @param offset the `offset` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Get the 10th-20th people from this query.
|
||||
* await db.select().from(people).offset(10).limit(10);
|
||||
* ```
|
||||
*/
|
||||
offset(offset: number | Placeholder): SQLiteSelectWithout<this, TDynamic, 'offset'>;
|
||||
toSQL(): Query;
|
||||
as<TAlias extends string>(alias: TAlias): SubqueryWithSelection<this['_']['selectedFields'], TAlias>;
|
||||
$dynamic(): SQLiteSelectDynamic<this>;
|
||||
}
|
||||
export interface SQLiteSelectBase<TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection extends ColumnsSelection, TSelectMode extends SelectMode = 'single', TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>> extends SQLiteSelectQueryBuilderBase<SQLiteSelectHKT, TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields>, QueryPromise<TResult> {
|
||||
}
|
||||
export declare class SQLiteSelectBase<TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection, TSelectMode extends SelectMode = 'single', TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>> extends SQLiteSelectQueryBuilderBase<SQLiteSelectHKT, TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields> implements RunnableQuery<TResult, 'sqlite'>, SQLWrapper {
|
||||
static readonly [entityKind]: string;
|
||||
prepare(): SQLiteSelectPrepare<this>;
|
||||
run: ReturnType<this['prepare']>['run'];
|
||||
all: ReturnType<this['prepare']>['all'];
|
||||
get: ReturnType<this['prepare']>['get'];
|
||||
values: ReturnType<this['prepare']>['values'];
|
||||
execute(): Promise<SQLiteSelectExecute<this>>;
|
||||
}
|
||||
/**
|
||||
* Adds `union` set operator to the query.
|
||||
*
|
||||
* Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all unique names from customers and users tables
|
||||
* import { union } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await union(
|
||||
* db.select({ name: users.name }).from(users),
|
||||
* db.select({ name: customers.name }).from(customers)
|
||||
* );
|
||||
* // or
|
||||
* await db.select({ name: users.name })
|
||||
* .from(users)
|
||||
* .union(
|
||||
* db.select({ name: customers.name }).from(customers)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export declare const union: SQLiteCreateSetOperatorFn;
|
||||
/**
|
||||
* Adds `union all` set operator to the query.
|
||||
*
|
||||
* Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all transaction ids from both online and in-store sales
|
||||
* import { unionAll } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await unionAll(
|
||||
* db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
|
||||
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
||||
* );
|
||||
* // or
|
||||
* await db.select({ transaction: onlineSales.transactionId })
|
||||
* .from(onlineSales)
|
||||
* .unionAll(
|
||||
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export declare const unionAll: SQLiteCreateSetOperatorFn;
|
||||
/**
|
||||
* Adds `intersect` set operator to the query.
|
||||
*
|
||||
* Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select course names that are offered in both departments A and B
|
||||
* import { intersect } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await intersect(
|
||||
* db.select({ courseName: depA.courseName }).from(depA),
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* // or
|
||||
* await db.select({ courseName: depA.courseName })
|
||||
* .from(depA)
|
||||
* .intersect(
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export declare const intersect: SQLiteCreateSetOperatorFn;
|
||||
/**
|
||||
* Adds `except` set operator to the query.
|
||||
*
|
||||
* Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all courses offered in department A but not in department B
|
||||
* import { except } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await except(
|
||||
* db.select({ courseName: depA.courseName }).from(depA),
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* // or
|
||||
* await db.select({ courseName: depA.courseName })
|
||||
* .from(depA)
|
||||
* .except(
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export declare const except: SQLiteCreateSetOperatorFn;
|
||||
533
node_modules/drizzle-orm/sqlite-core/query-builders/select.d.ts
generated
vendored
Normal file
533
node_modules/drizzle-orm/sqlite-core/query-builders/select.d.ts
generated
vendored
Normal file
@ -0,0 +1,533 @@
|
||||
import { entityKind } from "../../entity.js";
|
||||
import { TypedQueryBuilder } from "../../query-builders/query-builder.js";
|
||||
import type { BuildSubquerySelection, GetSelectTableName, GetSelectTableSelection, JoinNullability, SelectMode, SelectResult } from "../../query-builders/select.types.js";
|
||||
import { QueryPromise } from "../../query-promise.js";
|
||||
import type { RunnableQuery } from "../../runnable-query.js";
|
||||
import { SQL } from "../../sql/sql.js";
|
||||
import type { ColumnsSelection, Placeholder, Query, SQLWrapper } from "../../sql/sql.js";
|
||||
import type { SQLiteColumn } from "../columns/index.js";
|
||||
import type { SQLiteDialect } from "../dialect.js";
|
||||
import type { SQLiteSession } from "../session.js";
|
||||
import type { SubqueryWithSelection } from "../subquery.js";
|
||||
import type { SQLiteTable } from "../table.js";
|
||||
import { Subquery } from "../../subquery.js";
|
||||
import { type ValueOrArray } from "../../utils.js";
|
||||
import { SQLiteViewBase } from "../view-base.js";
|
||||
import type { CreateSQLiteSelectFromBuilderMode, GetSQLiteSetOperators, SelectedFields, SetOperatorRightSelect, SQLiteCreateSetOperatorFn, SQLiteSelectConfig, SQLiteSelectDynamic, SQLiteSelectExecute, SQLiteSelectHKT, SQLiteSelectHKTBase, SQLiteSelectJoinFn, SQLiteSelectPrepare, SQLiteSelectWithout, SQLiteSetOperatorExcludedMethods, SQLiteSetOperatorWithResult } from "./select.types.js";
|
||||
export declare class SQLiteSelectBuilder<TSelection extends SelectedFields | undefined, TResultType extends 'sync' | 'async', TRunResult, TBuilderMode extends 'db' | 'qb' = 'db'> {
|
||||
static readonly [entityKind]: string;
|
||||
private fields;
|
||||
private session;
|
||||
private dialect;
|
||||
private withList;
|
||||
private distinct;
|
||||
constructor(config: {
|
||||
fields: TSelection;
|
||||
session: SQLiteSession<any, any, any, any> | undefined;
|
||||
dialect: SQLiteDialect;
|
||||
withList?: Subquery[];
|
||||
distinct?: boolean;
|
||||
});
|
||||
from<TFrom extends SQLiteTable | Subquery | SQLiteViewBase | SQL>(source: TFrom): CreateSQLiteSelectFromBuilderMode<TBuilderMode, GetSelectTableName<TFrom>, TResultType, TRunResult, TSelection extends undefined ? GetSelectTableSelection<TFrom> : TSelection, TSelection extends undefined ? 'single' : 'partial'>;
|
||||
}
|
||||
export declare abstract class SQLiteSelectQueryBuilderBase<THKT extends SQLiteSelectHKTBase, TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection extends ColumnsSelection, TSelectMode extends SelectMode, TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>> extends TypedQueryBuilder<TSelectedFields, TResult> {
|
||||
static readonly [entityKind]: string;
|
||||
readonly _: {
|
||||
readonly dialect: 'sqlite';
|
||||
readonly hkt: THKT;
|
||||
readonly tableName: TTableName;
|
||||
readonly resultType: TResultType;
|
||||
readonly runResult: TRunResult;
|
||||
readonly selection: TSelection;
|
||||
readonly selectMode: TSelectMode;
|
||||
readonly nullabilityMap: TNullabilityMap;
|
||||
readonly dynamic: TDynamic;
|
||||
readonly excludedMethods: TExcludedMethods;
|
||||
readonly result: TResult;
|
||||
readonly selectedFields: TSelectedFields;
|
||||
};
|
||||
protected joinsNotNullableMap: Record<string, boolean>;
|
||||
private tableName;
|
||||
private isPartialSelect;
|
||||
protected session: SQLiteSession<any, any, any, any> | undefined;
|
||||
protected dialect: SQLiteDialect;
|
||||
constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }: {
|
||||
table: SQLiteSelectConfig['table'];
|
||||
fields: SQLiteSelectConfig['fields'];
|
||||
isPartialSelect: boolean;
|
||||
session: SQLiteSession<any, any, any, any> | undefined;
|
||||
dialect: SQLiteDialect;
|
||||
withList: Subquery[] | undefined;
|
||||
distinct: boolean | undefined;
|
||||
});
|
||||
private createJoin;
|
||||
/**
|
||||
* Executes a `left join` operation by adding another table to the current query.
|
||||
*
|
||||
* Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#left-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User; pets: Pet | null }[] = await db.select()
|
||||
* .from(users)
|
||||
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
leftJoin: SQLiteSelectJoinFn<this, TDynamic, "left">;
|
||||
/**
|
||||
* Executes a `right join` operation by adding another table to the current query.
|
||||
*
|
||||
* Calling this method associates each row of the joined table with the corresponding row from the main table, if a match is found. If no matching row exists, it sets all columns of the main table to null.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#right-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User | null; pets: Pet }[] = await db.select()
|
||||
* .from(users)
|
||||
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number | null; petId: number }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
rightJoin: SQLiteSelectJoinFn<this, TDynamic, "right">;
|
||||
/**
|
||||
* Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
|
||||
*
|
||||
* Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User; pets: Pet }[] = await db.select()
|
||||
* .from(users)
|
||||
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number; petId: number }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
innerJoin: SQLiteSelectJoinFn<this, TDynamic, "inner">;
|
||||
/**
|
||||
* Executes a `full join` operation by combining rows from two tables into a new table.
|
||||
*
|
||||
* Calling this method retrieves all rows from both main and joined tables, merging rows with matching values and filling in `null` for non-matching columns.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#full-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User | null; pets: Pet | null }[] = await db.select()
|
||||
* .from(users)
|
||||
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number | null; petId: number | null }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
fullJoin: SQLiteSelectJoinFn<this, TDynamic, "full">;
|
||||
private createSetOperator;
|
||||
/**
|
||||
* Adds `union` set operator to the query.
|
||||
*
|
||||
* Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all unique names from customers and users tables
|
||||
* await db.select({ name: users.name })
|
||||
* .from(users)
|
||||
* .union(
|
||||
* db.select({ name: customers.name }).from(customers)
|
||||
* );
|
||||
* // or
|
||||
* import { union } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await union(
|
||||
* db.select({ name: users.name }).from(users),
|
||||
* db.select({ name: customers.name }).from(customers)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
union: <TValue extends SQLiteSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetSQLiteSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => SQLiteSelectWithout<this, TDynamic, SQLiteSetOperatorExcludedMethods, true>;
|
||||
/**
|
||||
* Adds `union all` set operator to the query.
|
||||
*
|
||||
* Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all transaction ids from both online and in-store sales
|
||||
* await db.select({ transaction: onlineSales.transactionId })
|
||||
* .from(onlineSales)
|
||||
* .unionAll(
|
||||
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
||||
* );
|
||||
* // or
|
||||
* import { unionAll } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await unionAll(
|
||||
* db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
|
||||
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
unionAll: <TValue extends SQLiteSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetSQLiteSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => SQLiteSelectWithout<this, TDynamic, SQLiteSetOperatorExcludedMethods, true>;
|
||||
/**
|
||||
* Adds `intersect` set operator to the query.
|
||||
*
|
||||
* Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select course names that are offered in both departments A and B
|
||||
* await db.select({ courseName: depA.courseName })
|
||||
* .from(depA)
|
||||
* .intersect(
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* // or
|
||||
* import { intersect } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await intersect(
|
||||
* db.select({ courseName: depA.courseName }).from(depA),
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
intersect: <TValue extends SQLiteSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetSQLiteSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => SQLiteSelectWithout<this, TDynamic, SQLiteSetOperatorExcludedMethods, true>;
|
||||
/**
|
||||
* Adds `except` set operator to the query.
|
||||
*
|
||||
* Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all courses offered in department A but not in department B
|
||||
* await db.select({ courseName: depA.courseName })
|
||||
* .from(depA)
|
||||
* .except(
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* // or
|
||||
* import { except } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await except(
|
||||
* db.select({ courseName: depA.courseName }).from(depA),
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
except: <TValue extends SQLiteSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetSQLiteSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => SQLiteSelectWithout<this, TDynamic, SQLiteSetOperatorExcludedMethods, true>;
|
||||
/**
|
||||
* Adds a `where` clause to the query.
|
||||
*
|
||||
* Calling this method will select only those rows that fulfill a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#filtering}
|
||||
*
|
||||
* @param where the `where` clause.
|
||||
*
|
||||
* @example
|
||||
* You can use conditional operators and `sql function` to filter the rows to be selected.
|
||||
*
|
||||
* ```ts
|
||||
* // Select all cars with green color
|
||||
* await db.select().from(cars).where(eq(cars.color, 'green'));
|
||||
* // or
|
||||
* await db.select().from(cars).where(sql`${cars.color} = 'green'`)
|
||||
* ```
|
||||
*
|
||||
* You can logically combine conditional operators with `and()` and `or()` operators:
|
||||
*
|
||||
* ```ts
|
||||
* // Select all BMW cars with a green color
|
||||
* await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
||||
*
|
||||
* // Select all cars with the green or blue color
|
||||
* await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
||||
* ```
|
||||
*/
|
||||
where(where: ((aliases: TSelection) => SQL | undefined) | SQL | undefined): SQLiteSelectWithout<this, TDynamic, 'where'>;
|
||||
/**
|
||||
* Adds a `having` clause to the query.
|
||||
*
|
||||
* Calling this method will select only those rows that fulfill a specified condition. It is typically used with aggregate functions to filter the aggregated data based on a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
|
||||
*
|
||||
* @param having the `having` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all brands with more than one car
|
||||
* await db.select({
|
||||
* brand: cars.brand,
|
||||
* count: sql<number>`cast(count(${cars.id}) as int)`,
|
||||
* })
|
||||
* .from(cars)
|
||||
* .groupBy(cars.brand)
|
||||
* .having(({ count }) => gt(count, 1));
|
||||
* ```
|
||||
*/
|
||||
having(having: ((aliases: this['_']['selection']) => SQL | undefined) | SQL | undefined): SQLiteSelectWithout<this, TDynamic, 'having'>;
|
||||
/**
|
||||
* Adds a `group by` clause to the query.
|
||||
*
|
||||
* Calling this method will group rows that have the same values into summary rows, often used for aggregation purposes.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Group and count people by their last names
|
||||
* await db.select({
|
||||
* lastName: people.lastName,
|
||||
* count: sql<number>`cast(count(*) as int)`
|
||||
* })
|
||||
* .from(people)
|
||||
* .groupBy(people.lastName);
|
||||
* ```
|
||||
*/
|
||||
groupBy(builder: (aliases: this['_']['selection']) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>): SQLiteSelectWithout<this, TDynamic, 'groupBy'>;
|
||||
groupBy(...columns: (SQLiteColumn | SQL)[]): SQLiteSelectWithout<this, TDynamic, 'groupBy'>;
|
||||
/**
|
||||
* Adds an `order by` clause to the query.
|
||||
*
|
||||
* Calling this method will sort the result-set in ascending or descending order. By default, the sort order is ascending.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#order-by}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```
|
||||
* // Select cars ordered by year
|
||||
* await db.select().from(cars).orderBy(cars.year);
|
||||
* ```
|
||||
*
|
||||
* You can specify whether results are in ascending or descending order with the `asc()` and `desc()` operators.
|
||||
*
|
||||
* ```ts
|
||||
* // Select cars ordered by year in descending order
|
||||
* await db.select().from(cars).orderBy(desc(cars.year));
|
||||
*
|
||||
* // Select cars ordered by year and price
|
||||
* await db.select().from(cars).orderBy(asc(cars.year), desc(cars.price));
|
||||
* ```
|
||||
*/
|
||||
orderBy(builder: (aliases: this['_']['selection']) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>): SQLiteSelectWithout<this, TDynamic, 'orderBy'>;
|
||||
orderBy(...columns: (SQLiteColumn | SQL)[]): SQLiteSelectWithout<this, TDynamic, 'orderBy'>;
|
||||
/**
|
||||
* Adds a `limit` clause to the query.
|
||||
*
|
||||
* Calling this method will set the maximum number of rows that will be returned by this query.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
||||
*
|
||||
* @param limit the `limit` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Get the first 10 people from this query.
|
||||
* await db.select().from(people).limit(10);
|
||||
* ```
|
||||
*/
|
||||
limit(limit: number | Placeholder): SQLiteSelectWithout<this, TDynamic, 'limit'>;
|
||||
/**
|
||||
* Adds an `offset` clause to the query.
|
||||
*
|
||||
* Calling this method will skip a number of rows when returning results from this query.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
||||
*
|
||||
* @param offset the `offset` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Get the 10th-20th people from this query.
|
||||
* await db.select().from(people).offset(10).limit(10);
|
||||
* ```
|
||||
*/
|
||||
offset(offset: number | Placeholder): SQLiteSelectWithout<this, TDynamic, 'offset'>;
|
||||
toSQL(): Query;
|
||||
as<TAlias extends string>(alias: TAlias): SubqueryWithSelection<this['_']['selectedFields'], TAlias>;
|
||||
$dynamic(): SQLiteSelectDynamic<this>;
|
||||
}
|
||||
export interface SQLiteSelectBase<TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection extends ColumnsSelection, TSelectMode extends SelectMode = 'single', TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>> extends SQLiteSelectQueryBuilderBase<SQLiteSelectHKT, TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields>, QueryPromise<TResult> {
|
||||
}
|
||||
export declare class SQLiteSelectBase<TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection, TSelectMode extends SelectMode = 'single', TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>> extends SQLiteSelectQueryBuilderBase<SQLiteSelectHKT, TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields> implements RunnableQuery<TResult, 'sqlite'>, SQLWrapper {
|
||||
static readonly [entityKind]: string;
|
||||
prepare(): SQLiteSelectPrepare<this>;
|
||||
run: ReturnType<this['prepare']>['run'];
|
||||
all: ReturnType<this['prepare']>['all'];
|
||||
get: ReturnType<this['prepare']>['get'];
|
||||
values: ReturnType<this['prepare']>['values'];
|
||||
execute(): Promise<SQLiteSelectExecute<this>>;
|
||||
}
|
||||
/**
|
||||
* Adds `union` set operator to the query.
|
||||
*
|
||||
* Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all unique names from customers and users tables
|
||||
* import { union } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await union(
|
||||
* db.select({ name: users.name }).from(users),
|
||||
* db.select({ name: customers.name }).from(customers)
|
||||
* );
|
||||
* // or
|
||||
* await db.select({ name: users.name })
|
||||
* .from(users)
|
||||
* .union(
|
||||
* db.select({ name: customers.name }).from(customers)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export declare const union: SQLiteCreateSetOperatorFn;
|
||||
/**
|
||||
* Adds `union all` set operator to the query.
|
||||
*
|
||||
* Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all transaction ids from both online and in-store sales
|
||||
* import { unionAll } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await unionAll(
|
||||
* db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
|
||||
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
||||
* );
|
||||
* // or
|
||||
* await db.select({ transaction: onlineSales.transactionId })
|
||||
* .from(onlineSales)
|
||||
* .unionAll(
|
||||
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export declare const unionAll: SQLiteCreateSetOperatorFn;
|
||||
/**
|
||||
* Adds `intersect` set operator to the query.
|
||||
*
|
||||
* Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select course names that are offered in both departments A and B
|
||||
* import { intersect } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await intersect(
|
||||
* db.select({ courseName: depA.courseName }).from(depA),
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* // or
|
||||
* await db.select({ courseName: depA.courseName })
|
||||
* .from(depA)
|
||||
* .intersect(
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export declare const intersect: SQLiteCreateSetOperatorFn;
|
||||
/**
|
||||
* Adds `except` set operator to the query.
|
||||
*
|
||||
* Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all courses offered in department A but not in department B
|
||||
* import { except } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await except(
|
||||
* db.select({ courseName: depA.courseName }).from(depA),
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* // or
|
||||
* await db.select({ courseName: depA.courseName })
|
||||
* .from(depA)
|
||||
* .except(
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export declare const except: SQLiteCreateSetOperatorFn;
|
||||
637
node_modules/drizzle-orm/sqlite-core/query-builders/select.js
generated
vendored
Normal file
637
node_modules/drizzle-orm/sqlite-core/query-builders/select.js
generated
vendored
Normal file
@ -0,0 +1,637 @@
|
||||
import { entityKind, is } from "../../entity.js";
|
||||
import { TypedQueryBuilder } from "../../query-builders/query-builder.js";
|
||||
import { QueryPromise } from "../../query-promise.js";
|
||||
import { SelectionProxyHandler } from "../../selection-proxy.js";
|
||||
import { SQL, View } from "../../sql/sql.js";
|
||||
import { Subquery } from "../../subquery.js";
|
||||
import { Table } from "../../table.js";
|
||||
import {
|
||||
applyMixins,
|
||||
getTableColumns,
|
||||
getTableLikeName,
|
||||
haveSameKeys,
|
||||
orderSelectedFields
|
||||
} from "../../utils.js";
|
||||
import { ViewBaseConfig } from "../../view-common.js";
|
||||
import { SQLiteViewBase } from "../view-base.js";
|
||||
class SQLiteSelectBuilder {
|
||||
static [entityKind] = "SQLiteSelectBuilder";
|
||||
fields;
|
||||
session;
|
||||
dialect;
|
||||
withList;
|
||||
distinct;
|
||||
constructor(config) {
|
||||
this.fields = config.fields;
|
||||
this.session = config.session;
|
||||
this.dialect = config.dialect;
|
||||
this.withList = config.withList;
|
||||
this.distinct = config.distinct;
|
||||
}
|
||||
from(source) {
|
||||
const isPartialSelect = !!this.fields;
|
||||
let fields;
|
||||
if (this.fields) {
|
||||
fields = this.fields;
|
||||
} else if (is(source, Subquery)) {
|
||||
fields = Object.fromEntries(
|
||||
Object.keys(source._.selectedFields).map((key) => [key, source[key]])
|
||||
);
|
||||
} else if (is(source, SQLiteViewBase)) {
|
||||
fields = source[ViewBaseConfig].selectedFields;
|
||||
} else if (is(source, SQL)) {
|
||||
fields = {};
|
||||
} else {
|
||||
fields = getTableColumns(source);
|
||||
}
|
||||
return new SQLiteSelectBase({
|
||||
table: source,
|
||||
fields,
|
||||
isPartialSelect,
|
||||
session: this.session,
|
||||
dialect: this.dialect,
|
||||
withList: this.withList,
|
||||
distinct: this.distinct
|
||||
});
|
||||
}
|
||||
}
|
||||
class SQLiteSelectQueryBuilderBase extends TypedQueryBuilder {
|
||||
static [entityKind] = "SQLiteSelectQueryBuilder";
|
||||
_;
|
||||
/** @internal */
|
||||
config;
|
||||
joinsNotNullableMap;
|
||||
tableName;
|
||||
isPartialSelect;
|
||||
session;
|
||||
dialect;
|
||||
constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }) {
|
||||
super();
|
||||
this.config = {
|
||||
withList,
|
||||
table,
|
||||
fields: { ...fields },
|
||||
distinct,
|
||||
setOperators: []
|
||||
};
|
||||
this.isPartialSelect = isPartialSelect;
|
||||
this.session = session;
|
||||
this.dialect = dialect;
|
||||
this._ = {
|
||||
selectedFields: fields
|
||||
};
|
||||
this.tableName = getTableLikeName(table);
|
||||
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
||||
}
|
||||
createJoin(joinType) {
|
||||
return (table, on) => {
|
||||
const baseTableName = this.tableName;
|
||||
const tableName = getTableLikeName(table);
|
||||
if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) {
|
||||
throw new Error(`Alias "${tableName}" is already used in this query`);
|
||||
}
|
||||
if (!this.isPartialSelect) {
|
||||
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") {
|
||||
this.config.fields = {
|
||||
[baseTableName]: this.config.fields
|
||||
};
|
||||
}
|
||||
if (typeof tableName === "string" && !is(table, SQL)) {
|
||||
const selection = is(table, Subquery) ? table._.selectedFields : is(table, View) ? table[ViewBaseConfig].selectedFields : table[Table.Symbol.Columns];
|
||||
this.config.fields[tableName] = selection;
|
||||
}
|
||||
}
|
||||
if (typeof on === "function") {
|
||||
on = on(
|
||||
new Proxy(
|
||||
this.config.fields,
|
||||
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
}
|
||||
if (!this.config.joins) {
|
||||
this.config.joins = [];
|
||||
}
|
||||
this.config.joins.push({ on, table, joinType, alias: tableName });
|
||||
if (typeof tableName === "string") {
|
||||
switch (joinType) {
|
||||
case "left": {
|
||||
this.joinsNotNullableMap[tableName] = false;
|
||||
break;
|
||||
}
|
||||
case "right": {
|
||||
this.joinsNotNullableMap = Object.fromEntries(
|
||||
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
||||
);
|
||||
this.joinsNotNullableMap[tableName] = true;
|
||||
break;
|
||||
}
|
||||
case "inner": {
|
||||
this.joinsNotNullableMap[tableName] = true;
|
||||
break;
|
||||
}
|
||||
case "full": {
|
||||
this.joinsNotNullableMap = Object.fromEntries(
|
||||
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
||||
);
|
||||
this.joinsNotNullableMap[tableName] = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Executes a `left join` operation by adding another table to the current query.
|
||||
*
|
||||
* Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#left-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User; pets: Pet | null }[] = await db.select()
|
||||
* .from(users)
|
||||
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
leftJoin = this.createJoin("left");
|
||||
/**
|
||||
* Executes a `right join` operation by adding another table to the current query.
|
||||
*
|
||||
* Calling this method associates each row of the joined table with the corresponding row from the main table, if a match is found. If no matching row exists, it sets all columns of the main table to null.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#right-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User | null; pets: Pet }[] = await db.select()
|
||||
* .from(users)
|
||||
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number | null; petId: number }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
rightJoin = this.createJoin("right");
|
||||
/**
|
||||
* Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
|
||||
*
|
||||
* Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User; pets: Pet }[] = await db.select()
|
||||
* .from(users)
|
||||
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number; petId: number }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
innerJoin = this.createJoin("inner");
|
||||
/**
|
||||
* Executes a `full join` operation by combining rows from two tables into a new table.
|
||||
*
|
||||
* Calling this method retrieves all rows from both main and joined tables, merging rows with matching values and filling in `null` for non-matching columns.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/joins#full-join}
|
||||
*
|
||||
* @param table the table to join.
|
||||
* @param on the `on` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all users and their pets
|
||||
* const usersWithPets: { user: User | null; pets: Pet | null }[] = await db.select()
|
||||
* .from(users)
|
||||
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
||||
*
|
||||
* // Select userId and petId
|
||||
* const usersIdsAndPetIds: { userId: number | null; petId: number | null }[] = await db.select({
|
||||
* userId: users.id,
|
||||
* petId: pets.id,
|
||||
* })
|
||||
* .from(users)
|
||||
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
||||
* ```
|
||||
*/
|
||||
fullJoin = this.createJoin("full");
|
||||
createSetOperator(type, isAll) {
|
||||
return (rightSelection) => {
|
||||
const rightSelect = typeof rightSelection === "function" ? rightSelection(getSQLiteSetOperators()) : rightSelection;
|
||||
if (!haveSameKeys(this.getSelectedFields(), rightSelect.getSelectedFields())) {
|
||||
throw new Error(
|
||||
"Set operator error (union / intersect / except): selected fields are not the same or are in a different order"
|
||||
);
|
||||
}
|
||||
this.config.setOperators.push({ type, isAll, rightSelect });
|
||||
return this;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Adds `union` set operator to the query.
|
||||
*
|
||||
* Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all unique names from customers and users tables
|
||||
* await db.select({ name: users.name })
|
||||
* .from(users)
|
||||
* .union(
|
||||
* db.select({ name: customers.name }).from(customers)
|
||||
* );
|
||||
* // or
|
||||
* import { union } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await union(
|
||||
* db.select({ name: users.name }).from(users),
|
||||
* db.select({ name: customers.name }).from(customers)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
union = this.createSetOperator("union", false);
|
||||
/**
|
||||
* Adds `union all` set operator to the query.
|
||||
*
|
||||
* Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all transaction ids from both online and in-store sales
|
||||
* await db.select({ transaction: onlineSales.transactionId })
|
||||
* .from(onlineSales)
|
||||
* .unionAll(
|
||||
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
||||
* );
|
||||
* // or
|
||||
* import { unionAll } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await unionAll(
|
||||
* db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
|
||||
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
unionAll = this.createSetOperator("union", true);
|
||||
/**
|
||||
* Adds `intersect` set operator to the query.
|
||||
*
|
||||
* Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select course names that are offered in both departments A and B
|
||||
* await db.select({ courseName: depA.courseName })
|
||||
* .from(depA)
|
||||
* .intersect(
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* // or
|
||||
* import { intersect } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await intersect(
|
||||
* db.select({ courseName: depA.courseName }).from(depA),
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
intersect = this.createSetOperator("intersect", false);
|
||||
/**
|
||||
* Adds `except` set operator to the query.
|
||||
*
|
||||
* Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all courses offered in department A but not in department B
|
||||
* await db.select({ courseName: depA.courseName })
|
||||
* .from(depA)
|
||||
* .except(
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* // or
|
||||
* import { except } from 'drizzle-orm/sqlite-core'
|
||||
*
|
||||
* await except(
|
||||
* db.select({ courseName: depA.courseName }).from(depA),
|
||||
* db.select({ courseName: depB.courseName }).from(depB)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
except = this.createSetOperator("except", false);
|
||||
/** @internal */
|
||||
addSetOperators(setOperators) {
|
||||
this.config.setOperators.push(...setOperators);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds a `where` clause to the query.
|
||||
*
|
||||
* Calling this method will select only those rows that fulfill a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#filtering}
|
||||
*
|
||||
* @param where the `where` clause.
|
||||
*
|
||||
* @example
|
||||
* You can use conditional operators and `sql function` to filter the rows to be selected.
|
||||
*
|
||||
* ```ts
|
||||
* // Select all cars with green color
|
||||
* await db.select().from(cars).where(eq(cars.color, 'green'));
|
||||
* // or
|
||||
* await db.select().from(cars).where(sql`${cars.color} = 'green'`)
|
||||
* ```
|
||||
*
|
||||
* You can logically combine conditional operators with `and()` and `or()` operators:
|
||||
*
|
||||
* ```ts
|
||||
* // Select all BMW cars with a green color
|
||||
* await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
||||
*
|
||||
* // Select all cars with the green or blue color
|
||||
* await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
||||
* ```
|
||||
*/
|
||||
where(where) {
|
||||
if (typeof where === "function") {
|
||||
where = where(
|
||||
new Proxy(
|
||||
this.config.fields,
|
||||
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
}
|
||||
this.config.where = where;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds a `having` clause to the query.
|
||||
*
|
||||
* Calling this method will select only those rows that fulfill a specified condition. It is typically used with aggregate functions to filter the aggregated data based on a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
|
||||
*
|
||||
* @param having the `having` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Select all brands with more than one car
|
||||
* await db.select({
|
||||
* brand: cars.brand,
|
||||
* count: sql<number>`cast(count(${cars.id}) as int)`,
|
||||
* })
|
||||
* .from(cars)
|
||||
* .groupBy(cars.brand)
|
||||
* .having(({ count }) => gt(count, 1));
|
||||
* ```
|
||||
*/
|
||||
having(having) {
|
||||
if (typeof having === "function") {
|
||||
having = having(
|
||||
new Proxy(
|
||||
this.config.fields,
|
||||
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
}
|
||||
this.config.having = having;
|
||||
return this;
|
||||
}
|
||||
groupBy(...columns) {
|
||||
if (typeof columns[0] === "function") {
|
||||
const groupBy = columns[0](
|
||||
new Proxy(
|
||||
this.config.fields,
|
||||
new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
this.config.groupBy = Array.isArray(groupBy) ? groupBy : [groupBy];
|
||||
} else {
|
||||
this.config.groupBy = columns;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
orderBy(...columns) {
|
||||
if (typeof columns[0] === "function") {
|
||||
const orderBy = columns[0](
|
||||
new Proxy(
|
||||
this.config.fields,
|
||||
new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
||||
if (this.config.setOperators.length > 0) {
|
||||
this.config.setOperators.at(-1).orderBy = orderByArray;
|
||||
} else {
|
||||
this.config.orderBy = orderByArray;
|
||||
}
|
||||
} else {
|
||||
const orderByArray = columns;
|
||||
if (this.config.setOperators.length > 0) {
|
||||
this.config.setOperators.at(-1).orderBy = orderByArray;
|
||||
} else {
|
||||
this.config.orderBy = orderByArray;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds a `limit` clause to the query.
|
||||
*
|
||||
* Calling this method will set the maximum number of rows that will be returned by this query.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
||||
*
|
||||
* @param limit the `limit` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Get the first 10 people from this query.
|
||||
* await db.select().from(people).limit(10);
|
||||
* ```
|
||||
*/
|
||||
limit(limit) {
|
||||
if (this.config.setOperators.length > 0) {
|
||||
this.config.setOperators.at(-1).limit = limit;
|
||||
} else {
|
||||
this.config.limit = limit;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds an `offset` clause to the query.
|
||||
*
|
||||
* Calling this method will skip a number of rows when returning results from this query.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
||||
*
|
||||
* @param offset the `offset` clause.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* // Get the 10th-20th people from this query.
|
||||
* await db.select().from(people).offset(10).limit(10);
|
||||
* ```
|
||||
*/
|
||||
offset(offset) {
|
||||
if (this.config.setOperators.length > 0) {
|
||||
this.config.setOperators.at(-1).offset = offset;
|
||||
} else {
|
||||
this.config.offset = offset;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/** @internal */
|
||||
getSQL() {
|
||||
return this.dialect.buildSelectQuery(this.config);
|
||||
}
|
||||
toSQL() {
|
||||
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
||||
return rest;
|
||||
}
|
||||
as(alias) {
|
||||
return new Proxy(
|
||||
new Subquery(this.getSQL(), this.config.fields, alias),
|
||||
new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
||||
);
|
||||
}
|
||||
/** @internal */
|
||||
getSelectedFields() {
|
||||
return new Proxy(
|
||||
this.config.fields,
|
||||
new SelectionProxyHandler({ alias: this.tableName, sqlAliasedBehavior: "alias", sqlBehavior: "error" })
|
||||
);
|
||||
}
|
||||
$dynamic() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class SQLiteSelectBase extends SQLiteSelectQueryBuilderBase {
|
||||
static [entityKind] = "SQLiteSelect";
|
||||
/** @internal */
|
||||
_prepare(isOneTimeQuery = true) {
|
||||
if (!this.session) {
|
||||
throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
|
||||
}
|
||||
const fieldsList = orderSelectedFields(this.config.fields);
|
||||
const query = this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
||||
this.dialect.sqlToQuery(this.getSQL()),
|
||||
fieldsList,
|
||||
"all",
|
||||
true
|
||||
);
|
||||
query.joinsNotNullableMap = this.joinsNotNullableMap;
|
||||
return query;
|
||||
}
|
||||
prepare() {
|
||||
return this._prepare(false);
|
||||
}
|
||||
run = (placeholderValues) => {
|
||||
return this._prepare().run(placeholderValues);
|
||||
};
|
||||
all = (placeholderValues) => {
|
||||
return this._prepare().all(placeholderValues);
|
||||
};
|
||||
get = (placeholderValues) => {
|
||||
return this._prepare().get(placeholderValues);
|
||||
};
|
||||
values = (placeholderValues) => {
|
||||
return this._prepare().values(placeholderValues);
|
||||
};
|
||||
async execute() {
|
||||
return this.all();
|
||||
}
|
||||
}
|
||||
applyMixins(SQLiteSelectBase, [QueryPromise]);
|
||||
function createSetOperator(type, isAll) {
|
||||
return (leftSelect, rightSelect, ...restSelects) => {
|
||||
const setOperators = [rightSelect, ...restSelects].map((select) => ({
|
||||
type,
|
||||
isAll,
|
||||
rightSelect: select
|
||||
}));
|
||||
for (const setOperator of setOperators) {
|
||||
if (!haveSameKeys(leftSelect.getSelectedFields(), setOperator.rightSelect.getSelectedFields())) {
|
||||
throw new Error(
|
||||
"Set operator error (union / intersect / except): selected fields are not the same or are in a different order"
|
||||
);
|
||||
}
|
||||
}
|
||||
return leftSelect.addSetOperators(setOperators);
|
||||
};
|
||||
}
|
||||
const getSQLiteSetOperators = () => ({
|
||||
union,
|
||||
unionAll,
|
||||
intersect,
|
||||
except
|
||||
});
|
||||
const union = createSetOperator("union", false);
|
||||
const unionAll = createSetOperator("union", true);
|
||||
const intersect = createSetOperator("intersect", false);
|
||||
const except = createSetOperator("except", false);
|
||||
export {
|
||||
SQLiteSelectBase,
|
||||
SQLiteSelectBuilder,
|
||||
SQLiteSelectQueryBuilderBase,
|
||||
except,
|
||||
intersect,
|
||||
union,
|
||||
unionAll
|
||||
};
|
||||
//# sourceMappingURL=select.js.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/select.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/select.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
17
node_modules/drizzle-orm/sqlite-core/query-builders/select.types.cjs
generated
vendored
Normal file
17
node_modules/drizzle-orm/sqlite-core/query-builders/select.types.cjs
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var select_types_exports = {};
|
||||
module.exports = __toCommonJS(select_types_exports);
|
||||
//# sourceMappingURL=select.types.cjs.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/select.types.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/select.types.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
128
node_modules/drizzle-orm/sqlite-core/query-builders/select.types.d.cts
generated
vendored
Normal file
128
node_modules/drizzle-orm/sqlite-core/query-builders/select.types.d.cts
generated
vendored
Normal file
@ -0,0 +1,128 @@
|
||||
import type { ColumnsSelection, Placeholder, SQL, View } from "../../sql/sql.cjs";
|
||||
import type { SQLiteColumn } from "../columns/index.cjs";
|
||||
import type { SQLiteTable, SQLiteTableWithColumns } from "../table.cjs";
|
||||
import type { Assume, ValidateShape } from "../../utils.cjs";
|
||||
import type { SelectedFields as SelectFieldsBase, SelectedFieldsFlat as SelectFieldsFlatBase, SelectedFieldsOrdered as SelectFieldsOrderedBase } from "../../operations.cjs";
|
||||
import type { TypedQueryBuilder } from "../../query-builders/query-builder.cjs";
|
||||
import type { AppendToNullabilityMap, AppendToResult, BuildSubquerySelection, GetSelectTableName, JoinNullability, JoinType, MapColumnsToTableAlias, SelectMode, SelectResult, SetOperator } from "../../query-builders/select.types.cjs";
|
||||
import type { Subquery } from "../../subquery.cjs";
|
||||
import type { Table, UpdateTableConfig } from "../../table.cjs";
|
||||
import type { SQLitePreparedQuery } from "../session.cjs";
|
||||
import type { SQLiteViewBase } from "../view-base.cjs";
|
||||
import type { SQLiteViewWithSelection } from "../view.cjs";
|
||||
import type { SQLiteSelectBase, SQLiteSelectQueryBuilderBase } from "./select.cjs";
|
||||
export interface SQLiteSelectJoinConfig {
|
||||
on: SQL | undefined;
|
||||
table: SQLiteTable | Subquery | SQLiteViewBase | SQL;
|
||||
alias: string | undefined;
|
||||
joinType: JoinType;
|
||||
}
|
||||
export type BuildAliasTable<TTable extends SQLiteTable | View, TAlias extends string> = TTable extends Table ? SQLiteTableWithColumns<UpdateTableConfig<TTable['_']['config'], {
|
||||
name: TAlias;
|
||||
columns: MapColumnsToTableAlias<TTable['_']['columns'], TAlias, 'sqlite'>;
|
||||
}>> : TTable extends View ? SQLiteViewWithSelection<TAlias, TTable['_']['existing'], MapColumnsToTableAlias<TTable['_']['selectedFields'], TAlias, 'sqlite'>> : never;
|
||||
export interface SQLiteSelectConfig {
|
||||
withList?: Subquery[];
|
||||
fields: Record<string, unknown>;
|
||||
fieldsFlat?: SelectedFieldsOrdered;
|
||||
where?: SQL;
|
||||
having?: SQL;
|
||||
table: SQLiteTable | Subquery | SQLiteViewBase | SQL;
|
||||
limit?: number | Placeholder;
|
||||
offset?: number | Placeholder;
|
||||
joins?: SQLiteSelectJoinConfig[];
|
||||
orderBy?: (SQLiteColumn | SQL | SQL.Aliased)[];
|
||||
groupBy?: (SQLiteColumn | SQL | SQL.Aliased)[];
|
||||
distinct?: boolean;
|
||||
setOperators: {
|
||||
rightSelect: TypedQueryBuilder<any, any>;
|
||||
type: SetOperator;
|
||||
isAll: boolean;
|
||||
orderBy?: (SQLiteColumn | SQL | SQL.Aliased)[];
|
||||
limit?: number | Placeholder;
|
||||
offset?: number | Placeholder;
|
||||
}[];
|
||||
}
|
||||
export type SQLiteSelectJoin<T extends AnySQLiteSelectQueryBuilder, TDynamic extends boolean, TJoinType extends JoinType, TJoinedTable extends SQLiteTable | Subquery | SQLiteViewBase | SQL, TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>> = T extends any ? SQLiteSelectWithout<SQLiteSelectKind<T['_']['hkt'], T['_']['tableName'], T['_']['resultType'], T['_']['runResult'], AppendToResult<T['_']['tableName'], T['_']['selection'], TJoinedName, TJoinedTable extends SQLiteTable ? TJoinedTable['_']['columns'] : TJoinedTable extends Subquery | View ? Assume<TJoinedTable['_']['selectedFields'], SelectedFields> : never, T['_']['selectMode']>, T['_']['selectMode'] extends 'partial' ? T['_']['selectMode'] : 'multiple', AppendToNullabilityMap<T['_']['nullabilityMap'], TJoinedName, TJoinType>, T['_']['dynamic'], T['_']['excludedMethods']>, TDynamic, T['_']['excludedMethods']> : never;
|
||||
export type SQLiteSelectJoinFn<T extends AnySQLiteSelectQueryBuilder, TDynamic extends boolean, TJoinType extends JoinType> = <TJoinedTable extends SQLiteTable | Subquery | SQLiteViewBase | SQL, TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable, on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined) => SQLiteSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
|
||||
export type SelectedFieldsFlat = SelectFieldsFlatBase<SQLiteColumn>;
|
||||
export type SelectedFields = SelectFieldsBase<SQLiteColumn, SQLiteTable>;
|
||||
export type SelectedFieldsOrdered = SelectFieldsOrderedBase<SQLiteColumn>;
|
||||
export interface SQLiteSelectHKTBase {
|
||||
tableName: string | undefined;
|
||||
resultType: 'sync' | 'async';
|
||||
runResult: unknown;
|
||||
selection: unknown;
|
||||
selectMode: SelectMode;
|
||||
nullabilityMap: unknown;
|
||||
dynamic: boolean;
|
||||
excludedMethods: string;
|
||||
result: unknown;
|
||||
selectedFields: unknown;
|
||||
_type: unknown;
|
||||
}
|
||||
export type SQLiteSelectKind<T extends SQLiteSelectHKTBase, TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection extends ColumnsSelection, TSelectMode extends SelectMode, TNullabilityMap extends Record<string, JoinNullability>, TDynamic extends boolean, TExcludedMethods extends string, TResult = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields = BuildSubquerySelection<TSelection, TNullabilityMap>> = (T & {
|
||||
tableName: TTableName;
|
||||
resultType: TResultType;
|
||||
runResult: TRunResult;
|
||||
selection: TSelection;
|
||||
selectMode: TSelectMode;
|
||||
nullabilityMap: TNullabilityMap;
|
||||
dynamic: TDynamic;
|
||||
excludedMethods: TExcludedMethods;
|
||||
result: TResult;
|
||||
selectedFields: TSelectedFields;
|
||||
})['_type'];
|
||||
export interface SQLiteSelectQueryBuilderHKT extends SQLiteSelectHKTBase {
|
||||
_type: SQLiteSelectQueryBuilderBase<SQLiteSelectQueryBuilderHKT, this['tableName'], this['resultType'], this['runResult'], Assume<this['selection'], ColumnsSelection>, this['selectMode'], Assume<this['nullabilityMap'], Record<string, JoinNullability>>, this['dynamic'], this['excludedMethods'], Assume<this['result'], any[]>, Assume<this['selectedFields'], ColumnsSelection>>;
|
||||
}
|
||||
export interface SQLiteSelectHKT extends SQLiteSelectHKTBase {
|
||||
_type: SQLiteSelectBase<this['tableName'], this['resultType'], this['runResult'], Assume<this['selection'], ColumnsSelection>, this['selectMode'], Assume<this['nullabilityMap'], Record<string, JoinNullability>>, this['dynamic'], this['excludedMethods'], Assume<this['result'], any[]>, Assume<this['selectedFields'], ColumnsSelection>>;
|
||||
}
|
||||
export type SQLiteSetOperatorExcludedMethods = 'config' | 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin' | 'where' | 'having' | 'groupBy';
|
||||
export type CreateSQLiteSelectFromBuilderMode<TBuilderMode extends 'db' | 'qb', TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection extends ColumnsSelection, TSelectMode extends SelectMode> = TBuilderMode extends 'db' ? SQLiteSelectBase<TTableName, TResultType, TRunResult, TSelection, TSelectMode> : SQLiteSelectQueryBuilderBase<SQLiteSelectQueryBuilderHKT, TTableName, TResultType, TRunResult, TSelection, TSelectMode>;
|
||||
export type SQLiteSelectWithout<T extends AnySQLiteSelectQueryBuilder, TDynamic extends boolean, K extends keyof T & string, TResetExcluded extends boolean = false> = TDynamic extends true ? T : Omit<SQLiteSelectKind<T['_']['hkt'], T['_']['tableName'], T['_']['resultType'], T['_']['runResult'], T['_']['selection'], T['_']['selectMode'], T['_']['nullabilityMap'], TDynamic, TResetExcluded extends true ? K : T['_']['excludedMethods'] | K, T['_']['result'], T['_']['selectedFields']>, TResetExcluded extends true ? K : T['_']['excludedMethods'] | K>;
|
||||
export type SQLiteSelectExecute<T extends AnySQLiteSelect> = T['_']['result'];
|
||||
export type SQLiteSelectPrepare<T extends AnySQLiteSelect> = SQLitePreparedQuery<{
|
||||
type: T['_']['resultType'];
|
||||
run: T['_']['runResult'];
|
||||
all: T['_']['result'];
|
||||
get: T['_']['result'][number] | undefined;
|
||||
values: any[][];
|
||||
execute: SQLiteSelectExecute<T>;
|
||||
}>;
|
||||
export type SQLiteSelectDynamic<T extends AnySQLiteSelectQueryBuilder> = SQLiteSelectKind<T['_']['hkt'], T['_']['tableName'], T['_']['resultType'], T['_']['runResult'], T['_']['selection'], T['_']['selectMode'], T['_']['nullabilityMap'], true, never, T['_']['result'], T['_']['selectedFields']>;
|
||||
export type SQLiteSelectQueryBuilder<THKT extends SQLiteSelectHKTBase = SQLiteSelectQueryBuilderHKT, TTableName extends string | undefined = string | undefined, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = unknown, TSelection extends ColumnsSelection = ColumnsSelection, TSelectMode extends SelectMode = SelectMode, TNullabilityMap extends Record<string, JoinNullability> = Record<string, JoinNullability>, TResult extends any[] = unknown[], TSelectedFields extends ColumnsSelection = ColumnsSelection> = SQLiteSelectQueryBuilderBase<THKT, TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, true, never, TResult, TSelectedFields>;
|
||||
export type AnySQLiteSelectQueryBuilder = SQLiteSelectQueryBuilderBase<any, any, any, any, any, any, any, any, any, any, any>;
|
||||
export type AnySQLiteSetOperatorInterface = SQLiteSetOperatorInterface<any, any, any, any, any, any, any, any, any>;
|
||||
export interface SQLiteSetOperatorInterface<TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection extends ColumnsSelection, TSelectMode extends SelectMode = 'single', TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>> {
|
||||
_: {
|
||||
readonly hkt: SQLiteSelectHKTBase;
|
||||
readonly tableName: TTableName;
|
||||
readonly resultType: TResultType;
|
||||
readonly runResult: TRunResult;
|
||||
readonly selection: TSelection;
|
||||
readonly selectMode: TSelectMode;
|
||||
readonly nullabilityMap: TNullabilityMap;
|
||||
readonly dynamic: TDynamic;
|
||||
readonly excludedMethods: TExcludedMethods;
|
||||
readonly result: TResult;
|
||||
readonly selectedFields: TSelectedFields;
|
||||
};
|
||||
}
|
||||
export type SQLiteSetOperatorWithResult<TResult extends any[]> = SQLiteSetOperatorInterface<any, any, any, any, any, any, any, any, TResult, any>;
|
||||
export type SQLiteSelect<TTableName extends string | undefined = string | undefined, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = unknown, TSelection extends ColumnsSelection = Record<string, any>, TSelectMode extends SelectMode = SelectMode, TNullabilityMap extends Record<string, JoinNullability> = Record<string, JoinNullability>> = SQLiteSelectBase<TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, true, never>;
|
||||
export type AnySQLiteSelect = SQLiteSelectBase<any, any, any, any, any, any, any, any, any, any>;
|
||||
export type SQLiteSetOperator<TTableName extends string | undefined = string | undefined, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = unknown, TSelection extends ColumnsSelection = Record<string, any>, TSelectMode extends SelectMode = SelectMode, TNullabilityMap extends Record<string, JoinNullability> = Record<string, JoinNullability>> = SQLiteSelectBase<TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, true, SQLiteSetOperatorExcludedMethods>;
|
||||
export type SetOperatorRightSelect<TValue extends SQLiteSetOperatorWithResult<TResult>, TResult extends any[]> = TValue extends SQLiteSetOperatorInterface<any, any, any, any, any, any, any, any, infer TValueResult, any> ? ValidateShape<TValueResult[number], TResult[number], TypedQueryBuilder<any, TValueResult>> : TValue;
|
||||
export type SetOperatorRestSelect<TValue extends readonly SQLiteSetOperatorWithResult<TResult>[], TResult extends any[]> = TValue extends [infer First, ...infer Rest] ? First extends SQLiteSetOperatorInterface<any, any, any, any, any, any, any, any, infer TValueResult, any> ? Rest extends AnySQLiteSetOperatorInterface[] ? [
|
||||
ValidateShape<TValueResult[number], TResult[number], TypedQueryBuilder<any, TValueResult>>,
|
||||
...SetOperatorRestSelect<Rest, TResult>
|
||||
] : ValidateShape<TValueResult[number], TResult[number], TypedQueryBuilder<any, TValueResult>[]> : never : TValue;
|
||||
export type SQLiteCreateSetOperatorFn = <TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection extends ColumnsSelection, TValue extends SQLiteSetOperatorWithResult<TResult>, TRest extends SQLiteSetOperatorWithResult<TResult>[], TSelectMode extends SelectMode = 'single', TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>>(leftSelect: SQLiteSetOperatorInterface<TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields>, rightSelect: SetOperatorRightSelect<TValue, TResult>, ...restSelects: SetOperatorRestSelect<TRest, TResult>) => SQLiteSelectWithout<SQLiteSelectBase<TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields>, false, SQLiteSetOperatorExcludedMethods, true>;
|
||||
export type GetSQLiteSetOperators = {
|
||||
union: SQLiteCreateSetOperatorFn;
|
||||
intersect: SQLiteCreateSetOperatorFn;
|
||||
except: SQLiteCreateSetOperatorFn;
|
||||
unionAll: SQLiteCreateSetOperatorFn;
|
||||
};
|
||||
128
node_modules/drizzle-orm/sqlite-core/query-builders/select.types.d.ts
generated
vendored
Normal file
128
node_modules/drizzle-orm/sqlite-core/query-builders/select.types.d.ts
generated
vendored
Normal file
@ -0,0 +1,128 @@
|
||||
import type { ColumnsSelection, Placeholder, SQL, View } from "../../sql/sql.js";
|
||||
import type { SQLiteColumn } from "../columns/index.js";
|
||||
import type { SQLiteTable, SQLiteTableWithColumns } from "../table.js";
|
||||
import type { Assume, ValidateShape } from "../../utils.js";
|
||||
import type { SelectedFields as SelectFieldsBase, SelectedFieldsFlat as SelectFieldsFlatBase, SelectedFieldsOrdered as SelectFieldsOrderedBase } from "../../operations.js";
|
||||
import type { TypedQueryBuilder } from "../../query-builders/query-builder.js";
|
||||
import type { AppendToNullabilityMap, AppendToResult, BuildSubquerySelection, GetSelectTableName, JoinNullability, JoinType, MapColumnsToTableAlias, SelectMode, SelectResult, SetOperator } from "../../query-builders/select.types.js";
|
||||
import type { Subquery } from "../../subquery.js";
|
||||
import type { Table, UpdateTableConfig } from "../../table.js";
|
||||
import type { SQLitePreparedQuery } from "../session.js";
|
||||
import type { SQLiteViewBase } from "../view-base.js";
|
||||
import type { SQLiteViewWithSelection } from "../view.js";
|
||||
import type { SQLiteSelectBase, SQLiteSelectQueryBuilderBase } from "./select.js";
|
||||
export interface SQLiteSelectJoinConfig {
|
||||
on: SQL | undefined;
|
||||
table: SQLiteTable | Subquery | SQLiteViewBase | SQL;
|
||||
alias: string | undefined;
|
||||
joinType: JoinType;
|
||||
}
|
||||
export type BuildAliasTable<TTable extends SQLiteTable | View, TAlias extends string> = TTable extends Table ? SQLiteTableWithColumns<UpdateTableConfig<TTable['_']['config'], {
|
||||
name: TAlias;
|
||||
columns: MapColumnsToTableAlias<TTable['_']['columns'], TAlias, 'sqlite'>;
|
||||
}>> : TTable extends View ? SQLiteViewWithSelection<TAlias, TTable['_']['existing'], MapColumnsToTableAlias<TTable['_']['selectedFields'], TAlias, 'sqlite'>> : never;
|
||||
export interface SQLiteSelectConfig {
|
||||
withList?: Subquery[];
|
||||
fields: Record<string, unknown>;
|
||||
fieldsFlat?: SelectedFieldsOrdered;
|
||||
where?: SQL;
|
||||
having?: SQL;
|
||||
table: SQLiteTable | Subquery | SQLiteViewBase | SQL;
|
||||
limit?: number | Placeholder;
|
||||
offset?: number | Placeholder;
|
||||
joins?: SQLiteSelectJoinConfig[];
|
||||
orderBy?: (SQLiteColumn | SQL | SQL.Aliased)[];
|
||||
groupBy?: (SQLiteColumn | SQL | SQL.Aliased)[];
|
||||
distinct?: boolean;
|
||||
setOperators: {
|
||||
rightSelect: TypedQueryBuilder<any, any>;
|
||||
type: SetOperator;
|
||||
isAll: boolean;
|
||||
orderBy?: (SQLiteColumn | SQL | SQL.Aliased)[];
|
||||
limit?: number | Placeholder;
|
||||
offset?: number | Placeholder;
|
||||
}[];
|
||||
}
|
||||
export type SQLiteSelectJoin<T extends AnySQLiteSelectQueryBuilder, TDynamic extends boolean, TJoinType extends JoinType, TJoinedTable extends SQLiteTable | Subquery | SQLiteViewBase | SQL, TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>> = T extends any ? SQLiteSelectWithout<SQLiteSelectKind<T['_']['hkt'], T['_']['tableName'], T['_']['resultType'], T['_']['runResult'], AppendToResult<T['_']['tableName'], T['_']['selection'], TJoinedName, TJoinedTable extends SQLiteTable ? TJoinedTable['_']['columns'] : TJoinedTable extends Subquery | View ? Assume<TJoinedTable['_']['selectedFields'], SelectedFields> : never, T['_']['selectMode']>, T['_']['selectMode'] extends 'partial' ? T['_']['selectMode'] : 'multiple', AppendToNullabilityMap<T['_']['nullabilityMap'], TJoinedName, TJoinType>, T['_']['dynamic'], T['_']['excludedMethods']>, TDynamic, T['_']['excludedMethods']> : never;
|
||||
export type SQLiteSelectJoinFn<T extends AnySQLiteSelectQueryBuilder, TDynamic extends boolean, TJoinType extends JoinType> = <TJoinedTable extends SQLiteTable | Subquery | SQLiteViewBase | SQL, TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable, on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined) => SQLiteSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
|
||||
export type SelectedFieldsFlat = SelectFieldsFlatBase<SQLiteColumn>;
|
||||
export type SelectedFields = SelectFieldsBase<SQLiteColumn, SQLiteTable>;
|
||||
export type SelectedFieldsOrdered = SelectFieldsOrderedBase<SQLiteColumn>;
|
||||
export interface SQLiteSelectHKTBase {
|
||||
tableName: string | undefined;
|
||||
resultType: 'sync' | 'async';
|
||||
runResult: unknown;
|
||||
selection: unknown;
|
||||
selectMode: SelectMode;
|
||||
nullabilityMap: unknown;
|
||||
dynamic: boolean;
|
||||
excludedMethods: string;
|
||||
result: unknown;
|
||||
selectedFields: unknown;
|
||||
_type: unknown;
|
||||
}
|
||||
export type SQLiteSelectKind<T extends SQLiteSelectHKTBase, TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection extends ColumnsSelection, TSelectMode extends SelectMode, TNullabilityMap extends Record<string, JoinNullability>, TDynamic extends boolean, TExcludedMethods extends string, TResult = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields = BuildSubquerySelection<TSelection, TNullabilityMap>> = (T & {
|
||||
tableName: TTableName;
|
||||
resultType: TResultType;
|
||||
runResult: TRunResult;
|
||||
selection: TSelection;
|
||||
selectMode: TSelectMode;
|
||||
nullabilityMap: TNullabilityMap;
|
||||
dynamic: TDynamic;
|
||||
excludedMethods: TExcludedMethods;
|
||||
result: TResult;
|
||||
selectedFields: TSelectedFields;
|
||||
})['_type'];
|
||||
export interface SQLiteSelectQueryBuilderHKT extends SQLiteSelectHKTBase {
|
||||
_type: SQLiteSelectQueryBuilderBase<SQLiteSelectQueryBuilderHKT, this['tableName'], this['resultType'], this['runResult'], Assume<this['selection'], ColumnsSelection>, this['selectMode'], Assume<this['nullabilityMap'], Record<string, JoinNullability>>, this['dynamic'], this['excludedMethods'], Assume<this['result'], any[]>, Assume<this['selectedFields'], ColumnsSelection>>;
|
||||
}
|
||||
export interface SQLiteSelectHKT extends SQLiteSelectHKTBase {
|
||||
_type: SQLiteSelectBase<this['tableName'], this['resultType'], this['runResult'], Assume<this['selection'], ColumnsSelection>, this['selectMode'], Assume<this['nullabilityMap'], Record<string, JoinNullability>>, this['dynamic'], this['excludedMethods'], Assume<this['result'], any[]>, Assume<this['selectedFields'], ColumnsSelection>>;
|
||||
}
|
||||
export type SQLiteSetOperatorExcludedMethods = 'config' | 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin' | 'where' | 'having' | 'groupBy';
|
||||
export type CreateSQLiteSelectFromBuilderMode<TBuilderMode extends 'db' | 'qb', TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection extends ColumnsSelection, TSelectMode extends SelectMode> = TBuilderMode extends 'db' ? SQLiteSelectBase<TTableName, TResultType, TRunResult, TSelection, TSelectMode> : SQLiteSelectQueryBuilderBase<SQLiteSelectQueryBuilderHKT, TTableName, TResultType, TRunResult, TSelection, TSelectMode>;
|
||||
export type SQLiteSelectWithout<T extends AnySQLiteSelectQueryBuilder, TDynamic extends boolean, K extends keyof T & string, TResetExcluded extends boolean = false> = TDynamic extends true ? T : Omit<SQLiteSelectKind<T['_']['hkt'], T['_']['tableName'], T['_']['resultType'], T['_']['runResult'], T['_']['selection'], T['_']['selectMode'], T['_']['nullabilityMap'], TDynamic, TResetExcluded extends true ? K : T['_']['excludedMethods'] | K, T['_']['result'], T['_']['selectedFields']>, TResetExcluded extends true ? K : T['_']['excludedMethods'] | K>;
|
||||
export type SQLiteSelectExecute<T extends AnySQLiteSelect> = T['_']['result'];
|
||||
export type SQLiteSelectPrepare<T extends AnySQLiteSelect> = SQLitePreparedQuery<{
|
||||
type: T['_']['resultType'];
|
||||
run: T['_']['runResult'];
|
||||
all: T['_']['result'];
|
||||
get: T['_']['result'][number] | undefined;
|
||||
values: any[][];
|
||||
execute: SQLiteSelectExecute<T>;
|
||||
}>;
|
||||
export type SQLiteSelectDynamic<T extends AnySQLiteSelectQueryBuilder> = SQLiteSelectKind<T['_']['hkt'], T['_']['tableName'], T['_']['resultType'], T['_']['runResult'], T['_']['selection'], T['_']['selectMode'], T['_']['nullabilityMap'], true, never, T['_']['result'], T['_']['selectedFields']>;
|
||||
export type SQLiteSelectQueryBuilder<THKT extends SQLiteSelectHKTBase = SQLiteSelectQueryBuilderHKT, TTableName extends string | undefined = string | undefined, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = unknown, TSelection extends ColumnsSelection = ColumnsSelection, TSelectMode extends SelectMode = SelectMode, TNullabilityMap extends Record<string, JoinNullability> = Record<string, JoinNullability>, TResult extends any[] = unknown[], TSelectedFields extends ColumnsSelection = ColumnsSelection> = SQLiteSelectQueryBuilderBase<THKT, TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, true, never, TResult, TSelectedFields>;
|
||||
export type AnySQLiteSelectQueryBuilder = SQLiteSelectQueryBuilderBase<any, any, any, any, any, any, any, any, any, any, any>;
|
||||
export type AnySQLiteSetOperatorInterface = SQLiteSetOperatorInterface<any, any, any, any, any, any, any, any, any>;
|
||||
export interface SQLiteSetOperatorInterface<TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection extends ColumnsSelection, TSelectMode extends SelectMode = 'single', TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>> {
|
||||
_: {
|
||||
readonly hkt: SQLiteSelectHKTBase;
|
||||
readonly tableName: TTableName;
|
||||
readonly resultType: TResultType;
|
||||
readonly runResult: TRunResult;
|
||||
readonly selection: TSelection;
|
||||
readonly selectMode: TSelectMode;
|
||||
readonly nullabilityMap: TNullabilityMap;
|
||||
readonly dynamic: TDynamic;
|
||||
readonly excludedMethods: TExcludedMethods;
|
||||
readonly result: TResult;
|
||||
readonly selectedFields: TSelectedFields;
|
||||
};
|
||||
}
|
||||
export type SQLiteSetOperatorWithResult<TResult extends any[]> = SQLiteSetOperatorInterface<any, any, any, any, any, any, any, any, TResult, any>;
|
||||
export type SQLiteSelect<TTableName extends string | undefined = string | undefined, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = unknown, TSelection extends ColumnsSelection = Record<string, any>, TSelectMode extends SelectMode = SelectMode, TNullabilityMap extends Record<string, JoinNullability> = Record<string, JoinNullability>> = SQLiteSelectBase<TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, true, never>;
|
||||
export type AnySQLiteSelect = SQLiteSelectBase<any, any, any, any, any, any, any, any, any, any>;
|
||||
export type SQLiteSetOperator<TTableName extends string | undefined = string | undefined, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = unknown, TSelection extends ColumnsSelection = Record<string, any>, TSelectMode extends SelectMode = SelectMode, TNullabilityMap extends Record<string, JoinNullability> = Record<string, JoinNullability>> = SQLiteSelectBase<TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, true, SQLiteSetOperatorExcludedMethods>;
|
||||
export type SetOperatorRightSelect<TValue extends SQLiteSetOperatorWithResult<TResult>, TResult extends any[]> = TValue extends SQLiteSetOperatorInterface<any, any, any, any, any, any, any, any, infer TValueResult, any> ? ValidateShape<TValueResult[number], TResult[number], TypedQueryBuilder<any, TValueResult>> : TValue;
|
||||
export type SetOperatorRestSelect<TValue extends readonly SQLiteSetOperatorWithResult<TResult>[], TResult extends any[]> = TValue extends [infer First, ...infer Rest] ? First extends SQLiteSetOperatorInterface<any, any, any, any, any, any, any, any, infer TValueResult, any> ? Rest extends AnySQLiteSetOperatorInterface[] ? [
|
||||
ValidateShape<TValueResult[number], TResult[number], TypedQueryBuilder<any, TValueResult>>,
|
||||
...SetOperatorRestSelect<Rest, TResult>
|
||||
] : ValidateShape<TValueResult[number], TResult[number], TypedQueryBuilder<any, TValueResult>[]> : never : TValue;
|
||||
export type SQLiteCreateSetOperatorFn = <TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection extends ColumnsSelection, TValue extends SQLiteSetOperatorWithResult<TResult>, TRest extends SQLiteSetOperatorWithResult<TResult>[], TSelectMode extends SelectMode = 'single', TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>>(leftSelect: SQLiteSetOperatorInterface<TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields>, rightSelect: SetOperatorRightSelect<TValue, TResult>, ...restSelects: SetOperatorRestSelect<TRest, TResult>) => SQLiteSelectWithout<SQLiteSelectBase<TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields>, false, SQLiteSetOperatorExcludedMethods, true>;
|
||||
export type GetSQLiteSetOperators = {
|
||||
union: SQLiteCreateSetOperatorFn;
|
||||
intersect: SQLiteCreateSetOperatorFn;
|
||||
except: SQLiteCreateSetOperatorFn;
|
||||
unionAll: SQLiteCreateSetOperatorFn;
|
||||
};
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/select.types.js
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/select.types.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
//# sourceMappingURL=select.types.js.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/select.types.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/select.types.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
||||
198
node_modules/drizzle-orm/sqlite-core/query-builders/update.cjs
generated
vendored
Normal file
198
node_modules/drizzle-orm/sqlite-core/query-builders/update.cjs
generated
vendored
Normal file
@ -0,0 +1,198 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var update_exports = {};
|
||||
__export(update_exports, {
|
||||
SQLiteUpdateBase: () => SQLiteUpdateBase,
|
||||
SQLiteUpdateBuilder: () => SQLiteUpdateBuilder
|
||||
});
|
||||
module.exports = __toCommonJS(update_exports);
|
||||
var import_entity = require("../../entity.cjs");
|
||||
var import_query_promise = require("../../query-promise.cjs");
|
||||
var import_selection_proxy = require("../../selection-proxy.cjs");
|
||||
var import_table = require("../table.cjs");
|
||||
var import_subquery = require("../../subquery.cjs");
|
||||
var import_table2 = require("../../table.cjs");
|
||||
var import_utils = require("../../utils.cjs");
|
||||
var import_view_common = require("../../view-common.cjs");
|
||||
var import_view_base = require("../view-base.cjs");
|
||||
class SQLiteUpdateBuilder {
|
||||
constructor(table, session, dialect, withList) {
|
||||
this.table = table;
|
||||
this.session = session;
|
||||
this.dialect = dialect;
|
||||
this.withList = withList;
|
||||
}
|
||||
static [import_entity.entityKind] = "SQLiteUpdateBuilder";
|
||||
set(values) {
|
||||
return new SQLiteUpdateBase(
|
||||
this.table,
|
||||
(0, import_utils.mapUpdateSet)(this.table, values),
|
||||
this.session,
|
||||
this.dialect,
|
||||
this.withList
|
||||
);
|
||||
}
|
||||
}
|
||||
class SQLiteUpdateBase extends import_query_promise.QueryPromise {
|
||||
constructor(table, set, session, dialect, withList) {
|
||||
super();
|
||||
this.session = session;
|
||||
this.dialect = dialect;
|
||||
this.config = { set, table, withList, joins: [] };
|
||||
}
|
||||
static [import_entity.entityKind] = "SQLiteUpdate";
|
||||
/** @internal */
|
||||
config;
|
||||
from(source) {
|
||||
this.config.from = source;
|
||||
return this;
|
||||
}
|
||||
createJoin(joinType) {
|
||||
return (table, on) => {
|
||||
const tableName = (0, import_utils.getTableLikeName)(table);
|
||||
if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) {
|
||||
throw new Error(`Alias "${tableName}" is already used in this query`);
|
||||
}
|
||||
if (typeof on === "function") {
|
||||
const from = this.config.from ? (0, import_entity.is)(table, import_table.SQLiteTable) ? table[import_table2.Table.Symbol.Columns] : (0, import_entity.is)(table, import_subquery.Subquery) ? table._.selectedFields : (0, import_entity.is)(table, import_view_base.SQLiteViewBase) ? table[import_view_common.ViewBaseConfig].selectedFields : void 0 : void 0;
|
||||
on = on(
|
||||
new Proxy(
|
||||
this.config.table[import_table2.Table.Symbol.Columns],
|
||||
new import_selection_proxy.SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
||||
),
|
||||
from && new Proxy(
|
||||
from,
|
||||
new import_selection_proxy.SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
}
|
||||
this.config.joins.push({ on, table, joinType, alias: tableName });
|
||||
return this;
|
||||
};
|
||||
}
|
||||
leftJoin = this.createJoin("left");
|
||||
rightJoin = this.createJoin("right");
|
||||
innerJoin = this.createJoin("inner");
|
||||
fullJoin = this.createJoin("full");
|
||||
/**
|
||||
* Adds a 'where' clause to the query.
|
||||
*
|
||||
* Calling this method will update only those rows that fulfill a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/update}
|
||||
*
|
||||
* @param where the 'where' clause.
|
||||
*
|
||||
* @example
|
||||
* You can use conditional operators and `sql function` to filter the rows to be updated.
|
||||
*
|
||||
* ```ts
|
||||
* // Update all cars with green color
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(eq(cars.color, 'green'));
|
||||
* // or
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(sql`${cars.color} = 'green'`)
|
||||
* ```
|
||||
*
|
||||
* You can logically combine conditional operators with `and()` and `or()` operators:
|
||||
*
|
||||
* ```ts
|
||||
* // Update all BMW cars with a green color
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
||||
*
|
||||
* // Update all cars with the green or blue color
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
||||
* ```
|
||||
*/
|
||||
where(where) {
|
||||
this.config.where = where;
|
||||
return this;
|
||||
}
|
||||
orderBy(...columns) {
|
||||
if (typeof columns[0] === "function") {
|
||||
const orderBy = columns[0](
|
||||
new Proxy(
|
||||
this.config.table[import_table2.Table.Symbol.Columns],
|
||||
new import_selection_proxy.SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
||||
this.config.orderBy = orderByArray;
|
||||
} else {
|
||||
const orderByArray = columns;
|
||||
this.config.orderBy = orderByArray;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
limit(limit) {
|
||||
this.config.limit = limit;
|
||||
return this;
|
||||
}
|
||||
returning(fields = this.config.table[import_table.SQLiteTable.Symbol.Columns]) {
|
||||
this.config.returning = (0, import_utils.orderSelectedFields)(fields);
|
||||
return this;
|
||||
}
|
||||
/** @internal */
|
||||
getSQL() {
|
||||
return this.dialect.buildUpdateQuery(this.config);
|
||||
}
|
||||
toSQL() {
|
||||
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
||||
return rest;
|
||||
}
|
||||
/** @internal */
|
||||
_prepare(isOneTimeQuery = true) {
|
||||
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
||||
this.dialect.sqlToQuery(this.getSQL()),
|
||||
this.config.returning,
|
||||
this.config.returning ? "all" : "run",
|
||||
true
|
||||
);
|
||||
}
|
||||
prepare() {
|
||||
return this._prepare(false);
|
||||
}
|
||||
run = (placeholderValues) => {
|
||||
return this._prepare().run(placeholderValues);
|
||||
};
|
||||
all = (placeholderValues) => {
|
||||
return this._prepare().all(placeholderValues);
|
||||
};
|
||||
get = (placeholderValues) => {
|
||||
return this._prepare().get(placeholderValues);
|
||||
};
|
||||
values = (placeholderValues) => {
|
||||
return this._prepare().values(placeholderValues);
|
||||
};
|
||||
async execute() {
|
||||
return this.config.returning ? this.all() : this.run();
|
||||
}
|
||||
$dynamic() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
SQLiteUpdateBase,
|
||||
SQLiteUpdateBuilder
|
||||
});
|
||||
//# sourceMappingURL=update.cjs.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/update.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/update.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
151
node_modules/drizzle-orm/sqlite-core/query-builders/update.d.cts
generated
vendored
Normal file
151
node_modules/drizzle-orm/sqlite-core/query-builders/update.d.cts
generated
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
import type { GetColumnData } from "../../column.cjs";
|
||||
import { entityKind } from "../../entity.cjs";
|
||||
import type { SelectResultFields } from "../../query-builders/select.types.cjs";
|
||||
import { QueryPromise } from "../../query-promise.cjs";
|
||||
import type { RunnableQuery } from "../../runnable-query.cjs";
|
||||
import type { Placeholder, Query, SQL, SQLWrapper } from "../../sql/sql.cjs";
|
||||
import type { SQLiteDialect } from "../dialect.cjs";
|
||||
import type { SQLitePreparedQuery, SQLiteSession } from "../session.cjs";
|
||||
import { SQLiteTable } from "../table.cjs";
|
||||
import { Subquery } from "../../subquery.cjs";
|
||||
import { type DrizzleTypeError, type UpdateSet, type ValueOrArray } from "../../utils.cjs";
|
||||
import type { SQLiteColumn } from "../columns/common.cjs";
|
||||
import { SQLiteViewBase } from "../view-base.cjs";
|
||||
import type { SelectedFields, SelectedFieldsOrdered, SQLiteSelectJoinConfig } from "./select.types.cjs";
|
||||
export interface SQLiteUpdateConfig {
|
||||
where?: SQL | undefined;
|
||||
limit?: number | Placeholder;
|
||||
orderBy?: (SQLiteColumn | SQL | SQL.Aliased)[];
|
||||
set: UpdateSet;
|
||||
table: SQLiteTable;
|
||||
from?: SQLiteTable | Subquery | SQLiteViewBase | SQL;
|
||||
joins: SQLiteSelectJoinConfig[];
|
||||
returning?: SelectedFieldsOrdered;
|
||||
withList?: Subquery[];
|
||||
}
|
||||
export type SQLiteUpdateSetSource<TTable extends SQLiteTable> = {
|
||||
[Key in keyof TTable['$inferInsert']]?: GetColumnData<TTable['_']['columns'][Key], 'query'> | SQL | SQLiteColumn | undefined;
|
||||
} & {};
|
||||
export declare class SQLiteUpdateBuilder<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult> {
|
||||
protected table: TTable;
|
||||
protected session: SQLiteSession<any, any, any, any>;
|
||||
protected dialect: SQLiteDialect;
|
||||
private withList?;
|
||||
static readonly [entityKind]: string;
|
||||
readonly _: {
|
||||
readonly table: TTable;
|
||||
};
|
||||
constructor(table: TTable, session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[] | undefined);
|
||||
set(values: SQLiteUpdateSetSource<TTable>): SQLiteUpdateWithout<SQLiteUpdateBase<TTable, TResultType, TRunResult>, false, 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin'>;
|
||||
}
|
||||
export type SQLiteUpdateWithout<T extends AnySQLiteUpdate, TDynamic extends boolean, K extends keyof T & string> = TDynamic extends true ? T : Omit<SQLiteUpdateBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['from'], T['_']['returning'], TDynamic, T['_']['excludedMethods'] | K>, T['_']['excludedMethods'] | K>;
|
||||
export type SQLiteUpdateWithJoins<T extends AnySQLiteUpdate, TDynamic extends boolean, TFrom extends SQLiteTable | Subquery | SQLiteViewBase | SQL> = TDynamic extends true ? T : Omit<SQLiteUpdateBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], TFrom, T['_']['returning'], TDynamic, Exclude<T['_']['excludedMethods'] | 'from', 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin'>>, Exclude<T['_']['excludedMethods'] | 'from', 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin'>>;
|
||||
export type SQLiteUpdateReturningAll<T extends AnySQLiteUpdate, TDynamic extends boolean> = SQLiteUpdateWithout<SQLiteUpdateBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['from'], T['_']['table']['$inferSelect'], TDynamic, T['_']['excludedMethods']>, TDynamic, 'returning'>;
|
||||
export type SQLiteUpdateReturning<T extends AnySQLiteUpdate, TDynamic extends boolean, TSelectedFields extends SelectedFields> = SQLiteUpdateWithout<SQLiteUpdateBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['from'], SelectResultFields<TSelectedFields>, TDynamic, T['_']['excludedMethods']>, TDynamic, 'returning'>;
|
||||
export type SQLiteUpdateExecute<T extends AnySQLiteUpdate> = T['_']['returning'] extends undefined ? T['_']['runResult'] : T['_']['returning'][];
|
||||
export type SQLiteUpdatePrepare<T extends AnySQLiteUpdate> = SQLitePreparedQuery<{
|
||||
type: T['_']['resultType'];
|
||||
run: T['_']['runResult'];
|
||||
all: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'> : T['_']['returning'][];
|
||||
get: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'> : T['_']['returning'];
|
||||
values: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'> : any[][];
|
||||
execute: SQLiteUpdateExecute<T>;
|
||||
}>;
|
||||
export type SQLiteUpdateJoinFn<T extends AnySQLiteUpdate> = <TJoinedTable extends SQLiteTable | Subquery | SQLiteViewBase | SQL>(table: TJoinedTable, on: ((updateTable: T['_']['table']['_']['columns'], from: T['_']['from'] extends SQLiteTable ? T['_']['from']['_']['columns'] : T['_']['from'] extends Subquery | SQLiteViewBase ? T['_']['from']['_']['selectedFields'] : never) => SQL | undefined) | SQL | undefined) => T;
|
||||
export type SQLiteUpdateDynamic<T extends AnySQLiteUpdate> = SQLiteUpdate<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['returning']>;
|
||||
export type SQLiteUpdate<TTable extends SQLiteTable = SQLiteTable, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = any, TFrom extends SQLiteTable | Subquery | SQLiteViewBase | SQL | undefined = undefined, TReturning extends Record<string, unknown> | undefined = Record<string, unknown> | undefined> = SQLiteUpdateBase<TTable, TResultType, TRunResult, TFrom, TReturning, true, never>;
|
||||
export type AnySQLiteUpdate = SQLiteUpdateBase<any, any, any, any, any, any, any>;
|
||||
export interface SQLiteUpdateBase<TTable extends SQLiteTable = SQLiteTable, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = unknown, TFrom extends SQLiteTable | Subquery | SQLiteViewBase | SQL | undefined = undefined, TReturning = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends SQLWrapper, QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]> {
|
||||
readonly _: {
|
||||
readonly dialect: 'sqlite';
|
||||
readonly table: TTable;
|
||||
readonly resultType: TResultType;
|
||||
readonly runResult: TRunResult;
|
||||
readonly from: TFrom;
|
||||
readonly returning: TReturning;
|
||||
readonly dynamic: TDynamic;
|
||||
readonly excludedMethods: TExcludedMethods;
|
||||
readonly result: TReturning extends undefined ? TRunResult : TReturning[];
|
||||
};
|
||||
}
|
||||
export declare class SQLiteUpdateBase<TTable extends SQLiteTable = SQLiteTable, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = unknown, TFrom extends SQLiteTable | Subquery | SQLiteViewBase | SQL | undefined = undefined, TReturning = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]> implements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper {
|
||||
private session;
|
||||
private dialect;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(table: TTable, set: UpdateSet, session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[]);
|
||||
from<TFrom extends SQLiteTable | Subquery | SQLiteViewBase | SQL>(source: TFrom): SQLiteUpdateWithJoins<this, TDynamic, TFrom>;
|
||||
private createJoin;
|
||||
leftJoin: SQLiteUpdateJoinFn<this>;
|
||||
rightJoin: SQLiteUpdateJoinFn<this>;
|
||||
innerJoin: SQLiteUpdateJoinFn<this>;
|
||||
fullJoin: SQLiteUpdateJoinFn<this>;
|
||||
/**
|
||||
* Adds a 'where' clause to the query.
|
||||
*
|
||||
* Calling this method will update only those rows that fulfill a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/update}
|
||||
*
|
||||
* @param where the 'where' clause.
|
||||
*
|
||||
* @example
|
||||
* You can use conditional operators and `sql function` to filter the rows to be updated.
|
||||
*
|
||||
* ```ts
|
||||
* // Update all cars with green color
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(eq(cars.color, 'green'));
|
||||
* // or
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(sql`${cars.color} = 'green'`)
|
||||
* ```
|
||||
*
|
||||
* You can logically combine conditional operators with `and()` and `or()` operators:
|
||||
*
|
||||
* ```ts
|
||||
* // Update all BMW cars with a green color
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
||||
*
|
||||
* // Update all cars with the green or blue color
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
||||
* ```
|
||||
*/
|
||||
where(where: SQL | undefined): SQLiteUpdateWithout<this, TDynamic, 'where'>;
|
||||
orderBy(builder: (updateTable: TTable) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>): SQLiteUpdateWithout<this, TDynamic, 'orderBy'>;
|
||||
orderBy(...columns: (SQLiteColumn | SQL | SQL.Aliased)[]): SQLiteUpdateWithout<this, TDynamic, 'orderBy'>;
|
||||
limit(limit: number | Placeholder): SQLiteUpdateWithout<this, TDynamic, 'limit'>;
|
||||
/**
|
||||
* Adds a `returning` clause to the query.
|
||||
*
|
||||
* Calling this method will return the specified fields of the updated rows. If no fields are specified, all fields will be returned.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/update#update-with-returning}
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Update all cars with the green color and return all fields
|
||||
* const updatedCars: Car[] = await db.update(cars)
|
||||
* .set({ color: 'red' })
|
||||
* .where(eq(cars.color, 'green'))
|
||||
* .returning();
|
||||
*
|
||||
* // Update all cars with the green color and return only their id and brand fields
|
||||
* const updatedCarsIdsAndBrands: { id: number, brand: string }[] = await db.update(cars)
|
||||
* .set({ color: 'red' })
|
||||
* .where(eq(cars.color, 'green'))
|
||||
* .returning({ id: cars.id, brand: cars.brand });
|
||||
* ```
|
||||
*/
|
||||
returning(): SQLiteUpdateReturningAll<this, TDynamic>;
|
||||
returning<TSelectedFields extends SelectedFields>(fields: TSelectedFields): SQLiteUpdateReturning<this, TDynamic, TSelectedFields>;
|
||||
toSQL(): Query;
|
||||
prepare(): SQLiteUpdatePrepare<this>;
|
||||
run: ReturnType<this['prepare']>['run'];
|
||||
all: ReturnType<this['prepare']>['all'];
|
||||
get: ReturnType<this['prepare']>['get'];
|
||||
values: ReturnType<this['prepare']>['values'];
|
||||
execute(): Promise<SQLiteUpdateExecute<this>>;
|
||||
$dynamic(): SQLiteUpdateDynamic<this>;
|
||||
}
|
||||
151
node_modules/drizzle-orm/sqlite-core/query-builders/update.d.ts
generated
vendored
Normal file
151
node_modules/drizzle-orm/sqlite-core/query-builders/update.d.ts
generated
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
import type { GetColumnData } from "../../column.js";
|
||||
import { entityKind } from "../../entity.js";
|
||||
import type { SelectResultFields } from "../../query-builders/select.types.js";
|
||||
import { QueryPromise } from "../../query-promise.js";
|
||||
import type { RunnableQuery } from "../../runnable-query.js";
|
||||
import type { Placeholder, Query, SQL, SQLWrapper } from "../../sql/sql.js";
|
||||
import type { SQLiteDialect } from "../dialect.js";
|
||||
import type { SQLitePreparedQuery, SQLiteSession } from "../session.js";
|
||||
import { SQLiteTable } from "../table.js";
|
||||
import { Subquery } from "../../subquery.js";
|
||||
import { type DrizzleTypeError, type UpdateSet, type ValueOrArray } from "../../utils.js";
|
||||
import type { SQLiteColumn } from "../columns/common.js";
|
||||
import { SQLiteViewBase } from "../view-base.js";
|
||||
import type { SelectedFields, SelectedFieldsOrdered, SQLiteSelectJoinConfig } from "./select.types.js";
|
||||
export interface SQLiteUpdateConfig {
|
||||
where?: SQL | undefined;
|
||||
limit?: number | Placeholder;
|
||||
orderBy?: (SQLiteColumn | SQL | SQL.Aliased)[];
|
||||
set: UpdateSet;
|
||||
table: SQLiteTable;
|
||||
from?: SQLiteTable | Subquery | SQLiteViewBase | SQL;
|
||||
joins: SQLiteSelectJoinConfig[];
|
||||
returning?: SelectedFieldsOrdered;
|
||||
withList?: Subquery[];
|
||||
}
|
||||
export type SQLiteUpdateSetSource<TTable extends SQLiteTable> = {
|
||||
[Key in keyof TTable['$inferInsert']]?: GetColumnData<TTable['_']['columns'][Key], 'query'> | SQL | SQLiteColumn | undefined;
|
||||
} & {};
|
||||
export declare class SQLiteUpdateBuilder<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult> {
|
||||
protected table: TTable;
|
||||
protected session: SQLiteSession<any, any, any, any>;
|
||||
protected dialect: SQLiteDialect;
|
||||
private withList?;
|
||||
static readonly [entityKind]: string;
|
||||
readonly _: {
|
||||
readonly table: TTable;
|
||||
};
|
||||
constructor(table: TTable, session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[] | undefined);
|
||||
set(values: SQLiteUpdateSetSource<TTable>): SQLiteUpdateWithout<SQLiteUpdateBase<TTable, TResultType, TRunResult>, false, 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin'>;
|
||||
}
|
||||
export type SQLiteUpdateWithout<T extends AnySQLiteUpdate, TDynamic extends boolean, K extends keyof T & string> = TDynamic extends true ? T : Omit<SQLiteUpdateBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['from'], T['_']['returning'], TDynamic, T['_']['excludedMethods'] | K>, T['_']['excludedMethods'] | K>;
|
||||
export type SQLiteUpdateWithJoins<T extends AnySQLiteUpdate, TDynamic extends boolean, TFrom extends SQLiteTable | Subquery | SQLiteViewBase | SQL> = TDynamic extends true ? T : Omit<SQLiteUpdateBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], TFrom, T['_']['returning'], TDynamic, Exclude<T['_']['excludedMethods'] | 'from', 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin'>>, Exclude<T['_']['excludedMethods'] | 'from', 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin'>>;
|
||||
export type SQLiteUpdateReturningAll<T extends AnySQLiteUpdate, TDynamic extends boolean> = SQLiteUpdateWithout<SQLiteUpdateBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['from'], T['_']['table']['$inferSelect'], TDynamic, T['_']['excludedMethods']>, TDynamic, 'returning'>;
|
||||
export type SQLiteUpdateReturning<T extends AnySQLiteUpdate, TDynamic extends boolean, TSelectedFields extends SelectedFields> = SQLiteUpdateWithout<SQLiteUpdateBase<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['from'], SelectResultFields<TSelectedFields>, TDynamic, T['_']['excludedMethods']>, TDynamic, 'returning'>;
|
||||
export type SQLiteUpdateExecute<T extends AnySQLiteUpdate> = T['_']['returning'] extends undefined ? T['_']['runResult'] : T['_']['returning'][];
|
||||
export type SQLiteUpdatePrepare<T extends AnySQLiteUpdate> = SQLitePreparedQuery<{
|
||||
type: T['_']['resultType'];
|
||||
run: T['_']['runResult'];
|
||||
all: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'> : T['_']['returning'][];
|
||||
get: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'> : T['_']['returning'];
|
||||
values: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'> : any[][];
|
||||
execute: SQLiteUpdateExecute<T>;
|
||||
}>;
|
||||
export type SQLiteUpdateJoinFn<T extends AnySQLiteUpdate> = <TJoinedTable extends SQLiteTable | Subquery | SQLiteViewBase | SQL>(table: TJoinedTable, on: ((updateTable: T['_']['table']['_']['columns'], from: T['_']['from'] extends SQLiteTable ? T['_']['from']['_']['columns'] : T['_']['from'] extends Subquery | SQLiteViewBase ? T['_']['from']['_']['selectedFields'] : never) => SQL | undefined) | SQL | undefined) => T;
|
||||
export type SQLiteUpdateDynamic<T extends AnySQLiteUpdate> = SQLiteUpdate<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['returning']>;
|
||||
export type SQLiteUpdate<TTable extends SQLiteTable = SQLiteTable, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = any, TFrom extends SQLiteTable | Subquery | SQLiteViewBase | SQL | undefined = undefined, TReturning extends Record<string, unknown> | undefined = Record<string, unknown> | undefined> = SQLiteUpdateBase<TTable, TResultType, TRunResult, TFrom, TReturning, true, never>;
|
||||
export type AnySQLiteUpdate = SQLiteUpdateBase<any, any, any, any, any, any, any>;
|
||||
export interface SQLiteUpdateBase<TTable extends SQLiteTable = SQLiteTable, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = unknown, TFrom extends SQLiteTable | Subquery | SQLiteViewBase | SQL | undefined = undefined, TReturning = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends SQLWrapper, QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]> {
|
||||
readonly _: {
|
||||
readonly dialect: 'sqlite';
|
||||
readonly table: TTable;
|
||||
readonly resultType: TResultType;
|
||||
readonly runResult: TRunResult;
|
||||
readonly from: TFrom;
|
||||
readonly returning: TReturning;
|
||||
readonly dynamic: TDynamic;
|
||||
readonly excludedMethods: TExcludedMethods;
|
||||
readonly result: TReturning extends undefined ? TRunResult : TReturning[];
|
||||
};
|
||||
}
|
||||
export declare class SQLiteUpdateBase<TTable extends SQLiteTable = SQLiteTable, TResultType extends 'sync' | 'async' = 'sync' | 'async', TRunResult = unknown, TFrom extends SQLiteTable | Subquery | SQLiteViewBase | SQL | undefined = undefined, TReturning = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]> implements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper {
|
||||
private session;
|
||||
private dialect;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(table: TTable, set: UpdateSet, session: SQLiteSession<any, any, any, any>, dialect: SQLiteDialect, withList?: Subquery[]);
|
||||
from<TFrom extends SQLiteTable | Subquery | SQLiteViewBase | SQL>(source: TFrom): SQLiteUpdateWithJoins<this, TDynamic, TFrom>;
|
||||
private createJoin;
|
||||
leftJoin: SQLiteUpdateJoinFn<this>;
|
||||
rightJoin: SQLiteUpdateJoinFn<this>;
|
||||
innerJoin: SQLiteUpdateJoinFn<this>;
|
||||
fullJoin: SQLiteUpdateJoinFn<this>;
|
||||
/**
|
||||
* Adds a 'where' clause to the query.
|
||||
*
|
||||
* Calling this method will update only those rows that fulfill a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/update}
|
||||
*
|
||||
* @param where the 'where' clause.
|
||||
*
|
||||
* @example
|
||||
* You can use conditional operators and `sql function` to filter the rows to be updated.
|
||||
*
|
||||
* ```ts
|
||||
* // Update all cars with green color
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(eq(cars.color, 'green'));
|
||||
* // or
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(sql`${cars.color} = 'green'`)
|
||||
* ```
|
||||
*
|
||||
* You can logically combine conditional operators with `and()` and `or()` operators:
|
||||
*
|
||||
* ```ts
|
||||
* // Update all BMW cars with a green color
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
||||
*
|
||||
* // Update all cars with the green or blue color
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
||||
* ```
|
||||
*/
|
||||
where(where: SQL | undefined): SQLiteUpdateWithout<this, TDynamic, 'where'>;
|
||||
orderBy(builder: (updateTable: TTable) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>): SQLiteUpdateWithout<this, TDynamic, 'orderBy'>;
|
||||
orderBy(...columns: (SQLiteColumn | SQL | SQL.Aliased)[]): SQLiteUpdateWithout<this, TDynamic, 'orderBy'>;
|
||||
limit(limit: number | Placeholder): SQLiteUpdateWithout<this, TDynamic, 'limit'>;
|
||||
/**
|
||||
* Adds a `returning` clause to the query.
|
||||
*
|
||||
* Calling this method will return the specified fields of the updated rows. If no fields are specified, all fields will be returned.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/update#update-with-returning}
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Update all cars with the green color and return all fields
|
||||
* const updatedCars: Car[] = await db.update(cars)
|
||||
* .set({ color: 'red' })
|
||||
* .where(eq(cars.color, 'green'))
|
||||
* .returning();
|
||||
*
|
||||
* // Update all cars with the green color and return only their id and brand fields
|
||||
* const updatedCarsIdsAndBrands: { id: number, brand: string }[] = await db.update(cars)
|
||||
* .set({ color: 'red' })
|
||||
* .where(eq(cars.color, 'green'))
|
||||
* .returning({ id: cars.id, brand: cars.brand });
|
||||
* ```
|
||||
*/
|
||||
returning(): SQLiteUpdateReturningAll<this, TDynamic>;
|
||||
returning<TSelectedFields extends SelectedFields>(fields: TSelectedFields): SQLiteUpdateReturning<this, TDynamic, TSelectedFields>;
|
||||
toSQL(): Query;
|
||||
prepare(): SQLiteUpdatePrepare<this>;
|
||||
run: ReturnType<this['prepare']>['run'];
|
||||
all: ReturnType<this['prepare']>['all'];
|
||||
get: ReturnType<this['prepare']>['get'];
|
||||
values: ReturnType<this['prepare']>['values'];
|
||||
execute(): Promise<SQLiteUpdateExecute<this>>;
|
||||
$dynamic(): SQLiteUpdateDynamic<this>;
|
||||
}
|
||||
177
node_modules/drizzle-orm/sqlite-core/query-builders/update.js
generated
vendored
Normal file
177
node_modules/drizzle-orm/sqlite-core/query-builders/update.js
generated
vendored
Normal file
@ -0,0 +1,177 @@
|
||||
import { entityKind, is } from "../../entity.js";
|
||||
import { QueryPromise } from "../../query-promise.js";
|
||||
import { SelectionProxyHandler } from "../../selection-proxy.js";
|
||||
import { SQLiteTable } from "../table.js";
|
||||
import { Subquery } from "../../subquery.js";
|
||||
import { Table } from "../../table.js";
|
||||
import {
|
||||
getTableLikeName,
|
||||
mapUpdateSet,
|
||||
orderSelectedFields
|
||||
} from "../../utils.js";
|
||||
import { ViewBaseConfig } from "../../view-common.js";
|
||||
import { SQLiteViewBase } from "../view-base.js";
|
||||
class SQLiteUpdateBuilder {
|
||||
constructor(table, session, dialect, withList) {
|
||||
this.table = table;
|
||||
this.session = session;
|
||||
this.dialect = dialect;
|
||||
this.withList = withList;
|
||||
}
|
||||
static [entityKind] = "SQLiteUpdateBuilder";
|
||||
set(values) {
|
||||
return new SQLiteUpdateBase(
|
||||
this.table,
|
||||
mapUpdateSet(this.table, values),
|
||||
this.session,
|
||||
this.dialect,
|
||||
this.withList
|
||||
);
|
||||
}
|
||||
}
|
||||
class SQLiteUpdateBase extends QueryPromise {
|
||||
constructor(table, set, session, dialect, withList) {
|
||||
super();
|
||||
this.session = session;
|
||||
this.dialect = dialect;
|
||||
this.config = { set, table, withList, joins: [] };
|
||||
}
|
||||
static [entityKind] = "SQLiteUpdate";
|
||||
/** @internal */
|
||||
config;
|
||||
from(source) {
|
||||
this.config.from = source;
|
||||
return this;
|
||||
}
|
||||
createJoin(joinType) {
|
||||
return (table, on) => {
|
||||
const tableName = getTableLikeName(table);
|
||||
if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) {
|
||||
throw new Error(`Alias "${tableName}" is already used in this query`);
|
||||
}
|
||||
if (typeof on === "function") {
|
||||
const from = this.config.from ? is(table, SQLiteTable) ? table[Table.Symbol.Columns] : is(table, Subquery) ? table._.selectedFields : is(table, SQLiteViewBase) ? table[ViewBaseConfig].selectedFields : void 0 : void 0;
|
||||
on = on(
|
||||
new Proxy(
|
||||
this.config.table[Table.Symbol.Columns],
|
||||
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
||||
),
|
||||
from && new Proxy(
|
||||
from,
|
||||
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
}
|
||||
this.config.joins.push({ on, table, joinType, alias: tableName });
|
||||
return this;
|
||||
};
|
||||
}
|
||||
leftJoin = this.createJoin("left");
|
||||
rightJoin = this.createJoin("right");
|
||||
innerJoin = this.createJoin("inner");
|
||||
fullJoin = this.createJoin("full");
|
||||
/**
|
||||
* Adds a 'where' clause to the query.
|
||||
*
|
||||
* Calling this method will update only those rows that fulfill a specified condition.
|
||||
*
|
||||
* See docs: {@link https://orm.drizzle.team/docs/update}
|
||||
*
|
||||
* @param where the 'where' clause.
|
||||
*
|
||||
* @example
|
||||
* You can use conditional operators and `sql function` to filter the rows to be updated.
|
||||
*
|
||||
* ```ts
|
||||
* // Update all cars with green color
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(eq(cars.color, 'green'));
|
||||
* // or
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(sql`${cars.color} = 'green'`)
|
||||
* ```
|
||||
*
|
||||
* You can logically combine conditional operators with `and()` and `or()` operators:
|
||||
*
|
||||
* ```ts
|
||||
* // Update all BMW cars with a green color
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
||||
*
|
||||
* // Update all cars with the green or blue color
|
||||
* db.update(cars).set({ color: 'red' })
|
||||
* .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
||||
* ```
|
||||
*/
|
||||
where(where) {
|
||||
this.config.where = where;
|
||||
return this;
|
||||
}
|
||||
orderBy(...columns) {
|
||||
if (typeof columns[0] === "function") {
|
||||
const orderBy = columns[0](
|
||||
new Proxy(
|
||||
this.config.table[Table.Symbol.Columns],
|
||||
new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
||||
)
|
||||
);
|
||||
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
||||
this.config.orderBy = orderByArray;
|
||||
} else {
|
||||
const orderByArray = columns;
|
||||
this.config.orderBy = orderByArray;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
limit(limit) {
|
||||
this.config.limit = limit;
|
||||
return this;
|
||||
}
|
||||
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
||||
this.config.returning = orderSelectedFields(fields);
|
||||
return this;
|
||||
}
|
||||
/** @internal */
|
||||
getSQL() {
|
||||
return this.dialect.buildUpdateQuery(this.config);
|
||||
}
|
||||
toSQL() {
|
||||
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
||||
return rest;
|
||||
}
|
||||
/** @internal */
|
||||
_prepare(isOneTimeQuery = true) {
|
||||
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
||||
this.dialect.sqlToQuery(this.getSQL()),
|
||||
this.config.returning,
|
||||
this.config.returning ? "all" : "run",
|
||||
true
|
||||
);
|
||||
}
|
||||
prepare() {
|
||||
return this._prepare(false);
|
||||
}
|
||||
run = (placeholderValues) => {
|
||||
return this._prepare().run(placeholderValues);
|
||||
};
|
||||
all = (placeholderValues) => {
|
||||
return this._prepare().all(placeholderValues);
|
||||
};
|
||||
get = (placeholderValues) => {
|
||||
return this._prepare().get(placeholderValues);
|
||||
};
|
||||
values = (placeholderValues) => {
|
||||
return this._prepare().values(placeholderValues);
|
||||
};
|
||||
async execute() {
|
||||
return this.config.returning ? this.all() : this.run();
|
||||
}
|
||||
$dynamic() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
export {
|
||||
SQLiteUpdateBase,
|
||||
SQLiteUpdateBuilder
|
||||
};
|
||||
//# sourceMappingURL=update.js.map
|
||||
1
node_modules/drizzle-orm/sqlite-core/query-builders/update.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/sqlite-core/query-builders/update.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user