mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
Show result of the last query in a script #36
This commit is contained in:
@@ -105,8 +105,8 @@ class Database {
|
|||||||
if (results.error) {
|
if (results.error) {
|
||||||
throw results.error
|
throw results.error
|
||||||
}
|
}
|
||||||
// if it was more than one select - take only the first one
|
// if it was more than one select - take only the last one
|
||||||
return results[0]
|
return results[results.length - 1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ describe('database.js', () => {
|
|||||||
await expect(db.loadDb(buffer)).to.be.rejectedWith('foo')
|
await expect(db.loadDb(buffer)).to.be.rejectedWith('foo')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns a query result', async () => {
|
it('returns the last query result', async () => {
|
||||||
const SQL = await getSQL
|
const SQL = await getSQL
|
||||||
const tempDb = new SQL.Database()
|
const tempDb = new SQL.Database()
|
||||||
tempDb.run(`
|
tempDb.run(`
|
||||||
@@ -99,18 +99,12 @@ describe('database.js', () => {
|
|||||||
const buffer = new Blob([data])
|
const buffer = new Blob([data])
|
||||||
|
|
||||||
await db.loadDb(buffer)
|
await db.loadDb(buffer)
|
||||||
const result = await db.execute('SELECT * from test')
|
const result = await db.execute('SELECT * from test limit 1; SELECT * from test;')
|
||||||
expect(result.columns).to.have.lengthOf(3)
|
expect(result.columns).to.have.lengthOf(3)
|
||||||
expect(result.columns[0]).to.equal('id')
|
expect(result.columns).to.eql(['id', 'name', 'faculty'])
|
||||||
expect(result.columns[1]).to.equal('name')
|
|
||||||
expect(result.columns[2]).to.equal('faculty')
|
|
||||||
expect(result.values).to.have.lengthOf(2)
|
expect(result.values).to.have.lengthOf(2)
|
||||||
expect(result.values[0][0]).to.equal(1)
|
expect(result.values[0]).to.eql([1, 'Harry Potter', 'Griffindor'])
|
||||||
expect(result.values[0][1]).to.equal('Harry Potter')
|
expect(result.values[1]).to.eql([2, 'Draco Malfoy', 'Slytherin'])
|
||||||
expect(result.values[0][2]).to.equal('Griffindor')
|
|
||||||
expect(result.values[1][0]).to.equal(2)
|
|
||||||
expect(result.values[1][1]).to.equal('Draco Malfoy')
|
|
||||||
expect(result.values[1][2]).to.equal('Slytherin')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns an error', async () => {
|
it('returns an error', async () => {
|
||||||
@@ -149,12 +143,9 @@ describe('database.js', () => {
|
|||||||
expect(schema).to.have.lengthOf(1)
|
expect(schema).to.have.lengthOf(1)
|
||||||
expect(schema[0].name).to.equal('csv_import')
|
expect(schema[0].name).to.equal('csv_import')
|
||||||
expect(schema[0].columns).to.have.lengthOf(3)
|
expect(schema[0].columns).to.have.lengthOf(3)
|
||||||
expect(schema[0].columns[0].name).to.equal('id')
|
expect(schema[0].columns[0]).to.eql({ name: 'id', type: 'real' })
|
||||||
expect(schema[0].columns[0].type).to.equal('real')
|
expect(schema[0].columns[1]).to.eql({ name: 'name', type: 'text' })
|
||||||
expect(schema[0].columns[1].name).to.equal('name')
|
expect(schema[0].columns[2]).to.eql({ name: 'faculty', type: 'text' })
|
||||||
expect(schema[0].columns[1].type).to.equal('text')
|
|
||||||
expect(schema[0].columns[2].name).to.equal('faculty')
|
|
||||||
expect(schema[0].columns[2].type).to.equal('text')
|
|
||||||
|
|
||||||
const result = await db.execute('SELECT * from csv_import')
|
const result = await db.execute('SELECT * from csv_import')
|
||||||
expect(result.columns).to.eql(data.columns)
|
expect(result.columns).to.eql(data.columns)
|
||||||
|
|||||||
Reference in New Issue
Block a user