1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-09 03:28:54 +08:00

12 Commits
0.4.0 ... 0.5.0

Author SHA1 Message Date
lana-k
c991691fcb add .sqlite extension in db uploader 2020-11-14 20:36:35 +01:00
lana-k
39151732cf No db in schema sidebar #10 2020-11-13 23:32:37 +01:00
lana-k
92e6150ea5 add licence in package.json 2020-11-13 23:23:53 +01:00
lana-k
d4c233e1ef new splitter style 2020-11-13 23:21:04 +01:00
lana-k
05243ec991 dbuploader is a component now #10 2020-11-13 16:43:21 +01:00
lana-k
ec2b2b21d0 return predefined query 2020-11-13 16:04:09 +01:00
lana-k
1ae68a0043 Create LICENSE 2020-11-13 15:56:22 +01:00
lana-k
19f3e8b74a Empty state for my queries #8 2020-11-12 18:11:36 +01:00
lana-k
f65953a2e1 Add schema tokens in codemirror autocomplit #1 2020-11-12 15:30:37 +01:00
lana-k
c5fa3e903a Fix wrong trigger of autocomplete #15 2020-11-11 22:42:44 +01:00
lana-k
3f0a7597a2 Virtual tables are displayed now #13 2020-11-11 19:45:41 +01:00
lana-k
9912ed24cf new design for tab header and sql editor 2020-11-11 14:41:55 +01:00
21 changed files with 478 additions and 116 deletions

201
LICENSE Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

7
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "sqliteviz", "name": "sqliteviz",
"version": "0.0.1", "version": "0.5.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@@ -5149,6 +5149,11 @@
"integrity": "sha1-sgOOhG3DO6pXlhKNCAS0VbjB4h0=", "integrity": "sha1-sgOOhG3DO6pXlhKNCAS0VbjB4h0=",
"dev": true "dev": true
}, },
"debounce": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/debounce/-/debounce-1.2.0.tgz",
"integrity": "sha512-mYtLl1xfZLi1m4RtQYlZgJUNQjl4ZxVnHzIR8nLLgi4q1YT8o/WM+MK/f8yfcc9s5Ir5zRaPZyZU6xs1Syoocg=="
},
"debug": { "debug": {
"version": "4.1.1", "version": "4.1.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",

View File

@@ -1,6 +1,7 @@
{ {
"name": "sqliteviz", "name": "sqliteviz",
"version": "0.3.0", "version": "0.5.0",
"license" : "Apache-2.0",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",
@@ -11,6 +12,7 @@
"dependencies": { "dependencies": {
"codemirror": "^5.57.0", "codemirror": "^5.57.0",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"debounce": "^1.2.0",
"nanoid": "^3.1.12", "nanoid": "^3.1.12",
"plotly.js": "^1.57.1", "plotly.js": "^1.57.1",
"react": "^16.13.1", "react": "^16.13.1",

View File

@@ -1,3 +1,3 @@
<svg width="8" height="12" viewBox="0 0 8 12" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg width="4" height="9" viewBox="0 0 4 9" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0.721924 9.93097L4.85292 5.79997L0.721924 1.66897L1.99992 0.399973L7.39992 5.79997L1.99992 11.2L0.721924 9.93097Z" fill="#506784"/> <path d="M4 0.98056V4.5L4.00004 7.71428L4 9L1.10694e-07 4.5L4 0V0.98056Z" fill="#506784"/>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 243 B

After

Width:  |  Height:  |  Size: 190 B

View File

@@ -0,0 +1,6 @@
.warning {
background-color: var(--color-bg-warning);
color: var(--color-text-base);
font-size: 13px;
padding: 0 24px;
}

View File

@@ -31,6 +31,7 @@
--color-text-error: var(--color-red); --color-text-error: var(--color-red);
--shadow: 0 1px 2px rgba(42, 63, 95, 0.7); --shadow: 0 1px 2px rgba(42, 63, 95, 0.7);
--shadow-1: 0 2px 9px rgba(80, 103, 132, 0.2);
--border-radius-big: 5px; --border-radius-big: 5px;
--border-radius-medium: 3px; --border-radius-medium: 3px;

View File

@@ -1,6 +1,6 @@
<template> <template>
<div v-show="visible" class="chart-container"> <div v-show="visible" class="chart-container">
<div class="chart-worning" v-show="!sqlResult && visible"> <div class="warning chart-warning" v-show="!sqlResult && visible">
There is no data to build a chart. Run your sql query and make sure the result is not empty. There is no data to build a chart. Run your sql query and make sure the result is not empty.
</div> </div>
<PlotlyEditor <PlotlyEditor
@@ -95,13 +95,9 @@ export default {
.chart-container { .chart-container {
height: calc(100% - 89px); height: calc(100% - 89px);
} }
.chart-worning { .chart-warning {
background-color: var(--color-bg-warning);
height: 40px; height: 40px;
line-height: 40px; line-height: 40px;
color: var(--color-text-base);
font-size: 13px;
padding: 0 24px;
} }
.chart { .chart {
border-top: 1px solid var(--color-border); border-top: 1px solid var(--color-border);

View File

@@ -1,14 +1,13 @@
<template> <template>
<div id="dbloader-container"> <div>
<h1>Sqliteviz</h1>
<label for="assetsFieldHandle"> <label for="assetsFieldHandle">
<div id="drop-area" @dragover="dragover" @dragleave="dragleave" @drop="drop"> <div class="drop-area" @dragover="dragover" @dragleave="dragleave" @drop="drop">
<input <input
type="file" type="file"
id="assetsFieldHandle" id="assetsFieldHandle"
@change="loadDb" @change="loadDb"
ref="file" ref="file"
accept=".db" accept=".db,.sqlite,.sqlite3"
/> />
<div> <div>
Drop the database file to upload here or click to choose a file from your computer. Drop the database file to upload here or click to choose a file from your computer.
@@ -16,9 +15,6 @@
</div> </div>
</label> </label>
<div id="error" class="error"></div> <div id="error" class="error"></div>
<button id ="skip" class="secondary" @click="$router.push('/editor')">
Skip database connection for now
</button>
</div> </div>
</template> </template>
@@ -55,39 +51,27 @@ export default {
</script> </script>
<style scoped> <style scoped>
#dbloader-container {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
h1 {
color: var(--color-accent);
}
label { label {
display: inline-block; display: inline-block;
border: 1px dashed var(--color-border); border: 1px dashed var(--color-border);
padding: 8px; padding: 8px;
border-radius: var(--border-radius-big); border-radius: var(--border-radius-big);
height: 100%;
box-sizing: border-box;
} }
#drop-area { .drop-area {
width: 628px;
height: 490px;
background-color: var(--color-bg-light-3); background-color: var(--color-bg-light-3);
border-radius: var(--border-radius-big); border-radius: var(--border-radius-big);
color: var(--color-text-base); color: var(--color-text-base);
font-size: 13px; font-size: 13px;
padding: 200px 144px;
text-align: center; text-align: center;
box-sizing: border-box; box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
height: 100%;
} }
input { input {
display: none; display: none;
} }
#skip {
position: absolute;
bottom: 50px;
}
</style> </style>

View File

@@ -6,15 +6,15 @@
</div> </div>
<div> <div>
<button <button
v-if="$store.state.tabs.length > 0" v-if="currentQuery"
class="primary" class="primary"
:disabled="currentQuery && !$store.state.schema || !currentQuery.query" :disabled="currentQuery && (!$store.state.schema || !currentQuery.query)"
@click="currentQuery.execute" @click="currentQuery.execute"
> >
Run Run
</button> </button>
<button <button
v-if="$store.state.tabs.length > 0" v-if="currentQuery"
class="primary" class="primary"
:disabled="currentQuery && !currentQuery.isUnsaved" :disabled="currentQuery && !currentQuery.isUnsaved"
@click="checkQueryBeforeSave" @click="checkQueryBeforeSave"
@@ -171,6 +171,7 @@ nav {
align-items: center; align-items: center;
background-color: var(--color-bg-light); background-color: var(--color-bg-light);
border-bottom: 1px solid var(--color-border-light); border-bottom: 1px solid var(--color-border-light);
box-shadow: var(--shadow-1);
box-sizing: border-box; box-sizing: border-box;
position: fixed; position: fixed;
top: 0; top: 0;

View File

@@ -31,9 +31,9 @@
<div v-if="schemaVisible" class="schema"> <div v-if="schemaVisible" class="schema">
<table-description <table-description
v-for="table in schema" v-for="table in schema"
:key="table[0]" :key="table.name"
:name="table[0]" :name="table.name"
:sql="table[1]" :columns="table.columns"
/> />
</div> </div>
</div> </div>

View File

@@ -88,11 +88,11 @@ export default {
const translation = 'translate(-50%, -50%)' const translation = 'translate(-50%, -50%)'
if (this.horizontal) { if (this.horizontal) {
return { return {
transform: `${translation} ${this.expanded ? 'rotate(-90deg)' : 'rotate(90deg)'}` transform: `${translation} ${this.expanded ? 'rotate(90deg)' : 'rotate(-90deg)'}`
} }
} else { } else {
return { return {
transform: `${translation} ${this.expanded ? 'rotate(180deg)' : ''}` transform: `${translation} ${this.expanded ? 'rotate(0deg)' : 'rotate(180deg)'}`
} }
} }
} }
@@ -248,13 +248,23 @@ export default {
.splitpanes__splitter { .splitpanes__splitter {
touch-action: none; touch-action: none;
background-color: var(--color-bg-light-2); background-color: var(--color-bg-light);
box-sizing: border-box; box-sizing: border-box;
position: relative; position: relative;
flex-shrink: 0; flex-shrink: 0;
z-index: 1; z-index: 1;
} }
.splitpanes--horizontal > .splitpanes__splitter {
border-top: 1px solid var(--color-border-light);
border-bottom: 1px solid var(--color-border-light);
}
.splitpanes--vertical > .splitpanes__splitter {
border-left: 1px solid var(--color-border-light);
border-right: 1px solid var(--color-border-light);
}
.movable-splitter { .movable-splitter {
position: absolute; position: absolute;
background-color:rgba(162, 177, 198, 0.5); background-color:rgba(162, 177, 198, 0.5);
@@ -262,23 +272,25 @@ export default {
.splitpanes--vertical > .splitpanes__splitter, .splitpanes--vertical > .splitpanes__splitter,
.splitpanes--vertical .movable-splitter { .splitpanes--vertical .movable-splitter {
width: 3px; width: 8px;
z-index: 5; z-index: 5;
height: 100% height: 100%
} }
.splitpanes--horizontal > .splitpanes__splitter, .splitpanes--horizontal > .splitpanes__splitter,
.splitpanes--horizontal .movable-splitter { .splitpanes--horizontal .movable-splitter {
height: 3px; height: 8px;
width: 100%; width: 100%;
} }
.splitpanes__splitter .toggle-btn { .splitpanes__splitter .toggle-btn {
background-color: var(--color-bg-light-2); background-color: var(--color-border-light);
border-radius: var(--border-radius-small); border-radius: var(--border-radius-small);
border: 1px solid var(--color-border);
position: absolute; position: absolute;
top: 50%; top: 50%;
left: 50%; left: 50%;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
box-sizing: border-box;
} }
.splitpanes__splitter .toggle-btn:hover { .splitpanes__splitter .toggle-btn:hover {
@@ -286,12 +298,12 @@ export default {
} }
.splitpanes--vertical .toggle-btn { .splitpanes--vertical .toggle-btn {
height: 68px; height: 49px;
width: 15px; width: 8px;
} }
.splitpanes--horizontal .toggle-btn { .splitpanes--horizontal .toggle-btn {
width: 68px; width: 49px;
height: 15px; height: 8px;
} }
.splitpanes__splitter .toggle-btn .direction-icon { .splitpanes__splitter .toggle-btn .direction-icon {
position: absolute; position: absolute;

View File

@@ -13,6 +13,19 @@ import 'codemirror/theme/neo.css'
import 'codemirror/addon/hint/show-hint.js' import 'codemirror/addon/hint/show-hint.js'
import 'codemirror/addon/hint/show-hint.css' import 'codemirror/addon/hint/show-hint.css'
import 'codemirror/addon/hint/sql-hint.js' import 'codemirror/addon/hint/sql-hint.js'
import { debounce } from 'debounce'
const sqlHint = CM.hint.sql
CM.hint.sql = (cm, options) => {
const token = cm.getTokenAt(cm.getCursor()).string.toUpperCase()
const result = sqlHint(cm, options)
// Don't show the hint if there is only one option
// and the token is already completed with this option
if (result.list.length === 1 && result.list[0].text.toUpperCase() === token) {
result.list = []
}
return result
}
export default { export default {
name: 'SqlEditor', name: 'SqlEditor',
@@ -30,8 +43,18 @@ export default {
theme: 'neo', theme: 'neo',
lineNumbers: true, lineNumbers: true,
line: true line: true
}, }
result: null }
},
computed: {
tables () {
const tables = {}
if (this.$store.state.schema) {
this.$store.state.schema.forEach(table => {
tables[table.name] = table.columns.map(column => column.name)
})
}
return tables
} }
}, },
watch: { watch: {
@@ -40,25 +63,23 @@ export default {
} }
}, },
methods: { methods: {
onCmChange (editor) { onCmChange: debounce(function (editor) {
// Don't show autocomplete after a space or semicolon // Don't show autocomplete after a space or semicolon or in string literals
const ch = editor.getTokenAt(editor.getCursor()).string.slice(-1) const ch = editor.getTokenAt(editor.getCursor()).string.slice(-1)
if (!ch || ch === ' ' || ch === ';') { const tokenType = editor.getTokenAt(editor.getCursor()).type
if (tokenType === 'string' || !ch || ch === ' ' || ch === ';') {
return return
} }
const hintOptions = { const hintOptions = {
// tables: this.state.tables, tables: this.tables,
completeSingle: false, completeSingle: false,
completeOnSingleClick: true completeOnSingleClick: true,
alignWithWord: false
} }
// editor.hint.sql is defined when importing codemirror/addon/hint/sql-hint
// (this is mentioned in codemirror addon documentation)
// Reference the hint function imported here when including other hint addons
// or supply your own
CM.showHint(editor, CM.hint.sql, hintOptions) CM.showHint(editor, CM.hint.sql, hintOptions)
} }, 400)
} }
} }
</script> </script>
@@ -74,8 +95,6 @@ export default {
max-height: 100%; max-height: 100%;
} }
>>> .CodeMirror { >>> .CodeMirror {
border: 1px solid var(--color-border);
border-radius: var(--border-radius-big);
height: 100%; height: 100%;
max-height: 100%; max-height: 100%;
} }

View File

@@ -147,14 +147,14 @@ export default {
<style scoped> <style scoped>
.tab-content-container { .tab-content-container {
padding-top: 6px; background-color: var(--color-white);
background-color: var(--color-bg-light);
border-top: 1px solid var(--color-border-light); border-top: 1px solid var(--color-border-light);
margin-top: -1px; margin-top: -1px;
} }
#bottomPane { #bottomPane {
height: 100%; height: 100%;
background-color: var(--color-bg-light);
} }
.query-results-splitter { .query-results-splitter {
@@ -163,7 +163,6 @@ export default {
} }
.query-editor { .query-editor {
padding: 52px;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: 100%; height: 100%;

View File

@@ -27,40 +27,18 @@
</template> </template>
<script> <script>
import sqliteParser from 'sqlite-parser'
export default { export default {
name: 'TableDescription', name: 'TableDescription',
props: ['name', 'sql'], props: ['name', 'columns'],
data () { data () {
return { return {
colVisible: false colVisible: false
} }
},
computed: {
ast () {
return sqliteParser(this.sql)
},
columns () {
const columns = []
this.ast.statement[0].definition.forEach(item => {
if (item.variant === 'column') {
let type = item.datatype.variant
if (item.datatype.args) {
type = type + '(' + item.datatype.args.expression[0].value
if (item.datatype.args.expression.length === 2) {
type = type + ', ' + item.datatype.args.expression[1].value
}
type = type + ')'
}
columns.push({ name: item.name, type: type })
}
})
return columns
}
} }
} }
</script> </script>
<style scoped> <style scoped>
.table-name, .column { .table-name, .column {
margin-top: 11px; margin-top: 11px;

View File

@@ -81,6 +81,7 @@ export default {
#tabs-container { #tabs-container {
position: relative; position: relative;
height: 100%; height: 100%;
background-color: var(--color-bg-light);
} }
#tabs__header { #tabs__header {
display: flex; display: flex;
@@ -119,19 +120,11 @@ export default {
color: var(--color-text-active); color: var(--color-text-active);
font-weight: 600; font-weight: 600;
border-bottom: none; border-bottom: none;
background-color: var(--color-white);
} }
#tabs__header .tab__selected:hover { #tabs__header .tab__selected:hover {
cursor: default; cursor: default;
} }
#tabs__header .tab__selected:before {
content: '';
position: absolute;
width: 100%;
height: 5px;
background-color: var(--color-accent);
top: 0;
left: 0;
}
.close-icon { .close-icon {
margin-left: 5px; margin-left: 5px;

View File

@@ -11,6 +11,7 @@ import '@/assets/styles/buttons.css'
import '@/assets/styles/tables.css' import '@/assets/styles/tables.css'
import '@/assets/styles/dialogs.css' import '@/assets/styles/dialogs.css'
import '@/assets/styles/tooltips.css' import '@/assets/styles/tooltips.css'
import '@/assets/styles/messages.css'
Vue.use(VuePlugin) Vue.use(VuePlugin)
Vue.use(VModal) Vue.use(VModal)

View File

@@ -2,7 +2,7 @@ import Vue from 'vue'
import VueRouter from 'vue-router' import VueRouter from 'vue-router'
import Editor from '../views/Editor' import Editor from '../views/Editor'
import MyQueries from '../views/MyQueries' import MyQueries from '../views/MyQueries'
import DbUpload from '../views/DbUpload' import Home from '../views/Home'
import MainView from '../views/MainView' import MainView from '../views/MainView'
Vue.use(VueRouter) Vue.use(VueRouter)
@@ -11,7 +11,7 @@ const routes = [
{ {
path: '/', path: '/',
name: 'Welcome', name: 'Welcome',
component: DbUpload component: Home
}, },
{ {
path: '/', path: '/',

View File

@@ -1,8 +1,46 @@
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import sqliteParser from 'sqlite-parser'
Vue.use(Vuex) Vue.use(Vuex)
function getAst (sql) {
// There is a bug is sqlite-parser
// It throws an error if tokenizer has an arguments:
// https://github.com/codeschool/sqlite-parser/issues/59
const fixedSql = sql
.replace(/(?<=tokenize=.+)"tokenchars=.+"/, '')
.replace(/(?<=tokenize=.+)"remove_diacritics=.+"/, '')
.replace(/(?<=tokenize=.+)"separators=.+"/, '')
.replace(/tokenize=.+(?=(,|\)))/, 'tokenize=unicode61')
return sqliteParser(fixedSql)
}
function getColumns (sql) {
const columns = []
const ast = getAst(sql)
const columnDefinition = ast.statement[0].format === 'table'
? ast.statement[0].definition
: ast.statement[0].result.args.expression // virtual table
columnDefinition.forEach(item => {
if (item.variant === 'column' && ['identifier', 'definition'].includes(item.type)) {
let type = item.datatype ? item.datatype.variant : 'N/A'
if (item.datatype && item.datatype.args) {
type = type + '(' + item.datatype.args.expression[0].value
if (item.datatype.args.expression.length === 2) {
type = type + ', ' + item.datatype.args.expression[1].value
}
type = type + ')'
}
columns.push({ name: item.name, type: type })
}
})
return columns
}
export default new Vuex.Store({ export default new Vuex.Store({
state: { state: {
schema: null, schema: null,
@@ -16,7 +54,14 @@ export default new Vuex.Store({
}, },
mutations: { mutations: {
saveSchema (state, schema) { saveSchema (state, schema) {
state.schema = schema const parsedSchema = []
schema.forEach(item => {
parsedSchema.push({
name: item[0],
columns: getColumns(item[1])
})
})
state.schema = parsedSchema
}, },
saveDbFile (state, file) { saveDbFile (state, file) {
state.dbFile = file state.dbFile = file

View File

@@ -6,7 +6,13 @@
:after="{ size: 80, max: 100 }" :after="{ size: 80, max: 100 }"
> >
<template #left-pane> <template #left-pane>
<schema /> <schema v-if="$store.state.schema"/>
<div v-else id="empty-schema-container">
<div class="warning">
Database is not uploaded. Queries cant be run without database.
</div>
<db-upload id="db-uploader"/>
</div>
</template> </template>
<template #right-pane> <template #right-pane>
<tabs /> <tabs />
@@ -19,20 +25,42 @@
import Splitpanes from '@/components/Splitpanes' import Splitpanes from '@/components/Splitpanes'
import Schema from '@/components/Schema' import Schema from '@/components/Schema'
import Tabs from '@/components/Tabs' import Tabs from '@/components/Tabs'
import dbUpload from '@/components/DbUpload'
export default { export default {
name: 'Editor', name: 'Editor',
components: { components: {
Schema, Schema,
Splitpanes, Splitpanes,
Tabs Tabs,
dbUpload
} }
} }
</script> </script>
<style> <style scoped>
.schema-tabs-splitter { .schema-tabs-splitter {
height: 100%; height: 100%;
margin-left: 6px; background-color: var(--color-white);
}
#empty-schema-container {
display: flex;
flex-direction: column;
align-items: center;
min-width: 200px;
height: 100%;
}
#db-uploader {
flex-grow: 1;
margin: 24px;
}
.warning {
padding: 12px 24px;
}
>>>.drop-area {
padding: 0 15px;
} }
</style> </style>

70
src/views/Home.vue Normal file
View File

@@ -0,0 +1,70 @@
<template>
<div id="dbloader-container">
<h1>Sqliteviz</h1>
<db-upload />
<button id ="skip" class="secondary" @click="$router.push('/editor')">
Skip database connection for now
</button>
</div>
</template>
<script>
import dbUpload from '@/components/DbUpload'
export default {
name: 'Home',
components: { dbUpload },
methods: {
loadDb () {
this.$db.loadDb(this.$refs.file.files[0])
},
dragover (event) {
event.preventDefault()
// TODO: Add some visual stuff to show the user can drop its files
if (!event.currentTarget.classList.contains('bg-green-300')) {
event.currentTarget.classList.remove('bg-gray-100')
event.currentTarget.classList.add('bg-green-300')
}
},
dragleave (event) {
// Clean up
event.currentTarget.classList.add('bg-gray-100')
event.currentTarget.classList.remove('bg-green-300')
},
drop (event) {
event.preventDefault()
this.$refs.file.files = event.dataTransfer.files
this.loadDb()
// Clean up
event.currentTarget.classList.add('bg-gray-100')
event.currentTarget.classList.remove('bg-green-300')
}
}
}
</script>
<style scoped>
#dbloader-container {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
h1 {
color: var(--color-accent);
}
#skip {
position: absolute;
bottom: 50px;
}
>>>.drop-area {
width: 628px;
height: 490px;
padding: 0 150px;
}
</style>

View File

@@ -1,6 +1,12 @@
<template> <template>
<div> <div>
<div id="my-queries-content"> <div id="start-guide" v-if="showedQueries.length === 0">
You don't have saved queries so far.
<span class="link" @click="create">Create</span>
the one from scratch or
<label for="import-file" class="link">import</label> from a file.
</div>
<div id="my-queries-content" v-show="showedQueries.length > 0">
<div id="my-queries-toolbar"> <div id="my-queries-toolbar">
<div id="toolbar-buttons"> <div id="toolbar-buttons">
<input <input
@@ -10,11 +16,11 @@
id="import-file" id="import-file"
@change="importQueries" @change="importQueries"
/> />
<button class="toolbar"> <button class="toolbar">
<label for="import-file"> <label for="import-file">
Import Import
</label> </label>
</button> </button>
<button <button
class="toolbar" class="toolbar"
v-show="selectedQueriesCount > 0" v-show="selectedQueriesCount > 0"
@@ -244,7 +250,12 @@ export default {
}, },
methods: { methods: {
calcNameWidth () { calcNameWidth () {
this.$refs['name-th'].style = `width: ${this.$refs['name-td'][0].offsetWidth}px` const nameWidth = this.$refs['name-td'] ? this.$refs['name-td'][0].offsetWidth : 0
this.$refs['name-th'].style = `width: ${nameWidth}px`
},
create () {
this.$root.$emit('createNewQuery')
this.$router.push('/editor')
}, },
openQuery (index) { openQuery (index) {
const tab = JSON.parse(JSON.stringify(this.showedQueries[index])) const tab = JSON.parse(JSON.stringify(this.showedQueries[index]))
@@ -428,6 +439,16 @@ export default {
</script> </script>
<style scoped> <style scoped>
#start-guide {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: var(--color-text-base);
font-size: 14px;
text-align: center;
}
#my-queries-content { #my-queries-content {
padding: 52px; padding: 52px;
} }