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

Commit 5a30142

Browse files
committed
Merge pull request #14 from tkopets/master
list functions (ctrl+e ctrl+f) and get their definitions
2 parents 43b6e35 + 8d9ae0c commit 5a30142

File tree

7 files changed

+45
-1
lines changed

7 files changed

+45
-1
lines changed

Default (Linux).sublime-keymap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{ "keys": ["ctrl+e", "ctrl+h"], "command": "st_history" },
55
{ "keys": ["ctrl+e", "ctrl+s"], "command": "st_show_records" },
66
{ "keys": ["ctrl+e", "ctrl+d"], "command": "st_desc_table" },
7+
{ "keys": ["ctrl+e", "ctrl+f"], "command": "st_desc_function" },
78
{ "keys": ["ctrl+e", "ctrl+b"], "command": "st_format" },
89
{ "keys": ["ctrl+e", "ctrl+q"], "command": "st_save_query" },
910
{ "keys": ["ctrl+e", "ctrl+r"], "command": "st_remove_saved_query" },

Default (OSX).sublime-keymap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{ "keys": ["ctrl+e", "ctrl+h"], "command": "st_history" },
55
{ "keys": ["ctrl+e", "ctrl+s"], "command": "st_show_records" },
66
{ "keys": ["ctrl+e", "ctrl+d"], "command": "st_desc_table" },
7+
{ "keys": ["ctrl+e", "ctrl+f"], "command": "st_desc_function" },
78
{ "keys": ["ctrl+e", "ctrl+b"], "command": "st_format" },
89
{ "keys": ["ctrl+e", "ctrl+q"], "command": "st_save_query" },
910
{ "keys": ["ctrl+e", "ctrl+r"], "command": "st_remove_saved_query" },

Default (Windows).sublime-keymap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{ "keys": ["ctrl+e", "ctrl+h"], "command": "st_history" },
55
{ "keys": ["ctrl+e", "ctrl+s"], "command": "st_show_records" },
66
{ "keys": ["ctrl+e", "ctrl+d"], "command": "st_desc_table" },
7+
{ "keys": ["ctrl+e", "ctrl+f"], "command": "st_desc_function" },
78
{ "keys": ["ctrl+e", "ctrl+b"], "command": "st_format" },
89
{ "keys": ["ctrl+e", "ctrl+q"], "command": "st_save_query" },
910
{ "keys": ["ctrl+e", "ctrl+r"], "command": "st_remove_saved_query" },

Default.sublime-commands

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"caption": "ST: Table Description",
2424
"command": "st_desc_table"
2525
},
26+
{
27+
"caption": "ST: Function Description",
28+
"command": "st_desc_function"
29+
},
2630
{
2731
"caption": "ST: Save Query",
2832
"command": "st_save_query"

SQLTools.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def loadConnectionData():
4545

4646
ST.conn.getTables(lambda tables: ST.setTablesIfNotEmpty(tables))
4747
ST.conn.getColumns(lambda columns: setattr(ST, 'columns', columns))
48+
ST.conn.getFunctions(lambda functions: setattr(ST, 'functions', functions))
4849

4950
@staticmethod
5051
def setConnection(index):
@@ -98,6 +99,13 @@ def getAutoCompleteList(self, word):
9899
except Exception:
99100
continue
100101

102+
for w in ST.functions:
103+
try:
104+
if word.lower() in w.lower():
105+
ST.autoCompleteList.append(("{0}\t({1})".format(w, 'Func'), w))
106+
except Exception:
107+
continue
108+
101109
ST.autoCompleteList.sort()
102110
return (ST.autoCompleteList)
103111

@@ -159,6 +167,15 @@ def run(self):
159167

160168
STM.Window().show_quick_panel(ST.tables, lambda index: ST.conn.getTableDescription(ST.tables[index], ST.display) if index != -1 else None)
161169

170+
class StDescFunction(sublime_plugin.WindowCommand):
171+
def run(self):
172+
if not ST.conn:
173+
ST.showConnectionMenu()
174+
return
175+
176+
# get everything until first occurence of "(", e.g. get "function_name" from "function_name(int)"
177+
STM.Window().show_quick_panel(ST.functions, lambda index: ST.conn.getFunctionDescription(ST.functions[index].split('(', 1)[0], ST.display) if index != -1 else None)
178+
162179
class StHistory(sublime_plugin.WindowCommand):
163180
def run(self):
164181
if not ST.conn:

SQLTools.sublime-settings

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,17 @@
5858
"query": "SELECT DISTINCT '|' || table_name || '.' || column_name || '|' FROM information_schema.columns WHERE table_schema = CURRENT_SCHEMA() GROUP BY table_name, column_name;",
5959
"options": ["-t", "--no-psqlrc"],
6060
"format" : "|%s|"
61-
}
61+
},
62+
"functions": {
63+
"query": "SELECT '|' || CASE WHEN n.nspname = current_schema() THEN quote_ident(f.proname) ELSE quote_ident(n.nspname)||'.'||quote_ident(f.proname) END || '(' || pg_get_function_identity_arguments(f.oid) || ')' || '|' AS funname FROM pg_catalog.pg_proc AS f INNER JOIN pg_catalog.pg_namespace AS n ON n.oid = f.pronamespace WHERE proisagg = false AND n.nspname NOT IN ('pg_catalog', 'information_schema')",
64+
"options": ["-t", "--no-psqlrc"],
65+
"format" : "|%s|"
66+
},
67+
"desc function": {
68+
"query": "\\sf %s",
69+
"options": [],
70+
"format" : "|%s|"
71+
},
6272
}
6373
},
6474
"oracle": {

SQLToolsModels.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ def getColumns(self, callback):
148148
except Exception:
149149
pass
150150

151+
def getFunctions(self, callback):
152+
query = self.getOptionsForSgdbCli()['queries']['functions']['query']
153+
self.runCommand(self.builArgs('functions'), query, lambda result: Utils.getResultAsList(result, callback))
154+
155+
151156
def getTableRecords(self, tableName, callback):
152157
query = self.getOptionsForSgdbCli()['queries']['show records']['query'].format(tableName, self.rowsLimit)
153158
self.runCommand(self.builArgs('show records'), query, lambda result: callback(result))
@@ -156,6 +161,11 @@ def getTableDescription(self, tableName, callback):
156161
query = self.getOptionsForSgdbCli()['queries']['desc table']['query'] % tableName
157162
self.runCommand(self.builArgs('desc table'), query, lambda result: callback(result))
158163

164+
def getFunctionDescription(self, functionName, callback):
165+
query = self.getOptionsForSgdbCli()['queries']['desc function']['query'] % functionName
166+
self.runCommand(self.builArgs('desc function'), query, lambda result: callback(result))
167+
168+
159169
def execute(self, queries, callback):
160170
queryToRun = ''
161171

0 commit comments

Comments
 (0)