-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcppgen.lua
More file actions
33 lines (30 loc) · 1.09 KB
/
cppgen.lua
File metadata and controls
33 lines (30 loc) · 1.09 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
local db = require("crymp.db")
text = ""
for i, v in pairs(db) do
if v.entity then
text = text .. " struct " .. i .. " : public orm::with_orm {\n"
local props = ""
for j, w in pairs(v.entity) do
local t = w.type.name()
if t == "text" then t = "std::string" end
if t == "decimal" then t = "double" end
if t == "datetime" then t = "orm::datetime" end
local vch = t:match("varchar%((%d+)%)")
if vch then
t = "util::varstr<" .. vch .. ">"
end
text = text .. " " .. t .. " " .. j .. ";\n"
props = props .. " { \"" .. (w.field or j) .. "\", " .. j .. " },\n"
end
text = text .. "\n orm::mapper get_orm() {\n return {\n" .. props .. " };\n }\n"
text = text .. " };\n\n"
end
end
local f, err = io.open("db.cpp", "w")
if f then
f:write("#include <90s/orm/orm.hpp>\n\nnamespace db {\n using namespace s90;\n")
f:write(text)
f:write("}\n")
f:close()
end
aio:quit()