drizzle-orm 1.0.0-beta.1-94774b0 → 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 +69 -30
- package/relations.cjs.map +1 -1
- package/relations.d.cts +6 -5
- package/relations.d.ts +6 -5
- package/relations.js +69 -30
- 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
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as V1 from "../../_relations.cjs";
|
|
2
|
+
import { entityKind } from "../../entity.cjs";
|
|
3
|
+
import { QueryPromise } from "../../query-promise.cjs";
|
|
4
|
+
import type { Query } from "../../sql/sql.cjs";
|
|
5
|
+
import type { KnownKeysOnly } from "../../utils.cjs";
|
|
6
|
+
import type { SingleStoreDialect } from "../dialect.cjs";
|
|
7
|
+
import type { PreparedQueryHKTBase, PreparedQueryKind, SingleStorePreparedQueryConfig, SingleStoreSession } from "../session.cjs";
|
|
8
|
+
import type { SingleStoreTable } from "../table.cjs";
|
|
9
|
+
export declare class _RelationalQueryBuilder<TPreparedQueryHKT extends PreparedQueryHKTBase, TSchema extends V1.TablesRelationalConfig, TFields extends V1.TableRelationalConfig> {
|
|
10
|
+
private fullSchema;
|
|
11
|
+
private schema;
|
|
12
|
+
private tableNamesMap;
|
|
13
|
+
private table;
|
|
14
|
+
private tableConfig;
|
|
15
|
+
private dialect;
|
|
16
|
+
private session;
|
|
17
|
+
static readonly [entityKind]: string;
|
|
18
|
+
constructor(fullSchema: Record<string, unknown>, schema: TSchema, tableNamesMap: Record<string, string>, table: SingleStoreTable, tableConfig: V1.TableRelationalConfig, dialect: SingleStoreDialect, session: SingleStoreSession);
|
|
19
|
+
findMany<TConfig extends V1.DBQueryConfig<'many', true, TSchema, TFields>>(config?: KnownKeysOnly<TConfig, V1.DBQueryConfig<'many', true, TSchema, TFields>>): SingleStoreRelationalQuery<TPreparedQueryHKT, V1.BuildQueryResult<TSchema, TFields, TConfig>[]>;
|
|
20
|
+
findFirst<TSelection extends Omit<V1.DBQueryConfig<'many', true, TSchema, TFields>, 'limit'>>(config?: KnownKeysOnly<TSelection, Omit<V1.DBQueryConfig<'many', true, TSchema, TFields>, 'limit'>>): SingleStoreRelationalQuery<TPreparedQueryHKT, V1.BuildQueryResult<TSchema, TFields, TSelection> | undefined>;
|
|
21
|
+
}
|
|
22
|
+
export declare class SingleStoreRelationalQuery<TPreparedQueryHKT extends PreparedQueryHKTBase, TResult> extends QueryPromise<TResult> {
|
|
23
|
+
private fullSchema;
|
|
24
|
+
private schema;
|
|
25
|
+
private tableNamesMap;
|
|
26
|
+
private table;
|
|
27
|
+
private tableConfig;
|
|
28
|
+
private dialect;
|
|
29
|
+
private session;
|
|
30
|
+
private config;
|
|
31
|
+
private queryMode;
|
|
32
|
+
static readonly [entityKind]: string;
|
|
33
|
+
protected $brand: 'SingleStoreRelationalQuery';
|
|
34
|
+
constructor(fullSchema: Record<string, unknown>, schema: V1.TablesRelationalConfig, tableNamesMap: Record<string, string>, table: SingleStoreTable, tableConfig: V1.TableRelationalConfig, dialect: SingleStoreDialect, session: SingleStoreSession, config: V1.DBQueryConfig<'many', true> | true, queryMode: 'many' | 'first');
|
|
35
|
+
prepare(): PreparedQueryKind<TPreparedQueryHKT, SingleStorePreparedQueryConfig & {
|
|
36
|
+
execute: TResult;
|
|
37
|
+
}, true>;
|
|
38
|
+
private _getQuery;
|
|
39
|
+
private _toSQL;
|
|
40
|
+
toSQL(): Query;
|
|
41
|
+
execute(): Promise<TResult>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as V1 from "../../_relations.js";
|
|
2
|
+
import { entityKind } from "../../entity.js";
|
|
3
|
+
import { QueryPromise } from "../../query-promise.js";
|
|
4
|
+
import type { Query } from "../../sql/sql.js";
|
|
5
|
+
import type { KnownKeysOnly } from "../../utils.js";
|
|
6
|
+
import type { SingleStoreDialect } from "../dialect.js";
|
|
7
|
+
import type { PreparedQueryHKTBase, PreparedQueryKind, SingleStorePreparedQueryConfig, SingleStoreSession } from "../session.js";
|
|
8
|
+
import type { SingleStoreTable } from "../table.js";
|
|
9
|
+
export declare class _RelationalQueryBuilder<TPreparedQueryHKT extends PreparedQueryHKTBase, TSchema extends V1.TablesRelationalConfig, TFields extends V1.TableRelationalConfig> {
|
|
10
|
+
private fullSchema;
|
|
11
|
+
private schema;
|
|
12
|
+
private tableNamesMap;
|
|
13
|
+
private table;
|
|
14
|
+
private tableConfig;
|
|
15
|
+
private dialect;
|
|
16
|
+
private session;
|
|
17
|
+
static readonly [entityKind]: string;
|
|
18
|
+
constructor(fullSchema: Record<string, unknown>, schema: TSchema, tableNamesMap: Record<string, string>, table: SingleStoreTable, tableConfig: V1.TableRelationalConfig, dialect: SingleStoreDialect, session: SingleStoreSession);
|
|
19
|
+
findMany<TConfig extends V1.DBQueryConfig<'many', true, TSchema, TFields>>(config?: KnownKeysOnly<TConfig, V1.DBQueryConfig<'many', true, TSchema, TFields>>): SingleStoreRelationalQuery<TPreparedQueryHKT, V1.BuildQueryResult<TSchema, TFields, TConfig>[]>;
|
|
20
|
+
findFirst<TSelection extends Omit<V1.DBQueryConfig<'many', true, TSchema, TFields>, 'limit'>>(config?: KnownKeysOnly<TSelection, Omit<V1.DBQueryConfig<'many', true, TSchema, TFields>, 'limit'>>): SingleStoreRelationalQuery<TPreparedQueryHKT, V1.BuildQueryResult<TSchema, TFields, TSelection> | undefined>;
|
|
21
|
+
}
|
|
22
|
+
export declare class SingleStoreRelationalQuery<TPreparedQueryHKT extends PreparedQueryHKTBase, TResult> extends QueryPromise<TResult> {
|
|
23
|
+
private fullSchema;
|
|
24
|
+
private schema;
|
|
25
|
+
private tableNamesMap;
|
|
26
|
+
private table;
|
|
27
|
+
private tableConfig;
|
|
28
|
+
private dialect;
|
|
29
|
+
private session;
|
|
30
|
+
private config;
|
|
31
|
+
private queryMode;
|
|
32
|
+
static readonly [entityKind]: string;
|
|
33
|
+
protected $brand: 'SingleStoreRelationalQuery';
|
|
34
|
+
constructor(fullSchema: Record<string, unknown>, schema: V1.TablesRelationalConfig, tableNamesMap: Record<string, string>, table: SingleStoreTable, tableConfig: V1.TableRelationalConfig, dialect: SingleStoreDialect, session: SingleStoreSession, config: V1.DBQueryConfig<'many', true> | true, queryMode: 'many' | 'first');
|
|
35
|
+
prepare(): PreparedQueryKind<TPreparedQueryHKT, SingleStorePreparedQueryConfig & {
|
|
36
|
+
execute: TResult;
|
|
37
|
+
}, true>;
|
|
38
|
+
private _getQuery;
|
|
39
|
+
private _toSQL;
|
|
40
|
+
toSQL(): Query;
|
|
41
|
+
execute(): Promise<TResult>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import * as V1 from "../../_relations.js";
|
|
2
|
+
import { entityKind } from "../../entity.js";
|
|
3
|
+
import { QueryPromise } from "../../query-promise.js";
|
|
4
|
+
class _RelationalQueryBuilder {
|
|
5
|
+
constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session) {
|
|
6
|
+
this.fullSchema = fullSchema;
|
|
7
|
+
this.schema = schema;
|
|
8
|
+
this.tableNamesMap = tableNamesMap;
|
|
9
|
+
this.table = table;
|
|
10
|
+
this.tableConfig = tableConfig;
|
|
11
|
+
this.dialect = dialect;
|
|
12
|
+
this.session = session;
|
|
13
|
+
}
|
|
14
|
+
static [entityKind] = "SingleStoreRelationalQueryBuilder";
|
|
15
|
+
findMany(config) {
|
|
16
|
+
return new SingleStoreRelationalQuery(
|
|
17
|
+
this.fullSchema,
|
|
18
|
+
this.schema,
|
|
19
|
+
this.tableNamesMap,
|
|
20
|
+
this.table,
|
|
21
|
+
this.tableConfig,
|
|
22
|
+
this.dialect,
|
|
23
|
+
this.session,
|
|
24
|
+
config ? config : {},
|
|
25
|
+
"many"
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
findFirst(config) {
|
|
29
|
+
return new SingleStoreRelationalQuery(
|
|
30
|
+
this.fullSchema,
|
|
31
|
+
this.schema,
|
|
32
|
+
this.tableNamesMap,
|
|
33
|
+
this.table,
|
|
34
|
+
this.tableConfig,
|
|
35
|
+
this.dialect,
|
|
36
|
+
this.session,
|
|
37
|
+
config ? { ...config, limit: 1 } : { limit: 1 },
|
|
38
|
+
"first"
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
class SingleStoreRelationalQuery extends QueryPromise {
|
|
43
|
+
constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session, config, queryMode) {
|
|
44
|
+
super();
|
|
45
|
+
this.fullSchema = fullSchema;
|
|
46
|
+
this.schema = schema;
|
|
47
|
+
this.tableNamesMap = tableNamesMap;
|
|
48
|
+
this.table = table;
|
|
49
|
+
this.tableConfig = tableConfig;
|
|
50
|
+
this.dialect = dialect;
|
|
51
|
+
this.session = session;
|
|
52
|
+
this.config = config;
|
|
53
|
+
this.queryMode = queryMode;
|
|
54
|
+
}
|
|
55
|
+
static [entityKind] = "SingleStoreRelationalQuery";
|
|
56
|
+
prepare() {
|
|
57
|
+
const { query, builtQuery } = this._toSQL();
|
|
58
|
+
return this.session.prepareQuery(
|
|
59
|
+
builtQuery,
|
|
60
|
+
void 0,
|
|
61
|
+
(rawRows) => {
|
|
62
|
+
const rows = rawRows.map((row) => V1.mapRelationalRow(this.schema, this.tableConfig, row, query.selection));
|
|
63
|
+
if (this.queryMode === "first") {
|
|
64
|
+
return rows[0];
|
|
65
|
+
}
|
|
66
|
+
return rows;
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
_getQuery() {
|
|
71
|
+
return this.dialect._buildRelationalQuery({
|
|
72
|
+
fullSchema: this.fullSchema,
|
|
73
|
+
schema: this.schema,
|
|
74
|
+
tableNamesMap: this.tableNamesMap,
|
|
75
|
+
table: this.table,
|
|
76
|
+
tableConfig: this.tableConfig,
|
|
77
|
+
queryConfig: this.config,
|
|
78
|
+
tableAlias: this.tableConfig.tsName
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
_toSQL() {
|
|
82
|
+
const query = this._getQuery();
|
|
83
|
+
const builtQuery = this.dialect.sqlToQuery(query.sql);
|
|
84
|
+
return { builtQuery, query };
|
|
85
|
+
}
|
|
86
|
+
/** @internal */
|
|
87
|
+
getSQL() {
|
|
88
|
+
return this._getQuery().sql;
|
|
89
|
+
}
|
|
90
|
+
toSQL() {
|
|
91
|
+
return this._toSQL().builtQuery;
|
|
92
|
+
}
|
|
93
|
+
execute() {
|
|
94
|
+
return this.prepare().execute();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
SingleStoreRelationalQuery,
|
|
99
|
+
_RelationalQueryBuilder
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=_query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/singlestore-core/query-builders/_query.ts"],"sourcesContent":["import * as V1 from '~/_relations.ts';\nimport { entityKind } from '~/entity.ts';\nimport { QueryPromise } from '~/query-promise.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';\n\nexport class _RelationalQueryBuilder<\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTSchema extends V1.TablesRelationalConfig,\n\tTFields extends V1.TableRelationalConfig,\n> {\n\tstatic readonly [entityKind]: string = 'SingleStoreRelationalQueryBuilder';\n\n\tconstructor(\n\t\tprivate fullSchema: Record<string, unknown>,\n\t\tprivate schema: TSchema,\n\t\tprivate tableNamesMap: Record<string, string>,\n\t\tprivate table: SingleStoreTable,\n\t\tprivate tableConfig: V1.TableRelationalConfig,\n\t\tprivate dialect: SingleStoreDialect,\n\t\tprivate session: SingleStoreSession,\n\t) {}\n\n\tfindMany<TConfig extends V1.DBQueryConfig<'many', true, TSchema, TFields>>(\n\t\tconfig?: KnownKeysOnly<TConfig, V1.DBQueryConfig<'many', true, TSchema, TFields>>,\n\t): SingleStoreRelationalQuery<TPreparedQueryHKT, V1.BuildQueryResult<TSchema, TFields, TConfig>[]> {\n\t\treturn new SingleStoreRelationalQuery(\n\t\t\tthis.fullSchema,\n\t\t\tthis.schema,\n\t\t\tthis.tableNamesMap,\n\t\t\tthis.table,\n\t\t\tthis.tableConfig,\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tconfig ? (config as V1.DBQueryConfig<'many', true>) : {},\n\t\t\t'many',\n\t\t);\n\t}\n\n\tfindFirst<TSelection extends Omit<V1.DBQueryConfig<'many', true, TSchema, TFields>, 'limit'>>(\n\t\tconfig?: KnownKeysOnly<TSelection, Omit<V1.DBQueryConfig<'many', true, TSchema, TFields>, 'limit'>>,\n\t): SingleStoreRelationalQuery<TPreparedQueryHKT, V1.BuildQueryResult<TSchema, TFields, TSelection> | undefined> {\n\t\treturn new SingleStoreRelationalQuery(\n\t\t\tthis.fullSchema,\n\t\t\tthis.schema,\n\t\t\tthis.tableNamesMap,\n\t\t\tthis.table,\n\t\t\tthis.tableConfig,\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tconfig ? { ...(config as V1.DBQueryConfig<'many', true> | undefined), limit: 1 } : { limit: 1 },\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 = 'SingleStoreRelationalQuery';\n\n\tdeclare protected $brand: 'SingleStoreRelationalQuery';\n\n\tconstructor(\n\t\tprivate fullSchema: Record<string, unknown>,\n\t\tprivate schema: V1.TablesRelationalConfig,\n\t\tprivate tableNamesMap: Record<string, string>,\n\t\tprivate table: SingleStoreTable,\n\t\tprivate tableConfig: V1.TableRelationalConfig,\n\t\tprivate dialect: SingleStoreDialect,\n\t\tprivate session: SingleStoreSession,\n\t\tprivate config: V1.DBQueryConfig<'many', true> | true,\n\t\tprivate queryMode: 'many' | 'first',\n\t) {\n\t\tsuper();\n\t}\n\n\tprepare() {\n\t\tconst { query, builtQuery } = this._toSQL();\n\t\treturn this.session.prepareQuery(\n\t\t\tbuiltQuery,\n\t\t\tundefined,\n\t\t\t(rawRows) => {\n\t\t\t\tconst rows = rawRows.map((row) => V1.mapRelationalRow(this.schema, this.tableConfig, row, query.selection));\n\t\t\t\tif (this.queryMode === '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\tfullSchema: this.fullSchema,\n\t\t\tschema: this.schema,\n\t\t\ttableNamesMap: this.tableNamesMap,\n\t\t\ttable: this.table,\n\t\t\ttableConfig: this.tableConfig,\n\t\t\tqueryConfig: this.config,\n\t\t\ttableAlias: this.tableConfig.tsName,\n\t\t});\n\t}\n\n\tprivate _toSQL(): { query: V1.BuildRelationalQueryResult; builtQuery: QueryWithTypings } {\n\t\tconst query = this._getQuery();\n\n\t\tconst builtQuery = this.dialect.sqlToQuery(query.sql as SQL);\n\n\t\treturn { builtQuery, query };\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this._getQuery().sql as 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,YAAY,QAAQ;AACpB,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAYtB,MAAM,wBAIX;AAAA,EAGD,YACS,YACA,QACA,eACA,OACA,aACA,SACA,SACP;AAPO;AACA;AACA;AACA;AACA;AACA;AACA;AAAA,EACN;AAAA,EAVH,QAAiB,UAAU,IAAY;AAAA,EAYvC,SACC,QACkG;AAClG,WAAO,IAAI;AAAA,MACV,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,SAAU,SAA4C,CAAC;AAAA,MACvD;AAAA,IACD;AAAA,EACD;AAAA,EAEA,UACC,QAC+G;AAC/G,WAAO,IAAI;AAAA,MACV,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,SAAS,EAAE,GAAI,QAAuD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE;AAAA,MAC9F;AAAA,IACD;AAAA,EACD;AACD;AAEO,MAAM,mCAGH,aAAsB;AAAA,EAK/B,YACS,YACA,QACA,eACA,OACA,aACA,SACA,SACA,QACA,WACP;AACD,UAAM;AAVE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA,EAGT;AAAA,EAhBA,QAA0B,UAAU,IAAY;AAAA,EAkBhD,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,GAAG,iBAAiB,KAAK,QAAQ,KAAK,aAAa,KAAK,MAAM,SAAS,CAAC;AAC1G,YAAI,KAAK,cAAc,SAAS;AAC/B,iBAAO,KAAK,CAAC;AAAA,QACd;AACA,eAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAAA,EAEQ,YAAY;AACnB,WAAO,KAAK,QAAQ,sBAAsB;AAAA,MACzC,YAAY,KAAK;AAAA,MACjB,QAAQ,KAAK;AAAA,MACb,eAAe,KAAK;AAAA,MACpB,OAAO,KAAK;AAAA,MACZ,aAAa,KAAK;AAAA,MAClB,aAAa,KAAK;AAAA,MAClB,YAAY,KAAK,YAAY;AAAA,IAC9B,CAAC;AAAA,EACF;AAAA,EAEQ,SAAiF;AACxF,UAAM,QAAQ,KAAK,UAAU;AAE7B,UAAM,aAAa,KAAK,QAAQ,WAAW,MAAM,GAAU;AAE3D,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,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
|
}
|