2021-08-28 21:12:08 +02:00
|
|
|
$GENERATED_PYTHON_COMMENT
|
|
|
|
|
2021-08-31 17:24:54 +02:00
|
|
|
from db import dbGetMany, dbGetOne, dbInsert
|
|
|
|
from loguru import logger
|
2021-08-02 16:52:31 +02:00
|
|
|
|
|
|
|
#for $table in $tables
|
|
|
|
def get_${table.name}s(user, token_info):
|
|
|
|
return dbGetMany(user, token_info, {
|
|
|
|
"statement": """
|
|
|
|
SELECT
|
|
|
|
id
|
|
|
|
#for $column in $table.columns
|
|
|
|
,$column.name
|
|
|
|
#end for
|
|
|
|
FROM ${table.name}_t
|
2021-08-28 19:00:49 +02:00
|
|
|
#if $table.selectors
|
|
|
|
ORDER BY
|
|
|
|
#set $sep = ""
|
|
|
|
#for $selector in $table.selectors
|
|
|
|
$sep$selector
|
|
|
|
#set $sep = ","
|
|
|
|
#end for
|
|
|
|
#end if
|
2021-08-02 16:52:31 +02:00
|
|
|
""",
|
|
|
|
"params": ()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-08-31 17:24:54 +02:00
|
|
|
def insert_${table.name}(user, token_info, **args):
|
|
|
|
try:
|
|
|
|
body = args["body"]
|
|
|
|
#for $column in $table.columns
|
|
|
|
v_$column.name = body["$column.name"]
|
|
|
|
#end for
|
|
|
|
return dbInsert(user, token_info, {
|
|
|
|
"statement": """
|
|
|
|
INSERT INTO ${table.name}_t
|
|
|
|
(
|
|
|
|
#set $sep=""
|
|
|
|
#for $column in $table.columns
|
|
|
|
$sep$column.name
|
|
|
|
#set $sep=","
|
|
|
|
#end for
|
|
|
|
) VALUES (
|
|
|
|
#set $sep=""
|
|
|
|
#for $column in $table.columns
|
|
|
|
$sep%s
|
|
|
|
#set $sep=","
|
|
|
|
#end for
|
|
|
|
)
|
|
|
|
RETURNING *
|
|
|
|
""",
|
|
|
|
"params": [
|
|
|
|
#set $sep=""
|
|
|
|
#for $column in $table.columns
|
|
|
|
${sep}v_$column.name
|
|
|
|
#set $sep=","
|
|
|
|
#end for
|
|
|
|
]
|
|
|
|
})
|
|
|
|
except KeyError as e:
|
|
|
|
logger.warning("insert_${table.name}: parameter missing: {}".format(e))
|
|
|
|
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))
|
|
|
|
|
|
|
|
|
2021-08-02 16:52:31 +02:00
|
|
|
def get_${table.name}(user, token_info, ${table.name}Id=None):
|
|
|
|
return dbGetOne(user, token_info, {
|
|
|
|
"statement": """
|
|
|
|
SELECT
|
|
|
|
id
|
|
|
|
#for $column in $table.columns
|
|
|
|
,$column.name
|
|
|
|
#end for
|
|
|
|
FROM ${table.name}_t
|
|
|
|
WHERE id = %s
|
|
|
|
""",
|
|
|
|
"params": (${table.name}Id, )
|
|
|
|
}
|
|
|
|
)
|
|
|
|
#end for
|