diff --git a/hayamiki_generator.aproj b/hayamiki_generator.aproj
index c812e23..6480a56 100644
--- a/hayamiki_generator.aproj
+++ b/hayamiki_generator.aproj
@@ -489,6 +489,7 @@
+
diff --git a/hayamiki_lib b/hayamiki_lib
index 27f3d0f..523830e 160000
--- a/hayamiki_lib
+++ b/hayamiki_lib
@@ -1 +1 @@
-Subproject commit 27f3d0f6b93aa27fbbd34993a72cef1fb36b347f
+Subproject commit 523830e5bcc852cc87262ed92f96d7a0ec0d0032
diff --git a/src/generation/densaku.anubis b/src/generation/densaku.anubis
new file mode 100644
index 0000000..9d5366d
--- /dev/null
+++ b/src/generation/densaku.anubis
@@ -0,0 +1,127 @@
+/*
+ * Created by PyramIDE.
+ * User: フランスのトトロ aka (David RENÉ)
+ * Date: 26/01/2017
+ * Time: 00:14
+ * © Calexium
+ */
+
+read hayamiki_lib/types/hayamiki.anubis
+read tools/basis.anubis
+read tools/streams.anubis
+read system/string.anubis
+read fields.anubis
+read columns.anubis
+read tools/ISO-8601.anubis
+
+define List(String)
+/**
+ */
+ _generate_densaku_type
+ (
+ List(HK_Model_Column) columns,
+ List(String) so_far
+ )=
+ if columns is
+ {
+ [] then reverse(so_far),
+ [h . t ] then
+ since h is hk_column(name, col_type, _, _),
+ _generate_densaku_type(t, [ " component("+fill(to_densaku_type(col_type), 12) + ", \"" + name +"\")". so_far])
+ }.
+
+public define Maybe(One)
+ generate_densaku_type
+ (
+ Stream stream,
+ HK_Table table
+ )=
+ since table is hk_table(name, short_name, model, display),
+ since model is hk_model(columns, show_string),
+ with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
+
+ //generate the type of the HK_Table that contain all components
+ if write_string(stream,
+ " ds_type(\""+type_name+"\", [\n"+
+ " alternative(\""+name+"\", [\n"+ //head of the type declaration
+ join(",\n",_generate_densaku_type(columns, []))+ //all components of the type
+ " ])\n"+
+ " ]),\n") is //end of declaration
+ {
+ failure then println("can't write type "+type_name); failure,
+ success(_) then success(unique)
+ }.
+
+public define Maybe(One)
+/*
+ */
+ generate_densaku_type
+ (
+ HK_Table table,
+ String dest_dir,
+ Bool use_densaku
+ )=
+ if use_densaku then
+ with file_name = dest_dir+"database/generated/densaku_type.anubis",
+ if file(file_name, append) is
+ {
+ failure then println("can't create file "+file_name);failure,
+ success(fd) then
+ with strm = make_stream(fd),
+ generate_densaku_type(strm, table)
+ }
+ else
+ success(unique)
+.
+
+public define One
+ make_densaku_header
+ (
+ String dest_dir,
+ Bool use_densaku
+ )=
+ if use_densaku then
+ with file_name = dest_dir+"database/generated/densaku_type.anubis",
+ if file(file_name, new) is
+ {
+ failure then unique,
+ success(fd) then
+ with strm = make_stream(fd),
+ forget(write_string(strm,
+"/*
+ * Created by 早見木 (Hayamiki).
+ * Types & Messages generator written by フランスのトトロ aka (David RENÉ)
+ * Date: "+_Int_to_ISO_8601_date(now)+"
+ * Time: "+_Int_to_ISO_8601_time(now)+"
+ *
+ */
+
+read densaku_lib/types/densaku.anubis
+
+public define List(DS_Type) hayamiki_types_list =
+ [\n"))
+ }
+ else
+ unique
+.
+
+public define One
+ close_densaku_file
+ (
+ String dest_dir,
+ Bool use_densaku
+ )=
+ if use_densaku then
+ with file_name = dest_dir+"database/generated/densaku_type.anubis",
+ if file(file_name, append) is
+ {
+ failure then unique,
+ success(fd) then
+ with strm = make_stream(fd),
+ forget(write_string(strm,
+" ]
+.\n"))
+ }
+ else
+ unique
+.
diff --git a/src/generation/fields.anubis b/src/generation/fields.anubis
index 6aaf15f..f20e895 100644
--- a/src/generation/fields.anubis
+++ b/src/generation/fields.anubis
@@ -36,6 +36,29 @@ public define String
password_field(_) then "String",
text_field then "String"
}.
+
+public define String
+/** Return the corresponding Anubis type of the field
+ */
+ to_densaku_type
+ (
+ HK_Model_Field t
+ ) =
+ if t is
+ {
+ //anubis(_T) then "ByteArray",
+ p_key then "extern_type(\"DB_id\", \"calexium_lib/model/db_types.anubis\")",
+ //binary then "ByteArray",
+ boolean_field then "bool",
+ date_field(_) then "extern_type(\"DB_date\", \"calexium_lib/model/db_types.anubis\")",
+ time_field(_) then "extern_type(\"DB_time\", \"calexium_lib/model/db_types.anubis\")",
+ datetime_field(_) then "extern_type(\"DB_datetime\", \"calexium_lib/model/db_types.anubis\")",
+ foreign_key(_,_) then "int",
+ integer_field(_) then "int",
+ char_field(_,_) then "string",
+ password_field(_) then "string",
+ text_field then "string"
+ }.
public define String
to_SQL_CREATE
diff --git a/src/generation/files.anubis b/src/generation/files.anubis
index 1c75adc..fad1353 100644
--- a/src/generation/files.anubis
+++ b/src/generation/files.anubis
@@ -17,6 +17,7 @@ read tools/streams.anubis
read tools/ISO-8601.anubis
read generation/header.anubis
read generation/types.anubis
+read generation/densaku.anubis
read generation/create_table.anubis
read generation/menu.anubis
read generation/fn_delete.anubis
@@ -27,8 +28,9 @@ read check.anubis
define Maybe(One)
generate_table
(
- HK_Table org_table, //table to generate
- String dest_dir //root directory of the generation
+ HK_Table org_table, //table to generate
+ String dest_dir, //root directory of the generation
+ Bool use_densaku //if true, this means the types are constructed by densaku for generating also the messages
)
=
since org_table is hk_table(name, short_name, old_model, display),
@@ -49,7 +51,8 @@ define Maybe(One)
success(fd) then
with strm = make_stream(fd),
if generate_header(strm, columns) is { failure then failure, success(_) then
- if generate_type(strm, table) is { failure then failure, success(_) then
+ if generate_densaku_type(table, dest_dir, use_densaku) is { failure then failure, success(_) then
+ if generate_type(strm, table, use_densaku) is { failure then failure, success(_) then
if generate_get_default(strm, table) is { failure then failure, success(_) then
if generate_extract_web_arg(strm, table) is { failure then failure, success(_) then
if generate_extract_db_cursor(strm, table) is { failure then failure, success(_) then
@@ -64,24 +67,25 @@ define Maybe(One)
if generate_choices_selector(strm, table) is { failure then failure, success(_) then
if generate_VT_all_view(strm, table) is { failure then failure, success(_) then
if generate_VT_all_edit(strm, table) is { failure then failure, success(_) then
- success(unique)}}}}}}}}}}}}}}}}
+ success(unique)}}}}}}}}}}}}}}}}}
}.
define One
make_all_tables
(
List(HK_Table) tables, //list of the table model description
- String dest_dir
+ String dest_dir,
+ Bool use_densaku
)
=
if tables is
{
[] then println("Generation finished"),
[h . t] then
- if generate_table(h, dest_dir) is
+ if generate_table(h, dest_dir, use_densaku) is
{
failure then println("Generation error")
- success(_) then make_all_tables(t, dest_dir)
+ success(_) then make_all_tables(t, dest_dir, use_densaku)
}
}.
@@ -89,13 +93,18 @@ define One
make_all_tables
(
List(HK_App) apps,
- String dest_dir
+ String dest_dir,
+ Bool use_densaku
)=
+ make_densaku_header(dest_dir, use_densaku);
+
map_forget((HK_App app) |-> since app is hk_app(app_name, _, _, tables),
println("generating tables for App ["+app_name+"]");
- make_all_tables(tables, dest_dir), apps).
-
+ make_all_tables(tables, dest_dir, use_densaku), apps);
+
+ close_densaku_file(dest_dir, use_densaku)
+.
define Maybe(One)
generate_vtm_file
@@ -115,7 +124,7 @@ define Maybe(One)
if write_string(make_stream(fd),
"/*
* Created by 早見木 (Hayamiki).
- * User: Automaton
+ * Database generator written by フランスのトトロ aka (David RENÉ)
* Date: "+_Int_to_ISO_8601_date(now)+"
* Time: "+_Int_to_ISO_8601_time(now)+"
*
@@ -194,7 +203,8 @@ define Maybe(One)
generate_model_files
(
HK_Database db, //database model description
- String destination_dir
+ String destination_dir,
+ Bool use_densaku
)=
if check_database(db) is
@@ -203,7 +213,7 @@ define Maybe(One)
success(database) then
since database is hk_database(name, apps),
println("Generating models for Database "+name);
- make_all_tables(apps, destination_dir);
+ make_all_tables(apps, destination_dir, use_densaku);
println("Generating VTM for Database "+name);
make_vtm(apps, destination_dir);
println("Generating create for Database "+name);
diff --git a/src/generation/header.anubis b/src/generation/header.anubis
index ff531f6..860ae16 100644
--- a/src/generation/header.anubis
+++ b/src/generation/header.anubis
@@ -45,7 +45,7 @@ public define Maybe(One)
if write_string(stream,
"/*
* Created by 早見木 (Hayamiki).
- * User: Automat
+ * Database generator written by フランスのトトロ aka (David RENÉ)
* Date: "+_Int_to_ISO_8601_date(now)+"
* Time: "+_Int_to_ISO_8601_time(now)+"
*
diff --git a/src/generation/types.anubis b/src/generation/types.anubis
index 0d4b48b..e50910e 100644
--- a/src/generation/types.anubis
+++ b/src/generation/types.anubis
@@ -34,22 +34,32 @@ public define Maybe(One)
generate_type
(
Stream stream,
- HK_Table table
+ HK_Table table,
+ Bool use_densaku
)=
since table is hk_table(name, short_name, model, display),
since model is hk_model(columns, show_string),
with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
- //generate the type of the HK_Table that contain all components
- if write_string(stream,
- "\n\npublic type "+type_name+":\n "+name+"\n (\n"+ //head of the type declaration
- join(",\n",_generate_type(columns, []))+ //all components of the type
- "\n ).\n") is //end of declaration
- {
- failure then println("can't write type "+type_name); failure,
- success(_) then success(unique)
- }.
+ //if we use densaku for generating the type, we insert the read of that type after densaku generation
+ if use_densaku then
+ write_string(stream,
+ "\n\nread types/generated/ "+to_lower(type_name)+".anubis\n") //read of the type declaration
+
+ else
+ //generate the type of the HK_Table that contain all components
+ if write_string(stream,
+ "\n\npublic type "+type_name+":\n "+name+"\n (\n"+ //head of the type declaration
+ join(",\n",_generate_type(columns, []))+ //all components of the type
+ "\n ).\n") is //end of declaration
+ {
+ failure then println("can't write type "+type_name); failure,
+ success(_) then success(unique)
+ }
+.
+
+
define List(String)
/**
*/
diff --git a/src/main.anubis b/src/main.anubis
index f51e91e..5a67015 100644
--- a/src/main.anubis
+++ b/src/main.anubis
@@ -28,7 +28,7 @@ global define One
if load_hk_generator is
{
failure then println("Hayamiki generator can't be load"),
- success(hk_gen) then forget(hk_gen.generate_model_files(the_database_description, ""))
+ success(hk_gen) then forget(hk_gen.generate_model_files(the_database_description, "", true))
}.
global define One
--
libgit2 0.21.4