From c0af45f7cc7c251cbac2837e95cdb7bea2379d95 Mon Sep 17 00:00:00 2001 From: totoro Date: Sun, 23 Jul 2017 22:39:27 +0200 Subject: [PATCH] add constraint definition on table model add mobile_field and url_field --- ds_files/ds_types.anubis | 28 +++++++++++++++++++++++----- model/fields.anubis | 10 +++++++++- model/model.anubis | 7 +++++++ model/tables.anubis | 1 + model/types/hk_constraint.anubis | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ model/types/hk_model.anubis | 21 ++++++++++++++------- model/types/hk_model_field.anubis | 20 ++++++++++++++++++-- model/types/hk_on_conflict.anubis | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 240 insertions(+), 15 deletions(-) create mode 100644 model/types/hk_constraint.anubis create mode 100644 model/types/hk_on_conflict.anubis diff --git a/ds_files/ds_types.anubis b/ds_files/ds_types.anubis index 274c2e8..00e0719 100644 --- a/ds_files/ds_types.anubis +++ b/ds_files/ds_types.anubis @@ -61,6 +61,7 @@ public define List(DS_Type_File) hayamiki_lib_types_description = ds_type("HK_Model", [ alternative("hk_model", [ component(list, extern_type("HK_Model_Column", model_types+"hk_model_column.anubis"), "columns", comment("columns other than the primary key column (if any)")), + component(list, extern_type("HK_Constraint", model_types+"hk_constraint.anubis"), "constraints"), component(string, "show_string") ]) ]), @@ -107,9 +108,11 @@ public define List(DS_Type_File) hayamiki_lib_types_description = [ component(extern_type("HK_Text_Field_Attr", model_types+"hk_text_field_attr.anubis"), "hk_text_field_attr"), ]), - enum("color_field", comment("String which representing RGBA color like HTML")), - enum("phone_field", comment("phone field")), - enum("email_field", comment("email field")), + enum("color_field", comment("String which representing RGBA color like HTML")), + enum("phone_field", comment("phone field")), + enum("mobile_field", comment("mobile phone field")), + enum("url_field", comment("url field for website and so forth")), + enum("email_field", comment("email field")), ]), // @@ -173,8 +176,23 @@ public define List(DS_Type_File) hayamiki_lib_types_description = ]), enum("not_null"), ]), - - + + //HK_CONSTRAINT + ds_type("HK_Constraint", [ + alternative("unique", [ + component(string, "name"), + component(list, string, "columns", comment("columns on which the constraint is bound")), + component(extern_type("HK_On_Conflict", model_types+"hk_on_conflict.anubis"), "on_conflict") + ]) + ]), + + ds_type("HK_On_Conflict" ,[ + enum("rollback"), + enum("abort"), + enum("fail"), + enum("ignore"), + enum("replace") + ]), //HK_DISPLAY ds_type("HK_Display", [ diff --git a/model/fields.anubis b/model/fields.anubis index 758aba7..2ffd7ae 100644 --- a/model/fields.anubis +++ b/model/fields.anubis @@ -254,7 +254,15 @@ public define JsonValue phone_field then [ json_member("type", json_string("phone_field")) ], - + + mobile_field then + [ json_member("type", json_string("mobile_field")) + ], + + url_field then + [ json_member("type", json_string("url_field")) + ], + email_field then [ json_member("type", json_string("email_field")) ] diff --git a/model/model.anubis b/model/model.anubis index c2a401f..34e409a 100644 --- a/model/model.anubis +++ b/model/model.anubis @@ -11,6 +11,13 @@ transmit columns.anubis transmit calexium_lib/web/CXM_json.anubis transmit hayamiki_lib/model/types/hk_model.anubis +public define HK_Model + hk_model( + List(HK_Model_Column) columns, //columns other than the primary key column (if any) + String show_string + )= + hk_model(columns, [], show_string) +. _HK_MODEL message format: ======================== diff --git a/model/tables.anubis b/model/tables.anubis index d6a7242..540ba88 100644 --- a/model/tables.anubis +++ b/model/tables.anubis @@ -12,6 +12,7 @@ transmit model.anubis transmit calexium_lib/web/CXM_json.anubis transmit hayamiki_lib/model/types/hk_table.anubis +transmit hayamiki_lib/model/types/hk_constraint.anubis public define HK_Table hk_table diff --git a/model/types/hk_constraint.anubis b/model/types/hk_constraint.anubis new file mode 100644 index 0000000..66c86ec --- /dev/null +++ b/model/types/hk_constraint.anubis @@ -0,0 +1,78 @@ +/* + * Created by 伝作 (Densaku). + * Types & Messages generator written by フランスのトトロ aka (David RENÉ) + * Date: 2017-07-23 + * Time: 21:15:01 + * + */ + +transmit system/muscle.anubis +transmit system/convert.anubis +transmit tools/basis.anubis + +transmit hayamiki_lib/model/types/hk_on_conflict.anubis + + + +public type HK_Constraint: + unique( + String name, + List(String) columns, //columns on which the constraint is bound + HK_On_Conflict on_conflict + ) +. + + HK_Constraint message format + ============================ + + +public define Message + to_Message + ( + HK_Constraint _hk_constraint + )= + with _hk_constraint_message = message((Word32)0), // + forget(add_string(_hk_constraint_message, "__TYPE__", "HK_Constraint")); + if _hk_constraint is + { + //Alternative unique + unique(_name, __columns, _on_conflict) then + forget(add_string(_hk_constraint_message, "__TYPE_ALT__", "unique")); + // [type = String] unique.name + forget(add_string(_hk_constraint_message, "name", _name)); + // [type = List(String)] unique.columns + map_forget((String _columns) |-> add_string(_hk_constraint_message, "columns", _columns), __columns); + // [type = HK_On_Conflict] unique.on_conflict + forget(add_message(_hk_constraint_message, "on_conflict", to_Message(_on_conflict))), + + }; + _hk_constraint_message +. + +public define Maybe(HK_Constraint) + from_Message + ( + Message _hk_constraint_message + )= + if find_string(_hk_constraint_message, "__TYPE__") is {failure then failure, success(__type__) then + if find_string(_hk_constraint_message, "__TYPE_ALT__") is {failure then failure, success(__type_alt__) then + if __type__ = "HK_Constraint" then + //Alternative unique + if __type_alt__ = "unique" then //Alternative unique + // [type = String] unique.name + if find_string(_hk_constraint_message, "name") is {failure then failure, success(_name_) then + // [type = List(String)] unique.columns + with _columns_ = find_string_list(_hk_constraint_message, "columns"), + // [type = HK_On_Conflict] unique.on_conflict + if find_message(_hk_constraint_message, "on_conflict") is {failure then failure, success(_on_conflict__msg) then + if (Maybe(HK_On_Conflict))from_Message(_on_conflict__msg) is {failure then failure, success(_on_conflict_) then + + success(unique(_name_, _columns_, _on_conflict_)) + }}} + else + failure //No valid Alternative found ! + else + failure //Type not found in message ! + }} +. + diff --git a/model/types/hk_model.anubis b/model/types/hk_model.anubis index e42cb63..44a70f8 100644 --- a/model/types/hk_model.anubis +++ b/model/types/hk_model.anubis @@ -1,8 +1,8 @@ /* * Created by 伝作 (Densaku). * Types & Messages generator written by フランスのトトロ aka (David RENÉ) - * Date: 2017-05-19 - * Time: 09:24:24 + * Date: 2017-07-23 + * Time: 21:35:44 * */ @@ -10,14 +10,16 @@ transmit system/muscle.anubis transmit system/convert.anubis transmit tools/basis.anubis +transmit hayamiki_lib/model/types/hk_constraint.anubis transmit hayamiki_lib/model/types/hk_model_column.anubis public type HK_Model: hk_model( - List(HK_Model_Column) columns, //columns other than the primary key column (if any) - String show_string + List(HK_Model_Column) columns, //columns other than the primary key column (if any) + List(HK_Constraint) constraints, + String show_string ) . @@ -35,10 +37,12 @@ public define Message if _hk_model is { //Alternative hk_model - hk_model(__columns, _show_string) then + hk_model(__columns, __constraints, _show_string) then forget(add_string(_hk_model_message, "__TYPE_ALT__", "hk_model")); // [type = List(HK_Model_Column)] hk_model.columns map_forget((HK_Model_Column _columns) |-> add_message(_hk_model_message, "columns", to_Message(_columns)), __columns); + // [type = List(HK_Constraint)] hk_model.constraints + map_forget((HK_Constraint _constraints) |-> add_message(_hk_model_message, "constraints", to_Message(_constraints)), __constraints); // [type = String] hk_model.show_string forget(add_string(_hk_model_message, "show_string", _show_string)), @@ -59,11 +63,14 @@ public define Maybe(HK_Model) // [type = List(HK_Model_Column)] hk_model.columns with mb__columns_ = map_escape(( Message msg ) |-> (Maybe(HK_Model_Column)) from_Message(msg), find_messages(_hk_model_message, "columns")), if mb__columns_ is {failure then failure, success(_columns_) then + // [type = List(HK_Constraint)] hk_model.constraints + with mb__constraints_ = map_escape(( Message msg ) |-> (Maybe(HK_Constraint)) from_Message(msg), find_messages(_hk_model_message, "constraints")), + if mb__constraints_ is {failure then failure, success(_constraints_) then // [type = String] hk_model.show_string if find_string(_hk_model_message, "show_string") is {failure then failure, success(_show_string_) then - success(hk_model(_columns_, _show_string_)) - }} + success(hk_model(_columns_, _constraints_, _show_string_)) + }}} else failure //No valid Alternative found ! else diff --git a/model/types/hk_model_field.anubis b/model/types/hk_model_field.anubis index 6950f5b..89686da 100644 --- a/model/types/hk_model_field.anubis +++ b/model/types/hk_model_field.anubis @@ -1,8 +1,8 @@ /* * Created by 伝作 (Densaku). * Types & Messages generator written by フランスのトトロ aka (David RENÉ) - * Date: 2017-05-24 - * Time: 01:57:03 + * Date: 2017-07-23 + * Time: 21:35:44 * */ @@ -55,6 +55,8 @@ public type HK_Model_Field: ), color_field, //String which representing RGBA color like HTML phone_field, //phone field + mobile_field, //mobile phone field + url_field, //url field for website and so forth email_field //email field . @@ -147,6 +149,14 @@ public define Message phone_field then forget(add_string(_hk_model_field_message, "__TYPE_ALT__", "phone_field")), + //Alternative mobile_field (NO TYPE) + mobile_field then + forget(add_string(_hk_model_field_message, "__TYPE_ALT__", "mobile_field")), + + //Alternative url_field (NO TYPE) + url_field then + forget(add_string(_hk_model_field_message, "__TYPE_ALT__", "url_field")), + //Alternative email_field (NO TYPE) email_field then forget(add_string(_hk_model_field_message, "__TYPE_ALT__", "email_field")), @@ -251,6 +261,12 @@ public define Maybe(HK_Model_Field) else //Alternative phone_field (NO TYPE) if __type_alt__ = "phone_field" then success(phone_field) + else //Alternative mobile_field (NO TYPE) + if __type_alt__ = "mobile_field" then + success(mobile_field) + else //Alternative url_field (NO TYPE) + if __type_alt__ = "url_field" then + success(url_field) else //Alternative email_field (NO TYPE) if __type_alt__ = "email_field" then success(email_field) diff --git a/model/types/hk_on_conflict.anubis b/model/types/hk_on_conflict.anubis new file mode 100644 index 0000000..b05fced --- /dev/null +++ b/model/types/hk_on_conflict.anubis @@ -0,0 +1,90 @@ +/* + * Created by 伝作 (Densaku). + * Types & Messages generator written by フランスのトトロ aka (David RENÉ) + * Date: 2017-07-23 + * Time: 21:15:01 + * + */ + +transmit system/muscle.anubis +transmit system/convert.anubis +transmit tools/basis.anubis + + + + +public type HK_On_Conflict: + rollback, + abort, + fail, + ignore, + replace +. + + HK_On_Conflict message format + ============================= + + +public define Message + to_Message + ( + HK_On_Conflict _hk_on_conflict + )= + with _hk_on_conflict_message = message((Word32)0), // + forget(add_string(_hk_on_conflict_message, "__TYPE__", "HK_On_Conflict")); + if _hk_on_conflict is + { + //Alternative rollback (NO TYPE) + rollback then + forget(add_string(_hk_on_conflict_message, "__TYPE_ALT__", "rollback")), + + //Alternative abort (NO TYPE) + abort then + forget(add_string(_hk_on_conflict_message, "__TYPE_ALT__", "abort")), + + //Alternative fail (NO TYPE) + fail then + forget(add_string(_hk_on_conflict_message, "__TYPE_ALT__", "fail")), + + //Alternative ignore (NO TYPE) + ignore then + forget(add_string(_hk_on_conflict_message, "__TYPE_ALT__", "ignore")), + + //Alternative replace (NO TYPE) + replace then + forget(add_string(_hk_on_conflict_message, "__TYPE_ALT__", "replace")), + + }; + _hk_on_conflict_message +. + +public define Maybe(HK_On_Conflict) + from_Message + ( + Message _hk_on_conflict_message + )= + if find_string(_hk_on_conflict_message, "__TYPE__") is {failure then failure, success(__type__) then + if find_string(_hk_on_conflict_message, "__TYPE_ALT__") is {failure then failure, success(__type_alt__) then + if __type__ = "HK_On_Conflict" then + //Alternative rollback (NO TYPE) + if __type_alt__ = "rollback" then + success(rollback) + else //Alternative abort (NO TYPE) + if __type_alt__ = "abort" then + success(abort) + else //Alternative fail (NO TYPE) + if __type_alt__ = "fail" then + success(fail) + else //Alternative ignore (NO TYPE) + if __type_alt__ = "ignore" then + success(ignore) + else //Alternative replace (NO TYPE) + if __type_alt__ = "replace" then + success(replace) + else + failure //No valid Alternative found ! + else + failure //Type not found in message ! + }} +. + -- libgit2 0.21.4