MaCH repo
This commit is contained in:
40
03_hello_world_html_db/main.c
Normal file
40
03_hello_world_html_db/main.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <mach.h>
|
||||
#include <sqlite.h>
|
||||
|
||||
void mach(){
|
||||
resource("home", "/",
|
||||
.get = {
|
||||
sqlite_query({.set_key = "greeting", .db = "hello_db", .query =
|
||||
"select name "
|
||||
"from greetings "
|
||||
"limit 1;"
|
||||
}),
|
||||
mustache(.template =
|
||||
"<html>"
|
||||
"<body>"
|
||||
"{{#greeting}}"
|
||||
"<p>Hello {{name}}</p>"
|
||||
"{{/greeting}}"
|
||||
"</body>"
|
||||
"</html>"
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
sqlite_database(
|
||||
.name = "hello_db",
|
||||
.connect = "file:hello.db?mode=rwc",
|
||||
.migrations = {
|
||||
"CREATE TABLE greetings ("
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||
"name TEXT NOT NULL"
|
||||
");"
|
||||
},
|
||||
.seeds = {
|
||||
"INSERT INTO greetings(name)"
|
||||
"VALUES('World');"
|
||||
}
|
||||
);
|
||||
|
||||
module(sqlite);
|
||||
}
|
||||
Reference in New Issue
Block a user