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

Commit a36f196

Browse files
committed
Preparing for ST2 port
1 parent 53d296e commit a36f196

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
*.pyc
3+
*.sublime-workspace

SQLTools.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import sublime, sublime_plugin
1+
import sublime, sublime_plugin, sys, os
22

3-
from .SQLToolsModels import Log, Settings, Connection, Selection, Window, View, Const, History
3+
sys.path.append(os.path.dirname(__file__))
4+
from SQLToolsModels import Log, Settings, Connection, Selection, Window, View, Const, History
45

56
class ST(sublime_plugin.EventListener):
67
conn = None
@@ -10,17 +11,20 @@ class ST(sublime_plugin.EventListener):
1011
connectionList = {}
1112
autoCompleteList = []
1213

14+
@staticmethod
1315
def bootstrap():
1416
ST.connectionList = Settings.getConnections()
1517
ST.checkDefaultConnection()
1618

19+
@staticmethod
1720
def loadConnectionData():
1821
if not ST.conn:
1922
return
2023

2124
ST.conn.getTables(lambda tables: setattr(ST, 'tables', tables))
2225
ST.conn.getColumns(lambda columns: setattr(ST, 'columns', columns))
2326

27+
@staticmethod
2428
def setConnection(index):
2529
if index < 0 or index > (len(ST.connectionList) - 1) :
2630
return
@@ -33,6 +37,7 @@ def setConnection(index):
3337

3438
Log.debug('Connection {0} selected'.format(ST.conn))
3539

40+
@staticmethod
3641
def showConnectionMenu():
3742
ST.connectionList = Settings.getConnections()
3843
if len(ST.connectionList) == 0:
@@ -74,6 +79,7 @@ def getAutoCompleteList(self, word):
7479
ST.autoCompleteList.sort()
7580
return (ST.autoCompleteList, sublime.INHIBIT_EXPLICIT_COMPLETIONS)
7681

82+
@staticmethod
7783
def checkDefaultConnection():
7884
default = Connection.loadDefaultConnectionName()
7985
if not default:
@@ -84,6 +90,7 @@ def checkDefaultConnection():
8490
except Exception as e:
8591
Log.debug("Invalid connection setted")
8692

93+
@staticmethod
8794
def display(content, name="SQLTools Result"):
8895
if not sublime.load_settings(Const.SETTINGS_FILENAME).get('show_result_on_window'):
8996
resultContainer = Window().create_output_panel(name)

SQLTools.sublime-settings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"mysql" : "mysql",
1111
"pgsql" : "psql",
1212
"oracle" : "sqlplus",
13-
"vertica" : "vsql",
13+
"vertica" : "vsql"
1414
},
1515
"show_records" : {
1616
"limit" : 50

SQLToolsModels.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def getConnections():
3535

3636
return connections
3737

38+
@staticmethod
3839
def userFolder():
3940
return '{0}/User'.format(sublime.packages_path())
4041

@@ -44,20 +45,24 @@ class Storage:
4445
savedQueries = None
4546
selectedQuery = ''
4647

48+
@staticmethod
4749
def getSavedQueries():
4850
Storage.savedQueries = sublime.load_settings(Const.USER_QUERIES_FILENAME)
4951
return Storage.savedQueries
5052

53+
@staticmethod
5154
def flushSavedQueries():
5255
if not Storage.savedQueries:
5356
Storage.getSavedQueries()
5457

5558
return sublime.save_settings(Const.USER_QUERIES_FILENAME)
5659

60+
@staticmethod
5761
def promptQueryAlias():
5862
Storage.selectedQuery = Selection.get()
5963
Window().show_input_panel('Query alias', '', Storage.saveQuery, None, None)
6064

65+
@staticmethod
6166
def saveQuery(alias):
6267
if len(alias) <= 0:
6368
return
@@ -67,6 +72,7 @@ def saveQuery(alias):
6772
Storage.flushSavedQueries()
6873

6974

75+
@staticmethod
7076
def getSavedQuery(alias):
7177
if len(alias) <= 0:
7278
return
@@ -102,6 +108,7 @@ def _info(self):
102108
def _quickPanel(self):
103109
return [self.name, self._info()]
104110

111+
@staticmethod
105112
def killCommandAfterTimeout(command):
106113
timeout = sublime.load_settings(Const.SETTINGS_FILENAME).get('thread_timeout', 5000)
107114
sublime.set_timeout(command.stop, timeout)
@@ -181,6 +188,7 @@ def getOptionsForSgdbCli(self):
181188

182189

183190
class Selection:
191+
@staticmethod
184192
def get():
185193
text = []
186194
if View().sel():
@@ -191,6 +199,7 @@ def get():
191199
text.append(View().substr(region))
192200
return text
193201

202+
@staticmethod
194203
def formatSql(edit):
195204
for region in View().sel():
196205
if region.empty():
@@ -219,9 +228,10 @@ def run(self):
219228
self.tmp.write(self.query)
220229
self.tmp.close()
221230

231+
self.args = map(str, self.args)
222232
self.process = subprocess.Popen(self.args, stdout=subprocess.PIPE,stderr=subprocess.PIPE, stdin=open(self.tmp.name))
223233

224-
results, errors = self.process.communicate(input=self.query.encode('utf-8'))
234+
results, errors = self.process.communicate()
225235

226236
if errors:
227237
self.callback(errors.decode('utf-8', 'replace').replace('\r', ''))
@@ -244,6 +254,7 @@ def stop(self):
244254
os.unlink(self.tmp.name)
245255

246256
class Utils:
257+
@staticmethod
247258
def getResultAsList(results, callback=None):
248259
resultList = []
249260
for result in results.splitlines():
@@ -257,6 +268,7 @@ def getResultAsList(results, callback=None):
257268

258269
return resultList
259270

271+
@staticmethod
260272
def formatSql(raw):
261273
settings = sublime.load_settings(Const.SETTINGS_FILENAME).get("format")
262274
try:
@@ -279,11 +291,13 @@ def formatSql(raw):
279291
class History:
280292
queries = []
281293

294+
@staticmethod
282295
def add(query):
283296
if len(History.queries) >= sublime.load_settings(Const.SETTINGS_FILENAME).get('history_size', 100):
284297
History.queries.pop(0)
285298
History.queries.append(query)
286299

300+
@staticmethod
287301
def get(index):
288302
if index < 0 or index > (len(History.queries) - 1):
289303
raise "No query selected"

0 commit comments

Comments
 (0)