@sqb/connect 4.24.1 → 4.26.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.
@@ -1,4 +1,4 @@
1
- import { And, Count, Select } from '@sqb/builder';
1
+ import { And, Count, Select, TableName } from '@sqb/builder';
2
2
  import { prepareFilter } from './command.helper.js';
3
3
  export class CountCommand {
4
4
  // istanbul ignore next
@@ -12,9 +12,17 @@ export class CountCommand {
12
12
  where = And();
13
13
  await prepareFilter(entity, filter, where, 'T');
14
14
  }
15
- const query = Select(Count()).from(entity.tableName + ' T');
16
- if (args.comment)
17
- query.comment(args.comment, args.commentDialect);
15
+ const query = Select(Count()).from(TableName({
16
+ table: entity.tableName,
17
+ alias: 'T',
18
+ optimizerHint: args.optimizerHint,
19
+ }));
20
+ if (args.comment) {
21
+ if (Array.isArray(args.comment))
22
+ args.comment.forEach(c => query.comment(c));
23
+ else
24
+ query.comment(args.comment);
25
+ }
18
26
  if (where)
19
27
  query.where(where);
20
28
  // Execute query
@@ -23,8 +23,12 @@ export class CreateCommand {
23
23
  if (!ctx.colCount)
24
24
  throw new Error('No field given to create new entity instance');
25
25
  const query = Insert(tableName, ctx.queryValues);
26
- if (args.comment)
27
- query.comment(args.comment, args.commentDialect);
26
+ if (args.comment) {
27
+ if (Array.isArray(args.comment))
28
+ args.comment.forEach(c => query.comment(c));
29
+ else
30
+ query.comment(args.comment);
31
+ }
28
32
  if (args.returning) {
29
33
  const primaryIndexColumns = EntityMetadata.getPrimaryIndexColumns(entity);
30
34
  if (primaryIndexColumns.length)
@@ -1,4 +1,4 @@
1
- import { And, Delete } from '@sqb/builder';
1
+ import { And, Delete, TableName } from '@sqb/builder';
2
2
  import { prepareFilter } from './command.helper.js';
3
3
  export class DeleteCommand {
4
4
  // istanbul ignore next
@@ -12,9 +12,17 @@ export class DeleteCommand {
12
12
  where = And();
13
13
  await prepareFilter(entity, filter, where);
14
14
  }
15
- const query = Delete(entity.tableName + ' T');
16
- if (args.comment)
17
- query.comment(args.comment, args.commentDialect);
15
+ const query = Delete(TableName({
16
+ table: entity.tableName,
17
+ alias: 'T',
18
+ optimizerHint: args.optimizerHint,
19
+ }));
20
+ if (args.comment) {
21
+ if (Array.isArray(args.comment))
22
+ args.comment.forEach(c => query.comment(c));
23
+ else
24
+ query.comment(args.comment);
25
+ }
18
26
  if (where)
19
27
  query.where(...where._items);
20
28
  // Execute query
@@ -38,6 +38,6 @@ export declare class FindCommand {
38
38
  private _selectColumn;
39
39
  filter(filter: any): Promise<void>;
40
40
  sort(sortFields: string[]): Promise<void>;
41
- execute(args: Pick<FindCommandArgs, 'connection' | 'distinct' | 'offset' | 'limit' | 'params' | 'onTransformRow' | 'prettyPrint' | 'comment' | 'commentDialect'>): Promise<any[]>;
41
+ execute(args: Pick<FindCommandArgs, 'connection' | 'distinct' | 'offset' | 'limit' | 'params' | 'onTransformRow' | 'prettyPrint' | 'comment' | 'optimizerHint'>): Promise<any[]>;
42
42
  private _getEntityFromAlias;
43
43
  }
@@ -1,4 +1,4 @@
1
- import { And, In, Param, Select } from '@sqb/builder';
1
+ import { And, In, Param, Select, TableName } from '@sqb/builder';
2
2
  import { AssociationNode } from '../model/association-node.js';
3
3
  import { EntityMetadata } from '../model/entity-metadata.js';
4
4
  import { isAssociationField, isColumnField, isEmbeddedField, resolveEntityForEmbeddedField, } from '../util/orm.helper.js';
@@ -241,9 +241,17 @@ export class FindCommand {
241
241
  const columnSqls = Object.keys(this._selectColumns).map(x => this._selectColumns[x].statement);
242
242
  if (!columnSqls.length)
243
243
  columnSqls.push('1');
244
- const query = Select(...columnSqls).from(this.mainEntity.tableName + ' as ' + this.mainAlias);
245
- if (args.comment)
246
- query.comment(args.comment, args.commentDialect);
244
+ const query = Select(...columnSqls).from(TableName({
245
+ table: this.mainEntity.tableName,
246
+ alias: this.mainAlias,
247
+ optimizerHint: args.optimizerHint,
248
+ }));
249
+ if (args.comment) {
250
+ if (Array.isArray(args.comment))
251
+ args.comment.forEach(c => query.comment(c));
252
+ else
253
+ query.comment(args.comment);
254
+ }
247
255
  if (args.distinct)
248
256
  query.distinct();
249
257
  query.where(...this._filter._items);
@@ -1,4 +1,4 @@
1
- import { And, Param, Update } from '@sqb/builder';
1
+ import { And, Param, TableName, Update } from '@sqb/builder';
2
2
  import { checkEnumValue, isColumnField, isEmbeddedField, resolveEntityForEmbeddedField, } from '../util/orm.helper.js';
3
3
  import { prepareFilter } from './command.helper.js';
4
4
  export class UpdateCommand {
@@ -25,9 +25,17 @@ export class UpdateCommand {
25
25
  return 0;
26
26
  if (args.filter)
27
27
  await this._prepareFilter(ctx, args.filter);
28
- const query = Update(tableName + ' as T', ctx.queryValues).where(...ctx.queryFilter);
29
- if (args.comment)
30
- query.comment(args.comment, args.commentDialect);
28
+ const query = Update(TableName({
29
+ table: tableName,
30
+ alias: 'T',
31
+ optimizerHint: args.optimizerHint,
32
+ }), ctx.queryValues).where(...ctx.queryFilter);
33
+ if (args.comment) {
34
+ if (Array.isArray(args.comment))
35
+ args.comment.forEach(c => query.comment(c));
36
+ else
37
+ query.comment(args.comment);
38
+ }
31
39
  const qr = await args.connection.execute(query, {
32
40
  params: args.params ? [...args.params, ctx.queryParams] : ctx.queryParams,
33
41
  objectRows: false,
@@ -1,4 +1,5 @@
1
1
  import { LogicalOperator } from '@sqb/builder';
2
+ import { OptimizerHintArgs } from '@sqb/builder/build/sql-objects/table-name';
2
3
  import { PartialDTO, PatchDTO, RequiredSome, StrictOmit, Type } from 'ts-gems';
3
4
  import { FieldInfoMap } from '../client/field-info-map.js';
4
5
  import type { SqbClient } from '../client/sqb-client.js';
@@ -17,8 +18,14 @@ export declare namespace Repository {
17
18
  interface CommandOptions {
18
19
  connection?: SqbConnection;
19
20
  prettyPrint?: boolean;
20
- comment?: string;
21
- commentDialect?: string[];
21
+ comment?: string | string[] | {
22
+ comment: string;
23
+ dialect?: string[];
24
+ } | {
25
+ comment: string;
26
+ dialect?: string[];
27
+ }[];
28
+ optimizerHint?: string | string[] | OptimizerHintArgs | OptimizerHintArgs[];
22
29
  }
23
30
  interface CreateOptions extends CommandOptions, Projection {
24
31
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sqb/connect",
3
3
  "description": "Multi-dialect database connection framework written with TypeScript",
4
- "version": "4.24.1",
4
+ "version": "4.26.0",
5
5
  "author": "Panates",
6
6
  "license": "Apache-2.0",
7
7
  "dependencies": {
@@ -21,7 +21,7 @@
21
21
  "tslib": "^2.8.1"
22
22
  },
23
23
  "peerDependencies": {
24
- "@sqb/builder": "^4.24.1",
24
+ "@sqb/builder": "^4.26.0",
25
25
  "reflect-metadata": "^0.2.2"
26
26
  },
27
27
  "type": "module",