Skip to content
This repository was archived by the owner on Aug 20, 2020. It is now read-only.

Commit 124bdb7

Browse files
committed
Abstraction: add INSERT default values & UPDATE custom value
1 parent fc093ab commit 124bdb7

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

abstraction.lua

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ function thismod.create_table_sql(name, params)
99
for _, coldata in ipairs(params.columns) do
1010
local line = (coldata.name or coldata[1]) .. ' ' .. (coldata.type or coldata[2])
1111
if coldata.notnull then
12-
line = line .. ' NOT NULL'
12+
line = line .. ' NOT NULL'
13+
end
14+
if coldata.default then
15+
line = line .. ' DEFAULT ' .. coldata.default
1316
end
1417
if coldata.autoincrement then
1518
line = line .. ' AUTO_INCREMENT'
@@ -69,8 +72,10 @@ end
6972
function thismod.prepare_update(tablename, cols, where, wheretypes)
7073
local colnames, paramtypes = {}, {}
7174
for _, col in ipairs(cols) do
72-
table.insert(colnames, (col.name or col[1]) .. '=?')
73-
table.insert(paramtypes, col.type or col[2])
75+
table.insert(colnames, (col.name or col[1]) .. '=' .. (col.value or '?'))
76+
if col.type or col[2] then
77+
table.insert(paramtypes, col.type or col[2])
78+
end
7479
end
7580
for _, wheretype in ipairs(wheretypes) do
7681
table.insert(paramtypes, wheretype)

0 commit comments

Comments
 (0)