mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-07 02:28:54 +08:00
use execute method
This commit is contained in:
@@ -14,24 +14,23 @@ export default {
|
|||||||
FROM sqlite_master
|
FROM sqlite_master
|
||||||
WHERE type='table' AND name NOT LIKE 'sqlite_%';`
|
WHERE type='table' AND name NOT LIKE 'sqlite_%';`
|
||||||
|
|
||||||
// on 'action: exec' completed
|
this.execute(getSchemaSql)
|
||||||
worker.onmessage = event => {
|
.then(result => {
|
||||||
// Parse DDL statements to get column names and types
|
// Parse DDL statements to get column names and types
|
||||||
const parsedSchema = []
|
const parsedSchema = []
|
||||||
event.data.results[0].values.forEach(item => {
|
result.values.forEach(item => {
|
||||||
parsedSchema.push({
|
parsedSchema.push({
|
||||||
name: item[0],
|
name: item[0],
|
||||||
columns: getColumns(item[1])
|
columns: getColumns(item[1])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// Return db name and schema
|
||||||
|
resolve({
|
||||||
|
dbName: file.name,
|
||||||
|
schema: parsedSchema
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// Return db name and schema
|
|
||||||
resolve({
|
|
||||||
dbName: file.name,
|
|
||||||
schema: parsedSchema
|
|
||||||
})
|
|
||||||
}
|
|
||||||
worker.postMessage({ action: 'exec', sql: getSchemaSql })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -4,7 +4,7 @@ import router from './router'
|
|||||||
import store from './store'
|
import store from './store'
|
||||||
import { VuePlugin } from 'vuera'
|
import { VuePlugin } from 'vuera'
|
||||||
import VModal from 'vue-js-modal'
|
import VModal from 'vue-js-modal'
|
||||||
import db from '@/dataBase'
|
import db from '@/database'
|
||||||
|
|
||||||
import '@/assets/styles/variables.css'
|
import '@/assets/styles/variables.css'
|
||||||
import '@/assets/styles/buttons.css'
|
import '@/assets/styles/buttons.css'
|
||||||
|
|||||||
@@ -14,19 +14,26 @@ describe('HelloWorld.vue', () => {
|
|||||||
*/
|
*/
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
import initSqlJs from 'sql.js'
|
import initSqlJs from 'sql.js'
|
||||||
import db from '@/dataBase.js'
|
import db from '@/database.js'
|
||||||
|
|
||||||
describe('dataBase.js', () => {
|
describe('database.js', () => {
|
||||||
it('creates schema', () => {
|
it('creates schema', () => {
|
||||||
const config = {
|
const config = {
|
||||||
locateFile: filename => `js/sql-wasm.wasm`
|
locateFile: filename => `js/sql-wasm.wasm`
|
||||||
}
|
}
|
||||||
return initSqlJs(config)
|
return initSqlJs(config)
|
||||||
.then(SQL => {
|
.then(SQL => {
|
||||||
const dataBase = new SQL.Database()
|
const database = new SQL.Database()
|
||||||
dataBase.run('CREATE TABLE test (col1, col2);')
|
database.run(`
|
||||||
|
CREATE TABLE test (
|
||||||
|
col1,
|
||||||
|
col2 integer,
|
||||||
|
col3 decimal(5,2),
|
||||||
|
col4 varchar(30)
|
||||||
|
)
|
||||||
|
`)
|
||||||
|
|
||||||
const data = dataBase.export()
|
const data = database.export()
|
||||||
const buffer = new Blob([data])
|
const buffer = new Blob([data])
|
||||||
return db.loadDb(buffer)
|
return db.loadDb(buffer)
|
||||||
})
|
})
|
||||||
@@ -37,7 +44,11 @@ describe('dataBase.js', () => {
|
|||||||
expect(schema[0].columns[0].name).to.equal('col1')
|
expect(schema[0].columns[0].name).to.equal('col1')
|
||||||
expect(schema[0].columns[0].type).to.equal('N/A')
|
expect(schema[0].columns[0].type).to.equal('N/A')
|
||||||
expect(schema[0].columns[1].name).to.equal('col2')
|
expect(schema[0].columns[1].name).to.equal('col2')
|
||||||
expect(schema[0].columns[1].type).to.equal('N/A')
|
expect(schema[0].columns[1].type).to.equal('integer')
|
||||||
|
expect(schema[0].columns[2].name).to.equal('col3')
|
||||||
|
expect(schema[0].columns[2].type).to.equal('decimal(5, 2)')
|
||||||
|
expect(schema[0].columns[3].name).to.equal('col4')
|
||||||
|
expect(schema[0].columns[3].type).to.equal('varchar(30)')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user