mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 10:08:52 +08:00
* 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.
39 lines
1.0 KiB
JavaScript
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);'
|
|
)
|
|
})
|
|
})
|