replace db mechanism

This commit is contained in:
Alexey Kasyanchuk
2018-08-15 07:14:18 +03:00
parent 5ef25693c1
commit cff0f11c79
2 changed files with 85 additions and 0 deletions

31
tests/sphinx.api.test.js Normal file
View File

@ -0,0 +1,31 @@
import { assert } from "chai";
const {pool} = require('../src/background/mysql')
describe("big table for check", () => {
let sphinx;
it("init", async function() {
sphinx = await pool()
assert(sphinx)
await sphinx.query(`delete from feed where id >= 1`)
})
it("replace with add", async function() {
await sphinx.query(`insert into feed(id, data) values(1, '{a: 1}')`)
assert.equal((await sphinx.query(`select data from feed where id = 1`))[0].data, '{"a":1}')
await sphinx.replaceValues('feed', {id: 1, data: {a: 1, b: 2}}, true)
assert.equal((await sphinx.query(`select data from feed`))[0].data, '{"a":1,"b":2}')
})
it("replace without add", async function() {
await sphinx.query(`insert into feed(id, data) values(2, '{a: 1}')`)
await sphinx.replaceValues('feed', {id: 1, data: {a: 1, b: 2, c: 3}}, false)
assert.equal((await sphinx.query(`select data from feed where id = 1`))[0].data, '{"a":1,"b":2,"c":3}')
assert.equal((await sphinx.query(`select count(*) as c from feed`))[0].c, 2)
})
it("close", async function() {
await sphinx.end()
})
});