-
Notifications
You must be signed in to change notification settings - Fork 853
Expand file tree
/
Copy pathsql.py
More file actions
47 lines (38 loc) · 1.19 KB
/
sql.py
File metadata and controls
47 lines (38 loc) · 1.19 KB
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
from talon import Context, actions
from ...core.described_functions import create_described_insert_between
from ..tags.operators import Operators
ctx = Context()
ctx.matches = r"""
code.language: sql
"""
operators = Operators(
MATH_ADD=" + ",
MATH_SUBTRACT=" - ",
MATH_MULTIPLY=" * ",
MATH_DIVIDE=" / ",
MATH_EQUAL=" = ",
MATH_NOT_EQUAL=" <> ",
MATH_GREATER_THAN=" > ",
MATH_GREATER_THAN_OR_EQUAL=" >= ",
MATH_LESS_THAN=" < ",
MATH_LESS_THAN_OR_EQUAL=" <= ",
MATH_IN=create_described_insert_between(" IN (", ")"),
MATH_NOT_IN=create_described_insert_between(" NOT IN (", ")"),
MATH_AND=" AND ",
MATH_OR=" OR ",
)
@ctx.action_class("user")
class UserActions:
def code_get_operators() -> Operators:
return operators
def code_insert_null():
actions.insert("NULL")
def code_insert_is_null():
actions.insert(" IS NULL")
def code_insert_is_not_null():
actions.insert(" IS NOT NULL")
def code_insert_function(text: str, selection: str):
substitutions = {"1": text}
if selection:
substitutions["0"] = selection
actions.user.insert_snippet_by_name("functionCall", substitutions)