Skip to content

Commit

Permalink
fix(db-ql): fix remove() fatal error;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Oct 20, 2021
1 parent 3958d5f commit 0d64aa7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/database-ql/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export class Query {
}

const param = this.buildQueryParam()
param.multi = options.multi ?? false
param.multi = options?.multi ?? false

const res = await this.send(ActionType.remove, param)
if (res.error) {
Expand Down Expand Up @@ -531,7 +531,7 @@ export class Query {
protected async internalMerge<T = any>(options?: { intersection?: boolean }): Promise<GetRes<T>> {

options = options ?? {} as any
const intersection = options.intersection ?? false
const intersection = options?.intersection ?? false

// 调用 get() 执行主查询
const res = await this.internalGet()
Expand Down
30 changes: 30 additions & 0 deletions packages/database-ql/tests/units/remove/remove.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

const { Actions, getDb } = require('../_utils')
const assert = require('assert')
const { ObjectId, Binary } = require('bson')

describe('db-ql(unit): db::remove()', () => {
it('remove() should be ok', async () => {
const { db, req } = getDb()

const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72])
const uid = new ObjectId()
const res = await db.collection('tasks')
.where({ name: 'laf' })
.remove()

assert.strictEqual(req.action, Actions.remove)
assert.strictEqual(req.params.collectionName, 'tasks')

// check options
console.log(req.params, res)
assert.equal(req.params.multi, false)

// check query
assert.deepEqual(req.params.query, { name: 'laf' })

// check result
assert.ok(!res.code)
assert.equal(res.deleted, 1)
})
})

0 comments on commit 0d64aa7

Please sign in to comment.