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

fix column order in result set #74

This commit is contained in:
lana-k
2021-08-10 20:31:12 +02:00
parent 2ed5160f65
commit 9f32323a80
13 changed files with 155 additions and 92 deletions

View File

@@ -8,10 +8,15 @@ const hintsByCode = {
export default {
getResult (source) {
const result = {}
const result = {
columns: []
}
const values = {}
if (source.meta.fields) {
source.meta.fields.forEach(col => {
result[col.trim()] = source.data.map(row => {
let colName = col.trim()
result.columns.push(colName)
values[colName] = source.data.map(row => {
let value = row[col]
if (value instanceof Date) {
value = value.toISOString()
@@ -21,7 +26,9 @@ export default {
})
} else {
for (let i = 0; i <= source.data[0].length - 1; i++) {
result[`col${i + 1}`] = source.data.map(row => {
let colName = `col${i + 1}`
result.columns.push(colName)
values[colName] = source.data.map(row => {
let value = row[i]
if (value instanceof Date) {
value = value.toISOString()
@@ -30,6 +37,8 @@ export default {
})
}
}
result.values = values
return result
},

View File

@@ -30,7 +30,7 @@
<tr v-for="rowIndex in currentPageData.count" :key="rowIndex">
<td v-for="(col, colIndex) in columns" :key="colIndex">
<div class="cell-data" :style="cellStyle">
{{ dataSet[col][rowIndex - 1 + currentPageData.start] }}
{{ dataSet.values[col][rowIndex - 1 + currentPageData.start] }}
</div>
</td>
</tr>
@@ -74,10 +74,10 @@ export default {
},
computed: {
columns () {
return Object.keys(this.dataSet)
return this.dataSet.columns
},
rowCount () {
return this.dataSet[this.columns[0]].length
return this.dataSet.values[this.columns[0]].length
},
cellStyle () {
const eq = this.tableWidth / this.columns.length

View File

@@ -48,17 +48,22 @@ export default class Sql {
throw new Error('exec: Missing query string')
}
const sqlResults = this.db.exec(sql, params)
return sqlResults.map(result => _getDataSourcesFromSqlResult(result))
return sqlResults.map(result => {
return {
columns: result.columns,
values: _getDataSourcesFromSqlResult(result)
}
})
}
import (tabName, data, progressCounterId, progressCallback, chunkSize = 1500) {
if (this.db === null) {
this.createDb()
}
const columns = Object.keys(data)
const rowCount = data[columns[0]].length
this.db.exec(dbUtils.getCreateStatement(tabName, data))
const chunks = dbUtils.generateChunks(data, chunkSize)
const columns = data.columns
const rowCount = data.values[columns[0]].length
this.db.exec(dbUtils.getCreateStatement(tabName, data.values))
const chunks = dbUtils.generateChunks(data.values, chunkSize)
const chunksAmount = Math.ceil(rowCount / chunkSize)
let count = 0
const insertStr = dbUtils.getInsertStmt(tabName, columns)

View File

@@ -88,11 +88,11 @@ class Database {
const result = await this.execute(getSchemaSql)
// Parse DDL statements to get column names and types
const parsedSchema = []
if (result && result.name) {
result.name.forEach((table, index) => {
if (result && result.values && result.values.name) {
result.values.name.forEach((table, index) => {
parsedSchema.push({
name: table,
columns: stms.getColumns(result.sql[index])
columns: stms.getColumns(result.values.sql[index])
})
})
}

View File

@@ -44,13 +44,13 @@ export default {
async created () {
const state = this.$store.state
let result = await state.db.execute('select sqlite_version()')
let result = (await state.db.execute('select sqlite_version()')).values
this.info.push({
name: 'SQLite version',
info: result['sqlite_version()']
})
result = await state.db.execute('PRAGMA compile_options')
result = (await state.db.execute('PRAGMA compile_options')).values
this.info.push({
name: 'SQLite compile options',
info: result.compile_options

View File

@@ -38,7 +38,7 @@
<teleport :to="`#${layout.dataView}-${tabIndex}`">
<data-view
:data-source="result"
:data-source="(result && result.values) || null"
:init-options="initViewOptions"
:init-mode="initViewType"
ref="dataView"