update methods and immutable attribute added

This commit is contained in:
2021-09-07 15:22:55 +02:00
parent 0afef9f3cd
commit 6470aa5358
10 changed files with 956 additions and 20 deletions

View File

@ -1,7 +1,8 @@
$GENERATED_PYTHON_COMMENT
from db import dbGetMany, dbGetOne, dbInsert
from db import dbGetMany, dbGetOne, dbInsert, dbUpdate
from loguru import logger
import werkzeug
#for $table in $tables
def get_${table.name}s(user, token_info):
@ -77,4 +78,42 @@ SELECT
"params": (${table.name}Id, )
}
)
#if (('immutable' not in $table) or (not $table.immutable))
def update_${table.name}(user, token_info, ${table.name}Id=None, **args):
try:
body = args["body"]
#for $column in $table.columns
#if (('immutable' not in $column) or (not $column.immutable))
v_$column.name = body["$column.name"]
#end if
#end for
return dbUpdate(user, token_info, {
"statement": """
UPDATE ${table.name}_t
SET
#set $sep=""
#for $column in $table.columns
#if (('immutable' not in $column) or (not $column.immutable))
$sep$column.name = %s
#end if
#set $sep=","
#end for
WHERE id = %s
RETURNING *
""",
"params": [
#for $column in $table.columns
#if (('immutable' not in $column) or (not $column.immutable))
v_${column.name},
#end if
#end for
${table.name}Id
]
})
except KeyError as e:
logger.warning("update_${table.name}: parameter missing: {}".format(e))
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))
#end if
#end for