@cloudcome/utils-uni 1.13.0 → 1.15.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/dist/database.cjs CHANGED
@@ -2,54 +2,196 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const type = require("@cloudcome/utils-core/type");
4
4
  const _helpers = require("./_helpers.cjs");
5
+ const error = require("./error.cjs");
5
6
  const object = require("@cloudcome/utils-core/object");
6
7
  const _try = require("@cloudcome/utils-core/try");
7
- const dbCmd = uniCloud.database().command;
8
+ class DbBaseCommand {
9
+ command;
10
+ parameter;
11
+ isQuery = false;
12
+ isMutate = false;
13
+ constructor(command, parameter) {
14
+ this.command = command;
15
+ this.parameter = parameter;
16
+ }
17
+ getValue(db) {
18
+ return db.command[this.command].call(
19
+ db.command,
20
+ this.parameter
21
+ );
22
+ }
23
+ getExpression(fieldName) {
24
+ return {
25
+ [`$${this.command}`]: [fieldName, this.parameter]
26
+ };
27
+ }
28
+ }
29
+ class DbQueryCommand extends DbBaseCommand {
30
+ isQuery = true;
31
+ }
32
+ class DbMutateCommand extends DbBaseCommand {
33
+ isMutate = true;
34
+ }
35
+ const dbQuery = {
36
+ /**
37
+ * 等于操作符
38
+ * @param value 比较值
39
+ * @returns DbQueryCommand 查询命令对象
40
+ */
41
+ eq: (value) => new DbQueryCommand("eq", value),
42
+ /**
43
+ * 不等于操作符
44
+ * @param value 比较值
45
+ * @returns DbQueryCommand 查询命令对象
46
+ */
47
+ neq: (value) => new DbQueryCommand("neq", value),
48
+ /**
49
+ * 大于操作符
50
+ * @param value 比较值
51
+ * @returns DbQueryCommand 查询命令对象
52
+ */
53
+ gt: (value) => new DbQueryCommand("gt", value),
54
+ /**
55
+ * 大于等于操作符
56
+ * @param value 比较值
57
+ * @returns DbQueryCommand 查询命令对象
58
+ */
59
+ gte: (value) => new DbQueryCommand("gte", value),
60
+ /**
61
+ * 小于操作符
62
+ * @param value 比较值
63
+ * @returns DbQueryCommand 查询命令对象
64
+ */
65
+ lt: (value) => new DbQueryCommand("lt", value),
66
+ /**
67
+ * 小于等于操作符
68
+ * @param value 比较值
69
+ * @returns DbQueryCommand 查询命令对象
70
+ */
71
+ lte: (value) => new DbQueryCommand("lte", value),
72
+ /**
73
+ * 包含在数组中操作符
74
+ * @param value 值数组
75
+ * @returns DbQueryCommand 查询命令对象
76
+ */
77
+ in: (value) => new DbQueryCommand("in", value),
78
+ /**
79
+ * 不包含在数组中操作符
80
+ * @param value 值数组
81
+ * @returns DbQueryCommand 查询命令对象
82
+ */
83
+ nin: (value) => new DbQueryCommand("nin", value),
84
+ /**
85
+ * 逻辑与操作符
86
+ * @param conditions 查询条件参数
87
+ * @returns DbQueryCommand 查询命令对象
88
+ */
89
+ and: (conditions) => new DbQueryCommand("and", conditions),
90
+ /**
91
+ * 逻辑或操作符
92
+ * @param conditions 查询条件参数
93
+ * @returns DbQueryCommand 查询命令对象
94
+ */
95
+ or: (conditions) => new DbQueryCommand("or", conditions),
96
+ /**
97
+ * 数组长度匹配操作符
98
+ * @param size 数组长度
99
+ * @returns DbQueryCommand 查询命令对象
100
+ */
101
+ size: (size) => new DbQueryCommand("size", size)
102
+ };
103
+ const dbMutate = {
104
+ /**
105
+ * 数值增加操作符
106
+ * @param value 增加的数值
107
+ * @returns DbMutateCommand 变更命令对象
108
+ */
109
+ inc: (value) => new DbMutateCommand("inc", value),
110
+ /**
111
+ * 数值乘法操作符
112
+ * @param value 乘数
113
+ * @returns DbMutateCommand 变更命令对象
114
+ */
115
+ mul: (value) => new DbMutateCommand("mul", value),
116
+ /**
117
+ * 设置字段值操作符
118
+ * @param value 设置的值
119
+ * @returns DbMutateCommand 变更命令对象
120
+ */
121
+ set: (value) => new DbMutateCommand("set", value),
122
+ /**
123
+ * 向数组末尾添加元素操作符
124
+ * @param value 添加的值
125
+ * @returns DbMutateCommand 变更命令对象
126
+ */
127
+ push: (value) => new DbMutateCommand("push", value),
128
+ /**
129
+ * 向数组开头添加元素操作符
130
+ * @param value 添加的值
131
+ * @returns DbMutateCommand 变更命令对象
132
+ */
133
+ unshift: (value) => new DbMutateCommand("unshift", value),
134
+ /**
135
+ * 从数组末尾移除元素操作符
136
+ * @returns DbMutateCommand 变更命令对象
137
+ */
138
+ pop: () => new DbMutateCommand("pop", void 0),
139
+ /**
140
+ * 从数组开头移除元素操作符
141
+ * @returns DbMutateCommand 变更命令对象
142
+ */
143
+ shift: () => new DbMutateCommand("shift", void 0),
144
+ /**
145
+ * 移除字段操作符
146
+ * @returns DbMutateCommand 变更命令对象
147
+ */
148
+ remove: () => new DbMutateCommand("remove", void 0)
149
+ };
8
150
  const dbAgg = uniCloud.database().command.aggregate;
9
151
  const db0 = uniCloud.database();
10
152
  let gid = 0;
11
153
  class Db {
12
- #host;
154
+ _host;
13
155
  /**
14
156
  * 是否为事务环境
15
157
  * - 查询条件只能是 id
16
158
  * - 不能聚合操作
17
159
  */
18
- #isTransaction = false;
19
- #options;
160
+ _isTransaction = false;
161
+ _options;
20
162
  /**
21
163
  * 构造函数,初始化数据库集合引用
22
164
  * @param collection 数据表名称
23
165
  * @param _mockDatabase 模拟数据库,用于单元测试
24
166
  */
25
167
  constructor(options) {
26
- this.#options = options;
27
- this.#host = options._mockDatabase || options.transaction?.collection(options.table) || db0.collection(options.table);
28
- this.#isTransaction = !!options.transaction;
168
+ this._options = options;
169
+ this._host = options._mockDatabase || options.transaction?.collection(options.table) || db0.collection(options.table);
170
+ this._isTransaction = !!options.transaction;
29
171
  }
30
172
  get table() {
31
- return this.#options.table;
173
+ return this._options.table;
32
174
  }
33
175
  /**
34
176
  * 获取聚合操作实例
35
177
  * @returns 聚合操作实例
36
178
  */
37
179
  aggregate() {
38
- return this.#host.aggregate();
180
+ return this._host.aggregate();
39
181
  }
40
- #hasWhere = void 0;
41
- #hasWhereId = void 0;
42
- #where = {};
43
- #doWhere(where, from) {
44
- if (this.#hasWhere) throw new Error(`已调用过一次 db.${_toWhereMethod(this.#hasWhere)} 了`);
182
+ _hasWhere = void 0;
183
+ _hasWhereId = void 0;
184
+ _where = {};
185
+ _doWhere(where, from) {
186
+ if (this._hasWhere) throw new Error(`已调用过一次 db.${_toWhereMethod(this._hasWhere)} 了`);
45
187
  const whereKeys = Object.keys(where);
46
188
  const isWhereId = whereKeys.length === 1 && "_id" in where && (type.isString(where._id) || type.isNumber(where._id));
47
- if (isWhereId && this.#hasLimit) {
189
+ if (isWhereId && this._hasLimit) {
48
190
  throw new Error(`db.${_toWhereIdMethod(from)} 方法不能与 db.limit() 方法同时调用`);
49
191
  }
50
- this.#hasWhere = from;
51
- this.#where = where;
52
- if (isWhereId) this.#hasWhereId = from;
192
+ this._hasWhere = from;
193
+ this._where = where;
194
+ if (isWhereId) this._hasWhereId = from;
53
195
  return this;
54
196
  }
55
197
  /**
@@ -58,7 +200,7 @@ class Db {
58
200
  * @returns 当前Db实例,支持链式调用
59
201
  */
60
202
  where(where) {
61
- return this.#doWhere(where, "where");
203
+ return this._doWhere(where, "where");
62
204
  }
63
205
  /**
64
206
  * 根据ID设置查询条件
@@ -66,102 +208,100 @@ class Db {
66
208
  * @returns 当前Db实例,支持链式调用
67
209
  */
68
210
  whereId(id) {
69
- return this.#doWhere({ _id: id }, "whereId");
211
+ return this._doWhere({ _id: id }, "whereId");
70
212
  }
71
- #hasSelect = 0;
72
- #select = {};
213
+ _hasSelect = 0;
214
+ _select = {};
73
215
  /**
74
216
  * 指定要返回的字段
75
217
  * @param fields 要返回的字段对象,true表示返回,false表示不返回
76
218
  * @returns 当前Db实例,支持链式调用
77
219
  */
78
220
  select(fields) {
79
- if (this.#hasSelect) throw new Error("db.select() 方法只能调用一次");
80
- this.#hasSelect++;
81
- this.#select = fields;
221
+ if (this._hasSelect) throw new Error("db.select() 方法只能调用一次");
222
+ this._hasSelect++;
223
+ this._select = fields;
82
224
  return this;
83
225
  }
84
- #hasOrder = 0;
85
- #order = {};
226
+ _hasOrder = 0;
227
+ _order = {};
86
228
  /**
87
229
  * 设置排序规则
88
230
  * @param order 排序规则对象,key为字段名,value为"asc"或"desc"
89
231
  * @returns 当前Db实例,支持链式调用
90
232
  */
91
233
  order(order) {
92
- this.#hasOrder++;
93
- this.#order = order;
234
+ this._hasOrder++;
235
+ this._order = order;
94
236
  return this;
95
237
  }
96
- #hasSkip = 0;
97
- #skip = 0;
238
+ _hasSkip = 0;
239
+ _skip = 0;
98
240
  /**
99
241
  * 跳过指定数量的记录
100
242
  * @param skip 要跳过的记录数
101
243
  * @returns 当前Db实例,支持链式调用
102
244
  */
103
245
  skip(skip) {
104
- if (this.#hasSkip) throw new Error("db.skip() 方法只能调用一次");
105
- this.#hasSkip++;
106
- this.#skip = skip;
246
+ if (this._hasSkip) throw new Error("db.skip() 方法只能调用一次");
247
+ this._hasSkip++;
248
+ this._skip = skip;
107
249
  return this;
108
250
  }
109
- #hasLimit = 0;
110
- #limit = 0;
251
+ _hasLimit = 0;
252
+ _limit = 0;
111
253
  /**
112
254
  * 限制返回的记录数量
113
255
  * @param limit 最大返回记录数
114
256
  * @returns 当前Db实例,支持链式调用
115
257
  */
116
258
  limit(limit) {
117
- if (this.#hasLimit) throw new Error("db.limit() 方法只能调用一次");
118
- if (this.#hasWhereId) {
119
- throw new Error(`db.limit() 方法不能与 ${_toWhereIdMethod(this.#hasWhereId)} 方法同时调用`);
259
+ if (this._hasLimit) throw new Error("db.limit() 方法只能调用一次");
260
+ if (this._hasWhereId) {
261
+ throw new Error(`db.limit() 方法不能与 ${_toWhereIdMethod(this._hasWhereId)} 方法同时调用`);
120
262
  }
121
- this.#hasLimit++;
122
- this.#limit = limit;
263
+ this._hasLimit++;
264
+ this._limit = limit;
123
265
  return this;
124
266
  }
125
- #hasLookup = 0;
267
+ _hasLookup = 0;
126
268
  get hasLookup() {
127
- return this.#hasLookup > 0;
269
+ return this._hasLookup > 0;
128
270
  }
129
- #lookups = [];
271
+ _lookups = [];
130
272
  lookup(table, lookup) {
131
- table.#hasLookup++;
132
- this.#hasLookup++;
133
- this.#lookups.push({
273
+ table._hasLookup++;
274
+ this._hasLookup++;
275
+ this._lookups.push({
134
276
  ...lookup,
135
- table,
136
- from: table.table
277
+ table
137
278
  });
138
279
  return this;
139
280
  }
140
- #aggregated = false;
141
- #endAggregate(aggRef) {
142
- if (this.#aggregated) throw new Error(`相同的数据表实例(${this.table})不能重复使用`);
143
- this.#aggregated = true;
281
+ _aggregated = false;
282
+ _endAggregate(aggRef) {
283
+ if (this._aggregated) throw new Error(`相同的数据表实例(${this.table})不能重复使用`);
284
+ this._aggregated = true;
144
285
  let returnAggRef = aggRef;
145
286
  const projects = {};
146
- for (const { type: type2, as, foreignField, from, localField, table } of this.#lookups) {
147
- const varName = `v${gid++}`;
287
+ for (const { type: type2, as, foreignField, localField, table, unselect } of this._lookups) {
288
+ const letName = `let${gid++}`;
148
289
  let pipeline = dbAgg.pipeline();
149
- pipeline = pipeline.match(
150
- dbCmd.expr(
151
- type2 === "n:1" ? (
152
- // @ts-ignore
153
- dbAgg.in([`$${foreignField}`, `$$${varName}`])
154
- ) : dbAgg.eq([`$${foreignField}`, `$$${varName}`])
155
- )
156
- );
157
- pipeline = table.#endAggregate(pipeline);
290
+ pipeline = pipeline.match({
291
+ $expr: {
292
+ $and: [
293
+ type2 === "n:1" ? { $in: [`$${foreignField}`, `$$${letName}`] } : { $eq: [`$${foreignField}`, `$$${letName}`] }
294
+ ]
295
+ }
296
+ });
297
+ pipeline = table._endAggregate(pipeline);
158
298
  pipeline = pipeline.done();
159
299
  returnAggRef = returnAggRef.lookup({
160
300
  let: {
161
- [varName]: `$${localField}`
301
+ [letName]: `$${localField}`
162
302
  },
163
303
  as,
164
- from,
304
+ from: table.table,
165
305
  pipeline
166
306
  });
167
307
  if (type2 === "1:1") {
@@ -170,30 +310,30 @@ class Db {
170
310
  preserveNullAndEmptyArrays: true
171
311
  });
172
312
  }
173
- projects[as] = true;
313
+ if (as && !unselect) projects[as] = true;
174
314
  }
175
- if (this.#hasWhere) returnAggRef = returnAggRef.match(this.#where);
176
- if (this.#hasSelect) returnAggRef = returnAggRef.project({ ...this.#select, ...projects });
177
- if (this.#hasOrder) returnAggRef = returnAggRef.sort(object.objectMap(this.#order, (v) => v === "asc" ? 1 : -1));
178
- if (this.#hasSkip) returnAggRef = returnAggRef.skip(this.#skip);
179
- if (this.#hasLimit) returnAggRef = returnAggRef.limit(this.#limit);
315
+ if (this._hasWhere) returnAggRef = returnAggRef.match(_mapCommandRaw(this._where));
316
+ if (this._hasSelect) returnAggRef = returnAggRef.project({ ...this._select, ...projects });
317
+ if (this._hasOrder) returnAggRef = returnAggRef.sort(object.objectMap(this._order, (v) => v === "asc" ? 1 : -1));
318
+ if (this._hasSkip) returnAggRef = returnAggRef.skip(this._skip);
319
+ if (this._hasLimit) returnAggRef = returnAggRef.limit(this._limit);
180
320
  return returnAggRef;
181
321
  }
182
- #endHost() {
183
- if (this.#hasWhere) {
184
- this.#host = this.#host.where(this.#where);
322
+ _endHost() {
323
+ if (this._hasWhere) {
324
+ this._host = this._host.where(_mapCommandRaw(this._where));
185
325
  }
186
- if (this.#hasSelect) {
187
- this.#host = this.#host.field(this.#select);
326
+ if (this._hasSelect) {
327
+ this._host = this._host.field(this._select);
188
328
  }
189
- if (this.#hasOrder) {
190
- object.objectEach(this.#order, (val, key) => {
191
- this.#host = this.#host.orderBy(key, val);
329
+ if (this._hasOrder) {
330
+ object.objectEach(this._order, (val, key) => {
331
+ this._host = this._host.orderBy(key, val);
192
332
  });
193
333
  }
194
- if (this.#hasSkip) this.#host = this.#host.skip(this.#skip);
195
- if (this.#hasLimit) this.#host = this.#host.limit(this.#limit);
196
- else if (this.#hasWhereId) this.#host = this.#host.limit(1);
334
+ if (this._hasSkip) this._host = this._host.skip(this._skip);
335
+ if (this._hasLimit) this._host = this._host.limit(this._limit);
336
+ else if (this._hasWhereId) this._host = this._host.limit(1);
197
337
  }
198
338
  /**
199
339
  * 执行查询操作
@@ -201,38 +341,38 @@ class Db {
201
341
  */
202
342
  async query() {
203
343
  let res;
204
- if (this.#hasLookup) {
344
+ if (this._hasLookup) {
205
345
  const aggRef = this.aggregate();
206
- this.#endAggregate(aggRef);
346
+ this._endAggregate(aggRef);
207
347
  res = await aggRef.end();
208
348
  } else {
209
- this.#endHost();
210
- res = await this.#host.get();
349
+ this._endHost();
350
+ res = await this._host.get();
211
351
  }
212
352
  type.isArray(res.data) ? res.data : [res.data];
213
353
  const { data } = _helpers.parseDatabaseOutput(res);
214
354
  return data;
215
355
  }
216
- async queryOne(ignoreMiss = false) {
217
- if (this.#hasLimit) throw new Error("db.queryOne() 方法不支持 limit 条件");
218
- if (!this.#hasWhereId) this.limit(1);
356
+ async queryOne(allowMiss = false) {
357
+ if (this._hasLimit) throw new Error("db.queryOne() 方法不支持 limit 条件");
358
+ if (!this._hasWhereId) this.limit(1);
219
359
  const data = await this.query();
220
360
  const res = data.at(0);
221
- if (!ignoreMiss && !res) throw new Error("未找到匹配记录");
222
- return res;
361
+ if (!allowMiss && !res) throw error.createCloudObjectError("查询数据为空", "queryOneNotFound");
362
+ return res || null;
223
363
  }
224
364
  /**
225
365
  * 获取匹配记录的数量
226
366
  * @returns 记录总数
227
367
  */
228
368
  async count() {
229
- if (this.#hasLookup) throw new Error("db.count() 方法不支持 lookup 聚合");
230
- if (this.#hasSelect) throw new Error("db.count() 方法不支持 select 条件");
231
- if (this.#hasOrder) throw new Error("db.count() 方法不支持 order 条件");
232
- if (this.#hasSkip) throw new Error("db.count() 方法不支持 skip 条件");
233
- if (this.#hasLimit) throw new Error("db.count() 方法不支持 limit 条件");
234
- this.#endHost();
235
- const res = await this.#host.count();
369
+ if (this._hasLookup) throw new Error("db.count() 方法不支持 lookup 聚合");
370
+ if (this._hasSelect) throw new Error("db.count() 方法不支持 select 条件");
371
+ if (this._hasOrder) throw new Error("db.count() 方法不支持 order 条件");
372
+ if (this._hasSkip) throw new Error("db.count() 方法不支持 skip 条件");
373
+ if (this._hasLimit) throw new Error("db.count() 方法不支持 limit 条件");
374
+ this._endHost();
375
+ const res = await this._host.count();
236
376
  const { total } = _helpers.parseDatabaseOutput(res);
237
377
  return total;
238
378
  }
@@ -242,14 +382,14 @@ class Db {
242
382
  * @returns 创建结果
243
383
  */
244
384
  async create(data) {
245
- if (this.#hasLookup) throw new Error("db.create() 方法不支持 lookup 聚合");
246
- if (this.#hasWhere) throw new Error("db.create() 方法不支持 where 条件");
247
- if (this.#hasSelect) throw new Error("db.create() 方法不支持 select 条件");
248
- if (this.#hasOrder) throw new Error("db.create() 方法不支持 order 条件");
249
- if (this.#hasSkip) throw new Error("db.create() 方法不支持 skip 条件");
250
- if (this.#hasLimit) throw new Error("db.create() 方法不支持 limit 条件");
251
- this.#endHost();
252
- const res = await this.#host.add(data);
385
+ if (this._hasLookup) throw new Error("db.create() 方法不支持 lookup 聚合");
386
+ if (this._hasWhere) throw new Error("db.create() 方法不支持 where 条件");
387
+ if (this._hasSelect) throw new Error("db.create() 方法不支持 select 条件");
388
+ if (this._hasOrder) throw new Error("db.create() 方法不支持 order 条件");
389
+ if (this._hasSkip) throw new Error("db.create() 方法不支持 skip 条件");
390
+ if (this._hasLimit) throw new Error("db.create() 方法不支持 limit 条件");
391
+ this._endHost();
392
+ const res = await this._host.add(data);
253
393
  const { id } = _helpers.parseDatabaseOutput(res);
254
394
  return id;
255
395
  }
@@ -259,15 +399,15 @@ class Db {
259
399
  * @returns 更新结果
260
400
  */
261
401
  async update(data) {
262
- if (this.#hasLookup) throw new Error("db.update() 方法不支持 lookup 聚合");
263
- if (!this.#hasWhere) throw new Error("设置 where 条件后才能执行 db.update() 方法");
264
- if (this.#hasSelect) throw new Error("db.update() 方法不支持 select 条件");
265
- if (this.#hasOrder) throw new Error("db.update() 方法不支持 order 条件");
266
- if (this.#hasSkip) throw new Error("db.update() 方法不支持 skip 条件");
267
- if (this.#hasLimit) throw new Error("db.update() 方法不支持 limit 条件");
268
- if (this.#isTransaction && !this.#hasWhereId) throw new Error("事务模式下 db.update() 的 where 条件必须是 _id");
269
- this.#endHost();
270
- const res = await this.#host.update(data);
402
+ if (this._hasLookup) throw new Error("db.update() 方法不支持 lookup 聚合");
403
+ if (!this._hasWhere) throw new Error("设置 where 条件后才能执行 db.update() 方法");
404
+ if (this._hasSelect) throw new Error("db.update() 方法不支持 select 条件");
405
+ if (this._hasOrder) throw new Error("db.update() 方法不支持 order 条件");
406
+ if (this._hasSkip) throw new Error("db.update() 方法不支持 skip 条件");
407
+ if (this._hasLimit) throw new Error("db.update() 方法不支持 limit 条件");
408
+ if (this._isTransaction && !this._hasWhereId) throw new Error("事务模式下 db.update() 的 where 条件必须是 _id");
409
+ this._endHost();
410
+ const res = await this._host.update(_mapCommandRaw(data));
271
411
  const { updated } = _helpers.parseDatabaseOutput(res);
272
412
  return updated;
273
413
  }
@@ -276,15 +416,15 @@ class Db {
276
416
  * @returns 删除结果
277
417
  */
278
418
  async remove() {
279
- if (this.#hasLookup) throw new Error("db.remove() 方法不支持 lookup 聚合");
280
- if (!this.#hasWhere) throw new Error("设置 where 条件后才能执行 db.remove() 方法");
281
- if (this.#hasSelect) throw new Error("db.remove() 方法不支持 select 条件");
282
- if (this.#hasOrder) throw new Error("db.remove() 方法不支持 order 条件");
283
- if (this.#hasSkip) throw new Error("db.remove() 方法不支持 skip 条件");
284
- if (this.#hasLimit) throw new Error("db.remove() 方法不支持 limit 条件");
285
- if (this.#isTransaction && !this.#hasWhereId) throw new Error("事务模式下 db.remove() 的 where 条件必须是 _id");
286
- this.#endHost();
287
- const res = await this.#host.remove();
419
+ if (this._hasLookup) throw new Error("db.remove() 方法不支持 lookup 聚合");
420
+ if (!this._hasWhere) throw new Error("设置 where 条件后才能执行 db.remove() 方法");
421
+ if (this._hasSelect) throw new Error("db.remove() 方法不支持 select 条件");
422
+ if (this._hasOrder) throw new Error("db.remove() 方法不支持 order 条件");
423
+ if (this._hasSkip) throw new Error("db.remove() 方法不支持 skip 条件");
424
+ if (this._hasLimit) throw new Error("db.remove() 方法不支持 limit 条件");
425
+ if (this._isTransaction && !this._hasWhereId) throw new Error("事务模式下 db.remove() 的 where 条件必须是 _id");
426
+ this._endHost();
427
+ const res = await this._host.remove();
288
428
  const { deleted } = _helpers.parseDatabaseOutput(res);
289
429
  return deleted;
290
430
  }
@@ -295,6 +435,11 @@ function _toWhereMethod(whereFrom) {
295
435
  function _toWhereIdMethod(whereFrom) {
296
436
  return whereFrom === "where" ? "where({ _id })" : "whereId(id)";
297
437
  }
438
+ function _mapCommandRaw(where) {
439
+ return object.objectMap(where, (val, key) => {
440
+ return type.isObject(val) && val instanceof DbBaseCommand ? val.getValue(db0) : val;
441
+ });
442
+ }
298
443
  function dbProxy(name) {
299
444
  return new Proxy(
300
445
  {},
@@ -366,9 +511,9 @@ async function dbTransaction(transacting, _mockDatabase, _mockDbInstance) {
366
511
  return result;
367
512
  }
368
513
  exports.parseDatabaseOutput = _helpers.parseDatabaseOutput;
369
- exports.dbAgg = dbAgg;
370
- exports.dbCmd = dbCmd;
514
+ exports.dbMutate = dbMutate;
371
515
  exports.dbProxy = dbProxy;
516
+ exports.dbQuery = dbQuery;
372
517
  exports.dbTransaction = dbTransaction;
373
518
  exports.dbUnique = dbUnique;
374
519
  exports.dbUpsert = dbUpsert;