Commit dd039c8079292880fce88f46ef86f3c8a967fc7f
1 parent
d771e057
rename almost all db_xx in hk_xx
add HK_App_Name which use to designate the app in foreign_key
Showing
1 changed file
with
164 additions
and
91 deletions
Show diff stats
database/model/db_model.anubis
| ... | ... | @@ -20,14 +20,18 @@ |
| 20 | 20 | |
| 21 | 21 | *** (1) Formal description of the database. |
| 22 | 22 | |
| 23 | - *** (1.1) 'DB_Model_Field' (data types of table columns). | |
| 23 | + *** (1.1) 'HK_Model_Field' (data types of table columns). | |
| 24 | +public type HK_App_Name: | |
| 25 | + this, | |
| 26 | + app_name(String name), | |
| 27 | + none. | |
| 24 | 28 | |
| 25 | 29 | public type DB_Datetime_Field_Attr: |
| 26 | 30 | none, //Nothing special, normal behaviour |
| 27 | 31 | auto_now, //Always update datetime at SQL update |
| 28 | 32 | auto_now_add. //Set current datetime when row is created and can't be edited anymore |
| 29 | 33 | |
| 30 | -public type DB_Model_Field: | |
| 34 | +public type HK_Model_Field: | |
| 31 | 35 | //anubis(String _T), // the datum of type _T is serialized and base64 encoded |
| 32 | 36 | p_key, |
| 33 | 37 | //binary, // contains a byte array |
| ... | ... | @@ -35,11 +39,18 @@ public type DB_Model_Field: |
| 35 | 39 | date_field(DB_Datetime_Field_Attr), // date with the precision of the day |
| 36 | 40 | time_field(DB_Datetime_Field_Attr), // time with the precision of the second |
| 37 | 41 | datetime_field(DB_Datetime_Field_Attr), // datetime with the precision of the second |
| 38 | - foreign_key(String table_name), // foreign key to 'id' in another (or same) table and column_name for choice selector. | |
| 42 | + foreign_key(HK_App_Name app_name, String table_name), // foreign key to 'id' in another (or same) table and column_name for choice selector. | |
| 39 | 43 | integer_field, // integer of arbitrary size |
| 40 | 44 | char_field(Int size), // text of maximal size 'size' (number of characters) |
| 41 | 45 | text_field. // text of variable size |
| 42 | 46 | |
| 47 | +public define HK_Model_Field | |
| 48 | + foreign_key | |
| 49 | + ( | |
| 50 | + String table_name | |
| 51 | + )= | |
| 52 | + foreign_key(this, table_name). | |
| 53 | + | |
| 43 | 54 | From the point of view of your Anubis program, these data will be of types: |
| 44 | 55 | |
| 45 | 56 | Name | Anubis type | Type within the database |
| ... | ... | @@ -74,17 +85,19 @@ public type MaybeNull($T): |
| 74 | 85 | (number of seconds since the epoch) are provided in 'library/tools/ISO-8601.anubis'. |
| 75 | 86 | |
| 76 | 87 | |
| 77 | - *** (1.3) 'DB_Model_Attr' (attributes of columns). | |
| 88 | + *** (1.3) 'HK_Model_Attr' (attributes of columns). | |
| 78 | 89 | |
| 79 | 90 | Possible attributes of columns: (each column has a list of such attributes) |
| 80 | 91 | |
| 81 | -public type DB_Model_Attr: | |
| 92 | +public type HK_Model_Attr: | |
| 82 | 93 | unique, // by default, the values in a column are not required to be all different |
| 83 | 94 | indexed, // by default, a column is not indexed |
| 84 | - default(String). // default value (used in case of creation of a NON NULL column | |
| 95 | + default(String), // default value (used in case of creation of a NON NULL column | |
| 85 | 96 | // in a table which already contains some rows) |
| 97 | + not_null. | |
| 98 | + | |
| 86 | 99 | |
| 87 | -public type DB_Help_Text: | |
| 100 | +public type HK_Help_Text: | |
| 88 | 101 | no_help_text, //no help text available |
| 89 | 102 | help_text_TAG(String), //TAG use with Anubis translation tool /locale/L3.anubis |
| 90 | 103 | help_text(String). //pure text to show |
| ... | ... | @@ -94,7 +107,7 @@ public define String |
| 94 | 107 | */ |
| 95 | 108 | to_Anubis_source |
| 96 | 109 | ( |
| 97 | - DB_Help_Text help | |
| 110 | + HK_Help_Text help | |
| 98 | 111 | )= |
| 99 | 112 | if help is |
| 100 | 113 | { |
| ... | ... | @@ -103,48 +116,48 @@ public define String |
| 103 | 116 | help_text(str) then "help_text(\""+str+"\")" |
| 104 | 117 | }. |
| 105 | 118 | |
| 106 | - Of course, 'NOT NULL' is not an alternative of 'DB_Model_Attr' because it is already coded into the | |
| 107 | - database type itself (type 'DB_Model_Field' above). | |
| 119 | + Of course, 'NOT NULL' is not an alternative of 'HK_Model_Attr' because it is already coded into the | |
| 120 | + database type itself (type 'HK_Model_Field' above). | |
| 108 | 121 | |
| 109 | 122 | |
| 110 | - *** (1.4) 'DB_Model_Column' (describing a column in a table). | |
| 123 | + *** (1.4) 'HK_Model_Column' (describing a column in a table). | |
| 111 | 124 | |
| 112 | 125 | Description of a column: |
| 113 | 126 | |
| 114 | -public type DB_Model_Column: | |
| 115 | - db_column (String name, // name of ordinary column (i.e. all but 'id') | |
| 116 | - DB_Model_Field type, | |
| 117 | - List(DB_Model_Attr) attributes, | |
| 118 | - DB_Help_Text help | |
| 127 | +public type HK_Model_Column: | |
| 128 | + hk_column (String name, // name of ordinary column (i.e. all but 'id') | |
| 129 | + HK_Model_Field type, | |
| 130 | + List(HK_Model_Attr) attributes, | |
| 131 | + HK_Help_Text help | |
| 119 | 132 | ). |
| 120 | 133 | |
| 121 | -public define DB_Model_Column | |
| 134 | +public define HK_Model_Column | |
| 122 | 135 | /* Constructor helper for db_column without help attribute. |
| 123 | 136 | the real type constructor will be called with the attribute no_help_text |
| 124 | 137 | */ |
| 125 | - db_column | |
| 138 | + hk_column | |
| 126 | 139 | ( |
| 127 | 140 | String name, |
| 128 | - DB_Model_Field type, | |
| 129 | - List(DB_Model_Attr) attributes, | |
| 141 | + HK_Model_Field type, | |
| 142 | + List(HK_Model_Attr) attributes, | |
| 130 | 143 | )= |
| 131 | - db_column(name, type, attributes, no_help_text). | |
| 144 | + hk_column(name, type, attributes, no_help_text). | |
| 132 | 145 | |
| 133 | -public define DB_Model_Column | |
| 134 | - db_column | |
| 146 | +public define HK_Model_Column | |
| 147 | + hk_column | |
| 135 | 148 | ( |
| 136 | 149 | String name, |
| 137 | - DB_Model_Field type | |
| 150 | + HK_Model_Field type | |
| 138 | 151 | )= |
| 139 | - db_column(name, type, [], no_help_text). | |
| 152 | + hk_column(name, type, [], no_help_text). | |
| 140 | 153 | |
| 141 | 154 | |
| 142 | 155 | *** (3.7) 'DB_Model_Table' (describing a table). |
| 143 | 156 | |
| 144 | 157 | Description of a table: |
| 145 | 158 | |
| 146 | -public type DB_Model: | |
| 147 | - db_model( List(DB_Model_Column) columns, // columns other than the primary key column (if any) | |
| 159 | +public type HK_Model: | |
| 160 | + hk_model( List(HK_Model_Column) columns, // columns other than the primary key column (if any) | |
| 148 | 161 | String show_string). |
| 149 | 162 | |
| 150 | 163 | public type HK_List_View: |
| ... | ... | @@ -155,23 +168,29 @@ public type HK_Edit_View: |
| 155 | 168 | edit_view_all, |
| 156 | 169 | edit_view(String view_name, List(String) columns). |
| 157 | 170 | |
| 158 | -public type DB_Display: | |
| 171 | +public type HK_Display: | |
| 159 | 172 | db_display(List(HK_List_View) list_views, |
| 160 | 173 | //List(HK_Edit_View) edit_views |
| 161 | 174 | List(String)). |
| 162 | 175 | |
| 163 | -public type DB_Table: | |
| 164 | - db_table ( String name, // name of the table | |
| 165 | - DB_Model model, | |
| 166 | - DB_Display display). | |
| 176 | +public type HK_Table: | |
| 177 | + hk_table ( String name, // name of the table | |
| 178 | + HK_Model model, | |
| 179 | + HK_Display display). | |
| 167 | 180 | |
| 168 | 181 | *** (3.8) 'DB_Database' (describing a whole database). |
| 169 | 182 | |
| 170 | 183 | Description of a whole database: |
| 171 | 184 | |
| 172 | -public type DB_Database: | |
| 173 | - db_database (String name, // name of the database | |
| 174 | - List(DB_Table) tables). | |
| 185 | +public type HK_App: | |
| 186 | + hk_app( String app_name, | |
| 187 | + List(HK_Table) hk_tables | |
| 188 | + ). | |
| 189 | + | |
| 190 | +public type HK_Database: | |
| 191 | + hk_database (String name, // name of the database | |
| 192 | + List(HK_App) apps //list of applications | |
| 193 | + ). | |
| 175 | 194 | // list of all tables in the database |
| 176 | 195 | |
| 177 | 196 | |
| ... | ... | @@ -249,7 +268,27 @@ define macro Maybe(String) |
| 249 | 268 | } |
| 250 | 269 | }. |
| 251 | 270 | |
| 252 | - | |
| 271 | +define Int | |
| 272 | + _max | |
| 273 | + ( | |
| 274 | + List(HK_Model_Column) columns, | |
| 275 | + Int current_max | |
| 276 | + )= | |
| 277 | + if columns is | |
| 278 | + { | |
| 279 | + [] then current_max, | |
| 280 | + [h . t] then | |
| 281 | + since h is hk_column(name, _, _, _), | |
| 282 | + _max(t, max(current_max, length(name))) | |
| 283 | + } | |
| 284 | + . | |
| 285 | + | |
| 286 | +public define Int | |
| 287 | + max | |
| 288 | + ( | |
| 289 | + List(HK_Model_Column) columns | |
| 290 | + )= | |
| 291 | + _max(columns, 0). | |
| 253 | 292 | |
| 254 | 293 | *** [2] Verifications concerning the description of the database and queries. |
| 255 | 294 | |
| ... | ... | @@ -260,8 +299,8 @@ define macro Maybe(String) |
| 260 | 299 | ( |
| 261 | 300 | String table_name, // the first 3 arguments concern the current table. |
| 262 | 301 | MetaSQL_PrimKey pk, |
| 263 | - List(DB_Model_Column) columns, | |
| 264 | - List(DB_Model_Column) forwards, // subsequent tables | |
| 302 | + List(HK_Model_Column) columns, | |
| 303 | + List(HK_Model_Column) forwards, // subsequent tables | |
| 265 | 304 | List(String) backwards // list of backwards table names |
| 266 | 305 | ) = |
| 267 | 306 | if columns is |
| ... | ... | @@ -277,7 +316,7 @@ define macro Maybe(String) |
| 277 | 316 | has_forbidden_cycles |
| 278 | 317 | ( |
| 279 | 318 | String db_name, |
| 280 | - List(DB_Model_Column) tables, | |
| 319 | + List(HK_Model_Column) tables, | |
| 281 | 320 | List(String) backwards // names of 'backwards' tables |
| 282 | 321 | ) = |
| 283 | 322 | if tables is |
| ... | ... | @@ -299,10 +338,10 @@ define macro Maybe(String) |
| 299 | 338 | define Bool |
| 300 | 339 | has_forbidden_column_names |
| 301 | 340 | ( |
| 302 | - DB_Model_Column tab | |
| 341 | + HK_Model_Column tab | |
| 303 | 342 | ) = |
| 304 | 343 | if tab is table(_,_,cols) then |
| 305 | - mapor((DB_Model_Column cs) |-> | |
| 344 | + mapor((HK_Model_Column cs) |-> | |
| 306 | 345 | if cs is col(name,_,_) then is_forbidden_column_name(name), |
| 307 | 346 | cols). |
| 308 | 347 | |
| ... | ... | @@ -323,7 +362,7 @@ define macro Maybe(String) |
| 323 | 362 | public define String |
| 324 | 363 | to_Anubis_type |
| 325 | 364 | ( |
| 326 | - DB_Model_Field t | |
| 365 | + HK_Model_Field t | |
| 327 | 366 | ) = |
| 328 | 367 | if t is |
| 329 | 368 | { |
| ... | ... | @@ -334,17 +373,51 @@ public define String |
| 334 | 373 | date_field(_) then "DB_date", |
| 335 | 374 | time_field(_) then "DB_time", |
| 336 | 375 | datetime_field(_) then "DB_datetime", |
| 337 | - foreign_key(_) then "Int", | |
| 376 | + foreign_key(_,_) then "Int", | |
| 338 | 377 | integer_field then "Int", |
| 339 | 378 | char_field(Int size) then "String", |
| 340 | 379 | text_field then "String" |
| 341 | 380 | }. |
| 342 | 381 | |
| 343 | - | |
| 382 | +define String | |
| 383 | + format_attributes | |
| 384 | + ( | |
| 385 | + List(HK_Model_Attr) attributes | |
| 386 | + )= | |
| 387 | + join(" ",map((HK_Model_Attr attr) |-> | |
| 388 | + if attr is | |
| 389 | + { | |
| 390 | + unique then "UNIQUE", | |
| 391 | + indexed then "INDEXED", // by default, a column is not indexed | |
| 392 | + default(str) then "DEFAULT "+str, // default value (used in case of creation of a NON NULL column | |
| 393 | + // in a table which already contains some rows) | |
| 394 | + not_null then "NOT NULL" | |
| 395 | + }, attributes)). | |
| 396 | + | |
| 397 | +public define String | |
| 398 | + to_SQL_CREATE | |
| 399 | + ( | |
| 400 | + HK_Model_Field t, | |
| 401 | + List(HK_Model_Attr) attributes, | |
| 402 | + ) = | |
| 403 | + if t is | |
| 404 | + { | |
| 405 | + //anubis(_T) then "ByteArray", | |
| 406 | + p_key then fill("INTEGER", 15) +" PRIMARY KEY", | |
| 407 | + boolean_field then fill("BOOL", 15) +format_attributes(attributes), | |
| 408 | + date_field(_) then fill("DATE", 15) +format_attributes(attributes), | |
| 409 | + time_field(_) then fill("TIME", 15) +format_attributes(attributes), | |
| 410 | + datetime_field(_) then fill("DATETIME", 15)+format_attributes(attributes), | |
| 411 | + foreign_key(app,fk) then fill("INTEGER", 15) +" NOT NULL REFERENCES "+fk+" (id)", | |
| 412 | + integer_field then fill("INTEGER", 15) +format_attributes(attributes), | |
| 413 | + char_field(Int size) then fill("VARCHAR("+size+")", 15) +format_attributes(attributes), | |
| 414 | + text_field then fill("TEXT", 15) +format_attributes(attributes), | |
| 415 | + }. | |
| 416 | + | |
| 344 | 417 | public define String |
| 345 | 418 | to_Anubis_default |
| 346 | 419 | ( |
| 347 | - DB_Model_Field t | |
| 420 | + HK_Model_Field t | |
| 348 | 421 | ) = |
| 349 | 422 | if t is |
| 350 | 423 | { |
| ... | ... | @@ -355,7 +428,7 @@ public define String |
| 355 | 428 | date_field(_) then "db_date(\"\")", |
| 356 | 429 | time_field(_) then "db_time(\"\")", |
| 357 | 430 | datetime_field(_) then "db_datetime(\"\")", |
| 358 | - foreign_key(_) then "(Int)0", | |
| 431 | + foreign_key(_,_) then "(Int)0", | |
| 359 | 432 | integer_field then "(Int)0", |
| 360 | 433 | char_field(Int size) then "\"\"", |
| 361 | 434 | text_field then "\"\"" |
| ... | ... | @@ -364,7 +437,7 @@ public define String |
| 364 | 437 | public define String |
| 365 | 438 | from_DB_cursor |
| 366 | 439 | ( |
| 367 | - DB_Model_Field t, | |
| 440 | + HK_Model_Field t, | |
| 368 | 441 | String cursor, |
| 369 | 442 | Int index |
| 370 | 443 | ) = |
| ... | ... | @@ -378,7 +451,7 @@ public define String |
| 378 | 451 | date_field(_) then "db_date(text"+cursor_index+")", |
| 379 | 452 | time_field(_) then "db_time(text"+cursor_index+")", |
| 380 | 453 | datetime_field(_) then "db_datetime(text"+cursor_index+")", |
| 381 | - foreign_key(_) then "(Int)db_integer"+cursor_index, | |
| 454 | + foreign_key(_,_) then "(Int)db_integer"+cursor_index, | |
| 382 | 455 | integer_field then "(Int)db_integer"+cursor_index, |
| 383 | 456 | char_field(Int size) then "text"+cursor_index, |
| 384 | 457 | text_field then "text"+cursor_index |
| ... | ... | @@ -389,7 +462,7 @@ define List(String) |
| 389 | 462 | */ |
| 390 | 463 | components |
| 391 | 464 | ( |
| 392 | - List(DB_Model_Column) columns, | |
| 465 | + List(HK_Model_Column) columns, | |
| 393 | 466 | String cursor_name, |
| 394 | 467 | List(String) so_far, |
| 395 | 468 | Int idx |
| ... | ... | @@ -398,7 +471,7 @@ define List(String) |
| 398 | 471 | { |
| 399 | 472 | [] then reverse(so_far), |
| 400 | 473 | [h . t ] then |
| 401 | - since h is db_column(name, col_type, _, _), | |
| 474 | + since h is hk_column(name, col_type, _, _), | |
| 402 | 475 | with line = fill(from_DB_cursor(col_type, cursor_name, idx), 35)+ "/* "+name+" */", |
| 403 | 476 | components(t, cursor_name, [line . so_far], idx + 1 ) |
| 404 | 477 | }. |
| ... | ... | @@ -408,7 +481,7 @@ public define String |
| 408 | 481 | ( |
| 409 | 482 | String constructor_name, |
| 410 | 483 | String cursor_name, |
| 411 | - List(DB_Model_Column) columns, | |
| 484 | + List(HK_Model_Column) columns, | |
| 412 | 485 | String indent |
| 413 | 486 | )= |
| 414 | 487 | indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", components(columns, cursor_name, [], 0))+"\n"+indent+")". |
| ... | ... | @@ -417,7 +490,7 @@ public define String |
| 417 | 490 | public define String |
| 418 | 491 | from_web_arg |
| 419 | 492 | ( |
| 420 | - DB_Model_Field t, | |
| 493 | + HK_Model_Field t, | |
| 421 | 494 | String name |
| 422 | 495 | ) = |
| 423 | 496 | if t is |
| ... | ... | @@ -429,7 +502,7 @@ public define String |
| 429 | 502 | date_field(attrs) then if attrs = none then "get_DB_date(lwa, \""+name+"\")" else "with "+name+" = get_dummy_DB_date,", |
| 430 | 503 | time_field(attrs) then if attrs = none then "get_DB_time(lwa, \""+name+"\")" else "with "+name+" = get_dummy_DB_time,", |
| 431 | 504 | datetime_field(attrs) then if attrs = none then "get_DB_datetime(lwa, \""+name+"\")" else "with "+name+" = get_dummy_DB_datetime,", |
| 432 | - foreign_key(String table) then "get_Int(lwa, \""+name+"\")", | |
| 505 | + foreign_key(_,_) then "get_Int(lwa, \""+name+"\")", | |
| 433 | 506 | integer_field then "get_Int(lwa, \""+name+"\")", |
| 434 | 507 | char_field(Int size) then "get_String(lwa, \""+name+"\")", |
| 435 | 508 | text_field then "get_String(lwa, \""+name+"\")" |
| ... | ... | @@ -440,7 +513,7 @@ define List(String) |
| 440 | 513 | */ |
| 441 | 514 | _to_List_String |
| 442 | 515 | ( |
| 443 | - List(DB_Model_Column) columns, | |
| 516 | + List(HK_Model_Column) columns, | |
| 444 | 517 | Bool with_pk, |
| 445 | 518 | List(String) so_far |
| 446 | 519 | )= |
| ... | ... | @@ -448,7 +521,7 @@ define List(String) |
| 448 | 521 | { |
| 449 | 522 | [] then reverse(so_far), |
| 450 | 523 | [h . t ] then |
| 451 | - since h is db_column(name, _, _, _), | |
| 524 | + since h is hk_column(name, _, _, _), | |
| 452 | 525 | if name = "id" & with_pk = false then |
| 453 | 526 | _to_List_String(t, with_pk, so_far) |
| 454 | 527 | else |
| ... | ... | @@ -460,7 +533,7 @@ public define List(String) |
| 460 | 533 | */ |
| 461 | 534 | to_List_String |
| 462 | 535 | ( |
| 463 | - List(DB_Model_Column) columns, | |
| 536 | + List(HK_Model_Column) columns, | |
| 464 | 537 | Bool with_pk |
| 465 | 538 | )= |
| 466 | 539 | _to_List_String(columns, with_pk, []). |
| ... | ... | @@ -470,7 +543,7 @@ public define String |
| 470 | 543 | generate_constructor |
| 471 | 544 | ( |
| 472 | 545 | String constructor_name, |
| 473 | - List(DB_Model_Column) columns, | |
| 546 | + List(HK_Model_Column) columns, | |
| 474 | 547 | String indent |
| 475 | 548 | )= |
| 476 | 549 | indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", to_List_String(columns, true))+")". |
| ... | ... | @@ -478,7 +551,7 @@ public define String |
| 478 | 551 | public define String |
| 479 | 552 | to_Bind |
| 480 | 553 | ( |
| 481 | - DB_Model_Field t, | |
| 554 | + HK_Model_Field t, | |
| 482 | 555 | String type_name, //name of the type |
| 483 | 556 | String name, //name of component into the type |
| 484 | 557 | Bool insert //true if insert time else false for update |
| ... | ... | @@ -501,7 +574,7 @@ public define String |
| 501 | 574 | else |
| 502 | 575 | "" |
| 503 | 576 | }, |
| 504 | - foreign_key(_) then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")", | |
| 577 | + foreign_key(_,_) then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")", | |
| 505 | 578 | integer_field then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")", |
| 506 | 579 | char_field(Int size) then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")", |
| 507 | 580 | text_field then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")" |
| ... | ... | @@ -512,7 +585,7 @@ public define List(String) |
| 512 | 585 | */ |
| 513 | 586 | to_Bind_list |
| 514 | 587 | ( |
| 515 | - List(DB_Model_Column) columns, | |
| 588 | + List(HK_Model_Column) columns, | |
| 516 | 589 | String type_name, //name of the type |
| 517 | 590 | List(String) so_far, |
| 518 | 591 | Bool insert |
| ... | ... | @@ -521,7 +594,7 @@ public define List(String) |
| 521 | 594 | { |
| 522 | 595 | [] then reverse(so_far), |
| 523 | 596 | [h . t ] then |
| 524 | - since h is db_column(name, col_type, _, _), | |
| 597 | + since h is hk_column(name, col_type, _, _), | |
| 525 | 598 | with result = to_Bind(col_type, type_name, name, insert), |
| 526 | 599 | //we eliminate the empty string because during the join it will have an empty line |
| 527 | 600 | if result = "" then |
| ... | ... | @@ -533,7 +606,7 @@ public define List(String) |
| 533 | 606 | public define String |
| 534 | 607 | generate_Bind_list |
| 535 | 608 | ( |
| 536 | - List(DB_Model_Column) columns, | |
| 609 | + List(HK_Model_Column) columns, | |
| 537 | 610 | String type_name, |
| 538 | 611 | String indent, |
| 539 | 612 | Bool insert |
| ... | ... | @@ -544,10 +617,10 @@ public define String |
| 544 | 617 | public define Maybe(String) |
| 545 | 618 | get_column_name |
| 546 | 619 | ( |
| 547 | - DB_Model_Column col, | |
| 620 | + HK_Model_Column col, | |
| 548 | 621 | Bool insert //true if insert time else false for update |
| 549 | 622 | ) = |
| 550 | - since col is db_column(name, col_type, _, _), | |
| 623 | + since col is hk_column(name, col_type, _, _), | |
| 551 | 624 | if col_type is |
| 552 | 625 | { |
| 553 | 626 | //anubis(_T) then "constant_byte_array(0,0)", |
| ... | ... | @@ -563,7 +636,7 @@ public define Maybe(String) |
| 563 | 636 | auto_now_add then |
| 564 | 637 | if insert then success(name) else failure |
| 565 | 638 | }, |
| 566 | - foreign_key(_) then success(name), | |
| 639 | + foreign_key(_,_) then success(name), | |
| 567 | 640 | integer_field then success(name), |
| 568 | 641 | char_field(Int size) then success(name), |
| 569 | 642 | text_field then success(name) |
| ... | ... | @@ -572,7 +645,7 @@ public define Maybe(String) |
| 572 | 645 | public define List(String) |
| 573 | 646 | columns_name |
| 574 | 647 | ( |
| 575 | - List(DB_Model_Column) columns, | |
| 648 | + List(HK_Model_Column) columns, | |
| 576 | 649 | Bool insert, //true if insert time else false for update |
| 577 | 650 | List(String) so_far |
| 578 | 651 | ) = |
| ... | ... | @@ -598,7 +671,7 @@ public define String |
| 598 | 671 | */ |
| 599 | 672 | insert_values |
| 600 | 673 | ( |
| 601 | - List(DB_Model_Column) columns, | |
| 674 | + List(HK_Model_Column) columns, | |
| 602 | 675 | String indent |
| 603 | 676 | )= |
| 604 | 677 | with columns_list = columns_name(columns, true, []), |
| ... | ... | @@ -612,7 +685,7 @@ public define String |
| 612 | 685 | */ |
| 613 | 686 | update_values |
| 614 | 687 | ( |
| 615 | - List(DB_Model_Column) columns, | |
| 688 | + List(HK_Model_Column) columns, | |
| 616 | 689 | String indent |
| 617 | 690 | )= |
| 618 | 691 | with columns_list = columns_name(columns, false, []), |
| ... | ... | @@ -622,10 +695,10 @@ public define String |
| 622 | 695 | public define Maybe(String) |
| 623 | 696 | get_VT_edit_entry |
| 624 | 697 | ( |
| 625 | - DB_Model_Column col, | |
| 698 | + HK_Model_Column col, | |
| 626 | 699 | String type_name |
| 627 | 700 | ) = |
| 628 | - since col is db_column(name, col_type, _, help), | |
| 701 | + since col is hk_column(name, col_type, _, help), | |
| 629 | 702 | if col_type is |
| 630 | 703 | { |
| 631 | 704 | //anubis(_T) then "constant_byte_array(0,0)", |
| ... | ... | @@ -650,7 +723,7 @@ public define Maybe(String) |
| 650 | 723 | auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")"), |
| 651 | 724 | auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")") |
| 652 | 725 | }, |
| 653 | - foreign_key(foreign_table) then success("foreign_text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", vt_edit_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")"), | |
| 726 | + foreign_key(app,foreign_table) then success("foreign_text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", vt_edit_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")"), | |
| 654 | 727 | integer_field then success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"), |
| 655 | 728 | char_field(Int size) then success("text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"), |
| 656 | 729 | text_field then success("text_area(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")") |
| ... | ... | @@ -659,7 +732,7 @@ public define Maybe(String) |
| 659 | 732 | public define String |
| 660 | 733 | edit_entries |
| 661 | 734 | ( |
| 662 | - List(DB_Model_Column) columns, | |
| 735 | + List(HK_Model_Column) columns, | |
| 663 | 736 | String type_name, |
| 664 | 737 | String indent, |
| 665 | 738 | List(String) so_far |
| ... | ... | @@ -683,17 +756,17 @@ public define String |
| 683 | 756 | )= |
| 684 | 757 | indent+join(",\n"+indent, map((String text) |-> "text(\""+to_upper(text)+"\")", list_view)). |
| 685 | 758 | |
| 686 | -public define Maybe(DB_Model_Column) | |
| 759 | +public define Maybe(HK_Model_Column) | |
| 687 | 760 | get_column_type |
| 688 | 761 | ( |
| 689 | - List(DB_Model_Column) columns, //columns in wich we search | |
| 762 | + List(HK_Model_Column) columns, //columns in wich we search | |
| 690 | 763 | String name_to_find //Column name to find in previous list |
| 691 | 764 | )= |
| 692 | 765 | if columns is |
| 693 | 766 | { |
| 694 | 767 | [] then failure, |
| 695 | 768 | [h . t] then |
| 696 | - since h is db_column(name, _, _, _), | |
| 769 | + since h is hk_column(name, _, _, _), | |
| 697 | 770 | if name_to_find = name then |
| 698 | 771 | success(h) |
| 699 | 772 | else |
| ... | ... | @@ -705,11 +778,11 @@ public define String |
| 705 | 778 | */ |
| 706 | 779 | to_String |
| 707 | 780 | ( |
| 708 | - DB_Model_Column col, | |
| 781 | + HK_Model_Column col, | |
| 709 | 782 | String current_type_name, |
| 710 | 783 | String general_type_name |
| 711 | 784 | ) = |
| 712 | - since col is db_column(name, col_type, _, _), | |
| 785 | + since col is hk_column(name, col_type, _, _), | |
| 713 | 786 | if col_type is |
| 714 | 787 | { |
| 715 | 788 | //anubis(_T) then "constant_byte_array(0,0)", |
| ... | ... | @@ -719,7 +792,7 @@ public define String |
| 719 | 792 | date_field(attrs) then "to_String("+current_type_name+"."+name+")", |
| 720 | 793 | time_field(attrs) then "to_String("+current_type_name+"."+name+")", |
| 721 | 794 | datetime_field(attrs) then "to_String("+current_type_name+"."+name+")" |
| 722 | - foreign_key(foreign_table) then "get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")", | |
| 795 | + foreign_key(app,foreign_table) then "get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")", | |
| 723 | 796 | integer_field then "to_String("+current_type_name+"."+name+")", |
| 724 | 797 | char_field(Int size) then current_type_name+"."+name, |
| 725 | 798 | text_field then current_type_name+"."+name |
| ... | ... | @@ -730,11 +803,11 @@ public define String |
| 730 | 803 | */ |
| 731 | 804 | to_Icon |
| 732 | 805 | ( |
| 733 | - DB_Model_Column col, | |
| 806 | + HK_Model_Column col, | |
| 734 | 807 | String current_type_name, |
| 735 | 808 | String general_type_name |
| 736 | 809 | ) = |
| 737 | - since col is db_column(name, col_type, _, _), | |
| 810 | + since col is hk_column(name, col_type, _, _), | |
| 738 | 811 | if col_type is |
| 739 | 812 | { |
| 740 | 813 | p_key then icn16_key, |
| ... | ... | @@ -742,7 +815,7 @@ public define String |
| 742 | 815 | date_field(attrs) then icn16_clock, |
| 743 | 816 | time_field(attrs) then icn16_clock, |
| 744 | 817 | datetime_field(attrs) then icn16_clock, |
| 745 | - foreign_key(foreign_table) then icn16_question, | |
| 818 | + foreign_key(app,foreign_table) then icn16_question, | |
| 746 | 819 | integer_field then icn16_question, |
| 747 | 820 | char_field(Int size) then icn16_question, |
| 748 | 821 | text_field then icn16_question |
| ... | ... | @@ -751,7 +824,7 @@ public define String |
| 751 | 824 | public define String |
| 752 | 825 | to_HTML_cell_text |
| 753 | 826 | ( |
| 754 | - DB_Model_Column column, | |
| 827 | + HK_Model_Column column, | |
| 755 | 828 | String data_name, |
| 756 | 829 | String general_type_name |
| 757 | 830 | )= |
| ... | ... | @@ -760,7 +833,7 @@ public define String |
| 760 | 833 | public define String |
| 761 | 834 | to_HTML_cell_link |
| 762 | 835 | ( |
| 763 | - DB_Model_Column column, | |
| 836 | + HK_Model_Column column, | |
| 764 | 837 | String data_name, |
| 765 | 838 | String general_type_name |
| 766 | 839 | )= |
| ... | ... | @@ -769,7 +842,7 @@ public define String |
| 769 | 842 | public define String |
| 770 | 843 | to_HTML_cell_link |
| 771 | 844 | ( |
| 772 | - List(DB_Model_Column) columns, | |
| 845 | + List(HK_Model_Column) columns, | |
| 773 | 846 | String column_name, |
| 774 | 847 | String data_name, |
| 775 | 848 | String general_type_name |
| ... | ... | @@ -783,7 +856,7 @@ public define String |
| 783 | 856 | public define String |
| 784 | 857 | to_HTML_cell_icon |
| 785 | 858 | ( |
| 786 | - DB_Model_Column column, | |
| 859 | + HK_Model_Column column, | |
| 787 | 860 | String data_name, |
| 788 | 861 | String general_type_name |
| 789 | 862 | )= |
| ... | ... | @@ -793,7 +866,7 @@ public define String |
| 793 | 866 | public define String |
| 794 | 867 | to_HTML_cell |
| 795 | 868 | ( |
| 796 | - List(DB_Model_Column) columns, | |
| 869 | + List(HK_Model_Column) columns, | |
| 797 | 870 | String column_name, |
| 798 | 871 | String data_name, |
| 799 | 872 | String general_type_name |
| ... | ... | @@ -802,7 +875,7 @@ public define String |
| 802 | 875 | { |
| 803 | 876 | failure then "column name "+column_name+"doesn't exist", |
| 804 | 877 | success(column) then |
| 805 | - since column is db_column(name, col_type, _, _), | |
| 878 | + since column is hk_column(name, col_type, _, _), | |
| 806 | 879 | if col_type is |
| 807 | 880 | { |
| 808 | 881 | //anubis(_T) then "constant_byte_array(0,0)", |
| ... | ... | @@ -812,7 +885,7 @@ public define String |
| 812 | 885 | date_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), |
| 813 | 886 | time_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), |
| 814 | 887 | datetime_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), |
| 815 | - foreign_key(foreign_table) then to_HTML_cell_text(column, data_name, general_type_name), | |
| 888 | + foreign_key(app,foreign_table) then to_HTML_cell_text(column, data_name, general_type_name), | |
| 816 | 889 | integer_field then to_HTML_cell_text(column, data_name, general_type_name), |
| 817 | 890 | char_field(Int size) then to_HTML_cell_text(column, data_name, general_type_name), |
| 818 | 891 | text_field then to_HTML_cell_text(column, data_name, general_type_name), |
| ... | ... | @@ -822,13 +895,13 @@ public define String |
| 822 | 895 | public define String |
| 823 | 896 | make_list_view_row |
| 824 | 897 | ( |
| 825 | - DB_Table table, //table to format | |
| 898 | + HK_Table table, //table to format | |
| 826 | 899 | String data_name, //name of data |
| 827 | 900 | String indent, //indentation string to use |
| 828 | 901 | HK_List_View list_view //list view to generate |
| 829 | 902 | )= |
| 830 | - since table is db_table(table_name, model, _), //get name and model of the table | |
| 831 | - since model is db_model( columns, _), //get all columns of table | |
| 903 | + since table is hk_table(table_name, model, _), //get name and model of the table | |
| 904 | + since model is hk_model( columns, _), //get all columns of table | |
| 832 | 905 | // since display is db_display(views, _), // |
| 833 | 906 | with current_list_column = if list_view is |
| 834 | 907 | { | ... | ... |