@dudousxd/nestjs-media-database-drizzle 0.9.0 → 0.10.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.
@@ -5,7 +5,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
5
5
  import { getDrizzleToken } from "@nestjs/drizzle";
6
6
 
7
7
  // src/drizzle-media-store.ts
8
- import { and, asc, count, eq as eq2, getTableColumns, gt, max, or as or2, sql, sum } from "drizzle-orm";
8
+ import { and, asc, count, eq as eq2, getTableColumns, gt, max, or as or2, sql as sql2, sum } from "drizzle-orm";
9
9
 
10
10
  // src/list-cursor.ts
11
11
  function encodeListCursor(record) {
@@ -73,9 +73,24 @@ var mediaTable = sqliteTable2("media", {
73
73
  tenantIdx: index("idx_media_tenant").on(table.tenantId, table.ownerType, table.ownerId, table.collection)
74
74
  }));
75
75
 
76
+ // src/schema-name.ts
77
+ var SCHEMA_NAME = /^[A-Za-z_][A-Za-z0-9_$]*$/;
78
+ function assertSchemaName(schema) {
79
+ if (typeof schema !== "string" || !SCHEMA_NAME.test(schema) || schema.length > 63) {
80
+ throw new TypeError(`[nestjs-media] \`schema\` must match /^[A-Za-z_][A-Za-z0-9_$]*$/ and be at most 63 characters, got ${JSON.stringify(schema)}`);
81
+ }
82
+ }
83
+ __name(assertSchemaName, "assertSchemaName");
84
+ function rejectSqliteSchema(schema) {
85
+ if (schema !== void 0) {
86
+ throw new Error(`[nestjs-media] \`schema: ${JSON.stringify(schema)}\` was set, but SQLite has no schemas. Remove \`schema\`, or use the Postgres store (\`@dudousxd/nestjs-media-database-drizzle/pg\`).`);
87
+ }
88
+ }
89
+ __name(rejectSqliteSchema, "rejectSqliteSchema");
90
+
76
91
  // src/tenancy.ts
77
92
  import { MediaTenancyUnavailableError } from "@dudousxd/nestjs-media-core";
78
- import { eq, isNull, or } from "drizzle-orm";
93
+ import { eq, isNull, or, sql } from "drizzle-orm";
79
94
  function tenantCondition(column, match) {
80
95
  if (match.id === null) return isNull(column);
81
96
  return match.orNull ? or(eq(column, match.id), isNull(column)) : eq(column, match.id);
@@ -97,6 +112,11 @@ async function assertTenantColumn(table, probe, fix) {
97
112
  }
98
113
  }
99
114
  __name(assertTenantColumn, "assertTenantColumn");
115
+ function nameContainsCondition(name, fileName, text5) {
116
+ const pattern = `%${text5.toLowerCase().replace(/[!%_]/g, (c) => `!${c}`)}%`;
117
+ return or(sql`lower(${name}) like ${pattern} escape '!'`, sql`lower(${fileName}) like ${pattern} escape '!'`);
118
+ }
119
+ __name(nameContainsCondition, "nameContainsCondition");
100
120
 
101
121
  // src/drizzle-media-store.ts
102
122
  function toRow(record, tenancy) {
@@ -113,8 +133,10 @@ var DrizzleMediaStore = class {
113
133
  }
114
134
  db;
115
135
  tenancy = false;
116
- constructor(db) {
136
+ /** `schema` is for Postgres only: SQLite has no schemas, so setting it throws. */
137
+ constructor(db, options = {}) {
117
138
  this.db = db;
139
+ rejectSqliteSchema(options.schema);
118
140
  }
119
141
  /** The columns to read: `tenant_id` only once tenancy is on. */
120
142
  get columns() {
@@ -203,6 +225,9 @@ var DrizzleMediaStore = class {
203
225
  ...filter.disk !== void 0 ? [
204
226
  eq2(mediaTable.disk, filter.disk)
205
227
  ] : [],
228
+ ...filter.nameContains !== void 0 ? [
229
+ nameContainsCondition(mediaTable.name, mediaTable.fileName, filter.nameContains)
230
+ ] : [],
206
231
  ...filter.tenant ? [
207
232
  tenantCondition(mediaTable.tenantId, filter.tenant)
208
233
  ] : [],
@@ -229,8 +254,11 @@ var DrizzleMediaStore = class {
229
254
  // src/pg/drizzle-pg-media-store.ts
230
255
  import { and as and2, asc as asc2, count as count2, eq as eq3, getTableColumns as getTableColumns2, gt as gt2, max as max2, or as or3, sum as sum2 } from "drizzle-orm";
231
256
 
257
+ // src/pg/schema.ts
258
+ import { index as index2, integer as integer3, pgSchema, pgTable, primaryKey, text as text4 } from "drizzle-orm/pg-core";
259
+
232
260
  // src/pg/columns.ts
233
- import { bigint, integer as integer2, jsonb, pgTable, text as text3, timestamp } from "drizzle-orm/pg-core";
261
+ import { bigint, integer as integer2, jsonb, text as text3, timestamp } from "drizzle-orm/pg-core";
234
262
  function mediaPgColumns() {
235
263
  return {
236
264
  id: text3("id").primaryKey(),
@@ -285,44 +313,69 @@ function uploadSessionPgColumns() {
285
313
  };
286
314
  }
287
315
  __name(uploadSessionPgColumns, "uploadSessionPgColumns");
288
- var mediaPgTableWithoutTenant = pgTable("media", mediaPgColumns());
289
- var mediaUploadSessionsPgTableWithoutTenant = pgTable("media_upload_sessions", uploadSessionPgColumns());
290
316
 
291
317
  // src/pg/schema.ts
292
- import { index as index2, integer as integer3, pgTable as pgTable2, primaryKey, text as text4 } from "drizzle-orm/pg-core";
293
- var mediaPgTable = pgTable2("media", {
294
- ...mediaPgColumns(),
295
- /** Tenancy only: read and written once the store's `enableTenancy()` ran. */
296
- tenantId: text4("tenant_id")
297
- }, (table) => [
298
- index2("idx_media_owner").on(table.ownerType, table.ownerId, table.collection),
299
- index2("idx_media_collection").on(table.collection),
300
- index2("idx_media_disk").on(table.disk),
301
- index2("idx_media_created_at").on(table.createdAt),
302
- index2("idx_media_collection_created_at").on(table.collection, table.createdAt, table.id),
303
- index2("idx_media_tenant").on(table.tenantId, table.ownerType, table.ownerId, table.collection)
304
- ]);
305
- var mediaUploadSessionsPgTable = pgTable2("media_upload_sessions", {
306
- ...uploadSessionPgColumns(),
307
- /** Tenancy only: read and written once the store's `enableTenancy()` ran. */
308
- tenantId: text4("tenant_id")
309
- }, (table) => [
310
- index2("idx_media_upload_sessions_tenant").on(table.tenantId)
311
- ]);
312
- var mediaUploadPartsPgTable = pgTable2("media_upload_parts", {
313
- sessionId: text4("session_id").notNull().references(() => mediaUploadSessionsPgTable.id, {
314
- onDelete: "cascade"
315
- }),
316
- partNumber: integer3("part_number").notNull(),
317
- etag: text4("etag").notNull()
318
- }, (table) => [
319
- primaryKey({
320
- columns: [
321
- table.sessionId,
322
- table.partNumber
323
- ]
324
- })
325
- ]);
318
+ function tableIn(schema) {
319
+ if (schema === void 0) return pgTable;
320
+ assertSchemaName(schema);
321
+ if (schema === "public") {
322
+ throw new TypeError("[nestjs-media] `schema: 'public'` is Postgres' default schema: leave `schema` unset to use it.");
323
+ }
324
+ return pgSchema(schema).table;
325
+ }
326
+ __name(tableIn, "tableIn");
327
+ function mediaPgTables(schema) {
328
+ const table = tableIn(schema);
329
+ const media = table("media", {
330
+ ...mediaPgColumns(),
331
+ /** Tenancy only: read and written once the store's `enableTenancy()` ran. */
332
+ tenantId: text4("tenant_id")
333
+ }, (t) => [
334
+ index2("idx_media_owner").on(t.ownerType, t.ownerId, t.collection),
335
+ index2("idx_media_collection").on(t.collection),
336
+ index2("idx_media_disk").on(t.disk),
337
+ index2("idx_media_created_at").on(t.createdAt),
338
+ index2("idx_media_collection_created_at").on(t.collection, t.createdAt, t.id),
339
+ index2("idx_media_tenant").on(t.tenantId, t.ownerType, t.ownerId, t.collection)
340
+ ]);
341
+ const uploadSessions = table("media_upload_sessions", {
342
+ ...uploadSessionPgColumns(),
343
+ /** Tenancy only: read and written once the store's `enableTenancy()` ran. */
344
+ tenantId: text4("tenant_id")
345
+ }, (t) => [
346
+ index2("idx_media_upload_sessions_tenant").on(t.tenantId)
347
+ ]);
348
+ const uploadParts = table("media_upload_parts", {
349
+ sessionId: text4("session_id").notNull().references(() => uploadSessions.id, {
350
+ onDelete: "cascade"
351
+ }),
352
+ partNumber: integer3("part_number").notNull(),
353
+ etag: text4("etag").notNull()
354
+ }, (t) => [
355
+ primaryKey({
356
+ columns: [
357
+ t.sessionId,
358
+ t.partNumber
359
+ ]
360
+ })
361
+ ]);
362
+ return {
363
+ media,
364
+ uploadSessions,
365
+ uploadParts,
366
+ /**
367
+ * Internal: the tables without `tenant_id`. The stores insert through them while tenancy is
368
+ * off, because Drizzle lists every column of a table in an `INSERT`.
369
+ */
370
+ mediaWithoutTenant: table("media", mediaPgColumns()),
371
+ uploadSessionsWithoutTenant: table("media_upload_sessions", uploadSessionPgColumns())
372
+ };
373
+ }
374
+ __name(mediaPgTables, "mediaPgTables");
375
+ var unqualified = mediaPgTables();
376
+ var mediaPgTable = unqualified.media;
377
+ var mediaUploadSessionsPgTable = unqualified.uploadSessions;
378
+ var mediaUploadPartsPgTable = unqualified.uploadParts;
326
379
 
327
380
  // src/pg/drizzle-pg-media-store.ts
328
381
  function toRecord(row) {
@@ -346,12 +399,18 @@ var DrizzlePgMediaStore = class {
346
399
  }
347
400
  db;
348
401
  tenancy = false;
349
- constructor(db) {
402
+ t;
403
+ /**
404
+ * `schema`: the Postgres schema the `media` table lives in. Every statement names it
405
+ * (`search_path` is never used). Default: unqualified, the connection's current schema.
406
+ */
407
+ constructor(db, options = {}) {
350
408
  this.db = db;
409
+ this.t = mediaPgTables(options.schema);
351
410
  }
352
411
  /** The columns to read: `tenant_id` only once tenancy is on. */
353
412
  get columns() {
354
- return selectable(getTableColumns2(mediaPgTable), this.tenancy);
413
+ return selectable(getTableColumns2(this.t.media), this.tenancy);
355
414
  }
356
415
  /**
357
416
  * Tenancy: checks the `tenant_id` column exists, then reads and writes it. Called by the
@@ -359,66 +418,66 @@ var DrizzlePgMediaStore = class {
359
418
  */
360
419
  async enableTenancy() {
361
420
  await assertTenantColumn("media", () => this.db.select({
362
- tenantId: mediaPgTable.tenantId
363
- }).from(mediaPgTable).limit(1), "Generate a migration with drizzle-kit from `mediaPgTable` (it declares `tenant_id` and the `idx_media_tenant` index), or run `ALTER TABLE media ADD COLUMN tenant_id text; CREATE INDEX idx_media_tenant ON media (tenant_id, owner_type, owner_id, collection);`.");
421
+ tenantId: this.t.media.tenantId
422
+ }).from(this.t.media).limit(1), "Generate a migration with drizzle-kit from `mediaPgTable` (or the tables of `mediaPgTables(schema)`; it declares `tenant_id` and the `idx_media_tenant` index), or run `ALTER TABLE media ADD COLUMN tenant_id text; CREATE INDEX idx_media_tenant ON media (tenant_id, owner_type, owner_id, collection);`.");
364
423
  this.tenancy = true;
365
424
  }
366
425
  async save(record) {
367
426
  const row = toRow2(record, this.tenancy);
368
427
  const { id: _id, ...rest } = row;
369
- await this.db.insert(this.tenancy ? mediaPgTable : mediaPgTableWithoutTenant).values(row).onConflictDoUpdate({
370
- target: mediaPgTable.id,
428
+ await this.db.insert(this.tenancy ? this.t.media : this.t.mediaWithoutTenant).values(row).onConflictDoUpdate({
429
+ target: this.t.media.id,
371
430
  set: rest
372
431
  });
373
432
  return row;
374
433
  }
375
434
  async find(id) {
376
- const rows = await this.db.select(this.columns).from(mediaPgTable).where(eq3(mediaPgTable.id, id)).limit(1);
435
+ const rows = await this.db.select(this.columns).from(this.t.media).where(eq3(this.t.media.id, id)).limit(1);
377
436
  const row = rows[0];
378
437
  return row ? toRecord(row) : null;
379
438
  }
380
439
  async listByOwner(ownerType, ownerId, collection) {
381
- const where = collection === void 0 ? and2(eq3(mediaPgTable.ownerType, ownerType), eq3(mediaPgTable.ownerId, ownerId)) : and2(eq3(mediaPgTable.ownerType, ownerType), eq3(mediaPgTable.ownerId, ownerId), eq3(mediaPgTable.collection, collection));
382
- const rows = await this.db.select(this.columns).from(mediaPgTable).where(where).orderBy(asc2(mediaPgTable.order), asc2(mediaPgTable.id));
440
+ const where = collection === void 0 ? and2(eq3(this.t.media.ownerType, ownerType), eq3(this.t.media.ownerId, ownerId)) : and2(eq3(this.t.media.ownerType, ownerType), eq3(this.t.media.ownerId, ownerId), eq3(this.t.media.collection, collection));
441
+ const rows = await this.db.select(this.columns).from(this.t.media).where(where).orderBy(asc2(this.t.media.order), asc2(this.t.media.id));
383
442
  return rows.map(toRecord);
384
443
  }
385
444
  async delete(id) {
386
- await this.db.delete(mediaPgTable).where(eq3(mediaPgTable.id, id));
445
+ await this.db.delete(this.t.media).where(eq3(this.t.media.id, id));
387
446
  }
388
447
  async nextOrder(ownerType, ownerId, collection) {
389
448
  const rows = await this.db.select({
390
- max: max2(mediaPgTable.order)
391
- }).from(mediaPgTable).where(and2(eq3(mediaPgTable.ownerType, ownerType), eq3(mediaPgTable.ownerId, ownerId), eq3(mediaPgTable.collection, collection)));
449
+ max: max2(this.t.media.order)
450
+ }).from(this.t.media).where(and2(eq3(this.t.media.ownerType, ownerType), eq3(this.t.media.ownerId, ownerId), eq3(this.t.media.collection, collection)));
392
451
  const top = rows[0]?.max;
393
452
  return top == null ? 0 : Number(top) + 1;
394
453
  }
395
454
  async count(filter = {}) {
396
455
  const conditions = [
397
456
  ...filter.ownerType !== void 0 ? [
398
- eq3(mediaPgTable.ownerType, filter.ownerType)
457
+ eq3(this.t.media.ownerType, filter.ownerType)
399
458
  ] : [],
400
459
  ...filter.collection !== void 0 ? [
401
- eq3(mediaPgTable.collection, filter.collection)
460
+ eq3(this.t.media.collection, filter.collection)
402
461
  ] : [],
403
462
  ...filter.disk !== void 0 ? [
404
- eq3(mediaPgTable.disk, filter.disk)
463
+ eq3(this.t.media.disk, filter.disk)
405
464
  ] : [],
406
465
  ...filter.tenant ? [
407
- tenantCondition(mediaPgTable.tenantId, filter.tenant)
466
+ tenantCondition(this.t.media.tenantId, filter.tenant)
408
467
  ] : []
409
468
  ];
410
469
  const rows = await this.db.select({
411
470
  value: count2()
412
- }).from(mediaPgTable).where(conditions.length ? and2(...conditions) : void 0);
471
+ }).from(this.t.media).where(conditions.length ? and2(...conditions) : void 0);
413
472
  return Number(rows[0]?.value ?? 0);
414
473
  }
415
474
  async aggregate(query) {
416
- const column = query.groupBy === "collection" ? mediaPgTable.collection : mediaPgTable.disk;
475
+ const column = query.groupBy === "collection" ? this.t.media.collection : this.t.media.disk;
417
476
  const rows = await this.db.select({
418
477
  key: column,
419
478
  count: count2(),
420
- sumSize: sum2(mediaPgTable.size)
421
- }).from(mediaPgTable).where(query.tenant ? tenantCondition(mediaPgTable.tenantId, query.tenant) : void 0).groupBy(column);
479
+ sumSize: sum2(this.t.media.size)
480
+ }).from(this.t.media).where(query.tenant ? tenantCondition(this.t.media.tenantId, query.tenant) : void 0).groupBy(column);
422
481
  return rows.map((row) => ({
423
482
  key: row.key,
424
483
  count: Number(row.count),
@@ -431,22 +490,25 @@ var DrizzlePgMediaStore = class {
431
490
  const cursor = page.cursor ? decodeListCursor(page.cursor) : null;
432
491
  const filterConditions = [
433
492
  ...filter.ownerType !== void 0 ? [
434
- eq3(mediaPgTable.ownerType, filter.ownerType)
493
+ eq3(this.t.media.ownerType, filter.ownerType)
435
494
  ] : [],
436
495
  ...filter.collection !== void 0 ? [
437
- eq3(mediaPgTable.collection, filter.collection)
496
+ eq3(this.t.media.collection, filter.collection)
438
497
  ] : [],
439
498
  ...filter.disk !== void 0 ? [
440
- eq3(mediaPgTable.disk, filter.disk)
499
+ eq3(this.t.media.disk, filter.disk)
500
+ ] : [],
501
+ ...filter.nameContains !== void 0 ? [
502
+ nameContainsCondition(this.t.media.name, this.t.media.fileName, filter.nameContains)
441
503
  ] : [],
442
504
  ...filter.tenant ? [
443
- tenantCondition(mediaPgTable.tenantId, filter.tenant)
505
+ tenantCondition(this.t.media.tenantId, filter.tenant)
444
506
  ] : [],
445
507
  ...cursor ? [
446
- or3(gt2(mediaPgTable.createdAt, cursor.createdAt), and2(eq3(mediaPgTable.createdAt, cursor.createdAt), gt2(mediaPgTable.id, cursor.id)))
508
+ or3(gt2(this.t.media.createdAt, cursor.createdAt), and2(eq3(this.t.media.createdAt, cursor.createdAt), gt2(this.t.media.id, cursor.id)))
447
509
  ] : []
448
510
  ];
449
- const rows = await this.db.select(this.columns).from(mediaPgTable).where(filterConditions.length ? and2(...filterConditions) : void 0).orderBy(asc2(mediaPgTable.createdAt), asc2(mediaPgTable.id)).limit(limit + 1);
511
+ const rows = await this.db.select(this.columns).from(this.t.media).where(filterConditions.length ? and2(...filterConditions) : void 0).orderBy(asc2(this.t.media.createdAt), asc2(this.t.media.id)).limit(limit + 1);
450
512
  const hasMore = rows.length > limit;
451
513
  const records = rows.slice(0, limit).map(toRecord);
452
514
  const result = {
@@ -461,7 +523,7 @@ var DrizzlePgMediaStore = class {
461
523
  };
462
524
 
463
525
  // src/pg/drizzle-pg-upload-session-store.ts
464
- import { and as and3, asc as asc3, eq as eq4, getTableColumns as getTableColumns3, like, sql as sql2 } from "drizzle-orm";
526
+ import { and as and3, asc as asc3, eq as eq4, getTableColumns as getTableColumns3, like, sql as sql3 } from "drizzle-orm";
465
527
  function escapeLike(value) {
466
528
  return value.replace(/[\\%_]/g, (char) => `\\${char}`);
467
529
  }
@@ -505,16 +567,22 @@ var DrizzlePgUploadSessionStore = class {
505
567
  }
506
568
  db;
507
569
  tenancy = false;
508
- constructor(db) {
570
+ t;
571
+ /**
572
+ * `schema`: the Postgres schema of `media_upload_sessions` / `media_upload_parts`. Every
573
+ * statement names it (`search_path` is never used). Default: unqualified.
574
+ */
575
+ constructor(db, options = {}) {
509
576
  this.db = db;
577
+ this.t = mediaPgTables(options.schema);
510
578
  }
511
579
  /** Off: the table without `tenant_id`, which Drizzle would otherwise list in an INSERT. */
512
580
  get sessionsTable() {
513
- return this.tenancy ? mediaUploadSessionsPgTable : mediaUploadSessionsPgTableWithoutTenant;
581
+ return this.tenancy ? this.t.uploadSessions : this.t.uploadSessionsWithoutTenant;
514
582
  }
515
583
  /** The columns to read: `tenant_id` only once tenancy is on. */
516
584
  get columns() {
517
- return selectable(getTableColumns3(mediaUploadSessionsPgTable), this.tenancy);
585
+ return selectable(getTableColumns3(this.t.uploadSessions), this.tenancy);
518
586
  }
519
587
  /**
520
588
  * Tenancy: checks the `tenant_id` column exists, then reads and writes it. Called by the upload
@@ -522,8 +590,8 @@ var DrizzlePgUploadSessionStore = class {
522
590
  */
523
591
  async enableTenancy() {
524
592
  await assertTenantColumn("media_upload_sessions", () => this.db.select({
525
- tenantId: mediaUploadSessionsPgTable.tenantId
526
- }).from(mediaUploadSessionsPgTable).limit(1), "Generate a migration with drizzle-kit from `mediaUploadSessionsPgTable` (it declares `tenant_id` and its index), or run `ALTER TABLE media_upload_sessions ADD COLUMN tenant_id text; CREATE INDEX idx_media_upload_sessions_tenant ON media_upload_sessions (tenant_id);`.");
593
+ tenantId: this.t.uploadSessions.tenantId
594
+ }).from(this.t.uploadSessions).limit(1), "Generate a migration with drizzle-kit from `mediaUploadSessionsPgTable` (or the tables of `mediaPgTables(schema)`; it declares `tenant_id` and its index), or run `ALTER TABLE media_upload_sessions ADD COLUMN tenant_id text; CREATE INDEX idx_media_upload_sessions_tenant ON media_upload_sessions (tenant_id);`.");
527
595
  this.tenancy = true;
528
596
  }
529
597
  /** The session as persisted: off, no `tenantId`; on, `tenantId` or `null`. */
@@ -548,7 +616,7 @@ var DrizzlePgUploadSessionStore = class {
548
616
  };
549
617
  }
550
618
  async get(id) {
551
- const rows = await this.db.select(this.columns).from(mediaUploadSessionsPgTable).where(eq4(mediaUploadSessionsPgTable.id, id)).limit(1);
619
+ const rows = await this.db.select(this.columns).from(this.t.uploadSessions).where(eq4(this.t.uploadSessions.id, id)).limit(1);
552
620
  const row = rows[0];
553
621
  return row ? toSession(row) : null;
554
622
  }
@@ -564,34 +632,34 @@ var DrizzlePgUploadSessionStore = class {
564
632
  id: session.id,
565
633
  ...columns
566
634
  }).onConflictDoUpdate({
567
- target: mediaUploadSessionsPgTable.id,
635
+ target: this.t.uploadSessions.id,
568
636
  set: columns
569
637
  });
570
638
  return this.persisted(session);
571
639
  }
572
640
  async delete(id) {
573
- await this.db.delete(mediaUploadSessionsPgTable).where(eq4(mediaUploadSessionsPgTable.id, id));
641
+ await this.db.delete(this.t.uploadSessions).where(eq4(this.t.uploadSessions.id, id));
574
642
  }
575
643
  async addPart(id, part) {
576
- await this.db.insert(mediaUploadPartsPgTable).values({
644
+ await this.db.insert(this.t.uploadParts).values({
577
645
  sessionId: id,
578
646
  partNumber: part.partNumber,
579
647
  etag: part.etag
580
648
  }).onConflictDoUpdate({
581
649
  target: [
582
- mediaUploadPartsPgTable.sessionId,
583
- mediaUploadPartsPgTable.partNumber
650
+ this.t.uploadParts.sessionId,
651
+ this.t.uploadParts.partNumber
584
652
  ],
585
653
  set: {
586
- etag: sql2`excluded.etag`
654
+ etag: sql3`excluded.etag`
587
655
  }
588
656
  });
589
657
  }
590
658
  async listParts(id) {
591
659
  const rows = await this.db.select({
592
- partNumber: mediaUploadPartsPgTable.partNumber,
593
- etag: mediaUploadPartsPgTable.etag
594
- }).from(mediaUploadPartsPgTable).where(eq4(mediaUploadPartsPgTable.sessionId, id)).orderBy(asc3(mediaUploadPartsPgTable.partNumber));
660
+ partNumber: this.t.uploadParts.partNumber,
661
+ etag: this.t.uploadParts.etag
662
+ }).from(this.t.uploadParts).where(eq4(this.t.uploadParts.sessionId, id)).orderBy(asc3(this.t.uploadParts.partNumber));
595
663
  return rows.map((row) => ({
596
664
  partNumber: Number(row.partNumber),
597
665
  etag: row.etag
@@ -600,21 +668,29 @@ var DrizzlePgUploadSessionStore = class {
600
668
  async list(filter = {}) {
601
669
  const conditions = [
602
670
  ...filter.disk !== void 0 ? [
603
- eq4(mediaUploadSessionsPgTable.disk, filter.disk)
671
+ eq4(this.t.uploadSessions.disk, filter.disk)
604
672
  ] : [],
605
673
  ...filter.keyPrefix !== void 0 ? [
606
- like(mediaUploadSessionsPgTable.key, `${escapeLike(filter.keyPrefix)}%`)
674
+ like(this.t.uploadSessions.key, `${escapeLike(filter.keyPrefix)}%`)
607
675
  ] : [],
608
676
  ...filter.tenant ? [
609
- tenantCondition(mediaUploadSessionsPgTable.tenantId, filter.tenant)
677
+ tenantCondition(this.t.uploadSessions.tenantId, filter.tenant)
610
678
  ] : []
611
679
  ];
612
- const rows = await this.db.select(this.columns).from(mediaUploadSessionsPgTable).where(conditions.length ? and3(...conditions) : void 0).orderBy(asc3(mediaUploadSessionsPgTable.createdAt), asc3(mediaUploadSessionsPgTable.id));
680
+ const rows = await this.db.select(this.columns).from(this.t.uploadSessions).where(conditions.length ? and3(...conditions) : void 0).orderBy(asc3(this.t.uploadSessions.createdAt), asc3(this.t.uploadSessions.id));
613
681
  return rows.map(toSession);
614
682
  }
615
683
  };
616
684
 
617
685
  // src/nest/index.ts
686
+ function storeOptions(options) {
687
+ if (options.schema === void 0) return {};
688
+ mediaPgTables(options.schema);
689
+ return {
690
+ schema: options.schema
691
+ };
692
+ }
693
+ __name(storeOptions, "storeOptions");
618
694
  function factory(options, build) {
619
695
  return {
620
696
  inject: [
@@ -625,15 +701,18 @@ function factory(options, build) {
625
701
  }
626
702
  __name(factory, "factory");
627
703
  function drizzleMediaStore(options = {}) {
704
+ rejectSqliteSchema(options.schema);
628
705
  return factory(options, (db) => new DrizzleMediaStore(db));
629
706
  }
630
707
  __name(drizzleMediaStore, "drizzleMediaStore");
631
708
  function drizzlePgMediaStore(options = {}) {
632
- return factory(options, (db) => new DrizzlePgMediaStore(db));
709
+ const store = storeOptions(options);
710
+ return factory(options, (db) => new DrizzlePgMediaStore(db, store));
633
711
  }
634
712
  __name(drizzlePgMediaStore, "drizzlePgMediaStore");
635
713
  function drizzlePgUploadSessions(options = {}) {
636
- return factory(options, (db) => new DrizzlePgUploadSessionStore(db));
714
+ const store = storeOptions(options);
715
+ return factory(options, (db) => new DrizzlePgUploadSessionStore(db, store));
637
716
  }
638
717
  __name(drizzlePgUploadSessions, "drizzlePgUploadSessions");
639
718
  export {