From 0dc1ce0224fd2c94a99c8b7a715431086299d18c Mon Sep 17 00:00:00 2001 From: totoro Date: Mon, 22 Aug 2022 10:12:53 +0900 Subject: [PATCH] [*] get_column_name has option to return also primary key. This is useful for generating full insert. --- src/generation/columns.anubis | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/generation/columns.anubis b/src/generation/columns.anubis index f71caaf..d997871 100644 --- a/src/generation/columns.anubis +++ b/src/generation/columns.anubis @@ -138,13 +138,14 @@ public define Maybe(String) get_column_name ( HK_Model_Column col, - Bool insert //true if insert time else false for update + Bool p_key_id, //true if the "id" column must be returned + Bool insert //true if insert time else false for update ) = since col is hk_column(name, col_type, _, _), if col_type is { //anubis(_T) then "constant_byte_array(0,0)", - p_key then if name = "id" then failure else success(name), + p_key then if name = "id" & p_key_id = false then failure else success(name), //binary then "constant_byte_array(0,0)", boolean_field then success(name), date_field(attrs) then success(name), @@ -172,6 +173,7 @@ public define List(String) columns_name ( List(HK_Model_Column) columns, + Bool p_key_id, //true if we need to have the first primary_key column named "id" Bool insert, //true if insert time else false for update List(String) so_far ) = @@ -179,14 +181,14 @@ public define List(String) { [] then reverse(so_far), [h . t] then - if get_column_name(h, insert) is + if get_column_name(h, p_key_id, insert) is { - failure then columns_name(t, insert, so_far) + failure then columns_name(t, p_key_id, insert, so_far) success(result) then if insert then - columns_name(t, insert, [result . so_far]) + columns_name(t, p_key_id, insert, [result . so_far]) else - columns_name(t, insert, [enclose("\\\"",result)+" = :v_"+result . so_far]) + columns_name(t, p_key_id, insert, [enclose("\\\"",result)+" = :v_"+result . so_far]) } }. @@ -198,9 +200,10 @@ public define String insert_values ( List(HK_Model_Column) columns, + Bool p_key_id, String indent )= - with columns_list = columns_name(columns, true, []), + with columns_list = columns_name(columns, p_key_id, true, []), indent+" ("+join(", ", enclose("\\\"",columns_list))+")\n"+indent+"VALUES\n"+indent+" ("+prefixed_join(":v_", columns_list, ", ")+")". @@ -214,7 +217,7 @@ public define String List(HK_Model_Column) columns, String indent )= - with columns_list = columns_name(columns, false, []), + with columns_list = columns_name(columns, false, false, []), indent+" "+join(", ", columns_list). -- libgit2 0.21.4