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

Commit

Permalink
Abstraction: add INSERT default values & UPDATE custom value
Browse files Browse the repository at this point in the history
  • Loading branch information
ElementW committed Nov 22, 2017
1 parent fc093ab commit 124bdb7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions abstraction.lua
Expand Up @@ -9,7 +9,10 @@ function thismod.create_table_sql(name, params)
for _, coldata in ipairs(params.columns) do
local line = (coldata.name or coldata[1]) .. ' ' .. (coldata.type or coldata[2])
if coldata.notnull then
line = line .. ' NOT NULL'
line = line .. ' NOT NULL'
end
if coldata.default then
line = line .. ' DEFAULT ' .. coldata.default
end
if coldata.autoincrement then
line = line .. ' AUTO_INCREMENT'
Expand Down Expand Up @@ -69,8 +72,10 @@ end
function thismod.prepare_update(tablename, cols, where, wheretypes)
local colnames, paramtypes = {}, {}
for _, col in ipairs(cols) do
table.insert(colnames, (col.name or col[1]) .. '=?')
table.insert(paramtypes, col.type or col[2])
table.insert(colnames, (col.name or col[1]) .. '=' .. (col.value or '?'))
if col.type or col[2] then
table.insert(paramtypes, col.type or col[2])
end
end
for _, wheretype in ipairs(wheretypes) do
table.insert(paramtypes, wheretype)
Expand Down

0 comments on commit 124bdb7

Please sign in to comment.