drizzle-orm 1.0.0-beta.1-34ee105 → 1.0.0-beta.1-69a2ca0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/column-builder.cjs.map +1 -1
- package/column-builder.d.cts +1 -1
- package/column-builder.d.ts +1 -1
- package/column-builder.js.map +1 -1
- package/mysql-core/db.cjs.map +1 -1
- package/mysql-core/db.js.map +1 -1
- package/mysql-core/dialect.cjs +3 -3
- package/mysql-core/dialect.cjs.map +1 -1
- package/mysql-core/dialect.d.cts +2 -2
- package/mysql-core/dialect.d.ts +2 -2
- package/mysql-core/dialect.js +3 -3
- package/mysql-core/dialect.js.map +1 -1
- package/mysql-core/query-builders/query.cjs.map +1 -1
- package/mysql-core/query-builders/query.d.cts +3 -2
- package/mysql-core/query-builders/query.d.ts +3 -2
- package/mysql-core/query-builders/query.js.map +1 -1
- package/package.json +13 -1
- package/relations.cjs +6 -1
- package/relations.cjs.map +1 -1
- package/relations.d.cts +6 -5
- package/relations.d.ts +6 -5
- package/relations.js +6 -1
- package/relations.js.map +1 -1
- package/singlestore/driver.cjs +9 -5
- package/singlestore/driver.cjs.map +1 -1
- package/singlestore/driver.d.cts +9 -8
- package/singlestore/driver.d.ts +9 -8
- package/singlestore/driver.js +9 -5
- package/singlestore/driver.js.map +1 -1
- package/singlestore/migrator.cjs.map +1 -1
- package/singlestore/migrator.d.cts +2 -1
- package/singlestore/migrator.d.ts +2 -1
- package/singlestore/migrator.js.map +1 -1
- package/singlestore/session.cjs +32 -2
- package/singlestore/session.cjs.map +1 -1
- package/singlestore/session.d.cts +12 -7
- package/singlestore/session.d.ts +12 -7
- package/singlestore/session.js +32 -2
- package/singlestore/session.js.map +1 -1
- package/singlestore-core/columns/float.cjs +4 -0
- package/singlestore-core/columns/float.cjs.map +1 -1
- package/singlestore-core/columns/float.d.cts +1 -0
- package/singlestore-core/columns/float.d.ts +1 -0
- package/singlestore-core/columns/float.js +4 -0
- package/singlestore-core/columns/float.js.map +1 -1
- package/singlestore-core/columns/vector.cjs +72 -3
- package/singlestore-core/columns/vector.cjs.map +1 -1
- package/singlestore-core/columns/vector.d.cts +32 -9
- package/singlestore-core/columns/vector.d.ts +32 -9
- package/singlestore-core/columns/vector.js +70 -3
- package/singlestore-core/columns/vector.js.map +1 -1
- package/singlestore-core/columns/year.cjs +4 -0
- package/singlestore-core/columns/year.cjs.map +1 -1
- package/singlestore-core/columns/year.d.cts +1 -0
- package/singlestore-core/columns/year.d.ts +1 -0
- package/singlestore-core/columns/year.js +4 -0
- package/singlestore-core/columns/year.js.map +1 -1
- package/singlestore-core/db.cjs +16 -5
- package/singlestore-core/db.cjs.map +1 -1
- package/singlestore-core/db.d.cts +10 -6
- package/singlestore-core/db.d.ts +10 -6
- package/singlestore-core/db.js +16 -5
- package/singlestore-core/db.js.map +1 -1
- package/singlestore-core/dialect.cjs +186 -2
- package/singlestore-core/dialect.cjs.map +1 -1
- package/singlestore-core/dialect.d.cts +24 -1
- package/singlestore-core/dialect.d.ts +24 -1
- package/singlestore-core/dialect.js +195 -4
- package/singlestore-core/dialect.js.map +1 -1
- package/singlestore-core/query-builders/_query.cjs +136 -0
- package/singlestore-core/query-builders/_query.cjs.map +1 -0
- package/singlestore-core/query-builders/_query.d.cts +42 -0
- package/singlestore-core/query-builders/_query.d.ts +42 -0
- package/singlestore-core/query-builders/_query.js +101 -0
- package/singlestore-core/query-builders/_query.js.map +1 -0
- package/singlestore-core/query-builders/query.cjs +12 -32
- package/singlestore-core/query-builders/query.cjs.map +1 -1
- package/singlestore-core/query-builders/query.d.cts +8 -11
- package/singlestore-core/query-builders/query.d.ts +8 -11
- package/singlestore-core/query-builders/query.js +14 -22
- package/singlestore-core/query-builders/query.js.map +1 -1
- package/singlestore-core/session.cjs +3 -2
- package/singlestore-core/session.cjs.map +1 -1
- package/singlestore-core/session.d.cts +8 -5
- package/singlestore-core/session.d.ts +8 -5
- package/singlestore-core/session.js +3 -2
- package/singlestore-core/session.js.map +1 -1
- package/singlestore-proxy/driver.cjs +3 -2
- package/singlestore-proxy/driver.cjs.map +1 -1
- package/singlestore-proxy/driver.d.cts +3 -2
- package/singlestore-proxy/driver.d.ts +3 -2
- package/singlestore-proxy/driver.js +3 -2
- package/singlestore-proxy/driver.js.map +1 -1
- package/singlestore-proxy/migrator.cjs.map +1 -1
- package/singlestore-proxy/migrator.d.cts +2 -1
- package/singlestore-proxy/migrator.d.ts +2 -1
- package/singlestore-proxy/migrator.js.map +1 -1
- package/singlestore-proxy/session.cjs +26 -2
- package/singlestore-proxy/session.cjs.map +1 -1
- package/singlestore-proxy/session.d.cts +12 -7
- package/singlestore-proxy/session.d.ts +12 -7
- package/singlestore-proxy/session.js +26 -2
- package/singlestore-proxy/session.js.map +1 -1
- package/version.cjs +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var query_exports = {};
|
|
30
20
|
__export(query_exports, {
|
|
@@ -32,69 +22,61 @@ __export(query_exports, {
|
|
|
32
22
|
SingleStoreRelationalQuery: () => SingleStoreRelationalQuery
|
|
33
23
|
});
|
|
34
24
|
module.exports = __toCommonJS(query_exports);
|
|
35
|
-
var V1 = __toESM(require("../../_relations.cjs"), 1);
|
|
36
25
|
var import_entity = require("../../entity.cjs");
|
|
37
26
|
var import_query_promise = require("../../query-promise.cjs");
|
|
27
|
+
var import_relations = require("../../relations.cjs");
|
|
38
28
|
class RelationalQueryBuilder {
|
|
39
|
-
constructor(
|
|
40
|
-
this.fullSchema = fullSchema;
|
|
29
|
+
constructor(schema, table, tableConfig, dialect, session) {
|
|
41
30
|
this.schema = schema;
|
|
42
|
-
this.tableNamesMap = tableNamesMap;
|
|
43
31
|
this.table = table;
|
|
44
32
|
this.tableConfig = tableConfig;
|
|
45
33
|
this.dialect = dialect;
|
|
46
34
|
this.session = session;
|
|
47
35
|
}
|
|
48
|
-
static [import_entity.entityKind] = "
|
|
36
|
+
static [import_entity.entityKind] = "SingleStoreRelationalQueryBuilderV2";
|
|
49
37
|
findMany(config) {
|
|
50
38
|
return new SingleStoreRelationalQuery(
|
|
51
|
-
this.fullSchema,
|
|
52
39
|
this.schema,
|
|
53
|
-
this.tableNamesMap,
|
|
54
40
|
this.table,
|
|
55
41
|
this.tableConfig,
|
|
56
42
|
this.dialect,
|
|
57
43
|
this.session,
|
|
58
|
-
config
|
|
44
|
+
config ?? true,
|
|
59
45
|
"many"
|
|
60
46
|
);
|
|
61
47
|
}
|
|
62
48
|
findFirst(config) {
|
|
63
49
|
return new SingleStoreRelationalQuery(
|
|
64
|
-
this.fullSchema,
|
|
65
50
|
this.schema,
|
|
66
|
-
this.tableNamesMap,
|
|
67
51
|
this.table,
|
|
68
52
|
this.tableConfig,
|
|
69
53
|
this.dialect,
|
|
70
54
|
this.session,
|
|
71
|
-
config
|
|
55
|
+
config ?? true,
|
|
72
56
|
"first"
|
|
73
57
|
);
|
|
74
58
|
}
|
|
75
59
|
}
|
|
76
60
|
class SingleStoreRelationalQuery extends import_query_promise.QueryPromise {
|
|
77
|
-
constructor(
|
|
61
|
+
constructor(schema, table, tableConfig, dialect, session, config, mode) {
|
|
78
62
|
super();
|
|
79
|
-
this.fullSchema = fullSchema;
|
|
80
63
|
this.schema = schema;
|
|
81
|
-
this.tableNamesMap = tableNamesMap;
|
|
82
64
|
this.table = table;
|
|
83
65
|
this.tableConfig = tableConfig;
|
|
84
66
|
this.dialect = dialect;
|
|
85
67
|
this.session = session;
|
|
86
68
|
this.config = config;
|
|
87
|
-
this.
|
|
69
|
+
this.mode = mode;
|
|
88
70
|
}
|
|
89
|
-
static [import_entity.entityKind] = "
|
|
71
|
+
static [import_entity.entityKind] = "SingleStoreRelationalQueryV2";
|
|
90
72
|
prepare() {
|
|
91
73
|
const { query, builtQuery } = this._toSQL();
|
|
92
|
-
return this.session.
|
|
74
|
+
return this.session.prepareRelationalQuery(
|
|
93
75
|
builtQuery,
|
|
94
76
|
void 0,
|
|
95
77
|
(rawRows) => {
|
|
96
|
-
const rows = rawRows.map((row) =>
|
|
97
|
-
if (this.
|
|
78
|
+
const rows = rawRows.map((row) => (0, import_relations.mapRelationalRow)(row, query.selection, void 0, void 0, true));
|
|
79
|
+
if (this.mode === "first") {
|
|
98
80
|
return rows[0];
|
|
99
81
|
}
|
|
100
82
|
return rows;
|
|
@@ -103,13 +85,11 @@ class SingleStoreRelationalQuery extends import_query_promise.QueryPromise {
|
|
|
103
85
|
}
|
|
104
86
|
_getQuery() {
|
|
105
87
|
return this.dialect.buildRelationalQuery({
|
|
106
|
-
fullSchema: this.fullSchema,
|
|
107
88
|
schema: this.schema,
|
|
108
|
-
tableNamesMap: this.tableNamesMap,
|
|
109
89
|
table: this.table,
|
|
110
90
|
tableConfig: this.tableConfig,
|
|
111
91
|
queryConfig: this.config,
|
|
112
|
-
|
|
92
|
+
mode: this.mode
|
|
113
93
|
});
|
|
114
94
|
}
|
|
115
95
|
_toSQL() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/singlestore-core/query-builders/query.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/singlestore-core/query-builders/query.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport {\n\ttype BuildQueryResult,\n\ttype BuildRelationalQueryResult,\n\ttype DBQueryConfig,\n\tmapRelationalRow,\n\ttype TableRelationalConfig,\n\ttype TablesRelationalConfig,\n} from '~/relations.ts';\nimport type { Query, QueryWithTypings, SQL } from '~/sql/sql.ts';\nimport type { KnownKeysOnly } from '~/utils.ts';\nimport type { SingleStoreDialect } from '../dialect.ts';\nimport type {\n\tPreparedQueryHKTBase,\n\tPreparedQueryKind,\n\tSingleStorePreparedQueryConfig,\n\tSingleStoreSession,\n} from '../session.ts';\nimport type { SingleStoreTable } from '../table.ts';\nimport type { SingleStoreView } from '../view.ts';\n\nexport class RelationalQueryBuilder<\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTSchema extends TablesRelationalConfig,\n\tTFields extends TableRelationalConfig,\n> {\n\tstatic readonly [entityKind]: string = 'SingleStoreRelationalQueryBuilderV2';\n\n\tconstructor(\n\t\tprivate schema: TSchema,\n\t\tprivate table: SingleStoreTable | SingleStoreView,\n\t\tprivate tableConfig: TableRelationalConfig,\n\t\tprivate dialect: SingleStoreDialect,\n\t\tprivate session: SingleStoreSession,\n\t) {}\n\n\tfindMany<TConfig extends DBQueryConfig<'many', TSchema, TFields>>(\n\t\tconfig?: KnownKeysOnly<TConfig, DBQueryConfig<'many', TSchema, TFields>>,\n\t): SingleStoreRelationalQuery<TPreparedQueryHKT, BuildQueryResult<TSchema, TFields, TConfig>[]> {\n\t\treturn new SingleStoreRelationalQuery(\n\t\t\tthis.schema,\n\t\t\tthis.table,\n\t\t\tthis.tableConfig,\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tconfig as DBQueryConfig<'many'> | undefined ?? true,\n\t\t\t'many',\n\t\t);\n\t}\n\n\tfindFirst<TSelection extends DBQueryConfig<'one', TSchema, TFields>>(\n\t\tconfig?: KnownKeysOnly<TSelection, DBQueryConfig<'one', TSchema, TFields>>,\n\t): SingleStoreRelationalQuery<TPreparedQueryHKT, BuildQueryResult<TSchema, TFields, TSelection> | undefined> {\n\t\treturn new SingleStoreRelationalQuery(\n\t\t\tthis.schema,\n\t\t\tthis.table,\n\t\t\tthis.tableConfig,\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tconfig as DBQueryConfig<'one'> | undefined ?? true,\n\t\t\t'first',\n\t\t);\n\t}\n}\n\nexport class SingleStoreRelationalQuery<\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTResult,\n> extends QueryPromise<TResult> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreRelationalQueryV2';\n\n\tdeclare protected $brand: 'SingleStoreRelationalQuery';\n\n\tconstructor(\n\t\tprivate schema: TablesRelationalConfig,\n\t\tprivate table: SingleStoreTable | SingleStoreView,\n\t\tprivate tableConfig: TableRelationalConfig,\n\t\tprivate dialect: SingleStoreDialect,\n\t\tprivate session: SingleStoreSession,\n\t\tprivate config: DBQueryConfig<'many' | 'one'> | true,\n\t\tprivate mode: 'many' | 'first',\n\t) {\n\t\tsuper();\n\t}\n\n\tprepare() {\n\t\tconst { query, builtQuery } = this._toSQL();\n\t\treturn this.session.prepareRelationalQuery(\n\t\t\tbuiltQuery,\n\t\t\tundefined,\n\t\t\t(rawRows) => {\n\t\t\t\tconst rows = rawRows.map((row) => mapRelationalRow(row, query.selection, undefined, undefined, true));\n\t\t\t\tif (this.mode === 'first') {\n\t\t\t\t\treturn rows[0] as TResult;\n\t\t\t\t}\n\t\t\t\treturn rows as TResult;\n\t\t\t},\n\t\t) as PreparedQueryKind<TPreparedQueryHKT, SingleStorePreparedQueryConfig & { execute: TResult }, true>;\n\t}\n\n\tprivate _getQuery() {\n\t\treturn this.dialect.buildRelationalQuery({\n\t\t\tschema: this.schema,\n\t\t\ttable: this.table,\n\t\t\ttableConfig: this.tableConfig,\n\t\t\tqueryConfig: this.config,\n\t\t\tmode: this.mode,\n\t\t});\n\t}\n\n\tprivate _toSQL(): { query: BuildRelationalQueryResult; builtQuery: QueryWithTypings } {\n\t\tconst query = this._getQuery();\n\n\t\tconst builtQuery = this.dialect.sqlToQuery(query.sql);\n\n\t\treturn { builtQuery, query };\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this._getQuery().sql;\n\t}\n\n\ttoSQL(): Query {\n\t\treturn this._toSQL().builtQuery;\n\t}\n\n\toverride execute(): Promise<TResult> {\n\t\treturn this.prepare().execute();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAC3B,2BAA6B;AAC7B,uBAOO;AAaA,MAAM,uBAIX;AAAA,EAGD,YACS,QACA,OACA,aACA,SACA,SACP;AALO;AACA;AACA;AACA;AACA;AAAA,EACN;AAAA,EARH,QAAiB,wBAAU,IAAY;AAAA,EAUvC,SACC,QAC+F;AAC/F,WAAO,IAAI;AAAA,MACV,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,UAA+C;AAAA,MAC/C;AAAA,IACD;AAAA,EACD;AAAA,EAEA,UACC,QAC4G;AAC5G,WAAO,IAAI;AAAA,MACV,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,UAA8C;AAAA,MAC9C;AAAA,IACD;AAAA,EACD;AACD;AAEO,MAAM,mCAGH,kCAAsB;AAAA,EAK/B,YACS,QACA,OACA,aACA,SACA,SACA,QACA,MACP;AACD,UAAM;AARE;AACA;AACA;AACA;AACA;AACA;AACA;AAAA,EAGT;AAAA,EAdA,QAA0B,wBAAU,IAAY;AAAA,EAgBhD,UAAU;AACT,UAAM,EAAE,OAAO,WAAW,IAAI,KAAK,OAAO;AAC1C,WAAO,KAAK,QAAQ;AAAA,MACnB;AAAA,MACA;AAAA,MACA,CAAC,YAAY;AACZ,cAAM,OAAO,QAAQ,IAAI,CAAC,YAAQ,mCAAiB,KAAK,MAAM,WAAW,QAAW,QAAW,IAAI,CAAC;AACpG,YAAI,KAAK,SAAS,SAAS;AAC1B,iBAAO,KAAK,CAAC;AAAA,QACd;AACA,eAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAAA,EAEQ,YAAY;AACnB,WAAO,KAAK,QAAQ,qBAAqB;AAAA,MACxC,QAAQ,KAAK;AAAA,MACb,OAAO,KAAK;AAAA,MACZ,aAAa,KAAK;AAAA,MAClB,aAAa,KAAK;AAAA,MAClB,MAAM,KAAK;AAAA,IACZ,CAAC;AAAA,EACF;AAAA,EAEQ,SAA8E;AACrF,UAAM,QAAQ,KAAK,UAAU;AAE7B,UAAM,aAAa,KAAK,QAAQ,WAAW,MAAM,GAAG;AAEpD,WAAO,EAAE,YAAY,MAAM;AAAA,EAC5B;AAAA;AAAA,EAGA,SAAc;AACb,WAAO,KAAK,UAAU,EAAE;AAAA,EACzB;AAAA,EAEA,QAAe;AACd,WAAO,KAAK,OAAO,EAAE;AAAA,EACtB;AAAA,EAES,UAA4B;AACpC,WAAO,KAAK,QAAQ,EAAE,QAAQ;AAAA,EAC/B;AACD;","names":[]}
|
|
@@ -1,37 +1,34 @@
|
|
|
1
|
-
import * as V1 from "../../_relations.cjs";
|
|
2
1
|
import { entityKind } from "../../entity.cjs";
|
|
3
2
|
import { QueryPromise } from "../../query-promise.cjs";
|
|
3
|
+
import { type BuildQueryResult, type DBQueryConfig, type TableRelationalConfig, type TablesRelationalConfig } from "../../relations.cjs";
|
|
4
4
|
import type { Query } from "../../sql/sql.cjs";
|
|
5
5
|
import type { KnownKeysOnly } from "../../utils.cjs";
|
|
6
6
|
import type { SingleStoreDialect } from "../dialect.cjs";
|
|
7
7
|
import type { PreparedQueryHKTBase, PreparedQueryKind, SingleStorePreparedQueryConfig, SingleStoreSession } from "../session.cjs";
|
|
8
8
|
import type { SingleStoreTable } from "../table.cjs";
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
import type { SingleStoreView } from "../view.cjs";
|
|
10
|
+
export declare class RelationalQueryBuilder<TPreparedQueryHKT extends PreparedQueryHKTBase, TSchema extends TablesRelationalConfig, TFields extends TableRelationalConfig> {
|
|
11
11
|
private schema;
|
|
12
|
-
private tableNamesMap;
|
|
13
12
|
private table;
|
|
14
13
|
private tableConfig;
|
|
15
14
|
private dialect;
|
|
16
15
|
private session;
|
|
17
16
|
static readonly [entityKind]: string;
|
|
18
|
-
constructor(
|
|
19
|
-
findMany<TConfig extends
|
|
20
|
-
findFirst<TSelection extends
|
|
17
|
+
constructor(schema: TSchema, table: SingleStoreTable | SingleStoreView, tableConfig: TableRelationalConfig, dialect: SingleStoreDialect, session: SingleStoreSession);
|
|
18
|
+
findMany<TConfig extends DBQueryConfig<'many', TSchema, TFields>>(config?: KnownKeysOnly<TConfig, DBQueryConfig<'many', TSchema, TFields>>): SingleStoreRelationalQuery<TPreparedQueryHKT, BuildQueryResult<TSchema, TFields, TConfig>[]>;
|
|
19
|
+
findFirst<TSelection extends DBQueryConfig<'one', TSchema, TFields>>(config?: KnownKeysOnly<TSelection, DBQueryConfig<'one', TSchema, TFields>>): SingleStoreRelationalQuery<TPreparedQueryHKT, BuildQueryResult<TSchema, TFields, TSelection> | undefined>;
|
|
21
20
|
}
|
|
22
21
|
export declare class SingleStoreRelationalQuery<TPreparedQueryHKT extends PreparedQueryHKTBase, TResult> extends QueryPromise<TResult> {
|
|
23
|
-
private fullSchema;
|
|
24
22
|
private schema;
|
|
25
|
-
private tableNamesMap;
|
|
26
23
|
private table;
|
|
27
24
|
private tableConfig;
|
|
28
25
|
private dialect;
|
|
29
26
|
private session;
|
|
30
27
|
private config;
|
|
31
|
-
private
|
|
28
|
+
private mode;
|
|
32
29
|
static readonly [entityKind]: string;
|
|
33
30
|
protected $brand: 'SingleStoreRelationalQuery';
|
|
34
|
-
constructor(
|
|
31
|
+
constructor(schema: TablesRelationalConfig, table: SingleStoreTable | SingleStoreView, tableConfig: TableRelationalConfig, dialect: SingleStoreDialect, session: SingleStoreSession, config: DBQueryConfig<'many' | 'one'> | true, mode: 'many' | 'first');
|
|
35
32
|
prepare(): PreparedQueryKind<TPreparedQueryHKT, SingleStorePreparedQueryConfig & {
|
|
36
33
|
execute: TResult;
|
|
37
34
|
}, true>;
|
|
@@ -1,37 +1,34 @@
|
|
|
1
|
-
import * as V1 from "../../_relations.js";
|
|
2
1
|
import { entityKind } from "../../entity.js";
|
|
3
2
|
import { QueryPromise } from "../../query-promise.js";
|
|
3
|
+
import { type BuildQueryResult, type DBQueryConfig, type TableRelationalConfig, type TablesRelationalConfig } from "../../relations.js";
|
|
4
4
|
import type { Query } from "../../sql/sql.js";
|
|
5
5
|
import type { KnownKeysOnly } from "../../utils.js";
|
|
6
6
|
import type { SingleStoreDialect } from "../dialect.js";
|
|
7
7
|
import type { PreparedQueryHKTBase, PreparedQueryKind, SingleStorePreparedQueryConfig, SingleStoreSession } from "../session.js";
|
|
8
8
|
import type { SingleStoreTable } from "../table.js";
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
import type { SingleStoreView } from "../view.js";
|
|
10
|
+
export declare class RelationalQueryBuilder<TPreparedQueryHKT extends PreparedQueryHKTBase, TSchema extends TablesRelationalConfig, TFields extends TableRelationalConfig> {
|
|
11
11
|
private schema;
|
|
12
|
-
private tableNamesMap;
|
|
13
12
|
private table;
|
|
14
13
|
private tableConfig;
|
|
15
14
|
private dialect;
|
|
16
15
|
private session;
|
|
17
16
|
static readonly [entityKind]: string;
|
|
18
|
-
constructor(
|
|
19
|
-
findMany<TConfig extends
|
|
20
|
-
findFirst<TSelection extends
|
|
17
|
+
constructor(schema: TSchema, table: SingleStoreTable | SingleStoreView, tableConfig: TableRelationalConfig, dialect: SingleStoreDialect, session: SingleStoreSession);
|
|
18
|
+
findMany<TConfig extends DBQueryConfig<'many', TSchema, TFields>>(config?: KnownKeysOnly<TConfig, DBQueryConfig<'many', TSchema, TFields>>): SingleStoreRelationalQuery<TPreparedQueryHKT, BuildQueryResult<TSchema, TFields, TConfig>[]>;
|
|
19
|
+
findFirst<TSelection extends DBQueryConfig<'one', TSchema, TFields>>(config?: KnownKeysOnly<TSelection, DBQueryConfig<'one', TSchema, TFields>>): SingleStoreRelationalQuery<TPreparedQueryHKT, BuildQueryResult<TSchema, TFields, TSelection> | undefined>;
|
|
21
20
|
}
|
|
22
21
|
export declare class SingleStoreRelationalQuery<TPreparedQueryHKT extends PreparedQueryHKTBase, TResult> extends QueryPromise<TResult> {
|
|
23
|
-
private fullSchema;
|
|
24
22
|
private schema;
|
|
25
|
-
private tableNamesMap;
|
|
26
23
|
private table;
|
|
27
24
|
private tableConfig;
|
|
28
25
|
private dialect;
|
|
29
26
|
private session;
|
|
30
27
|
private config;
|
|
31
|
-
private
|
|
28
|
+
private mode;
|
|
32
29
|
static readonly [entityKind]: string;
|
|
33
30
|
protected $brand: 'SingleStoreRelationalQuery';
|
|
34
|
-
constructor(
|
|
31
|
+
constructor(schema: TablesRelationalConfig, table: SingleStoreTable | SingleStoreView, tableConfig: TableRelationalConfig, dialect: SingleStoreDialect, session: SingleStoreSession, config: DBQueryConfig<'many' | 'one'> | true, mode: 'many' | 'first');
|
|
35
32
|
prepare(): PreparedQueryKind<TPreparedQueryHKT, SingleStorePreparedQueryConfig & {
|
|
36
33
|
execute: TResult;
|
|
37
34
|
}, true>;
|
|
@@ -1,66 +1,60 @@
|
|
|
1
|
-
import * as V1 from "../../_relations.js";
|
|
2
1
|
import { entityKind } from "../../entity.js";
|
|
3
2
|
import { QueryPromise } from "../../query-promise.js";
|
|
3
|
+
import {
|
|
4
|
+
mapRelationalRow
|
|
5
|
+
} from "../../relations.js";
|
|
4
6
|
class RelationalQueryBuilder {
|
|
5
|
-
constructor(
|
|
6
|
-
this.fullSchema = fullSchema;
|
|
7
|
+
constructor(schema, table, tableConfig, dialect, session) {
|
|
7
8
|
this.schema = schema;
|
|
8
|
-
this.tableNamesMap = tableNamesMap;
|
|
9
9
|
this.table = table;
|
|
10
10
|
this.tableConfig = tableConfig;
|
|
11
11
|
this.dialect = dialect;
|
|
12
12
|
this.session = session;
|
|
13
13
|
}
|
|
14
|
-
static [entityKind] = "
|
|
14
|
+
static [entityKind] = "SingleStoreRelationalQueryBuilderV2";
|
|
15
15
|
findMany(config) {
|
|
16
16
|
return new SingleStoreRelationalQuery(
|
|
17
|
-
this.fullSchema,
|
|
18
17
|
this.schema,
|
|
19
|
-
this.tableNamesMap,
|
|
20
18
|
this.table,
|
|
21
19
|
this.tableConfig,
|
|
22
20
|
this.dialect,
|
|
23
21
|
this.session,
|
|
24
|
-
config
|
|
22
|
+
config ?? true,
|
|
25
23
|
"many"
|
|
26
24
|
);
|
|
27
25
|
}
|
|
28
26
|
findFirst(config) {
|
|
29
27
|
return new SingleStoreRelationalQuery(
|
|
30
|
-
this.fullSchema,
|
|
31
28
|
this.schema,
|
|
32
|
-
this.tableNamesMap,
|
|
33
29
|
this.table,
|
|
34
30
|
this.tableConfig,
|
|
35
31
|
this.dialect,
|
|
36
32
|
this.session,
|
|
37
|
-
config
|
|
33
|
+
config ?? true,
|
|
38
34
|
"first"
|
|
39
35
|
);
|
|
40
36
|
}
|
|
41
37
|
}
|
|
42
38
|
class SingleStoreRelationalQuery extends QueryPromise {
|
|
43
|
-
constructor(
|
|
39
|
+
constructor(schema, table, tableConfig, dialect, session, config, mode) {
|
|
44
40
|
super();
|
|
45
|
-
this.fullSchema = fullSchema;
|
|
46
41
|
this.schema = schema;
|
|
47
|
-
this.tableNamesMap = tableNamesMap;
|
|
48
42
|
this.table = table;
|
|
49
43
|
this.tableConfig = tableConfig;
|
|
50
44
|
this.dialect = dialect;
|
|
51
45
|
this.session = session;
|
|
52
46
|
this.config = config;
|
|
53
|
-
this.
|
|
47
|
+
this.mode = mode;
|
|
54
48
|
}
|
|
55
|
-
static [entityKind] = "
|
|
49
|
+
static [entityKind] = "SingleStoreRelationalQueryV2";
|
|
56
50
|
prepare() {
|
|
57
51
|
const { query, builtQuery } = this._toSQL();
|
|
58
|
-
return this.session.
|
|
52
|
+
return this.session.prepareRelationalQuery(
|
|
59
53
|
builtQuery,
|
|
60
54
|
void 0,
|
|
61
55
|
(rawRows) => {
|
|
62
|
-
const rows = rawRows.map((row) =>
|
|
63
|
-
if (this.
|
|
56
|
+
const rows = rawRows.map((row) => mapRelationalRow(row, query.selection, void 0, void 0, true));
|
|
57
|
+
if (this.mode === "first") {
|
|
64
58
|
return rows[0];
|
|
65
59
|
}
|
|
66
60
|
return rows;
|
|
@@ -69,13 +63,11 @@ class SingleStoreRelationalQuery extends QueryPromise {
|
|
|
69
63
|
}
|
|
70
64
|
_getQuery() {
|
|
71
65
|
return this.dialect.buildRelationalQuery({
|
|
72
|
-
fullSchema: this.fullSchema,
|
|
73
66
|
schema: this.schema,
|
|
74
|
-
tableNamesMap: this.tableNamesMap,
|
|
75
67
|
table: this.table,
|
|
76
68
|
tableConfig: this.tableConfig,
|
|
77
69
|
queryConfig: this.config,
|
|
78
|
-
|
|
70
|
+
mode: this.mode
|
|
79
71
|
});
|
|
80
72
|
}
|
|
81
73
|
_toSQL() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/singlestore-core/query-builders/query.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/singlestore-core/query-builders/query.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport {\n\ttype BuildQueryResult,\n\ttype BuildRelationalQueryResult,\n\ttype DBQueryConfig,\n\tmapRelationalRow,\n\ttype TableRelationalConfig,\n\ttype TablesRelationalConfig,\n} from '~/relations.ts';\nimport type { Query, QueryWithTypings, SQL } from '~/sql/sql.ts';\nimport type { KnownKeysOnly } from '~/utils.ts';\nimport type { SingleStoreDialect } from '../dialect.ts';\nimport type {\n\tPreparedQueryHKTBase,\n\tPreparedQueryKind,\n\tSingleStorePreparedQueryConfig,\n\tSingleStoreSession,\n} from '../session.ts';\nimport type { SingleStoreTable } from '../table.ts';\nimport type { SingleStoreView } from '../view.ts';\n\nexport class RelationalQueryBuilder<\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTSchema extends TablesRelationalConfig,\n\tTFields extends TableRelationalConfig,\n> {\n\tstatic readonly [entityKind]: string = 'SingleStoreRelationalQueryBuilderV2';\n\n\tconstructor(\n\t\tprivate schema: TSchema,\n\t\tprivate table: SingleStoreTable | SingleStoreView,\n\t\tprivate tableConfig: TableRelationalConfig,\n\t\tprivate dialect: SingleStoreDialect,\n\t\tprivate session: SingleStoreSession,\n\t) {}\n\n\tfindMany<TConfig extends DBQueryConfig<'many', TSchema, TFields>>(\n\t\tconfig?: KnownKeysOnly<TConfig, DBQueryConfig<'many', TSchema, TFields>>,\n\t): SingleStoreRelationalQuery<TPreparedQueryHKT, BuildQueryResult<TSchema, TFields, TConfig>[]> {\n\t\treturn new SingleStoreRelationalQuery(\n\t\t\tthis.schema,\n\t\t\tthis.table,\n\t\t\tthis.tableConfig,\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tconfig as DBQueryConfig<'many'> | undefined ?? true,\n\t\t\t'many',\n\t\t);\n\t}\n\n\tfindFirst<TSelection extends DBQueryConfig<'one', TSchema, TFields>>(\n\t\tconfig?: KnownKeysOnly<TSelection, DBQueryConfig<'one', TSchema, TFields>>,\n\t): SingleStoreRelationalQuery<TPreparedQueryHKT, BuildQueryResult<TSchema, TFields, TSelection> | undefined> {\n\t\treturn new SingleStoreRelationalQuery(\n\t\t\tthis.schema,\n\t\t\tthis.table,\n\t\t\tthis.tableConfig,\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tconfig as DBQueryConfig<'one'> | undefined ?? true,\n\t\t\t'first',\n\t\t);\n\t}\n}\n\nexport class SingleStoreRelationalQuery<\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTResult,\n> extends QueryPromise<TResult> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreRelationalQueryV2';\n\n\tdeclare protected $brand: 'SingleStoreRelationalQuery';\n\n\tconstructor(\n\t\tprivate schema: TablesRelationalConfig,\n\t\tprivate table: SingleStoreTable | SingleStoreView,\n\t\tprivate tableConfig: TableRelationalConfig,\n\t\tprivate dialect: SingleStoreDialect,\n\t\tprivate session: SingleStoreSession,\n\t\tprivate config: DBQueryConfig<'many' | 'one'> | true,\n\t\tprivate mode: 'many' | 'first',\n\t) {\n\t\tsuper();\n\t}\n\n\tprepare() {\n\t\tconst { query, builtQuery } = this._toSQL();\n\t\treturn this.session.prepareRelationalQuery(\n\t\t\tbuiltQuery,\n\t\t\tundefined,\n\t\t\t(rawRows) => {\n\t\t\t\tconst rows = rawRows.map((row) => mapRelationalRow(row, query.selection, undefined, undefined, true));\n\t\t\t\tif (this.mode === 'first') {\n\t\t\t\t\treturn rows[0] as TResult;\n\t\t\t\t}\n\t\t\t\treturn rows as TResult;\n\t\t\t},\n\t\t) as PreparedQueryKind<TPreparedQueryHKT, SingleStorePreparedQueryConfig & { execute: TResult }, true>;\n\t}\n\n\tprivate _getQuery() {\n\t\treturn this.dialect.buildRelationalQuery({\n\t\t\tschema: this.schema,\n\t\t\ttable: this.table,\n\t\t\ttableConfig: this.tableConfig,\n\t\t\tqueryConfig: this.config,\n\t\t\tmode: this.mode,\n\t\t});\n\t}\n\n\tprivate _toSQL(): { query: BuildRelationalQueryResult; builtQuery: QueryWithTypings } {\n\t\tconst query = this._getQuery();\n\n\t\tconst builtQuery = this.dialect.sqlToQuery(query.sql);\n\n\t\treturn { builtQuery, query };\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this._getQuery().sql;\n\t}\n\n\ttoSQL(): Query {\n\t\treturn this._toSQL().builtQuery;\n\t}\n\n\toverride execute(): Promise<TResult> {\n\t\treturn this.prepare().execute();\n\t}\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B;AAAA,EAIC;AAAA,OAGM;AAaA,MAAM,uBAIX;AAAA,EAGD,YACS,QACA,OACA,aACA,SACA,SACP;AALO;AACA;AACA;AACA;AACA;AAAA,EACN;AAAA,EARH,QAAiB,UAAU,IAAY;AAAA,EAUvC,SACC,QAC+F;AAC/F,WAAO,IAAI;AAAA,MACV,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,UAA+C;AAAA,MAC/C;AAAA,IACD;AAAA,EACD;AAAA,EAEA,UACC,QAC4G;AAC5G,WAAO,IAAI;AAAA,MACV,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,UAA8C;AAAA,MAC9C;AAAA,IACD;AAAA,EACD;AACD;AAEO,MAAM,mCAGH,aAAsB;AAAA,EAK/B,YACS,QACA,OACA,aACA,SACA,SACA,QACA,MACP;AACD,UAAM;AARE;AACA;AACA;AACA;AACA;AACA;AACA;AAAA,EAGT;AAAA,EAdA,QAA0B,UAAU,IAAY;AAAA,EAgBhD,UAAU;AACT,UAAM,EAAE,OAAO,WAAW,IAAI,KAAK,OAAO;AAC1C,WAAO,KAAK,QAAQ;AAAA,MACnB;AAAA,MACA;AAAA,MACA,CAAC,YAAY;AACZ,cAAM,OAAO,QAAQ,IAAI,CAAC,QAAQ,iBAAiB,KAAK,MAAM,WAAW,QAAW,QAAW,IAAI,CAAC;AACpG,YAAI,KAAK,SAAS,SAAS;AAC1B,iBAAO,KAAK,CAAC;AAAA,QACd;AACA,eAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAAA,EAEQ,YAAY;AACnB,WAAO,KAAK,QAAQ,qBAAqB;AAAA,MACxC,QAAQ,KAAK;AAAA,MACb,OAAO,KAAK;AAAA,MACZ,aAAa,KAAK;AAAA,MAClB,aAAa,KAAK;AAAA,MAClB,MAAM,KAAK;AAAA,IACZ,CAAC;AAAA,EACF;AAAA,EAEQ,SAA8E;AACrF,UAAM,QAAQ,KAAK,UAAU;AAE7B,UAAM,aAAa,KAAK,QAAQ,WAAW,MAAM,GAAG;AAEpD,WAAO,EAAE,YAAY,MAAM;AAAA,EAC5B;AAAA;AAAA,EAGA,SAAc;AACb,WAAO,KAAK,UAAU,EAAE;AAAA,EACzB;AAAA,EAEA,QAAe;AACd,WAAO,KAAK,OAAO,EAAE;AAAA,EACtB;AAAA,EAES,UAA4B;AACpC,WAAO,KAAK,QAAQ,EAAE,QAAQ;AAAA,EAC/B;AACD;","names":[]}
|
|
@@ -146,8 +146,9 @@ class SingleStoreSession {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
class SingleStoreTransaction extends import_db.SingleStoreDatabase {
|
|
149
|
-
constructor(dialect, session, schema, nestedIndex) {
|
|
150
|
-
super(dialect, session, schema);
|
|
149
|
+
constructor(dialect, session, relations, schema, nestedIndex) {
|
|
150
|
+
super(dialect, session, relations, schema);
|
|
151
|
+
this.relations = relations;
|
|
151
152
|
this.schema = schema;
|
|
152
153
|
this.nestedIndex = nestedIndex;
|
|
153
154
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/singlestore-core/session.ts"],"sourcesContent":["import type * as V1 from '~/_relations.ts';\nimport { type Cache, hashQuery, NoopCache } from '~/cache/core/cache.ts';\nimport type { WithCacheConfig } from '~/cache/core/types.ts';\nimport { entityKind, is } from '~/entity.ts';\nimport { DrizzleQueryError, TransactionRollbackError } from '~/errors.ts';\nimport { type Query, type SQL, sql } from '~/sql/sql.ts';\nimport type { Assume, Equal } from '~/utils.ts';\nimport { SingleStoreDatabase } from './db.ts';\nimport type { SingleStoreDialect } from './dialect.ts';\nimport type { SelectedFieldsOrdered } from './query-builders/select.types.ts';\n\nexport interface SingleStoreQueryResultHKT {\n\treadonly $brand: 'SingleStoreQueryResultHKT';\n\treadonly row: unknown;\n\treadonly type: unknown;\n}\n\nexport interface AnySingleStoreQueryResultHKT extends SingleStoreQueryResultHKT {\n\treadonly type: any;\n}\n\nexport type SingleStoreQueryResultKind<TKind extends SingleStoreQueryResultHKT, TRow> = (TKind & {\n\treadonly row: TRow;\n})['type'];\n\nexport interface SingleStorePreparedQueryConfig {\n\texecute: unknown;\n\titerator: unknown;\n}\n\nexport interface SingleStorePreparedQueryHKT {\n\treadonly $brand: 'SingleStorePreparedQueryHKT';\n\treadonly config: unknown;\n\treadonly type: unknown;\n}\n\nexport type PreparedQueryKind<\n\tTKind extends SingleStorePreparedQueryHKT,\n\tTConfig extends SingleStorePreparedQueryConfig,\n\tTAssume extends boolean = false,\n> = Equal<TAssume, true> extends true\n\t? Assume<(TKind & { readonly config: TConfig })['type'], SingleStorePreparedQuery<TConfig>>\n\t: (TKind & { readonly config: TConfig })['type'];\n\nexport abstract class SingleStorePreparedQuery<T extends SingleStorePreparedQueryConfig> {\n\tstatic readonly [entityKind]: string = 'SingleStorePreparedQuery';\n\n\tconstructor(\n\t\tprivate cache?: Cache,\n\t\t// per query related metadata\n\t\tprivate queryMetadata?: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t} | undefined,\n\t\t// config that was passed through $withCache\n\t\tprivate cacheConfig?: WithCacheConfig,\n\t) {\n\t\t// it means that no $withCache options were passed and it should be just enabled\n\t\tif (cache && cache.strategy() === 'all' && cacheConfig === undefined) {\n\t\t\tthis.cacheConfig = { enable: true, autoInvalidate: true };\n\t\t}\n\t\tif (!this.cacheConfig?.enable) {\n\t\t\tthis.cacheConfig = undefined;\n\t\t}\n\t}\n\n\t/** @internal */\n\tprotected async queryWithCache<T>(\n\t\tqueryString: string,\n\t\tparams: any[],\n\t\tquery: () => Promise<T>,\n\t): Promise<T> {\n\t\tif (this.cache === undefined || is(this.cache, NoopCache) || this.queryMetadata === undefined) {\n\t\t\ttry {\n\t\t\t\treturn await query();\n\t\t\t} catch (e) {\n\t\t\t\tthrow new DrizzleQueryError(queryString, params, e as Error);\n\t\t\t}\n\t\t}\n\n\t\t// don't do any mutations, if globally is false\n\t\tif (this.cacheConfig && !this.cacheConfig.enable) {\n\t\t\ttry {\n\t\t\t\treturn await query();\n\t\t\t} catch (e) {\n\t\t\t\tthrow new DrizzleQueryError(queryString, params, e as Error);\n\t\t\t}\n\t\t}\n\n\t\t// For mutate queries, we should query the database, wait for a response, and then perform invalidation\n\t\tif (\n\t\t\t(\n\t\t\t\tthis.queryMetadata.type === 'insert' || this.queryMetadata.type === 'update'\n\t\t\t\t|| this.queryMetadata.type === 'delete'\n\t\t\t) && this.queryMetadata.tables.length > 0\n\t\t) {\n\t\t\ttry {\n\t\t\t\tconst [res] = await Promise.all([\n\t\t\t\t\tquery(),\n\t\t\t\t\tthis.cache.onMutate({ tables: this.queryMetadata.tables }),\n\t\t\t\t]);\n\t\t\t\treturn res;\n\t\t\t} catch (e) {\n\t\t\t\tthrow new DrizzleQueryError(queryString, params, e as Error);\n\t\t\t}\n\t\t}\n\n\t\t// don't do any reads if globally disabled\n\t\tif (!this.cacheConfig) {\n\t\t\ttry {\n\t\t\t\treturn await query();\n\t\t\t} catch (e) {\n\t\t\t\tthrow new DrizzleQueryError(queryString, params, e as Error);\n\t\t\t}\n\t\t}\n\n\t\tif (this.queryMetadata.type === 'select') {\n\t\t\tconst fromCache = await this.cache.get(\n\t\t\t\tthis.cacheConfig.tag ?? await hashQuery(queryString, params),\n\t\t\t\tthis.queryMetadata.tables,\n\t\t\t\tthis.cacheConfig.tag !== undefined,\n\t\t\t\tthis.cacheConfig.autoInvalidate,\n\t\t\t);\n\t\t\tif (fromCache === undefined) {\n\t\t\t\tlet result;\n\t\t\t\ttry {\n\t\t\t\t\tresult = await query();\n\t\t\t\t} catch (e) {\n\t\t\t\t\tthrow new DrizzleQueryError(queryString, params, e as Error);\n\t\t\t\t}\n\n\t\t\t\t// put actual key\n\t\t\t\tawait this.cache.put(\n\t\t\t\t\tthis.cacheConfig.tag ?? await hashQuery(queryString, params),\n\t\t\t\t\tresult,\n\t\t\t\t\t// make sure we send tables that were used in a query only if user wants to invalidate it on each write\n\t\t\t\t\tthis.cacheConfig.autoInvalidate ? this.queryMetadata.tables : [],\n\t\t\t\t\tthis.cacheConfig.tag !== undefined,\n\t\t\t\t\tthis.cacheConfig.config,\n\t\t\t\t);\n\t\t\t\t// put flag if we should invalidate or not\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\treturn fromCache as unknown as T;\n\t\t}\n\t\ttry {\n\t\t\treturn await query();\n\t\t} catch (e) {\n\t\t\tthrow new DrizzleQueryError(queryString, params, e as Error);\n\t\t}\n\t}\n\n\t/** @internal */\n\tjoinsNotNullableMap?: Record<string, boolean>;\n\n\tabstract execute(placeholderValues?: Record<string, unknown>): Promise<T['execute']>;\n\n\tabstract iterator(placeholderValues?: Record<string, unknown>): AsyncGenerator<T['iterator']>;\n}\n\nexport interface SingleStoreTransactionConfig {\n\twithConsistentSnapshot?: boolean;\n\taccessMode?: 'read only' | 'read write';\n\tisolationLevel: 'read committed'; // SingleStore only supports read committed isolation level (https://docs.singlestore.com/db/v8.7/introduction/faqs/durability/)\n}\n\nexport abstract class SingleStoreSession<\n\tTQueryResult extends SingleStoreQueryResultHKT = SingleStoreQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = Record<string, never>,\n\tTSchema extends V1.TablesRelationalConfig = Record<string, never>,\n> {\n\tstatic readonly [entityKind]: string = 'SingleStoreSession';\n\n\tconstructor(protected dialect: SingleStoreDialect) {}\n\n\tabstract prepareQuery<\n\t\tT extends SingleStorePreparedQueryConfig,\n\t\tTPreparedQueryHKT extends SingleStorePreparedQueryHKT,\n\t>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tcustomResultMapper?: (rows: unknown[][]) => T['execute'],\n\t\tgeneratedIds?: Record<string, unknown>[],\n\t\treturningIds?: SelectedFieldsOrdered,\n\t\tqueryMetadata?: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t},\n\t\tcacheConfig?: WithCacheConfig,\n\t): PreparedQueryKind<TPreparedQueryHKT, T>;\n\n\texecute<T>(query: SQL): Promise<T> {\n\t\treturn this.prepareQuery<SingleStorePreparedQueryConfig & { execute: T }, PreparedQueryHKTBase>(\n\t\t\tthis.dialect.sqlToQuery(query),\n\t\t\tundefined,\n\t\t).execute();\n\t}\n\n\tabstract all<T = unknown>(query: SQL): Promise<T[]>;\n\n\tasync count(sql: SQL): Promise<number> {\n\t\tconst res = await this.execute<[[{ count: string }]]>(sql);\n\n\t\treturn Number(\n\t\t\tres[0][0]['count'],\n\t\t);\n\t}\n\n\tabstract transaction<T>(\n\t\ttransaction: (tx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>) => Promise<T>,\n\t\tconfig?: SingleStoreTransactionConfig,\n\t): Promise<T>;\n\n\tprotected getSetTransactionSQL(config: SingleStoreTransactionConfig): SQL | undefined {\n\t\tconst parts: string[] = [];\n\n\t\tif (config.isolationLevel) {\n\t\t\tparts.push(`isolation level ${config.isolationLevel}`);\n\t\t}\n\n\t\treturn parts.length ? sql`set transaction ${sql.raw(parts.join(' '))}` : undefined;\n\t}\n\n\tprotected getStartTransactionSQL(config: SingleStoreTransactionConfig): SQL | undefined {\n\t\tconst parts: string[] = [];\n\n\t\tif (config.withConsistentSnapshot) {\n\t\t\tparts.push('with consistent snapshot');\n\t\t}\n\n\t\tif (config.accessMode) {\n\t\t\tparts.push(config.accessMode);\n\t\t}\n\n\t\treturn parts.length ? sql`start transaction ${sql.raw(parts.join(' '))}` : undefined;\n\t}\n}\n\nexport abstract class SingleStoreTransaction<\n\tTQueryResult extends SingleStoreQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = Record<string, never>,\n\tTSchema extends V1.TablesRelationalConfig = Record<string, never>,\n> extends SingleStoreDatabase<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreTransaction';\n\n\tconstructor(\n\t\tdialect: SingleStoreDialect,\n\t\tsession: SingleStoreSession,\n\t\tprotected schema: V1.RelationalSchemaConfig<TSchema> | undefined,\n\t\tprotected readonly nestedIndex: number,\n\t) {\n\t\tsuper(dialect, session, schema);\n\t}\n\n\trollback(): never {\n\t\tthrow new TransactionRollbackError();\n\t}\n\n\t/** Nested transactions (aka savepoints) only work with InnoDB engine. */\n\tabstract override transaction<T>(\n\t\ttransaction: (tx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>) => Promise<T>,\n\t): Promise<T>;\n}\n\nexport interface PreparedQueryHKTBase extends SingleStorePreparedQueryHKT {\n\ttype: SingleStorePreparedQuery<Assume<this['config'], SingleStorePreparedQueryConfig>>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAiD;AAEjD,oBAA+B;AAC/B,oBAA4D;AAC5D,iBAA0C;AAE1C,gBAAoC;AAqC7B,MAAe,yBAAmE;AAAA,EAGxF,YACS,OAEA,eAKA,aACP;AARO;AAEA;AAKA;AAGR,QAAI,SAAS,MAAM,SAAS,MAAM,SAAS,gBAAgB,QAAW;AACrE,WAAK,cAAc,EAAE,QAAQ,MAAM,gBAAgB,KAAK;AAAA,IACzD;AACA,QAAI,CAAC,KAAK,aAAa,QAAQ;AAC9B,WAAK,cAAc;AAAA,IACpB;AA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vF,UAAM,QAAkB,CAAC;AAEzB,QAAI,OAAO,wBAAwB;AAClC,YAAM,KAAK,0BAA0B;AAAA,IACtC;AAEA,QAAI,OAAO,YAAY;AACtB,YAAM,KAAK,OAAO,UAAU;AAAA,IAC7B;AAEA,WAAO,MAAM,SAAS,mCAAwB,eAAI,IAAI,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK;AAAA,EAC5E;AACD;AAEO,MAAe,+BAKZ,8BAA2E;AAAA,EAGpF,YACC,SACA,SACU,QACS,aAClB;AACD,UAAM,SAAS,SAAS,MAAM;AAHpB;AACS;AAAA,EAGpB;AAAA,EATA,QAA0B,wBAAU,IAAY;AAAA,EAWhD,WAAkB;AACjB,UAAM,IAAI,uCAAyB;AAAA,EACpC;AAMD;","names":["sql"]}
|
|
1
|
+
{"version":3,"sources":["../../src/singlestore-core/session.ts"],"sourcesContent":["import type * as V1 from '~/_relations.ts';\nimport { type Cache, hashQuery, NoopCache } from '~/cache/core/cache.ts';\nimport type { WithCacheConfig } from '~/cache/core/types.ts';\nimport { entityKind, is } from '~/entity.ts';\nimport { DrizzleQueryError, TransactionRollbackError } from '~/errors.ts';\nimport type { AnyRelations, EmptyRelations } from '~/relations.ts';\nimport { type Query, type SQL, sql } from '~/sql/sql.ts';\nimport type { Assume, Equal } from '~/utils.ts';\nimport { SingleStoreDatabase } from './db.ts';\nimport type { SingleStoreDialect } from './dialect.ts';\nimport type { SelectedFieldsOrdered } from './query-builders/select.types.ts';\n\nexport interface SingleStoreQueryResultHKT {\n\treadonly $brand: 'SingleStoreQueryResultHKT';\n\treadonly row: unknown;\n\treadonly type: unknown;\n}\n\nexport interface AnySingleStoreQueryResultHKT extends SingleStoreQueryResultHKT {\n\treadonly type: any;\n}\n\nexport type SingleStoreQueryResultKind<TKind extends SingleStoreQueryResultHKT, TRow> = (TKind & {\n\treadonly row: TRow;\n})['type'];\n\nexport interface SingleStorePreparedQueryConfig {\n\texecute: unknown;\n\titerator: unknown;\n}\n\nexport interface SingleStorePreparedQueryHKT {\n\treadonly $brand: 'SingleStorePreparedQueryHKT';\n\treadonly config: unknown;\n\treadonly type: unknown;\n}\n\nexport type PreparedQueryKind<\n\tTKind extends SingleStorePreparedQueryHKT,\n\tTConfig extends SingleStorePreparedQueryConfig,\n\tTAssume extends boolean = false,\n> = Equal<TAssume, true> extends true\n\t? Assume<(TKind & { readonly config: TConfig })['type'], SingleStorePreparedQuery<TConfig>>\n\t: (TKind & { readonly config: TConfig })['type'];\n\nexport abstract class SingleStorePreparedQuery<T extends SingleStorePreparedQueryConfig> {\n\tstatic readonly [entityKind]: string = 'SingleStorePreparedQuery';\n\n\tconstructor(\n\t\tprivate cache?: Cache,\n\t\t// per query related metadata\n\t\tprivate queryMetadata?: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t} | undefined,\n\t\t// config that was passed through $withCache\n\t\tprivate cacheConfig?: WithCacheConfig,\n\t) {\n\t\t// it means that no $withCache options were passed and it should be just enabled\n\t\tif (cache && cache.strategy() === 'all' && cacheConfig === undefined) {\n\t\t\tthis.cacheConfig = { enable: true, autoInvalidate: true };\n\t\t}\n\t\tif (!this.cacheConfig?.enable) {\n\t\t\tthis.cacheConfig = undefined;\n\t\t}\n\t}\n\n\t/** @internal */\n\tprotected async queryWithCache<T>(\n\t\tqueryString: string,\n\t\tparams: any[],\n\t\tquery: () => Promise<T>,\n\t): Promise<T> {\n\t\tif (this.cache === undefined || is(this.cache, NoopCache) || this.queryMetadata === undefined) {\n\t\t\ttry {\n\t\t\t\treturn await query();\n\t\t\t} catch (e) {\n\t\t\t\tthrow new DrizzleQueryError(queryString, params, e as Error);\n\t\t\t}\n\t\t}\n\n\t\t// don't do any mutations, if globally is false\n\t\tif (this.cacheConfig && !this.cacheConfig.enable) {\n\t\t\ttry {\n\t\t\t\treturn await query();\n\t\t\t} catch (e) {\n\t\t\t\tthrow new DrizzleQueryError(queryString, params, e as Error);\n\t\t\t}\n\t\t}\n\n\t\t// For mutate queries, we should query the database, wait for a response, and then perform invalidation\n\t\tif (\n\t\t\t(\n\t\t\t\tthis.queryMetadata.type === 'insert' || this.queryMetadata.type === 'update'\n\t\t\t\t|| this.queryMetadata.type === 'delete'\n\t\t\t) && this.queryMetadata.tables.length > 0\n\t\t) {\n\t\t\ttry {\n\t\t\t\tconst [res] = await Promise.all([\n\t\t\t\t\tquery(),\n\t\t\t\t\tthis.cache.onMutate({ tables: this.queryMetadata.tables }),\n\t\t\t\t]);\n\t\t\t\treturn res;\n\t\t\t} catch (e) {\n\t\t\t\tthrow new DrizzleQueryError(queryString, params, e as Error);\n\t\t\t}\n\t\t}\n\n\t\t// don't do any reads if globally disabled\n\t\tif (!this.cacheConfig) {\n\t\t\ttry {\n\t\t\t\treturn await query();\n\t\t\t} catch (e) {\n\t\t\t\tthrow new DrizzleQueryError(queryString, params, e as Error);\n\t\t\t}\n\t\t}\n\n\t\tif (this.queryMetadata.type === 'select') {\n\t\t\tconst fromCache = await this.cache.get(\n\t\t\t\tthis.cacheConfig.tag ?? await hashQuery(queryString, params),\n\t\t\t\tthis.queryMetadata.tables,\n\t\t\t\tthis.cacheConfig.tag !== undefined,\n\t\t\t\tthis.cacheConfig.autoInvalidate,\n\t\t\t);\n\t\t\tif (fromCache === undefined) {\n\t\t\t\tlet result;\n\t\t\t\ttry {\n\t\t\t\t\tresult = await query();\n\t\t\t\t} catch (e) {\n\t\t\t\t\tthrow new DrizzleQueryError(queryString, params, e as Error);\n\t\t\t\t}\n\n\t\t\t\t// put actual key\n\t\t\t\tawait this.cache.put(\n\t\t\t\t\tthis.cacheConfig.tag ?? await hashQuery(queryString, params),\n\t\t\t\t\tresult,\n\t\t\t\t\t// make sure we send tables that were used in a query only if user wants to invalidate it on each write\n\t\t\t\t\tthis.cacheConfig.autoInvalidate ? this.queryMetadata.tables : [],\n\t\t\t\t\tthis.cacheConfig.tag !== undefined,\n\t\t\t\t\tthis.cacheConfig.config,\n\t\t\t\t);\n\t\t\t\t// put flag if we should invalidate or not\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\treturn fromCache as unknown as T;\n\t\t}\n\t\ttry {\n\t\t\treturn await query();\n\t\t} catch (e) {\n\t\t\tthrow new DrizzleQueryError(queryString, params, e as Error);\n\t\t}\n\t}\n\n\t/** @internal */\n\tjoinsNotNullableMap?: Record<string, boolean>;\n\n\tabstract execute(placeholderValues?: Record<string, unknown>): Promise<T['execute']>;\n\n\tabstract iterator(placeholderValues?: Record<string, unknown>): AsyncGenerator<T['iterator']>;\n}\n\nexport interface SingleStoreTransactionConfig {\n\twithConsistentSnapshot?: boolean;\n\taccessMode?: 'read only' | 'read write';\n\tisolationLevel: 'read committed'; // SingleStore only supports read committed isolation level (https://docs.singlestore.com/db/v8.7/introduction/faqs/durability/)\n}\n\nexport abstract class SingleStoreSession<\n\tTQueryResult extends SingleStoreQueryResultHKT = SingleStoreQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = Record<string, never>,\n\tTRelations extends AnyRelations = EmptyRelations,\n\tTSchema extends V1.TablesRelationalConfig = Record<string, never>,\n> {\n\tstatic readonly [entityKind]: string = 'SingleStoreSession';\n\n\tconstructor(protected dialect: SingleStoreDialect) {}\n\n\tabstract prepareQuery<\n\t\tT extends SingleStorePreparedQueryConfig,\n\t\tTPreparedQueryHKT extends SingleStorePreparedQueryHKT,\n\t>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tcustomResultMapper?: (rows: unknown[][]) => T['execute'],\n\t\tgeneratedIds?: Record<string, unknown>[],\n\t\treturningIds?: SelectedFieldsOrdered,\n\t\tqueryMetadata?: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t},\n\t\tcacheConfig?: WithCacheConfig,\n\t): PreparedQueryKind<TPreparedQueryHKT, T>;\n\n\tabstract prepareRelationalQuery<\n\t\tT extends SingleStorePreparedQueryConfig,\n\t\tTPreparedQueryHKT extends SingleStorePreparedQueryHKT,\n\t>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tcustomResultMapper: (rows: Record<string, unknown>[]) => T['execute'],\n\t\tgeneratedIds?: Record<string, unknown>[],\n\t\treturningIds?: SelectedFieldsOrdered,\n\t): PreparedQueryKind<TPreparedQueryHKT, T>;\n\n\texecute<T>(query: SQL): Promise<T> {\n\t\treturn this.prepareQuery<SingleStorePreparedQueryConfig & { execute: T }, PreparedQueryHKTBase>(\n\t\t\tthis.dialect.sqlToQuery(query),\n\t\t\tundefined,\n\t\t).execute();\n\t}\n\n\tabstract all<T = unknown>(query: SQL): Promise<T[]>;\n\n\tasync count(sql: SQL): Promise<number> {\n\t\tconst res = await this.execute<[[{ count: string }]]>(sql);\n\n\t\treturn Number(\n\t\t\tres[0][0]['count'],\n\t\t);\n\t}\n\n\tabstract transaction<T>(\n\t\ttransaction: (\n\t\t\ttx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TRelations, TSchema>,\n\t\t) => Promise<T>,\n\t\tconfig?: SingleStoreTransactionConfig,\n\t): Promise<T>;\n\n\tprotected getSetTransactionSQL(config: SingleStoreTransactionConfig): SQL | undefined {\n\t\tconst parts: string[] = [];\n\n\t\tif (config.isolationLevel) {\n\t\t\tparts.push(`isolation level ${config.isolationLevel}`);\n\t\t}\n\n\t\treturn parts.length ? sql`set transaction ${sql.raw(parts.join(' '))}` : undefined;\n\t}\n\n\tprotected getStartTransactionSQL(config: SingleStoreTransactionConfig): SQL | undefined {\n\t\tconst parts: string[] = [];\n\n\t\tif (config.withConsistentSnapshot) {\n\t\t\tparts.push('with consistent snapshot');\n\t\t}\n\n\t\tif (config.accessMode) {\n\t\t\tparts.push(config.accessMode);\n\t\t}\n\n\t\treturn parts.length ? sql`start transaction ${sql.raw(parts.join(' '))}` : undefined;\n\t}\n}\n\nexport abstract class SingleStoreTransaction<\n\tTQueryResult extends SingleStoreQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = Record<string, never>,\n\tTRelations extends AnyRelations = EmptyRelations,\n\tTSchema extends V1.TablesRelationalConfig = Record<string, never>,\n> extends SingleStoreDatabase<TQueryResult, TPreparedQueryHKT, TFullSchema, TRelations, TSchema> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreTransaction';\n\n\tconstructor(\n\t\tdialect: SingleStoreDialect,\n\t\tsession: SingleStoreSession,\n\t\tprotected relations: TRelations,\n\t\tprotected schema: V1.RelationalSchemaConfig<TSchema> | undefined,\n\t\tprotected readonly nestedIndex: number,\n\t) {\n\t\tsuper(dialect, session, relations, schema);\n\t}\n\n\trollback(): never {\n\t\tthrow new TransactionRollbackError();\n\t}\n\n\t/** Nested transactions (aka savepoints) only work with InnoDB engine. */\n\tabstract override transaction<T>(\n\t\ttransaction: (\n\t\t\ttx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TRelations, TSchema>,\n\t\t) => Promise<T>,\n\t): Promise<T>;\n}\n\nexport interface PreparedQueryHKTBase extends SingleStorePreparedQueryHKT {\n\ttype: SingleStorePreparedQuery<Assume<this['config'], SingleStorePreparedQueryConfig>>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAiD;AAEjD,oBAA+B;AAC/B,oBAA4D;AAE5D,iBAA0C;AAE1C,gBAAoC;AAqC7B,MAAe,yBAAmE;AAAA,EAGxF,YACS,OAEA,eAKA,aACP;AARO;AAEA;AAKA;AAGR,QAAI,SAAS,MAAM,SAAS,MAAM,SAAS,gBAAgB,QAAW;AACrE,WAAK,cAAc,EAAE,QAAQ,MAAM,gBAAgB,KAAK;AAAA,IACzD;AACA,QAAI,CAAC,KAAK,aAAa,QAAQ;AAC9B,WAAK,cAAc;AAAA,IACpB;AAAA,EACD;AAAA,EAnBA,QAAiB,wBAAU,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AAO,wBAAwB;AAClC,YAAM,KAAK,0BAA0B;AAAA,IACtC;AAEA,QAAI,OAAO,YAAY;AACtB,YAAM,KAAK,OAAO,UAAU;AAAA,IAC7B;AAEA,WAAO,MAAM,SAAS,mCAAwB,eAAI,IAAI,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK;AAAA,EAC5E;AACD;AAEO,MAAe,+BAMZ,8BAAuF;AAAA,EAGhG,YACC,SACA,SACU,WACA,QACS,aAClB;AACD,UAAM,SAAS,SAAS,WAAW,MAAM;AAJ/B;AACA;AACS;AAAA,EAGpB;AAAA,EAVA,QAA0B,wBAAU,IAAY;AAAA,EAYhD,WAAkB;AACjB,UAAM,IAAI,uCAAyB;AAAA,EACpC;AAQD;","names":["sql"]}
|
|
@@ -2,6 +2,7 @@ import type * as V1 from "../_relations.cjs";
|
|
|
2
2
|
import { type Cache } from "../cache/core/cache.cjs";
|
|
3
3
|
import type { WithCacheConfig } from "../cache/core/types.cjs";
|
|
4
4
|
import { entityKind } from "../entity.cjs";
|
|
5
|
+
import type { AnyRelations, EmptyRelations } from "../relations.cjs";
|
|
5
6
|
import { type Query, type SQL } from "../sql/sql.cjs";
|
|
6
7
|
import type { Assume, Equal } from "../utils.cjs";
|
|
7
8
|
import { SingleStoreDatabase } from "./db.cjs";
|
|
@@ -49,7 +50,7 @@ export interface SingleStoreTransactionConfig {
|
|
|
49
50
|
accessMode?: 'read only' | 'read write';
|
|
50
51
|
isolationLevel: 'read committed';
|
|
51
52
|
}
|
|
52
|
-
export declare abstract class SingleStoreSession<TQueryResult extends SingleStoreQueryResultHKT = SingleStoreQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends V1.TablesRelationalConfig = Record<string, never>> {
|
|
53
|
+
export declare abstract class SingleStoreSession<TQueryResult extends SingleStoreQueryResultHKT = SingleStoreQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations, TSchema extends V1.TablesRelationalConfig = Record<string, never>> {
|
|
53
54
|
protected dialect: SingleStoreDialect;
|
|
54
55
|
static readonly [entityKind]: string;
|
|
55
56
|
constructor(dialect: SingleStoreDialect);
|
|
@@ -57,21 +58,23 @@ export declare abstract class SingleStoreSession<TQueryResult extends SingleStor
|
|
|
57
58
|
type: 'select' | 'update' | 'delete' | 'insert';
|
|
58
59
|
tables: string[];
|
|
59
60
|
}, cacheConfig?: WithCacheConfig): PreparedQueryKind<TPreparedQueryHKT, T>;
|
|
61
|
+
abstract prepareRelationalQuery<T extends SingleStorePreparedQueryConfig, TPreparedQueryHKT extends SingleStorePreparedQueryHKT>(query: Query, fields: SelectedFieldsOrdered | undefined, customResultMapper: (rows: Record<string, unknown>[]) => T['execute'], generatedIds?: Record<string, unknown>[], returningIds?: SelectedFieldsOrdered): PreparedQueryKind<TPreparedQueryHKT, T>;
|
|
60
62
|
execute<T>(query: SQL): Promise<T>;
|
|
61
63
|
abstract all<T = unknown>(query: SQL): Promise<T[]>;
|
|
62
64
|
count(sql: SQL): Promise<number>;
|
|
63
|
-
abstract transaction<T>(transaction: (tx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>) => Promise<T>, config?: SingleStoreTransactionConfig): Promise<T>;
|
|
65
|
+
abstract transaction<T>(transaction: (tx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TRelations, TSchema>) => Promise<T>, config?: SingleStoreTransactionConfig): Promise<T>;
|
|
64
66
|
protected getSetTransactionSQL(config: SingleStoreTransactionConfig): SQL | undefined;
|
|
65
67
|
protected getStartTransactionSQL(config: SingleStoreTransactionConfig): SQL | undefined;
|
|
66
68
|
}
|
|
67
|
-
export declare abstract class SingleStoreTransaction<TQueryResult extends SingleStoreQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends V1.TablesRelationalConfig = Record<string, never>> extends SingleStoreDatabase<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema> {
|
|
69
|
+
export declare abstract class SingleStoreTransaction<TQueryResult extends SingleStoreQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations, TSchema extends V1.TablesRelationalConfig = Record<string, never>> extends SingleStoreDatabase<TQueryResult, TPreparedQueryHKT, TFullSchema, TRelations, TSchema> {
|
|
70
|
+
protected relations: TRelations;
|
|
68
71
|
protected schema: V1.RelationalSchemaConfig<TSchema> | undefined;
|
|
69
72
|
protected readonly nestedIndex: number;
|
|
70
73
|
static readonly [entityKind]: string;
|
|
71
|
-
constructor(dialect: SingleStoreDialect, session: SingleStoreSession, schema: V1.RelationalSchemaConfig<TSchema> | undefined, nestedIndex: number);
|
|
74
|
+
constructor(dialect: SingleStoreDialect, session: SingleStoreSession, relations: TRelations, schema: V1.RelationalSchemaConfig<TSchema> | undefined, nestedIndex: number);
|
|
72
75
|
rollback(): never;
|
|
73
76
|
/** Nested transactions (aka savepoints) only work with InnoDB engine. */
|
|
74
|
-
abstract transaction<T>(transaction: (tx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>) => Promise<T>): Promise<T>;
|
|
77
|
+
abstract transaction<T>(transaction: (tx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TRelations, TSchema>) => Promise<T>): Promise<T>;
|
|
75
78
|
}
|
|
76
79
|
export interface PreparedQueryHKTBase extends SingleStorePreparedQueryHKT {
|
|
77
80
|
type: SingleStorePreparedQuery<Assume<this['config'], SingleStorePreparedQueryConfig>>;
|
|
@@ -2,6 +2,7 @@ import type * as V1 from "../_relations.js";
|
|
|
2
2
|
import { type Cache } from "../cache/core/cache.js";
|
|
3
3
|
import type { WithCacheConfig } from "../cache/core/types.js";
|
|
4
4
|
import { entityKind } from "../entity.js";
|
|
5
|
+
import type { AnyRelations, EmptyRelations } from "../relations.js";
|
|
5
6
|
import { type Query, type SQL } from "../sql/sql.js";
|
|
6
7
|
import type { Assume, Equal } from "../utils.js";
|
|
7
8
|
import { SingleStoreDatabase } from "./db.js";
|
|
@@ -49,7 +50,7 @@ export interface SingleStoreTransactionConfig {
|
|
|
49
50
|
accessMode?: 'read only' | 'read write';
|
|
50
51
|
isolationLevel: 'read committed';
|
|
51
52
|
}
|
|
52
|
-
export declare abstract class SingleStoreSession<TQueryResult extends SingleStoreQueryResultHKT = SingleStoreQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends V1.TablesRelationalConfig = Record<string, never>> {
|
|
53
|
+
export declare abstract class SingleStoreSession<TQueryResult extends SingleStoreQueryResultHKT = SingleStoreQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations, TSchema extends V1.TablesRelationalConfig = Record<string, never>> {
|
|
53
54
|
protected dialect: SingleStoreDialect;
|
|
54
55
|
static readonly [entityKind]: string;
|
|
55
56
|
constructor(dialect: SingleStoreDialect);
|
|
@@ -57,21 +58,23 @@ export declare abstract class SingleStoreSession<TQueryResult extends SingleStor
|
|
|
57
58
|
type: 'select' | 'update' | 'delete' | 'insert';
|
|
58
59
|
tables: string[];
|
|
59
60
|
}, cacheConfig?: WithCacheConfig): PreparedQueryKind<TPreparedQueryHKT, T>;
|
|
61
|
+
abstract prepareRelationalQuery<T extends SingleStorePreparedQueryConfig, TPreparedQueryHKT extends SingleStorePreparedQueryHKT>(query: Query, fields: SelectedFieldsOrdered | undefined, customResultMapper: (rows: Record<string, unknown>[]) => T['execute'], generatedIds?: Record<string, unknown>[], returningIds?: SelectedFieldsOrdered): PreparedQueryKind<TPreparedQueryHKT, T>;
|
|
60
62
|
execute<T>(query: SQL): Promise<T>;
|
|
61
63
|
abstract all<T = unknown>(query: SQL): Promise<T[]>;
|
|
62
64
|
count(sql: SQL): Promise<number>;
|
|
63
|
-
abstract transaction<T>(transaction: (tx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>) => Promise<T>, config?: SingleStoreTransactionConfig): Promise<T>;
|
|
65
|
+
abstract transaction<T>(transaction: (tx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TRelations, TSchema>) => Promise<T>, config?: SingleStoreTransactionConfig): Promise<T>;
|
|
64
66
|
protected getSetTransactionSQL(config: SingleStoreTransactionConfig): SQL | undefined;
|
|
65
67
|
protected getStartTransactionSQL(config: SingleStoreTransactionConfig): SQL | undefined;
|
|
66
68
|
}
|
|
67
|
-
export declare abstract class SingleStoreTransaction<TQueryResult extends SingleStoreQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends V1.TablesRelationalConfig = Record<string, never>> extends SingleStoreDatabase<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema> {
|
|
69
|
+
export declare abstract class SingleStoreTransaction<TQueryResult extends SingleStoreQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations, TSchema extends V1.TablesRelationalConfig = Record<string, never>> extends SingleStoreDatabase<TQueryResult, TPreparedQueryHKT, TFullSchema, TRelations, TSchema> {
|
|
70
|
+
protected relations: TRelations;
|
|
68
71
|
protected schema: V1.RelationalSchemaConfig<TSchema> | undefined;
|
|
69
72
|
protected readonly nestedIndex: number;
|
|
70
73
|
static readonly [entityKind]: string;
|
|
71
|
-
constructor(dialect: SingleStoreDialect, session: SingleStoreSession, schema: V1.RelationalSchemaConfig<TSchema> | undefined, nestedIndex: number);
|
|
74
|
+
constructor(dialect: SingleStoreDialect, session: SingleStoreSession, relations: TRelations, schema: V1.RelationalSchemaConfig<TSchema> | undefined, nestedIndex: number);
|
|
72
75
|
rollback(): never;
|
|
73
76
|
/** Nested transactions (aka savepoints) only work with InnoDB engine. */
|
|
74
|
-
abstract transaction<T>(transaction: (tx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>) => Promise<T>): Promise<T>;
|
|
77
|
+
abstract transaction<T>(transaction: (tx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TRelations, TSchema>) => Promise<T>): Promise<T>;
|
|
75
78
|
}
|
|
76
79
|
export interface PreparedQueryHKTBase extends SingleStorePreparedQueryHKT {
|
|
77
80
|
type: SingleStorePreparedQuery<Assume<this['config'], SingleStorePreparedQueryConfig>>;
|
|
@@ -121,8 +121,9 @@ class SingleStoreSession {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
class SingleStoreTransaction extends SingleStoreDatabase {
|
|
124
|
-
constructor(dialect, session, schema, nestedIndex) {
|
|
125
|
-
super(dialect, session, schema);
|
|
124
|
+
constructor(dialect, session, relations, schema, nestedIndex) {
|
|
125
|
+
super(dialect, session, relations, schema);
|
|
126
|
+
this.relations = relations;
|
|
126
127
|
this.schema = schema;
|
|
127
128
|
this.nestedIndex = nestedIndex;
|
|
128
129
|
}
|