Skip to content
This repository was archived by the owner on Mar 12, 2020. It is now read-only.

Commit 7975d31

Browse files
committed
Added default db selection on startup
1 parent 95fa5ed commit 7975d31

File tree

6 files changed

+102
-21
lines changed

6 files changed

+102
-21
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,39 @@ In case your database command is not in your `PATH` enviroment var, you can set
5353
| `pgsql` | `"psql"` |
5454
| `oracle` | `"sqlplus"` |
5555
| `vertica` | `"vsql"` |
56+
57+
## Connections
58+
59+
SQLToolConnections.sublime-settings example:
60+
61+
```json
62+
{
63+
"connections": {
64+
"Connection 1": {
65+
"type" : "mysql",
66+
"host" : "127.0.0.1",
67+
"port" : 3306,
68+
"username": "user",
69+
"password": "password",
70+
"database": "dbname"
71+
},
72+
"Connection 2": {
73+
"type" : "pgsql",
74+
"host" : "127.0.0.1",
75+
"port" : 5432,
76+
"username": "anotheruser",
77+
"database": "dbname"
78+
},
79+
"Connection 2": {
80+
"type" : "oracle",
81+
"host" : "127.0.0.1",
82+
"port" : 1522,
83+
"username": "anotheruser",
84+
"password": "password",
85+
"database": "dbname",
86+
"service" : "servicename"
87+
}
88+
},
89+
"default": "Connection 1"
90+
}
91+
```

SQLTool.py renamed to SQLTools.py

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
1-
21
import sublime, sublime_plugin, tempfile, os, subprocess, threading, signal, sys
32

4-
from SQLTools import const
5-
from SQLTools.lib.connection import Connection
6-
from SQLTools.lib.command import Command
7-
from SQLTools.lib.general import Selection, Options, Log
3+
from os.path import dirname
4+
sys.path.append(dirname(__file__))
5+
6+
from lib import const
7+
from lib.connection import Connection
8+
from lib.command import Command
9+
from lib.general import Selection, Options, Log
810

911
if sys.version_info >= (3, 0):
10-
from SQLTools import sqlparse3 as sqlparse
12+
import sqlparse3 as sqlparse
1113
else:
12-
from SQLTools import sqlparse2 as sqlparse
14+
import sqlparse2 as sqlparse
1315

14-
connection = None
15-
history = ['']
16+
connection = None
17+
history = ['']
18+
tableNames = []
1619

1720
def sqlChangeConnection(index):
1821
global connection
19-
names = Options.list()
20-
options = Options(names[index])
22+
global tableNames
23+
names = Options.list()
24+
options = Options(names[index])
2125
connection = Connection(options)
26+
tableNames = connection.desc()
2227
sublime.status_message('ST: Connection switched to %s' % names[index])
2328

2429
def showTableRecords(index):
2530
global connection
31+
global tableNames
2632
if index > -1:
2733
if connection != None:
2834
tables = connection.desc()
@@ -143,3 +149,31 @@ def run(self, edit):
143149
self.replace_region_with_formatted_sql(edit, region)
144150

145151
Log.debug("Package Loaded")
152+
153+
154+
# class SqlCompletePlugin(sublime_plugin.EventListener):
155+
# def on_query_completions(self, view, prefix, locations):
156+
# return self.get_autocomplete_list(prefix)
157+
158+
# def get_autocomplete_list(self, word):
159+
# global tableNames
160+
# completions = list(set(tableNames))
161+
# completions.sort()
162+
# # return the array
163+
# print (word)
164+
# autocomplete_list = []
165+
# for w in tableNames:
166+
# try:
167+
# if word.lower() in w.lower():
168+
# autocomplete_list.append((w, w))
169+
# except UnicodeDecodeError:
170+
# continue
171+
172+
# return autocomplete_list
173+
174+
if sublime.load_settings(const.connectionsFilename).get("default", False):
175+
default = sublime.load_settings(const.connectionsFilename).get("default")
176+
Log.debug("Default database set to " + default)
177+
dbs = Options.list()
178+
index = dbs.index(default)
179+
sqlChangeConnection(index)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"connections": {}
2+
"connections": {},
3+
"default": null
34
}

lib/command.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import sublime, os, subprocess, threading, signal
1+
import sublime, os, subprocess, threading, signal, sys
22

3-
from SQLTools import const
4-
from SQLTools.lib.general import Log
3+
from os.path import dirname
4+
sys.path.append(dirname(dirname(__file__)))
5+
6+
from lib import const
7+
from lib.general import Log
58

69
class Command(threading.Thread):
710
def __init__(self, text, tempfile=None):

lib/connection.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import sublime, tempfile
1+
import sublime, tempfile, sys
22

3-
from SQLTools import const
4-
from SQLTools.lib.command import Command
5-
from SQLTools.lib.general import Log
3+
from os.path import dirname
4+
sys.path.append(dirname(dirname(__file__)))
5+
6+
from lib import const
7+
from lib.command import Command
8+
from lib.general import Log
69

710
class Connection:
811
def __init__(self, options):

lib/general.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import sublime
2-
from SQLTools import const
1+
import sublime, sys
2+
3+
from os.path import dirname
4+
sys.path.append(dirname(dirname(__file__)))
5+
6+
from lib import const
37

48
class Selection:
59
def __init__(self, view):

0 commit comments

Comments
 (0)