1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 10:08:52 +08:00

remove saveDbName method (refactor)

This commit is contained in:
lana-k
2020-12-27 18:03:04 +01:00
parent 1150b2e7c4
commit 34764a6e33
5 changed files with 11 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "sqliteviz", "name": "sqliteviz",
"version": "0.8.0", "version": "1.0.0",
"license": "Apache-2.0", "license": "Apache-2.0",
"private": true, "private": true,
"scripts": { "scripts": {

View File

@@ -78,8 +78,8 @@ export default {
loadDb () { loadDb () {
this.state = 'drop' this.state = 'drop'
return Promise.all([this.$db.loadDb(this.$refs.file.files[0]), this.animationPromise]) return Promise.all([this.$db.loadDb(this.$refs.file.files[0]), this.animationPromise])
.then(([schema]) => { .then(([{ dbName, schema }]) => {
this.$store.commit('saveSchema', schema) this.$store.commit('saveSchema', { dbName, schema })
if (this.$route.path !== '/editor') { if (this.$route.path !== '/editor') {
this.$router.push('/editor') this.$router.push('/editor')
} }

View File

@@ -65,8 +65,8 @@ export default {
methods: { methods: {
changeDb () { changeDb () {
this.$db.loadDb(this.$refs.dbfile.files[0]) this.$db.loadDb(this.$refs.dbfile.files[0])
.then((schema) => { .then(({ dbName, schema }) => {
this.$store.commit('saveSchema', schema) this.$store.commit('saveSchema', { dbName, schema })
}) })
} }
} }

View File

@@ -1,11 +1,8 @@
import store from '@/store'
const worker = new Worker('js/worker.sql-wasm.js') const worker = new Worker('js/worker.sql-wasm.js')
export default { export default {
loadDb (file) { loadDb (file) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const dbName = file.name
store.commit('saveDbName', dbName)
const f = file const f = file
const r = new FileReader() const r = new FileReader()
r.onload = () => { r.onload = () => {
@@ -18,7 +15,10 @@ export default {
// on 'action: exec' completed // on 'action: exec' completed
worker.onmessage = event => { worker.onmessage = event => {
resolve(event.data.results[0].values) resolve({
dbName: file.name,
schema: event.data.results[0].values
})
} }
worker.postMessage({ action: 'exec', sql: getSchemaSql }) worker.postMessage({ action: 'exec', sql: getSchemaSql })
} }

View File

@@ -53,7 +53,8 @@ export default new Vuex.Store({
predefinedQueries: [] predefinedQueries: []
}, },
mutations: { mutations: {
saveSchema (state, schema) { saveSchema (state, { dbName, schema }) {
state.dbName = dbName
const parsedSchema = [] const parsedSchema = []
schema.forEach(item => { schema.forEach(item => {
parsedSchema.push({ parsedSchema.push({
@@ -66,9 +67,6 @@ export default new Vuex.Store({
saveDbFile (state, file) { saveDbFile (state, file) {
state.dbFile = file state.dbFile = file
}, },
saveDbName (state, name) {
state.dbName = name
},
addTab (state, tab) { addTab (state, tab) {
// add new tab only if was not already opened // add new tab only if was not already opened
if (!state.tabs.some(openedTab => openedTab.id === tab.id)) { if (!state.tabs.some(openedTab => openedTab.id === tab.id)) {