bigal 13.1.1 → 13.2.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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # [13.2.0](https://github.com/bigalorm/bigal/compare/v13.1.1...v13.2.0) (2025-05-08)
2
+
3
+ ### Features
4
+
5
+ - add support for schemas ([#111](https://github.com/bigalorm/bigal/issues/111)) ([96af423](https://github.com/bigalorm/bigal/commit/96af423c5933fbc1e5b1860b7b1bac327a4b0357))
6
+
1
7
  ## [13.1.1](https://github.com/bigalorm/bigal/compare/v13.1.0...v13.1.1) (2025-05-05)
2
8
 
3
9
  # [13.1.0](https://github.com/bigalorm/bigal/compare/v13.0.11...v13.1.0) (2025-05-01)
package/dist/index.cjs CHANGED
@@ -296,9 +296,13 @@ class ModelMetadata {
296
296
  get versionColumns() {
297
297
  return this._versionDateColumns;
298
298
  }
299
+ get qualifiedTableName() {
300
+ return `${this.schema ? `"${this.schema}".` : ""}"${this.tableName}"`;
301
+ }
299
302
  name;
300
303
  type;
301
304
  connection;
305
+ schema;
302
306
  tableName;
303
307
  readonly;
304
308
  columnsByColumnName = {};
@@ -308,12 +312,14 @@ class ModelMetadata {
308
312
  //
309
313
  type,
310
314
  connection,
315
+ schema,
311
316
  tableName,
312
317
  readonly = false
313
318
  }) {
314
319
  this.name = name;
315
320
  this.type = type;
316
321
  this.connection = connection;
322
+ this.schema = schema;
317
323
  this.tableName = tableName ?? ___default.snakeCase(name);
318
324
  this.readonly = readonly;
319
325
  }
@@ -352,7 +358,7 @@ function getSelectQueryAndParams({
352
358
  model,
353
359
  select
354
360
  });
355
- query += ` FROM "${model.tableName}"`;
361
+ query += ` FROM ${model.qualifiedTableName}`;
356
362
  const { whereStatement, params } = buildWhereStatement({
357
363
  repositoriesByModelNameLowered,
358
364
  model,
@@ -399,7 +405,7 @@ function getCountQueryAndParams({
399
405
  model,
400
406
  where
401
407
  }) {
402
- let query = `SELECT count(*) AS "count" FROM "${model.tableName}"`;
408
+ let query = `SELECT count(*) AS "count" FROM ${model.qualifiedTableName}`;
403
409
  const { whereStatement, params } = buildWhereStatement({
404
410
  repositoriesByModelNameLowered,
405
411
  model,
@@ -489,7 +495,7 @@ function getInsertQueryAndParams({
489
495
  }
490
496
  const valueCollections = entitiesToInsert.map(() => []);
491
497
  const params = [];
492
- let query = `INSERT INTO "${model.tableName}" (`;
498
+ let query = `INSERT INTO ${model.qualifiedTableName} (`;
493
499
  for (const [columnIndex, column] of columnsToInsert.entries()) {
494
500
  if (columnIndex > 0) {
495
501
  query += ",";
@@ -614,7 +620,7 @@ function getUpdateQueryAndParams({
614
620
  }
615
621
  }
616
622
  const params = [];
617
- let query = `UPDATE "${model.tableName}" SET `;
623
+ let query = `UPDATE ${model.qualifiedTableName} SET `;
618
624
  let isFirstProperty = true;
619
625
  for (const [propertyName, value] of Object.entries(values)) {
620
626
  const column = model.columnsByPropertyName[propertyName];
@@ -701,7 +707,7 @@ function getDeleteQueryAndParams({
701
707
  returnRecords = true,
702
708
  returnSelect
703
709
  }) {
704
- let query = `DELETE FROM "${model.tableName}"`;
710
+ let query = `DELETE FROM ${model.qualifiedTableName}`;
705
711
  const { whereStatement, params } = buildWhereStatement({
706
712
  repositoriesByModelNameLowered,
707
713
  model,
@@ -2297,6 +2303,7 @@ function table(dbNameOrTableOptions, options) {
2297
2303
  const metadataStorage = getMetadataStorage();
2298
2304
  const modelMetadata = new ModelMetadata({
2299
2305
  name: className,
2306
+ schema: options.schema,
2300
2307
  type: classObject,
2301
2308
  tableName: options.name,
2302
2309
  readonly: options.readonly ?? false,
package/dist/index.d.cts CHANGED
@@ -354,6 +354,7 @@ interface ModelMetadataOptions<T extends Entity> {
354
354
  name: string;
355
355
  type: EntityStatic<T>;
356
356
  connection?: string;
357
+ schema?: string;
357
358
  tableName?: string;
358
359
  readonly?: boolean;
359
360
  }
@@ -369,15 +370,17 @@ declare class ModelMetadata<T extends Entity> {
369
370
  get createDateColumns(): readonly Column[];
370
371
  get updateDateColumns(): readonly Column[];
371
372
  get versionColumns(): readonly Column[];
373
+ get qualifiedTableName(): string;
372
374
  name: string;
373
375
  type: EntityStatic<T>;
374
376
  connection?: string;
377
+ schema?: string;
375
378
  tableName: string;
376
379
  readonly: boolean;
377
380
  columnsByColumnName: ColumnByStringId;
378
381
  columnsByPropertyName: ColumnByStringId;
379
382
  constructor({ name, //
380
- type, connection, tableName, readonly, }: ModelMetadataOptions<T>);
383
+ type, connection, schema, tableName, readonly, }: ModelMetadataOptions<T>);
381
384
  }
382
385
 
383
386
  /**
@@ -849,6 +852,10 @@ interface TableOptions {
849
852
  * Table name in the database
850
853
  */
851
854
  name?: string;
855
+ /**
856
+ * Schema table belongs to in the database
857
+ */
858
+ schema?: string;
852
859
  /**
853
860
  * Connection name to use for queries
854
861
  */
package/dist/index.d.mts CHANGED
@@ -354,6 +354,7 @@ interface ModelMetadataOptions<T extends Entity> {
354
354
  name: string;
355
355
  type: EntityStatic<T>;
356
356
  connection?: string;
357
+ schema?: string;
357
358
  tableName?: string;
358
359
  readonly?: boolean;
359
360
  }
@@ -369,15 +370,17 @@ declare class ModelMetadata<T extends Entity> {
369
370
  get createDateColumns(): readonly Column[];
370
371
  get updateDateColumns(): readonly Column[];
371
372
  get versionColumns(): readonly Column[];
373
+ get qualifiedTableName(): string;
372
374
  name: string;
373
375
  type: EntityStatic<T>;
374
376
  connection?: string;
377
+ schema?: string;
375
378
  tableName: string;
376
379
  readonly: boolean;
377
380
  columnsByColumnName: ColumnByStringId;
378
381
  columnsByPropertyName: ColumnByStringId;
379
382
  constructor({ name, //
380
- type, connection, tableName, readonly, }: ModelMetadataOptions<T>);
383
+ type, connection, schema, tableName, readonly, }: ModelMetadataOptions<T>);
381
384
  }
382
385
 
383
386
  /**
@@ -849,6 +852,10 @@ interface TableOptions {
849
852
  * Table name in the database
850
853
  */
851
854
  name?: string;
855
+ /**
856
+ * Schema table belongs to in the database
857
+ */
858
+ schema?: string;
852
859
  /**
853
860
  * Connection name to use for queries
854
861
  */
package/dist/index.d.ts CHANGED
@@ -354,6 +354,7 @@ interface ModelMetadataOptions<T extends Entity> {
354
354
  name: string;
355
355
  type: EntityStatic<T>;
356
356
  connection?: string;
357
+ schema?: string;
357
358
  tableName?: string;
358
359
  readonly?: boolean;
359
360
  }
@@ -369,15 +370,17 @@ declare class ModelMetadata<T extends Entity> {
369
370
  get createDateColumns(): readonly Column[];
370
371
  get updateDateColumns(): readonly Column[];
371
372
  get versionColumns(): readonly Column[];
373
+ get qualifiedTableName(): string;
372
374
  name: string;
373
375
  type: EntityStatic<T>;
374
376
  connection?: string;
377
+ schema?: string;
375
378
  tableName: string;
376
379
  readonly: boolean;
377
380
  columnsByColumnName: ColumnByStringId;
378
381
  columnsByPropertyName: ColumnByStringId;
379
382
  constructor({ name, //
380
- type, connection, tableName, readonly, }: ModelMetadataOptions<T>);
383
+ type, connection, schema, tableName, readonly, }: ModelMetadataOptions<T>);
381
384
  }
382
385
 
383
386
  /**
@@ -849,6 +852,10 @@ interface TableOptions {
849
852
  * Table name in the database
850
853
  */
851
854
  name?: string;
855
+ /**
856
+ * Schema table belongs to in the database
857
+ */
858
+ schema?: string;
852
859
  /**
853
860
  * Connection name to use for queries
854
861
  */
package/dist/index.mjs CHANGED
@@ -290,9 +290,13 @@ class ModelMetadata {
290
290
  get versionColumns() {
291
291
  return this._versionDateColumns;
292
292
  }
293
+ get qualifiedTableName() {
294
+ return `${this.schema ? `"${this.schema}".` : ""}"${this.tableName}"`;
295
+ }
293
296
  name;
294
297
  type;
295
298
  connection;
299
+ schema;
296
300
  tableName;
297
301
  readonly;
298
302
  columnsByColumnName = {};
@@ -302,12 +306,14 @@ class ModelMetadata {
302
306
  //
303
307
  type,
304
308
  connection,
309
+ schema,
305
310
  tableName,
306
311
  readonly = false
307
312
  }) {
308
313
  this.name = name;
309
314
  this.type = type;
310
315
  this.connection = connection;
316
+ this.schema = schema;
311
317
  this.tableName = tableName ?? _.snakeCase(name);
312
318
  this.readonly = readonly;
313
319
  }
@@ -346,7 +352,7 @@ function getSelectQueryAndParams({
346
352
  model,
347
353
  select
348
354
  });
349
- query += ` FROM "${model.tableName}"`;
355
+ query += ` FROM ${model.qualifiedTableName}`;
350
356
  const { whereStatement, params } = buildWhereStatement({
351
357
  repositoriesByModelNameLowered,
352
358
  model,
@@ -393,7 +399,7 @@ function getCountQueryAndParams({
393
399
  model,
394
400
  where
395
401
  }) {
396
- let query = `SELECT count(*) AS "count" FROM "${model.tableName}"`;
402
+ let query = `SELECT count(*) AS "count" FROM ${model.qualifiedTableName}`;
397
403
  const { whereStatement, params } = buildWhereStatement({
398
404
  repositoriesByModelNameLowered,
399
405
  model,
@@ -483,7 +489,7 @@ function getInsertQueryAndParams({
483
489
  }
484
490
  const valueCollections = entitiesToInsert.map(() => []);
485
491
  const params = [];
486
- let query = `INSERT INTO "${model.tableName}" (`;
492
+ let query = `INSERT INTO ${model.qualifiedTableName} (`;
487
493
  for (const [columnIndex, column] of columnsToInsert.entries()) {
488
494
  if (columnIndex > 0) {
489
495
  query += ",";
@@ -608,7 +614,7 @@ function getUpdateQueryAndParams({
608
614
  }
609
615
  }
610
616
  const params = [];
611
- let query = `UPDATE "${model.tableName}" SET `;
617
+ let query = `UPDATE ${model.qualifiedTableName} SET `;
612
618
  let isFirstProperty = true;
613
619
  for (const [propertyName, value] of Object.entries(values)) {
614
620
  const column = model.columnsByPropertyName[propertyName];
@@ -695,7 +701,7 @@ function getDeleteQueryAndParams({
695
701
  returnRecords = true,
696
702
  returnSelect
697
703
  }) {
698
- let query = `DELETE FROM "${model.tableName}"`;
704
+ let query = `DELETE FROM ${model.qualifiedTableName}`;
699
705
  const { whereStatement, params } = buildWhereStatement({
700
706
  repositoriesByModelNameLowered,
701
707
  model,
@@ -2291,6 +2297,7 @@ function table(dbNameOrTableOptions, options) {
2291
2297
  const metadataStorage = getMetadataStorage();
2292
2298
  const modelMetadata = new ModelMetadata({
2293
2299
  name: className,
2300
+ schema: options.schema,
2294
2301
  type: classObject,
2295
2302
  tableName: options.name,
2296
2303
  readonly: options.readonly ?? false,
package/eslint.config.mjs CHANGED
@@ -3,6 +3,9 @@ import { config } from 'eslint-config-decent';
3
3
  export default [
4
4
  ...config({
5
5
  tsconfigRootDir: import.meta.dirname,
6
+ enableJest: false,
7
+ enableVitest: false,
8
+ enableTestingLibrary: false,
6
9
  }),
7
10
  {
8
11
  files: ['**/*.ts'],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bigal",
3
- "version": "13.1.1",
3
+ "version": "13.2.0",
4
4
  "description": "A fast and lightweight orm for postgres and node.js, written in typescript.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",