mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 10:08:52 +08:00
Always create empty db on start #46
This commit is contained in:
@@ -4,6 +4,8 @@ import Editor from '@/views/Main/Editor'
|
||||
import MyQueries from '@/views/Main/MyQueries'
|
||||
import Welcome from '@/views/Welcome'
|
||||
import Main from '@/views/Main'
|
||||
import store from '@/store'
|
||||
import database from '@/lib/database'
|
||||
|
||||
Vue.use(VueRouter)
|
||||
|
||||
@@ -36,4 +38,13 @@ const router = new VueRouter({
|
||||
routes
|
||||
})
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
if (!store.state.db) {
|
||||
const newDb = database.getNewDatabase()
|
||||
await newDb.loadDb()
|
||||
store.commit('setDb', newDb)
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
import Splitpanes from '@/components/Splitpanes'
|
||||
import Schema from './Schema'
|
||||
import Tabs from './Tabs'
|
||||
import database from '@/lib/database'
|
||||
import store from '@/store'
|
||||
|
||||
export default {
|
||||
name: 'Editor',
|
||||
@@ -29,11 +27,9 @@ export default {
|
||||
Splitpanes,
|
||||
Tabs
|
||||
},
|
||||
async beforeRouteEnter (to, from, next) {
|
||||
if (!store.state.db) {
|
||||
const newDb = database.getNewDatabase()
|
||||
await newDb.loadDb()
|
||||
store.commit('setDb', newDb)
|
||||
async beforeCreate () {
|
||||
const schema = this.$store.state.db.schema
|
||||
if (!schema || schema.length === 0) {
|
||||
const stmt = [
|
||||
'/*',
|
||||
' * Your database is empty. In order to start building charts',
|
||||
@@ -51,10 +47,9 @@ export default {
|
||||
"('Slytherin', 80);"
|
||||
].join('\n')
|
||||
|
||||
const tabId = await store.dispatch('addTab', { query: stmt })
|
||||
store.commit('setCurrentTabId', tabId)
|
||||
const tabId = await this.$store.dispatch('addTab', { query: stmt })
|
||||
this.$store.commit('setCurrentTabId', tabId)
|
||||
}
|
||||
next()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user