drizzle-orm 0.30.3 → 0.30.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +54 -1
- package/version.cjs +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/xata-http/driver.cjs +82 -0
- package/xata-http/driver.cjs.map +1 -0
- package/xata-http/driver.d.cts +24 -0
- package/xata-http/driver.d.ts +24 -0
- package/xata-http/driver.js +56 -0
- package/xata-http/driver.js.map +1 -0
- package/xata-http/index.cjs +25 -0
- package/xata-http/index.cjs.map +1 -0
- package/xata-http/index.d.cts +2 -0
- package/xata-http/index.d.ts +2 -0
- package/xata-http/index.js +3 -0
- package/xata-http/index.js.map +1 -0
- package/xata-http/migrator.cjs +56 -0
- package/xata-http/migrator.cjs.map +1 -0
- package/xata-http/migrator.d.cts +13 -0
- package/xata-http/migrator.d.ts +13 -0
- package/xata-http/migrator.js +32 -0
- package/xata-http/migrator.js.map +1 -0
- package/xata-http/session.cjs +122 -0
- package/xata-http/session.cjs.map +1 -0
- package/xata-http/session.d.cts +52 -0
- package/xata-http/session.d.ts +52 -0
- package/xata-http/session.js +96 -0
- package/xata-http/session.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-orm",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.4",
|
|
4
4
|
"description": "Drizzle ORM package for SQL databases",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"@types/react": ">=18",
|
|
56
56
|
"@types/sql.js": "*",
|
|
57
57
|
"@vercel/postgres": "*",
|
|
58
|
+
"@xata.io/client": "*",
|
|
58
59
|
"better-sqlite3": ">=7",
|
|
59
60
|
"bun-types": "*",
|
|
60
61
|
"expo-sqlite": ">=13.2.0",
|
|
@@ -74,6 +75,9 @@
|
|
|
74
75
|
"@vercel/postgres": {
|
|
75
76
|
"optional": true
|
|
76
77
|
},
|
|
78
|
+
"@xata.io/client": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
77
81
|
"better-sqlite3": {
|
|
78
82
|
"optional": true
|
|
79
83
|
},
|
|
@@ -153,6 +157,7 @@
|
|
|
153
157
|
"@types/react": "^18.2.45",
|
|
154
158
|
"@types/sql.js": "^1.4.4",
|
|
155
159
|
"@vercel/postgres": "^0.3.0",
|
|
160
|
+
"@xata.io/client": "^0.29.3",
|
|
156
161
|
"better-sqlite3": "^8.4.0",
|
|
157
162
|
"bun-types": "^0.6.6",
|
|
158
163
|
"cpy": "^10.1.0",
|
|
@@ -1985,6 +1990,54 @@
|
|
|
1985
1990
|
"types": "./vercel-postgres/session.d.ts",
|
|
1986
1991
|
"default": "./vercel-postgres/session.js"
|
|
1987
1992
|
},
|
|
1993
|
+
"./xata-http/driver": {
|
|
1994
|
+
"import": {
|
|
1995
|
+
"types": "./xata-http/driver.d.ts",
|
|
1996
|
+
"default": "./xata-http/driver.js"
|
|
1997
|
+
},
|
|
1998
|
+
"require": {
|
|
1999
|
+
"types": "./xata-http/driver.d.cts",
|
|
2000
|
+
"default": "./xata-http/driver.cjs"
|
|
2001
|
+
},
|
|
2002
|
+
"types": "./xata-http/driver.d.ts",
|
|
2003
|
+
"default": "./xata-http/driver.js"
|
|
2004
|
+
},
|
|
2005
|
+
"./xata-http": {
|
|
2006
|
+
"import": {
|
|
2007
|
+
"types": "./xata-http/index.d.ts",
|
|
2008
|
+
"default": "./xata-http/index.js"
|
|
2009
|
+
},
|
|
2010
|
+
"require": {
|
|
2011
|
+
"types": "./xata-http/index.d.cts",
|
|
2012
|
+
"default": "./xata-http/index.cjs"
|
|
2013
|
+
},
|
|
2014
|
+
"types": "./xata-http/index.d.ts",
|
|
2015
|
+
"default": "./xata-http/index.js"
|
|
2016
|
+
},
|
|
2017
|
+
"./xata-http/migrator": {
|
|
2018
|
+
"import": {
|
|
2019
|
+
"types": "./xata-http/migrator.d.ts",
|
|
2020
|
+
"default": "./xata-http/migrator.js"
|
|
2021
|
+
},
|
|
2022
|
+
"require": {
|
|
2023
|
+
"types": "./xata-http/migrator.d.cts",
|
|
2024
|
+
"default": "./xata-http/migrator.cjs"
|
|
2025
|
+
},
|
|
2026
|
+
"types": "./xata-http/migrator.d.ts",
|
|
2027
|
+
"default": "./xata-http/migrator.js"
|
|
2028
|
+
},
|
|
2029
|
+
"./xata-http/session": {
|
|
2030
|
+
"import": {
|
|
2031
|
+
"types": "./xata-http/session.d.ts",
|
|
2032
|
+
"default": "./xata-http/session.js"
|
|
2033
|
+
},
|
|
2034
|
+
"require": {
|
|
2035
|
+
"types": "./xata-http/session.d.cts",
|
|
2036
|
+
"default": "./xata-http/session.cjs"
|
|
2037
|
+
},
|
|
2038
|
+
"types": "./xata-http/session.d.ts",
|
|
2039
|
+
"default": "./xata-http/session.js"
|
|
2040
|
+
},
|
|
1988
2041
|
"./aws-data-api/common": {
|
|
1989
2042
|
"import": {
|
|
1990
2043
|
"types": "./aws-data-api/common/index.d.ts",
|
package/version.cjs
CHANGED
package/version.d.cts
CHANGED
package/version.d.ts
CHANGED
package/version.js
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var driver_exports = {};
|
|
20
|
+
__export(driver_exports, {
|
|
21
|
+
XataHttpDatabase: () => XataHttpDatabase,
|
|
22
|
+
XataHttpDriver: () => XataHttpDriver,
|
|
23
|
+
drizzle: () => drizzle
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(driver_exports);
|
|
26
|
+
var import_entity = require("../entity.cjs");
|
|
27
|
+
var import_logger = require("../logger.cjs");
|
|
28
|
+
var import_db = require("../pg-core/db.cjs");
|
|
29
|
+
var import_dialect = require("../pg-core/dialect.cjs");
|
|
30
|
+
var import_relations = require("../relations.cjs");
|
|
31
|
+
var import_session = require("./session.cjs");
|
|
32
|
+
class XataHttpDriver {
|
|
33
|
+
constructor(client, dialect, options = {}) {
|
|
34
|
+
this.client = client;
|
|
35
|
+
this.dialect = dialect;
|
|
36
|
+
this.options = options;
|
|
37
|
+
this.initMappers();
|
|
38
|
+
}
|
|
39
|
+
static [import_entity.entityKind] = "XataDriver";
|
|
40
|
+
createSession(schema) {
|
|
41
|
+
return new import_session.XataHttpSession(this.client, this.dialect, schema, {
|
|
42
|
+
logger: this.options.logger
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
initMappers() {
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
class XataHttpDatabase extends import_db.PgDatabase {
|
|
49
|
+
static [import_entity.entityKind] = "XataHttpDatabase";
|
|
50
|
+
}
|
|
51
|
+
function drizzle(client, config = {}) {
|
|
52
|
+
const dialect = new import_dialect.PgDialect();
|
|
53
|
+
let logger;
|
|
54
|
+
if (config.logger === true) {
|
|
55
|
+
logger = new import_logger.DefaultLogger();
|
|
56
|
+
} else if (config.logger !== false) {
|
|
57
|
+
logger = config.logger;
|
|
58
|
+
}
|
|
59
|
+
let schema;
|
|
60
|
+
if (config.schema) {
|
|
61
|
+
const tablesConfig = (0, import_relations.extractTablesRelationalConfig)(config.schema, import_relations.createTableRelationsHelpers);
|
|
62
|
+
schema = {
|
|
63
|
+
fullSchema: config.schema,
|
|
64
|
+
schema: tablesConfig.tables,
|
|
65
|
+
tableNamesMap: tablesConfig.tableNamesMap
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const driver = new XataHttpDriver(client, dialect, { logger });
|
|
69
|
+
const session = driver.createSession(schema);
|
|
70
|
+
return new XataHttpDatabase(
|
|
71
|
+
dialect,
|
|
72
|
+
session,
|
|
73
|
+
schema
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
XataHttpDatabase,
|
|
79
|
+
XataHttpDriver,
|
|
80
|
+
drizzle
|
|
81
|
+
});
|
|
82
|
+
//# sourceMappingURL=driver.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/xata-http/driver.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { DefaultLogger } from '~/logger.ts';\nimport { PgDatabase } from '~/pg-core/db.ts';\nimport { PgDialect } from '~/pg-core/dialect.ts';\nimport type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { createTableRelationsHelpers, extractTablesRelationalConfig } from '~/relations.ts';\nimport type { DrizzleConfig } from '~/utils.ts';\nimport type { XataHttpClient, XataHttpQueryResultHKT } from './session.ts';\nimport { XataHttpSession } from './session.ts';\n\nexport interface XataDriverOptions {\n\tlogger?: Logger;\n}\n\nexport class XataHttpDriver {\n\tstatic readonly [entityKind]: string = 'XataDriver';\n\n\tconstructor(\n\t\tprivate client: XataHttpClient,\n\t\tprivate dialect: PgDialect,\n\t\tprivate options: XataDriverOptions = {},\n\t) {\n\t\tthis.initMappers();\n\t}\n\n\tcreateSession(\n\t\tschema: RelationalSchemaConfig<TablesRelationalConfig> | undefined,\n\t): XataHttpSession<Record<string, unknown>, TablesRelationalConfig> {\n\t\treturn new XataHttpSession(this.client, this.dialect, schema, {\n\t\t\tlogger: this.options.logger,\n\t\t});\n\t}\n\n\tinitMappers() {\n\t\t// TODO: Add custom type parsers\n\t}\n}\n\nexport class XataHttpDatabase<TSchema extends Record<string, unknown> = Record<string, never>>\n\textends PgDatabase<XataHttpQueryResultHKT, TSchema>\n{\n\tstatic readonly [entityKind]: string = 'XataHttpDatabase';\n\n\t/** @internal */\n\tdeclare readonly session: XataHttpSession<TSchema, ExtractTablesWithRelations<TSchema>>;\n}\n\nexport function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(\n\tclient: XataHttpClient,\n\tconfig: DrizzleConfig<TSchema> = {},\n): XataHttpDatabase<TSchema> {\n\tconst dialect = new PgDialect();\n\tlet logger;\n\tif (config.logger === true) {\n\t\tlogger = new DefaultLogger();\n\t} else if (config.logger !== false) {\n\t\tlogger = config.logger;\n\t}\n\n\tlet schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;\n\tif (config.schema) {\n\t\tconst tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);\n\t\tschema = {\n\t\t\tfullSchema: config.schema,\n\t\t\tschema: tablesConfig.tables,\n\t\t\ttableNamesMap: tablesConfig.tableNamesMap,\n\t\t};\n\t}\n\n\tconst driver = new XataHttpDriver(client, dialect, { logger });\n\tconst session = driver.createSession(schema);\n\n\treturn new XataHttpDatabase(\n\t\tdialect,\n\t\tsession,\n\t\tschema as RelationalSchemaConfig<ExtractTablesWithRelations<TSchema>> | undefined,\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAE3B,oBAA8B;AAC9B,gBAA2B;AAC3B,qBAA0B;AAE1B,uBAA2E;AAG3E,qBAAgC;AAMzB,MAAM,eAAe;AAAA,EAG3B,YACS,QACA,SACA,UAA6B,CAAC,GACrC;AAHO;AACA;AACA;AAER,SAAK,YAAY;AAAA,EAClB;AAAA,EARA,QAAiB,wBAAU,IAAY;AAAA,EAUvC,cACC,QACmE;AACnE,WAAO,IAAI,+BAAgB,KAAK,QAAQ,KAAK,SAAS,QAAQ;AAAA,MAC7D,QAAQ,KAAK,QAAQ;AAAA,IACtB,CAAC;AAAA,EACF;AAAA,EAEA,cAAc;AAAA,EAEd;AACD;AAEO,MAAM,yBACJ,qBACT;AAAA,EACC,QAAiB,wBAAU,IAAY;AAIxC;AAEO,SAAS,QACf,QACA,SAAiC,CAAC,GACN;AAC5B,QAAM,UAAU,IAAI,yBAAU;AAC9B,MAAI;AACJ,MAAI,OAAO,WAAW,MAAM;AAC3B,aAAS,IAAI,4BAAc;AAAA,EAC5B,WAAW,OAAO,WAAW,OAAO;AACnC,aAAS,OAAO;AAAA,EACjB;AAEA,MAAI;AACJ,MAAI,OAAO,QAAQ;AAClB,UAAM,mBAAe,gDAA8B,OAAO,QAAQ,4CAA2B;AAC7F,aAAS;AAAA,MACR,YAAY,OAAO;AAAA,MACnB,QAAQ,aAAa;AAAA,MACrB,eAAe,aAAa;AAAA,IAC7B;AAAA,EACD;AAEA,QAAM,SAAS,IAAI,eAAe,QAAQ,SAAS,EAAE,OAAO,CAAC;AAC7D,QAAM,UAAU,OAAO,cAAc,MAAM;AAE3C,SAAO,IAAI;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { entityKind } from "../entity.cjs";
|
|
2
|
+
import type { Logger } from "../logger.cjs";
|
|
3
|
+
import { PgDatabase } from "../pg-core/db.cjs";
|
|
4
|
+
import { PgDialect } from "../pg-core/dialect.cjs";
|
|
5
|
+
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.cjs";
|
|
6
|
+
import type { DrizzleConfig } from "../utils.cjs";
|
|
7
|
+
import type { XataHttpClient, XataHttpQueryResultHKT } from "./session.cjs";
|
|
8
|
+
import { XataHttpSession } from "./session.cjs";
|
|
9
|
+
export interface XataDriverOptions {
|
|
10
|
+
logger?: Logger;
|
|
11
|
+
}
|
|
12
|
+
export declare class XataHttpDriver {
|
|
13
|
+
private client;
|
|
14
|
+
private dialect;
|
|
15
|
+
private options;
|
|
16
|
+
static readonly [entityKind]: string;
|
|
17
|
+
constructor(client: XataHttpClient, dialect: PgDialect, options?: XataDriverOptions);
|
|
18
|
+
createSession(schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined): XataHttpSession<Record<string, unknown>, TablesRelationalConfig>;
|
|
19
|
+
initMappers(): void;
|
|
20
|
+
}
|
|
21
|
+
export declare class XataHttpDatabase<TSchema extends Record<string, unknown> = Record<string, never>> extends PgDatabase<XataHttpQueryResultHKT, TSchema> {
|
|
22
|
+
static readonly [entityKind]: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(client: XataHttpClient, config?: DrizzleConfig<TSchema>): XataHttpDatabase<TSchema>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { entityKind } from "../entity.js";
|
|
2
|
+
import type { Logger } from "../logger.js";
|
|
3
|
+
import { PgDatabase } from "../pg-core/db.js";
|
|
4
|
+
import { PgDialect } from "../pg-core/dialect.js";
|
|
5
|
+
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.js";
|
|
6
|
+
import type { DrizzleConfig } from "../utils.js";
|
|
7
|
+
import type { XataHttpClient, XataHttpQueryResultHKT } from "./session.js";
|
|
8
|
+
import { XataHttpSession } from "./session.js";
|
|
9
|
+
export interface XataDriverOptions {
|
|
10
|
+
logger?: Logger;
|
|
11
|
+
}
|
|
12
|
+
export declare class XataHttpDriver {
|
|
13
|
+
private client;
|
|
14
|
+
private dialect;
|
|
15
|
+
private options;
|
|
16
|
+
static readonly [entityKind]: string;
|
|
17
|
+
constructor(client: XataHttpClient, dialect: PgDialect, options?: XataDriverOptions);
|
|
18
|
+
createSession(schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined): XataHttpSession<Record<string, unknown>, TablesRelationalConfig>;
|
|
19
|
+
initMappers(): void;
|
|
20
|
+
}
|
|
21
|
+
export declare class XataHttpDatabase<TSchema extends Record<string, unknown> = Record<string, never>> extends PgDatabase<XataHttpQueryResultHKT, TSchema> {
|
|
22
|
+
static readonly [entityKind]: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(client: XataHttpClient, config?: DrizzleConfig<TSchema>): XataHttpDatabase<TSchema>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { entityKind } from "../entity.js";
|
|
2
|
+
import { DefaultLogger } from "../logger.js";
|
|
3
|
+
import { PgDatabase } from "../pg-core/db.js";
|
|
4
|
+
import { PgDialect } from "../pg-core/dialect.js";
|
|
5
|
+
import { createTableRelationsHelpers, extractTablesRelationalConfig } from "../relations.js";
|
|
6
|
+
import { XataHttpSession } from "./session.js";
|
|
7
|
+
class XataHttpDriver {
|
|
8
|
+
constructor(client, dialect, options = {}) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
this.dialect = dialect;
|
|
11
|
+
this.options = options;
|
|
12
|
+
this.initMappers();
|
|
13
|
+
}
|
|
14
|
+
static [entityKind] = "XataDriver";
|
|
15
|
+
createSession(schema) {
|
|
16
|
+
return new XataHttpSession(this.client, this.dialect, schema, {
|
|
17
|
+
logger: this.options.logger
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
initMappers() {
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class XataHttpDatabase extends PgDatabase {
|
|
24
|
+
static [entityKind] = "XataHttpDatabase";
|
|
25
|
+
}
|
|
26
|
+
function drizzle(client, config = {}) {
|
|
27
|
+
const dialect = new PgDialect();
|
|
28
|
+
let logger;
|
|
29
|
+
if (config.logger === true) {
|
|
30
|
+
logger = new DefaultLogger();
|
|
31
|
+
} else if (config.logger !== false) {
|
|
32
|
+
logger = config.logger;
|
|
33
|
+
}
|
|
34
|
+
let schema;
|
|
35
|
+
if (config.schema) {
|
|
36
|
+
const tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);
|
|
37
|
+
schema = {
|
|
38
|
+
fullSchema: config.schema,
|
|
39
|
+
schema: tablesConfig.tables,
|
|
40
|
+
tableNamesMap: tablesConfig.tableNamesMap
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const driver = new XataHttpDriver(client, dialect, { logger });
|
|
44
|
+
const session = driver.createSession(schema);
|
|
45
|
+
return new XataHttpDatabase(
|
|
46
|
+
dialect,
|
|
47
|
+
session,
|
|
48
|
+
schema
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
XataHttpDatabase,
|
|
53
|
+
XataHttpDriver,
|
|
54
|
+
drizzle
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/xata-http/driver.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { DefaultLogger } from '~/logger.ts';\nimport { PgDatabase } from '~/pg-core/db.ts';\nimport { PgDialect } from '~/pg-core/dialect.ts';\nimport type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { createTableRelationsHelpers, extractTablesRelationalConfig } from '~/relations.ts';\nimport type { DrizzleConfig } from '~/utils.ts';\nimport type { XataHttpClient, XataHttpQueryResultHKT } from './session.ts';\nimport { XataHttpSession } from './session.ts';\n\nexport interface XataDriverOptions {\n\tlogger?: Logger;\n}\n\nexport class XataHttpDriver {\n\tstatic readonly [entityKind]: string = 'XataDriver';\n\n\tconstructor(\n\t\tprivate client: XataHttpClient,\n\t\tprivate dialect: PgDialect,\n\t\tprivate options: XataDriverOptions = {},\n\t) {\n\t\tthis.initMappers();\n\t}\n\n\tcreateSession(\n\t\tschema: RelationalSchemaConfig<TablesRelationalConfig> | undefined,\n\t): XataHttpSession<Record<string, unknown>, TablesRelationalConfig> {\n\t\treturn new XataHttpSession(this.client, this.dialect, schema, {\n\t\t\tlogger: this.options.logger,\n\t\t});\n\t}\n\n\tinitMappers() {\n\t\t// TODO: Add custom type parsers\n\t}\n}\n\nexport class XataHttpDatabase<TSchema extends Record<string, unknown> = Record<string, never>>\n\textends PgDatabase<XataHttpQueryResultHKT, TSchema>\n{\n\tstatic readonly [entityKind]: string = 'XataHttpDatabase';\n\n\t/** @internal */\n\tdeclare readonly session: XataHttpSession<TSchema, ExtractTablesWithRelations<TSchema>>;\n}\n\nexport function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(\n\tclient: XataHttpClient,\n\tconfig: DrizzleConfig<TSchema> = {},\n): XataHttpDatabase<TSchema> {\n\tconst dialect = new PgDialect();\n\tlet logger;\n\tif (config.logger === true) {\n\t\tlogger = new DefaultLogger();\n\t} else if (config.logger !== false) {\n\t\tlogger = config.logger;\n\t}\n\n\tlet schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;\n\tif (config.schema) {\n\t\tconst tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);\n\t\tschema = {\n\t\t\tfullSchema: config.schema,\n\t\t\tschema: tablesConfig.tables,\n\t\t\ttableNamesMap: tablesConfig.tableNamesMap,\n\t\t};\n\t}\n\n\tconst driver = new XataHttpDriver(client, dialect, { logger });\n\tconst session = driver.createSession(schema);\n\n\treturn new XataHttpDatabase(\n\t\tdialect,\n\t\tsession,\n\t\tschema as RelationalSchemaConfig<ExtractTablesWithRelations<TSchema>> | undefined,\n\t);\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAE3B,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAE1B,SAAS,6BAA6B,qCAAqC;AAG3E,SAAS,uBAAuB;AAMzB,MAAM,eAAe;AAAA,EAG3B,YACS,QACA,SACA,UAA6B,CAAC,GACrC;AAHO;AACA;AACA;AAER,SAAK,YAAY;AAAA,EAClB;AAAA,EARA,QAAiB,UAAU,IAAY;AAAA,EAUvC,cACC,QACmE;AACnE,WAAO,IAAI,gBAAgB,KAAK,QAAQ,KAAK,SAAS,QAAQ;AAAA,MAC7D,QAAQ,KAAK,QAAQ;AAAA,IACtB,CAAC;AAAA,EACF;AAAA,EAEA,cAAc;AAAA,EAEd;AACD;AAEO,MAAM,yBACJ,WACT;AAAA,EACC,QAAiB,UAAU,IAAY;AAIxC;AAEO,SAAS,QACf,QACA,SAAiC,CAAC,GACN;AAC5B,QAAM,UAAU,IAAI,UAAU;AAC9B,MAAI;AACJ,MAAI,OAAO,WAAW,MAAM;AAC3B,aAAS,IAAI,cAAc;AAAA,EAC5B,WAAW,OAAO,WAAW,OAAO;AACnC,aAAS,OAAO;AAAA,EACjB;AAEA,MAAI;AACJ,MAAI,OAAO,QAAQ;AAClB,UAAM,eAAe,8BAA8B,OAAO,QAAQ,2BAA2B;AAC7F,aAAS;AAAA,MACR,YAAY,OAAO;AAAA,MACnB,QAAQ,aAAa;AAAA,MACrB,eAAe,aAAa;AAAA,IAC7B;AAAA,EACD;AAEA,QAAM,SAAS,IAAI,eAAe,QAAQ,SAAS,EAAE,OAAO,CAAC;AAC7D,QAAM,UAAU,OAAO,cAAc,MAAM;AAE3C,SAAO,IAAI;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var xata_http_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(xata_http_exports);
|
|
18
|
+
__reExport(xata_http_exports, require("./driver.cjs"), module.exports);
|
|
19
|
+
__reExport(xata_http_exports, require("./session.cjs"), module.exports);
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require("./driver.cjs"),
|
|
23
|
+
...require("./session.cjs")
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/xata-http/index.ts"],"sourcesContent":["export * from './driver.ts';\nexport * from './session.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,8BAAc,wBAAd;AACA,8BAAc,yBADd;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/xata-http/index.ts"],"sourcesContent":["export * from './driver.ts';\nexport * from './session.ts';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var migrator_exports = {};
|
|
20
|
+
__export(migrator_exports, {
|
|
21
|
+
migrate: () => migrate
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(migrator_exports);
|
|
24
|
+
var import_migrator = require("../migrator.cjs");
|
|
25
|
+
var import_sql = require("../sql/sql.cjs");
|
|
26
|
+
async function migrate(db, config) {
|
|
27
|
+
const migrations = (0, import_migrator.readMigrationFiles)(config);
|
|
28
|
+
const migrationsTable = typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
|
29
|
+
const migrationTableCreate = import_sql.sql`
|
|
30
|
+
CREATE TABLE IF NOT EXISTS ${import_sql.sql.identifier(migrationsTable)} (
|
|
31
|
+
id SERIAL PRIMARY KEY,
|
|
32
|
+
hash text NOT NULL,
|
|
33
|
+
created_at bigint
|
|
34
|
+
)
|
|
35
|
+
`;
|
|
36
|
+
await db.session.execute(migrationTableCreate);
|
|
37
|
+
const dbMigrations = await db.session.all(
|
|
38
|
+
import_sql.sql`select id, hash, created_at from ${import_sql.sql.identifier(migrationsTable)} order by created_at desc limit 1`
|
|
39
|
+
);
|
|
40
|
+
const lastDbMigration = dbMigrations[0];
|
|
41
|
+
for await (const migration of migrations) {
|
|
42
|
+
if (!lastDbMigration || Number(lastDbMigration.created_at) < migration.folderMillis) {
|
|
43
|
+
for (const stmt of migration.sql) {
|
|
44
|
+
await db.session.execute(import_sql.sql.raw(stmt));
|
|
45
|
+
}
|
|
46
|
+
await db.session.execute(
|
|
47
|
+
import_sql.sql`insert into ${import_sql.sql.identifier(migrationsTable)} ("hash", "created_at") values(${migration.hash}, ${migration.folderMillis})`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
migrate
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=migrator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/xata-http/migrator.ts"],"sourcesContent":["import { readMigrationFiles } from '~/migrator.ts';\nimport { sql } from '~/sql/sql.ts';\nimport type { XataHttpDatabase } from './driver.ts';\n\nexport interface MigrationConfig {\n\tmigrationsFolder: string;\n\tmigrationsTable?: string;\n}\n\n/**\n * This function reads migrationFolder and execute each unapplied migration and mark it as executed in database\n *\n * NOTE: The Xata HTTP driver does not support transactions. This means that if any part of a migration fails,\n * no rollback will be executed. Currently, you will need to handle unsuccessful migration yourself.\n * @param db - drizzle db instance\n * @param config - path to migration folder generated by drizzle-kit\n */ export async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: XataHttpDatabase<TSchema>,\n\tconfig: string | MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\tconst migrationsTable = typeof config === 'string'\n\t\t? '__drizzle_migrations'\n\t\t: config.migrationsTable ?? '__drizzle_migrations';\n\tconst migrationTableCreate = sql`\n\t\tCREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (\n\t\t\tid SERIAL PRIMARY KEY,\n\t\t\thash text NOT NULL,\n\t\t\tcreated_at bigint\n\t\t)\n\t`;\n\tawait db.session.execute(migrationTableCreate);\n\n\tconst dbMigrations = await db.session.all<{\n\t\tid: number;\n\t\thash: string;\n\t\tcreated_at: string;\n\t}>(\n\t\tsql`select id, hash, created_at from ${sql.identifier(migrationsTable)} order by created_at desc limit 1`,\n\t);\n\n\tconst lastDbMigration = dbMigrations[0];\n\n\tfor await (const migration of migrations) {\n\t\tif (!lastDbMigration || Number(lastDbMigration.created_at) < migration.folderMillis) {\n\t\t\tfor (const stmt of migration.sql) {\n\t\t\t\tawait db.session.execute(sql.raw(stmt));\n\t\t\t}\n\n\t\t\tawait db.session.execute(\n\t\t\t\tsql`insert into ${\n\t\t\t\t\tsql.identifier(migrationsTable)\n\t\t\t\t} (\"hash\", \"created_at\") values(${migration.hash}, ${migration.folderMillis})`,\n\t\t\t);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAmC;AACnC,iBAAoB;AAehB,eAAsB,QACzB,IACA,QACC;AACD,QAAM,iBAAa,oCAAmB,MAAM;AAC5C,QAAM,kBAAkB,OAAO,WAAW,WACvC,yBACA,OAAO,mBAAmB;AAC7B,QAAM,uBAAuB;AAAA,+BACC,eAAI,WAAW,eAAe,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAM7D,QAAM,GAAG,QAAQ,QAAQ,oBAAoB;AAE7C,QAAM,eAAe,MAAM,GAAG,QAAQ;AAAA,IAKrC,kDAAuC,eAAI,WAAW,eAAe,CAAC;AAAA,EACvE;AAEA,QAAM,kBAAkB,aAAa,CAAC;AAEtC,mBAAiB,aAAa,YAAY;AACzC,QAAI,CAAC,mBAAmB,OAAO,gBAAgB,UAAU,IAAI,UAAU,cAAc;AACpF,iBAAW,QAAQ,UAAU,KAAK;AACjC,cAAM,GAAG,QAAQ,QAAQ,eAAI,IAAI,IAAI,CAAC;AAAA,MACvC;AAEA,YAAM,GAAG,QAAQ;AAAA,QAChB,6BACC,eAAI,WAAW,eAAe,CAC/B,kCAAkC,UAAU,IAAI,KAAK,UAAU,YAAY;AAAA,MAC5E;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { XataHttpDatabase } from "./driver.cjs";
|
|
2
|
+
export interface MigrationConfig {
|
|
3
|
+
migrationsFolder: string;
|
|
4
|
+
migrationsTable?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* This function reads migrationFolder and execute each unapplied migration and mark it as executed in database
|
|
8
|
+
*
|
|
9
|
+
* NOTE: The Xata HTTP driver does not support transactions. This means that if any part of a migration fails,
|
|
10
|
+
* no rollback will be executed. Currently, you will need to handle unsuccessful migration yourself.
|
|
11
|
+
* @param db - drizzle db instance
|
|
12
|
+
* @param config - path to migration folder generated by drizzle-kit
|
|
13
|
+
*/ export declare function migrate<TSchema extends Record<string, unknown>>(db: XataHttpDatabase<TSchema>, config: string | MigrationConfig): Promise<void>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { XataHttpDatabase } from "./driver.js";
|
|
2
|
+
export interface MigrationConfig {
|
|
3
|
+
migrationsFolder: string;
|
|
4
|
+
migrationsTable?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* This function reads migrationFolder and execute each unapplied migration and mark it as executed in database
|
|
8
|
+
*
|
|
9
|
+
* NOTE: The Xata HTTP driver does not support transactions. This means that if any part of a migration fails,
|
|
10
|
+
* no rollback will be executed. Currently, you will need to handle unsuccessful migration yourself.
|
|
11
|
+
* @param db - drizzle db instance
|
|
12
|
+
* @param config - path to migration folder generated by drizzle-kit
|
|
13
|
+
*/ export declare function migrate<TSchema extends Record<string, unknown>>(db: XataHttpDatabase<TSchema>, config: string | MigrationConfig): Promise<void>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { readMigrationFiles } from "../migrator.js";
|
|
2
|
+
import { sql } from "../sql/sql.js";
|
|
3
|
+
async function migrate(db, config) {
|
|
4
|
+
const migrations = readMigrationFiles(config);
|
|
5
|
+
const migrationsTable = typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
|
6
|
+
const migrationTableCreate = sql`
|
|
7
|
+
CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
|
|
8
|
+
id SERIAL PRIMARY KEY,
|
|
9
|
+
hash text NOT NULL,
|
|
10
|
+
created_at bigint
|
|
11
|
+
)
|
|
12
|
+
`;
|
|
13
|
+
await db.session.execute(migrationTableCreate);
|
|
14
|
+
const dbMigrations = await db.session.all(
|
|
15
|
+
sql`select id, hash, created_at from ${sql.identifier(migrationsTable)} order by created_at desc limit 1`
|
|
16
|
+
);
|
|
17
|
+
const lastDbMigration = dbMigrations[0];
|
|
18
|
+
for await (const migration of migrations) {
|
|
19
|
+
if (!lastDbMigration || Number(lastDbMigration.created_at) < migration.folderMillis) {
|
|
20
|
+
for (const stmt of migration.sql) {
|
|
21
|
+
await db.session.execute(sql.raw(stmt));
|
|
22
|
+
}
|
|
23
|
+
await db.session.execute(
|
|
24
|
+
sql`insert into ${sql.identifier(migrationsTable)} ("hash", "created_at") values(${migration.hash}, ${migration.folderMillis})`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
migrate
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=migrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/xata-http/migrator.ts"],"sourcesContent":["import { readMigrationFiles } from '~/migrator.ts';\nimport { sql } from '~/sql/sql.ts';\nimport type { XataHttpDatabase } from './driver.ts';\n\nexport interface MigrationConfig {\n\tmigrationsFolder: string;\n\tmigrationsTable?: string;\n}\n\n/**\n * This function reads migrationFolder and execute each unapplied migration and mark it as executed in database\n *\n * NOTE: The Xata HTTP driver does not support transactions. This means that if any part of a migration fails,\n * no rollback will be executed. Currently, you will need to handle unsuccessful migration yourself.\n * @param db - drizzle db instance\n * @param config - path to migration folder generated by drizzle-kit\n */ export async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: XataHttpDatabase<TSchema>,\n\tconfig: string | MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\tconst migrationsTable = typeof config === 'string'\n\t\t? '__drizzle_migrations'\n\t\t: config.migrationsTable ?? '__drizzle_migrations';\n\tconst migrationTableCreate = sql`\n\t\tCREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (\n\t\t\tid SERIAL PRIMARY KEY,\n\t\t\thash text NOT NULL,\n\t\t\tcreated_at bigint\n\t\t)\n\t`;\n\tawait db.session.execute(migrationTableCreate);\n\n\tconst dbMigrations = await db.session.all<{\n\t\tid: number;\n\t\thash: string;\n\t\tcreated_at: string;\n\t}>(\n\t\tsql`select id, hash, created_at from ${sql.identifier(migrationsTable)} order by created_at desc limit 1`,\n\t);\n\n\tconst lastDbMigration = dbMigrations[0];\n\n\tfor await (const migration of migrations) {\n\t\tif (!lastDbMigration || Number(lastDbMigration.created_at) < migration.folderMillis) {\n\t\t\tfor (const stmt of migration.sql) {\n\t\t\t\tawait db.session.execute(sql.raw(stmt));\n\t\t\t}\n\n\t\t\tawait db.session.execute(\n\t\t\t\tsql`insert into ${\n\t\t\t\t\tsql.identifier(migrationsTable)\n\t\t\t\t} (\"hash\", \"created_at\") values(${migration.hash}, ${migration.folderMillis})`,\n\t\t\t);\n\t\t}\n\t}\n}\n"],"mappings":"AAAA,SAAS,0BAA0B;AACnC,SAAS,WAAW;AAehB,eAAsB,QACzB,IACA,QACC;AACD,QAAM,aAAa,mBAAmB,MAAM;AAC5C,QAAM,kBAAkB,OAAO,WAAW,WACvC,yBACA,OAAO,mBAAmB;AAC7B,QAAM,uBAAuB;AAAA,+BACC,IAAI,WAAW,eAAe,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAM7D,QAAM,GAAG,QAAQ,QAAQ,oBAAoB;AAE7C,QAAM,eAAe,MAAM,GAAG,QAAQ;AAAA,IAKrC,uCAAuC,IAAI,WAAW,eAAe,CAAC;AAAA,EACvE;AAEA,QAAM,kBAAkB,aAAa,CAAC;AAEtC,mBAAiB,aAAa,YAAY;AACzC,QAAI,CAAC,mBAAmB,OAAO,gBAAgB,UAAU,IAAI,UAAU,cAAc;AACpF,iBAAW,QAAQ,UAAU,KAAK;AACjC,cAAM,GAAG,QAAQ,QAAQ,IAAI,IAAI,IAAI,CAAC;AAAA,MACvC;AAEA,YAAM,GAAG,QAAQ;AAAA,QAChB,kBACC,IAAI,WAAW,eAAe,CAC/B,kCAAkC,UAAU,IAAI,KAAK,UAAU,YAAY;AAAA,MAC5E;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var session_exports = {};
|
|
20
|
+
__export(session_exports, {
|
|
21
|
+
XataHttpPreparedQuery: () => XataHttpPreparedQuery,
|
|
22
|
+
XataHttpSession: () => XataHttpSession,
|
|
23
|
+
XataTransaction: () => XataTransaction
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(session_exports);
|
|
26
|
+
var import_entity = require("../entity.cjs");
|
|
27
|
+
var import_logger = require("../logger.cjs");
|
|
28
|
+
var import_pg_core = require("../pg-core/index.cjs");
|
|
29
|
+
var import_session = require("../pg-core/session.cjs");
|
|
30
|
+
var import_sql = require("../sql/sql.cjs");
|
|
31
|
+
var import_utils = require("../utils.cjs");
|
|
32
|
+
class XataHttpPreparedQuery extends import_session.PgPreparedQuery {
|
|
33
|
+
constructor(client, query, logger, fields, _isResponseInArrayMode, customResultMapper) {
|
|
34
|
+
super(query);
|
|
35
|
+
this.client = client;
|
|
36
|
+
this.logger = logger;
|
|
37
|
+
this.fields = fields;
|
|
38
|
+
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
39
|
+
this.customResultMapper = customResultMapper;
|
|
40
|
+
}
|
|
41
|
+
static [import_entity.entityKind] = "XataHttpPreparedQuery";
|
|
42
|
+
async execute(placeholderValues = {}) {
|
|
43
|
+
const params = (0, import_sql.fillPlaceholders)(this.query.params, placeholderValues);
|
|
44
|
+
this.logger.logQuery(this.query.sql, params);
|
|
45
|
+
const { fields, client, query, customResultMapper, joinsNotNullableMap } = this;
|
|
46
|
+
if (!fields && !customResultMapper) {
|
|
47
|
+
return await client.sql({ statement: query.sql, params });
|
|
48
|
+
}
|
|
49
|
+
const { rows, warning } = await client.sql({ statement: query.sql, params, responseType: "array" });
|
|
50
|
+
if (warning)
|
|
51
|
+
console.warn(warning);
|
|
52
|
+
return customResultMapper ? customResultMapper(rows) : rows.map((row) => (0, import_utils.mapResultRow)(fields, row, joinsNotNullableMap));
|
|
53
|
+
}
|
|
54
|
+
all(placeholderValues = {}) {
|
|
55
|
+
const params = (0, import_sql.fillPlaceholders)(this.query.params, placeholderValues);
|
|
56
|
+
this.logger.logQuery(this.query.sql, params);
|
|
57
|
+
return this.client.sql({ statement: this.query.sql, params, responseType: "array" }).then((result) => result.rows);
|
|
58
|
+
}
|
|
59
|
+
values(placeholderValues = {}) {
|
|
60
|
+
const params = (0, import_sql.fillPlaceholders)(this.query.params, placeholderValues);
|
|
61
|
+
this.logger.logQuery(this.query.sql, params);
|
|
62
|
+
return this.client.sql({ statement: this.query.sql, params }).then((result) => result.records);
|
|
63
|
+
}
|
|
64
|
+
/** @internal */
|
|
65
|
+
isResponseInArrayMode() {
|
|
66
|
+
return this._isResponseInArrayMode;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
class XataHttpSession extends import_session.PgSession {
|
|
70
|
+
constructor(client, dialect, schema, options = {}) {
|
|
71
|
+
super(dialect);
|
|
72
|
+
this.client = client;
|
|
73
|
+
this.schema = schema;
|
|
74
|
+
this.options = options;
|
|
75
|
+
this.logger = options.logger ?? new import_logger.NoopLogger();
|
|
76
|
+
}
|
|
77
|
+
static [import_entity.entityKind] = "XataHttpSession";
|
|
78
|
+
logger;
|
|
79
|
+
prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper) {
|
|
80
|
+
return new XataHttpPreparedQuery(
|
|
81
|
+
this.client,
|
|
82
|
+
query,
|
|
83
|
+
this.logger,
|
|
84
|
+
fields,
|
|
85
|
+
isResponseInArrayMode,
|
|
86
|
+
customResultMapper
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
async query(query, params) {
|
|
90
|
+
this.logger.logQuery(query, params);
|
|
91
|
+
const result = await this.client.sql({ statement: query, params, responseType: "array" });
|
|
92
|
+
return {
|
|
93
|
+
rowCount: result.rows.length,
|
|
94
|
+
rows: result.rows,
|
|
95
|
+
rowAsArray: true
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async queryObjects(query, params) {
|
|
99
|
+
const result = await this.client.sql({ statement: query, params });
|
|
100
|
+
return {
|
|
101
|
+
rowCount: result.records.length,
|
|
102
|
+
rows: result.records,
|
|
103
|
+
rowAsArray: false
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async transaction(_transaction, _config = {}) {
|
|
107
|
+
throw new Error("No transactions support in Xata Http driver");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
class XataTransaction extends import_pg_core.PgTransaction {
|
|
111
|
+
static [import_entity.entityKind] = "XataHttpTransaction";
|
|
112
|
+
async transaction(_transaction) {
|
|
113
|
+
throw new Error("No transactions support in Xata Http driver");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
117
|
+
0 && (module.exports = {
|
|
118
|
+
XataHttpPreparedQuery,
|
|
119
|
+
XataHttpSession,
|
|
120
|
+
XataTransaction
|
|
121
|
+
});
|
|
122
|
+
//# sourceMappingURL=session.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/xata-http/session.ts"],"sourcesContent":["import type { SQLPluginResult, SQLQueryResult } from '@xata.io/client';\nimport { entityKind } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { NoopLogger } from '~/logger.ts';\nimport type { PgDialect } from '~/pg-core/dialect.ts';\nimport { PgTransaction } from '~/pg-core/index.ts';\nimport type { SelectedFieldsOrdered } from '~/pg-core/query-builders/select.types.ts';\nimport type { PgTransactionConfig, PreparedQueryConfig, QueryResultHKT } from '~/pg-core/session.ts';\nimport { PgPreparedQuery, PgSession } from '~/pg-core/session.ts';\nimport type { RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { fillPlaceholders, type Query } from '~/sql/sql.ts';\nimport { mapResultRow } from '~/utils.ts';\n\nexport type XataHttpClient = {\n\tsql: SQLPluginResult;\n};\n\nexport interface QueryResults<ArrayMode extends 'json' | 'array'> {\n\trowCount: number;\n\trows: ArrayMode extends 'array' ? any[][] : Record<string, any>[];\n\trowAsArray: ArrayMode extends 'array' ? true : false;\n}\n\nexport class XataHttpPreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {\n\tstatic readonly [entityKind]: string = 'XataHttpPreparedQuery';\n\n\tconstructor(\n\t\tprivate client: XataHttpClient,\n\t\tquery: Query,\n\t\tprivate logger: Logger,\n\t\tprivate fields: SelectedFieldsOrdered | undefined,\n\t\tprivate _isResponseInArrayMode: boolean,\n\t\tprivate customResultMapper?: (rows: unknown[][]) => T['execute'],\n\t) {\n\t\tsuper(query);\n\t}\n\n\tasync execute(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['execute']> {\n\t\tconst params = fillPlaceholders(this.query.params, placeholderValues);\n\n\t\tthis.logger.logQuery(this.query.sql, params);\n\n\t\tconst { fields, client, query, customResultMapper, joinsNotNullableMap } = this;\n\n\t\tif (!fields && !customResultMapper) {\n\t\t\treturn await client.sql<Record<string, any>>({ statement: query.sql, params });\n\t\t\t// return { rowCount: result.records.length, rows: result.records, rowAsArray: false };\n\t\t}\n\n\t\tconst { rows, warning } = await client.sql({ statement: query.sql, params, responseType: 'array' });\n\t\tif (warning) console.warn(warning);\n\n\t\treturn customResultMapper\n\t\t\t? customResultMapper(rows as unknown[][])\n\t\t\t: rows.map((row) => mapResultRow<T['execute']>(fields!, row as unknown[], joinsNotNullableMap));\n\t}\n\n\tall(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['all']> {\n\t\tconst params = fillPlaceholders(this.query.params, placeholderValues);\n\t\tthis.logger.logQuery(this.query.sql, params);\n\t\treturn this.client.sql({ statement: this.query.sql, params, responseType: 'array' }).then((result) => result.rows);\n\t}\n\n\tvalues(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['values']> {\n\t\tconst params = fillPlaceholders(this.query.params, placeholderValues);\n\t\tthis.logger.logQuery(this.query.sql, params);\n\t\treturn this.client.sql({ statement: this.query.sql, params }).then((result) => result.records);\n\t}\n\n\t/** @internal */\n\tisResponseInArrayMode() {\n\t\treturn this._isResponseInArrayMode;\n\t}\n}\n\nexport interface XataHttpSessionOptions {\n\tlogger?: Logger;\n}\n\nexport class XataHttpSession<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig>\n\textends PgSession<\n\t\tXataHttpQueryResultHKT,\n\t\tTFullSchema,\n\t\tTSchema\n\t>\n{\n\tstatic readonly [entityKind]: string = 'XataHttpSession';\n\n\tprivate logger: Logger;\n\n\tconstructor(\n\t\tprivate client: XataHttpClient,\n\t\tdialect: PgDialect,\n\t\tprivate schema: RelationalSchemaConfig<TSchema> | undefined,\n\t\tprivate options: XataHttpSessionOptions = {},\n\t) {\n\t\tsuper(dialect);\n\t\tthis.logger = options.logger ?? new NoopLogger();\n\t}\n\n\tprepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tisResponseInArrayMode: boolean,\n\t\tcustomResultMapper?: (rows: unknown[][]) => T['execute'],\n\t): PgPreparedQuery<T> {\n\t\treturn new XataHttpPreparedQuery(\n\t\t\tthis.client,\n\t\t\tquery,\n\t\t\tthis.logger,\n\t\t\tfields,\n\t\t\tisResponseInArrayMode,\n\t\t\tcustomResultMapper,\n\t\t);\n\t}\n\n\tasync query(query: string, params: unknown[]): Promise<QueryResults<'array'>> {\n\t\tthis.logger.logQuery(query, params);\n\t\tconst result = await this.client.sql({ statement: query, params, responseType: 'array' });\n\n\t\treturn {\n\t\t\trowCount: result.rows.length,\n\t\t\trows: result.rows,\n\t\t\trowAsArray: true,\n\t\t};\n\t}\n\n\tasync queryObjects(query: string, params: unknown[]): Promise<QueryResults<'json'>> {\n\t\tconst result = await this.client.sql<Record<string, any>>({ statement: query, params });\n\n\t\treturn {\n\t\t\trowCount: result.records.length,\n\t\t\trows: result.records,\n\t\t\trowAsArray: false,\n\t\t};\n\t}\n\n\toverride async transaction<T>(\n\t\t_transaction: (tx: XataTransaction<TFullSchema, TSchema>) => Promise<T>,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t_config: PgTransactionConfig = {},\n\t): Promise<T> {\n\t\tthrow new Error('No transactions support in Xata Http driver');\n\t}\n}\n\nexport class XataTransaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig>\n\textends PgTransaction<\n\t\tXataHttpQueryResultHKT,\n\t\tTFullSchema,\n\t\tTSchema\n\t>\n{\n\tstatic readonly [entityKind]: string = 'XataHttpTransaction';\n\n\toverride async transaction<T>(_transaction: (tx: XataTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T> {\n\t\tthrow new Error('No transactions support in Xata Http driver');\n\t}\n}\n\nexport interface XataHttpQueryResultHKT extends QueryResultHKT {\n\ttype: SQLQueryResult<this['row']>;\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { SQLPluginResult, SQLQueryResult } from '@xata.io/client';
|
|
2
|
+
import { entityKind } from "../entity.cjs";
|
|
3
|
+
import type { Logger } from "../logger.cjs";
|
|
4
|
+
import type { PgDialect } from "../pg-core/dialect.cjs";
|
|
5
|
+
import { PgTransaction } from "../pg-core/index.cjs";
|
|
6
|
+
import type { SelectedFieldsOrdered } from "../pg-core/query-builders/select.types.cjs";
|
|
7
|
+
import type { PgTransactionConfig, PreparedQueryConfig, QueryResultHKT } from "../pg-core/session.cjs";
|
|
8
|
+
import { PgPreparedQuery, PgSession } from "../pg-core/session.cjs";
|
|
9
|
+
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.cjs";
|
|
10
|
+
import { type Query } from "../sql/sql.cjs";
|
|
11
|
+
export type XataHttpClient = {
|
|
12
|
+
sql: SQLPluginResult;
|
|
13
|
+
};
|
|
14
|
+
export interface QueryResults<ArrayMode extends 'json' | 'array'> {
|
|
15
|
+
rowCount: number;
|
|
16
|
+
rows: ArrayMode extends 'array' ? any[][] : Record<string, any>[];
|
|
17
|
+
rowAsArray: ArrayMode extends 'array' ? true : false;
|
|
18
|
+
}
|
|
19
|
+
export declare class XataHttpPreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {
|
|
20
|
+
private client;
|
|
21
|
+
private logger;
|
|
22
|
+
private fields;
|
|
23
|
+
private _isResponseInArrayMode;
|
|
24
|
+
private customResultMapper?;
|
|
25
|
+
static readonly [entityKind]: string;
|
|
26
|
+
constructor(client: XataHttpClient, query: Query, logger: Logger, fields: SelectedFieldsOrdered | undefined, _isResponseInArrayMode: boolean, customResultMapper?: ((rows: unknown[][]) => T['execute']) | undefined);
|
|
27
|
+
execute(placeholderValues?: Record<string, unknown> | undefined): Promise<T['execute']>;
|
|
28
|
+
all(placeholderValues?: Record<string, unknown> | undefined): Promise<T['all']>;
|
|
29
|
+
values(placeholderValues?: Record<string, unknown> | undefined): Promise<T['values']>;
|
|
30
|
+
}
|
|
31
|
+
export interface XataHttpSessionOptions {
|
|
32
|
+
logger?: Logger;
|
|
33
|
+
}
|
|
34
|
+
export declare class XataHttpSession<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgSession<XataHttpQueryResultHKT, TFullSchema, TSchema> {
|
|
35
|
+
private client;
|
|
36
|
+
private schema;
|
|
37
|
+
private options;
|
|
38
|
+
static readonly [entityKind]: string;
|
|
39
|
+
private logger;
|
|
40
|
+
constructor(client: XataHttpClient, dialect: PgDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options?: XataHttpSessionOptions);
|
|
41
|
+
prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, name: string | undefined, isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => T['execute']): PgPreparedQuery<T>;
|
|
42
|
+
query(query: string, params: unknown[]): Promise<QueryResults<'array'>>;
|
|
43
|
+
queryObjects(query: string, params: unknown[]): Promise<QueryResults<'json'>>;
|
|
44
|
+
transaction<T>(_transaction: (tx: XataTransaction<TFullSchema, TSchema>) => Promise<T>, _config?: PgTransactionConfig): Promise<T>;
|
|
45
|
+
}
|
|
46
|
+
export declare class XataTransaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgTransaction<XataHttpQueryResultHKT, TFullSchema, TSchema> {
|
|
47
|
+
static readonly [entityKind]: string;
|
|
48
|
+
transaction<T>(_transaction: (tx: XataTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
|
|
49
|
+
}
|
|
50
|
+
export interface XataHttpQueryResultHKT extends QueryResultHKT {
|
|
51
|
+
type: SQLQueryResult<this['row']>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { SQLPluginResult, SQLQueryResult } from '@xata.io/client';
|
|
2
|
+
import { entityKind } from "../entity.js";
|
|
3
|
+
import type { Logger } from "../logger.js";
|
|
4
|
+
import type { PgDialect } from "../pg-core/dialect.js";
|
|
5
|
+
import { PgTransaction } from "../pg-core/index.js";
|
|
6
|
+
import type { SelectedFieldsOrdered } from "../pg-core/query-builders/select.types.js";
|
|
7
|
+
import type { PgTransactionConfig, PreparedQueryConfig, QueryResultHKT } from "../pg-core/session.js";
|
|
8
|
+
import { PgPreparedQuery, PgSession } from "../pg-core/session.js";
|
|
9
|
+
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.js";
|
|
10
|
+
import { type Query } from "../sql/sql.js";
|
|
11
|
+
export type XataHttpClient = {
|
|
12
|
+
sql: SQLPluginResult;
|
|
13
|
+
};
|
|
14
|
+
export interface QueryResults<ArrayMode extends 'json' | 'array'> {
|
|
15
|
+
rowCount: number;
|
|
16
|
+
rows: ArrayMode extends 'array' ? any[][] : Record<string, any>[];
|
|
17
|
+
rowAsArray: ArrayMode extends 'array' ? true : false;
|
|
18
|
+
}
|
|
19
|
+
export declare class XataHttpPreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {
|
|
20
|
+
private client;
|
|
21
|
+
private logger;
|
|
22
|
+
private fields;
|
|
23
|
+
private _isResponseInArrayMode;
|
|
24
|
+
private customResultMapper?;
|
|
25
|
+
static readonly [entityKind]: string;
|
|
26
|
+
constructor(client: XataHttpClient, query: Query, logger: Logger, fields: SelectedFieldsOrdered | undefined, _isResponseInArrayMode: boolean, customResultMapper?: ((rows: unknown[][]) => T['execute']) | undefined);
|
|
27
|
+
execute(placeholderValues?: Record<string, unknown> | undefined): Promise<T['execute']>;
|
|
28
|
+
all(placeholderValues?: Record<string, unknown> | undefined): Promise<T['all']>;
|
|
29
|
+
values(placeholderValues?: Record<string, unknown> | undefined): Promise<T['values']>;
|
|
30
|
+
}
|
|
31
|
+
export interface XataHttpSessionOptions {
|
|
32
|
+
logger?: Logger;
|
|
33
|
+
}
|
|
34
|
+
export declare class XataHttpSession<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgSession<XataHttpQueryResultHKT, TFullSchema, TSchema> {
|
|
35
|
+
private client;
|
|
36
|
+
private schema;
|
|
37
|
+
private options;
|
|
38
|
+
static readonly [entityKind]: string;
|
|
39
|
+
private logger;
|
|
40
|
+
constructor(client: XataHttpClient, dialect: PgDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options?: XataHttpSessionOptions);
|
|
41
|
+
prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, name: string | undefined, isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => T['execute']): PgPreparedQuery<T>;
|
|
42
|
+
query(query: string, params: unknown[]): Promise<QueryResults<'array'>>;
|
|
43
|
+
queryObjects(query: string, params: unknown[]): Promise<QueryResults<'json'>>;
|
|
44
|
+
transaction<T>(_transaction: (tx: XataTransaction<TFullSchema, TSchema>) => Promise<T>, _config?: PgTransactionConfig): Promise<T>;
|
|
45
|
+
}
|
|
46
|
+
export declare class XataTransaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgTransaction<XataHttpQueryResultHKT, TFullSchema, TSchema> {
|
|
47
|
+
static readonly [entityKind]: string;
|
|
48
|
+
transaction<T>(_transaction: (tx: XataTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
|
|
49
|
+
}
|
|
50
|
+
export interface XataHttpQueryResultHKT extends QueryResultHKT {
|
|
51
|
+
type: SQLQueryResult<this['row']>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { entityKind } from "../entity.js";
|
|
2
|
+
import { NoopLogger } from "../logger.js";
|
|
3
|
+
import { PgTransaction } from "../pg-core/index.js";
|
|
4
|
+
import { PgPreparedQuery, PgSession } from "../pg-core/session.js";
|
|
5
|
+
import { fillPlaceholders } from "../sql/sql.js";
|
|
6
|
+
import { mapResultRow } from "../utils.js";
|
|
7
|
+
class XataHttpPreparedQuery extends PgPreparedQuery {
|
|
8
|
+
constructor(client, query, logger, fields, _isResponseInArrayMode, customResultMapper) {
|
|
9
|
+
super(query);
|
|
10
|
+
this.client = client;
|
|
11
|
+
this.logger = logger;
|
|
12
|
+
this.fields = fields;
|
|
13
|
+
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
14
|
+
this.customResultMapper = customResultMapper;
|
|
15
|
+
}
|
|
16
|
+
static [entityKind] = "XataHttpPreparedQuery";
|
|
17
|
+
async execute(placeholderValues = {}) {
|
|
18
|
+
const params = fillPlaceholders(this.query.params, placeholderValues);
|
|
19
|
+
this.logger.logQuery(this.query.sql, params);
|
|
20
|
+
const { fields, client, query, customResultMapper, joinsNotNullableMap } = this;
|
|
21
|
+
if (!fields && !customResultMapper) {
|
|
22
|
+
return await client.sql({ statement: query.sql, params });
|
|
23
|
+
}
|
|
24
|
+
const { rows, warning } = await client.sql({ statement: query.sql, params, responseType: "array" });
|
|
25
|
+
if (warning)
|
|
26
|
+
console.warn(warning);
|
|
27
|
+
return customResultMapper ? customResultMapper(rows) : rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
|
|
28
|
+
}
|
|
29
|
+
all(placeholderValues = {}) {
|
|
30
|
+
const params = fillPlaceholders(this.query.params, placeholderValues);
|
|
31
|
+
this.logger.logQuery(this.query.sql, params);
|
|
32
|
+
return this.client.sql({ statement: this.query.sql, params, responseType: "array" }).then((result) => result.rows);
|
|
33
|
+
}
|
|
34
|
+
values(placeholderValues = {}) {
|
|
35
|
+
const params = fillPlaceholders(this.query.params, placeholderValues);
|
|
36
|
+
this.logger.logQuery(this.query.sql, params);
|
|
37
|
+
return this.client.sql({ statement: this.query.sql, params }).then((result) => result.records);
|
|
38
|
+
}
|
|
39
|
+
/** @internal */
|
|
40
|
+
isResponseInArrayMode() {
|
|
41
|
+
return this._isResponseInArrayMode;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
class XataHttpSession extends PgSession {
|
|
45
|
+
constructor(client, dialect, schema, options = {}) {
|
|
46
|
+
super(dialect);
|
|
47
|
+
this.client = client;
|
|
48
|
+
this.schema = schema;
|
|
49
|
+
this.options = options;
|
|
50
|
+
this.logger = options.logger ?? new NoopLogger();
|
|
51
|
+
}
|
|
52
|
+
static [entityKind] = "XataHttpSession";
|
|
53
|
+
logger;
|
|
54
|
+
prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper) {
|
|
55
|
+
return new XataHttpPreparedQuery(
|
|
56
|
+
this.client,
|
|
57
|
+
query,
|
|
58
|
+
this.logger,
|
|
59
|
+
fields,
|
|
60
|
+
isResponseInArrayMode,
|
|
61
|
+
customResultMapper
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
async query(query, params) {
|
|
65
|
+
this.logger.logQuery(query, params);
|
|
66
|
+
const result = await this.client.sql({ statement: query, params, responseType: "array" });
|
|
67
|
+
return {
|
|
68
|
+
rowCount: result.rows.length,
|
|
69
|
+
rows: result.rows,
|
|
70
|
+
rowAsArray: true
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async queryObjects(query, params) {
|
|
74
|
+
const result = await this.client.sql({ statement: query, params });
|
|
75
|
+
return {
|
|
76
|
+
rowCount: result.records.length,
|
|
77
|
+
rows: result.records,
|
|
78
|
+
rowAsArray: false
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async transaction(_transaction, _config = {}) {
|
|
82
|
+
throw new Error("No transactions support in Xata Http driver");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
class XataTransaction extends PgTransaction {
|
|
86
|
+
static [entityKind] = "XataHttpTransaction";
|
|
87
|
+
async transaction(_transaction) {
|
|
88
|
+
throw new Error("No transactions support in Xata Http driver");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
XataHttpPreparedQuery,
|
|
93
|
+
XataHttpSession,
|
|
94
|
+
XataTransaction
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/xata-http/session.ts"],"sourcesContent":["import type { SQLPluginResult, SQLQueryResult } from '@xata.io/client';\nimport { entityKind } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { NoopLogger } from '~/logger.ts';\nimport type { PgDialect } from '~/pg-core/dialect.ts';\nimport { PgTransaction } from '~/pg-core/index.ts';\nimport type { SelectedFieldsOrdered } from '~/pg-core/query-builders/select.types.ts';\nimport type { PgTransactionConfig, PreparedQueryConfig, QueryResultHKT } from '~/pg-core/session.ts';\nimport { PgPreparedQuery, PgSession } from '~/pg-core/session.ts';\nimport type { RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { fillPlaceholders, type Query } from '~/sql/sql.ts';\nimport { mapResultRow } from '~/utils.ts';\n\nexport type XataHttpClient = {\n\tsql: SQLPluginResult;\n};\n\nexport interface QueryResults<ArrayMode extends 'json' | 'array'> {\n\trowCount: number;\n\trows: ArrayMode extends 'array' ? any[][] : Record<string, any>[];\n\trowAsArray: ArrayMode extends 'array' ? true : false;\n}\n\nexport class XataHttpPreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {\n\tstatic readonly [entityKind]: string = 'XataHttpPreparedQuery';\n\n\tconstructor(\n\t\tprivate client: XataHttpClient,\n\t\tquery: Query,\n\t\tprivate logger: Logger,\n\t\tprivate fields: SelectedFieldsOrdered | undefined,\n\t\tprivate _isResponseInArrayMode: boolean,\n\t\tprivate customResultMapper?: (rows: unknown[][]) => T['execute'],\n\t) {\n\t\tsuper(query);\n\t}\n\n\tasync execute(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['execute']> {\n\t\tconst params = fillPlaceholders(this.query.params, placeholderValues);\n\n\t\tthis.logger.logQuery(this.query.sql, params);\n\n\t\tconst { fields, client, query, customResultMapper, joinsNotNullableMap } = this;\n\n\t\tif (!fields && !customResultMapper) {\n\t\t\treturn await client.sql<Record<string, any>>({ statement: query.sql, params });\n\t\t\t// return { rowCount: result.records.length, rows: result.records, rowAsArray: false };\n\t\t}\n\n\t\tconst { rows, warning } = await client.sql({ statement: query.sql, params, responseType: 'array' });\n\t\tif (warning) console.warn(warning);\n\n\t\treturn customResultMapper\n\t\t\t? customResultMapper(rows as unknown[][])\n\t\t\t: rows.map((row) => mapResultRow<T['execute']>(fields!, row as unknown[], joinsNotNullableMap));\n\t}\n\n\tall(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['all']> {\n\t\tconst params = fillPlaceholders(this.query.params, placeholderValues);\n\t\tthis.logger.logQuery(this.query.sql, params);\n\t\treturn this.client.sql({ statement: this.query.sql, params, responseType: 'array' }).then((result) => result.rows);\n\t}\n\n\tvalues(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['values']> {\n\t\tconst params = fillPlaceholders(this.query.params, placeholderValues);\n\t\tthis.logger.logQuery(this.query.sql, params);\n\t\treturn this.client.sql({ statement: this.query.sql, params }).then((result) => result.records);\n\t}\n\n\t/** @internal */\n\tisResponseInArrayMode() {\n\t\treturn this._isResponseInArrayMode;\n\t}\n}\n\nexport interface XataHttpSessionOptions {\n\tlogger?: Logger;\n}\n\nexport class XataHttpSession<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig>\n\textends PgSession<\n\t\tXataHttpQueryResultHKT,\n\t\tTFullSchema,\n\t\tTSchema\n\t>\n{\n\tstatic readonly [entityKind]: string = 'XataHttpSession';\n\n\tprivate logger: Logger;\n\n\tconstructor(\n\t\tprivate client: XataHttpClient,\n\t\tdialect: PgDialect,\n\t\tprivate schema: RelationalSchemaConfig<TSchema> | undefined,\n\t\tprivate options: XataHttpSessionOptions = {},\n\t) {\n\t\tsuper(dialect);\n\t\tthis.logger = options.logger ?? new NoopLogger();\n\t}\n\n\tprepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tisResponseInArrayMode: boolean,\n\t\tcustomResultMapper?: (rows: unknown[][]) => T['execute'],\n\t): PgPreparedQuery<T> {\n\t\treturn new XataHttpPreparedQuery(\n\t\t\tthis.client,\n\t\t\tquery,\n\t\t\tthis.logger,\n\t\t\tfields,\n\t\t\tisResponseInArrayMode,\n\t\t\tcustomResultMapper,\n\t\t);\n\t}\n\n\tasync query(query: string, params: unknown[]): Promise<QueryResults<'array'>> {\n\t\tthis.logger.logQuery(query, params);\n\t\tconst result = await this.client.sql({ statement: query, params, responseType: 'array' });\n\n\t\treturn {\n\t\t\trowCount: result.rows.length,\n\t\t\trows: result.rows,\n\t\t\trowAsArray: true,\n\t\t};\n\t}\n\n\tasync queryObjects(query: string, params: unknown[]): Promise<QueryResults<'json'>> {\n\t\tconst result = await this.client.sql<Record<string, any>>({ statement: query, params });\n\n\t\treturn {\n\t\t\trowCount: result.records.length,\n\t\t\trows: result.records,\n\t\t\trowAsArray: false,\n\t\t};\n\t}\n\n\toverride async transaction<T>(\n\t\t_transaction: (tx: XataTransaction<TFullSchema, TSchema>) => Promise<T>,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t_config: PgTransactionConfig = {},\n\t): Promise<T> {\n\t\tthrow new Error('No transactions support in Xata Http driver');\n\t}\n}\n\nexport class XataTransaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig>\n\textends PgTransaction<\n\t\tXataHttpQueryResultHKT,\n\t\tTFullSchema,\n\t\tTSchema\n\t>\n{\n\tstatic readonly [entityKind]: string = 'XataHttpTransaction';\n\n\toverride async transaction<T>(_transaction: (tx: XataTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T> {\n\t\tthrow new Error('No transactions support in Xata Http driver');\n\t}\n}\n\nexport interface XataHttpQueryResultHKT extends QueryResultHKT {\n\ttype: SQLQueryResult<this['row']>;\n}\n"],"mappings":"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","names":[]}
|