-
Notifications
You must be signed in to change notification settings - Fork 755
/
sql.py
69 lines (47 loc) · 1.67 KB
/
sql.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from talon import Context, actions
ctx = Context()
ctx.matches = r"""
code.language: sql
"""
# these vary by dialect
ctx.lists["user.code_common_function"] = {"count": "Count", "min": "Min", "max": "Max"}
@ctx.action_class("user")
class UserActions:
def code_operator_addition():
actions.auto_insert(" + ")
def code_operator_subtraction():
actions.auto_insert(" - ")
def code_operator_multiplication():
actions.auto_insert(" * ")
def code_operator_division():
actions.auto_insert(" / ")
def code_operator_equal():
actions.auto_insert(" = ")
def code_operator_not_equal():
actions.auto_insert(" <> ")
def code_operator_greater_than():
actions.auto_insert(" > ")
def code_operator_greater_than_or_equal_to():
actions.auto_insert(" >= ")
def code_operator_less_than():
actions.auto_insert(" < ")
def code_operator_less_than_or_equal_to():
actions.auto_insert(" <= ")
def code_operator_in():
actions.user.insert_between(" IN (", ")")
def code_operator_not_in():
actions.user.insert_between(" NOT IN (", ")")
def code_operator_and():
actions.auto_insert("AND ")
def code_operator_or():
actions.auto_insert("OR ")
def code_insert_null():
actions.auto_insert("NULL")
def code_insert_is_null():
actions.auto_insert(" IS NULL")
def code_insert_is_not_null():
actions.auto_insert(" IS NOT NULL")
def code_comment_line_prefix():
actions.auto_insert("-- ")
def code_insert_function(text: str, selection: str):
actions.user.insert_between(f"{text}({selection or ''}", ")")