-
Notifications
You must be signed in to change notification settings - Fork 0
/
trash.sql
99 lines (62 loc) · 1.43 KB
/
trash.sql
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{% query
get-all-items
:doc "Query all the items from the database."
:as-unqualified-maps
%}
select
{% if fields %}
{{ fields | FIELDS }}
{% else %}
*
{% endif %}
from items
{% endquery %}
{% query get-item-by-sku
:doc "Get a single item by its SKU name."
:as-unqualified-maps
:1 %}
select * from items
where sku = {% ! sku %}
{% endquery %}
{% query get-item-with-fields
:1 :pg :as-unqualified-maps %}
select {{ fields | FIELDS }}, 42 as answer from items
where sku = {{ sku|? }}
{% endquery %}
{% query update-item-by-sku
:1 :as-unqualified-maps %}
update items
set {{ values | SET }}
where sku = {% ? sku %}
returning *
{% endquery %}
{% query upsert-item
:1 :as-unqualified-maps %}
insert into items ({{ values | FIELDS }})
values ({{ values | VALUES }})
on conflict (sku)
do update set {{ values | EXCLUDED }}
returning *
{% endquery %}
{% query upsert-item-multi
:as-unqualified-maps %}
insert into items ({{ values | first | FIELDS }})
values {{ values | MVALUES }}
on conflict (sku)
do update set {{ values | first | EXCLUDED }}
returning *
{% endquery %}
{% query delete-all-items :count %}
delete from items
{% endquery %}
{% query get-items-by-ids
:pg
%}
select * from {{ table | quote }}
where id {% IN ids %}
{% endquery %}
[nil
{:tag {:tag-type :expr, :tag-name :quote, :args ("table" "mysql")}}
nil
{:tag {:tag-type :expr, :tag-name :if, :args ("foo")}}
nil]