Commit c0af45f7cc7c251cbac2837e95cdb7bea2379d95
1 parent
7c2a7fd3
add constraint definition on table model
add mobile_field and url_field
Showing
8 changed files
with
240 additions
and
15 deletions
Show diff stats
ds_files/ds_types.anubis
| @@ -61,6 +61,7 @@ public define List(DS_Type_File) hayamiki_lib_types_description = | @@ -61,6 +61,7 @@ public define List(DS_Type_File) hayamiki_lib_types_description = | ||
| 61 | ds_type("HK_Model", [ | 61 | ds_type("HK_Model", [ |
| 62 | alternative("hk_model", [ | 62 | alternative("hk_model", [ |
| 63 | component(list, extern_type("HK_Model_Column", model_types+"hk_model_column.anubis"), "columns", comment("columns other than the primary key column (if any)")), | 63 | component(list, extern_type("HK_Model_Column", model_types+"hk_model_column.anubis"), "columns", comment("columns other than the primary key column (if any)")), |
| 64 | + component(list, extern_type("HK_Constraint", model_types+"hk_constraint.anubis"), "constraints"), | ||
| 64 | component(string, "show_string") | 65 | component(string, "show_string") |
| 65 | ]) | 66 | ]) |
| 66 | ]), | 67 | ]), |
| @@ -107,9 +108,11 @@ public define List(DS_Type_File) hayamiki_lib_types_description = | @@ -107,9 +108,11 @@ public define List(DS_Type_File) hayamiki_lib_types_description = | ||
| 107 | [ | 108 | [ |
| 108 | component(extern_type("HK_Text_Field_Attr", model_types+"hk_text_field_attr.anubis"), "hk_text_field_attr"), | 109 | component(extern_type("HK_Text_Field_Attr", model_types+"hk_text_field_attr.anubis"), "hk_text_field_attr"), |
| 109 | ]), | 110 | ]), |
| 110 | - enum("color_field", comment("String which representing RGBA color like HTML")), | ||
| 111 | - enum("phone_field", comment("phone field")), | ||
| 112 | - enum("email_field", comment("email field")), | 111 | + enum("color_field", comment("String which representing RGBA color like HTML")), |
| 112 | + enum("phone_field", comment("phone field")), | ||
| 113 | + enum("mobile_field", comment("mobile phone field")), | ||
| 114 | + enum("url_field", comment("url field for website and so forth")), | ||
| 115 | + enum("email_field", comment("email field")), | ||
| 113 | ]), | 116 | ]), |
| 114 | 117 | ||
| 115 | // | 118 | // |
| @@ -173,8 +176,23 @@ public define List(DS_Type_File) hayamiki_lib_types_description = | @@ -173,8 +176,23 @@ public define List(DS_Type_File) hayamiki_lib_types_description = | ||
| 173 | ]), | 176 | ]), |
| 174 | enum("not_null"), | 177 | enum("not_null"), |
| 175 | ]), | 178 | ]), |
| 176 | - | ||
| 177 | - | 179 | + |
| 180 | + //HK_CONSTRAINT | ||
| 181 | + ds_type("HK_Constraint", [ | ||
| 182 | + alternative("unique", [ | ||
| 183 | + component(string, "name"), | ||
| 184 | + component(list, string, "columns", comment("columns on which the constraint is bound")), | ||
| 185 | + component(extern_type("HK_On_Conflict", model_types+"hk_on_conflict.anubis"), "on_conflict") | ||
| 186 | + ]) | ||
| 187 | + ]), | ||
| 188 | + | ||
| 189 | + ds_type("HK_On_Conflict" ,[ | ||
| 190 | + enum("rollback"), | ||
| 191 | + enum("abort"), | ||
| 192 | + enum("fail"), | ||
| 193 | + enum("ignore"), | ||
| 194 | + enum("replace") | ||
| 195 | + ]), | ||
| 178 | 196 | ||
| 179 | //HK_DISPLAY | 197 | //HK_DISPLAY |
| 180 | ds_type("HK_Display", [ | 198 | ds_type("HK_Display", [ |
model/fields.anubis
| @@ -254,7 +254,15 @@ public define JsonValue | @@ -254,7 +254,15 @@ public define JsonValue | ||
| 254 | phone_field then | 254 | phone_field then |
| 255 | [ json_member("type", json_string("phone_field")) | 255 | [ json_member("type", json_string("phone_field")) |
| 256 | ], | 256 | ], |
| 257 | - | 257 | + |
| 258 | + mobile_field then | ||
| 259 | + [ json_member("type", json_string("mobile_field")) | ||
| 260 | + ], | ||
| 261 | + | ||
| 262 | + url_field then | ||
| 263 | + [ json_member("type", json_string("url_field")) | ||
| 264 | + ], | ||
| 265 | + | ||
| 258 | email_field then | 266 | email_field then |
| 259 | [ json_member("type", json_string("email_field")) | 267 | [ json_member("type", json_string("email_field")) |
| 260 | ] | 268 | ] |
model/model.anubis
| @@ -11,6 +11,13 @@ transmit columns.anubis | @@ -11,6 +11,13 @@ transmit columns.anubis | ||
| 11 | transmit calexium_lib/web/CXM_json.anubis | 11 | transmit calexium_lib/web/CXM_json.anubis |
| 12 | transmit hayamiki_lib/model/types/hk_model.anubis | 12 | transmit hayamiki_lib/model/types/hk_model.anubis |
| 13 | 13 | ||
| 14 | +public define HK_Model | ||
| 15 | + hk_model( | ||
| 16 | + List(HK_Model_Column) columns, //columns other than the primary key column (if any) | ||
| 17 | + String show_string | ||
| 18 | + )= | ||
| 19 | + hk_model(columns, [], show_string) | ||
| 20 | +. | ||
| 14 | 21 | ||
| 15 | _HK_MODEL message format: | 22 | _HK_MODEL message format: |
| 16 | ======================== | 23 | ======================== |
model/tables.anubis
| @@ -12,6 +12,7 @@ transmit model.anubis | @@ -12,6 +12,7 @@ transmit model.anubis | ||
| 12 | transmit calexium_lib/web/CXM_json.anubis | 12 | transmit calexium_lib/web/CXM_json.anubis |
| 13 | 13 | ||
| 14 | transmit hayamiki_lib/model/types/hk_table.anubis | 14 | transmit hayamiki_lib/model/types/hk_table.anubis |
| 15 | +transmit hayamiki_lib/model/types/hk_constraint.anubis | ||
| 15 | 16 | ||
| 16 | public define HK_Table | 17 | public define HK_Table |
| 17 | hk_table | 18 | hk_table |
| 1 | +/* | ||
| 2 | + * Created by 伝作 (Densaku). | ||
| 3 | + * Types & Messages generator written by フランスのトトロ aka (David RENÉ) | ||
| 4 | + * Date: 2017-07-23 | ||
| 5 | + * Time: 21:15:01 | ||
| 6 | + * | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +transmit system/muscle.anubis | ||
| 10 | +transmit system/convert.anubis | ||
| 11 | +transmit tools/basis.anubis | ||
| 12 | + | ||
| 13 | +transmit hayamiki_lib/model/types/hk_on_conflict.anubis | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +public type HK_Constraint: | ||
| 18 | + unique( | ||
| 19 | + String name, | ||
| 20 | + List(String) columns, //columns on which the constraint is bound | ||
| 21 | + HK_On_Conflict on_conflict | ||
| 22 | + ) | ||
| 23 | +. | ||
| 24 | + | ||
| 25 | + HK_Constraint message format | ||
| 26 | + ============================ | ||
| 27 | + | ||
| 28 | + | ||
| 29 | +public define Message | ||
| 30 | + to_Message | ||
| 31 | + ( | ||
| 32 | + HK_Constraint _hk_constraint | ||
| 33 | + )= | ||
| 34 | + with _hk_constraint_message = message((Word32)0), // | ||
| 35 | + forget(add_string(_hk_constraint_message, "__TYPE__", "HK_Constraint")); | ||
| 36 | + if _hk_constraint is | ||
| 37 | + { | ||
| 38 | + //Alternative unique | ||
| 39 | + unique(_name, __columns, _on_conflict) then | ||
| 40 | + forget(add_string(_hk_constraint_message, "__TYPE_ALT__", "unique")); | ||
| 41 | + // [type = String] unique.name | ||
| 42 | + forget(add_string(_hk_constraint_message, "name", _name)); | ||
| 43 | + // [type = List(String)] unique.columns | ||
| 44 | + map_forget((String _columns) |-> add_string(_hk_constraint_message, "columns", _columns), __columns); | ||
| 45 | + // [type = HK_On_Conflict] unique.on_conflict | ||
| 46 | + forget(add_message(_hk_constraint_message, "on_conflict", to_Message(_on_conflict))), | ||
| 47 | + | ||
| 48 | + }; | ||
| 49 | + _hk_constraint_message | ||
| 50 | +. | ||
| 51 | + | ||
| 52 | +public define Maybe(HK_Constraint) | ||
| 53 | + from_Message | ||
| 54 | + ( | ||
| 55 | + Message _hk_constraint_message | ||
| 56 | + )= | ||
| 57 | + if find_string(_hk_constraint_message, "__TYPE__") is {failure then failure, success(__type__) then | ||
| 58 | + if find_string(_hk_constraint_message, "__TYPE_ALT__") is {failure then failure, success(__type_alt__) then | ||
| 59 | + if __type__ = "HK_Constraint" then | ||
| 60 | + //Alternative unique | ||
| 61 | + if __type_alt__ = "unique" then //Alternative unique | ||
| 62 | + // [type = String] unique.name | ||
| 63 | + if find_string(_hk_constraint_message, "name") is {failure then failure, success(_name_) then | ||
| 64 | + // [type = List(String)] unique.columns | ||
| 65 | + with _columns_ = find_string_list(_hk_constraint_message, "columns"), | ||
| 66 | + // [type = HK_On_Conflict] unique.on_conflict | ||
| 67 | + if find_message(_hk_constraint_message, "on_conflict") is {failure then failure, success(_on_conflict__msg) then | ||
| 68 | + if (Maybe(HK_On_Conflict))from_Message(_on_conflict__msg) is {failure then failure, success(_on_conflict_) then | ||
| 69 | + | ||
| 70 | + success(unique(_name_, _columns_, _on_conflict_)) | ||
| 71 | + }}} | ||
| 72 | + else | ||
| 73 | + failure //No valid Alternative found ! | ||
| 74 | + else | ||
| 75 | + failure //Type not found in message ! | ||
| 76 | + }} | ||
| 77 | +. | ||
| 78 | + |
model/types/hk_model.anubis
| 1 | /* | 1 | /* |
| 2 | * Created by 伝作 (Densaku). | 2 | * Created by 伝作 (Densaku). |
| 3 | * Types & Messages generator written by フランスのトトロ aka (David RENÉ) | 3 | * Types & Messages generator written by フランスのトトロ aka (David RENÉ) |
| 4 | - * Date: 2017-05-19 | ||
| 5 | - * Time: 09:24:24 | 4 | + * Date: 2017-07-23 |
| 5 | + * Time: 21:35:44 | ||
| 6 | * | 6 | * |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| @@ -10,14 +10,16 @@ transmit system/muscle.anubis | @@ -10,14 +10,16 @@ transmit system/muscle.anubis | ||
| 10 | transmit system/convert.anubis | 10 | transmit system/convert.anubis |
| 11 | transmit tools/basis.anubis | 11 | transmit tools/basis.anubis |
| 12 | 12 | ||
| 13 | +transmit hayamiki_lib/model/types/hk_constraint.anubis | ||
| 13 | transmit hayamiki_lib/model/types/hk_model_column.anubis | 14 | transmit hayamiki_lib/model/types/hk_model_column.anubis |
| 14 | 15 | ||
| 15 | 16 | ||
| 16 | 17 | ||
| 17 | public type HK_Model: | 18 | public type HK_Model: |
| 18 | hk_model( | 19 | hk_model( |
| 19 | - List(HK_Model_Column) columns, //columns other than the primary key column (if any) | ||
| 20 | - String show_string | 20 | + List(HK_Model_Column) columns, //columns other than the primary key column (if any) |
| 21 | + List(HK_Constraint) constraints, | ||
| 22 | + String show_string | ||
| 21 | ) | 23 | ) |
| 22 | . | 24 | . |
| 23 | 25 | ||
| @@ -35,10 +37,12 @@ public define Message | @@ -35,10 +37,12 @@ public define Message | ||
| 35 | if _hk_model is | 37 | if _hk_model is |
| 36 | { | 38 | { |
| 37 | //Alternative hk_model | 39 | //Alternative hk_model |
| 38 | - hk_model(__columns, _show_string) then | 40 | + hk_model(__columns, __constraints, _show_string) then |
| 39 | forget(add_string(_hk_model_message, "__TYPE_ALT__", "hk_model")); | 41 | forget(add_string(_hk_model_message, "__TYPE_ALT__", "hk_model")); |
| 40 | // [type = List(HK_Model_Column)] hk_model.columns | 42 | // [type = List(HK_Model_Column)] hk_model.columns |
| 41 | map_forget((HK_Model_Column _columns) |-> add_message(_hk_model_message, "columns", to_Message(_columns)), __columns); | 43 | map_forget((HK_Model_Column _columns) |-> add_message(_hk_model_message, "columns", to_Message(_columns)), __columns); |
| 44 | + // [type = List(HK_Constraint)] hk_model.constraints | ||
| 45 | + map_forget((HK_Constraint _constraints) |-> add_message(_hk_model_message, "constraints", to_Message(_constraints)), __constraints); | ||
| 42 | // [type = String] hk_model.show_string | 46 | // [type = String] hk_model.show_string |
| 43 | forget(add_string(_hk_model_message, "show_string", _show_string)), | 47 | forget(add_string(_hk_model_message, "show_string", _show_string)), |
| 44 | 48 | ||
| @@ -59,11 +63,14 @@ public define Maybe(HK_Model) | @@ -59,11 +63,14 @@ public define Maybe(HK_Model) | ||
| 59 | // [type = List(HK_Model_Column)] hk_model.columns | 63 | // [type = List(HK_Model_Column)] hk_model.columns |
| 60 | with mb__columns_ = map_escape(( Message msg ) |-> (Maybe(HK_Model_Column)) from_Message(msg), find_messages(_hk_model_message, "columns")), | 64 | with mb__columns_ = map_escape(( Message msg ) |-> (Maybe(HK_Model_Column)) from_Message(msg), find_messages(_hk_model_message, "columns")), |
| 61 | if mb__columns_ is {failure then failure, success(_columns_) then | 65 | if mb__columns_ is {failure then failure, success(_columns_) then |
| 66 | + // [type = List(HK_Constraint)] hk_model.constraints | ||
| 67 | + with mb__constraints_ = map_escape(( Message msg ) |-> (Maybe(HK_Constraint)) from_Message(msg), find_messages(_hk_model_message, "constraints")), | ||
| 68 | + if mb__constraints_ is {failure then failure, success(_constraints_) then | ||
| 62 | // [type = String] hk_model.show_string | 69 | // [type = String] hk_model.show_string |
| 63 | if find_string(_hk_model_message, "show_string") is {failure then failure, success(_show_string_) then | 70 | if find_string(_hk_model_message, "show_string") is {failure then failure, success(_show_string_) then |
| 64 | 71 | ||
| 65 | - success(hk_model(_columns_, _show_string_)) | ||
| 66 | - }} | 72 | + success(hk_model(_columns_, _constraints_, _show_string_)) |
| 73 | + }}} | ||
| 67 | else | 74 | else |
| 68 | failure //No valid Alternative found ! | 75 | failure //No valid Alternative found ! |
| 69 | else | 76 | else |
model/types/hk_model_field.anubis
| 1 | /* | 1 | /* |
| 2 | * Created by 伝作 (Densaku). | 2 | * Created by 伝作 (Densaku). |
| 3 | * Types & Messages generator written by フランスのトトロ aka (David RENÉ) | 3 | * Types & Messages generator written by フランスのトトロ aka (David RENÉ) |
| 4 | - * Date: 2017-05-24 | ||
| 5 | - * Time: 01:57:03 | 4 | + * Date: 2017-07-23 |
| 5 | + * Time: 21:35:44 | ||
| 6 | * | 6 | * |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| @@ -55,6 +55,8 @@ public type HK_Model_Field: | @@ -55,6 +55,8 @@ public type HK_Model_Field: | ||
| 55 | ), | 55 | ), |
| 56 | color_field, //String which representing RGBA color like HTML | 56 | color_field, //String which representing RGBA color like HTML |
| 57 | phone_field, //phone field | 57 | phone_field, //phone field |
| 58 | + mobile_field, //mobile phone field | ||
| 59 | + url_field, //url field for website and so forth | ||
| 58 | email_field //email field | 60 | email_field //email field |
| 59 | . | 61 | . |
| 60 | 62 | ||
| @@ -147,6 +149,14 @@ public define Message | @@ -147,6 +149,14 @@ public define Message | ||
| 147 | phone_field then | 149 | phone_field then |
| 148 | forget(add_string(_hk_model_field_message, "__TYPE_ALT__", "phone_field")), | 150 | forget(add_string(_hk_model_field_message, "__TYPE_ALT__", "phone_field")), |
| 149 | 151 | ||
| 152 | + //Alternative mobile_field (NO TYPE) | ||
| 153 | + mobile_field then | ||
| 154 | + forget(add_string(_hk_model_field_message, "__TYPE_ALT__", "mobile_field")), | ||
| 155 | + | ||
| 156 | + //Alternative url_field (NO TYPE) | ||
| 157 | + url_field then | ||
| 158 | + forget(add_string(_hk_model_field_message, "__TYPE_ALT__", "url_field")), | ||
| 159 | + | ||
| 150 | //Alternative email_field (NO TYPE) | 160 | //Alternative email_field (NO TYPE) |
| 151 | email_field then | 161 | email_field then |
| 152 | forget(add_string(_hk_model_field_message, "__TYPE_ALT__", "email_field")), | 162 | forget(add_string(_hk_model_field_message, "__TYPE_ALT__", "email_field")), |
| @@ -251,6 +261,12 @@ public define Maybe(HK_Model_Field) | @@ -251,6 +261,12 @@ public define Maybe(HK_Model_Field) | ||
| 251 | else //Alternative phone_field (NO TYPE) | 261 | else //Alternative phone_field (NO TYPE) |
| 252 | if __type_alt__ = "phone_field" then | 262 | if __type_alt__ = "phone_field" then |
| 253 | success(phone_field) | 263 | success(phone_field) |
| 264 | + else //Alternative mobile_field (NO TYPE) | ||
| 265 | + if __type_alt__ = "mobile_field" then | ||
| 266 | + success(mobile_field) | ||
| 267 | + else //Alternative url_field (NO TYPE) | ||
| 268 | + if __type_alt__ = "url_field" then | ||
| 269 | + success(url_field) | ||
| 254 | else //Alternative email_field (NO TYPE) | 270 | else //Alternative email_field (NO TYPE) |
| 255 | if __type_alt__ = "email_field" then | 271 | if __type_alt__ = "email_field" then |
| 256 | success(email_field) | 272 | success(email_field) |
| 1 | +/* | ||
| 2 | + * Created by 伝作 (Densaku). | ||
| 3 | + * Types & Messages generator written by フランスのトトロ aka (David RENÉ) | ||
| 4 | + * Date: 2017-07-23 | ||
| 5 | + * Time: 21:15:01 | ||
| 6 | + * | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +transmit system/muscle.anubis | ||
| 10 | +transmit system/convert.anubis | ||
| 11 | +transmit tools/basis.anubis | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +public type HK_On_Conflict: | ||
| 17 | + rollback, | ||
| 18 | + abort, | ||
| 19 | + fail, | ||
| 20 | + ignore, | ||
| 21 | + replace | ||
| 22 | +. | ||
| 23 | + | ||
| 24 | + HK_On_Conflict message format | ||
| 25 | + ============================= | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +public define Message | ||
| 29 | + to_Message | ||
| 30 | + ( | ||
| 31 | + HK_On_Conflict _hk_on_conflict | ||
| 32 | + )= | ||
| 33 | + with _hk_on_conflict_message = message((Word32)0), // | ||
| 34 | + forget(add_string(_hk_on_conflict_message, "__TYPE__", "HK_On_Conflict")); | ||
| 35 | + if _hk_on_conflict is | ||
| 36 | + { | ||
| 37 | + //Alternative rollback (NO TYPE) | ||
| 38 | + rollback then | ||
| 39 | + forget(add_string(_hk_on_conflict_message, "__TYPE_ALT__", "rollback")), | ||
| 40 | + | ||
| 41 | + //Alternative abort (NO TYPE) | ||
| 42 | + abort then | ||
| 43 | + forget(add_string(_hk_on_conflict_message, "__TYPE_ALT__", "abort")), | ||
| 44 | + | ||
| 45 | + //Alternative fail (NO TYPE) | ||
| 46 | + fail then | ||
| 47 | + forget(add_string(_hk_on_conflict_message, "__TYPE_ALT__", "fail")), | ||
| 48 | + | ||
| 49 | + //Alternative ignore (NO TYPE) | ||
| 50 | + ignore then | ||
| 51 | + forget(add_string(_hk_on_conflict_message, "__TYPE_ALT__", "ignore")), | ||
| 52 | + | ||
| 53 | + //Alternative replace (NO TYPE) | ||
| 54 | + replace then | ||
| 55 | + forget(add_string(_hk_on_conflict_message, "__TYPE_ALT__", "replace")), | ||
| 56 | + | ||
| 57 | + }; | ||
| 58 | + _hk_on_conflict_message | ||
| 59 | +. | ||
| 60 | + | ||
| 61 | +public define Maybe(HK_On_Conflict) | ||
| 62 | + from_Message | ||
| 63 | + ( | ||
| 64 | + Message _hk_on_conflict_message | ||
| 65 | + )= | ||
| 66 | + if find_string(_hk_on_conflict_message, "__TYPE__") is {failure then failure, success(__type__) then | ||
| 67 | + if find_string(_hk_on_conflict_message, "__TYPE_ALT__") is {failure then failure, success(__type_alt__) then | ||
| 68 | + if __type__ = "HK_On_Conflict" then | ||
| 69 | + //Alternative rollback (NO TYPE) | ||
| 70 | + if __type_alt__ = "rollback" then | ||
| 71 | + success(rollback) | ||
| 72 | + else //Alternative abort (NO TYPE) | ||
| 73 | + if __type_alt__ = "abort" then | ||
| 74 | + success(abort) | ||
| 75 | + else //Alternative fail (NO TYPE) | ||
| 76 | + if __type_alt__ = "fail" then | ||
| 77 | + success(fail) | ||
| 78 | + else //Alternative ignore (NO TYPE) | ||
| 79 | + if __type_alt__ = "ignore" then | ||
| 80 | + success(ignore) | ||
| 81 | + else //Alternative replace (NO TYPE) | ||
| 82 | + if __type_alt__ = "replace" then | ||
| 83 | + success(replace) | ||
| 84 | + else | ||
| 85 | + failure //No valid Alternative found ! | ||
| 86 | + else | ||
| 87 | + failure //Type not found in message ! | ||
| 88 | + }} | ||
| 89 | +. | ||
| 90 | + |