From 124bdb740127d367f0636018faf1018e01dcab0b Mon Sep 17 00:00:00 2001 From: Dorian Wouters Date: Wed, 22 Nov 2017 21:30:58 +0100 Subject: [PATCH] Abstraction: add INSERT default values & UPDATE custom value --- abstraction.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/abstraction.lua b/abstraction.lua index cc66f4c..9a62ee9 100644 --- a/abstraction.lua +++ b/abstraction.lua @@ -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' @@ -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)