1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-10 03:58:54 +08:00
This commit is contained in:
lana-k
2022-06-24 21:29:40 +02:00
parent a20dd7f849
commit 518b22b489
15 changed files with 193 additions and 16 deletions

View File

@@ -7,6 +7,8 @@ import Worker from './_worker.js'
// https://github.com/nolanlawson/promise-worker
import PromiseWorker from 'promise-worker'
import { send } from '@/lib/utils/events'
function getNewDatabase () {
const worker = new Worker()
return new Database(worker)
@@ -76,6 +78,15 @@ class Database {
this.dbName = file ? fu.getFileName(file) : 'database'
this.refreshSchema()
send({
category: 'database',
action: 'import',
value: file ? file.size : 0,
label: file
? 'from=sqlite new_db=true'
: 'from=none new_db=true'
})
}
async refreshSchema () {
@@ -114,6 +125,12 @@ class Database {
throw new Error(data.error)
}
fu.exportToFile(data, fileName)
send({
category: 'database',
action: 'export',
value: data.byteLength,
label: 'to=sqlite'
})
}
async validateTableName (name) {

View File

@@ -1,5 +1,6 @@
import { nanoid } from 'nanoid'
import fu from '@/lib/utils/fileIo'
import { send } from '@/lib/utils/events'
import migration from './_migrations'
const migrate = migration._migrate
@@ -103,9 +104,27 @@ export default {
importInquiries () {
return fu.importFile()
.then(str => {
return this.deserialiseInquiries(str)
const inquires = this.deserialiseInquiries(str)
send({
category: 'inquiry',
action: 'import',
value: inquires.length
})
return inquires
})
},
export (inquiryList, fileName) {
const jsonStr = this.serialiseInquiries(inquiryList)
fu.exportToFile(jsonStr, fileName)
send({
category: 'inquiry',
action: 'export',
value: inquiryList.length
})
},
async readPredefinedInquiries () {
const res = await fu.readFile('./inquiries.json')

11
src/lib/utils/events.js Normal file
View File

@@ -0,0 +1,11 @@
export function send (payload) {
console.log(payload)
if (!window.sendEvent) {
return
}
const event = new CustomEvent('sqliteviz-app-event', {
detail: payload
})
window.dispatchEvent(event)
}