Compare commits

...

69 Commits

Author SHA1 Message Date
Jan Prochazka
f9545eaf7f CockroachDB analysis #112 2021-05-14 16:44:48 +02:00
Jan Prochazka
216ef7736b #112 fix for CockroachDB 2021-05-13 12:05:56 +02:00
Jan Prochazka
ae7697f655 v4.2.0-beta.3 2021-05-13 09:08:27 +02:00
Jan Prochazka
23225cf86b try to fix sqlite problem 2021-05-13 08:41:45 +02:00
Jan Prochazka
63ad36f758 v4.2.0-beta.2 2021-05-06 19:18:47 +02:00
Jan Prochazka
80e1563877 missing dependency 2021-05-06 19:18:34 +02:00
Jan Prochazka
3f5c7aecd7 v4.2.0-beta.1 2021-05-06 18:36:36 +02:00
Jan Prochazka
abd2492889 Merge branch 'master' into sqlite 2021-05-06 18:36:15 +02:00
Jan Prochazka
872468899d electron - open sqlite database with drag & drop or in open file menu 2021-05-06 18:33:50 +02:00
Jan Prochazka
7a008e5a9d sqlite bulk insert 2021-05-06 15:57:50 +02:00
Jan Prochazka
23940aa324 sqlite version 2021-05-06 15:27:25 +02:00
Jan Prochazka
1888de8728 sqlite stream reader 2021-05-06 15:23:45 +02:00
Jan Prochazka
615397f332 sqlite FK analyser, query runs in transaction 2021-05-06 14:11:51 +02:00
Jan Prochazka
e251459512 sqlite sync query 2021-05-06 13:32:37 +02:00
Jan Prochazka
a9c8cee08a sqlite stream 2021-05-06 12:32:54 +02:00
Jan Prochazka
1638095c98 database file label 2021-05-06 11:17:30 +02:00
Jan Prochazka
62cedd23b7 extracted getConnectionLabel functionality 2021-05-06 11:08:03 +02:00
Jan Prochazka
3d882f47a7 connection modal fix 2021-05-06 10:50:11 +02:00
Jan Prochazka
88ddc28208 scripts related to server 2021-05-06 10:34:24 +02:00
Jan Prochazka
800666f813 expand button fix 2021-05-06 09:48:07 +02:00
Jan Prochazka
0b8add848a execute command disabled, when query has not connection 2021-05-06 09:43:32 +02:00
Jan Prochazka
cd7edcb443 disconnect command (hard disconnect in electron, soft disconnect in webapp) 2021-05-06 09:34:05 +02:00
Jan Prochazka
e483fd9e99 changelog 2021-05-05 20:07:04 +02:00
Jan Prochazka
9664e6f981 v4.1.12 2021-05-05 20:05:35 +02:00
Jan Prochazka
d1429dd2a1 readme 2021-05-05 20:05:09 +02:00
Jan Prochazka
e739aed80d sqlite table analyser 2021-05-05 20:04:49 +02:00
Jan Prochazka
28e19402f3 Merge branch 'master' into sqlite 2021-05-03 21:09:41 +02:00
Jan Prochazka
45a065f391 v4.1.12-beta.2 2021-05-03 21:08:58 +02:00
Jan Prochazka
67e8eb32f7 svelte select fix 2021-05-03 21:08:45 +02:00
Jan Prochazka
5622e3af77 v4.1.12-beta.1 2021-05-03 20:41:19 +02:00
Jan Prochazka
7d34458553 fixed race condition when using SSH tunnel #110 2021-05-03 20:39:41 +02:00
Jan Prochazka
8b747796e7 Merge branch 'master' into sqlite 2021-05-03 18:43:34 +02:00
Jan Prochazka
4802c36b54 changelog 2021-05-03 18:42:04 +02:00
Jan Prochazka
988e4345d4 v4.1.11 2021-05-03 18:36:38 +02:00
Jan Prochazka
e02305879e v4.1.11-beta.2 2021-04-30 20:42:34 +02:00
Jan Prochazka
8baad56315 toolbar shows tab related commands aligned to right 2021-04-30 20:35:43 +02:00
Jan Prochazka
14bbc7b057 duplicate tab popup menu 2021-04-30 18:46:44 +02:00
Jan Prochazka
7b6ca27b66 add to favorites moved from toolbar into tab context menu 2021-04-30 18:03:34 +02:00
Jan Prochazka
38aae142ea loading structure status fix 2021-04-30 17:30:18 +02:00
Jan Prochazka
bd6c116cc0 timg safe compare token fixes #91 2021-04-30 17:21:35 +02:00
Jan Prochazka
4522c37bfa docker beta build 2021-04-29 20:47:35 +02:00
Jan Prochazka
7d789d5712 #109 all tables button in export fixed + added All collections button for nosql 2021-04-29 20:44:46 +02:00
Jan Prochazka
c4c2274488 v4.1.11-beta.1 2021-04-29 14:06:34 +02:00
Jan Prochazka
a8b71d452b ssh tunnel keyfile auth fix #106 2021-04-29 14:05:32 +02:00
Jan Prochazka
c7d69b0fb5 duplicate connection command 2021-04-29 13:25:12 +02:00
Jan Prochazka
47ea474555 settings optimalization 2021-04-29 11:28:32 +02:00
Jan Prochazka
e647ab471e ability to disable background model updates 2021-04-29 11:17:17 +02:00
Jan Prochazka
fd6524867e check & load db model in statusbar 2021-04-29 10:40:53 +02:00
Jan Prochazka
c24cc1dc72 patched svelte crash #105 2021-04-29 10:03:13 +02:00
Jan Prochazka
e3d1e4f53e fixed analysing postgre functions #105 2021-04-29 09:32:59 +02:00
Jan Prochazka
7b32424143 fix 2021-04-29 09:31:41 +02:00
Jan Prochazka
519767fd49 fixed postgres split query 2021-04-29 08:55:38 +02:00
Jan Prochazka
505ab2e075 editor theme to be added 2021-04-29 08:28:00 +02:00
Jan Prochazka
00d0c27502 handle plugin load error 2021-04-29 07:38:44 +02:00
Jan Prochazka
d171d7d785 changelog 2021-04-26 18:56:42 +02:00
Jan Prochazka
09593e0b22 changelog 2021-04-26 18:33:57 +02:00
Jan Prochazka
771ca6ad83 v4.1.10 2021-04-26 17:51:26 +02:00
Jan Prochazka
83014d3a5b v4.1.10-beta.6 2021-04-25 21:53:48 +02:00
Jan Prochazka
caa2d22dbd sqlite WIP 2021-04-25 21:53:27 +02:00
Jan Prochazka
3c089a5b81 connection modal supports file database 2021-04-25 20:38:41 +02:00
Jan Prochazka
d1bf2dbc4b sqlite plugin scaffold 2021-04-25 18:49:53 +02:00
Jan Prochazka
a8a9afc936 better display of server version 2021-04-25 12:28:18 +02:00
Jan Prochazka
d0cbd5d0a4 server version in statusbar 2021-04-25 12:08:47 +02:00
Jan Prochazka
67e1913683 select page by row_number for MS SQL 2008 #93 2021-04-25 11:48:23 +02:00
Jan Prochazka
8ff706a17f get server version 2021-04-25 10:25:16 +02:00
Jan Prochazka
08692dc63f error detail for connection errors 2021-04-25 09:00:11 +02:00
Jan Prochazka
41d85d4117 build 2021-04-24 13:23:39 +02:00
Jan Prochazka
f343d414ef v4.1.10-beta.5 2021-04-24 13:12:45 +02:00
Jan Prochazka
6cda7b2508 build 2021-04-24 13:12:00 +02:00
106 changed files with 1796 additions and 676 deletions

View File

@@ -63,6 +63,12 @@ jobs:
run: |
mkdir artifacts
cp app/dist/*.deb artifacts/dbgate-beta.deb || true
cp app/dist/*.AppImage artifacts/dbgate-beta.AppImage || true
cp app/dist/*.exe artifacts/dbgate-beta.exe || true
cp app/dist/*windows*.zip artifacts/dbgate-windows-beta.zip || true
cp app/dist/*.dmg artifacts/dbgate-beta.dmg || true
mv app/dist/*.exe artifacts/ || true
mv app/dist/*.zip artifacts/ || true
mv app/dist/*.AppImage artifacts/ || true

View File

@@ -74,7 +74,7 @@ jobs:
cp app/dist/*.deb artifacts/dbgate-latest.deb || true
cp app/dist/*.AppImage artifacts/dbgate-latest.AppImage || true
cp app/dist/*.exe artifacts/dbgate-latest.exe || true
cp app/dist/*.zip artifacts/dbgate-latest.zip || true
cp app/dist/*windows*.zip artifacts/dbgate-windows-latest.zip || true
cp app/dist/*.dmg artifacts/dbgate-latest.dmg || true
mv app/dist/*.exe artifacts/ || true

View File

@@ -0,0 +1,47 @@
name: Docker image
# on: [push]
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+'
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04]
steps:
- name: Context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Use Node.js 10.x
uses: actions/setup-node@v1
with:
node-version: 10.x
- name: yarn install
run: |
yarn install
- name: setCurrentVersion
run: |
yarn setCurrentVersion
- name: Prepare docker image
run: |
yarn run prepare:docker
- name: Build docker image
run: |
docker build ./docker -t dbgate
- name: Push docker image
run: |
docker tag dbgate dbgate/dbgate:beta
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker push dbgate/dbgate:beta

View File

@@ -1,5 +1,34 @@
# ChangeLog
### 4.1.11
- FIX: Fixed crash of API process when using SSH tunnel connection (race condition)
### 4.1.11
- FIX: fixed processing postgre query containing $$
- FIX: fixed postgre analysing procedures & functions
- FIX: patched svelte crash #105
- ADDED: ability to disbale background DB model updates
- ADDED: Duplicate connection
- ADDED: Duplicate tab
- FIX: SSH tunnel connection using keyfile auth #106
- FIX: All tables button fix in export #109
- CHANGED: Add to favorites moved from toolbar to tab context menu
- CHANGED: Toolbar design - current tab related commands are delimited
### 4.1.10
- ADDED: Default database option in connectin settings #96 #92
- FIX: Bundle size optimalization for Windows #97
- FIX: Popup menu placement on smaller displays #94
- ADDED: Browse table data with SQL Server 2008 #93
- FIX: Prevented malicious origins / DNS rebinding #91
- ADDED: Handle JSON fields in data editor (eg. jsonb field in Postgres) #90
- FIX: Fixed crash on Windows with Hyper-V #86
- ADDED: Show database server version in status bar
- ADDED: Show detailed info about error, when connect to database fails
- ADDED: Portable ZIP distribution for Windows #84
### 4.1.9
- FIX: Incorrect row count info in query result #83
### 4.1.1
- CHANGED: Default plugins are now part of installation
### 4.1.0

View File

@@ -1,4 +1,5 @@
[![NPM version](https://img.shields.io/npm/v/dbgate.svg)](https://www.npmjs.com/package/dbgate)
![GitHub All Releases](https://img.shields.io/github/downloads/dbgate/dbgate/total)
[![dbgate](https://snapcraft.io/dbgate/badge.svg)](https://snapcraft.io/dbgate)
[![dbgate](https://snapcraft.io/dbgate/trending.svg?name=0)](https://snapcraft.io/dbgate)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

View File

@@ -5,6 +5,7 @@
"author": "Jan Prochazka <jenasoft.database@gmail.com>",
"description": "Opensource database administration tool",
"dependencies": {
"better-sqlite3-with-prebuilds": "^7.1.8",
"electron-log": "^4.3.1",
"electron-store": "^5.1.1",
"electron-updater": "^4.3.5"

View File

@@ -60,6 +60,11 @@
dependencies:
"@types/node" "*"
"@types/integer@latest":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/integer/-/integer-4.0.0.tgz#3b778715df72d2cf8ba73bad27bd9d830907f944"
integrity sha512-2U1i6bIRiqizl6O+ETkp2HhUZIxg7g+burUabh9tzGd0qcszfNaFRaY9bGNlQKgEU7DCsH5qMajRDW5QamWQbw==
"@types/node@*":
version "13.9.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.9.1.tgz#96f606f8cd67fb018847d9b61e93997dabdefc72"
@@ -232,6 +237,23 @@ base64-js@^1.3.1:
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==
better-sqlite3-with-prebuilds@^7.1.8:
version "7.1.8"
resolved "https://registry.yarnpkg.com/better-sqlite3-with-prebuilds/-/better-sqlite3-with-prebuilds-7.1.8.tgz#3090c478fe9b60e74ce053a76807b189784f62d7"
integrity sha512-trwg1qhN91cPYEB8D2K0KVHIsMsiAnxKx6/syfQ7rLrtD+zOS3fqJq4VGszMF+OuYAZJNAR4oLsikys3YW/6aA==
dependencies:
"@types/integer" latest
bindings "^1.5.0"
prebuild-install "^6.0.1"
tar "^6.1.0"
bindings@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==
dependencies:
file-uri-to-path "1.0.0"
bl@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/bl/-/bl-4.0.3.tgz#12d6287adc29080e22a705e5764b2a9522cdc489"
@@ -369,6 +391,11 @@ chownr@^1.1.1:
resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.4.tgz#6fc9d7b42d32a583596337666e7d08084da2cc6b"
integrity sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==
chownr@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/chownr/-/chownr-2.0.0.tgz#15bfbe53d2eab4cf70f18a8cd68ebe5b3cb1dece"
integrity sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==
chromium-pickle-js@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/chromium-pickle-js/-/chromium-pickle-js-0.2.0.tgz#04a106672c18b085ab774d983dfa3ea138f22205"
@@ -815,6 +842,11 @@ fd-slicer@~1.0.1:
dependencies:
pend "~1.2.0"
file-uri-to-path@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==
filelist@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/filelist/-/filelist-1.0.1.tgz#f10d1a3ae86c1694808e8f20906f43d4c9132dbb"
@@ -853,6 +885,13 @@ fs-extra@^9.0.1:
jsonfile "^6.0.1"
universalify "^1.0.0"
fs-minipass@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-2.1.0.tgz#7f5036fdbf12c63c169190cbe4199c852271f9fb"
integrity sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==
dependencies:
minipass "^3.0.0"
fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -1295,6 +1334,21 @@ minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5:
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
minipass@^3.0.0:
version "3.1.3"
resolved "https://registry.yarnpkg.com/minipass/-/minipass-3.1.3.tgz#7d42ff1f39635482e15f9cdb53184deebd5815fd"
integrity sha512-Mgd2GdMVzY+x3IJ+oHnVM+KG3lA5c8tnabyJKmHSaG2kAGpudxuOf8ToDkhumF7UzME7DecbQE9uOZhNm7PuJg==
dependencies:
yallist "^4.0.0"
minizlib@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/minizlib/-/minizlib-2.1.2.tgz#e90d3466ba209b932451508a11ce3d3632145931"
integrity sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==
dependencies:
minipass "^3.0.0"
yallist "^4.0.0"
mkdirp-classic@^0.5.2, mkdirp-classic@^0.5.3:
version "0.5.3"
resolved "https://registry.yarnpkg.com/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz#fa10c9115cc6d8865be221ba47ee9bed78601113"
@@ -1307,6 +1361,11 @@ mkdirp@0.5.1, mkdirp@^0.5.1:
dependencies:
minimist "0.0.8"
mkdirp@^1.0.3:
version "1.0.4"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
@@ -1335,6 +1394,13 @@ napi-build-utils@^1.0.1:
resolved "https://registry.yarnpkg.com/napi-build-utils/-/napi-build-utils-1.0.2.tgz#b1fddc0b2c46e380a0b7a76f984dd47c41a13806"
integrity sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==
node-abi@^2.21.0:
version "2.26.0"
resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-2.26.0.tgz#355d5d4bc603e856f74197adbf3f5117a396ba40"
integrity sha512-ag/Vos/mXXpWLLAYWsAoQdgS+gW7IwvgMLOgqopm/DbzAjazLltzgzpVMsFlgmo9TzG5hGXeaBZx2AI731RIsQ==
dependencies:
semver "^5.4.1"
node-abi@^2.7.0:
version "2.19.3"
resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-2.19.3.tgz#252f5dcab12dad1b5503b2d27eddd4733930282d"
@@ -1509,6 +1575,26 @@ prebuild-install@^6.0.0:
tunnel-agent "^0.6.0"
which-pm-runs "^1.0.0"
prebuild-install@^6.0.1:
version "6.1.2"
resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-6.1.2.tgz#6ce5fc5978feba5d3cbffedca0682b136a0b5bff"
integrity sha512-PzYWIKZeP+967WuKYXlTOhYBgGOvTRSfaKI89XnfJ0ansRAH7hDU45X+K+FZeI1Wb/7p/NnuctPH3g0IqKUuSQ==
dependencies:
detect-libc "^1.0.3"
expand-template "^2.0.3"
github-from-package "0.0.0"
minimist "^1.2.3"
mkdirp-classic "^0.5.3"
napi-build-utils "^1.0.1"
node-abi "^2.21.0"
noop-logger "^0.1.1"
npmlog "^4.0.1"
pump "^3.0.0"
rc "^1.2.7"
simple-get "^3.0.3"
tar-fs "^2.0.0"
tunnel-agent "^0.6.0"
prepend-http@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
@@ -1944,6 +2030,18 @@ tar-stream@^2.1.4:
inherits "^2.0.3"
readable-stream "^3.1.1"
tar@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/tar/-/tar-6.1.0.tgz#d1724e9bcc04b977b18d5c573b333a2207229a83"
integrity sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==
dependencies:
chownr "^2.0.0"
fs-minipass "^2.0.0"
minipass "^3.0.0"
minizlib "^2.1.1"
mkdirp "^1.0.3"
yallist "^4.0.0"
temp-file@^3.3.7:
version "3.3.7"
resolved "https://registry.yarnpkg.com/temp-file/-/temp-file-3.3.7.tgz#686885d635f872748e384e871855958470aeb18a"

View File

@@ -5,6 +5,7 @@ let fillContent = '';
if (process.platform == 'win32') {
fillContent += `content.msnodesqlv8 = () => require('msnodesqlv8');`;
}
fillContent += `content['better-sqlite3-with-prebuilds'] = () => require('better-sqlite3-with-prebuilds');`;
const getContent = (empty) => `
// this file is generated automatically by script fillNativeModules.js, do not edit it manually

View File

@@ -1,6 +1,6 @@
{
"private": true,
"version": "4.1.10-beta.4",
"version": "4.2.0-beta.3",
"name": "dbgate-all",
"workspaces": [
"packages/*",

View File

@@ -19,6 +19,7 @@
"dependencies": {
"async-lock": "^1.2.4",
"axios": "^0.19.0",
"better-sqlite3-with-prebuilds": "^7.1.8",
"body-parser": "^1.19.0",
"bufferutil": "^4.0.1",
"byline": "^5.0.0",

View File

@@ -9,6 +9,16 @@ const currentVersion = require('../currentVersion');
const platformInfo = require('../utility/platformInfo');
module.exports = {
settingsValue: {},
async _init() {
try {
this.settingsValue = JSON.parse(await fs.readFile(path.join(datadir(), 'settings.json'), { encoding: 'utf-8' }));
} catch (err) {
this.settingsValue = {};
}
},
get_meta: 'get',
async get() {
// const toolbarButtons = process.env.TOOLBAR;
@@ -47,23 +57,19 @@ module.exports = {
getSettings_meta: 'get',
async getSettings() {
try {
return JSON.parse(await fs.readFile(path.join(datadir(), 'settings.json'), { encoding: 'utf-8' }));
} catch (err) {
return {};
}
return this.settingsValue;
},
updateSettings_meta: 'post',
async updateSettings(values) {
if (!hasPermission(`settings/change`)) return false;
const oldSettings = await this.getSettings();
try {
const updated = {
...oldSettings,
...this.settingsValue,
...values,
};
await fs.writeFile(path.join(datadir(), 'settings.json'), JSON.stringify(updated, undefined, 2));
this.settingsValue = updated;
socket.emitChanged(`settings-changed`);
return updated;
} catch (err) {

View File

@@ -4,6 +4,7 @@ const socket = require('../utility/socket');
const { fork } = require('child_process');
const { DatabaseAnalyser } = require('dbgate-tools');
const { handleProcessCommunication } = require('../utility/processComm');
const config = require('./config');
module.exports = {
/** @type {import('dbgate-types').OpenedDatabaseConnection[]} */
@@ -17,6 +18,13 @@ module.exports = {
existing.structure = structure;
socket.emitChanged(`database-structure-changed-${conid}-${database}`);
},
handle_version(conid, database, { version }) {
const existing = this.opened.find(x => x.conid == conid && x.database == database);
if (!existing) return;
existing.serverVersion = version;
socket.emitChanged(`database-server-version-changed-${conid}-${database}`);
},
handle_error(conid, database, props) {
const { error } = props;
console.log(`Error in database connection ${conid}, database ${database}: ${error}`);
@@ -51,6 +59,7 @@ module.exports = {
database,
subprocess,
structure: lastClosed ? lastClosed.structure : DatabaseAnalyser.createEmptyStructure(),
serverVersion: lastClosed ? lastClosed.serverVersion : null,
connection,
status: { name: 'pending' },
};
@@ -71,6 +80,7 @@ module.exports = {
msgtype: 'connect',
connection: { ...connection, database },
structure: lastClosed ? lastClosed.structure : null,
globalSettings: config.settingsValue,
});
return newOpened;
},
@@ -139,8 +149,8 @@ module.exports = {
},
refresh_meta: 'post',
async refresh({ conid, database }) {
this.close(conid, database);
async refresh({ conid, database, keepOpen }) {
if (!keepOpen) this.close(conid, database);
await this.ensureOpened(conid, database);
return { status: 'ok' };
@@ -163,6 +173,12 @@ module.exports = {
}
},
disconnect_meta: 'post',
async disconnect({ conid, database }) {
await this.close(conid, database, true);
return { status: 'ok' };
},
structure_meta: 'get',
async structure({ conid, database }) {
const opened = await this.ensureOpened(conid, database);
@@ -175,6 +191,12 @@ module.exports = {
// };
},
serverVersion_meta: 'get',
async serverVersion({ conid, database }) {
const opened = await this.ensureOpened(conid, database);
return opened.serverVersion;
},
sqlPreview_meta: 'post',
async sqlPreview({ conid, database, objects, options }) {
// wait for structure

View File

@@ -64,19 +64,23 @@ module.exports = {
const res = [];
for (const packageName of _.union(files1, files2)) {
if (!/^dbgate-plugin-.*$/.test(packageName)) continue;
const isPackaged = files1.includes(packageName);
const manifest = await fs
.readFile(path.join(isPackaged ? packagedPluginsDir() : pluginsdir(), packageName, 'package.json'), {
encoding: 'utf-8',
})
.then(x => JSON.parse(x));
const readmeFile = path.join(isPackaged ? packagedPluginsDir() : pluginsdir(), packageName, 'README.md');
// @ts-ignore
if (await fs.exists(readmeFile)) {
manifest.readme = await fs.readFile(readmeFile, { encoding: 'utf-8' });
try {
const isPackaged = files1.includes(packageName);
const manifest = await fs
.readFile(path.join(isPackaged ? packagedPluginsDir() : pluginsdir(), packageName, 'package.json'), {
encoding: 'utf-8',
})
.then(x => JSON.parse(x));
const readmeFile = path.join(isPackaged ? packagedPluginsDir() : pluginsdir(), packageName, 'README.md');
// @ts-ignore
if (await fs.exists(readmeFile)) {
manifest.readme = await fs.readFile(readmeFile, { encoding: 'utf-8' });
}
manifest.isPackaged = isPackaged;
res.push(manifest);
} catch (err) {
console.log(`Skipped plugin ${packageName}, error:`, err.message);
}
manifest.isPackaged = isPackaged;
res.push(manifest);
}
return res;
},

View File

@@ -5,6 +5,7 @@ const _ = require('lodash');
const AsyncLock = require('async-lock');
const { handleProcessCommunication } = require('../utility/processComm');
const lock = new AsyncLock();
const config = require('./config');
module.exports = {
opened: [],
@@ -17,6 +18,12 @@ module.exports = {
existing.databases = databases;
socket.emitChanged(`database-list-changed-${conid}`);
},
handle_version(conid, { version }) {
const existing = this.opened.find(x => x.conid == conid);
if (!existing) return;
existing.version = version;
socket.emitChanged(`server-version-changed-${conid}`);
},
handle_status(conid, { status }) {
const existing = this.opened.find(x => x.conid == conid);
if (!existing) return;
@@ -59,7 +66,7 @@ module.exports = {
if (newOpened.disconnected) return;
this.close(conid, false);
});
subprocess.send({ msgtype: 'connect', ...connection });
subprocess.send({ msgtype: 'connect', ...connection, globalSettings: config.settingsValue });
return newOpened;
});
return res;
@@ -79,12 +86,24 @@ module.exports = {
}
},
disconnect_meta: 'post',
async disconnect({ conid }) {
await this.close(conid, true);
return { status: 'ok' };
},
listDatabases_meta: 'get',
async listDatabases({ conid }) {
const opened = await this.ensureOpened(conid);
return opened.databases;
},
version_meta: 'get',
async version({ conid }) {
const opened = await this.ensureOpened(conid);
return opened.version;
},
serverStatus_meta: 'get',
async serverStatus() {
return {
@@ -110,8 +129,8 @@ module.exports = {
},
refresh_meta: 'post',
async refresh({ conid }) {
this.close(conid);
async refresh({ conid, keepOpen }) {
if (!keepOpen) this.close(conid);
await this.ensureOpened(conid);
return { status: 'ok' };

View File

@@ -31,6 +31,7 @@ const scheduler = require('./controllers/scheduler');
const { rundir } = require('./utility/directories');
const platformInfo = require('./utility/platformInfo');
const processArgs = require('./utility/processArgs');
const timingSafeCheckToken = require('./utility/timingSafeCheckToken');
let authorization = null;
let checkLocalhostOrigin = null;
@@ -56,7 +57,7 @@ function start() {
}
app.use(function (req, res, next) {
if (authorization && req.headers.authorization != authorization) {
if (authorization && !timingSafeCheckToken(req.headers.authorization, authorization)) {
return res.status(403).json({ error: 'Not authorized!' });
}
if (checkLocalhostOrigin) {

View File

@@ -2,6 +2,25 @@ const childProcessChecker = require('../utility/childProcessChecker');
const requireEngineDriver = require('../utility/requireEngineDriver');
const connectUtility = require('../utility/connectUtility');
const { handleProcessCommunication } = require('../utility/processComm');
const _ = require('lodash');
function pickSafeConnectionInfo(connection) {
return _.mapValues(connection, (v, k) => {
if (k == 'engine' || k == 'port' || k == 'authType' || k == 'sshMode' || k == 'passwordMode') return v;
if (v === null || v === true || v === false) return v;
if (v) return '***';
return undefined;
});
}
const formatErrorDetail = (e, connection) => `${e.stack}
Error JSON: ${JSON.stringify(e, undefined, 2)}
Connection: ${JSON.stringify(pickSafeConnectionInfo(connection), undefined, 2)}
Platform: ${process.platform}
`;
function start() {
childProcessChecker();
@@ -14,7 +33,11 @@ function start() {
process.send({ msgtype: 'connected', ...res });
} catch (e) {
console.error(e);
process.send({ msgtype: 'error', error: e.message });
process.send({
msgtype: 'error',
error: e.message,
detail: formatErrorDetail(e, connection),
});
}
});
}

View File

@@ -1,5 +1,6 @@
const stableStringify = require('json-stable-stringify');
const childProcessChecker = require('../utility/childProcessChecker');
const { extractBoolSettingsValue, extractIntSettingsValue } = require('dbgate-tools');
const requireEngineDriver = require('../utility/requireEngineDriver');
const connectUtility = require('../utility/connectUtility');
const { handleProcessCommunication } = require('../utility/processComm');
@@ -29,6 +30,7 @@ async function checkedAsyncCall(promise) {
async function handleFullRefresh() {
const driver = requireEngineDriver(storedConnection);
setStatusName('loadStructure');
analysedStructure = await checkedAsyncCall(driver.analyseFull(systemConnection));
process.send({ msgtype: 'structure', structure: analysedStructure });
setStatusName('ok');
@@ -36,6 +38,7 @@ async function handleFullRefresh() {
async function handleIncrementalRefresh() {
const driver = requireEngineDriver(storedConnection);
setStatusName('checkStructure');
const newStructure = await checkedAsyncCall(driver.analyseIncremental(systemConnection, analysedStructure));
if (newStructure != null) {
analysedStructure = newStructure;
@@ -56,20 +59,34 @@ function setStatusName(name) {
setStatus({ name });
}
async function handleConnect({ connection, structure }) {
async function readVersion() {
const driver = requireEngineDriver(storedConnection);
const version = await driver.getVersion(systemConnection);
process.send({ msgtype: 'version', version });
}
async function handleConnect({ connection, structure, globalSettings }) {
storedConnection = connection;
lastPing = new Date().getTime();
if (!structure) setStatusName('pending');
const driver = requireEngineDriver(storedConnection);
systemConnection = await checkedAsyncCall(connectUtility(driver, storedConnection));
readVersion();
if (structure) {
analysedStructure = structure;
handleIncrementalRefresh();
} else {
handleFullRefresh();
}
setInterval(handleIncrementalRefresh, 30 * 1000);
if (extractBoolSettingsValue(globalSettings, 'connection.autoRefresh', true)) {
setInterval(
handleIncrementalRefresh,
extractIntSettingsValue(globalSettings, 'connection.autoRefreshInterval', 30, 3, 3600) * 1000
);
}
for (const [resolve] of afterConnectCallbacks) {
resolve();
}

View File

@@ -1,4 +1,5 @@
const stableStringify = require('json-stable-stringify');
const { extractBoolSettingsValue, extractIntSettingsValue } = require('dbgate-tools');
const childProcessChecker = require('../utility/childProcessChecker');
const requireEngineDriver = require('../utility/requireEngineDriver');
const { decryptConnection } = require('../utility/crypting');
@@ -31,6 +32,12 @@ async function handleRefresh() {
}
}
async function readVersion() {
const driver = requireEngineDriver(storedConnection);
const version = await driver.getVersion(systemConnection);
process.send({ msgtype: 'version', version });
}
function setStatus(status) {
const statusString = stableStringify(status);
if (lastStatus != statusString) {
@@ -45,14 +52,18 @@ function setStatusName(name) {
async function handleConnect(connection) {
storedConnection = connection;
const { globalSettings } = storedConnection;
setStatusName('pending');
lastPing = new Date().getTime();
const driver = requireEngineDriver(storedConnection);
try {
systemConnection = await connectUtility(driver, storedConnection);
readVersion();
handleRefresh();
setInterval(handleRefresh, 30 * 1000);
if (extractBoolSettingsValue(globalSettings, 'connection.autoRefresh', true)) {
setInterval(handleRefresh, extractIntSettingsValue(globalSettings, 'connection.autoRefreshInterval', 30, 5, 3600) * 1000);
}
} catch (err) {
setStatus({
name: 'error',

View File

@@ -4,6 +4,8 @@ const portfinder = require('portfinder');
const stableStringify = require('json-stable-stringify');
const _ = require('lodash');
const platformInfo = require('./platformInfo');
const AsyncLock = require('async-lock');
const lock = new AsyncLock();
const sshConnectionCache = {};
const sshTunnelCache = {};
@@ -34,7 +36,7 @@ async function getSshConnection(connection) {
password: connection.sshMode == 'userPassword' ? connection.sshPassword : undefined,
agentSocket: connection.sshMode == 'agent' ? platformInfo.sshAuthSock : undefined,
privateKey:
connection.sshMode == 'keyFile' && connection.sshKeyFile ? await fs.readFile(connection.sshKeyFile) : undefined,
connection.sshMode == 'keyFile' && connection.sshKeyfile ? await fs.readFile(connection.sshKeyfile) : undefined,
skipAutoPrivateKey: true,
noReadline: true,
};
@@ -45,36 +47,43 @@ async function getSshConnection(connection) {
}
async function getSshTunnel(connection) {
const sshConn = await getSshConnection(connection);
const tunnelCacheKey = stableStringify(_.pick(connection, TUNNEL_FIELDS));
if (sshTunnelCache[tunnelCacheKey]) return sshTunnelCache[tunnelCacheKey];
const localPort = await portfinder.getPortPromise({ port: 10000, stopPort: 60000 });
// workaround for `getPortPromise` not releasing the port quickly enough
await new Promise(resolve => setTimeout(resolve, 500));
const tunnelConfig = {
fromPort: localPort,
toPort: connection.port,
toHost: connection.server,
};
try {
const tunnel = await sshConn.forward(tunnelConfig);
console.log(
`Created SSH tunnel to ${connection.sshHost}-${connection.server}:${connection.port}, using local port ${localPort}`
);
return await lock.acquire(tunnelCacheKey, async () => {
const sshConn = await getSshConnection(connection);
if (sshTunnelCache[tunnelCacheKey]) return sshTunnelCache[tunnelCacheKey];
sshTunnelCache[tunnelCacheKey] = {
state: 'ok',
localPort,
const localPort = await portfinder.getPortPromise({ port: 10000, stopPort: 60000 });
// workaround for `getPortPromise` not releasing the port quickly enough
await new Promise(resolve => setTimeout(resolve, 500));
const tunnelConfig = {
fromPort: localPort,
toPort: connection.port,
toHost: connection.server,
};
return sshTunnelCache[tunnelCacheKey];
} catch (err) {
// error is not cached
return {
state: 'error',
message: err.message,
};
}
try {
console.log(
`Creating SSH tunnel to ${connection.sshHost}-${connection.server}:${connection.port}, using local port ${localPort}`
);
const tunnel = await sshConn.forward(tunnelConfig);
console.log(
`Created SSH tunnel to ${connection.sshHost}-${connection.server}:${connection.port}, using local port ${localPort}`
);
sshTunnelCache[tunnelCacheKey] = {
state: 'ok',
localPort,
};
return sshTunnelCache[tunnelCacheKey];
} catch (err) {
// error is not cached
return {
state: 'error',
message: err.message,
};
}
});
}
module.exports = {

View File

@@ -0,0 +1,9 @@
const crypto = require('crypto');
function timingSafeCheckToken(a, b) {
if (!a || !b) return false;
if (a.length != b.length) return false;
return crypto.timingSafeEqual(Buffer.from(a), Buffer.from(b));
}
module.exports = timingSafeCheckToken;

View File

@@ -1,6 +1,14 @@
import _ from 'lodash';
import { GridConfig, GridCache, GridConfigColumns, createGridCache, GroupFunc } from './GridConfig';
import { ForeignKeyInfo, TableInfo, ColumnInfo, EngineDriver, NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
import {
ForeignKeyInfo,
TableInfo,
ColumnInfo,
EngineDriver,
NamedObjectInfo,
DatabaseInfo,
SqlDialect,
} from 'dbgate-types';
import { parseFilter, getFilterType, getFilterValueExpression } from 'dbgate-filterparser';
import { filterName } from './filterName';
import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet';
@@ -12,6 +20,7 @@ export class FormViewDisplay {
isLoadedCorrectly = true;
columns: DisplayColumn[];
public baseTable: TableInfo;
dialect: SqlDialect;
constructor(
public config: GridConfig,
@@ -19,8 +28,11 @@ export class FormViewDisplay {
public cache: GridCache,
protected setCache: ChangeCacheFunc,
public driver?: EngineDriver,
public dbinfo: DatabaseInfo = null
) {}
public dbinfo: DatabaseInfo = null,
public serverVersion = null
) {
this.dialect = (driver?.dialectByVersion && driver?.dialectByVersion(serverVersion)) || driver?.dialect;
}
addFilterColumn(column) {
if (!column) return;

View File

@@ -8,6 +8,7 @@ import {
NamedObjectInfo,
DatabaseInfo,
CollectionInfo,
SqlDialect,
} from 'dbgate-types';
import { parseFilter, getFilterType } from 'dbgate-filterparser';
import { filterName } from './filterName';
@@ -60,8 +61,12 @@ export abstract class GridDisplay {
public cache: GridCache,
protected setCache: ChangeCacheFunc,
public driver?: EngineDriver,
public dbinfo: DatabaseInfo = null
) {}
public dbinfo: DatabaseInfo = null,
public serverVersion = null
) {
this.dialect = (driver?.dialectByVersion && driver?.dialectByVersion(serverVersion)) || driver?.dialect;
}
dialect: SqlDialect;
columns: DisplayColumn[];
baseTable?: TableInfo;
baseCollection?: CollectionInfo;
@@ -460,12 +465,75 @@ export abstract class GridDisplay {
return select;
}
getRowNumberOverSelect(select: Select, offset: number, count: number): Select {
const innerSelect: Select = {
commandType: 'select',
from: select.from,
where: select.where,
columns: [
...select.columns,
{
alias: '_rowNumber',
exprType: 'rowNumber',
orderBy: select.orderBy
? select.orderBy.map(x =>
x.exprType != 'column'
? x
: x.source
? x
: {
...x,
source: { alias: 'basetbl' },
}
)
: [
{
...select.columns[0],
direction: 'ASC',
},
],
},
],
};
const res: Select = {
commandType: 'select',
selectAll: true,
from: {
subQuery: innerSelect,
alias: '_RowNumberResult',
},
where: {
conditionType: 'between',
expr: {
exprType: 'column',
columnName: '_RowNumber',
source: {
alias: '_RowNumberResult',
},
},
left: {
exprType: 'value',
value: offset + 1,
},
right: {
exprType: 'value',
value: offset + count,
},
},
};
return res;
}
getPageQuery(offset: number, count: number) {
if (!this.driver) return null;
const select = this.createSelect();
let select = this.createSelect();
if (!select) return null;
if (this.driver.dialect.rangeSelect) select.range = { offset: offset, limit: count };
else if (this.driver.dialect.limitSelect) select.topRecords = count;
if (this.dialect.rangeSelect) select.range = { offset: offset, limit: count };
else if (this.dialect.rowNumberOverPaging && offset > 0)
select = this.getRowNumberOverSelect(select, offset, count);
else if (this.dialect.limitSelect) select.topRecords = count;
const sql = treeToSql(this.driver, select, dumpSqlSelect);
return sql;
}

View File

@@ -29,9 +29,10 @@ export class TableFormViewDisplay extends FormViewDisplay {
cache: GridCache,
setCache: ChangeCacheFunc,
dbinfo: DatabaseInfo,
displayOptions
displayOptions,
serverVersion
) {
super(config, setConfig, cache, setCache, driver, dbinfo);
super(config, setConfig, cache, setCache, driver, dbinfo, serverVersion);
this.gridDisplay = new TableGridDisplay(
tableName,
driver,
@@ -40,7 +41,8 @@ export class TableFormViewDisplay extends FormViewDisplay {
cache,
setCache,
dbinfo,
displayOptions
displayOptions,
serverVersion
);
this.gridDisplay.addAllExpandedColumnsToSelected = true;

View File

@@ -18,9 +18,10 @@ export class TableGridDisplay extends GridDisplay {
cache: GridCache,
setCache: ChangeCacheFunc,
dbinfo: DatabaseInfo,
public displayOptions: any
public displayOptions: any,
serverVersion
) {
super(config, setConfig, cache, setCache, driver, dbinfo);
super(config, setConfig, cache, setCache, driver, dbinfo, serverVersion);
this.table = this.findTable(tableName);
if (!this.table) {

View File

@@ -10,9 +10,10 @@ export class ViewGridDisplay extends GridDisplay {
config: GridConfig,
setConfig: ChangeConfigFunc,
cache: GridCache,
setCache: ChangeCacheFunc
setCache: ChangeCacheFunc,
serverVersion
) {
super(config, setConfig, cache, setCache, driver);
super(config, setConfig, cache, setCache, driver, serverVersion);
this.columns = this.getDisplayColumns(view);
this.filterable = true;
this.sortable = true;

View File

@@ -62,5 +62,12 @@ export function dumpSqlCondition(dmp: SqlDumper, condition: Condition) {
dumpSqlSelect(dmp, condition.subQuery);
dmp.put(')');
break;
case 'between':
dumpSqlExpression(dmp, condition.expr);
dmp.put(' ^between ');
dumpSqlExpression(dmp, condition.left);
dmp.put(' ^and ');
dumpSqlExpression(dmp, condition.right);
break;
}
}

View File

@@ -38,5 +38,14 @@ export function dumpSqlExpression(dmp: SqlDumper, expr: Expression) {
case 'transform':
dmp.transform(expr.transform, () => dumpSqlExpression(dmp, expr.expr));
break;
case 'rowNumber':
dmp.put(" ^row_number() ^over (^order ^by ");
dmp.putCollection(', ', expr.orderBy, x => {
dumpSqlExpression(dmp, x);
dmp.put(' %k', x.direction);
});
dmp.put(")");
break;
}
}

View File

@@ -92,6 +92,13 @@ export interface NotExistsCondition {
subQuery: Select;
}
export interface BetweenCondition {
conditionType: 'between';
expr: Expression;
left: Expression;
right: Expression;
}
export type Condition =
| BinaryCondition
| NotCondition
@@ -99,7 +106,8 @@ export type Condition =
| CompoudCondition
| LikeCondition
| ExistsCondition
| NotExistsCondition;
| NotExistsCondition
| BetweenCondition;
export interface Source {
name?: NamedObjectInfo;
@@ -153,13 +161,19 @@ export interface TranformExpression {
transform: TransformType;
}
export interface RowNumberExpression {
exprType: 'rowNumber';
orderBy: OrderByExpression[];
}
export type Expression =
| ColumnRefExpression
| ValueExpression
| PlaceholderExpression
| RawExpression
| CallExpression
| TranformExpression;
| TranformExpression
| RowNumberExpression;
export type OrderByExpression = Expression & { direction: 'ASC' | 'DESC' };
export type ResultField = Expression & { alias?: string };

View File

@@ -71,6 +71,17 @@ export class DatabaseAnalyser {
// }
}
getRequestedObjectPureNames(objectTypeField, allPureNames) {
if (this.singleObjectFilter) {
const { typeField, pureName } = this.singleObjectFilter;
if (typeField == objectTypeField) return [pureName];
}
if (this.modifications) {
return this.modifications.filter(x => x.objectTypeField == objectTypeField).map(x => x.newName.pureName);
}
return allPureNames;
}
// findObjectById(id) {
// return this.structure.tables.find((x) => x.objectId == id);
// }

View File

@@ -24,7 +24,10 @@ export const driverBase = {
const analyser = new this.analyserClass(pool, this);
analyser.singleObjectFilter = { ...name, typeField };
const res = await analyser.fullAnalysis();
return res.tables[0];
if (res[typeField].length == 1) return res[typeField][0];
const obj = res[typeField].find(x => x.pureName == name.pureName && x.schemaName == name.schemaName);
// console.log('FIND', name, obj);
return obj;
},
analyseSingleTable(pool, name) {
return this.analyseSingleObject(pool, name, 'tables');

View File

@@ -7,6 +7,6 @@ export * from './DatabaseAnalyser';
export * from './driverBase';
export * from './SqlDumper';
export * from './testPermission';
export * from './splitPostgresQuery';
export * from './SqlGenerator';
export * from './structureTools';
export * from './settingsExtractors';

View File

@@ -0,0 +1,20 @@
import _ from 'lodash';
export function extractIntSettingsValue(settings, name, defaultValue, min = null, max = null) {
const parsed = parseInt(settings[name]);
if (_.isNaN(parsed)) {
return defaultValue;
}
if (_.isNumber(parsed)) {
if (min != null && parsed < min) return min;
if (max != null && parsed > max) return max;
return parsed;
}
return defaultValue;
}
export function extractBoolSettingsValue(settings, name, defaultValue) {
const res = settings[name];
if (res == null) return defaultValue;
return !!res;
}

View File

@@ -1,292 +0,0 @@
const SINGLE_QUOTE = "'";
const DOUBLE_QUOTE = '"';
// const BACKTICK = '`';
const DOUBLE_DASH_COMMENT_START = '--';
const HASH_COMMENT_START = '#';
const C_STYLE_COMMENT_START = '/*';
const SEMICOLON = ';';
const LINE_FEED = '\n';
const DELIMITER_KEYWORD = 'DELIMITER';
export interface SplitOptions {
multipleStatements?: boolean;
retainComments?: boolean;
}
interface SqlStatement {
value: string;
supportMulti: boolean;
}
interface SplitExecutionContext extends Required<SplitOptions> {
unread: string;
currentDelimiter: string;
currentStatement: SqlStatement;
output: SqlStatement[];
}
interface FindExpResult {
expIndex: number;
exp: string | null;
nextIndex: number;
}
const regexEscapeSetRegex = /[-/\\^$*+?.()|[\]{}]/g;
const singleQuoteStringEndRegex = /(?<!\\)'/;
const doubleQuoteStringEndRegex = /(?<!\\)"/;
// const backtickQuoteEndRegex = /(?<!`)`(?!`)/;
const doubleDashCommentStartRegex = /--[ \f\n\r\t\v]/;
const cStyleCommentStartRegex = /\/\*/;
const cStyleCommentEndRegex = /(?<!\/)\*\//;
const newLineRegex = /(?:[\r\n]+|$)/;
const delimiterStartRegex = /(?:^|[\n\r]+)[ \f\t\v]*DELIMITER[ \t]+/i;
// Best effort only, unable to find a syntax specification on delimiter
const delimiterTokenRegex = /^(?:'(.+)'|"(.+)"|`(.+)`|([^\s]+))/;
const semicolonKeyTokenRegex = buildKeyTokenRegex(SEMICOLON);
const quoteEndRegexDict: Record<string, RegExp> = {
[SINGLE_QUOTE]: singleQuoteStringEndRegex,
[DOUBLE_QUOTE]: doubleQuoteStringEndRegex,
// [BACKTICK]: backtickQuoteEndRegex,
};
function escapeRegex(value: string): string {
return value.replace(regexEscapeSetRegex, '\\$&');
}
function buildKeyTokenRegex(delimiter: string): RegExp {
return new RegExp(
'(?:' +
[
escapeRegex(delimiter),
SINGLE_QUOTE,
DOUBLE_QUOTE,
// BACKTICK,
doubleDashCommentStartRegex.source,
HASH_COMMENT_START,
cStyleCommentStartRegex.source,
delimiterStartRegex.source,
].join('|') +
')',
'i'
);
}
function findExp(content: string, regex: RegExp): FindExpResult {
const match = content.match(regex);
let result: FindExpResult;
if (match?.index !== undefined) {
result = {
expIndex: match.index,
exp: match[0],
nextIndex: match.index + match[0].length,
};
} else {
result = {
expIndex: -1,
exp: null,
nextIndex: content.length,
};
}
return result;
}
function findKeyToken(content: string, currentDelimiter: string): FindExpResult {
let regex;
if (currentDelimiter === SEMICOLON) {
regex = semicolonKeyTokenRegex;
} else {
regex = buildKeyTokenRegex(currentDelimiter);
}
return findExp(content, regex);
}
function findEndQuote(content: string, quote: string): FindExpResult {
if (!(quote in quoteEndRegexDict)) {
throw new TypeError(`Incorrect quote ${quote} supplied`);
}
return findExp(content, quoteEndRegexDict[quote]);
}
function read(
context: SplitExecutionContext,
readToIndex: number,
nextUnreadIndex?: number,
checkSemicolon?: boolean
): void {
if (checkSemicolon === undefined) {
checkSemicolon = true;
}
const readContent = context.unread.slice(0, readToIndex);
if (checkSemicolon && readContent.includes(SEMICOLON)) {
context.currentStatement.supportMulti = false;
}
context.currentStatement.value += readContent;
if (nextUnreadIndex !== undefined && nextUnreadIndex > 0) {
context.unread = context.unread.slice(nextUnreadIndex);
} else {
context.unread = context.unread.slice(readToIndex);
}
}
function readTillNewLine(context: SplitExecutionContext, checkSemicolon?: boolean): void {
const findResult = findExp(context.unread, newLineRegex);
read(context, findResult.expIndex, findResult.expIndex, checkSemicolon);
}
function discard(context: SplitExecutionContext, nextUnreadIndex: number): void {
if (nextUnreadIndex > 0) {
context.unread = context.unread.slice(nextUnreadIndex);
}
}
function discardTillNewLine(context: SplitExecutionContext): void {
const findResult = findExp(context.unread, newLineRegex);
discard(context, findResult.expIndex);
}
function publishStatementInMultiMode(splitOutput: SqlStatement[], currentStatement: SqlStatement): void {
if (splitOutput.length === 0) {
splitOutput.push({
value: '',
supportMulti: true,
});
}
const lastSplitResult = splitOutput[splitOutput.length - 1];
if (currentStatement.supportMulti) {
if (lastSplitResult.supportMulti) {
if (lastSplitResult.value !== '' && !lastSplitResult.value.endsWith(LINE_FEED)) {
lastSplitResult.value += LINE_FEED;
}
lastSplitResult.value += currentStatement.value + SEMICOLON;
} else {
splitOutput.push({
value: currentStatement.value + SEMICOLON,
supportMulti: true,
});
}
} else {
splitOutput.push({
value: currentStatement.value,
supportMulti: false,
});
}
}
function publishStatement(context: SplitExecutionContext): void {
const trimmed = context.currentStatement.value.trim();
if (trimmed !== '') {
if (!context.multipleStatements) {
context.output.push({
value: trimmed,
supportMulti: context.currentStatement.supportMulti,
});
} else {
context.currentStatement.value = trimmed;
publishStatementInMultiMode(context.output, context.currentStatement);
}
}
context.currentStatement.value = '';
context.currentStatement.supportMulti = true;
}
function handleKeyTokenFindResult(context: SplitExecutionContext, findResult: FindExpResult): void {
switch (findResult.exp?.trim()) {
case context.currentDelimiter:
read(context, findResult.expIndex, findResult.nextIndex);
publishStatement(context);
break;
// case BACKTICK:
case SINGLE_QUOTE:
case DOUBLE_QUOTE: {
read(context, findResult.nextIndex);
const findQuoteResult = findEndQuote(context.unread, findResult.exp);
read(context, findQuoteResult.nextIndex, undefined, false);
break;
}
case DOUBLE_DASH_COMMENT_START: {
if (context.retainComments) {
read(context, findResult.nextIndex);
readTillNewLine(context, false);
} else {
read(context, findResult.expIndex, findResult.expIndex + DOUBLE_DASH_COMMENT_START.length);
discardTillNewLine(context);
}
break;
}
case HASH_COMMENT_START: {
if (context.retainComments) {
read(context, findResult.nextIndex);
readTillNewLine(context, false);
} else {
read(context, findResult.expIndex, findResult.nextIndex);
discardTillNewLine(context);
}
break;
}
case C_STYLE_COMMENT_START: {
if (['!', '+'].includes(context.unread[findResult.nextIndex]) || context.retainComments) {
// Should not be skipped, see https://dev.mysql.com/doc/refman/5.7/en/comments.html
read(context, findResult.nextIndex);
const findCommentResult = findExp(context.unread, cStyleCommentEndRegex);
read(context, findCommentResult.nextIndex);
} else {
read(context, findResult.expIndex, findResult.nextIndex);
const findCommentResult = findExp(context.unread, cStyleCommentEndRegex);
discard(context, findCommentResult.nextIndex);
}
break;
}
case DELIMITER_KEYWORD: {
read(context, findResult.expIndex, findResult.nextIndex);
// MySQL client will return `DELIMITER cannot contain a backslash character` if backslash is used
// Shall we reject backslash as well?
const matched = context.unread.match(delimiterTokenRegex);
if (matched?.index !== undefined) {
context.currentDelimiter = matched[0].trim();
discard(context, matched[0].length);
}
discardTillNewLine(context);
break;
}
case undefined:
case null:
read(context, findResult.nextIndex);
publishStatement(context);
break;
default:
// This should never happen
throw new Error(`Unknown token '${findResult.exp ?? '(null)'}'`);
}
}
export function splitPostgresQuery(sql: string, options?: SplitOptions): string[] {
options = options ?? {};
const context: SplitExecutionContext = {
multipleStatements: options.multipleStatements ?? false,
retainComments: options.retainComments ?? false,
unread: sql,
currentDelimiter: SEMICOLON,
currentStatement: {
value: '',
supportMulti: true,
},
output: [],
};
let findResult: FindExpResult = {
expIndex: -1,
exp: null,
nextIndex: 0,
};
let lastUnreadLength;
do {
lastUnreadLength = context.unread.length;
findResult = findKeyToken(context.unread, context.currentDelimiter);
handleKeyTokenFindResult(context, findResult);
// Prevent infinite loop by returning incorrect result
if (lastUnreadLength === context.unread.length) {
read(context, context.unread.length);
}
} while (context.unread !== '');
publishStatement(context);
return context.output.map(v => v.value);
}

View File

@@ -1,6 +1,7 @@
export interface SqlDialect {
rangeSelect?: boolean;
limitSelect?: boolean;
rowNumberOverPaging?: boolean;
stringEscapeChar: string;
offsetFetchRangeSyntax?: boolean;
quoteIdentifier(s: string): string;

View File

@@ -38,6 +38,7 @@ export interface EngineDriver {
title: string;
defaultPort?: number;
supportsDatabaseUrl?: boolean;
isFileDatabase?: boolean;
databaseUrlPlaceholder?: string;
connect({ server, port, user, password, database }): any;
query(pool: any, sql: string): Promise<QueryResult>;
@@ -61,6 +62,7 @@ export interface EngineDriver {
analyseFull(pool: any): Promise<DatabaseInfo>;
analyseIncremental(pool: any, structure: DatabaseInfo): Promise<DatabaseInfo>;
dialect: SqlDialect;
dialectByVersion(version): SqlDialect;
createDumper(): SqlDumper;
getAuthTypes(): EngineAuthType[];
readCollection(pool: any, options: ReadCollectionOptions): Promise<any>;

View File

@@ -4,6 +4,7 @@ export interface OpenedDatabaseConnection {
conid: string;
database: string;
structure: DatabaseInfo;
serverVersion?: any;
subprocess: ChildProcess;
disconnected?: boolean;
status?: {

View File

@@ -10,6 +10,7 @@
$: fileTypeNames = _.compact([
...$extensions.fileFormats.filter(x => x.readerFunc).map(x => x.name),
electron ? 'SQL' : null,
electron ? 'SQLite database' : null,
]);
</script>

View File

@@ -1,24 +1,83 @@
<script context="module">
const getContextMenu = (data, $openedConnections, $extensions) => () => {
export const extractKey = data => data._id;
export const createMatcher = ({ displayName, server }) => filter => filterName(filter, displayName, server);
</script>
<script lang="ts">
import _ from 'lodash';
import AppObjectCore from './AppObjectCore.svelte';
import { currentDatabase, extensions, getCurrentConfig, openedConnections } from '../stores';
import axiosInstance from '../utility/axiosInstance';
import { filterName } from 'dbgate-datalib';
import { showModal } from '../modals/modalTools';
import ConnectionModal from '../modals/ConnectionModal.svelte';
import ConfirmModal from '../modals/ConfirmModal.svelte';
import InputTextModal from '../modals/InputTextModal.svelte';
import openNewTab from '../utility/openNewTab';
import { getDatabaseMenuItems } from './DatabaseAppObject.svelte';
import getElectron from '../utility/getElectron';
import getConnectionLabel from '../utility/getConnectionLabel';
export let data;
let statusIcon = null;
let statusTitle = null;
let extInfo = null;
let engineStatusIcon = null;
let engineStatusTitle = null;
const electron = getElectron();
const handleConnect = () => {
if (data.singleDatabase) {
$currentDatabase = { connection: data, name: data.defaultDatabase };
axiosInstance.post('database-connections/refresh', {
conid: data._id,
database: data.defaultDatabase,
keepOpen: true,
});
} else {
$openedConnections = _.uniq([...$openedConnections, data._id]);
axiosInstance.post('server-connections/refresh', {
conid: data._id,
keepOpen: true,
});
}
};
const getContextMenu = () => {
const config = getCurrentConfig();
const handleRefresh = () => {
axiosInstance.post('server-connections/refresh', { conid: data._id });
};
const handleDisconnect = () => {
openedConnections.update(list => list.filter(x => x != data._id));
};
const handleConnect = () => {
openedConnections.update(list => _.uniq([...list, data._id]));
if (electron) {
axiosInstance.post('server-connections/disconnect', { conid: data._id });
}
if (_.get($currentDatabase, 'connection._id') == data._id) {
if (electron) {
axiosInstance.post('database-connections/disconnect', { conid: data._id, database: $currentDatabase.name });
}
currentDatabase.set(null);
}
};
const handleEdit = () => {
showModal(ConnectionModal, { connection: data });
};
const handleDelete = () => {
showModal(ConfirmModal, {
message: `Really delete connection ${data.displayName || data.server}?`,
message: `Really delete connection ${getConnectionLabel(data)}?`,
onConfirm: () => axiosInstance.post('connections/delete', data),
});
};
const handleDuplicate = () => {
axiosInstance.post('connections/save', {
...data,
_id: undefined,
displayName: `${getConnectionLabel(data)} - copy`,
});
};
const handleCreateDatabase = () => {
showModal(InputTextModal, {
header: 'Create database',
@@ -32,7 +91,7 @@
});
};
const handleNewQuery = () => {
const tooltip = `${data.displayName || data.server}`;
const tooltip = `${getConnectionLabel(data)}`;
openNewTab({
title: 'Query #',
icon: 'img sql-file',
@@ -54,6 +113,10 @@
text: 'Delete',
onClick: handleDelete,
},
{
text: 'Duplicate',
onClick: handleDuplicate,
},
],
!data.singleDatabase && [
!$openedConnections.includes(data._id) && {
@@ -75,35 +138,13 @@
onClick: handleCreateDatabase,
},
],
data.singleDatabase && [{ divider: true }, getDatabaseMenuItems(data, data.defaultDatabase, $extensions)],
data.singleDatabase && [
{ divider: true },
getDatabaseMenuItems(data, data.defaultDatabase, $extensions, $currentDatabase),
],
];
};
export const extractKey = data => data._id;
export const createMatcher = ({ displayName, server }) => filter => filterName(filter, displayName, server);
</script>
<script lang="ts">
import _ from 'lodash';
import AppObjectCore from './AppObjectCore.svelte';
import { currentDatabase, extensions, getCurrentConfig, openedConnections } from '../stores';
import axiosInstance from '../utility/axiosInstance';
import { filterName } from 'dbgate-datalib';
import { showModal } from '../modals/modalTools';
import ConnectionModal from '../modals/ConnectionModal.svelte';
import ConfirmModal from '../modals/ConfirmModal.svelte';
import InputTextModal from '../modals/InputTextModal.svelte';
import openNewTab from '../utility/openNewTab';
import { getDatabaseMenuItems } from './DatabaseAppObject.svelte';
export let data;
let statusIcon = null;
let statusTitle = null;
let extInfo = null;
let engineStatusIcon = null;
let engineStatusTitle = null;
$: {
if ($extensions.drivers.find(x => x.engine == data.engine)) {
const match = (data.engine || '').match(/^([^@]*)@/);
@@ -132,30 +173,12 @@
statusTitle = null;
}
}
// const handleEdit = () => {
// showModal(modalState => <ConnectionModal modalState={modalState} connection={data} />);
// };
// const handleDelete = () => {
// showModal(modalState => (
// <ConfirmModal
// modalState={modalState}
// message={`Really delete connection ${data.displayName || data.server}?`}
// onConfirm={() => axios.post('connections/delete', data)}
// />
// ));
// };
// const handleCreateDatabase = () => {
// showModal(modalState => <CreateDatabaseModal modalState={modalState} conid={data._id} />);
// };
</script>
<AppObjectCore
{...$$restProps}
{data}
title={data.singleDatabase
? data.displayName || `${data.defaultDatabase} on ${data.server}`
: data.displayName || data.server}
title={getConnectionLabel(data)}
icon={data.singleDatabase ? 'img database' : 'img server'}
isBold={data.singleDatabase
? _.get($currentDatabase, 'connection._id') == data._id && _.get($currentDatabase, 'name') == data.defaultDatabase
@@ -163,10 +186,8 @@
statusIcon={statusIcon || engineStatusIcon}
statusTitle={statusTitle || engineStatusTitle}
{extInfo}
menu={getContextMenu(data, $openedConnections, $extensions)}
on:click={() => {
if (data.singleDatabase) $currentDatabase = { connection: data, name: data.defaultDatabase };
else $openedConnections = _.uniq([...$openedConnections, data._id]);
}}
menu={getContextMenu}
on:click={handleConnect}
on:click
on:expand
/>

View File

@@ -1,9 +1,10 @@
<script lang="ts" context="module">
export const extractKey = props => props.name;
const electron = getElectron();
export function getDatabaseMenuItems(connection, name, $extensions) {
export function getDatabaseMenuItems(connection, name, $extensions, $currentDatabase) {
const handleNewQuery = () => {
const tooltip = `${connection.displayName || connection.server}\n${name}`;
const tooltip = `${getConnectionLabel(connection)}\n${name}`;
openNewTab({
title: 'Query #',
icon: 'img sql-file',
@@ -45,28 +46,42 @@
});
};
const handleDisconnect = () => {
if (electron) {
axiosInstance.post('database-connections/disconnect', { conid: connection._id, database: name });
}
currentDatabase.set(null);
};
return [
{ onClick: handleNewQuery, text: 'New query' },
{ onClick: handleImport, text: 'Import' },
{ onClick: handleExport, text: 'Export' },
{ onClick: handleSqlGenerator, text: 'SQL Generator' },
_.get($currentDatabase, 'connection._id') == _.get(connection, '_id') &&
_.get($currentDatabase, 'name') == name && { onClick: handleDisconnect, text: 'Disconnect' },
];
}
</script>
<script lang="ts">
import getConnectionLabel from '../utility/getConnectionLabel';
import _ from 'lodash';
import ImportExportModal from '../modals/ImportExportModal.svelte';
import { showModal } from '../modals/modalTools';
import SqlGeneratorModal from '../modals/SqlGeneratorModal.svelte';
import { getDefaultFileFormat } from '../plugins/fileformats';
import { currentDatabase, extensions } from '../stores';
import axiosInstance from '../utility/axiosInstance';
import getElectron from '../utility/getElectron';
import openNewTab from '../utility/openNewTab';
import AppObjectCore from './AppObjectCore.svelte';
export let data;
function createMenu() {
return getDatabaseMenuItems(data.connection, data.name, $extensions);
return getDatabaseMenuItems(data.connection, data.name, $extensions, $currentDatabase);
}
</script>

View File

@@ -228,7 +228,7 @@
initialData
) {
const connection = await getConnectionInfo({ conid });
const tooltip = `${connection.displayName || connection.server}\n${database}\n${fullDisplayName({
const tooltip = `${getConnectionLabel(connection)}\n${database}\n${fullDisplayName({
schemaName,
pureName,
})}`;
@@ -267,6 +267,7 @@
import { findEngineDriver } from 'dbgate-tools';
import uuidv1 from 'uuid/v1';
import SqlGeneratorModal from '../modals/SqlGeneratorModal.svelte';
import getConnectionLabel from '../utility/getConnectionLabel';
export let data;

View File

@@ -67,6 +67,7 @@
import { currentDatabase } from '../stores';
import axiosInstance from '../utility/axiosInstance';
import getConnectionLabel from '../utility/getConnectionLabel';
import hasPermission from '../utility/hasPermission';
import openNewTab from '../utility/openNewTab';
@@ -130,7 +131,7 @@
const database = _.get($currentDatabase, 'name');
connProps.conid = connection._id;
connProps.database = database;
tooltip = `${connection.displayName || connection.server}\n${database}`;
tooltip = `${getConnectionLabel(connection)}\n${database}`;
}
openNewTab(

View File

@@ -1,5 +1,6 @@
import _ from 'lodash';
import { recentDatabases, currentDatabase, getRecentDatabases } from '../stores';
import getConnectionLabel from '../utility/getConnectionLabel';
import registerCommand from './registerCommand';
currentDatabase.subscribe(value => {
@@ -15,7 +16,7 @@ currentDatabase.subscribe(value => {
function switchDatabaseCommand(db) {
return {
text: `${db.name} on ${db?.connection?.displayName || db?.connection?.server}`,
text: `${db.name} on ${getConnectionLabel(db?.connection, { allowExplicitDatabase: false })}`,
onClick: () => currentDatabase.set(db),
};
}

View File

@@ -27,6 +27,7 @@ export interface GlobalCommand {
menuName?: string;
toolbarOrder?: number;
disableHandleKeyText?: string;
isRelatedToTab?: boolean,
}
export default function registerCommand(command: GlobalCommand) {

View File

@@ -241,6 +241,7 @@ export function registerFileCommands({
toggleComment = false,
findReplace = false,
undoRedo = false,
executeAdditionalCondition = null,
}) {
if (save) {
registerCommand({
@@ -251,6 +252,7 @@ export function registerFileCommands({
// keyText: 'Ctrl+S',
icon: 'icon save',
toolbar: true,
isRelatedToTab: true,
testEnabled: () => getCurrentEditor() != null,
onClick: () => saveTabFile(getCurrentEditor(), false, folder, format, fileExtension),
});
@@ -271,8 +273,12 @@ export function registerFileCommands({
name: 'Execute',
icon: 'icon run',
toolbar: true,
isRelatedToTab: true,
keyText: 'F5 | Ctrl+Enter',
testEnabled: () => getCurrentEditor() != null && !getCurrentEditor()?.isBusy(),
testEnabled: () =>
getCurrentEditor() != null &&
!getCurrentEditor()?.isBusy() &&
(executeAdditionalCondition == null || executeAdditionalCondition()),
onClick: () => getCurrentEditor().execute(),
});
registerCommand({
@@ -281,6 +287,7 @@ export function registerFileCommands({
name: 'Kill',
icon: 'icon close',
toolbar: true,
isRelatedToTab: true,
testEnabled: () => getCurrentEditor()?.canKill && getCurrentEditor().canKill(),
onClick: () => getCurrentEditor().kill(),
});

View File

@@ -7,6 +7,7 @@
name: 'Refresh',
keyText: 'F5',
toolbar: true,
isRelatedToTab: true,
icon: 'icon reload',
testEnabled: () => getCurrentDataGrid()?.getDisplay()?.supportsReload,
onClick: () => getCurrentDataGrid().refresh(),
@@ -63,6 +64,7 @@
group: 'undo',
icon: 'icon undo',
toolbar: true,
isRelatedToTab: true,
testEnabled: () => getCurrentDataGrid()?.getGrider()?.canUndo,
onClick: () => getCurrentDataGrid().undo(),
});
@@ -74,6 +76,7 @@
group: 'redo',
icon: 'icon redo',
toolbar: true,
isRelatedToTab: true,
testEnabled: () => getCurrentDataGrid()?.getGrider()?.canRedo,
onClick: () => getCurrentDataGrid().redo(),
});

View File

@@ -14,7 +14,12 @@
import { extensions } from '../stores';
import stableStringify from 'json-stable-stringify';
import { useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders';
import {
useConnectionInfo,
useDatabaseInfo,
useDatabaseServerVersion,
useServerVersion,
} from '../utility/metadataLoaders';
import DataGrid from './DataGrid.svelte';
import ReferenceHeader from './ReferenceHeader.svelte';
@@ -38,6 +43,9 @@
$: connection = useConnectionInfo({ conid });
$: dbinfo = useDatabaseInfo({ conid, database });
$: serverVersion = useDatabaseServerVersion({ conid, database });
// $: console.log('serverVersion', $serverVersion);
let myLoadedTime = 0;
@@ -45,31 +53,35 @@
// $: console.log('display', display);
$: display = connection
? new TableGridDisplay(
{ schemaName, pureName },
findEngineDriver($connection, $extensions),
config,
setConfig,
cache,
setCache,
$dbinfo,
{ showHintColumns: getBoolSettingsValue('dataGrid.showHintColumns', true) }
)
: null;
$: display =
connection && $serverVersion
? new TableGridDisplay(
{ schemaName, pureName },
findEngineDriver($connection, $extensions),
config,
setConfig,
cache,
setCache,
$dbinfo,
{ showHintColumns: getBoolSettingsValue('dataGrid.showHintColumns', true) },
$serverVersion
)
: null;
$: formDisplay = connection
? new TableFormViewDisplay(
{ schemaName, pureName },
findEngineDriver($connection, $extensions),
config,
setConfig,
cache,
setCache,
$dbinfo,
{ showHintColumns: getBoolSettingsValue('dataGrid.showHintColumns', true) }
)
: null;
$: formDisplay =
connection && $serverVersion
? new TableFormViewDisplay(
{ schemaName, pureName },
findEngineDriver($connection, $extensions),
config,
setConfig,
cache,
setCache,
$dbinfo,
{ showHintColumns: getBoolSettingsValue('dataGrid.showHintColumns', true) },
$serverVersion
)
: null;
const setChildConfig = (value, reference = undefined) => {
if (_.isFunction(value)) {

View File

@@ -54,6 +54,9 @@ export function countColumnSizes(grider: Grider, columns, containerWidth, displa
context.font = '14px Helvetica';
for (let rowIndex = 0; rowIndex < Math.min(grider.rowCount, 20); rowIndex += 1) {
const row = grider.getRowData(rowIndex);
if (!row) {
continue;
}
for (let colIndex = 0; colIndex < columns.length; colIndex++) {
const uqName = columns[colIndex].uniqueName;

View File

@@ -13,5 +13,5 @@
<span class="nowrap">
<FontIcon icon={getConstraintIcon(constraintType)} />
{constraintName}
{constraintName || '(without name)'}
</span>

View File

@@ -2,10 +2,12 @@
import { getFormContext } from './FormProviderCore.svelte';
import SelectField from './SelectField.svelte';
import { createEventDispatcher } from 'svelte';
import _ from 'lodash';
const dispatch = createEventDispatcher();
export let name;
export let options;
export let isClearable = false;
const { values, setFieldValue } = getFormContext();
@@ -14,6 +16,7 @@
<SelectField
{...$$restProps}
value={$values[name]}
options={_.compact(options)}
on:change={e => {
setFieldValue(name, e.detail);
dispatch('change', e.detail);

View File

@@ -18,6 +18,7 @@
name: 'Refresh',
keyText: 'F5',
toolbar: true,
isRelatedToTab: true,
icon: 'icon reload',
testEnabled: () => getCurrentDataForm() != null,
onClick: () => getCurrentDataForm().refresh(),
@@ -58,6 +59,7 @@
group: 'undo',
icon: 'icon undo',
toolbar: true,
isRelatedToTab: true,
testEnabled: () => getCurrentDataForm()?.getFormer()?.canUndo,
onClick: () => getCurrentDataForm().getFormer().undo(),
});
@@ -69,6 +71,7 @@
group: 'redo',
icon: 'icon redo',
toolbar: true,
isRelatedToTab: true,
testEnabled: () => getCurrentDataForm()?.getFormer()?.canRedo,
onClick: () => getCurrentDataForm().getFormer().redo(),
});
@@ -104,6 +107,7 @@
name: 'First',
keyText: 'Ctrl+Home',
toolbar: true,
isRelatedToTab: true,
icon: 'icon arrow-begin',
testEnabled: () => getCurrentDataForm() != null,
onClick: () => getCurrentDataForm().navigate('begin'),
@@ -115,6 +119,7 @@
name: 'Previous',
keyText: 'Ctrl+ArrowUp',
toolbar: true,
isRelatedToTab: true,
icon: 'icon arrow-left',
testEnabled: () => getCurrentDataForm() != null,
onClick: () => getCurrentDataForm().navigate('previous'),
@@ -126,6 +131,7 @@
name: 'Next',
keyText: 'Ctrl+ArrowDown',
toolbar: true,
isRelatedToTab: true,
icon: 'icon arrow-right',
testEnabled: () => getCurrentDataForm() != null,
onClick: () => getCurrentDataForm().navigate('next'),
@@ -137,6 +143,7 @@
name: 'Last',
keyText: 'Ctrl+End',
toolbar: true,
isRelatedToTab: true,
icon: 'icon arrow-end',
testEnabled: () => getCurrentDataForm() != null,
onClick: () => getCurrentDataForm().navigate('end'),

View File

@@ -40,7 +40,7 @@
</script>
<ManagerInnerContainer width={managerSize}>
{#each structure.columns as column, index}
{#each structure.columns || [] as column, index}
{#if index == editingColumn}
<ColumnNameEditor
defaultValue={column.columnName}
@@ -77,6 +77,6 @@
dispatchChangeColumns($$props, cols => [...cols, { columnName }]);
}}
placeholder="New column"
existingNames={structure.columns.map(x => x.columnName)}
existingNames={(structure.columns || []).map(x => x.columnName)}
/>
</ManagerInnerContainer>

View File

@@ -19,6 +19,7 @@
'icon sql-generator': 'mdi mdi-cog-transfer',
'icon keyboard': 'mdi mdi-keyboard-settings',
'icon settings': 'mdi mdi-cog',
'icon version': 'mdi mdi-ticket-confirmation',
'icon database': 'mdi mdi-database',
'icon server': 'mdi mdi-server',

View File

@@ -1,13 +1,14 @@
<script lang="ts">
import _ from 'lodash';
import FormSelectField from '../forms/FormSelectField.svelte';
import getConnectionLabel from '../utility/getConnectionLabel';
import { useConnectionList } from '../utility/metadataLoaders';
$: connections = useConnectionList();
$: connectionOptions = _.sortBy(
($connections || []).map(conn => ({
value: conn._id,
label: conn.displayName || conn.server,
label: getConnectionLabel(conn),
})),
'label'
);

View File

@@ -15,11 +15,7 @@
const { values, setFieldValue } = getFormContext();
$: dbinfo = useDatabaseInfo({ conid: $values[conidName], database: $values[databaseName] });
$: tablesOptions = [
...(($dbinfo && $dbinfo.tables) || []),
...(($dbinfo && $dbinfo.views) || []),
...(($dbinfo && $dbinfo.collections) || []),
]
$: tablesOptions = _.compact([...($dbinfo?.tables || []), ...($dbinfo?.views || []), ...($dbinfo?.collections || [])])
.filter(x => !$values[schemaName] || x.schemaName == $values[schemaName])
.map(x => ({
value: x.pureName,
@@ -31,18 +27,20 @@
<FormSelectField {...$$restProps} {name} options={tablesOptions} isMulti templateProps={{ noMargin: true }} />
<div>
<FormStyledButton
type="button"
value="All tables"
on:click={() =>
setFieldValue(name, _.uniq([...($values[name] || []), ...($dbinfo && $dbinfo.tables.map(x => x.pureName))]))}
/>
<FormStyledButton
type="button"
value="All views"
on:click={() =>
setFieldValue(name, _.uniq([...($values[name] || []), ...($dbinfo && $dbinfo.views.map(x => x.pureName))]))}
/>
{#each ['tables', 'views', 'collections'] as field}
{#if $dbinfo && $dbinfo[field]?.length > 0}
<FormStyledButton
type="button"
value={`All ${field}`}
on:click={() =>
setFieldValue(
name,
_.compact(_.uniq([...($values[name] || []), ...($dbinfo[field]?.map(x => x.pureName) || [])]))
)}
/>
{/if}
{/each}
<FormStyledButton type="button" value="Remove all" on:click={() => setFieldValue(name, [])} />
</div>
</div>

View File

@@ -12,14 +12,26 @@
import FormFieldTemplateLarge from '../forms/FormFieldTemplateLarge.svelte';
import ModalBase from './ModalBase.svelte';
import { closeCurrentModal, closeModal } from './modalTools';
import { closeCurrentModal, closeModal, showModal } from './modalTools';
import createRef from '../utility/createRef';
import Link from '../elements/Link.svelte';
import ErrorMessageModal from './ErrorMessageModal.svelte';
import { writable } from 'svelte/store';
import FormProviderCore from '../forms/FormProviderCore.svelte';
import { extensions } from '../stores';
import _ from 'lodash';
import { getDatabaseFileLabel } from '../utility/getConnectionLabel';
export let connection;
let isTesting;
let sqlConnectResult;
const values = writable(connection || { server: 'localhost', engine: 'mssql@dbgate-plugin-mssql' });
$: engine = $values.engine;
$: driver = $extensions.drivers.find(x => x.engine == engine);
const testIdRef = createRef(0);
async function handleTest(e) {
@@ -39,18 +51,22 @@
}
async function handleSubmit(e) {
axiosInstance.post('connections/save', {
...e.detail,
singleDatabase: e.detail.defaultDatabase ? e.detail.singleDatabase : false,
});
const connection = driver?.isFileDatabase
? {
..._.omit(e.detail, ['server', 'port', 'defaultDatabase']),
singleDatabase: true,
defaultDatabase: getDatabaseFileLabel(e.detail.databaseFile),
}
: {
..._.omit(e.detail, ['databaseFile']),
singleDatabase: e.detail.defaultDatabase ? e.detail.singleDatabase : false,
};
axiosInstance.post('connections/save', connection);
closeCurrentModal();
}
</script>
<FormProvider
template={FormFieldTemplateLarge}
initialValues={connection || { server: 'localhost', engine: 'mssql@dbgate-plugin-mssql' }}
>
<FormProviderCore template={FormFieldTemplateLarge} {values}>
<ModalBase {...$$restProps} noPadding>
<div slot="header">Add connection</div>
@@ -61,11 +77,11 @@
label: 'Main',
component: ConnectionModalDriverFields,
},
{
!driver?.isFileDatabase && {
label: 'SSH Tunnel',
component: ConnectionModalSshTunnelFields,
},
{
!driver?.isFileDatabase && {
label: 'SSL',
component: ConnectionModalSslFields,
},
@@ -92,6 +108,16 @@
<div class="error-result">
Connect failed: <FontIcon icon="img error" />
{sqlConnectResult.error}
<Link
onClick={() =>
showModal(ErrorMessageModal, {
message: sqlConnectResult.detail,
showAsCode: true,
title: 'Database connection error',
})}
>
Show detail
</Link>
</div>
{/if}
{#if isTesting}
@@ -102,7 +128,7 @@
</div>
</div>
</ModalBase>
</FormProvider>
</FormProviderCore>
<style>
.buttons {

View File

@@ -1,5 +1,6 @@
<script lang="ts">
import FormCheckboxField from '../forms/FormCheckboxField.svelte';
import FormElectronFileSelector from '../forms/FormElectronFileSelector.svelte';
import FormPasswordField from '../forms/FormPasswordField.svelte';
@@ -9,9 +10,12 @@
import FormTextField from '../forms/FormTextField.svelte';
import { extensions } from '../stores';
import getElectron from '../utility/getElectron';
import { useAuthTypes } from '../utility/metadataLoaders';
const { values } = getFormContext();
const electron = getElectron();
$: authType = $values.authType;
$: engine = $values.engine;
$: useDatabaseUrl = $values.useDatabaseUrl;
@@ -27,94 +31,100 @@
name="engine"
options={[
{ label: '(select driver)', value: '' },
...$extensions.drivers.map(driver => ({
value: driver.engine,
label: driver.title,
})),
...$extensions.drivers
.filter(driver => !driver.isFileDatabase || electron)
.map(driver => ({
value: driver.engine,
label: driver.title,
})),
]}
/>
{#if driver?.supportsDatabaseUrl}
<div class="radio">
<FormRadioGroupField
name="useDatabaseUrl"
options={[
{ label: 'Fill database connection details', value: '', default: true },
{ label: 'Use database URL', value: '1' },
]}
/>
</div>
{/if}
{#if driver?.supportsDatabaseUrl && useDatabaseUrl}
<FormTextField label="Database URL" name="databaseUrl" placeholder={driver?.databaseUrlPlaceholder} />
{#if driver?.isFileDatabase}
<FormElectronFileSelector label="Database file" name="databaseFile" disabled={!electron} />
{:else}
{#if $authTypes}
<FormSelectField
label="Authentication"
name="authType"
options={$authTypes.map(auth => ({
value: auth.name,
label: auth.title,
}))}
/>
{#if driver?.supportsDatabaseUrl}
<div class="radio">
<FormRadioGroupField
name="useDatabaseUrl"
options={[
{ label: 'Fill database connection details', value: '', default: true },
{ label: 'Use database URL', value: '1' },
]}
/>
</div>
{/if}
<div class="row">
<div class="col-9 mr-1">
<FormTextField
label="Server"
name="server"
disabled={disabledFields.includes('server')}
templateProps={{ noMargin: true }}
{#if driver?.supportsDatabaseUrl && useDatabaseUrl}
<FormTextField label="Database URL" name="databaseUrl" placeholder={driver?.databaseUrlPlaceholder} />
{:else}
{#if $authTypes}
<FormSelectField
label="Authentication"
name="authType"
options={$authTypes.map(auth => ({
value: auth.name,
label: auth.title,
}))}
/>
</div>
<div class="col-3 mr-1">
<FormTextField
label="Port"
name="port"
disabled={disabledFields.includes('port')}
templateProps={{ noMargin: true }}
placeholder={driver && driver.defaultPort}
/>
</div>
</div>
{/if}
<div class="row">
<div class="col-6 mr-1">
<FormTextField
label="User"
name="user"
disabled={disabledFields.includes('user')}
templateProps={{ noMargin: true }}
/>
<div class="row">
<div class="col-9 mr-1">
<FormTextField
label="Server"
name="server"
disabled={disabledFields.includes('server')}
templateProps={{ noMargin: true }}
/>
</div>
<div class="col-3 mr-1">
<FormTextField
label="Port"
name="port"
disabled={disabledFields.includes('port')}
templateProps={{ noMargin: true }}
placeholder={driver && driver.defaultPort}
/>
</div>
</div>
<div class="col-6 mr-1">
<FormPasswordField
label="Password"
name="password"
disabled={disabledFields.includes('password')}
templateProps={{ noMargin: true }}
/>
</div>
</div>
{#if !disabledFields.includes('password')}
<FormSelectField
label="Password mode"
name="passwordMode"
options={[
{ value: 'saveEncrypted', label: 'Save and encrypt' },
{ value: 'saveRaw', label: 'Save raw (UNSAFE!!)' },
]}
/>
<div class="row">
<div class="col-6 mr-1">
<FormTextField
label="User"
name="user"
disabled={disabledFields.includes('user')}
templateProps={{ noMargin: true }}
/>
</div>
<div class="col-6 mr-1">
<FormPasswordField
label="Password"
name="password"
disabled={disabledFields.includes('password')}
templateProps={{ noMargin: true }}
/>
</div>
</div>
{#if !disabledFields.includes('password')}
<FormSelectField
label="Password mode"
name="passwordMode"
options={[
{ value: 'saveEncrypted', label: 'Save and encrypt' },
{ value: 'saveRaw', label: 'Save raw (UNSAFE!!)' },
]}
/>
{/if}
{/if}
{/if}
<FormTextField label="Default database" name="defaultDatabase" />
<FormTextField label="Default database" name="defaultDatabase" />
{#if defaultDatabase}
<FormCheckboxField label={`Use only database ${defaultDatabase}`} name="singleDatabase" />
{#if defaultDatabase}
<FormCheckboxField label={`Use only database ${defaultDatabase}`} name="singleDatabase" />
{/if}
{/if}
<FormTextField label="Display name" name="displayName" />

View File

@@ -11,6 +11,7 @@
import getElectron from '../utility/getElectron';
import { usePlatformInfo } from '../utility/metadataLoaders';
import FontIcon from '../icons/FontIcon.svelte';
import { extensions } from '../stores';
const { values, setFieldValue } = getFormContext();
const electron = getElectron();

View File

@@ -9,18 +9,25 @@
export let title = 'Error';
export let message;
export let showAsCode = false;
</script>
<FormProvider>
<ModalBase {...$$restProps}>
<div slot="header">{title}</div>
<div class="wrapper">
<div class="icon">
<FontIcon icon="img error" />
{#if showAsCode}
<pre>{message}</pre>
{:else}
<div class="wrapper">
<div class="icon">
<FontIcon icon="img error" />
</div>
<div>
{message}
</div>
</div>
{message}
</div>
{/if}
<div slot="footer">
<FormSubmit value="Close" on:click={closeCurrentModal} />
@@ -38,4 +45,9 @@
margin-right: 10px;
font-size: 20pt;
}
pre {
max-height: calc(100vh - 300px);
overflow-y: auto;
}
</style>

View File

@@ -17,7 +17,7 @@
}
</script>
{#each plugins as packageManifest (packageManifest.name)}
{#each plugins || [] as packageManifest (packageManifest.name)}
<div class="wrapper" on:click={() => openPlugin(packageManifest)}>
<img class="icon" src={extractPluginIcon(packageManifest)} />
<div class="ml-2">

View File

@@ -11,10 +11,15 @@
import 'ace-builds/src-noconflict/mode-json';
import 'ace-builds/src-noconflict/mode-javascript';
import 'ace-builds/src-noconflict/mode-markdown';
import 'ace-builds/src-noconflict/theme-github';
import 'ace-builds/src-noconflict/theme-twilight';
import 'ace-builds/src-noconflict/ext-searchbox';
import 'ace-builds/src-noconflict/ext-language_tools';
import 'ace-builds/src-noconflict/theme-github';
// import 'ace-builds/src-noconflict/theme-sqlserver';
import 'ace-builds/src-noconflict/theme-twilight';
// import 'ace-builds/src-noconflict/theme-monokai';
import { currentDropDownMenu, currentThemeDefinition } from '../stores';
import _ from 'lodash';
import { handleCommandKeyDown } from '../commands/CommandListener.svelte';

View File

@@ -1,6 +1,7 @@
import _ from 'lodash';
import { get } from 'svelte/store';
import { currentDatabase } from '../stores';
import getConnectionLabel from '../utility/getConnectionLabel';
import openNewTab from '../utility/openNewTab';
export default function newQuery({
@@ -14,7 +15,7 @@ export default function newQuery({
const connection = _.get($currentDatabase, 'connection') || {};
const database = _.get($currentDatabase, 'name');
const tooltip = `${connection.displayName || connection.server}\n${database}`;
const tooltip = `${getConnectionLabel(connection)}\n${database}`;
openNewTab(
{

View File

@@ -19,6 +19,8 @@ function getParsedLocalStorage(key) {
return null;
}
const saveHandlersList = [];
export default function useEditorData({ tabid, reloadToken = 0, loadFromArgs = null, onInitialData = null }) {
const localStorageKey = `tabdata_editor_${tabid}`;
let changeCounter = 0;
@@ -90,6 +92,11 @@ export default function useEditorData({ tabid, reloadToken = 0, loadFromArgs = n
}));
};
const saveToStorageIfNeeded = async () => {
if (savedCounter == changeCounter) return; // all saved
await saveToStorage();
};
const saveToStorage = async () => {
if (value == null) return;
try {
@@ -128,11 +135,13 @@ export default function useEditorData({ tabid, reloadToken = 0, loadFromArgs = n
onMount(() => {
window.addEventListener('beforeunload', saveToStorageSync);
initialLoad();
saveHandlersList.push(saveToStorageIfNeeded);
});
onDestroy(() => {
saveToStorage();
window.removeEventListener('beforeunload', saveToStorageSync);
_.remove(saveHandlersList, x => x == saveToStorageIfNeeded);
});
return {
@@ -144,3 +153,9 @@ export default function useEditorData({ tabid, reloadToken = 0, loadFromArgs = n
initialLoad,
};
}
export async function saveAllPendingEditorData() {
for (const item of saveHandlersList) {
await item();
}
}

View File

@@ -7,6 +7,7 @@
import FormProvider from '../forms/FormProvider.svelte';
import FormSubmit from '../forms/FormSubmit.svelte';
import FormTextField from '../forms/FormTextField.svelte';
import FormValues from '../forms/FormValues.svelte';
import ModalBase from '../modals/ModalBase.svelte';
import { closeCurrentModal } from '../modals/modalTools';
@@ -32,17 +33,32 @@
<ModalBase {...$$restProps}>
<div slot="header">Settings</div>
<div class="heading">Appearance</div>
<FormCheckboxField name=":visibleToolbar" label="Show toolbar" defaultValue={true} />
<FormValues let:values>
<div class="heading">Appearance</div>
<FormCheckboxField name=":visibleToolbar" label="Show toolbar" defaultValue={true} />
<div class="heading">Data grid</div>
<FormCheckboxField name="dataGrid.hideLeftColumn" label="Hide left column by default" />
<FormTextField
name="dataGrid.pageSize"
label="Page size (number of rows for incremental loading, must be between 5 and 1000)"
defaultValue="100"
/>
<FormCheckboxField name="dataGrid.showHintColumns" label="Show foreign key hints" defaultValue={true} />
<div class="heading">Data grid</div>
<FormCheckboxField name="dataGrid.hideLeftColumn" label="Hide left column by default" />
<FormTextField
name="dataGrid.pageSize"
label="Page size (number of rows for incremental loading, must be between 5 and 1000)"
defaultValue="100"
/>
<FormCheckboxField name="dataGrid.showHintColumns" label="Show foreign key hints" defaultValue={true} />
<div class="heading">Connection</div>
<FormCheckboxField
name="connection.autoRefresh"
label="Automatic refresh of database model on background"
defaultValue={true}
/>
<FormTextField
name="connection.autoRefreshInterval"
label="Interval between automatic refreshes in seconds"
defaultValue="30"
disabled={values['connection.autoRefresh'] === false}
/>
</FormValues>
<div slot="footer">
<FormSubmit value="OK" on:click={handleOk} />

View File

@@ -11,6 +11,7 @@
name: 'Save',
// keyText: 'Ctrl+S',
toolbar: true,
isRelatedToTab: true,
icon: 'icon save',
testEnabled: () => getCurrentEditor()?.canSave(),
onClick: () => getCurrentEditor().save(),

View File

@@ -8,6 +8,7 @@
name: 'Save',
// keyText: 'Ctrl+S',
toolbar: true,
isRelatedToTab: true,
icon: 'icon save',
testEnabled: () => getCurrentEditor() != null,
onClick: () => getCurrentEditor().save(),

View File

@@ -19,6 +19,7 @@
name: 'Preview',
icon: 'icon run',
toolbar: true,
isRelatedToTab: true,
keyText: 'F5 | Ctrl+Enter',
testEnabled: () => getCurrentEditor() != null,
onClick: () => getCurrentEditor().preview(),

View File

@@ -27,6 +27,7 @@
execute: true,
toggleComment: true,
findReplace: true,
executeAdditionalCondition: () => getCurrentEditor()?.hasConnection(),
});
</script>
@@ -121,6 +122,10 @@
return tabid;
}
export function hasConnection() {
return !!conid;
}
export async function execute() {
if (busy) return;
executeNumber++;

View File

@@ -8,6 +8,7 @@
name: 'Save',
// keyText: 'Ctrl+S',
toolbar: true,
isRelatedToTab: true,
icon: 'icon save',
testEnabled: () => getCurrentEditor()?.canSave(),
onClick: () => getCurrentEditor().save(),

View File

@@ -11,7 +11,7 @@
import DataGrid from '../datagrid/DataGrid.svelte';
import SqlDataGridCore from '../datagrid/SqlDataGridCore.svelte';
import { extensions } from '../stores';
import { useConnectionInfo, useViewInfo } from '../utility/metadataLoaders';
import { useConnectionInfo, useDatabaseServerVersion, useViewInfo } from '../utility/metadataLoaders';
import useGridConfig from '../utility/useGridConfig';
export let tabid;
@@ -22,12 +22,13 @@
$: connection = useConnectionInfo({ conid });
$: viewInfo = useViewInfo({ conid, database, schemaName, pureName });
$: serverVersion = useDatabaseServerVersion({ conid, database });
const config = useGridConfig(tabid);
const cache = writable(createGridCache());
$: display =
$viewInfo && $connection
$viewInfo && $connection && $serverVersion
? new ViewGridDisplay(
$viewInfo,
findEngineDriver($connection, $extensions),
@@ -35,7 +36,8 @@
$config,
config.update,
$cache,
cache.update
cache.update,
$serverVersion
)
: null;
</script>

View File

@@ -13,6 +13,8 @@
console.log('CRASH DETECTED!!!');
const lastDbGateCrashJson = localStorage.getItem('lastDbGateCrash');
const lastDbGateCrash = lastDbGateCrashJson ? JSON.parse(lastDbGateCrashJson) : null;
// let detail = e?.reason?.stack || '';
// if (detail) detail = '\n\n' + detail;
if (lastDbGateCrash && new Date().getTime() - lastDbGateCrash < 30 * 1000) {
if (

View File

@@ -0,0 +1,25 @@
export function getDatabaseFileLabel(databaseFile) {
if (!databaseFile) return databaseFile;
const m = databaseFile.match(/[\/]([^\/]+)$/);
if (m) return m[1];
return databaseFile;
}
export default function getConnectionLabel(connection, { allowExplicitDatabase = true } = {}) {
if (!connection) {
return null;
}
if (connection.displayName) {
return connection.displayName;
}
if (connection.singleDatabase && connection.server && allowExplicitDatabase && connection.defaultDatabase) {
return `${connection.defaultDatabase} on ${connection.server}`;
}
if (connection.databaseFile) {
return getDatabaseFileLabel(connection.databaseFile);
}
if (connection.server) {
return connection.server;
}
return '';
}

View File

@@ -76,6 +76,18 @@ const databaseListLoader = ({ conid }) => ({
reloadTrigger: `database-list-changed-${conid}`,
});
const serverVersionLoader = ({ conid }) => ({
url: 'server-connections/version',
params: { conid },
reloadTrigger: `server-version-changed-${conid}`,
});
const databaseServerVersionLoader = ({ conid, database }) => ({
url: 'database-connections/server-version',
params: { conid, database },
reloadTrigger: `database-server-version-changed-${conid}-${database}`,
});
const archiveFoldersLoader = () => ({
url: 'archive/folders',
params: {},
@@ -318,6 +330,21 @@ export function useDatabaseList(args) {
return useCore(databaseListLoader, args);
}
export function getServerVersion(args) {
return getCore(serverVersionLoader, args);
}
export function useServerVersion(args) {
return useCore(serverVersionLoader, args);
}
export function getDatabaseServerVersion(args) {
return getCore(databaseServerVersionLoader, args);
}
export function useDatabaseServerVersion(args) {
return useCore(databaseServerVersionLoader, args);
}
export function getServerStatus() {
return getCore(serverStatusLoader, {});
}

View File

@@ -3,19 +3,37 @@ import { get } from 'svelte/store';
import newQuery from '../query/newQuery';
import ImportExportModal from '../modals/ImportExportModal.svelte';
import getElectron from './getElectron';
import { extensions } from '../stores';
import { currentDatabase, extensions } from '../stores';
import { getUploadListener } from './uploadFiles';
import axiosInstance from '../utility/axiosInstance';
import { getDatabaseFileLabel } from './getConnectionLabel';
export function canOpenByElectron(file, extensions) {
if (!file) return false;
const nameLower = file.toLowerCase();
if (nameLower.endsWith('.sql')) return true;
if (nameLower.endsWith('.db') || nameLower.endsWith('.sqlite') || nameLower.endsWith('.sqlite3')) return true;
for (const format of extensions.fileFormats) {
if (nameLower.endsWith(`.${format.extension}`)) return true;
}
return false;
}
export async function openSqliteFile(filePath) {
const defaultDatabase = getDatabaseFileLabel(filePath);
const resp = await axiosInstance.post('connections/save', {
_id: undefined,
databaseFile: filePath,
engine: 'sqlite@dbgate-plugin-sqlite',
singleDatabase: true,
defaultDatabase,
});
currentDatabase.set({
connection: resp.data,
name: getDatabaseFileLabel(filePath),
});
}
export function openElectronFileCore(filePath, extensions) {
const nameLower = filePath.toLowerCase();
const path = window.require('path');
@@ -33,6 +51,11 @@ export function openElectronFileCore(filePath, extensions) {
savedFilePath: filePath,
savedFormat: 'text',
});
return;
}
if (nameLower.endsWith('.db') || nameLower.endsWith('.sqlite') || nameLower.endsWith('.sqlite')) {
openSqliteFile(filePath);
return;
}
for (const format of extensions.fileFormats) {
if (nameLower.endsWith(`.${format.extension}`)) {
@@ -72,8 +95,9 @@ export function openElectronFile() {
const ext = get(extensions);
const filePaths = electron.remote.dialog.showOpenDialogSync(electron.remote.getCurrentWindow(), {
filters: [
{ name: `All supported files`, extensions: ['sql', ...getFileFormatExtensions(ext)] },
{ name: `All supported files`, extensions: ['sql', 'sqlite', 'db', 'sqlite3', ...getFileFormatExtensions(ext)] },
{ name: `SQL files`, extensions: ['sql'] },
{ name: `SQLite database`, extensions: ['sqlite', 'db', 'sqlite3'] },
...getFileFormatFilters(ext),
],
});

View File

@@ -6,6 +6,7 @@ import tabs from '../tabs';
import { setSelectedTabFunc } from './common';
import localforage from 'localforage';
import stableStringify from 'json-stable-stringify';
import { saveAllPendingEditorData } from '../query/useEditorData';
function findFreeNumber(numbers: number[]) {
if (numbers.length == 0) return 1;
@@ -74,9 +75,9 @@ export default async function openNewTab(newTab, initialData = undefined, option
openedTabs.update(files => [
...(files || []).map(x => ({ ...x, selected: false })),
{
...newTab,
tabid,
selected: true,
...newTab,
},
]);
@@ -91,3 +92,35 @@ export default async function openNewTab(newTab, initialData = undefined, option
// },
// ]);
}
export async function duplicateTab(tab) {
await saveAllPendingEditorData();
let title = tab.title;
const mtitle = title.match(/^(.*#)[\d]+$/);
if (mtitle) title = mtitle[1];
const keyRegex = /^tabdata_([^_]+)_([^_]+)$/;
const initialData = {};
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
const m = key.match(keyRegex);
if (m && m[2] == tab.tabid) {
initialData[m[1]] = JSON.parse(localStorage.getItem(key));
}
}
for (const key of await localforage.keys()) {
const m = key.match(keyRegex);
if (m && m[2] == tab.tabid) {
initialData[m[1]] = await localforage.getItem(key);
}
}
openNewTab(
{
..._.omit(tab, ['tabid']),
title,
},
initialData,
{ forceNewTab: true }
);
}

View File

@@ -12,6 +12,7 @@
import axiosInstance from '../utility/axiosInstance';
import ToolbarButton from './ToolbarButton.svelte';
import runCommand from '../commands/runCommand';
import getConnectionLabel from '../utility/getConnectionLabel';
const connections = useConnectionList();
const serverStatus = useServerStatus();
@@ -36,7 +37,7 @@
</SearchBoxWrapper>
<WidgetsInnerContainer>
<AppObjectList
list={_.sortBy(connectionsWithStatus, ({ displayName, server }) => (displayName || server || '').toUpperCase())}
list={_.sortBy(connectionsWithStatus, connection => (getConnectionLabel(connection) || '').toUpperCase())}
module={connectionAppObject}
subItemsComponent={SubDatabaseList}
expandOnClick

View File

@@ -42,7 +42,7 @@
<ErrorInfo message={$status.message} icon="img error" />
<InlineButton on:click={handleRefreshDatabase}>Refresh</InlineButton>
</WidgetsInnerContainer>
{:else if objectList.length == 0 && $status && $status.name != 'pending' && $objects}
{:else if objectList.length == 0 && $status && $status.name != 'pending' && $status.name != 'checkStructure' && $status.name != 'loadStructure' && $objects}
<WidgetsInnerContainer>
<ErrorInfo
message={`Database ${database} is empty or structure is not loaded, press Refresh button to reload structure`}
@@ -56,7 +56,7 @@
<InlineButton on:click={handleRefreshDatabase}>Refresh</InlineButton>
</SearchBoxWrapper>
<WidgetsInnerContainer>
{#if ($status && $status.name == 'pending' && $objects) || !$objects}
{#if ($status && ($status.name == 'pending' || $status.name == 'checkStructure' || $status.name == 'loadStructure') && $objects) || !$objects}
<LoadingInfo message="Loading database structure" />
{:else}
<AppObjectList

View File

@@ -6,10 +6,11 @@
import WidgetsInnerContainer from './WidgetsInnerContainer.svelte';
$: conid = _.get($currentDatabase, 'connection._id');
$: singleDatabase = _.get($currentDatabase, 'connection.singleDatabase');
$: database = _.get($currentDatabase, 'name');
</script>
{#if conid && database}
{#if conid && (database || singleDatabase)}
<SqlObjectList {conid} {database} />
{:else}
<WidgetsInnerContainer>

View File

@@ -15,13 +15,16 @@
import FontIcon from '../icons/FontIcon.svelte';
import { activeTabId, currentDatabase } from '../stores';
import { useDatabaseStatus } from '../utility/metadataLoaders';
import getConnectionLabel from '../utility/getConnectionLabel';
import { useDatabaseServerVersion, useDatabaseStatus } from '../utility/metadataLoaders';
$: databaseName = $currentDatabase && $currentDatabase.name;
$: connection = $currentDatabase && $currentDatabase.connection;
$: status = useDatabaseStatus(connection ? { conid: connection._id, database: databaseName } : {});
$: serverVersion = useDatabaseServerVersion(connection ? { conid: connection._id, database: databaseName } : {});
$: contextItems = $statusBarTabInfo[$activeTabId] as any[];
$: connectionLabel = getConnectionLabel(connection, { allowExplicitDatabase: false });
</script>
<div class="main">
@@ -32,10 +35,10 @@
{databaseName}
</div>
{/if}
{#if connection && (connection.displayName || connection.server)}
{#if connectionLabel}
<div class="item">
<FontIcon icon="icon server" />
{connection.displayName || connection.server}
{connectionLabel}
</div>
{/if}
{#if connection && connection.user}
@@ -48,6 +51,10 @@
<div class="item">
{#if $status.name == 'pending'}
<FontIcon icon="icon loading" /> Loading
{:else if $status.name == 'checkStructure'}
<FontIcon icon="icon loading" /> Checking model
{:else if $status.name == 'loadStructure'}
<FontIcon icon="icon loading" /> Loading model
{:else if $status.name == 'ok'}
<FontIcon icon="img ok-inv" /> Connected
{:else if $status.name == 'error'}
@@ -60,6 +67,14 @@
<FontIcon icon="icon disconnected" /> Not connected
</div>
{/if}
{#if $serverVersion}
<div class="item flex" title={$serverVersion.version}>
<FontIcon icon="icon version" />
<div class="version ml-1">
{$serverVersion.versionText || $serverVersion.version}
</div>
</div>
{/if}
</div>
<div class="container">
{#each contextItems || [] as item}
@@ -86,4 +101,11 @@
.item {
padding: 2px 10px;
}
.version {
max-width: 200px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>

View File

@@ -45,22 +45,34 @@
);
const closeOthers = closeTabFunc((x, active) => x.tabid != active.tabid);
function getTabDbName(tab) {
function getTabDbName(tab, connectionList) {
if (tab.props && tab.props.conid && tab.props.database) return tab.props.database;
if (tab.props && tab.props.conid) {
const connection = connectionList?.find(x => x._id == tab.props.conid);
if (connection) return getConnectionLabel(connection.displayName, { allowExplicitDatabase: false });
return '???';
}
if (tab.props && tab.props.archiveFolder) return tab.props.archiveFolder;
return '(no DB)';
}
function getTabDbKey(tab) {
if (tab.props && tab.props.conid && tab.props.database)
if (tab.props && tab.props.conid && tab.props.database) {
return `database://${tab.props.database}-${tab.props.conid}`;
if (tab.props && tab.props.archiveFolder) return `archive://${tab.props.archiveFolder}`;
}
if (tab.props && tab.props.conid) {
return `server://${tab.props.conid}`;
}
if (tab.props && tab.props.archiveFolder) {
return `archive://${tab.props.archiveFolder}`;
}
return '_no';
}
function getDbIcon(key) {
if (key.startsWith('database://')) return 'icon database';
if (key.startsWith('archive://')) return 'icon archive';
if (key.startsWith('server://')) return 'icon server';
return 'icon file';
}
@@ -87,9 +99,9 @@
registerCommand({
id: 'tabs.addToFavorites',
category: 'Tabs',
name: 'Favorites',
icon: 'icon favorite',
toolbar: true,
name: 'Add current tab to favorites',
// icon: 'icon favorite',
// toolbar: true,
testEnabled: () =>
getActiveTab()?.tabComponent &&
tabs[getActiveTab()?.tabComponent] &&
@@ -112,18 +124,24 @@
import tabs from '../tabs';
import { setSelectedTab } from '../utility/common';
import contextMenu from '../utility/contextMenu';
import { getConnectionInfo } from '../utility/metadataLoaders';
import getConnectionLabel from '../utility/getConnectionLabel';
import { getConnectionInfo, useConnectionList } from '../utility/metadataLoaders';
import { duplicateTab } from '../utility/openNewTab';
$: connectionList = useConnectionList();
$: currentDbKey =
$currentDatabase && $currentDatabase.name && $currentDatabase.connection
? `database://${$currentDatabase.name}-${$currentDatabase.connection._id}`
: $currentDatabase && $currentDatabase.connection
? `server://${$currentDatabase.connection._id}`
: '_no';
$: tabsWithDb = $openedTabs
.filter(x => !x.closedTime)
.map(tab => ({
...tab,
tabDbName: getTabDbName(tab),
tabDbName: getTabDbName(tab, $connectionList),
tabDbKey: getTabDbKey(tab),
}));
@@ -146,9 +164,10 @@
}
};
const getContextMenu = (tabid, props) => () => {
const getContextMenu = tab => () => {
const { tabid, props, tabComponent } = tab;
const { conid, database } = props || {};
const res = [
return [
{
text: 'Close',
onClick: () => closeTab(tabid),
@@ -161,20 +180,33 @@
text: 'Close others',
onClick: () => closeOthers(tabid),
},
{
text: 'Duplicate',
onClick: () => duplicateTab(tab),
},
tabComponent &&
tabs[tabComponent] &&
tabs[tabComponent].allowAddToFavorites &&
tabs[tabComponent].allowAddToFavorites(props) && [
{ divider: true },
{
text: 'Add to favorites',
onClick: () => showModal(FavoriteModal, { savingTab: tab }),
},
],
conid &&
database && [
{ divider: true },
{
text: `Close with same DB - ${database}`,
onClick: () => closeWithSameDb(tabid),
},
{
text: `Close with other DB than ${database}`,
onClick: () => closeWithOtherDb(tabid),
},
],
];
if (conid && database) {
res.push(
{
text: `Close with same DB - ${database}`,
onClick: () => closeWithSameDb(tabid),
},
{
text: `Close with other DB than ${database}`,
onClick: () => closeWithOtherDb(tabid),
}
);
}
return res;
};
const handleSetDb = async props => {
@@ -216,7 +248,7 @@
class:selected={tab.selected}
on:click={e => handleTabClick(e, tab.tabid)}
on:mouseup={e => handleMouseUp(e, tab.tabid)}
use:contextMenu={getContextMenu(tab.tabid, tab.props)}
use:contextMenu={getContextMenu(tab)}
>
<FontIcon icon={tab.busy ? 'icon loading' : tab.icon} />
<span class="file-name">

View File

@@ -10,7 +10,8 @@
import _ from 'lodash';
import { openFavorite } from '../appobj/FavoriteFileAppObject.svelte';
import runCommand from '../commands/runCommand';
import { commands, commandsCustomized } from '../stores';
import FontIcon from '../icons/FontIcon.svelte';
import { activeTab, commands, commandsCustomized } from '../stores';
import getElectron from '../utility/getElectron';
import { useFavorites } from '../utility/metadataLoaders';
import ToolbarButton from './ToolbarButton.svelte';
@@ -25,26 +26,48 @@
);
</script>
<div class="container">
{#if !electron}
<ToolbarButton externalImage="logo192.png" on:click={() => runCommand('about.show')} />
{/if}
{#each ($favorites || []).filter(x => x.showInToolbar) as item}
<ToolbarButton on:click={() => openFavorite(item)} icon={item.icon || 'icon favorite'}>
{item.title}
</ToolbarButton>
{/each}
<div class="root">
<div class="container">
{#if !electron}
<ToolbarButton externalImage="logo192.png" on:click={() => runCommand('about.show')} />
{/if}
{#each ($favorites || []).filter(x => x.showInToolbar) as item}
<ToolbarButton on:click={() => openFavorite(item)} icon={item.icon || 'icon favorite'}>
{item.title}
</ToolbarButton>
{/each}
{#each list as command}
<ToolbarButton
icon={command.icon}
on:click={command.onClick}
disabled={!command.enabled}
title={getCommandTitle(command)}
>
{command.toolbarName || command.name}
</ToolbarButton>
{/each}
{#each list.filter(x => !x.isRelatedToTab) as command}
<ToolbarButton
icon={command.icon}
on:click={command.onClick}
disabled={!command.enabled}
title={getCommandTitle(command)}
>
{command.toolbarName || command.name}
</ToolbarButton>
{/each}
</div>
<div class="container">
{#if $activeTab && list.filter(x => x.isRelatedToTab).length > 0}
<div class="activeTab">
<div class="activeTabInner">
<FontIcon icon={$activeTab.icon} />
{$activeTab.title}:
</div>
</div>
{/if}
{#each list.filter(x => x.isRelatedToTab) as command}
<ToolbarButton
icon={command.icon}
on:click={command.onClick}
disabled={!command.enabled}
title={getCommandTitle(command)}
>
{command.toolbarName || command.name}
</ToolbarButton>
{/each}
</div>
</div>
<style>
@@ -54,4 +77,21 @@
align-items: stretch;
height: var(--dim-toolbar-height);
}
.root {
display: flex;
align-items: stretch;
justify-content: space-between;
}
.activeTab {
background-color: var(--theme-bg-2);
white-space: nowrap;
display: flex;
padding-left: 15px;
padding-right: 15px;
}
.activeTabInner {
align-self: center;
}
</style>

View File

@@ -0,0 +1,13 @@
diff --git a/node_modules/sql-query-identifier/lib/tokenizer.js b/node_modules/sql-query-identifier/lib/tokenizer.js
index f8980fe..bb03059 100644
--- a/node_modules/sql-query-identifier/lib/tokenizer.js
+++ b/node_modules/sql-query-identifier/lib/tokenizer.js
@@ -249,7 +249,7 @@ function skipWord(state, value) {
};
}
function isWhitespace(ch) {
- return ch === ' ' || ch === '\t' || ch === '\n';
+ return ch === ' ' || ch === '\t' || ch === '\n' || ch == '\r';
}
function isString(ch, dialect) {
const stringStart = dialect === 'mysql' ? ["'", '"'] : ["'"];

View File

@@ -0,0 +1,13 @@
diff --git a/node_modules/svelte/internal/index.js b/node_modules/svelte/internal/index.js
index ee20a17..7b6fff8 100644
--- a/node_modules/svelte/internal/index.js
+++ b/node_modules/svelte/internal/index.js
@@ -200,7 +200,7 @@ function insert(target, node, anchor) {
target.insertBefore(node, anchor || null);
}
function detach(node) {
- node.parentNode.removeChild(node);
+ if (node.parentNode) node.parentNode.removeChild(node);
}
function destroy_each(iterations, detaching) {
for (let i = 0; i < iterations.length; i += 1) {

View File

@@ -8,14 +8,11 @@ class Analyser extends DatabaseAnalyser {
async _runAnalysis() {
const collections = await this.pool.__getDatabase().listCollections().toArray();
const res = this.mergeAnalyseResult(
{
collections: collections.map((x) => ({
pureName: x.name,
})),
},
(x) => x.pureName
);
const res = this.mergeAnalyseResult({
collections: collections.map((x) => ({
pureName: x.name,
})),
});
// console.log('MERGED', res);
return res;
}

View File

@@ -178,7 +178,10 @@ const driver = {
},
async getVersion(pool) {
const status = await pool.__getDatabase().admin().serverInfo();
return status;
return {
...status,
versionText: `MongoDB ${status.version}`,
};
},
async listDatabases(pool) {
const res = await pool.__getDatabase().admin().listDatabases();

View File

@@ -11,6 +11,24 @@ const { tediousConnect, tediousQueryCore, tediousReadQuery, tediousStream } = re
const { nativeConnect, nativeQueryCore, nativeReadQuery, nativeStream } = nativeDriver;
let msnodesqlv8;
const versionQuery = `
SELECT
@@VERSION AS version,
SERVERPROPERTY ('productversion') as productVersion,
CASE
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '8%' THEN 'SQL Server 2000'
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '9%' THEN 'SQL Server 2005'
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '10.0%' THEN 'SQL Server 2008'
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '10.5%' THEN 'SQL Server 2008 R2'
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '11%' THEN 'SQL Server 2012'
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '12%' THEN 'SQL Server 2014'
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '13%' THEN 'SQL Server 2016'
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '14%' THEN 'SQL Server 2017'
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '15%' THEN 'SQL Server 2019'
ELSE 'Unknown'
END AS versionText
`;
const windowsAuthTypes = [
{
title: 'Windows',
@@ -79,8 +97,16 @@ const driver = {
}
},
async getVersion(pool) {
const { version } = (await this.query(pool, 'SELECT @@VERSION AS version')).rows[0];
return { version };
const res = (await this.query(pool, versionQuery)).rows[0];
if (res.productVersion) {
const splitted = res.productVersion.split('.');
const number = parseInt(splitted[0]) || 0;
res.productVersionNumber = number;
} else {
res.productVersionNumber = 0;
}
return res;
},
async listDatabases(pool) {
const { rows } = await this.query(pool, 'SELECT name FROM sys.databases order by name');

View File

@@ -6,6 +6,7 @@ const dialect = {
limitSelect: true,
rangeSelect: true,
offsetFetchRangeSyntax: true,
rowNumberOverPaging: true,
stringEscapeChar: "'",
fallbackDataType: 'nvarchar(max)',
explicitDropConstraint: false,
@@ -21,6 +22,16 @@ const driver = {
...driverBase,
dumperClass: MsSqlDumper,
dialect,
dialectByVersion(version) {
if (version && version.productVersionNumber < 11) {
return {
...dialect,
rangeSelect: false,
offsetFetchRangeSyntax: false,
};
}
return dialect;
},
engine: 'mssql@dbgate-plugin-mssql',
title: 'Microsoft SQL Server',
defaultPort: 1433,

View File

@@ -66,14 +66,7 @@ class Analyser extends DatabaseAnalyser {
}
getRequestedViewNames(allViewNames) {
if (this.singleObjectFilter) {
const { typeField, pureName } = this.singleObjectFilter;
if (typeField == 'views') return [pureName];
}
if (this.modifications) {
return this.modifications.filter(x => x.objectTypeField == 'views').map(x => x.newName.pureName);
}
return allViewNames;
return this.getRequestedObjectPureNames('views', allViewNames);
}
async getViewTexts(allViewNames) {
@@ -82,7 +75,7 @@ class Analyser extends DatabaseAnalyser {
try {
const resp = await this.driver.query(this.pool, `SHOW CREATE VIEW \`${viewName}\``);
res[viewName] = resp.rows[0]['Create View'];
} catch(err) {
} catch (err) {
console.log('ERROR', err);
res[viewName] = `${err}`;
}

View File

@@ -171,7 +171,10 @@ const driver = {
async getVersion(connection) {
const { rows } = await this.query(connection, "show variables like 'version'");
const version = rows[0].Value;
return { version };
return {
version,
versionText: `MySQL ${version}`,
};
},
async listDatabases(connection) {
const { rows } = await this.query(connection, 'show databases');

View File

@@ -31,11 +31,12 @@
},
"devDependencies": {
"dbgate-plugin-tools": "^1.0.7",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11",
"dbgate-tools": "^4.1.1",
"lodash": "^4.17.15",
"pg": "^7.17.0",
"pg-query-stream": "^3.1.1"
"pg-query-stream": "^3.1.1",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11",
"sql-query-identifier": "^2.1.0"
}
}
}

View File

@@ -1,10 +1,12 @@
const _ = require('lodash');
const stream = require('stream');
const { identify } = require('sql-query-identifier');
const driverBase = require('../frontend/driver');
const Analyser = require('./Analyser');
const pg = require('pg');
const pgQueryStream = require('pg-query-stream');
const { createBulkInsertStreamBase, splitPostgresQuery, makeUniqueColumnNames } = require('dbgate-tools');
const { createBulkInsertStreamBase, makeUniqueColumnNames } = require('dbgate-tools');
function extractPostgresColumns(result) {
if (!result || !result.fields) return [];
@@ -97,6 +99,7 @@ const driver = {
async connect({ server, port, user, password, database, ssl }) {
const client = new pg.Client({
// connectionString: 'postgres://root@localhost:26257/postgres?sslmode=disabke'
host: server,
port,
user,
@@ -119,10 +122,16 @@ const driver = {
return { rows: res.rows.map(row => zipDataRow(row, columns)), columns };
},
async stream(client, sql, options) {
const sqlSplitted = splitPostgresQuery(sql);
let sqlSplitted;
try {
sqlSplitted = identify(sql, { dialect: 'psql', strict: false });
} catch (e) {
// workaround
sqlSplitted = [{ text: sql }];
}
for (const sqlItem of sqlSplitted) {
await runStreamItem(client, sqlItem, options);
await runStreamItem(client, sqlItem.text, options);
}
options.done();
@@ -141,7 +150,10 @@ const driver = {
async getVersion(client) {
const { rows } = await this.query(client, 'SELECT version()');
const { version } = rows[0];
return { version };
return {
version,
versionText: (version || '').replace(/\s*\(.*$/, ''),
};
},
// async analyseFull(pool) {
// const analyser = new PostgreAnalyser(pool, this);

View File

@@ -8,8 +8,8 @@ select
from
information_schema.routines where routine_schema != 'information_schema' and routine_schema != 'pg_catalog'
and (
(routine_type = 'PROCEDURE' and ('procedures:' || routine_schema || '.' || routine_schema) =OBJECT_ID_CONDITION)
(routine_type = 'PROCEDURE' and ('procedures:' || routine_schema || '.' || routine_name) =OBJECT_ID_CONDITION)
or
(routine_type = 'FUNCTION' and ('functions:' || routine_schema || '.' || routine_schema) =OBJECT_ID_CONDITION)
(routine_type = 'FUNCTION' and ('functions:' || routine_schema || '.' || routine_name) =OBJECT_ID_CONDITION)
)
`;

View File

@@ -1,9 +1,9 @@
module.exports = `
with pkey as
(
select cc.conrelid, format(E'create constraint %I primary key(%s);\\n', cc.conname,
string_agg(a.attname, ', '
order by array_position(cc.conkey, a.attnum))) pkey
select cc.conrelid, 'create constraint ' || cc.conname || ' primary key(' ||
string_agg(a.attname, ', ' order by array_position(cc.conkey, a.attnum)) || ');\\n'
pkey
from pg_catalog.pg_constraint cc
join pg_catalog.pg_class c on c.oid = cc.conrelid
join pg_catalog.pg_attribute a on a.attrelid = cc.conrelid
@@ -47,6 +47,8 @@ from
AND n.nspname !~ '^pg_toast'
ORDER BY a.attnum
) as tabledefinition
inner join information_schema.tables on tables.table_schema = tabledefinition.nspname and tables.table_name = tabledefinition.relname
and tables.table_type not like '%VIEW%'
where ('tables:' || nspname || '.' || relname) =OBJECT_ID_CONDITION
group by relname, nspname, oid
`;

25
plugins/dbgate-plugin-sqlite/.gitignore vendored Normal file
View File

@@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
build
dist
lib
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

View File

@@ -0,0 +1,6 @@
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![NPM version](https://img.shields.io/npm/v/dbgate-plugin-sqlite.svg)](https://www.npmjs.com/package/dbgate-plugin-sqlite)
# dbgate-plugin-sqlite
Use DbGate for install of this plugin

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 384 384" style="enable-background:new 0 0 384 384;" xml:space="preserve">
<polygon style="fill:#EFEEEE;" points="64,0 64,384 288,384 384,288 384,0 "/>
<polygon style="fill:#ABABAB;" points="288,288 288,384 384,288 "/>
<polygon style="fill:#DEDEDD;" points="192,384 288,384 288,288 "/>
<path style="fill:#448E47;" d="M0,96v112h256V96L0,96L0,96z"/>
<g>
<path style="fill:#FFFFFF;" d="M64.32,130.112c-1.184-2.288-3.344-3.424-6.48-3.424c-1.728,0-3.152,0.464-4.272,1.408
c-1.12,0.928-2,2.416-2.64,4.496s-1.088,4.8-1.344,8.176c-0.272,3.36-0.384,7.472-0.384,12.336c0,5.184,0.176,9.376,0.528,12.576
c0.336,3.2,0.896,5.664,1.632,7.44s1.664,2.96,2.784,3.552c1.12,0.608,2.416,0.928,3.888,0.928c1.216,0,2.352-0.208,3.408-0.624
s1.968-1.248,2.736-2.496c0.784-1.248,1.392-3.008,1.824-5.28c0.448-2.272,0.672-5.264,0.672-8.976H80.48
c0,3.696-0.288,7.232-0.864,10.56s-1.664,6.24-3.216,8.736c-1.584,2.48-3.776,4.432-6.624,5.84
c-2.848,1.408-6.544,2.128-11.088,2.128c-5.168,0-9.312-0.848-12.368-2.496c-3.072-1.664-5.424-4.064-7.056-7.2
s-2.688-6.88-3.168-11.232c-0.464-4.336-0.72-9.152-0.72-14.384c0-5.184,0.256-9.968,0.72-14.352
c0.48-4.368,1.552-8.144,3.168-11.28c1.648-3.12,3.984-5.584,7.056-7.344c3.056-1.744,7.2-2.64,12.368-2.64
c4.944,0,8.816,0.8,11.664,2.4c2.848,1.6,4.976,3.632,6.368,6.096s2.304,5.12,2.64,7.968c0.352,2.848,0.528,5.52,0.528,8.016H66.08
C66.08,136,65.488,132.368,64.32,130.112z"/>
<path style="fill:#FFFFFF;" d="M109.072,167.008c0,1.6,0.144,3.056,0.384,4.352c0.272,1.312,0.736,2.416,1.44,3.312
c0.704,0.912,1.664,1.616,2.848,2.128c1.168,0.496,2.672,0.768,4.448,0.768c2.128,0,4.016-0.688,5.712-2.064
c1.68-1.376,2.544-3.52,2.544-6.384c0-1.536-0.224-2.864-0.624-3.984c-0.416-1.12-1.104-2.128-2.064-3.008
c-0.976-0.912-2.24-1.712-3.792-2.448s-3.504-1.488-5.808-2.256c-3.056-1.024-5.712-2.16-7.968-3.376
c-2.24-1.2-4.112-2.624-5.616-4.272c-1.504-1.632-2.608-3.52-3.312-5.664c-0.704-2.16-1.056-4.624-1.056-7.456
c0-6.784,1.888-11.824,5.664-15.152c3.76-3.328,8.96-4.992,15.552-4.992c3.072,0,5.904,0.336,8.496,1.008s4.832,1.744,6.72,3.264
c1.888,1.504,3.36,3.424,4.416,5.744c1.04,2.336,1.584,5.136,1.584,8.4v1.92h-13.232c0-3.264-0.576-5.776-1.712-7.552
c-1.152-1.744-3.072-2.64-5.76-2.64c-1.536,0-2.816,0.24-3.84,0.672c-1.008,0.448-1.84,1.04-2.448,1.776s-1.04,1.616-1.264,2.576
c-0.24,0.96-0.336,1.952-0.336,2.976c0,2.128,0.448,3.888,1.344,5.328c0.896,1.456,2.816,2.784,5.76,3.984l10.656,4.608
c2.624,1.152,4.768,2.352,6.416,3.616c1.664,1.248,3.008,2.592,3.984,4.032c0.992,1.44,1.68,3.008,2.064,4.752
c0.384,1.712,0.576,3.648,0.576,5.744c0,7.232-2.096,12.496-6.288,15.792c-4.192,3.296-10.032,4.96-17.52,4.96
c-7.808,0-13.392-1.696-16.768-5.088c-3.36-3.392-5.024-8.256-5.024-14.592v-2.784h13.824L109.072,167.008L109.072,167.008z"/>
<path style="fill:#FFFFFF;" d="M177.344,168.544h0.304l10.176-50.688h14.32L186.4,186.4h-17.76l-15.728-68.544h14.784
L177.344,168.544z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@@ -0,0 +1,33 @@
{
"name": "dbgate-plugin-sqlite",
"main": "dist/backend.js",
"version": "1.0.0",
"license": "MIT",
"keywords": [
"dbgate",
"dbgateplugin",
"sqlite"
],
"files": [
"dist"
],
"scripts": {
"build:frontend": "webpack --config webpack-frontend.config",
"build:frontend:watch": "webpack --watch --config webpack-frontend.config",
"build:backend": "webpack --config webpack-backend.config.js",
"build": "yarn build:frontend && yarn build:backend",
"plugin": "yarn build && yarn pack && dbgate-plugin dbgate-plugin-sqlite",
"copydist": "yarn build && yarn pack && dbgate-copydist ../dist/dbgate-plugin-sqlite",
"plugout": "dbgate-plugout dbgate-plugin-sqlite",
"prepublishOnly": "yarn build"
},
"devDependencies": {
"dbgate-tools": "^4.1.1",
"dbgate-plugin-tools": "^1.0.4",
"byline": "^5.0.0",
"sql-query-identifier": "^2.1.0",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11"
}
}

View File

@@ -0,0 +1,8 @@
module.exports = {
trailingComma: 'es5',
tabWidth: 2,
semi: true,
singleQuote: true,
arrowParen: 'avoid',
printWidth: 120,
};

View File

@@ -0,0 +1,82 @@
const _ = require('lodash');
const { DatabaseAnalyser } = require('dbgate-tools');
class Analyser extends DatabaseAnalyser {
constructor(pool, driver) {
super(pool, driver);
}
async _runAnalysis() {
const tables = await this.driver.query(this.pool, "select * from sqlite_master where type='table'");
// console.log('TABLES', tables);
const tableSqls = _.zipObject(
tables.rows.map((x) => x.name),
tables.rows.map((x) => x.sql)
);
const tableList = tables.rows.map((x) => ({
pureName: x.name,
objectId: x.name,
}));
for (const tableName of this.getRequestedObjectPureNames(
'tables',
tables.rows.map((x) => x.name)
)) {
const tableObj = tableList.find((x) => x.pureName == tableName);
if (!tableObj) continue;
const info = await this.driver.query(this.pool, `pragma table_info('${tableName}')`);
tableObj.columns = info.rows.map((col) => ({
columnName: col.name,
dataType: col.type,
notNull: !!col.notnull,
defaultValue: col.dflt_value == null ? undefined : col.dflt_value,
autoIncrement: tableSqls[tableName].toLowerCase().includes('autoincrement') && !!col.pk,
}));
const pkColumns = info.rows
.filter((x) => x.pk)
.map((col) => ({
columnName: col.name,
}));
if (pkColumns.length > 0) {
tableObj.primaryKey = {
columns: pkColumns,
};
}
const fklist = await this.driver.query(this.pool, `pragma foreign_key_list('${tableName}')`);
tableObj.foreignKeys = _.values(_.groupBy(fklist.rows, 'id')).map((fkcols) => {
const fkcol = fkcols[0];
const fk = {
pureName: tableName,
refTableName: fkcol.table,
columns: fkcols.map((col) => ({
columnName: col.from,
refColumnName: col.to,
})),
updateAction: fkcol.on_update,
deleteAction: fkcol.on_delete,
constraintName: `FK_${tableName}_${fkcol.id}`,
};
return fk;
});
// console.log(info);
}
const res = this.mergeAnalyseResult(
{
tables: tableList,
},
(x) => x.pureName
);
// console.log('MERGED', res);
return res;
}
}
module.exports = Analyser;

View File

@@ -0,0 +1,170 @@
const _ = require('lodash');
const stream = require('stream');
const driverBase = require('../frontend/driver');
const Analyser = require('./Analyser');
const { identify } = require('sql-query-identifier');
const { createBulkInsertStreamBase, makeUniqueColumnNames } = require('dbgate-tools');
let Database;
async function waitForDrain(stream) {
return new Promise((resolve) => {
stream.once('drain', () => {
// console.log('CONTINUE DRAIN');
resolve();
});
});
}
function runStreamItem(client, sql, options, rowCounter) {
const stmt = client.prepare(sql);
if (stmt.reader) {
const columns = stmt.columns();
// const rows = stmt.all();
options.recordset(
columns.map((col) => ({
columnName: col.name,
dataType: col.type,
}))
);
for (const row of stmt.iterate()) {
options.row(row);
}
} else {
const info = stmt.run();
rowCounter.count += info.changes;
if (!rowCounter.date) rowCounter.date = new Date().getTime();
if (new Date().getTime() > rowCounter.date > 1000) {
options.info({
message: `${rowCounter.count} rows affected`,
time: new Date(),
severity: 'info',
});
rowCounter.count = 0;
rowCounter.date = null;
}
}
}
/** @type {import('dbgate-types').EngineDriver} */
const driver = {
...driverBase,
analyserClass: Analyser,
async connect({ databaseFile }) {
const pool = new Database(databaseFile);
return pool;
},
// @ts-ignore
async query(pool, sql) {
const stmt = pool.prepare(sql);
// stmt.raw();
if (stmt.reader) {
const columns = stmt.columns();
const rows = stmt.all();
return {
rows,
columns: columns.map((col) => ({
columnName: col.name,
dataType: col.type,
})),
};
} else {
stmt.run();
return {
rows: [],
columns: [],
};
}
},
async stream(client, sql, options) {
const sqlSplitted = identify(sql, { dialect: 'sqlite', strict: false });
const rowCounter = { count: 0, date: null };
const inTransaction = client.transaction(() => {
for (const sqlItem of sqlSplitted) {
runStreamItem(client, sqlItem.text, options, rowCounter);
}
if (rowCounter.date) {
options.info({
message: `${rowCounter.count} rows affected`,
time: new Date(),
severity: 'info',
});
}
});
try {
inTransaction();
} catch (error) {
console.log('ERROR', error);
const { message, lineNumber, procName } = error;
options.info({
message,
line: lineNumber,
procedure: procName,
time: new Date(),
severity: 'error',
});
}
options.done();
// return stream;
},
async readQueryTask(stmt, pass) {
// let sent = 0;
for (const row of stmt.iterate()) {
// sent++;
if (!pass.write(row)) {
// console.log('WAIT DRAIN', sent);
await waitForDrain(pass);
}
}
pass.end();
},
async readQuery(pool, sql, structure) {
const pass = new stream.PassThrough({
objectMode: true,
highWaterMark: 100,
});
const stmt = pool.prepare(sql);
const columns = stmt.columns();
pass.write({
__isStreamHeader: true,
...(structure || {
columns: columns.map((col) => ({
columnName: col.name,
dataType: col.type,
})),
}),
});
this.readQueryTask(stmt, pass);
return pass;
},
async writeTable(pool, name, options) {
return createBulkInsertStreamBase(this, stream, pool, name, options);
},
async getVersion(pool) {
const { rows } = await this.query(pool, 'select sqlite_version() as version');
const { version } = rows[0];
return {
version,
versionText: `SQLite ${version}`,
};
},
};
driver.initialize = (dbgateEnv) => {
if (dbgateEnv.nativeModules && dbgateEnv.nativeModules['better-sqlite3-with-prebuilds']) {
Database = dbgateEnv.nativeModules['better-sqlite3-with-prebuilds']();
}
};
module.exports = driver;

View File

@@ -0,0 +1,9 @@
const driver = require('./driver');
module.exports = {
packageName: 'dbgate-plugin-sqlite',
driver,
initialize(dbgateEnv) {
driver.initialize(dbgateEnv);
},
};

Some files were not shown because too many files have changed in this diff Show More