@nocobase/database 1.6.0-alpha.19 → 1.6.0-alpha.20

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.
@@ -36,6 +36,46 @@ function escapeLike(value) {
36
36
  return value.replace(/[_%]/g, "\\$&");
37
37
  }
38
38
  __name(escapeLike, "escapeLike");
39
+ const getFieldName = /* @__PURE__ */ __name((ctx) => {
40
+ const fullNameSplit = ctx.fullName.split(".");
41
+ const fieldName = ctx.fieldName;
42
+ let columnName = fieldName;
43
+ const associationPath = [];
44
+ if (fullNameSplit.length > 1) {
45
+ for (let i = 0; i < fullNameSplit.length - 1; i++) {
46
+ associationPath.push(fullNameSplit[i]);
47
+ }
48
+ }
49
+ const getModelFromAssociationPath = /* @__PURE__ */ __name(() => {
50
+ let model2 = ctx.model;
51
+ for (const association of associationPath) {
52
+ model2 = model2.associations[association].target;
53
+ }
54
+ return model2;
55
+ }, "getModelFromAssociationPath");
56
+ const model = getModelFromAssociationPath();
57
+ let columnPrefix = model.name;
58
+ if (model.rawAttributes[fieldName]) {
59
+ columnName = model.rawAttributes[fieldName].field || fieldName;
60
+ }
61
+ if (associationPath.length > 0) {
62
+ const association = associationPath.join("->");
63
+ columnPrefix = association;
64
+ }
65
+ columnName = `${columnPrefix}.${columnName}`;
66
+ return columnName;
67
+ }, "getFieldName");
68
+ function getFieldExpression(value, ctx, operator) {
69
+ if ((0, import_utils.isPg)(ctx)) {
70
+ const fieldName = getFieldName(ctx);
71
+ const queryInterface = ctx.db.sequelize.getQueryInterface();
72
+ const quotedField = queryInterface.quoteIdentifiers(fieldName);
73
+ return import_sequelize.Sequelize.literal(`CAST(${quotedField} AS TEXT) ${operator} ${ctx.db.sequelize.escape(value)}`);
74
+ }
75
+ const op = operator === "LIKE" ? import_sequelize.Op.like : operator === "NOT LIKE" ? import_sequelize.Op.notLike : operator === "ILIKE" ? import_sequelize.Op.like : operator === "NOT ILIKE" ? import_sequelize.Op.notLike : import_sequelize.Op.like;
76
+ return { [op]: value };
77
+ }
78
+ __name(getFieldExpression, "getFieldExpression");
39
79
  var string_default = {
40
80
  $includes(value, ctx) {
41
81
  if (value === null) {
@@ -44,16 +84,14 @@ var string_default = {
44
84
  };
45
85
  }
46
86
  if (Array.isArray(value)) {
47
- const conditions = value.map((item) => ({
48
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.iLike : import_sequelize.Op.like]: `%${escapeLike(item)}%`
49
- }));
87
+ const conditions = value.map(
88
+ (item) => getFieldExpression(`%${escapeLike(item)}%`, ctx, (0, import_utils.isPg)(ctx) ? "ILIKE" : "LIKE")
89
+ );
50
90
  return {
51
91
  [import_sequelize.Op.or]: conditions
52
92
  };
53
93
  }
54
- return {
55
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.iLike : import_sequelize.Op.like]: `%${escapeLike(value)}%`
56
- };
94
+ return getFieldExpression(`%${escapeLike(value)}%`, ctx, (0, import_utils.isPg)(ctx) ? "ILIKE" : "LIKE");
57
95
  },
58
96
  $notIncludes(value, ctx) {
59
97
  if (value === null) {
@@ -62,67 +100,57 @@ var string_default = {
62
100
  };
63
101
  }
64
102
  if (Array.isArray(value)) {
65
- const conditions = value.map((item) => ({
66
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.notILike : import_sequelize.Op.notLike]: `%${escapeLike(item)}%`
67
- }));
103
+ const conditions = value.map(
104
+ (item) => getFieldExpression(`%${escapeLike(item)}%`, ctx, (0, import_utils.isPg)(ctx) ? "NOT ILIKE" : "NOT LIKE")
105
+ );
68
106
  return {
69
107
  [import_sequelize.Op.and]: conditions
70
108
  };
71
109
  }
72
- return {
73
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.notILike : import_sequelize.Op.notLike]: `%${escapeLike(value)}%`
74
- };
110
+ return getFieldExpression(`%${escapeLike(value)}%`, ctx, (0, import_utils.isPg)(ctx) ? "NOT ILIKE" : "NOT LIKE");
75
111
  },
76
112
  $startsWith(value, ctx) {
77
113
  if (Array.isArray(value)) {
78
- const conditions = value.map((item) => ({
79
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.iLike : import_sequelize.Op.like]: `${escapeLike(item)}%`
80
- }));
114
+ const conditions = value.map(
115
+ (item) => getFieldExpression(`${escapeLike(item)}%`, ctx, (0, import_utils.isPg)(ctx) ? "ILIKE" : "LIKE")
116
+ );
81
117
  return {
82
118
  [import_sequelize.Op.or]: conditions
83
119
  };
84
120
  }
85
- return {
86
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.iLike : import_sequelize.Op.like]: `${escapeLike(value)}%`
87
- };
121
+ return getFieldExpression(`${escapeLike(value)}%`, ctx, (0, import_utils.isPg)(ctx) ? "ILIKE" : "LIKE");
88
122
  },
89
123
  $notStartsWith(value, ctx) {
90
124
  if (Array.isArray(value)) {
91
- const conditions = value.map((item) => ({
92
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.notILike : import_sequelize.Op.notLike]: `${escapeLike(item)}%`
93
- }));
125
+ const conditions = value.map(
126
+ (item) => getFieldExpression(`${escapeLike(item)}%`, ctx, (0, import_utils.isPg)(ctx) ? "NOT ILIKE" : "NOT LIKE")
127
+ );
94
128
  return {
95
129
  [import_sequelize.Op.and]: conditions
96
130
  };
97
131
  }
98
- return {
99
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.notILike : import_sequelize.Op.notLike]: `${escapeLike(value)}%`
100
- };
132
+ return getFieldExpression(`${escapeLike(value)}%`, ctx, (0, import_utils.isPg)(ctx) ? "NOT ILIKE" : "NOT LIKE");
101
133
  },
102
134
  $endWith(value, ctx) {
103
135
  if (Array.isArray(value)) {
104
- const conditions = value.map((item) => ({
105
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.iLike : import_sequelize.Op.like]: `%${escapeLike(item)}`
106
- }));
136
+ const conditions = value.map(
137
+ (item) => getFieldExpression(`%${escapeLike(item)}`, ctx, (0, import_utils.isPg)(ctx) ? "ILIKE" : "LIKE")
138
+ );
107
139
  return {
108
140
  [import_sequelize.Op.or]: conditions
109
141
  };
110
142
  }
111
- return {
112
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.iLike : import_sequelize.Op.like]: `%${escapeLike(value)}`
113
- };
143
+ return getFieldExpression(`%${escapeLike(value)}`, ctx, (0, import_utils.isPg)(ctx) ? "ILIKE" : "LIKE");
114
144
  },
115
145
  $notEndWith(value, ctx) {
116
146
  if (Array.isArray(value)) {
117
- const conditions = value.map((item) => ({
118
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.notILike : import_sequelize.Op.notLike]: `%${escapeLike(item)}`
119
- }));
147
+ const conditions = value.map(
148
+ (item) => getFieldExpression(`%${escapeLike(item)}`, ctx, (0, import_utils.isPg)(ctx) ? "NOT ILIKE" : "NOT LIKE")
149
+ );
120
150
  return {
121
151
  [import_sequelize.Op.and]: conditions
122
152
  };
123
153
  }
124
- return {
125
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.notILike : import_sequelize.Op.notLike]: `%${escapeLike(value)}`
126
- };
154
+ return getFieldExpression(`%${escapeLike(value)}`, ctx, (0, import_utils.isPg)(ctx) ? "NOT ILIKE" : "NOT LIKE");
127
155
  }
128
156
  };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/database",
3
- "version": "1.6.0-alpha.19",
3
+ "version": "1.6.0-alpha.20",
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": "1.6.0-alpha.19",
10
- "@nocobase/utils": "1.6.0-alpha.19",
9
+ "@nocobase/logger": "1.6.0-alpha.20",
10
+ "@nocobase/utils": "1.6.0-alpha.20",
11
11
  "async-mutex": "^0.3.2",
12
12
  "chalk": "^4.1.1",
13
13
  "cron-parser": "4.4.0",
@@ -38,5 +38,5 @@
38
38
  "url": "git+https://github.com/nocobase/nocobase.git",
39
39
  "directory": "packages/database"
40
40
  },
41
- "gitHead": "667b67a161c841c01d4ab337afa42cd29d6cf540"
41
+ "gitHead": "c127664eb2b900edd5c18c9344046cd663a06c3b"
42
42
  }