@nocobase/database 1.0.0-alpha.13 → 1.0.0-alpha.15

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/collection.js CHANGED
@@ -240,7 +240,7 @@ const _Collection = class _Collection extends import_events.EventEmitter {
240
240
  (0, import_utils.checkIdentifier)(name);
241
241
  this.checkFieldType(name, options);
242
242
  const { database } = this.context;
243
- database.logger.debug(`beforeSetField: ${(0, import_safe_json_stringify.default)(options)}`, {
243
+ database.logger.trace(`beforeSetField: ${(0, import_safe_json_stringify.default)(options)}`, {
244
244
  databaseInstanceId: database.instanceId,
245
245
  collectionName: this.name,
246
246
  fieldName: name
package/lib/database.js CHANGED
@@ -73,7 +73,6 @@ var import_migration = require("./migration");
73
73
  var import_model_hook = require("./model-hook");
74
74
  var import_operators = __toESM(require("./operators"));
75
75
  var import_query_interface_builder = __toESM(require("./query-interface/query-interface-builder"));
76
- var import_sql_collection = require("./sql-collection/sql-collection");
77
76
  var import_utils2 = require("./utils");
78
77
  var import_value_parsers = require("./value-parsers");
79
78
  var import_view_collection = require("./view-collection");
@@ -415,7 +414,7 @@ const _Database = class _Database extends import_events.EventEmitter {
415
414
  if (this.options.underscored) {
416
415
  options.underscored = true;
417
416
  }
418
- this.logger.debug(`beforeDefineCollection: ${(0, import_safe_json_stringify.default)(options)}`, {
417
+ this.logger.trace(`beforeDefineCollection: ${(0, import_safe_json_stringify.default)(options)}`, {
419
418
  databaseInstanceId: this.instanceId
420
419
  });
421
420
  this.emit("beforeDefineCollection", options);
@@ -759,17 +758,6 @@ const _Database = class _Database extends import_events.EventEmitter {
759
758
  return;
760
759
  }
761
760
  });
762
- this.collectionFactory.registerCollectionType(import_sql_collection.SqlCollection, {
763
- condition: (options) => {
764
- return options.sql;
765
- },
766
- async onSync() {
767
- return;
768
- },
769
- async onDump(dumper, collection) {
770
- return;
771
- }
772
- });
773
761
  }
774
762
  };
775
763
  __name(_Database, "Database");
package/lib/index.d.ts CHANGED
@@ -32,5 +32,5 @@ export { snakeCase } from './utils';
32
32
  export * from './value-parsers';
33
33
  export * from './view-collection';
34
34
  export * from './view/view-inference';
35
- export * from './sql-collection';
36
35
  export * from './helpers';
36
+ export { default as sqlParser, SQLParserTypes } from './sql-parser';
package/lib/index.js CHANGED
@@ -46,6 +46,7 @@ __export(src_exports, {
46
46
  HasManyGetAssociationsMixin: () => import_sequelize.HasManyGetAssociationsMixin,
47
47
  ModelStatic: () => import_sequelize.ModelStatic,
48
48
  Op: () => import_sequelize.Op,
49
+ SQLParserTypes: () => import_sql_parser.SQLParserTypes,
49
50
  SyncOptions: () => import_sequelize.SyncOptions,
50
51
  Transaction: () => import_sequelize.Transaction,
51
52
  UniqueConstraintError: () => import_sequelize.UniqueConstraintError,
@@ -55,6 +56,7 @@ __export(src_exports, {
55
56
  fn: () => import_sequelize.fn,
56
57
  literal: () => import_sequelize.literal,
57
58
  snakeCase: () => import_utils.snakeCase,
59
+ sqlParser: () => import_sql_parser.default,
58
60
  where: () => import_sequelize.where
59
61
  });
60
62
  module.exports = __toCommonJS(src_exports);
@@ -84,8 +86,8 @@ var import_utils = require("./utils");
84
86
  __reExport(src_exports, require("./value-parsers"), module.exports);
85
87
  __reExport(src_exports, require("./view-collection"), module.exports);
86
88
  __reExport(src_exports, require("./view/view-inference"), module.exports);
87
- __reExport(src_exports, require("./sql-collection"), module.exports);
88
89
  __reExport(src_exports, require("./helpers"), module.exports);
90
+ var import_sql_parser = __toESM(require("./sql-parser"));
89
91
  // Annotate the CommonJS export names for ESM import in node:
90
92
  0 && (module.exports = {
91
93
  BaseError,
@@ -97,6 +99,7 @@ __reExport(src_exports, require("./helpers"), module.exports);
97
99
  HasManyGetAssociationsMixin,
98
100
  ModelStatic,
99
101
  Op,
102
+ SQLParserTypes,
100
103
  SyncOptions,
101
104
  Transaction,
102
105
  UniqueConstraintError,
@@ -105,6 +108,7 @@ __reExport(src_exports, require("./helpers"), module.exports);
105
108
  fn,
106
109
  literal,
107
110
  snakeCase,
111
+ sqlParser,
108
112
  where,
109
113
  ...require("./collection"),
110
114
  ...require("./collection-group-manager"),
@@ -128,6 +132,5 @@ __reExport(src_exports, require("./helpers"), module.exports);
128
132
  ...require("./value-parsers"),
129
133
  ...require("./view-collection"),
130
134
  ...require("./view/view-inference"),
131
- ...require("./sql-collection"),
132
135
  ...require("./helpers")
133
136
  });
@@ -61,13 +61,15 @@ const getFieldName = /* @__PURE__ */ __name((ctx) => {
61
61
  return model2;
62
62
  }, "getModelFromAssociationPath");
63
63
  const model = getModelFromAssociationPath();
64
+ let columnPrefix = model.name;
64
65
  if (model.rawAttributes[fieldName]) {
65
66
  columnName = model.rawAttributes[fieldName].field || fieldName;
66
67
  }
67
68
  if (associationPath.length > 0) {
68
69
  const association = associationPath.join("->");
69
- columnName = `${association}.${columnName}`;
70
+ columnPrefix = association;
70
71
  }
72
+ columnName = `${columnPrefix}.${columnName}`;
71
73
  return columnName;
72
74
  }, "getFieldName");
73
75
  const escape = /* @__PURE__ */ __name((value, ctx) => {
@@ -41,7 +41,7 @@ __export(postgres_query_interface_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(postgres_query_interface_exports);
43
43
  var import_lodash = __toESM(require("lodash"));
44
- var import_postgres = __toESM(require("../sql-parser/postgres"));
44
+ var import_sql_parser = __toESM(require("../sql-parser"));
45
45
  var import_query_interface = __toESM(require("./query-interface"));
46
46
  const _PostgresQueryInterface = class _PostgresQueryInterface extends import_query_interface.default {
47
47
  constructor(db) {
@@ -123,7 +123,9 @@ const _PostgresQueryInterface = class _PostgresQueryInterface extends import_que
123
123
  return import_lodash.default.trim(viewDefQuery[0]["definition"]);
124
124
  }
125
125
  parseSQL(sql) {
126
- return import_postgres.default.parse(sql);
126
+ return import_sql_parser.default.parse(sql, {
127
+ database: "Postgresql"
128
+ });
127
129
  }
128
130
  async viewColumnUsage(options) {
129
131
  const { viewName, schema = "public" } = options;
package/lib/repository.js CHANGED
@@ -119,35 +119,37 @@ const _Repository = class _Repository {
119
119
  this.collection = collection;
120
120
  this.model = collection.model;
121
121
  }
122
- static valuesToFilter(values, filterKeys) {
123
- const filterAnd = [];
124
- const flattedValues = (0, import_flat.flatten)(values);
125
- const keyWithOutArrayIndex = /* @__PURE__ */ __name((key) => {
122
+ static valuesToFilter(values = {}, filterKeys) {
123
+ const removeArrayIndexInKey = /* @__PURE__ */ __name((key) => {
126
124
  const chunks = key.split(".");
127
125
  return chunks.filter((chunk) => {
128
126
  return !chunk.match(/\d+/);
129
127
  }).join(".");
130
- }, "keyWithOutArrayIndex");
131
- for (const filterKey of filterKeys) {
132
- let filterValue;
133
- for (const flattedKey of Object.keys(flattedValues)) {
134
- const flattedKeyWithoutIndex = keyWithOutArrayIndex(flattedKey);
135
- if (flattedKeyWithoutIndex === filterKey) {
136
- if (filterValue) {
137
- if (Array.isArray(filterValue)) {
138
- filterValue.push(flattedValues[flattedKey]);
139
- } else {
140
- filterValue = [filterValue, flattedValues[flattedKey]];
141
- }
142
- } else {
143
- filterValue = flattedValues[flattedKey];
144
- }
128
+ }, "removeArrayIndexInKey");
129
+ const filterAnd = [];
130
+ const flattedValues = (0, import_flat.flatten)(values);
131
+ const flattedValuesObject = {};
132
+ for (const key in flattedValues) {
133
+ const keyWithoutArrayIndex = removeArrayIndexInKey(key);
134
+ if (flattedValuesObject[keyWithoutArrayIndex]) {
135
+ if (!Array.isArray(flattedValuesObject[keyWithoutArrayIndex])) {
136
+ flattedValuesObject[keyWithoutArrayIndex] = [flattedValuesObject[keyWithoutArrayIndex]];
145
137
  }
138
+ flattedValuesObject[keyWithoutArrayIndex].push(flattedValues[key]);
139
+ } else {
140
+ flattedValuesObject[keyWithoutArrayIndex] = [flattedValues[key]];
146
141
  }
142
+ }
143
+ for (const filterKey of filterKeys) {
144
+ const filterValue = flattedValuesObject[filterKey] ? flattedValuesObject[filterKey] : import_lodash.default.get(values, filterKey);
147
145
  if (filterValue) {
148
146
  filterAnd.push({
149
147
  [filterKey]: filterValue
150
148
  });
149
+ } else {
150
+ filterAnd.push({
151
+ [filterKey]: null
152
+ });
151
153
  }
152
154
  }
153
155
  return {
@@ -6,5 +6,8 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- export * from './sql-model';
10
- export * from './sql-collection';
9
+ import { Parser } from 'node-sql-parser';
10
+ import type * as SQLParserTypes from 'node-sql-parser';
11
+ declare const _default: Parser;
12
+ export default _default;
13
+ export type { SQLParserTypes };