1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 18:18:53 +08:00
Files
sqliteviz/tests/lib/database/_statements.spec.js
twoxfh 53b2d8372f Updating how database object information is getting retrieved (#79)
* Updating how database object information is getting retrieved

I updated the SQLite query for gathering database objects to make use of the JSON1 extension so you can grab tables and views name, their associated columns with types and set it to the schema. This removes the need to work with DDL's. Hints for Tables and Views works since my approach is they are both database objects.
2021-08-18 20:22:30 +02:00

39 lines
1.0 KiB
JavaScript

import { expect } from 'chai'
import stmts from '@/lib/database/_statements'
describe('_statements.js', () => {
it('generateChunks', () => {
const source = {
id: ['1', '2', '3', '4', '5']
}
const size = 2
const chunks = stmts.generateChunks(source, size)
const output = []
for (const chunk of chunks) {
output.push(chunk)
}
expect(output[0]).to.eql([['1'], ['2']])
expect(output[1]).to.eql([['3'], ['4']])
expect(output[2]).to.eql([['5']])
})
it('getInsertStmt', () => {
const columns = ['id', 'name']
expect(stmts.getInsertStmt('foo', columns))
.to.equal('INSERT INTO "foo" ("id", "name") VALUES (?, ?);')
})
it('getCreateStatement', () => {
const data = {
id: [1, 2],
name: ['foo', 'bar'],
isAdmin: [true, false],
startDate: [new Date(), new Date()]
}
expect(stmts.getCreateStatement('foo', data)).to.equal(
'CREATE table "foo"("id" REAL, "name" TEXT, "isAdmin" INTEGER, "startDate" TEXT);'
)
})
})