Commit 6b95d3a55ad17f9e884442211234e56ffd9735b6
1 parent
c67a99e0
add support of Foreign key "on update" and "on delete" directive
Showing
5 changed files
with
295 additions
and
32 deletions
Show diff stats
ds_files/ds_types.anubis
| ... | ... | @@ -92,6 +92,7 @@ public define List(DS_Type_File) hayamiki_lib_types_description = |
| 92 | 92 | component(extern_type("HK_App_Name", model_types+"hk_app_name.anubis"), "app_name"), |
| 93 | 93 | component(string, "table_name"), |
| 94 | 94 | component(list, string, "searchable_fields"), |
| 95 | + component(list, extern_type("HK_Foreign_Key_Clause", model_types+"hk_foreign_key_clause.anubis"), "hk_fk_clause"), | |
| 95 | 96 | ]), |
| 96 | 97 | alternative("integer_field", [ |
| 97 | 98 | component(extern_type("HK_Int_Choices", model_types+"hk_int_choices.anubis"), "choices", comment("integer of arbitrary size ")), |
| ... | ... | @@ -124,12 +125,23 @@ public define List(DS_Type_File) hayamiki_lib_types_description = |
| 124 | 125 | enum("none", comment("Nothing special, normal behaviour")), |
| 125 | 126 | enum("rich_editor", comment("Use richt text editor for that area")) |
| 126 | 127 | ]), |
| 127 | - | |
| 128 | -// ds_type("HK_FK_Attr", [ | |
| 129 | -// alternative("searchable", [ | |
| 130 | -// component(list, string, "searchable_fields") | |
| 131 | -// ]) | |
| 132 | -// ]), | |
| 128 | + | |
| 129 | + ds_type("HK_Foreign_Key_Clause_On_Directive", [ | |
| 130 | + enum("set_null", comment("Set to null")), | |
| 131 | + enum("set_default", comment("Set to Default value")), | |
| 132 | + enum("cascade", comment("cascading the action")), | |
| 133 | + enum("restrict", comment("restrict")), | |
| 134 | + enum("no_action", comment("Do nothing, this is the default behaviour")) | |
| 135 | + ]), | |
| 136 | + | |
| 137 | + ds_type("HK_Foreign_Key_Clause", [ | |
| 138 | + alternative("on_delete", [ | |
| 139 | + component(extern_type("HK_Foreign_Key_Clause_On_Directive", model_types+"hk_foreign_key_clause_on_directive.anubis"), "on_delete") | |
| 140 | + ]), | |
| 141 | + alternative("on_update", [ | |
| 142 | + component(extern_type("HK_Foreign_Key_Clause_On_Directive", model_types+"hk_foreign_key_clause_on_directive.anubis"), "on_update") | |
| 143 | + ]) | |
| 144 | + ]), | |
| 133 | 145 | |
| 134 | 146 | ds_type("HK_Int_Choices", [ |
| 135 | 147 | enum("no_choice", comment("No list choice is available. Hence the user must enter the value")), | ... | ... |
model/fields.anubis
| ... | ... | @@ -147,6 +147,20 @@ define String |
| 147 | 147 | fax then "fax" |
| 148 | 148 | }. |
| 149 | 149 | |
| 150 | +public define String | |
| 151 | + to_String | |
| 152 | + ( | |
| 153 | + HK_Foreign_Key_Clause_On_Directive directive | |
| 154 | + )= | |
| 155 | + if directive is | |
| 156 | + { | |
| 157 | + set_null then "SET NULL", | |
| 158 | + set_default then "SET DEFAULT", | |
| 159 | + cascade then "CASCADE", | |
| 160 | + restrict then "RESTRICT", | |
| 161 | + no_action then "NO ACTION" | |
| 162 | + } | |
| 163 | +. | |
| 150 | 164 | |
| 151 | 165 | public define String |
| 152 | 166 | to_Anubis_source |
| ... | ... | @@ -174,9 +188,64 @@ public define HK_Model_Field |
| 174 | 188 | ( |
| 175 | 189 | String table_name |
| 176 | 190 | )= |
| 177 | - foreign_key(this, table_name, []). | |
| 191 | + foreign_key(this, table_name, [], []). | |
| 192 | + | |
| 193 | + | |
| 194 | +public define HK_Model_Field | |
| 195 | + foreign_key | |
| 196 | + ( | |
| 197 | + HK_App_Name hk_app_name, | |
| 198 | + String table_name | |
| 199 | + )= | |
| 200 | + foreign_key(hk_app_name, table_name, [], []). | |
| 201 | + | |
| 202 | +public define HK_Model_Field | |
| 203 | + foreign_key | |
| 204 | + ( | |
| 205 | + HK_App_Name hk_app_name, | |
| 206 | + String table_name, | |
| 207 | + List(String) searchable_fields | |
| 208 | + )= | |
| 209 | + foreign_key(hk_app_name, table_name, searchable_fields, []). | |
| 210 | + | |
| 211 | +public define HK_Model_Field | |
| 212 | + foreign_key | |
| 213 | + ( | |
| 214 | + HK_App_Name hk_app_name, | |
| 215 | + String table_name, | |
| 216 | + List(HK_Foreign_Key_Clause) fk_clause | |
| 217 | + )= | |
| 218 | + foreign_key(hk_app_name, table_name, [], fk_clause). | |
| 219 | + | |
| 220 | +public define HK_Model_Field | |
| 221 | + foreign_key | |
| 222 | + ( | |
| 223 | + String table_name, | |
| 224 | + List(String) searchable_fields | |
| 225 | + )= | |
| 226 | + foreign_key(this, table_name, searchable_fields, []) | |
| 227 | +. | |
| 228 | + | |
| 229 | +public define HK_Model_Field | |
| 230 | + foreign_key | |
| 231 | + ( | |
| 232 | + String table_name, | |
| 233 | + List(String) searchable_fields, | |
| 234 | + List(HK_Foreign_Key_Clause) fk_clause | |
| 235 | + )= | |
| 236 | + foreign_key(this, table_name, searchable_fields, fk_clause) | |
| 237 | +. | |
| 178 | 238 | |
| 179 | 239 | public define HK_Model_Field |
| 240 | + foreign_key | |
| 241 | + ( | |
| 242 | + String table_name, | |
| 243 | + List(HK_Foreign_Key_Clause) fk_clause | |
| 244 | + )= | |
| 245 | + foreign_key(this, table_name, [], fk_clause) | |
| 246 | +. | |
| 247 | + | |
| 248 | +public define HK_Model_Field | |
| 180 | 249 | text_field |
| 181 | 250 | = |
| 182 | 251 | text_field(none) |
| ... | ... | @@ -240,7 +309,7 @@ public define JsonValue |
| 240 | 309 | json_member("dt_attribute", json_string(to_String(attr))) |
| 241 | 310 | ], |
| 242 | 311 | |
| 243 | - foreign_key(app_name, table_name,_) then // foreign key to 'id' in another (or same) table and column_name for choice selector. | |
| 312 | + foreign_key(app_name, table_name, _, _) then // foreign key to 'id' in another (or same) table and column_name for choice selector. | |
| 244 | 313 | [ json_member("type", json_string("foreign_key")), |
| 245 | 314 | json_member("app_name", to_JSON(app_name)), |
| 246 | 315 | json_member("table_name", json_string(table_name)), | ... | ... |
| 1 | +/* | |
| 2 | + * Created by 伝作 (Densaku). | |
| 3 | + * Types & Messages generator written by フランスのトトロ aka (David RENÉ) | |
| 4 | + * Date: 2018-11-10 | |
| 5 | + * Time: 17:14:38 | |
| 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_foreign_key_clause_on_directive.anubis | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | +public type HK_Foreign_Key_Clause: | |
| 18 | + on_delete( | |
| 19 | + HK_Foreign_Key_Clause_On_Directive on_delete | |
| 20 | + ), | |
| 21 | + on_update( | |
| 22 | + HK_Foreign_Key_Clause_On_Directive on_update | |
| 23 | + ) | |
| 24 | +. | |
| 25 | + | |
| 26 | + HK_Foreign_Key_Clause message format | |
| 27 | + ==================================== | |
| 28 | + | |
| 29 | + | |
| 30 | +public define Message | |
| 31 | + to_Message | |
| 32 | + ( | |
| 33 | + HK_Foreign_Key_Clause _hk_foreign_key_clause | |
| 34 | + )= | |
| 35 | + with _hk_foreign_key_clause_message = message((Word32)0), // | |
| 36 | + forget(add_string(_hk_foreign_key_clause_message, "__TYPE__", "HK_Foreign_Key_Clause")); | |
| 37 | + if _hk_foreign_key_clause is | |
| 38 | + { | |
| 39 | + //Alternative on_delete | |
| 40 | + on_delete(_on_delete) then | |
| 41 | + forget(add_string(_hk_foreign_key_clause_message, "__TYPE_ALT__", "on_delete")); | |
| 42 | + // [type = HK_Foreign_Key_Clause_On_Directive] on_delete.on_delete | |
| 43 | + forget(add_message(_hk_foreign_key_clause_message, "on_delete", to_Message(_on_delete))), | |
| 44 | + | |
| 45 | + //Alternative on_update | |
| 46 | + on_update(_on_update) then | |
| 47 | + forget(add_string(_hk_foreign_key_clause_message, "__TYPE_ALT__", "on_update")); | |
| 48 | + // [type = HK_Foreign_Key_Clause_On_Directive] on_update.on_update | |
| 49 | + forget(add_message(_hk_foreign_key_clause_message, "on_update", to_Message(_on_update))), | |
| 50 | + | |
| 51 | + }; | |
| 52 | + _hk_foreign_key_clause_message | |
| 53 | +. | |
| 54 | + | |
| 55 | +public define Maybe(HK_Foreign_Key_Clause) | |
| 56 | + from_Message | |
| 57 | + ( | |
| 58 | + Message _hk_foreign_key_clause_message | |
| 59 | + )= | |
| 60 | + if find_string(_hk_foreign_key_clause_message, "__TYPE__") is {failure then failure, success(__type__) then | |
| 61 | + if find_string(_hk_foreign_key_clause_message, "__TYPE_ALT__") is {failure then failure, success(__type_alt__) then | |
| 62 | + if __type__ = "HK_Foreign_Key_Clause" then | |
| 63 | + //Alternative on_delete | |
| 64 | + if __type_alt__ = "on_delete" then //Alternative on_delete | |
| 65 | + // [type = HK_Foreign_Key_Clause_On_Directive] on_delete.on_delete | |
| 66 | + if find_message(_hk_foreign_key_clause_message, "on_delete") is {failure then failure, success(_on_delete__msg) then | |
| 67 | + if (Maybe(HK_Foreign_Key_Clause_On_Directive))from_Message(_on_delete__msg) is {failure then failure, success(_on_delete_) then | |
| 68 | + | |
| 69 | + success(on_delete(_on_delete_)) | |
| 70 | + }} | |
| 71 | + else //Alternative on_update | |
| 72 | + if __type_alt__ = "on_update" then //Alternative on_update | |
| 73 | + // [type = HK_Foreign_Key_Clause_On_Directive] on_update.on_update | |
| 74 | + if find_message(_hk_foreign_key_clause_message, "on_update") is {failure then failure, success(_on_update__msg) then | |
| 75 | + if (Maybe(HK_Foreign_Key_Clause_On_Directive))from_Message(_on_update__msg) is {failure then failure, success(_on_update_) then | |
| 76 | + | |
| 77 | + success(on_update(_on_update_)) | |
| 78 | + }} | |
| 79 | + else | |
| 80 | + failure //No valid Alternative found ! | |
| 81 | + else | |
| 82 | + failure //Type not found in message ! | |
| 83 | + }} | |
| 84 | +. | |
| 85 | + | ... | ... |
model/types/hk_foreign_key_clause_on_directive.anubis
0 → 100644
| 1 | +/* | |
| 2 | + * Created by 伝作 (Densaku). | |
| 3 | + * Types & Messages generator written by フランスのトトロ aka (David RENÉ) | |
| 4 | + * Date: 2018-11-10 | |
| 5 | + * Time: 17:14:38 | |
| 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_Foreign_Key_Clause_On_Directive: | |
| 17 | + set_null, //Set to null | |
| 18 | + set_default, //Set to Default value | |
| 19 | + cascade, //cascading the action | |
| 20 | + restrict, //restrict | |
| 21 | + no_action //Do nothing, this is the default behaviour | |
| 22 | +. | |
| 23 | + | |
| 24 | + HK_Foreign_Key_Clause_On_Directive message format | |
| 25 | + ================================================= | |
| 26 | + | |
| 27 | + | |
| 28 | +public define Message | |
| 29 | + to_Message | |
| 30 | + ( | |
| 31 | + HK_Foreign_Key_Clause_On_Directive _hk_foreign_key_clause_on_directive | |
| 32 | + )= | |
| 33 | + with _hk_foreign_key_clause_on_directive_message = message((Word32)0), // | |
| 34 | + forget(add_string(_hk_foreign_key_clause_on_directive_message, "__TYPE__", "HK_Foreign_Key_Clause_On_Directive")); | |
| 35 | + if _hk_foreign_key_clause_on_directive is | |
| 36 | + { | |
| 37 | + //Alternative set_null (NO TYPE) | |
| 38 | + set_null then | |
| 39 | + forget(add_string(_hk_foreign_key_clause_on_directive_message, "__TYPE_ALT__", "set_null")), | |
| 40 | + | |
| 41 | + //Alternative set_default (NO TYPE) | |
| 42 | + set_default then | |
| 43 | + forget(add_string(_hk_foreign_key_clause_on_directive_message, "__TYPE_ALT__", "set_default")), | |
| 44 | + | |
| 45 | + //Alternative cascade (NO TYPE) | |
| 46 | + cascade then | |
| 47 | + forget(add_string(_hk_foreign_key_clause_on_directive_message, "__TYPE_ALT__", "cascade")), | |
| 48 | + | |
| 49 | + //Alternative restrict (NO TYPE) | |
| 50 | + restrict then | |
| 51 | + forget(add_string(_hk_foreign_key_clause_on_directive_message, "__TYPE_ALT__", "restrict")), | |
| 52 | + | |
| 53 | + //Alternative no_action (NO TYPE) | |
| 54 | + no_action then | |
| 55 | + forget(add_string(_hk_foreign_key_clause_on_directive_message, "__TYPE_ALT__", "no_action")), | |
| 56 | + | |
| 57 | + }; | |
| 58 | + _hk_foreign_key_clause_on_directive_message | |
| 59 | +. | |
| 60 | + | |
| 61 | +public define Maybe(HK_Foreign_Key_Clause_On_Directive) | |
| 62 | + from_Message | |
| 63 | + ( | |
| 64 | + Message _hk_foreign_key_clause_on_directive_message | |
| 65 | + )= | |
| 66 | + if find_string(_hk_foreign_key_clause_on_directive_message, "__TYPE__") is {failure then failure, success(__type__) then | |
| 67 | + if find_string(_hk_foreign_key_clause_on_directive_message, "__TYPE_ALT__") is {failure then failure, success(__type_alt__) then | |
| 68 | + if __type__ = "HK_Foreign_Key_Clause_On_Directive" then | |
| 69 | + //Alternative set_null (NO TYPE) | |
| 70 | + if __type_alt__ = "set_null" then | |
| 71 | + success(set_null) | |
| 72 | + else //Alternative set_default (NO TYPE) | |
| 73 | + if __type_alt__ = "set_default" then | |
| 74 | + success(set_default) | |
| 75 | + else //Alternative cascade (NO TYPE) | |
| 76 | + if __type_alt__ = "cascade" then | |
| 77 | + success(cascade) | |
| 78 | + else //Alternative restrict (NO TYPE) | |
| 79 | + if __type_alt__ = "restrict" then | |
| 80 | + success(restrict) | |
| 81 | + else //Alternative no_action (NO TYPE) | |
| 82 | + if __type_alt__ = "no_action" then | |
| 83 | + success(no_action) | |
| 84 | + else | |
| 85 | + failure //No valid Alternative found ! | |
| 86 | + else | |
| 87 | + failure //Type not found in message ! | |
| 88 | + }} | |
| 89 | +. | |
| 90 | + | ... | ... |
model/types/hk_model_field.anubis
| 1 | 1 | /* |
| 2 | 2 | * Created by 伝作 (Densaku). |
| 3 | 3 | * Types & Messages generator written by フランスのトトロ aka (David RENÉ) |
| 4 | - * Date: 2017-09-16 | |
| 5 | - * Time: 09:48:18 | |
| 4 | + * Date: 2018-11-10 | |
| 5 | + * Time: 17:14:38 | |
| 6 | 6 | * |
| 7 | 7 | */ |
| 8 | 8 | |
| ... | ... | @@ -14,54 +14,56 @@ transmit hayamiki_lib/model/types/hk_phone_field_attr.anubis |
| 14 | 14 | transmit hayamiki_lib/model/types/hk_text_field_attr.anubis |
| 15 | 15 | transmit hayamiki_lib/model/types/hk_text_choices.anubis |
| 16 | 16 | transmit hayamiki_lib/model/types/hk_int_choices.anubis |
| 17 | +transmit hayamiki_lib/model/types/hk_foreign_key_clause.anubis | |
| 17 | 18 | transmit hayamiki_lib/model/types/hk_app_name.anubis |
| 18 | 19 | transmit hayamiki_lib/model/types/hk_datetime_field_attr.anubis |
| 19 | 20 | |
| 20 | 21 | |
| 21 | 22 | |
| 22 | 23 | public type HK_Model_Field: |
| 23 | - p_key, | |
| 24 | - boolean_field, //true or false | |
| 24 | + p_key, | |
| 25 | + boolean_field, //true or false | |
| 25 | 26 | date_field( |
| 26 | - HK_Datetime_Field_Attr hk_dt_f_attr //date with the precision of the day | |
| 27 | + HK_Datetime_Field_Attr hk_dt_f_attr //date with the precision of the day | |
| 27 | 28 | ), |
| 28 | 29 | time_field( |
| 29 | - HK_Datetime_Field_Attr hk_dt_f_attr //time with the precision of the second | |
| 30 | + HK_Datetime_Field_Attr hk_dt_f_attr //time with the precision of the second | |
| 30 | 31 | ), |
| 31 | 32 | datetime_field( |
| 32 | - HK_Datetime_Field_Attr hk_dt_f_attr //datetime with the precision of the second | |
| 33 | + HK_Datetime_Field_Attr hk_dt_f_attr //datetime with the precision of the second | |
| 33 | 34 | ), |
| 34 | 35 | //foreign key to 'id' in another (or same) table and column_name for choice selector) |
| 35 | 36 | |
| 36 | 37 | foreign_key( |
| 37 | - HK_App_Name app_name, | |
| 38 | - String table_name, | |
| 39 | - List(String) searchable_fields | |
| 38 | + HK_App_Name app_name, | |
| 39 | + String table_name, | |
| 40 | + List(String) searchable_fields, | |
| 41 | + List(HK_Foreign_Key_Clause) hk_fk_clause | |
| 40 | 42 | ), |
| 41 | 43 | integer_field( |
| 42 | - HK_Int_Choices choices //integer of arbitrary size | |
| 44 | + HK_Int_Choices choices //integer of arbitrary size | |
| 43 | 45 | ), |
| 44 | - float_field, | |
| 46 | + float_field, | |
| 45 | 47 | char_field( |
| 46 | - HK_Text_Choices choices, | |
| 47 | - Int size //text of maximal size 'size' (number of characters) | |
| 48 | + HK_Text_Choices choices, | |
| 49 | + Int size //text of maximal size 'size' (number of characters) | |
| 48 | 50 | ), |
| 49 | 51 | password_field( |
| 50 | - Int min_size //the password field doesn't show the password string or store it in hashed version into database | |
| 52 | + Int min_size //the password field doesn't show the password string or store it in hashed version into database | |
| 51 | 53 | ), |
| 52 | 54 | //text of variable size |
| 53 | 55 | |
| 54 | 56 | text_field( |
| 55 | - HK_Text_Field_Attr hk_text_field_attr | |
| 57 | + HK_Text_Field_Attr hk_text_field_attr | |
| 56 | 58 | ), |
| 57 | - color_field, //String which representing RGBA color like HTML | |
| 59 | + color_field, //String which representing RGBA color like HTML | |
| 58 | 60 | //phone field |
| 59 | 61 | |
| 60 | 62 | phone_field( |
| 61 | - HK_Phone_Field_Attr hk_ph_f_attr //phone line number type like (cellphone, landline, fax, etc) | |
| 63 | + HK_Phone_Field_Attr hk_ph_f_attr //phone line number type like (cellphone, landline, fax, etc) | |
| 62 | 64 | ), |
| 63 | - url_field, //url field for website and so forth | |
| 64 | - email_field //email field | |
| 65 | + url_field, //url field for website and so forth | |
| 66 | + email_field //email field | |
| 65 | 67 | . |
| 66 | 68 | |
| 67 | 69 | HK_Model_Field message format |
| ... | ... | @@ -105,14 +107,16 @@ public define Message |
| 105 | 107 | |
| 106 | 108 | //Alternative foreign_key |
| 107 | 109 | //foreign key to 'id' in another (or same) table and column_name for choice selector) |
| 108 | - foreign_key(_app_name, _table_name, __searchable_fields) then | |
| 110 | + foreign_key(_app_name, _table_name, __searchable_fields, __hk_fk_clause) then | |
| 109 | 111 | forget(add_string(_hk_model_field_message, "__TYPE_ALT__", "foreign_key")); |
| 110 | 112 | // [type = HK_App_Name] foreign_key.app_name |
| 111 | 113 | forget(add_message(_hk_model_field_message, "app_name", to_Message(_app_name))); |
| 112 | 114 | // [type = String] foreign_key.table_name |
| 113 | 115 | forget(add_string(_hk_model_field_message, "table_name", _table_name)); |
| 114 | 116 | // [type = List(String)] foreign_key.searchable_fields |
| 115 | - map_forget((String _searchable_fields) |-> add_string(_hk_model_field_message, "searchable_fields", _searchable_fields), __searchable_fields), | |
| 117 | + map_forget((String _searchable_fields) |-> add_string(_hk_model_field_message, "searchable_fields", _searchable_fields), __searchable_fields); | |
| 118 | + // [type = List(HK_Foreign_Key_Clause)] foreign_key.hk_fk_clause | |
| 119 | + map_forget((HK_Foreign_Key_Clause _hk_fk_clause) |-> add_message(_hk_model_field_message, "hk_fk_clause", to_Message(_hk_fk_clause)), __hk_fk_clause), | |
| 116 | 120 | |
| 117 | 121 | //Alternative integer_field |
| 118 | 122 | integer_field(_choices) then |
| ... | ... | @@ -216,9 +220,12 @@ public define Maybe(HK_Model_Field) |
| 216 | 220 | if find_string(_hk_model_field_message, "table_name") is {failure then failure, success(_table_name_) then |
| 217 | 221 | // [type = List(String)] foreign_key.searchable_fields |
| 218 | 222 | with _searchable_fields_ = find_string_list(_hk_model_field_message, "searchable_fields"), |
| 223 | + // [type = List(HK_Foreign_Key_Clause)] foreign_key.hk_fk_clause | |
| 224 | + with mb__hk_fk_clause_ = map_escape(( Message msg ) |-> (Maybe(HK_Foreign_Key_Clause)) from_Message(msg), find_messages(_hk_model_field_message, "hk_fk_clause")), | |
| 225 | + if mb__hk_fk_clause_ is {failure then failure, success(_hk_fk_clause_) then | |
| 219 | 226 | |
| 220 | - success(foreign_key(_app_name_, _table_name_, _searchable_fields_)) | |
| 221 | - }}} | |
| 227 | + success(foreign_key(_app_name_, _table_name_, _searchable_fields_, _hk_fk_clause_)) | |
| 228 | + }}}} | |
| 222 | 229 | else //Alternative integer_field |
| 223 | 230 | if __type_alt__ = "integer_field" then //Alternative integer_field |
| 224 | 231 | // [type = HK_Int_Choices] integer_field.choices | ... | ... |