Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import/export sql files #1913

Merged
merged 5 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/studio/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
name="modals"
multiple
/>
<dropzone />
<data-manager />
<confirmation-modal :name="$confirmModalName"/>

Check warning on line 28 in apps/studio/src/App.vue

View workflow job for this annotation

GitHub Actions / build (macos-11)

Expected a space before '/>', but not found

Check warning on line 28 in apps/studio/src/App.vue

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04)

Expected a space before '/>', but not found

Check warning on line 28 in apps/studio/src/App.vue

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Expected a space before '/>', but not found
</div>
</template>

Expand All @@ -42,12 +43,13 @@
import NotificationManager from './components/NotificationManager.vue'
import UpgradeRequiredModal from './components/common/UpgradeRequiredModal.vue'
import ConfirmationModal from '@/components/common/modals/ConfirmationModal.vue'
import Dropzone from '@/components/Dropzone.vue'

export default Vue.extend({
name: 'App',
components: {
CoreInterface, ConnectionInterface, Titlebar, AutoUpdater, NotificationManager,
StateManager, DataManager, UpgradeRequiredModal, ConfirmationModal
StateManager, DataManager, UpgradeRequiredModal, ConfirmationModal, Dropzone,
},
data() {
return {
Expand Down
4 changes: 4 additions & 0 deletions apps/studio/src/assets/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ body.theme-system {
@import './components/content-placeholders.scss';
@import './components/context-menu.scss';
@import './components/quicksearch.scss';
@import './components/dropzone.scss';
@import './vendor.scss';
@import './app/_all.scss';
@import './themes/dark/theme.scss';
Expand All @@ -20,6 +21,7 @@ body.theme-system {
@import './components/content-placeholders.scss';
@import './components/context-menu.scss';
@import './components/quicksearch.scss';
@import './components/dropzone.scss';
@import './vendor.scss';
@import './app/_all.scss';
@import './themes/light/theme.scss';
Expand All @@ -30,6 +32,7 @@ body.theme-dark {
@import './components/content-placeholders.scss';
@import './components/context-menu.scss';
@import './components/quicksearch.scss';
@import './components/dropzone.scss';
@import './vendor.scss';
@import './app/_all.scss';
@import './themes/dark/theme.scss';
Expand All @@ -40,6 +43,7 @@ body.theme-light {
@import './components/content-placeholders.scss';
@import './components/context-menu.scss';
@import './components/quicksearch.scss';
@import './components/dropzone.scss';
@import './vendor.scss';
@import './app/_all.scss';
@import './themes/light/theme.scss';
Expand Down
14 changes: 6 additions & 8 deletions apps/studio/src/assets/styles/app/sidebar/favorite-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
// height: 100%;
// display: flex;
// flex-direction: column;
&:hover {
.list-heading {
.actions {
display: flex;
}
}
}
.sidebar-list {
position: relative;
flex: 1 1 auto;
Expand Down Expand Up @@ -46,7 +39,12 @@
}
.list-heading {
.actions {
display: none;
display: flex;
x-button {
height: auto;
padding: 0;
box-shadow: none;
}
}
}
.list-title {
Expand Down
24 changes: 24 additions & 0 deletions apps/studio/src/assets/styles/components/dropzone.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.dropzone {
position: fixed;
inset: 0;
z-index: 9999;
pointer-events: none;
visibility: hidden;

&[data-dragging] {
visibility: visible;
}

.dropzone-core-tabs {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background-color: $theme-bg;
color: $theme-base;
opacity: 0.5;
font-size: 2rem;
}
}

4 changes: 4 additions & 0 deletions apps/studio/src/common/AppEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export enum AppEvent {
quickSearch = 'quickSearch',
promptLogin = 'cloud_signin',
promptQueryImport = 'cloud_q_import',
promptQueryImportFromComputer = "q_import_from_computer",
promptQueryExport = 'q_export',
promptConnectionImport = 'cloud_c_import',
toggleHideEntity = 'toggleHideEntity',
toggleHideSchema = 'toggleHideSchema',
Expand All @@ -30,6 +32,8 @@ export enum AppEvent {
upgradeModal = 'showUpgradeModal',
toggleExpandTableList = 'toggleExpandTableList',
togglePinTableList = 'togglePinTableList',
dropzoneEnter = 'dropzoneEnter',
dropzoneDrop = 'dropzoneDrop',
}

export interface RootBinding {
Expand Down
11 changes: 11 additions & 0 deletions apps/studio/src/common/dropzone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface DropzoneEnterEvent {
event: DragEvent;
files: File[];
preventDrop: () => void;
}

export interface DropzoneDropEvent {
event: DragEvent;
files: File[];
}

42 changes: 42 additions & 0 deletions apps/studio/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import _ from 'lodash';
import platformInfo from './platform_info';
import { format } from 'sql-formatter';
import { TableFilter, TableOrView, Routine } from '@/lib/db/models';
import { SettingsPlugin } from '@/plugins/SettingsPlugin';

export function having<T, U>(item: T | undefined | null, f: (T) => U, errorOnNone?: string): U | null {
if (item) return f(item)
Expand Down Expand Up @@ -87,6 +88,26 @@ export function readJSONFileSync(filename: string): any {
return JSON.parse(data);
}

export function readWebFile(file: File) {
const reader = new FileReader()
const result = new Promise<string>((resolve, reject) => {
reader.onload = () => {
resolve(reader.result as string)
}
reader.onerror = () => {
reject(reader.error)
}
reader.onabort = () => {
reject(new Error('File reading aborted'))
}
})
reader.readAsText(file)
return {
result,
abort: reader.abort,
}
}

export function createParentDirectory(filename: string): Promise<string> {
return mkdirp(path.dirname(filename))
}
Expand Down Expand Up @@ -178,3 +199,24 @@ export function entityId(schema: string, entity?: TableOrView | Routine) {
if (entity) return `${entity.entityType}.${schema}.${entity.name}`;
return `schema.${schema}`;
}

export function isFile(e: DragEvent) {
const dt = e.dataTransfer;
for (let i = 0; i < dt.types.length; i++) {
if (dt.types[i] === "Files") {
return true;
}
}
return false;
}

export async function getLastExportPath(filename?: string) {
return await SettingsPlugin.get(
"lastExportPath",
path.join(homedir(), filename)
);
}

export async function setLastExportPath(exportPath: string) {
await SettingsPlugin.set('lastExportPath', exportPath)
}
15 changes: 10 additions & 5 deletions apps/studio/src/components/ConnectionInterface.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<div class="interface connection-interface">
<div
class="interface-wrap row"
@dragover.prevent=""
@drop.prevent="maybeLoadSqlite"
>
<sidebar
class="connection-sidebar"
Expand Down Expand Up @@ -214,6 +212,7 @@ import { dialectFor } from '@shared/lib/dialects/models'
import { findClient } from '@/lib/db/clients'
import OtherDatabaseNotice from './connection/OtherDatabaseNotice.vue'
import Vue from 'vue'
import { AppEvent } from '@/common/AppEvent'

const log = rawLog.scope('ConnectionInterface')
// import ImportUrlForm from './connection/ImportUrlForm';
Expand Down Expand Up @@ -253,7 +252,12 @@ export default Vue.extend({
},
determineLabelColor() {
return this.config.labelColor == "default" ? '' : `connection-label-color-${this.config.labelColor}`
}
},
rootBindings() {
return [
{ event: AppEvent.dropzoneDrop, handler: this.maybeLoadSqlite },
azmy60 marked this conversation as resolved.
Show resolved Hide resolved
]
},
},
watch: {
workspaceId() {
Expand Down Expand Up @@ -306,16 +310,17 @@ export default Vue.extend({
expandToMin: true,
} as Split.Options)
})
this.registerHandlers(this.rootBindings)
},
beforeDestroy() {
if (this.split) {
this.split.destroy()
}
this.unregisterHandlers(this.rootBindings)
},
methods: {
maybeLoadSqlite(e) {
maybeLoadSqlite({ files }) {
// cast to an array
const files = [...e.dataTransfer.files || []]
if (!files || !files.length) return
if (!this.config) return;
// we only load the first
Expand Down