# HG changeset patch # User jbe # Date 1581362239 -3600 # Node ID a0c49529ab8b0bb4a06c91ff462db30d7e452905 # Parent 7e874b5227b683efe8a5ee4ad4111c4fa87b3783 Support for BYTEA data type in models diff -r 7e874b5227b6 -r a0c49529ab8b libraries/mondelefant/mondelefant.lua --- a/libraries/mondelefant/mondelefant.lua Mon Dec 09 16:09:14 2019 +0100 +++ b/libraries/mondelefant/mondelefant.lua Mon Feb 10 20:17:19 2020 +0100 @@ -967,6 +967,15 @@ --//-- --[[-- +.binary_columns + +If binary data (PostgreSQL type BYTEA) is stored, must be set to a table mapping all column names used with binary data to true, e.g. File.binary_columns = { data = true }. + +--]]-- +class_prototype.binary_columns = nil +--// + +--[[-- db_handle = -- database connection handle used by this class :get_db_conn() @@ -1144,7 +1153,11 @@ local values = {sep = ", "} for key in pairs(self._dirty or {}) do add(fields, '"' .. key .. '"') - add(values, {'?', self._col[key]}) + if self._class.binary_columns and self._class.binary_columns[key] then + add(values, {'$', {self._connection:quote_binary(self._col[key])}}) + else + add(values, {'?', self._col[key]}) + end end local returning = { sep = ", " } if primary_key.json_doc then @@ -1243,7 +1256,11 @@ verify_mutability_state(self._col[key], mutability_state) ) then - add(update_sets, {'"$" = ?', {key}, self._col[key]}) + if self._class.binary_columns and self._class.binary_columns[key] then + add(update_sets, {'"$" = $', {key}, {self._connection:quote_binary(self._col[key])}}) + else + add(update_sets, {'"$" = ?', {key}, self._col[key]}) + end self._dirty[key] = true -- always dirty in case of later error end end