diff --git a/database/model/db_model.anubis b/database/model/db_model.anubis index 1d44481..4eb598b 100644 --- a/database/model/db_model.anubis +++ b/database/model/db_model.anubis @@ -6,19 +6,7 @@ * © David RENÉ */ - The HayamiKi (早見木) project - Interfacing, generating and controling a database with Anubis - - - Author: David René - - - In order to generate such tools, DB_Model needs a formal - description of the database. - - - *** (1.2) 'MaybeNull'. This type scheme is isomorphic to 'Maybe', and is used for representing data which @@ -33,69 +21,7 @@ public type MaybeNull($T): Conversion tools between date, time and datetime in ISO-8601 format and 'Int' (number of seconds since the epoch) are provided in 'library/tools/ISO-8601.anubis'. - - - *** (1.3) 'HK_Model_Attr' (attributes of columns). - - Possible attributes of columns: (each column has a list of such attributes) - - - - - - - - - Of course, 'NOT NULL' is not an alternative of 'HK_Model_Attr' because it is already coded into the - database type itself (type 'HK_Model_Field' above). - - - - - - *** (3.7) 'DB_Model_Table' (describing a table). - - Description of a table: - - - - - - - - - Description of a whole database: - - -// list of all tables in the database - - -//public define Maybe(String) convert_to_date (MaybeNull(ByteArray) b). -//public define MaybeNull(String) convert_to_date_or_null (MaybeNull(ByteArray) b). - - *** (8.3.6) Converting 'integer?' and 'integer?_or_null' to and fro. - - The next functions are used for integer16, integer32 and integer. - -//public define Maybe(Int) convert_to_integer (MaybeNull(ByteArray) b). -//public define MaybeNull(Int) convert_to_integer_or_null (MaybeNull(ByteArray) b). - - - *** (8.3.7) Converting 'char/text' and 'char_or_null/text_or_null' to and fro. - - The same functions are used for 'text/text_or_null' and 'vartext/vartext_or_null'. - - Litteral texts must be 'prepared' before they can be included into - SQL commands (this amounts to doubling the single quotes). - - public define MetaSQL_Prepared prepare_text (String t). - public define MetaSQL_Prepared prepare_text_or_null (MaybeNull(String) t). - - Conversely, texts arrive from the database in the form of byte arrays which must be - converted to strings. The two functions for converting to 'text' and to 'text_or_null' - are almost the same one. The only difference is that 'null' is interpreted as an error in - the case of 'text'. --- That's all for the public part !---------------------------------------------------------------- @@ -144,77 +70,3 @@ define macro Maybe(String) } }. - - - *** [2] Verifications concerning the description of the database and queries. - - - - define Bool - has_forbidden_references - ( - String table_name, // the first 3 arguments concern the current table. - MetaSQL_PrimKey pk, - List(HK_Model_Column) columns, - List(HK_Model_Column) forwards, // subsequent tables - List(String) backwards // list of backwards table names - ) = - if columns is - { - [ ] then false, // no forbidden reference found - [col1 . other_cols] then - if is_forbidden_reference(table_name,col1,forwards,backwards) - then true - else has_forbidden_references(table_name,pk,other_cols,forwards,backwards) - }. - - define Bool // returns 'true' if there is at least one forbidden cycle. - has_forbidden_cycles - ( - String db_name, - List(HK_Model_Column) tables, - List(String) backwards // names of 'backwards' tables - ) = - if tables is - { - [ ] then false, // no forbidden cycle found - [tab1 . other_tabs] then if tab1 is table(name1,pk1,cols1) then - if has_forbidden_references(name1,pk1,cols1,other_tabs,backwards) - then true - else has_forbidden_cycles(db_name,other_tabs,[name1 . backwards]) - }. - - define Bool - is_forbidden_column_name - ( - String name - ) = - name = "id" | name = "metasqlcheck". - - define Bool - has_forbidden_column_names - ( - HK_Model_Column tab - ) = - if tab is table(_,_,cols) then - mapor((HK_Model_Column cs) |-> - if cs is col(name,_,_) then is_forbidden_column_name(name), - cols). - - define Bool - has_forbidden_column_names - ( - DB_Model_DB db - ) = - if db is database(_,tables) then - mapor(has_forbidden_column_names,tables). - - *** [3] Generating the target file. - - *** [3.1] Converting a database type into the corresponding Anubis type: - - - - - - -- libgit2 0.21.4