@nocobase/database 2.0.0-alpha.20 → 2.0.0-alpha.22

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/lib/database.d.ts CHANGED
@@ -215,6 +215,7 @@ export declare class Database extends EventEmitter implements AsyncEmitter {
215
215
  private registerCollectionType;
216
216
  quoteIdentifier(identifier: string): string;
217
217
  quoteTable(tableName: string): string;
218
+ private runSQLWithSchema;
218
219
  runSQL(sql: string, options?: RunSQLOptions): Promise<any>;
219
220
  }
220
221
  export declare function extendCollection(collectionOptions: CollectionOptions, mergeOptions?: MergeOptions): {
package/lib/database.js CHANGED
@@ -431,11 +431,7 @@ const _Database = class _Database extends import_events.EventEmitter {
431
431
  */
432
432
  collection(options) {
433
433
  options = import_lodash.default.cloneDeep(options);
434
- if (typeof options.underscored !== "boolean") {
435
- if (this.options.underscored) {
436
- options.underscored = true;
437
- }
438
- }
434
+ options.underscored = options.underscored ?? this.options.underscored;
439
435
  this.logger.trace(`beforeDefineCollection: ${(0, import_safe_json_stringify.default)(options)}`, {
440
436
  databaseInstanceId: this.instanceId
441
437
  });
@@ -791,6 +787,16 @@ const _Database = class _Database extends import_events.EventEmitter {
791
787
  quoteTable(tableName) {
792
788
  return this.sequelize.getQueryInterface().quoteIdentifiers(tableName);
793
789
  }
790
+ async runSQLWithSchema(finalSQL, bind, transaction) {
791
+ if (!this.options.schema || !this.isPostgresCompatibleDialect()) {
792
+ return this.sequelize.query(finalSQL, { bind, transaction });
793
+ }
794
+ const execute = /* @__PURE__ */ __name(async (t) => {
795
+ await this.sequelize.query(`SET LOCAL search_path TO ${this.options.schema}`, { transaction: t });
796
+ return this.sequelize.query(finalSQL, { bind, transaction: t });
797
+ }, "execute");
798
+ return transaction ? execute(transaction) : this.sequelize.transaction(execute);
799
+ }
794
800
  async runSQL(sql, options = {}) {
795
801
  const { filter, bind, type, transaction } = options;
796
802
  let finalSQL = sql;
@@ -812,11 +818,8 @@ const _Database = class _Database extends import_events.EventEmitter {
812
818
  finalSQL = `SELECT * FROM (${normalizedSQL}) AS tmp WHERE ${wSQL}`;
813
819
  }
814
820
  }
815
- if (this.options.schema && this.isPostgresCompatibleDialect()) {
816
- finalSQL = `${queryGenerator.setSearchPath(this.options.schema)} ${finalSQL}`;
817
- }
818
821
  this.logger.debug("runSQL", { finalSQL });
819
- const result = await this.sequelize.query(finalSQL, { bind, transaction });
822
+ const result = await this.runSQLWithSchema(finalSQL, bind, transaction);
820
823
  let data = result[0];
821
824
  if (type === "selectVar") {
822
825
  if (Array.isArray(data)) {
@@ -215,7 +215,8 @@ const _EagerLoadingTree = class _EagerLoadingTree {
215
215
  attributes: [primaryKeyField],
216
216
  group: `${node.model.name}.${primaryKeyField}`,
217
217
  transaction,
218
- include: (0, import_utils.processIncludes)(includeForFilter, node.model)
218
+ include: (0, import_utils.processIncludes)(includeForFilter, node.model),
219
+ raw: true
219
220
  })).map((row) => {
220
221
  return { row, pk: row[primaryKeyField] };
221
222
  });
package/lib/index.d.ts CHANGED
@@ -36,11 +36,12 @@ export * from './repository';
36
36
  export * from './relation-repository/relation-repository';
37
37
  export { default as sqlParser, SQLParserTypes } from './sql-parser';
38
38
  export * from './update-associations';
39
- export { snakeCase } from './utils';
39
+ export { snakeCase, extractTypeFromDefinition } from './utils';
40
40
  export * from './value-parsers';
41
41
  export * from './view-collection';
42
42
  export { default as fieldTypeMap } from './view/field-type-map';
43
43
  export * from './view/view-inference';
44
44
  export * from './update-guard';
45
+ export { TableInfo } from './query-interface/query-interface';
45
46
  export { default as operators } from './operators';
46
47
  export { filterIncludes, mergeIncludes } from './utils/filter-include';
package/lib/index.js CHANGED
@@ -49,11 +49,13 @@ __export(src_exports, {
49
49
  Op: () => import_sequelize.Op,
50
50
  SQLParserTypes: () => import_sql_parser.SQLParserTypes,
51
51
  SyncOptions: () => import_sequelize.SyncOptions,
52
+ TableInfo: () => import_query_interface.TableInfo,
52
53
  Transaction: () => import_sequelize.Transaction,
53
54
  UniqueConstraintError: () => import_sequelize.UniqueConstraintError,
54
55
  ValidationError: () => import_sequelize.ValidationError,
55
56
  ValidationErrorItem: () => import_sequelize.ValidationErrorItem,
56
57
  default: () => import_database.Database,
58
+ extractTypeFromDefinition: () => import_utils.extractTypeFromDefinition,
57
59
  fieldTypeMap: () => import_field_type_map.default,
58
60
  filterIncludes: () => import_filter_include.filterIncludes,
59
61
  fn: () => import_sequelize.fn,
@@ -101,6 +103,7 @@ __reExport(src_exports, require("./view-collection"), module.exports);
101
103
  var import_field_type_map = __toESM(require("./view/field-type-map"));
102
104
  __reExport(src_exports, require("./view/view-inference"), module.exports);
103
105
  __reExport(src_exports, require("./update-guard"), module.exports);
106
+ var import_query_interface = require("./query-interface/query-interface");
104
107
  var import_operators = __toESM(require("./operators"));
105
108
  var import_filter_include = require("./utils/filter-include");
106
109
  // Annotate the CommonJS export names for ESM import in node:
@@ -117,10 +120,12 @@ var import_filter_include = require("./utils/filter-include");
117
120
  Op,
118
121
  SQLParserTypes,
119
122
  SyncOptions,
123
+ TableInfo,
120
124
  Transaction,
121
125
  UniqueConstraintError,
122
126
  ValidationError,
123
127
  ValidationErrorItem,
128
+ extractTypeFromDefinition,
124
129
  fieldTypeMap,
125
130
  filterIncludes,
126
131
  fn,
package/lib/utils.d.ts CHANGED
@@ -16,4 +16,5 @@ export declare function percent2float(value: string): number;
16
16
  export declare function isUndefinedOrNull(value: any): boolean;
17
17
  export declare function isStringOrNumber(value: any): boolean;
18
18
  export declare function getKeysByPrefix(keys: string[], prefix: string): string[];
19
+ export declare function extractTypeFromDefinition(rawType: string): string;
19
20
  export declare function processIncludes(includes: any[], model: any, parentAs?: string): any[];
package/lib/utils.js CHANGED
@@ -38,6 +38,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
38
38
  var utils_exports = {};
39
39
  __export(utils_exports, {
40
40
  checkIdentifier: () => checkIdentifier,
41
+ extractTypeFromDefinition: () => extractTypeFromDefinition,
41
42
  getKeysByPrefix: () => getKeysByPrefix,
42
43
  getTableName: () => getTableName,
43
44
  isStringOrNumber: () => isStringOrNumber,
@@ -141,6 +142,14 @@ function getKeysByPrefix(keys, prefix) {
141
142
  return keys.filter((key) => key.startsWith(`${prefix}.`)).map((key) => key.substring(prefix.length + 1));
142
143
  }
143
144
  __name(getKeysByPrefix, "getKeysByPrefix");
145
+ function extractTypeFromDefinition(rawType) {
146
+ const leftParenIndex = rawType.indexOf("(");
147
+ if (leftParenIndex === -1) {
148
+ return rawType.toLowerCase();
149
+ }
150
+ return rawType.substring(0, leftParenIndex).toLowerCase().trim();
151
+ }
152
+ __name(extractTypeFromDefinition, "extractTypeFromDefinition");
144
153
  function processIncludes(includes, model, parentAs = "") {
145
154
  includes.forEach((include, index) => {
146
155
  const association = model.associations[include.association];
@@ -164,6 +173,7 @@ __name(processIncludes, "processIncludes");
164
173
  // Annotate the CommonJS export names for ESM import in node:
165
174
  0 && (module.exports = {
166
175
  checkIdentifier,
176
+ extractTypeFromDefinition,
167
177
  getKeysByPrefix,
168
178
  getTableName,
169
179
  isStringOrNumber,
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/database",
3
- "version": "2.0.0-alpha.20",
3
+ "version": "2.0.0-alpha.22",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "license": "AGPL-3.0",
8
8
  "dependencies": {
9
- "@nocobase/logger": "2.0.0-alpha.20",
10
- "@nocobase/utils": "2.0.0-alpha.20",
9
+ "@nocobase/logger": "2.0.0-alpha.22",
10
+ "@nocobase/utils": "2.0.0-alpha.22",
11
11
  "async-mutex": "^0.3.2",
12
12
  "chalk": "^4.1.1",
13
13
  "cron-parser": "4.4.0",
@@ -39,5 +39,5 @@
39
39
  "url": "git+https://github.com/nocobase/nocobase.git",
40
40
  "directory": "packages/database"
41
41
  },
42
- "gitHead": "af5ff4eaa490349420135405128da466d72ac74c"
42
+ "gitHead": "717bcfaa0bdeaa8026717b4309a65abdc19478f1"
43
43
  }