1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-07 02:28:54 +08:00

fix column order in result set #74

This commit is contained in:
lana-k
2021-08-10 20:31:12 +02:00
parent 2ed5160f65
commit 9f32323a80
13 changed files with 155 additions and 92 deletions

View File

@@ -35,9 +35,12 @@ describe('_sql.js', () => {
const result = sql.exec('SELECT * from test')
expect(result).to.have.lengthOf(1)
expect(result[0]).to.eql({
id: [1, 2],
name: ['Harry Potter', 'Draco Malfoy'],
faculty: ['Griffindor', 'Slytherin']
columns: ['id', 'name','faculty'],
values: {
id: [1, 2],
name: ['Harry Potter', 'Draco Malfoy'],
faculty: ['Griffindor', 'Slytherin']
}
})
})
@@ -64,13 +67,16 @@ describe('_sql.js', () => {
it('imports', async () => {
const data = {
id: [1, 2, 3, 4],
name: [
'Harry Potter',
'Draco Malfoy',
'Hermione Granger',
'Ron Weasley'
]
columns: ['id', 'name'],
values: {
id: [1, 2, 3, 4],
name: [
'Harry Potter',
'Draco Malfoy',
'Hermione Granger',
'Ron Weasley'
]
}
}
const progressCallback = sinon.stub()
const progressCounterId = 1
@@ -104,7 +110,7 @@ describe('_sql.js', () => {
anotherSql.open(data)
const result = anotherSql.exec('SELECT * from test')
expect(result).to.have.lengthOf(1)
expect(result[0]).to.eql({
expect(result[0].values).to.eql({
id: [1, 2],
name: ['Harry Potter', 'Draco Malfoy'],
faculty: ['Griffindor', 'Slytherin']
@@ -146,26 +152,29 @@ describe('_sql.js', () => {
`)
let result = sql.exec('SELECT * from test')
expect(result[0]).to.eql({
expect(result[0].values).to.eql({
id: [1, 2],
name: ['foo', 'bar']
})
const data = {
id: [1, 2, 3, 4],
name: [
'Harry Potter',
'Draco Malfoy',
'Hermione Granger',
'Ron Weasley'
]
columns: ['id', 'name'],
values: {
id: [1, 2, 3, 4],
name: [
'Harry Potter',
'Draco Malfoy',
'Hermione Granger',
'Ron Weasley'
]
}
}
// import adds table
sql.import('foo', data, 1, sinon.stub(), 2)
result = sql.exec('SELECT * from foo')
expect(result[0]).to.eql(data)
result = sql.exec('SELECT * from test')
expect(result[0]).to.eql({
expect(result[0].values).to.eql({
id: [1, 2],
name: ['foo', 'bar']
})

View File

@@ -85,7 +85,7 @@ describe('database.js', () => {
await db.loadDb(buffer)
const result = await db.execute('SELECT * from test limit 1; SELECT * from test;')
expect(result).to.eql({
expect(result.values).to.eql({
id: [1, 2],
name: ['Harry Potter', 'Draco Malfoy'],
faculty: ['Griffindor', 'Slytherin']
@@ -116,9 +116,12 @@ describe('database.js', () => {
it('adds table from csv', async () => {
const data = {
id: [1, 2],
name: ['Harry Potter', 'Draco Malfoy'],
faculty: ['Griffindor', 'Slytherin']
columns: ['id', 'name','faculty'],
values: {
id: [1, 2],
name: ['Harry Potter', 'Draco Malfoy'],
faculty: ['Griffindor', 'Slytherin']
}
}
const progressHandler = sinon.spy()
const progressCounterId = db.createProgressCounter(progressHandler)
@@ -144,9 +147,12 @@ describe('database.js', () => {
it('addTableFromCsv throws errors', async () => {
const data = {
id: [1, 2],
name: ['Harry Potter', 'Draco Malfoy'],
faculty: null
columns: [],
values: {
id: [1, 2],
name: ['Harry Potter', 'Draco Malfoy'],
faculty: null
}
}
const progressHandler = sinon.stub()
const progressCounterId = db.createProgressCounter(progressHandler)
@@ -214,8 +220,11 @@ describe('database.js', () => {
// check that new db works and has the same table and data
result = await anotherDb.execute('SELECT * from foo')
expect(result).to.eql({
id: [1],
name: ['Harry Potter']
columns: ['id', 'name'],
values: {
id: [1],
name: ['Harry Potter']
}
})
})

View File

@@ -37,7 +37,7 @@ describe('SQLite extensions', function () {
abs(pi() / 2 - atan2(1, 0)) < 0.000001
`)
expect(actual).to.eql({
expect(actual.values).to.eql({
'abs(3.1415926 - pi()) < 0.000001': [1],
'abs(1 - cos(2 * pi())) < 0.000001': [1],
'abs(0 - sin(pi())) < 0.000001': [1],
@@ -71,7 +71,7 @@ describe('SQLite extensions', function () {
ceil(-1.95) + ceil(1.95),
floor(-1.95) + floor(1.95)
`)
expect(actual).to.eql({
expect(actual.values).to.eql({
'exp(0)': [1],
'log(exp(1))': [1],
'log10(10000)': [4],
@@ -99,7 +99,7 @@ describe('SQLite extensions', function () {
padc('foo', 5),
strfilter('abcba', 'bc')
`)
expect(actual).to.eql({
expect(actual.values).to.eql({
"replicate('ab', 4)": ['abababab'],
"charindex('ab', 'foobarabbarfoo')": [7],
"charindex('ab', 'foobarabbarfoo', 8)": [0],
@@ -137,7 +137,7 @@ describe('SQLite extensions', function () {
VALUES (1)
)
`)
expect(actual).to.eql({
expect(actual.values).to.eql({
'abs( 3.77406806 - stdev(x)) < 0.000001': [1],
'abs(14.24358974 - variance(x)) < 0.000001': [1],
'mode(x)': [1],
@@ -152,7 +152,7 @@ describe('SQLite extensions', function () {
SELECT value
FROM generate_series(5, 20, 5)
`)
expect(actual).to.eql({
expect(actual.values).to.eql({
value: [5, 10, 15, 20]
})
})
@@ -194,7 +194,7 @@ describe('SQLite extensions', function () {
WHERE nc.root = 2 AND nc.depth = 2
);
`)
expect(actual).to.eql({
expect(actual.values).to.eql({
name: [
'_sql.spec.js',
'_statements.spec.js',
@@ -212,7 +212,7 @@ describe('SQLite extensions', function () {
length(uuid()) as length,
uuid_str(uuid_blob('26a8349c8a7f4cbeb519bf792c3d7ac6')) as uid
`)
expect(actual).to.eql({
expect(actual.values).to.eql({
length: [36],
uid: ['26a8349c-8a7f-4cbe-b519-bf792c3d7ac6']
})
@@ -225,7 +225,7 @@ describe('SQLite extensions', function () {
regexpi('=\\s?\\d+', 'const foo = 123; const bar = "bar"') as two,
'const foo = 123; const bar = "bar"' REGEXP '=\\s?\\d+' as three
`)
expect(actual).to.eql({
expect(actual.values).to.eql({
one: [1],
two: [1],
three: [1]
@@ -260,7 +260,7 @@ describe('SQLite extensions', function () {
ALTER TABLE surface DROP COLUMN rownum;
SELECT * FROM surface;
`)
expect(actual).to.eql({
expect(actual.values).to.eql({
x: [5, 10, 15],
y: [3, 6, 9],
'5.0': [3.2, 4.3, 5.4],
@@ -292,7 +292,7 @@ describe('SQLite extensions', function () {
WHERE body MATCH '"full-text" NOT document'
ORDER BY rank;
`)
expect(actual).to.eql({
expect(actual.values).to.eql({
sender: ['bar@localhost']
})
})