@dudousxd/nestjs-durable-store-typeorm 0.29.0 → 0.30.0

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/dist/index.cjs CHANGED
@@ -39,6 +39,8 @@ __export(index_exports, {
39
39
  durableColumnResolver: () => durableColumnResolver,
40
40
  durableEntities: () => durableEntities,
41
41
  durableManagedTables: () => durableManagedTables,
42
+ durableSchemaName: () => durableSchemaName,
43
+ durableTableSchema: () => durableTableSchema,
42
44
  ensureTypeOrmDurableSchema: () => ensureTypeOrmDurableSchema,
43
45
  jsonBlobColumnType: () => jsonBlobColumnType,
44
46
  parseJsonColumn: () => parseJsonColumn,
@@ -188,12 +190,27 @@ var ScheduleEntity = class {
188
190
  createdAt;
189
191
  updatedAt;
190
192
  };
193
+ var SCHEMA_NAME = /^[A-Za-z_][A-Za-z0-9_$]*$/;
194
+ function durableSchemaName(schema) {
195
+ if (schema === void 0) return void 0;
196
+ if (!SCHEMA_NAME.test(schema) || schema.length > 63) {
197
+ throw new Error(`[nestjs-durable] invalid schema ${JSON.stringify(schema)}: use letters, digits, _ or $ (not first), at most 63 characters.`);
198
+ }
199
+ return schema;
200
+ }
201
+ __name(durableSchemaName, "durableSchemaName");
191
202
  function durableEntities(options = {}) {
192
203
  const col = columnNamer(options.naming ?? "snake_case");
204
+ const schema = durableSchemaName(options.schema);
205
+ const where = schema === void 0 ? {} : {
206
+ schema,
207
+ database: schema
208
+ };
193
209
  const workflowRuns = new import_typeorm.EntitySchema({
194
210
  name: "WorkflowRunEntity",
195
211
  target: WorkflowRunEntity,
196
212
  tableName: "durable_workflow_runs",
213
+ ...where,
197
214
  columns: {
198
215
  id: {
199
216
  type: "text",
@@ -328,6 +345,7 @@ function durableEntities(options = {}) {
328
345
  name: "StepCheckpointEntity",
329
346
  target: StepCheckpointEntity,
330
347
  tableName: "durable_step_checkpoints",
348
+ ...where,
331
349
  // A run's fan, in member order: `checkpointStats`/`queryCheckpoints` narrow by group and page by
332
350
  // seq. The DDL that actually creates it lives in `ensureTypeOrmDurableSchema`.
333
351
  indices: [
@@ -431,6 +449,7 @@ function durableEntities(options = {}) {
431
449
  name: "RunAttributeEntity",
432
450
  target: RunAttributeEntity,
433
451
  tableName: "durable_run_attributes",
452
+ ...where,
434
453
  columns: {
435
454
  runId: {
436
455
  type: "text",
@@ -459,6 +478,7 @@ function durableEntities(options = {}) {
459
478
  name: "SignalWaiterEntity",
460
479
  target: SignalWaiterEntity,
461
480
  tableName: "durable_signal_waiters",
481
+ ...where,
462
482
  indices: [
463
483
  {
464
484
  name: "durable_signal_waiters_run_id_idx",
@@ -495,6 +515,7 @@ function durableEntities(options = {}) {
495
515
  name: "BufferedSignalEntity",
496
516
  target: BufferedSignalEntity,
497
517
  tableName: "durable_buffered_signals",
518
+ ...where,
498
519
  columns: {
499
520
  // Auto-increment PK for FIFO ordering. Left as TypeORM's default increment generation so it
500
521
  // maps to the driver-native auto-increment column (INTEGER on SQLite, BIGINT/SERIAL elsewhere).
@@ -520,6 +541,7 @@ function durableEntities(options = {}) {
520
541
  name: "BufferedEventEntity",
521
542
  target: BufferedEventEntity,
522
543
  tableName: "durable_buffered_events",
544
+ ...where,
523
545
  // No `indices` here (unlike MikroORM's EntitySchema, which does declare one): this store manages
524
546
  // its DDL — including the `(name, publishedAt)` index — via raw SQL in `schema.ts`'s
525
547
  // `ensureTypeOrmDurableSchema`, the same as every other durable_* table's indexes.
@@ -551,6 +573,7 @@ function durableEntities(options = {}) {
551
573
  name: "SignalIdEntity",
552
574
  target: SignalIdEntity,
553
575
  tableName: "durable_signal_ids",
576
+ ...where,
554
577
  // Its `(token, signal_id)` key and `expires_at` index are raw DDL in `schema.ts`, like every
555
578
  // other durable table's.
556
579
  columns: {
@@ -574,6 +597,7 @@ function durableEntities(options = {}) {
574
597
  name: "ScheduleEntity",
575
598
  target: ScheduleEntity,
576
599
  tableName: "durable_schedules",
600
+ ...where,
577
601
  columns: {
578
602
  id: {
579
603
  type: "text",
@@ -716,6 +740,22 @@ function durableColumnResolver(dataSource) {
716
740
  };
717
741
  }
718
742
  __name(durableColumnResolver, "durableColumnResolver");
743
+ function durableTableSchema(dataSource, configured) {
744
+ const wanted = durableSchemaName(configured);
745
+ const args = dataSource.getMetadata(WorkflowRunEntity).tableMetadataArgs;
746
+ const registered = args.database ?? args.schema;
747
+ const type = String(dataSource.options.type);
748
+ const isSqlite = type === "sqlite" || type === "better-sqlite3" || type === "expo";
749
+ const schema = wanted ?? registered;
750
+ if (schema !== void 0 && isSqlite) {
751
+ throw new Error(`[nestjs-durable] store-typeorm: the schema option (${JSON.stringify(schema)}) is not supported on SQLite, which has no schemas. Remove it from the store options and from durableEntities().`);
752
+ }
753
+ if (wanted !== void 0 && wanted !== registered) {
754
+ throw new Error(`[nestjs-durable] store-typeorm: the store's schema is ${JSON.stringify(wanted)}, but the durable entities were registered ${registered === void 0 ? "without one" : `with ${JSON.stringify(registered)}`}. Register durableEntities({ schema: ${JSON.stringify(wanted)} }) in your DataSource.`);
755
+ }
756
+ return schema;
757
+ }
758
+ __name(durableTableSchema, "durableTableSchema");
719
759
  function jsonBlobColumnType(isMysql) {
720
760
  return isMysql ? "longtext" : "text";
721
761
  }
@@ -755,6 +795,8 @@ __name(typeOrmSchemaRepairWarning, "typeOrmSchemaRepairWarning");
755
795
  async function ensureTypeOrmDurableSchema(dataSource, options = {}) {
756
796
  const logger = options.logger ?? console;
757
797
  const q = /* @__PURE__ */ __name((id) => dataSource.driver.escape(id), "q");
798
+ const schema = durableTableSchema(dataSource, options.schema);
799
+ const qt = /* @__PURE__ */ __name((table) => schema === void 0 ? q(table) : `${q(schema)}.${q(table)}`, "qt");
758
800
  const resolve = durableColumnResolver(dataSource);
759
801
  const type = String(dataSource.options.type);
760
802
  const isPg = type === "postgres" || type === "aurora-postgres";
@@ -765,21 +807,21 @@ async function ensureTypeOrmDurableSchema(dataSource, options = {}) {
765
807
  const int = isMysql ? "int" : "integer";
766
808
  const ts = isPg ? "timestamptz" : isMysql ? MYSQL_DATETIME_TYPE : "datetime";
767
809
  const nsCol = `${str} NOT NULL DEFAULT 'default'`;
768
- const runs = q("durable_workflow_runs");
769
- const checkpoints = q("durable_step_checkpoints");
770
- const runAttributes = q("durable_run_attributes");
771
- const waiters = q("durable_signal_waiters");
772
- const buffered = q("durable_buffered_signals");
773
- const bufferedEvents = q("durable_buffered_events");
810
+ const runs = qt("durable_workflow_runs");
811
+ const checkpoints = qt("durable_step_checkpoints");
812
+ const runAttributes = qt("durable_run_attributes");
813
+ const waiters = qt("durable_signal_waiters");
814
+ const buffered = qt("durable_buffered_signals");
815
+ const bufferedEvents = qt("durable_buffered_events");
774
816
  const runsCol = /* @__PURE__ */ __name((property) => q(resolve("durable_workflow_runs", property)), "runsCol");
775
817
  const cpCol = /* @__PURE__ */ __name((property) => q(resolve("durable_step_checkpoints", property)), "cpCol");
776
818
  const attrCol = /* @__PURE__ */ __name((property) => q(resolve("durable_run_attributes", property)), "attrCol");
777
819
  const waiterCol = /* @__PURE__ */ __name((property) => q(resolve("durable_signal_waiters", property)), "waiterCol");
778
820
  const bufCol = /* @__PURE__ */ __name((property) => q(resolve("durable_buffered_signals", property)), "bufCol");
779
821
  const bevCol = /* @__PURE__ */ __name((property) => q(resolve("durable_buffered_events", property)), "bevCol");
780
- const schedules = q("durable_schedules");
822
+ const schedules = qt("durable_schedules");
781
823
  const schCol = /* @__PURE__ */ __name((property) => q(resolve("durable_schedules", property)), "schCol");
782
- const signalIds = q("durable_signal_ids");
824
+ const signalIds = qt("durable_signal_ids");
783
825
  const sidCol = /* @__PURE__ */ __name((property) => q(resolve("durable_signal_ids", property)), "sidCol");
784
826
  const num = isPg ? "double precision" : isMysql ? "double" : "real";
785
827
  const bufferedId = isSqlite ? `${bufCol("id")} integer PRIMARY KEY AUTOINCREMENT` : isMysql ? `${bufCol("id")} bigint NOT NULL AUTO_INCREMENT PRIMARY KEY` : isPg ? `${bufCol("id")} bigserial PRIMARY KEY` : `${bufCol("id")} bigint NOT NULL AUTO_INCREMENT PRIMARY KEY`;
@@ -984,9 +1026,14 @@ async function ensureTypeOrmDurableSchema(dataSource, options = {}) {
984
1026
  const created = /* @__PURE__ */ new Set();
985
1027
  const runner = dataSource.createQueryRunner();
986
1028
  try {
1029
+ if (schema !== void 0) await createSchemaIfMissing(runner, schema, {
1030
+ isMysql,
1031
+ q
1032
+ });
987
1033
  const before = await existingTables(runner, {
988
1034
  isSqlite,
989
- isMysql
1035
+ isMysql,
1036
+ schema
990
1037
  });
991
1038
  for (const [table, sql] of tables) {
992
1039
  await runner.query(sql);
@@ -998,25 +1045,26 @@ async function ensureTypeOrmDurableSchema(dataSource, options = {}) {
998
1045
  for (const [table, props] of Object.entries(additive)) {
999
1046
  const have = await existingColumns(runner, table, {
1000
1047
  isSqlite,
1001
- isMysql
1048
+ isMysql,
1049
+ schema
1002
1050
  });
1003
1051
  for (const [property, colType] of props) {
1004
1052
  const column = resolve(table, property);
1005
1053
  if (!have.has(column)) {
1006
- await runner.query(`ALTER TABLE ${q(table)} ADD COLUMN ${q(column)} ${colType}`);
1054
+ await runner.query(`ALTER TABLE ${qt(table)} ADD COLUMN ${q(column)} ${colType}`);
1007
1055
  repairs.push(`added column ${table}.${column}`);
1008
1056
  }
1009
1057
  }
1010
1058
  }
1011
1059
  if (isMysql) {
1012
1060
  for (const [table, props] of Object.entries(JSON_BLOB_COLUMNS)) {
1013
- const types = await mysqlColumnTypes(runner, table);
1061
+ const types = await mysqlColumnTypes(runner, table, schema);
1014
1062
  for (const prop of props) {
1015
1063
  const column = resolve(table, prop);
1016
1064
  const current = types.get(column);
1017
1065
  if (current === void 0 || current === "longtext") continue;
1018
1066
  try {
1019
- await runner.query(`ALTER TABLE ${q(table)} MODIFY COLUMN ${q(column)} ${jsonBlobColumnType(true)}`);
1067
+ await runner.query(`ALTER TABLE ${qt(table)} MODIFY COLUMN ${q(column)} ${jsonBlobColumnType(true)}`);
1020
1068
  repairs.push(`widened ${table}.${column} from ${current} to longtext`);
1021
1069
  } catch {
1022
1070
  }
@@ -1026,14 +1074,14 @@ async function ensureTypeOrmDurableSchema(dataSource, options = {}) {
1026
1074
  if (isMysql) {
1027
1075
  for (const [table, props] of Object.entries(DATETIME_COLUMNS)) {
1028
1076
  if (created.has(table)) continue;
1029
- const columns = await mysqlDatetimeColumns(runner, table);
1077
+ const columns = await mysqlDatetimeColumns(runner, table, schema);
1030
1078
  const behind = props.map((prop) => resolve(table, prop)).filter((column) => {
1031
1079
  const current = columns.get(column);
1032
1080
  return current !== void 0 && current.precision < 6;
1033
1081
  });
1034
1082
  if (behind.length === 0) continue;
1035
- const statement = `ALTER TABLE ${q(table)} ${behind.map((column) => `MODIFY COLUMN ${q(column)} ${MYSQL_DATETIME_TYPE} ${columns.get(column)?.nullable ? "NULL" : "NOT NULL"}`).join(", ")}`;
1036
- const rows = await mysqlEstimatedRows(runner, table);
1083
+ const statement = `ALTER TABLE ${qt(table)} ${behind.map((column) => `MODIFY COLUMN ${q(column)} ${MYSQL_DATETIME_TYPE} ${columns.get(column)?.nullable ? "NULL" : "NOT NULL"}`).join(", ")}`;
1084
+ const rows = await mysqlEstimatedRows(runner, table, schema);
1037
1085
  if (rows > rowLimit) {
1038
1086
  deferred.push({
1039
1087
  table,
@@ -1144,10 +1192,10 @@ async function ensureTypeOrmDurableSchema(dataSource, options = {}) {
1144
1192
  if (deferred.length > 0) logger.warn(typeOrmDeferredAlterWarning(deferred, rowLimit));
1145
1193
  }
1146
1194
  __name(ensureTypeOrmDurableSchema, "ensureTypeOrmDurableSchema");
1147
- async function mysqlDatetimeColumns(runner, table) {
1148
- const rows = await runner.query("SELECT column_name AS name, datetime_precision AS `precision`, is_nullable AS nullable FROM information_schema.columns WHERE table_name = ? AND TABLE_SCHEMA = DATABASE() AND data_type = 'datetime'", [
1195
+ async function mysqlDatetimeColumns(runner, table, schema) {
1196
+ const rows = await runner.query(`SELECT column_name AS name, datetime_precision AS \`precision\`, is_nullable AS nullable FROM information_schema.columns WHERE table_name = ? AND ${mysqlScope(schema)} AND data_type = 'datetime'`, mysqlParams([
1149
1197
  table
1150
- ]);
1198
+ ], schema));
1151
1199
  return new Map(rows.map((r) => [
1152
1200
  r.name,
1153
1201
  {
@@ -1157,10 +1205,10 @@ async function mysqlDatetimeColumns(runner, table) {
1157
1205
  ]));
1158
1206
  }
1159
1207
  __name(mysqlDatetimeColumns, "mysqlDatetimeColumns");
1160
- async function mysqlEstimatedRows(runner, table) {
1161
- const rows = await runner.query("SELECT table_rows AS n FROM information_schema.tables WHERE table_name = ? AND TABLE_SCHEMA = DATABASE() LIMIT 1", [
1208
+ async function mysqlEstimatedRows(runner, table, schema) {
1209
+ const rows = await runner.query(`SELECT table_rows AS n FROM information_schema.tables WHERE table_name = ? AND ${mysqlScope(schema)} LIMIT 1`, mysqlParams([
1162
1210
  table
1163
- ]);
1211
+ ], schema));
1164
1212
  return Number(rows[0]?.n ?? 0);
1165
1213
  }
1166
1214
  __name(mysqlEstimatedRows, "mysqlEstimatedRows");
@@ -1170,15 +1218,17 @@ async function existingTables(runner, d) {
1170
1218
  const rows2 = await runner.query("SELECT name FROM sqlite_master WHERE type = 'table'");
1171
1219
  return new Set(rows2.map((r) => r.name).filter((name) => names.includes(name)));
1172
1220
  }
1173
- const scope = d.isMysql ? "TABLE_SCHEMA = DATABASE()" : "table_schema = current_schema()";
1174
- const rows = await runner.query(`SELECT table_name AS name FROM information_schema.tables WHERE ${scope}`);
1221
+ const scope = d.isMysql ? mysqlScope(d.schema) : pgScope(d.schema, 1);
1222
+ const rows = await runner.query(`SELECT table_name AS name FROM information_schema.tables WHERE ${scope}`, d.schema === void 0 ? void 0 : [
1223
+ d.schema
1224
+ ]);
1175
1225
  return new Set(rows.map((r) => r.name ?? r.TABLE_NAME).filter((name) => names.includes(name)));
1176
1226
  }
1177
1227
  __name(existingTables, "existingTables");
1178
- async function mysqlColumnTypes(runner, table) {
1179
- const rows = await runner.query("SELECT column_name AS name, data_type AS type FROM information_schema.columns WHERE table_name = ? AND TABLE_SCHEMA = DATABASE()", [
1228
+ async function mysqlColumnTypes(runner, table, schema) {
1229
+ const rows = await runner.query(`SELECT column_name AS name, data_type AS type FROM information_schema.columns WHERE table_name = ? AND ${mysqlScope(schema)}`, mysqlParams([
1180
1230
  table
1181
- ]);
1231
+ ], schema));
1182
1232
  return new Map(rows.map((r) => [
1183
1233
  r.name ?? r.COLUMN_NAME,
1184
1234
  String(r.type ?? r.DATA_TYPE).toLowerCase()
@@ -1190,14 +1240,46 @@ async function existingColumns(runner, table, d) {
1190
1240
  const rows2 = await runner.query(`PRAGMA table_info("${table}")`);
1191
1241
  return new Set(rows2.map((r) => r.name));
1192
1242
  }
1193
- const scope = d.isMysql ? "TABLE_SCHEMA = DATABASE()" : "table_schema = current_schema()";
1243
+ const scope = d.isMysql ? mysqlScope(d.schema) : pgScope(d.schema, 2);
1194
1244
  const placeholder = d.isMysql ? "?" : "$1";
1195
- const rows = await runner.query(`SELECT column_name AS name FROM information_schema.columns WHERE table_name = ${placeholder} AND ${scope}`, [
1245
+ const rows = await runner.query(`SELECT column_name AS name FROM information_schema.columns WHERE table_name = ${placeholder} AND ${scope}`, d.schema === void 0 ? [
1196
1246
  table
1247
+ ] : [
1248
+ table,
1249
+ d.schema
1197
1250
  ]);
1198
1251
  return new Set(rows.map((r) => r.name ?? r.COLUMN_NAME));
1199
1252
  }
1200
1253
  __name(existingColumns, "existingColumns");
1254
+ function mysqlScope(schema) {
1255
+ return schema === void 0 ? "TABLE_SCHEMA = DATABASE()" : "TABLE_SCHEMA = ?";
1256
+ }
1257
+ __name(mysqlScope, "mysqlScope");
1258
+ function mysqlParams(params, schema) {
1259
+ return schema === void 0 ? params : [
1260
+ ...params,
1261
+ schema
1262
+ ];
1263
+ }
1264
+ __name(mysqlParams, "mysqlParams");
1265
+ function pgScope(schema, n) {
1266
+ return schema === void 0 ? "table_schema = current_schema()" : `table_schema = $${n}`;
1267
+ }
1268
+ __name(pgScope, "pgScope");
1269
+ async function createSchemaIfMissing(runner, schema, d) {
1270
+ const rows = await runner.query(d.isMysql ? "SELECT 1 AS found FROM information_schema.schemata WHERE schema_name = ?" : "SELECT 1 AS found FROM pg_namespace WHERE nspname = $1", [
1271
+ schema
1272
+ ]);
1273
+ if (rows.length > 0) return;
1274
+ try {
1275
+ await runner.query(`${d.isMysql ? "CREATE DATABASE" : "CREATE SCHEMA"} IF NOT EXISTS ${d.q(schema)}`);
1276
+ } catch (err) {
1277
+ throw new Error(`[nestjs-durable] store-typeorm could not create the ${d.isMysql ? "database" : "schema"} "${schema}" for the durable tables. Create it ahead of time, or grant this role ${d.isMysql ? "CREATE" : "CREATE on the database (GRANT CREATE ON DATABASE <db> TO <role>)"}. Cause: ${err.message}`, {
1278
+ cause: err
1279
+ });
1280
+ }
1281
+ }
1282
+ __name(createSchemaIfMissing, "createSchemaIfMissing");
1201
1283
 
1202
1284
  // src/typeorm-state-store.ts
1203
1285
  var import_nestjs_durable_core = require("@dudousxd/nestjs-durable-core");
@@ -1222,10 +1304,11 @@ var TypeOrmStateStore = class {
1222
1304
  constructor(dataSource, options = {}) {
1223
1305
  this.dataSource = dataSource;
1224
1306
  this.options = options;
1307
+ if (dataSource.isInitialized) this.tableSchema();
1225
1308
  const type = String(dataSource.options.type);
1226
1309
  const dialect = type === "postgres" ? "postgres" : type === "mysql" ? "mysql" : void 0;
1227
1310
  if (!dialect) return;
1228
- const fast = new TypeOrmRoundTrips(dataSource, dialect, this);
1311
+ const fast = new TypeOrmRoundTrips(dataSource, dialect, this, () => this.tableSchema());
1229
1312
  this.insertCheckpointIfAbsent = (cp) => fast.insertCheckpointIfAbsent(cp);
1230
1313
  this.settleResultsIfPending = (results) => fast.settleResultsIfPending(results);
1231
1314
  this.claimPendingRuns = (limit, owner, until, now, ns) => fast.claimPendingRuns(limit, owner, until, now, ns);
@@ -1236,9 +1319,18 @@ var TypeOrmStateStore = class {
1236
1319
  async ensureSchema() {
1237
1320
  await ensureTypeOrmDurableSchema(this.dataSource, {
1238
1321
  logger: this.options.schemaLogger,
1239
- blockingAlterRowLimit: this.options.schemaBlockingAlterRowLimit
1322
+ blockingAlterRowLimit: this.options.schemaBlockingAlterRowLimit,
1323
+ schema: this.options.schema
1240
1324
  });
1241
1325
  }
1326
+ resolvedSchema;
1327
+ /** The durable tables' schema (see {@link TypeOrmStateStoreOptions.schema}), resolved once. */
1328
+ tableSchema() {
1329
+ this.resolvedSchema ??= {
1330
+ schema: durableTableSchema(this.dataSource, this.options.schema)
1331
+ };
1332
+ return this.resolvedSchema.schema;
1333
+ }
1242
1334
  runs() {
1243
1335
  return this.dataSource.getRepository(WorkflowRunEntity);
1244
1336
  }
@@ -1881,7 +1973,8 @@ var TypeOrmStateStore = class {
1881
1973
  const runIdCol = wrap(resolve("durable_run_attributes", "runId"));
1882
1974
  const keyCol = wrap(resolve("durable_run_attributes", "key"));
1883
1975
  const runPkCol = wrap(resolve("durable_workflow_runs", "id"));
1884
- const table = wrap("durable_run_attributes");
1976
+ const schema = this.tableSchema();
1977
+ const table = schema === void 0 ? wrap("durable_run_attributes") : `${wrap(schema)}.${wrap("durable_run_attributes")}`;
1885
1978
  const a = `a${i}`;
1886
1979
  const params = {
1887
1980
  [keyParam]: f.key
@@ -2665,12 +2758,14 @@ var TypeOrmRoundTrips = class TypeOrmRoundTrips2 {
2665
2758
  }
2666
2759
  ds;
2667
2760
  store;
2761
+ schema;
2668
2762
  pg;
2669
2763
  /** The checkpoint columns' actual Postgres types (what the schema created), read once. */
2670
2764
  cpTypes;
2671
- constructor(ds, dialect, store) {
2765
+ constructor(ds, dialect, store, schema) {
2672
2766
  this.ds = ds;
2673
2767
  this.store = store;
2768
+ this.schema = schema;
2674
2769
  this.pg = dialect === "postgres";
2675
2770
  }
2676
2771
  get runs() {
@@ -2685,8 +2780,11 @@ var TypeOrmRoundTrips = class TypeOrmRoundTrips2 {
2685
2780
  * `synchronize`), so the value converts exactly as the repository's own writes convert it.
2686
2781
  */
2687
2782
  async cpType(property) {
2688
- this.cpTypes ??= this.ds.query("SELECT column_name AS name, data_type AS type FROM information_schema.columns WHERE table_name = $1 AND table_schema = current_schema()", [
2783
+ this.cpTypes ??= this.ds.query(this.schema() === void 0 ? "SELECT column_name AS name, data_type AS type FROM information_schema.columns WHERE table_name = $1 AND table_schema = current_schema()" : "SELECT column_name AS name, data_type AS type FROM information_schema.columns WHERE table_name = $1 AND table_schema = $2", this.schema() === void 0 ? [
2689
2784
  this.cps.tableName
2785
+ ] : [
2786
+ this.cps.tableName,
2787
+ this.schema()
2690
2788
  ]).then((rows) => new Map(rows.map((r) => [
2691
2789
  r.name,
2692
2790
  r.type
@@ -2709,7 +2807,8 @@ var TypeOrmRoundTrips = class TypeOrmRoundTrips2 {
2709
2807
  return this.q(this.col(meta, property).databaseName);
2710
2808
  }
2711
2809
  table(meta) {
2712
- return this.q(meta.tableName);
2810
+ const schema = this.schema();
2811
+ return schema === void 0 ? this.q(meta.tableName) : `${this.q(schema)}.${this.q(meta.tableName)}`;
2713
2812
  }
2714
2813
  /** `value` as the driver binds it for `property` (transformers and type conversion included). */
2715
2814
  bind(meta, property, value) {
@@ -2917,6 +3016,8 @@ var TypeOrmRoundTrips = class TypeOrmRoundTrips2 {
2917
3016
  durableColumnResolver,
2918
3017
  durableEntities,
2919
3018
  durableManagedTables,
3019
+ durableSchemaName,
3020
+ durableTableSchema,
2920
3021
  ensureTypeOrmDurableSchema,
2921
3022
  jsonBlobColumnType,
2922
3023
  parseJsonColumn,