-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticle.sql.js
More file actions
74 lines (62 loc) · 1.81 KB
/
Copy patharticle.sql.js
File metadata and controls
74 lines (62 loc) · 1.81 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
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
// article.sql.js
// ==============
// (Query compilation example)
"use strict";
const sqltt = require("../"); // sqltt
// Define multiple named query templates.
const q = {};
q.list = new sqltt({//{{{
data: {
columns: ["id", "sectionName", "title"],
},
presets: {
detailed: {columns: ["id", "sectionName", "title", "autor", "brief", "ctime", "mtime"]},
bySection: {filters: ["sectionId"]},
},
sql: /* @@sql@@ */ $=>$`
select ${$.keys($.data("columns"))}
from articles
join sections using(sectionId)
${$.entries($.data("filters"), "and", "where")}
`, /* @@/sql@@ */
})//}}}
q.mlist = q.list.mutation({
columns: ["manolo"],
});
q.show = new sqltt(//{{{
/* @@sql@@ */ $=>$`
select id, sectionName, title, body
from articles
join sections using(sectionId)
where id = ${"id"}
` /* @@/sql@@ */
);//}}}
q.insert = new sqltt({//{{{
name: "ArticleInsert",
description: "Perform an Insert.",
/// args: ["title", "body", "sectionId"],
data: {
columns: ['sectionId', 'title', 'body'],
},
sql: /* @@sql@@ */ $=>$`
insert into articles (${$.keys($.data('columns'))})
${$.values($.data('columns'), ', ', "values (%)")}
`, /* @@/sql@@ */
}, {debug: true});//}}}
q.update = new sqltt({//{{{
description: "Perform an update.",
args: {
"id": "Identifier",
"title": "Main title",
"contents": "Article contents",
"sectionId": "Related section id",
},
data: {
columns: {sectionId: 'sectionId', title: 'title', body: 'contents'},
},
sql: /* @@sql@@ */ $=>$`
update articles ${$.entries($.data('columns'), undefined, 'set')}
where id = ${"id"}
`, /* @@/sql@@ */
});//}}}
sqltt.publish(module, q /*, {debug: true}*/);