feat: Upgrade to Astro with full PDPA compliance
PDPA Features: ✅ Cookie consent banner ✅ Consent logging API ✅ Admin dashboard ✅ Privacy Policy ✅ Terms & Conditions Technical: ✅ Astro 5.x + Tailwind v4 ✅ Docker on port 80 ✅ SQLite database ✅ 15 pages built Ready for Easypanel deployment.
This commit is contained in:
1 parent
668f69048f
commit
77ac4d2d05
13719 files changed
+307487
-25765
No files matched your search
+111
@@ -0,0 +1,111 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var driver_exports = {};
|
||||
__export(driver_exports, {
|
||||
PgliteDatabase: () => PgliteDatabase,
|
||||
PgliteDriver: () => PgliteDriver,
|
||||
drizzle: () => drizzle
|
||||
});
|
||||
module.exports = __toCommonJS(driver_exports);
|
||||
var import_pglite = require("@electric-sql/pglite");
|
||||
var import_entity = require("../entity.cjs");
|
||||
var import_logger = require("../logger.cjs");
|
||||
var import_db = require("../pg-core/db.cjs");
|
||||
var import_dialect = require("../pg-core/dialect.cjs");
|
||||
var import_relations = require("../relations.cjs");
|
||||
var import_utils = require("../utils.cjs");
|
||||
var import_session = require("./session.cjs");
|
||||
class PgliteDriver {
|
||||
constructor(client, dialect, options = {}) {
|
||||
this.client = client;
|
||||
this.dialect = dialect;
|
||||
this.options = options;
|
||||
}
|
||||
static [import_entity.entityKind] = "PgliteDriver";
|
||||
createSession(schema) {
|
||||
return new import_session.PgliteSession(this.client, this.dialect, schema, {
|
||||
logger: this.options.logger,
|
||||
cache: this.options.cache
|
||||
});
|
||||
}
|
||||
}
|
||||
class PgliteDatabase extends import_db.PgDatabase {
|
||||
static [import_entity.entityKind] = "PgliteDatabase";
|
||||
}
|
||||
function construct(client, config = {}) {
|
||||
const dialect = new import_dialect.PgDialect({ casing: config.casing });
|
||||
let logger;
|
||||
if (config.logger === true) {
|
||||
logger = new import_logger.DefaultLogger();
|
||||
} else if (config.logger !== false) {
|
||||
logger = config.logger;
|
||||
}
|
||||
let schema;
|
||||
if (config.schema) {
|
||||
const tablesConfig = (0, import_relations.extractTablesRelationalConfig)(
|
||||
config.schema,
|
||||
import_relations.createTableRelationsHelpers
|
||||
);
|
||||
schema = {
|
||||
fullSchema: config.schema,
|
||||
schema: tablesConfig.tables,
|
||||
tableNamesMap: tablesConfig.tableNamesMap
|
||||
};
|
||||
}
|
||||
const driver = new PgliteDriver(client, dialect, { logger, cache: config.cache });
|
||||
const session = driver.createSession(schema);
|
||||
const db = new PgliteDatabase(dialect, session, schema);
|
||||
db.$client = client;
|
||||
db.$cache = config.cache;
|
||||
if (db.$cache) {
|
||||
db.$cache["invalidate"] = config.cache?.onMutate;
|
||||
}
|
||||
return db;
|
||||
}
|
||||
function drizzle(...params) {
|
||||
if (params[0] === void 0 || typeof params[0] === "string") {
|
||||
const instance = new import_pglite.PGlite(params[0]);
|
||||
return construct(instance, params[1]);
|
||||
}
|
||||
if ((0, import_utils.isConfig)(params[0])) {
|
||||
const { connection, client, ...drizzleConfig } = params[0];
|
||||
if (client) return construct(client, drizzleConfig);
|
||||
if (typeof connection === "object") {
|
||||
const { dataDir, ...options } = connection;
|
||||
const instance2 = new import_pglite.PGlite(dataDir, options);
|
||||
return construct(instance2, drizzleConfig);
|
||||
}
|
||||
const instance = new import_pglite.PGlite(connection);
|
||||
return construct(instance, drizzleConfig);
|
||||
}
|
||||
return construct(params[0], params[1]);
|
||||
}
|
||||
((drizzle2) => {
|
||||
function mock(config) {
|
||||
return construct({}, config);
|
||||
}
|
||||
drizzle2.mock = mock;
|
||||
})(drizzle || (drizzle = {}));
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
PgliteDatabase,
|
||||
PgliteDriver,
|
||||
drizzle
|
||||
});
|
||||
//# sourceMappingURL=driver.cjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/pglite/driver.ts"],"sourcesContent":["import { PGlite, type PGliteOptions } from '@electric-sql/pglite';\nimport type { Cache } from '~/cache/core/cache.ts';\nimport { 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 {\n\tcreateTableRelationsHelpers,\n\textractTablesRelationalConfig,\n\ttype RelationalSchemaConfig,\n\ttype TablesRelationalConfig,\n} from '~/relations.ts';\nimport { type DrizzleConfig, isConfig } from '~/utils.ts';\nimport type { PgliteClient, PgliteQueryResultHKT } from './session.ts';\nimport { PgliteSession } from './session.ts';\n\nexport interface PgDriverOptions {\n\tlogger?: Logger;\n\tcache?: Cache;\n}\n\nexport class PgliteDriver {\n\tstatic readonly [entityKind]: string = 'PgliteDriver';\n\n\tconstructor(\n\t\tprivate client: PgliteClient,\n\t\tprivate dialect: PgDialect,\n\t\tprivate options: PgDriverOptions = {},\n\t) {\n\t}\n\n\tcreateSession(\n\t\tschema: RelationalSchemaConfig<TablesRelationalConfig> | undefined,\n\t): PgliteSession<Record<string, unknown>, TablesRelationalConfig> {\n\t\treturn new PgliteSession(this.client, this.dialect, schema, {\n\t\t\tlogger: this.options.logger,\n\t\t\tcache: this.options.cache,\n\t\t});\n\t}\n}\n\nexport class PgliteDatabase<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n> extends PgDatabase<PgliteQueryResultHKT, TSchema> {\n\tstatic override readonly [entityKind]: string = 'PgliteDatabase';\n}\n\nfunction construct<TSchema extends Record<string, unknown> = Record<string, never>>(\n\tclient: PgliteClient,\n\tconfig: DrizzleConfig<TSchema> = {},\n): PgliteDatabase<TSchema> & {\n\t$client: PgliteClient;\n} {\n\tconst dialect = new PgDialect({ casing: config.casing });\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(\n\t\t\tconfig.schema,\n\t\t\tcreateTableRelationsHelpers,\n\t\t);\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 PgliteDriver(client, dialect, { logger, cache: config.cache });\n\tconst session = driver.createSession(schema);\n\tconst db = new PgliteDatabase(dialect, session, schema as any) as PgliteDatabase<TSchema>;\n\t(<any> db).$client = client;\n\t(<any> db).$cache = config.cache;\n\tif ((<any> db).$cache) {\n\t\t(<any> db).$cache['invalidate'] = config.cache?.onMutate;\n\t}\n\t// (<any> db).$cache = { invalidate: (<any> config).cache?.onMutate };\n\t// if (config.cache) {\n\t// \tfor (\n\t// \t\tconst key of Object.getOwnPropertyNames(Object.getPrototypeOf(config.cache)).filter((key) =>\n\t// \t\t\tkey !== 'constructor'\n\t// \t\t)\n\t// \t) {\n\t// \t\t(<any> db).$cache[key as keyof typeof config.cache] = (<any> config).cache[key];\n\t// \t}\n\t// }\n\n\treturn db as any;\n}\n\nexport function drizzle<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTClient extends PGlite = PGlite,\n>(\n\t...params:\n\t\t| []\n\t\t| [\n\t\t\tTClient | string,\n\t\t]\n\t\t| [\n\t\t\tTClient | string,\n\t\t\tDrizzleConfig<TSchema>,\n\t\t]\n\t\t| [\n\t\t\t(\n\t\t\t\t& DrizzleConfig<TSchema>\n\t\t\t\t& ({\n\t\t\t\t\tconnection?: (PGliteOptions & { dataDir?: string }) | string;\n\t\t\t\t} | {\n\t\t\t\t\tclient: TClient;\n\t\t\t\t})\n\t\t\t),\n\t\t]\n): PgliteDatabase<TSchema> & {\n\t$client: TClient;\n} {\n\tif (params[0] === undefined || typeof params[0] === 'string') {\n\t\tconst instance = new PGlite(params[0]);\n\t\treturn construct(instance, params[1]) as any;\n\t}\n\n\tif (isConfig(params[0])) {\n\t\tconst { connection, client, ...drizzleConfig } = params[0] as {\n\t\t\tconnection?: PGliteOptions & { dataDir: string };\n\t\t\tclient?: TClient;\n\t\t} & DrizzleConfig<TSchema>;\n\n\t\tif (client) return construct(client, drizzleConfig) as any;\n\n\t\tif (typeof connection === 'object') {\n\t\t\tconst { dataDir, ...options } = connection;\n\n\t\t\tconst instance = new PGlite(dataDir, options);\n\n\t\t\treturn construct(instance, drizzleConfig) as any;\n\t\t}\n\n\t\tconst instance = new PGlite(connection);\n\n\t\treturn construct(instance, drizzleConfig) as any;\n\t}\n\n\treturn construct(params[0] as TClient, params[1] as DrizzleConfig<TSchema> | undefined) as any;\n}\n\nexport namespace drizzle {\n\texport function mock<TSchema extends Record<string, unknown> = Record<string, never>>(\n\t\tconfig?: DrizzleConfig<TSchema>,\n\t): PgliteDatabase<TSchema> & {\n\t\t$client: '$client is not available on drizzle.mock()';\n\t} {\n\t\treturn construct({} as any, config) as any;\n\t}\n}\n"],"mappings":";;;Line truncated
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
import { PGlite, type PGliteOptions } from '@electric-sql/pglite';
|
||||
import type { Cache } from "../cache/core/cache.cjs";
|
||||
import { entityKind } from "../entity.cjs";
|
||||
import type { Logger } from "../logger.cjs";
|
||||
import { PgDatabase } from "../pg-core/db.cjs";
|
||||
import { PgDialect } from "../pg-core/dialect.cjs";
|
||||
import { type RelationalSchemaConfig, type TablesRelationalConfig } from "../relations.cjs";
|
||||
import { type DrizzleConfig } from "../utils.cjs";
|
||||
import type { PgliteClient, PgliteQueryResultHKT } from "./session.cjs";
|
||||
import { PgliteSession } from "./session.cjs";
|
||||
export interface PgDriverOptions {
|
||||
logger?: Logger;
|
||||
cache?: Cache;
|
||||
}
|
||||
export declare class PgliteDriver {
|
||||
private client;
|
||||
private dialect;
|
||||
private options;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(client: PgliteClient, dialect: PgDialect, options?: PgDriverOptions);
|
||||
createSession(schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined): PgliteSession<Record<string, unknown>, TablesRelationalConfig>;
|
||||
}
|
||||
export declare class PgliteDatabase<TSchema extends Record<string, unknown> = Record<string, never>> extends PgDatabase<PgliteQueryResultHKT, TSchema> {
|
||||
static readonly [entityKind]: string;
|
||||
}
|
||||
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>, TClient extends PGlite = PGlite>(...params: [] | [
|
||||
TClient | string
|
||||
] | [
|
||||
TClient | string,
|
||||
DrizzleConfig<TSchema>
|
||||
] | [
|
||||
(DrizzleConfig<TSchema> & ({
|
||||
connection?: (PGliteOptions & {
|
||||
dataDir?: string;
|
||||
}) | string;
|
||||
} | {
|
||||
client: TClient;
|
||||
}))
|
||||
]): PgliteDatabase<TSchema> & {
|
||||
$client: TClient;
|
||||
};
|
||||
export declare namespace drizzle {
|
||||
function mock<TSchema extends Record<string, unknown> = Record<string, never>>(config?: DrizzleConfig<TSchema>): PgliteDatabase<TSchema> & {
|
||||
$client: '$client is not available on drizzle.mock()';
|
||||
};
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
import { PGlite, type PGliteOptions } from '@electric-sql/pglite';
|
||||
import type { Cache } from "../cache/core/cache.js";
|
||||
import { entityKind } from "../entity.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { PgDatabase } from "../pg-core/db.js";
|
||||
import { PgDialect } from "../pg-core/dialect.js";
|
||||
import { type RelationalSchemaConfig, type TablesRelationalConfig } from "../relations.js";
|
||||
import { type DrizzleConfig } from "../utils.js";
|
||||
import type { PgliteClient, PgliteQueryResultHKT } from "./session.js";
|
||||
import { PgliteSession } from "./session.js";
|
||||
export interface PgDriverOptions {
|
||||
logger?: Logger;
|
||||
cache?: Cache;
|
||||
}
|
||||
export declare class PgliteDriver {
|
||||
private client;
|
||||
private dialect;
|
||||
private options;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(client: PgliteClient, dialect: PgDialect, options?: PgDriverOptions);
|
||||
createSession(schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined): PgliteSession<Record<string, unknown>, TablesRelationalConfig>;
|
||||
}
|
||||
export declare class PgliteDatabase<TSchema extends Record<string, unknown> = Record<string, never>> extends PgDatabase<PgliteQueryResultHKT, TSchema> {
|
||||
static readonly [entityKind]: string;
|
||||
}
|
||||
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>, TClient extends PGlite = PGlite>(...params: [] | [
|
||||
TClient | string
|
||||
] | [
|
||||
TClient | string,
|
||||
DrizzleConfig<TSchema>
|
||||
] | [
|
||||
(DrizzleConfig<TSchema> & ({
|
||||
connection?: (PGliteOptions & {
|
||||
dataDir?: string;
|
||||
}) | string;
|
||||
} | {
|
||||
client: TClient;
|
||||
}))
|
||||
]): PgliteDatabase<TSchema> & {
|
||||
$client: TClient;
|
||||
};
|
||||
export declare namespace drizzle {
|
||||
function mock<TSchema extends Record<string, unknown> = Record<string, never>>(config?: DrizzleConfig<TSchema>): PgliteDatabase<TSchema> & {
|
||||
$client: '$client is not available on drizzle.mock()';
|
||||
};
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
import { PGlite } from "@electric-sql/pglite";
|
||||
import { entityKind } from "../entity.js";
|
||||
import { DefaultLogger } from "../logger.js";
|
||||
import { PgDatabase } from "../pg-core/db.js";
|
||||
import { PgDialect } from "../pg-core/dialect.js";
|
||||
import {
|
||||
createTableRelationsHelpers,
|
||||
extractTablesRelationalConfig
|
||||
} from "../relations.js";
|
||||
import { isConfig } from "../utils.js";
|
||||
import { PgliteSession } from "./session.js";
|
||||
class PgliteDriver {
|
||||
constructor(client, dialect, options = {}) {
|
||||
this.client = client;
|
||||
this.dialect = dialect;
|
||||
this.options = options;
|
||||
}
|
||||
static [entityKind] = "PgliteDriver";
|
||||
createSession(schema) {
|
||||
return new PgliteSession(this.client, this.dialect, schema, {
|
||||
logger: this.options.logger,
|
||||
cache: this.options.cache
|
||||
});
|
||||
}
|
||||
}
|
||||
class PgliteDatabase extends PgDatabase {
|
||||
static [entityKind] = "PgliteDatabase";
|
||||
}
|
||||
function construct(client, config = {}) {
|
||||
const dialect = new PgDialect({ casing: config.casing });
|
||||
let logger;
|
||||
if (config.logger === true) {
|
||||
logger = new DefaultLogger();
|
||||
} else if (config.logger !== false) {
|
||||
logger = config.logger;
|
||||
}
|
||||
let schema;
|
||||
if (config.schema) {
|
||||
const tablesConfig = extractTablesRelationalConfig(
|
||||
config.schema,
|
||||
createTableRelationsHelpers
|
||||
);
|
||||
schema = {
|
||||
fullSchema: config.schema,
|
||||
schema: tablesConfig.tables,
|
||||
tableNamesMap: tablesConfig.tableNamesMap
|
||||
};
|
||||
}
|
||||
const driver = new PgliteDriver(client, dialect, { logger, cache: config.cache });
|
||||
const session = driver.createSession(schema);
|
||||
const db = new PgliteDatabase(dialect, session, schema);
|
||||
db.$client = client;
|
||||
db.$cache = config.cache;
|
||||
if (db.$cache) {
|
||||
db.$cache["invalidate"] = config.cache?.onMutate;
|
||||
}
|
||||
return db;
|
||||
}
|
||||
function drizzle(...params) {
|
||||
if (params[0] === void 0 || typeof params[0] === "string") {
|
||||
const instance = new PGlite(params[0]);
|
||||
return construct(instance, params[1]);
|
||||
}
|
||||
if (isConfig(params[0])) {
|
||||
const { connection, client, ...drizzleConfig } = params[0];
|
||||
if (client) return construct(client, drizzleConfig);
|
||||
if (typeof connection === "object") {
|
||||
const { dataDir, ...options } = connection;
|
||||
const instance2 = new PGlite(dataDir, options);
|
||||
return construct(instance2, drizzleConfig);
|
||||
}
|
||||
const instance = new PGlite(connection);
|
||||
return construct(instance, drizzleConfig);
|
||||
}
|
||||
return construct(params[0], params[1]);
|
||||
}
|
||||
((drizzle2) => {
|
||||
function mock(config) {
|
||||
return construct({}, config);
|
||||
}
|
||||
drizzle2.mock = mock;
|
||||
})(drizzle || (drizzle = {}));
|
||||
export {
|
||||
PgliteDatabase,
|
||||
PgliteDriver,
|
||||
drizzle
|
||||
};
|
||||
//# sourceMappingURL=driver.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/pglite/driver.ts"],"sourcesContent":["import { PGlite, type PGliteOptions } from '@electric-sql/pglite';\nimport type { Cache } from '~/cache/core/cache.ts';\nimport { 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 {\n\tcreateTableRelationsHelpers,\n\textractTablesRelationalConfig,\n\ttype RelationalSchemaConfig,\n\ttype TablesRelationalConfig,\n} from '~/relations.ts';\nimport { type DrizzleConfig, isConfig } from '~/utils.ts';\nimport type { PgliteClient, PgliteQueryResultHKT } from './session.ts';\nimport { PgliteSession } from './session.ts';\n\nexport interface PgDriverOptions {\n\tlogger?: Logger;\n\tcache?: Cache;\n}\n\nexport class PgliteDriver {\n\tstatic readonly [entityKind]: string = 'PgliteDriver';\n\n\tconstructor(\n\t\tprivate client: PgliteClient,\n\t\tprivate dialect: PgDialect,\n\t\tprivate options: PgDriverOptions = {},\n\t) {\n\t}\n\n\tcreateSession(\n\t\tschema: RelationalSchemaConfig<TablesRelationalConfig> | undefined,\n\t): PgliteSession<Record<string, unknown>, TablesRelationalConfig> {\n\t\treturn new PgliteSession(this.client, this.dialect, schema, {\n\t\t\tlogger: this.options.logger,\n\t\t\tcache: this.options.cache,\n\t\t});\n\t}\n}\n\nexport class PgliteDatabase<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n> extends PgDatabase<PgliteQueryResultHKT, TSchema> {\n\tstatic override readonly [entityKind]: string = 'PgliteDatabase';\n}\n\nfunction construct<TSchema extends Record<string, unknown> = Record<string, never>>(\n\tclient: PgliteClient,\n\tconfig: DrizzleConfig<TSchema> = {},\n): PgliteDatabase<TSchema> & {\n\t$client: PgliteClient;\n} {\n\tconst dialect = new PgDialect({ casing: config.casing });\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(\n\t\t\tconfig.schema,\n\t\t\tcreateTableRelationsHelpers,\n\t\t);\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 PgliteDriver(client, dialect, { logger, cache: config.cache });\n\tconst session = driver.createSession(schema);\n\tconst db = new PgliteDatabase(dialect, session, schema as any) as PgliteDatabase<TSchema>;\n\t(<any> db).$client = client;\n\t(<any> db).$cache = config.cache;\n\tif ((<any> db).$cache) {\n\t\t(<any> db).$cache['invalidate'] = config.cache?.onMutate;\n\t}\n\t// (<any> db).$cache = { invalidate: (<any> config).cache?.onMutate };\n\t// if (config.cache) {\n\t// \tfor (\n\t// \t\tconst key of Object.getOwnPropertyNames(Object.getPrototypeOf(config.cache)).filter((key) =>\n\t// \t\t\tkey !== 'constructor'\n\t// \t\t)\n\t// \t) {\n\t// \t\t(<any> db).$cache[key as keyof typeof config.cache] = (<any> config).cache[key];\n\t// \t}\n\t// }\n\n\treturn db as any;\n}\n\nexport function drizzle<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTClient extends PGlite = PGlite,\n>(\n\t...params:\n\t\t| []\n\t\t| [\n\t\t\tTClient | string,\n\t\t]\n\t\t| [\n\t\t\tTClient | string,\n\t\t\tDrizzleConfig<TSchema>,\n\t\t]\n\t\t| [\n\t\t\t(\n\t\t\t\t& DrizzleConfig<TSchema>\n\t\t\t\t& ({\n\t\t\t\t\tconnection?: (PGliteOptions & { dataDir?: string }) | string;\n\t\t\t\t} | {\n\t\t\t\t\tclient: TClient;\n\t\t\t\t})\n\t\t\t),\n\t\t]\n): PgliteDatabase<TSchema> & {\n\t$client: TClient;\n} {\n\tif (params[0] === undefined || typeof params[0] === 'string') {\n\t\tconst instance = new PGlite(params[0]);\n\t\treturn construct(instance, params[1]) as any;\n\t}\n\n\tif (isConfig(params[0])) {\n\t\tconst { connection, client, ...drizzleConfig } = params[0] as {\n\t\t\tconnection?: PGliteOptions & { dataDir: string };\n\t\t\tclient?: TClient;\n\t\t} & DrizzleConfig<TSchema>;\n\n\t\tif (client) return construct(client, drizzleConfig) as any;\n\n\t\tif (typeof connection === 'object') {\n\t\t\tconst { dataDir, ...options } = connection;\n\n\t\t\tconst instance = new PGlite(dataDir, options);\n\n\t\t\treturn construct(instance, drizzleConfig) as any;\n\t\t}\n\n\t\tconst instance = new PGlite(connection);\n\n\t\treturn construct(instance, drizzleConfig) as any;\n\t}\n\n\treturn construct(params[0] as TClient, params[1] as DrizzleConfig<TSchema> | undefined) as any;\n}\n\nexport namespace drizzle {\n\texport function mock<TSchema extends Record<string, unknown> = Record<string, never>>(\n\t\tconfig?: DrizzleConfig<TSchema>,\n\t): PgliteDatabase<TSchema> & {\n\t\t$client: '$client is not available on drizzle.mock()';\n\t} {\n\t\treturn construct({} as any, config) as any;\n\t}\n}\n"],"mappings":"AAALine truncated
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var pglite_exports = {};
|
||||
module.exports = __toCommonJS(pglite_exports);
|
||||
__reExport(pglite_exports, require("./driver.cjs"), module.exports);
|
||||
__reExport(pglite_exports, require("./session.cjs"), module.exports);
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
...require("./driver.cjs"),
|
||||
...require("./session.cjs")
|
||||
});
|
||||
//# sourceMappingURL=index.cjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/pglite/index.ts"],"sourcesContent":["export * from './driver.ts';\nexport * from './session.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,2BAAc,wBAAd;AACA,2BAAc,yBADd;","names":[]}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from "./driver.cjs";
|
||||
export * from "./session.cjs";
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from "./driver.js";
|
||||
export * from "./session.js";
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export * from "./driver.js";
|
||||
export * from "./session.js";
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/pglite/index.ts"],"sourcesContent":["export * from './driver.ts';\nexport * from './session.ts';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var migrator_exports = {};
|
||||
__export(migrator_exports, {
|
||||
migrate: () => migrate
|
||||
});
|
||||
module.exports = __toCommonJS(migrator_exports);
|
||||
var import_migrator = require("../migrator.cjs");
|
||||
async function migrate(db, config) {
|
||||
const migrations = (0, import_migrator.readMigrationFiles)(config);
|
||||
await db.dialect.migrate(migrations, db.session, config);
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
migrate
|
||||
});
|
||||
//# sourceMappingURL=migrator.cjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/pglite/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport type { PgliteDatabase } from './driver.ts';\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: PgliteDatabase<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\tawait db.dialect.migrate(migrations, db.session, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAmC;AAGnC,eAAsB,QACrB,IACA,QACC;AACD,QAAM,iBAAa,oCAAmB,MAAM;AAC5C,QAAM,GAAG,QAAQ,QAAQ,YAAY,GAAG,SAAS,MAAM;AACxD;","names":[]}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import type { MigrationConfig } from "../migrator.cjs";
|
||||
import type { PgliteDatabase } from "./driver.cjs";
|
||||
export declare function migrate<TSchema extends Record<string, unknown>>(db: PgliteDatabase<TSchema>, config: MigrationConfig): Promise<void>;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import type { MigrationConfig } from "../migrator.js";
|
||||
import type { PgliteDatabase } from "./driver.js";
|
||||
export declare function migrate<TSchema extends Record<string, unknown>>(db: PgliteDatabase<TSchema>, config: MigrationConfig): Promise<void>;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { readMigrationFiles } from "../migrator.js";
|
||||
async function migrate(db, config) {
|
||||
const migrations = readMigrationFiles(config);
|
||||
await db.dialect.migrate(migrations, db.session, config);
|
||||
}
|
||||
export {
|
||||
migrate
|
||||
};
|
||||
//# sourceMappingURL=migrator.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/pglite/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport type { PgliteDatabase } from './driver.ts';\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: PgliteDatabase<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\tawait db.dialect.migrate(migrations, db.session, config);\n}\n"],"mappings":"AACA,SAAS,0BAA0B;AAGnC,eAAsB,QACrB,IACA,QACC;AACD,QAAM,aAAa,mBAAmB,MAAM;AAC5C,QAAM,GAAG,QAAQ,QAAQ,YAAY,GAAG,SAAS,MAAM;AACxD;","names":[]}
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var session_exports = {};
|
||||
__export(session_exports, {
|
||||
PglitePreparedQuery: () => PglitePreparedQuery,
|
||||
PgliteSession: () => PgliteSession,
|
||||
PgliteTransaction: () => PgliteTransaction
|
||||
});
|
||||
module.exports = __toCommonJS(session_exports);
|
||||
var import_entity = require("../entity.cjs");
|
||||
var import_logger = require("../logger.cjs");
|
||||
var import_pg_core = require("../pg-core/index.cjs");
|
||||
var import_session = require("../pg-core/session.cjs");
|
||||
var import_sql = require("../sql/sql.cjs");
|
||||
var import_utils = require("../utils.cjs");
|
||||
var import_pglite = require("@electric-sql/pglite");
|
||||
var import_cache = require("../cache/core/cache.cjs");
|
||||
class PglitePreparedQuery extends import_session.PgPreparedQuery {
|
||||
constructor(client, queryString, params, logger, cache, queryMetadata, cacheConfig, fields, name, _isResponseInArrayMode, customResultMapper) {
|
||||
super({ sql: queryString, params }, cache, queryMetadata, cacheConfig);
|
||||
this.client = client;
|
||||
this.queryString = queryString;
|
||||
this.params = params;
|
||||
this.logger = logger;
|
||||
this.fields = fields;
|
||||
this._isResponseInArrayMode = _isResponseInArrayMode;
|
||||
this.customResultMapper = customResultMapper;
|
||||
this.rawQueryConfig = {
|
||||
rowMode: "object",
|
||||
parsers: {
|
||||
[import_pglite.types.TIMESTAMP]: (value) => value,
|
||||
[import_pglite.types.TIMESTAMPTZ]: (value) => value,
|
||||
[import_pglite.types.INTERVAL]: (value) => value,
|
||||
[import_pglite.types.DATE]: (value) => value,
|
||||
// numeric[]
|
||||
[1231]: (value) => value,
|
||||
// timestamp[]
|
||||
[1115]: (value) => value,
|
||||
// timestamp with timezone[]
|
||||
[1185]: (value) => value,
|
||||
// interval[]
|
||||
[1187]: (value) => value,
|
||||
// date[]
|
||||
[1182]: (value) => value
|
||||
}
|
||||
};
|
||||
this.queryConfig = {
|
||||
rowMode: "array",
|
||||
parsers: {
|
||||
[import_pglite.types.TIMESTAMP]: (value) => value,
|
||||
[import_pglite.types.TIMESTAMPTZ]: (value) => value,
|
||||
[import_pglite.types.INTERVAL]: (value) => value,
|
||||
[import_pglite.types.DATE]: (value) => value,
|
||||
// numeric[]
|
||||
[1231]: (value) => value,
|
||||
// timestamp[]
|
||||
[1115]: (value) => value,
|
||||
// timestamp with timezone[]
|
||||
[1185]: (value) => value,
|
||||
// interval[]
|
||||
[1187]: (value) => value,
|
||||
// date[]
|
||||
[1182]: (value) => value
|
||||
}
|
||||
};
|
||||
}
|
||||
static [import_entity.entityKind] = "PglitePreparedQuery";
|
||||
rawQueryConfig;
|
||||
queryConfig;
|
||||
async execute(placeholderValues = {}) {
|
||||
const params = (0, import_sql.fillPlaceholders)(this.params, placeholderValues);
|
||||
this.logger.logQuery(this.queryString, params);
|
||||
const { fields, client, queryConfig, joinsNotNullableMap, customResultMapper, queryString, rawQueryConfig } = this;
|
||||
if (!fields && !customResultMapper) {
|
||||
return this.queryWithCache(queryString, params, async () => {
|
||||
return await client.query(queryString, params, rawQueryConfig);
|
||||
});
|
||||
}
|
||||
const result = await this.queryWithCache(queryString, params, async () => {
|
||||
return await client.query(queryString, params, queryConfig);
|
||||
});
|
||||
return customResultMapper ? customResultMapper(result.rows) : result.rows.map((row) => (0, import_utils.mapResultRow)(fields, row, joinsNotNullableMap));
|
||||
}
|
||||
all(placeholderValues = {}) {
|
||||
const params = (0, import_sql.fillPlaceholders)(this.params, placeholderValues);
|
||||
this.logger.logQuery(this.queryString, params);
|
||||
return this.queryWithCache(this.queryString, params, async () => {
|
||||
return await this.client.query(this.queryString, params, this.rawQueryConfig);
|
||||
}).then((result) => result.rows);
|
||||
}
|
||||
/** @internal */
|
||||
isResponseInArrayMode() {
|
||||
return this._isResponseInArrayMode;
|
||||
}
|
||||
}
|
||||
class PgliteSession extends import_session.PgSession {
|
||||
constructor(client, dialect, schema, options = {}) {
|
||||
super(dialect);
|
||||
this.client = client;
|
||||
this.schema = schema;
|
||||
this.options = options;
|
||||
this.logger = options.logger ?? new import_logger.NoopLogger();
|
||||
this.cache = options.cache ?? new import_cache.NoopCache();
|
||||
}
|
||||
static [import_entity.entityKind] = "PgliteSession";
|
||||
logger;
|
||||
cache;
|
||||
prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
|
||||
return new PglitePreparedQuery(
|
||||
this.client,
|
||||
query.sql,
|
||||
query.params,
|
||||
this.logger,
|
||||
this.cache,
|
||||
queryMetadata,
|
||||
cacheConfig,
|
||||
fields,
|
||||
name,
|
||||
isResponseInArrayMode,
|
||||
customResultMapper
|
||||
);
|
||||
}
|
||||
async transaction(transaction, config) {
|
||||
return this.client.transaction(async (client) => {
|
||||
const session = new PgliteSession(
|
||||
client,
|
||||
this.dialect,
|
||||
this.schema,
|
||||
this.options
|
||||
);
|
||||
const tx = new PgliteTransaction(this.dialect, session, this.schema);
|
||||
if (config) {
|
||||
await tx.setTransaction(config);
|
||||
}
|
||||
return transaction(tx);
|
||||
});
|
||||
}
|
||||
async count(sql2) {
|
||||
const res = await this.execute(sql2);
|
||||
return Number(
|
||||
res["rows"][0]["count"]
|
||||
);
|
||||
}
|
||||
}
|
||||
class PgliteTransaction extends import_pg_core.PgTransaction {
|
||||
static [import_entity.entityKind] = "PgliteTransaction";
|
||||
async transaction(transaction) {
|
||||
const savepointName = `sp${this.nestedIndex + 1}`;
|
||||
const tx = new PgliteTransaction(
|
||||
this.dialect,
|
||||
this.session,
|
||||
this.schema,
|
||||
this.nestedIndex + 1
|
||||
);
|
||||
await tx.execute(import_sql.sql.raw(`savepoint ${savepointName}`));
|
||||
try {
|
||||
const result = await transaction(tx);
|
||||
await tx.execute(import_sql.sql.raw(`release savepoint ${savepointName}`));
|
||||
return result;
|
||||
} catch (err) {
|
||||
await tx.execute(import_sql.sql.raw(`rollback to savepoint ${savepointName}`));
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
PglitePreparedQuery,
|
||||
PgliteSession,
|
||||
PgliteTransaction
|
||||
});
|
||||
//# sourceMappingURL=session.cjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/pglite/session.ts"],"sourcesContent":["import type { PGlite, QueryOptions, Results, Row, Transaction } from '@electric-sql/pglite';\nimport { entityKind } from '~/entity.ts';\nimport { type Logger, 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 { PgQueryResultHKT, PgTransactionConfig, PreparedQueryConfig } from '~/pg-core/session.ts';\nimport { PgPreparedQuery, PgSession } from '~/pg-core/session.ts';\nimport type { RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { fillPlaceholders, type Query, type SQL, sql } from '~/sql/sql.ts';\nimport { type Assume, mapResultRow } from '~/utils.ts';\n\nimport { types } from '@electric-sql/pglite';\nimport { type Cache, NoopCache } from '~/cache/core/cache.ts';\nimport type { WithCacheConfig } from '~/cache/core/types.ts';\n\nexport type PgliteClient = PGlite;\n\nexport class PglitePreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {\n\tstatic override readonly [entityKind]: string = 'PglitePreparedQuery';\n\n\tprivate rawQueryConfig: QueryOptions;\n\tprivate queryConfig: QueryOptions;\n\n\tconstructor(\n\t\tprivate client: PgliteClient | Transaction,\n\t\tprivate queryString: string,\n\t\tprivate params: unknown[],\n\t\tprivate logger: Logger,\n\t\tcache: Cache,\n\t\tqueryMetadata: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t} | undefined,\n\t\tcacheConfig: WithCacheConfig | undefined,\n\t\tprivate fields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tprivate _isResponseInArrayMode: boolean,\n\t\tprivate customResultMapper?: (rows: unknown[][]) => T['execute'],\n\t) {\n\t\tsuper({ sql: queryString, params }, cache, queryMetadata, cacheConfig);\n\t\tthis.rawQueryConfig = {\n\t\t\trowMode: 'object',\n\t\t\tparsers: {\n\t\t\t\t[types.TIMESTAMP]: (value) => value,\n\t\t\t\t[types.TIMESTAMPTZ]: (value) => value,\n\t\t\t\t[types.INTERVAL]: (value) => value,\n\t\t\t\t[types.DATE]: (value) => value,\n\t\t\t\t// numeric[]\n\t\t\t\t[1231]: (value) => value,\n\t\t\t\t// timestamp[]\n\t\t\t\t[1115]: (value) => value,\n\t\t\t\t// timestamp with timezone[]\n\t\t\t\t[1185]: (value) => value,\n\t\t\t\t// interval[]\n\t\t\t\t[1187]: (value) => value,\n\t\t\t\t// date[]\n\t\t\t\t[1182]: (value) => value,\n\t\t\t},\n\t\t};\n\t\tthis.queryConfig = {\n\t\t\trowMode: 'array',\n\t\t\tparsers: {\n\t\t\t\t[types.TIMESTAMP]: (value) => value,\n\t\t\t\t[types.TIMESTAMPTZ]: (value) => value,\n\t\t\t\t[types.INTERVAL]: (value) => value,\n\t\t\t\t[types.DATE]: (value) => value,\n\t\t\t\t// numeric[]\n\t\t\t\t[1231]: (value) => value,\n\t\t\t\t// timestamp[]\n\t\t\t\t[1115]: (value) => value,\n\t\t\t\t// timestamp with timezone[]\n\t\t\t\t[1185]: (value) => value,\n\t\t\t\t// interval[]\n\t\t\t\t[1187]: (value) => value,\n\t\t\t\t// date[]\n\t\t\t\t[1182]: (value) => value,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync execute(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['execute']> {\n\t\tconst params = fillPlaceholders(this.params, placeholderValues);\n\n\t\tthis.logger.logQuery(this.queryString, params);\n\n\t\tconst { fields, client, queryConfig, joinsNotNullableMap, customResultMapper, queryString, rawQueryConfig } = this;\n\n\t\tif (!fields && !customResultMapper) {\n\t\t\treturn this.queryWithCache(queryString, params, async () => {\n\t\t\t\treturn await client.query<any[]>(queryString, params, rawQueryConfig);\n\t\t\t});\n\t\t}\n\n\t\tconst result = await this.queryWithCache(queryString, params, async () => {\n\t\t\treturn await client.query<any[]>(queryString, params, queryConfig);\n\t\t});\n\n\t\treturn customResultMapper\n\t\t\t? customResultMapper(result.rows)\n\t\t\t: result.rows.map((row) => mapResultRow<T['execute']>(fields!, row, joinsNotNullableMap));\n\t}\n\n\tall(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['all']> {\n\t\tconst params = fillPlaceholders(this.params, placeholderValues);\n\t\tthis.logger.logQuery(this.queryString, params);\n\t\treturn this.queryWithCache(this.queryString, params, async () => {\n\t\t\treturn await this.client.query<any[]>(this.queryString, params, this.rawQueryConfig);\n\t\t}).then((result) => result.rows);\n\t}\n\n\t/** @internal */\n\tisResponseInArrayMode(): boolean {\n\t\treturn this._isResponseInArrayMode;\n\t}\n}\n\nexport interface PgliteSessionOptions {\n\tlogger?: Logger;\n\tcache?: Cache;\n}\n\nexport class PgliteSession<\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n> extends PgSession<PgliteQueryResultHKT, TFullSchema, TSchema> {\n\tstatic override readonly [entityKind]: string = 'PgliteSession';\n\n\tprivate logger: Logger;\n\tprivate cache: Cache;\n\n\tconstructor(\n\t\tprivate client: PgliteClient | TraLine truncated
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
import type { PGlite, Results, Row, Transaction } from '@electric-sql/pglite';
|
||||
import { entityKind } from "../entity.cjs";
|
||||
import { type Logger } from "../logger.cjs";
|
||||
import type { PgDialect } from "../pg-core/dialect.cjs";
|
||||
import { PgTransaction } from "../pg-core/index.cjs";
|
||||
import type { SelectedFieldsOrdered } from "../pg-core/query-builders/select.types.cjs";
|
||||
import type { PgQueryResultHKT, PgTransactionConfig, PreparedQueryConfig } from "../pg-core/session.cjs";
|
||||
import { PgPreparedQuery, PgSession } from "../pg-core/session.cjs";
|
||||
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.cjs";
|
||||
import { type Query, type SQL } from "../sql/sql.cjs";
|
||||
import { type Assume } from "../utils.cjs";
|
||||
import { type Cache } from "../cache/core/cache.cjs";
|
||||
import type { WithCacheConfig } from "../cache/core/types.cjs";
|
||||
export type PgliteClient = PGlite;
|
||||
export declare class PglitePreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {
|
||||
private client;
|
||||
private queryString;
|
||||
private params;
|
||||
private logger;
|
||||
private fields;
|
||||
private _isResponseInArrayMode;
|
||||
private customResultMapper?;
|
||||
static readonly [entityKind]: string;
|
||||
private rawQueryConfig;
|
||||
private queryConfig;
|
||||
constructor(client: PgliteClient | Transaction, queryString: string, params: unknown[], logger: Logger, cache: Cache, queryMetadata: {
|
||||
type: 'select' | 'update' | 'delete' | 'insert';
|
||||
tables: string[];
|
||||
} | undefined, cacheConfig: WithCacheConfig | undefined, fields: SelectedFieldsOrdered | undefined, name: string | undefined, _isResponseInArrayMode: boolean, customResultMapper?: ((rows: unknown[][]) => T["execute"]) | undefined);
|
||||
execute(placeholderValues?: Record<string, unknown> | undefined): Promise<T['execute']>;
|
||||
all(placeholderValues?: Record<string, unknown> | undefined): Promise<T['all']>;
|
||||
}
|
||||
export interface PgliteSessionOptions {
|
||||
logger?: Logger;
|
||||
cache?: Cache;
|
||||
}
|
||||
export declare class PgliteSession<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgSession<PgliteQueryResultHKT, TFullSchema, TSchema> {
|
||||
private client;
|
||||
private schema;
|
||||
private options;
|
||||
static readonly [entityKind]: string;
|
||||
private logger;
|
||||
private cache;
|
||||
constructor(client: PgliteClient | Transaction, dialect: PgDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options?: PgliteSessionOptions);
|
||||
prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, name: string | undefined, isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => T['execute'], queryMetadata?: {
|
||||
type: 'select' | 'update' | 'delete' | 'insert';
|
||||
tables: string[];
|
||||
}, cacheConfig?: WithCacheConfig): PgPreparedQuery<T>;
|
||||
transaction<T>(transaction: (tx: PgliteTransaction<TFullSchema, TSchema>) => Promise<T>, config?: PgTransactionConfig | undefined): Promise<T>;
|
||||
count(sql: SQL): Promise<number>;
|
||||
}
|
||||
export declare class PgliteTransaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgTransaction<PgliteQueryResultHKT, TFullSchema, TSchema> {
|
||||
static readonly [entityKind]: string;
|
||||
transaction<T>(transaction: (tx: PgliteTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
|
||||
}
|
||||
export interface PgliteQueryResultHKT extends PgQueryResultHKT {
|
||||
type: Results<Assume<this['row'], Row>>;
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
import type { PGlite, Results, Row, Transaction } from '@electric-sql/pglite';
|
||||
import { entityKind } from "../entity.js";
|
||||
import { type Logger } from "../logger.js";
|
||||
import type { PgDialect } from "../pg-core/dialect.js";
|
||||
import { PgTransaction } from "../pg-core/index.js";
|
||||
import type { SelectedFieldsOrdered } from "../pg-core/query-builders/select.types.js";
|
||||
import type { PgQueryResultHKT, PgTransactionConfig, PreparedQueryConfig } from "../pg-core/session.js";
|
||||
import { PgPreparedQuery, PgSession } from "../pg-core/session.js";
|
||||
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.js";
|
||||
import { type Query, type SQL } from "../sql/sql.js";
|
||||
import { type Assume } from "../utils.js";
|
||||
import { type Cache } from "../cache/core/cache.js";
|
||||
import type { WithCacheConfig } from "../cache/core/types.js";
|
||||
export type PgliteClient = PGlite;
|
||||
export declare class PglitePreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {
|
||||
private client;
|
||||
private queryString;
|
||||
private params;
|
||||
private logger;
|
||||
private fields;
|
||||
private _isResponseInArrayMode;
|
||||
private customResultMapper?;
|
||||
static readonly [entityKind]: string;
|
||||
private rawQueryConfig;
|
||||
private queryConfig;
|
||||
constructor(client: PgliteClient | Transaction, queryString: string, params: unknown[], logger: Logger, cache: Cache, queryMetadata: {
|
||||
type: 'select' | 'update' | 'delete' | 'insert';
|
||||
tables: string[];
|
||||
} | undefined, cacheConfig: WithCacheConfig | undefined, fields: SelectedFieldsOrdered | undefined, name: string | undefined, _isResponseInArrayMode: boolean, customResultMapper?: ((rows: unknown[][]) => T["execute"]) | undefined);
|
||||
execute(placeholderValues?: Record<string, unknown> | undefined): Promise<T['execute']>;
|
||||
all(placeholderValues?: Record<string, unknown> | undefined): Promise<T['all']>;
|
||||
}
|
||||
export interface PgliteSessionOptions {
|
||||
logger?: Logger;
|
||||
cache?: Cache;
|
||||
}
|
||||
export declare class PgliteSession<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgSession<PgliteQueryResultHKT, TFullSchema, TSchema> {
|
||||
private client;
|
||||
private schema;
|
||||
private options;
|
||||
static readonly [entityKind]: string;
|
||||
private logger;
|
||||
private cache;
|
||||
constructor(client: PgliteClient | Transaction, dialect: PgDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options?: PgliteSessionOptions);
|
||||
prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, name: string | undefined, isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => T['execute'], queryMetadata?: {
|
||||
type: 'select' | 'update' | 'delete' | 'insert';
|
||||
tables: string[];
|
||||
}, cacheConfig?: WithCacheConfig): PgPreparedQuery<T>;
|
||||
transaction<T>(transaction: (tx: PgliteTransaction<TFullSchema, TSchema>) => Promise<T>, config?: PgTransactionConfig | undefined): Promise<T>;
|
||||
count(sql: SQL): Promise<number>;
|
||||
}
|
||||
export declare class PgliteTransaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgTransaction<PgliteQueryResultHKT, TFullSchema, TSchema> {
|
||||
static readonly [entityKind]: string;
|
||||
transaction<T>(transaction: (tx: PgliteTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
|
||||
}
|
||||
export interface PgliteQueryResultHKT extends PgQueryResultHKT {
|
||||
type: Results<Assume<this['row'], Row>>;
|
||||
}
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
import { entityKind } from "../entity.js";
|
||||
import { NoopLogger } from "../logger.js";
|
||||
import { PgTransaction } from "../pg-core/index.js";
|
||||
import { PgPreparedQuery, PgSession } from "../pg-core/session.js";
|
||||
import { fillPlaceholders, sql } from "../sql/sql.js";
|
||||
import { mapResultRow } from "../utils.js";
|
||||
import { types } from "@electric-sql/pglite";
|
||||
import { NoopCache } from "../cache/core/cache.js";
|
||||
class PglitePreparedQuery extends PgPreparedQuery {
|
||||
constructor(client, queryString, params, logger, cache, queryMetadata, cacheConfig, fields, name, _isResponseInArrayMode, customResultMapper) {
|
||||
super({ sql: queryString, params }, cache, queryMetadata, cacheConfig);
|
||||
this.client = client;
|
||||
this.queryString = queryString;
|
||||
this.params = params;
|
||||
this.logger = logger;
|
||||
this.fields = fields;
|
||||
this._isResponseInArrayMode = _isResponseInArrayMode;
|
||||
this.customResultMapper = customResultMapper;
|
||||
this.rawQueryConfig = {
|
||||
rowMode: "object",
|
||||
parsers: {
|
||||
[types.TIMESTAMP]: (value) => value,
|
||||
[types.TIMESTAMPTZ]: (value) => value,
|
||||
[types.INTERVAL]: (value) => value,
|
||||
[types.DATE]: (value) => value,
|
||||
// numeric[]
|
||||
[1231]: (value) => value,
|
||||
// timestamp[]
|
||||
[1115]: (value) => value,
|
||||
// timestamp with timezone[]
|
||||
[1185]: (value) => value,
|
||||
// interval[]
|
||||
[1187]: (value) => value,
|
||||
// date[]
|
||||
[1182]: (value) => value
|
||||
}
|
||||
};
|
||||
this.queryConfig = {
|
||||
rowMode: "array",
|
||||
parsers: {
|
||||
[types.TIMESTAMP]: (value) => value,
|
||||
[types.TIMESTAMPTZ]: (value) => value,
|
||||
[types.INTERVAL]: (value) => value,
|
||||
[types.DATE]: (value) => value,
|
||||
// numeric[]
|
||||
[1231]: (value) => value,
|
||||
// timestamp[]
|
||||
[1115]: (value) => value,
|
||||
// timestamp with timezone[]
|
||||
[1185]: (value) => value,
|
||||
// interval[]
|
||||
[1187]: (value) => value,
|
||||
// date[]
|
||||
[1182]: (value) => value
|
||||
}
|
||||
};
|
||||
}
|
||||
static [entityKind] = "PglitePreparedQuery";
|
||||
rawQueryConfig;
|
||||
queryConfig;
|
||||
async execute(placeholderValues = {}) {
|
||||
const params = fillPlaceholders(this.params, placeholderValues);
|
||||
this.logger.logQuery(this.queryString, params);
|
||||
const { fields, client, queryConfig, joinsNotNullableMap, customResultMapper, queryString, rawQueryConfig } = this;
|
||||
if (!fields && !customResultMapper) {
|
||||
return this.queryWithCache(queryString, params, async () => {
|
||||
return await client.query(queryString, params, rawQueryConfig);
|
||||
});
|
||||
}
|
||||
const result = await this.queryWithCache(queryString, params, async () => {
|
||||
return await client.query(queryString, params, queryConfig);
|
||||
});
|
||||
return customResultMapper ? customResultMapper(result.rows) : result.rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
|
||||
}
|
||||
all(placeholderValues = {}) {
|
||||
const params = fillPlaceholders(this.params, placeholderValues);
|
||||
this.logger.logQuery(this.queryString, params);
|
||||
return this.queryWithCache(this.queryString, params, async () => {
|
||||
return await this.client.query(this.queryString, params, this.rawQueryConfig);
|
||||
}).then((result) => result.rows);
|
||||
}
|
||||
/** @internal */
|
||||
isResponseInArrayMode() {
|
||||
return this._isResponseInArrayMode;
|
||||
}
|
||||
}
|
||||
class PgliteSession extends PgSession {
|
||||
constructor(client, dialect, schema, options = {}) {
|
||||
super(dialect);
|
||||
this.client = client;
|
||||
this.schema = schema;
|
||||
this.options = options;
|
||||
this.logger = options.logger ?? new NoopLogger();
|
||||
this.cache = options.cache ?? new NoopCache();
|
||||
}
|
||||
static [entityKind] = "PgliteSession";
|
||||
logger;
|
||||
cache;
|
||||
prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
|
||||
return new PglitePreparedQuery(
|
||||
this.client,
|
||||
query.sql,
|
||||
query.params,
|
||||
this.logger,
|
||||
this.cache,
|
||||
queryMetadata,
|
||||
cacheConfig,
|
||||
fields,
|
||||
name,
|
||||
isResponseInArrayMode,
|
||||
customResultMapper
|
||||
);
|
||||
}
|
||||
async transaction(transaction, config) {
|
||||
return this.client.transaction(async (client) => {
|
||||
const session = new PgliteSession(
|
||||
client,
|
||||
this.dialect,
|
||||
this.schema,
|
||||
this.options
|
||||
);
|
||||
const tx = new PgliteTransaction(this.dialect, session, this.schema);
|
||||
if (config) {
|
||||
await tx.setTransaction(config);
|
||||
}
|
||||
return transaction(tx);
|
||||
});
|
||||
}
|
||||
async count(sql2) {
|
||||
const res = await this.execute(sql2);
|
||||
return Number(
|
||||
res["rows"][0]["count"]
|
||||
);
|
||||
}
|
||||
}
|
||||
class PgliteTransaction extends PgTransaction {
|
||||
static [entityKind] = "PgliteTransaction";
|
||||
async transaction(transaction) {
|
||||
const savepointName = `sp${this.nestedIndex + 1}`;
|
||||
const tx = new PgliteTransaction(
|
||||
this.dialect,
|
||||
this.session,
|
||||
this.schema,
|
||||
this.nestedIndex + 1
|
||||
);
|
||||
await tx.execute(sql.raw(`savepoint ${savepointName}`));
|
||||
try {
|
||||
const result = await transaction(tx);
|
||||
await tx.execute(sql.raw(`release savepoint ${savepointName}`));
|
||||
return result;
|
||||
} catch (err) {
|
||||
await tx.execute(sql.raw(`rollback to savepoint ${savepointName}`));
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
export {
|
||||
PglitePreparedQuery,
|
||||
PgliteSession,
|
||||
PgliteTransaction
|
||||
};
|
||||
//# sourceMappingURL=session.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/pglite/session.ts"],"sourcesContent":["import type { PGlite, QueryOptions, Results, Row, Transaction } from '@electric-sql/pglite';\nimport { entityKind } from '~/entity.ts';\nimport { type Logger, 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 { PgQueryResultHKT, PgTransactionConfig, PreparedQueryConfig } from '~/pg-core/session.ts';\nimport { PgPreparedQuery, PgSession } from '~/pg-core/session.ts';\nimport type { RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { fillPlaceholders, type Query, type SQL, sql } from '~/sql/sql.ts';\nimport { type Assume, mapResultRow } from '~/utils.ts';\n\nimport { types } from '@electric-sql/pglite';\nimport { type Cache, NoopCache } from '~/cache/core/cache.ts';\nimport type { WithCacheConfig } from '~/cache/core/types.ts';\n\nexport type PgliteClient = PGlite;\n\nexport class PglitePreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {\n\tstatic override readonly [entityKind]: string = 'PglitePreparedQuery';\n\n\tprivate rawQueryConfig: QueryOptions;\n\tprivate queryConfig: QueryOptions;\n\n\tconstructor(\n\t\tprivate client: PgliteClient | Transaction,\n\t\tprivate queryString: string,\n\t\tprivate params: unknown[],\n\t\tprivate logger: Logger,\n\t\tcache: Cache,\n\t\tqueryMetadata: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t} | undefined,\n\t\tcacheConfig: WithCacheConfig | undefined,\n\t\tprivate fields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tprivate _isResponseInArrayMode: boolean,\n\t\tprivate customResultMapper?: (rows: unknown[][]) => T['execute'],\n\t) {\n\t\tsuper({ sql: queryString, params }, cache, queryMetadata, cacheConfig);\n\t\tthis.rawQueryConfig = {\n\t\t\trowMode: 'object',\n\t\t\tparsers: {\n\t\t\t\t[types.TIMESTAMP]: (value) => value,\n\t\t\t\t[types.TIMESTAMPTZ]: (value) => value,\n\t\t\t\t[types.INTERVAL]: (value) => value,\n\t\t\t\t[types.DATE]: (value) => value,\n\t\t\t\t// numeric[]\n\t\t\t\t[1231]: (value) => value,\n\t\t\t\t// timestamp[]\n\t\t\t\t[1115]: (value) => value,\n\t\t\t\t// timestamp with timezone[]\n\t\t\t\t[1185]: (value) => value,\n\t\t\t\t// interval[]\n\t\t\t\t[1187]: (value) => value,\n\t\t\t\t// date[]\n\t\t\t\t[1182]: (value) => value,\n\t\t\t},\n\t\t};\n\t\tthis.queryConfig = {\n\t\t\trowMode: 'array',\n\t\t\tparsers: {\n\t\t\t\t[types.TIMESTAMP]: (value) => value,\n\t\t\t\t[types.TIMESTAMPTZ]: (value) => value,\n\t\t\t\t[types.INTERVAL]: (value) => value,\n\t\t\t\t[types.DATE]: (value) => value,\n\t\t\t\t// numeric[]\n\t\t\t\t[1231]: (value) => value,\n\t\t\t\t// timestamp[]\n\t\t\t\t[1115]: (value) => value,\n\t\t\t\t// timestamp with timezone[]\n\t\t\t\t[1185]: (value) => value,\n\t\t\t\t// interval[]\n\t\t\t\t[1187]: (value) => value,\n\t\t\t\t// date[]\n\t\t\t\t[1182]: (value) => value,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync execute(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['execute']> {\n\t\tconst params = fillPlaceholders(this.params, placeholderValues);\n\n\t\tthis.logger.logQuery(this.queryString, params);\n\n\t\tconst { fields, client, queryConfig, joinsNotNullableMap, customResultMapper, queryString, rawQueryConfig } = this;\n\n\t\tif (!fields && !customResultMapper) {\n\t\t\treturn this.queryWithCache(queryString, params, async () => {\n\t\t\t\treturn await client.query<any[]>(queryString, params, rawQueryConfig);\n\t\t\t});\n\t\t}\n\n\t\tconst result = await this.queryWithCache(queryString, params, async () => {\n\t\t\treturn await client.query<any[]>(queryString, params, queryConfig);\n\t\t});\n\n\t\treturn customResultMapper\n\t\t\t? customResultMapper(result.rows)\n\t\t\t: result.rows.map((row) => mapResultRow<T['execute']>(fields!, row, joinsNotNullableMap));\n\t}\n\n\tall(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['all']> {\n\t\tconst params = fillPlaceholders(this.params, placeholderValues);\n\t\tthis.logger.logQuery(this.queryString, params);\n\t\treturn this.queryWithCache(this.queryString, params, async () => {\n\t\t\treturn await this.client.query<any[]>(this.queryString, params, this.rawQueryConfig);\n\t\t}).then((result) => result.rows);\n\t}\n\n\t/** @internal */\n\tisResponseInArrayMode(): boolean {\n\t\treturn this._isResponseInArrayMode;\n\t}\n}\n\nexport interface PgliteSessionOptions {\n\tlogger?: Logger;\n\tcache?: Cache;\n}\n\nexport class PgliteSession<\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n> extends PgSession<PgliteQueryResultHKT, TFullSchema, TSchema> {\n\tstatic override readonly [entityKind]: string = 'PgliteSession';\n\n\tprivate logger: Logger;\n\tprivate cache: Cache;\n\n\tconstructor(\n\t\tprivate client: PgliteClient | TraLine truncated
|
||||
Reference in new issue
Block a user