Commit e02dec72bfa98ea75dbab3e27662848f5afa13e4

Authored by totoro
1 parent dcaff5c8

adapt the generator according to hk_table_controller from hayamiki_lib.

This is means generate the name of columns; select_fields and json extractor
calexium_lib @ 8b1c73d0a94
1 -Subproject commit 977d6b04a745ecdf22e97a494197b52ad86cf87a 1 +Subproject commit 8b1c73d0a94bf27dcdd331455006dd3ae13aea76
hayamiki_lib @ 67283d2acf3
1 -Subproject commit 1ea67eb55022aaaa2c37b180530fa8d72e71f142 1 +Subproject commit 67283d2acf36bae89805163ecebbec67fa677e3f
src/generation/SQL_get_all.anubis
@@ -110,34 +110,21 @@ public define Maybe(One) @@ -110,34 +110,21 @@ public define Maybe(One)
110 " success(cursor) then _get_all_"+name+"(cursor, [])\n"+ 110 " success(cursor) then _get_all_"+name+"(cursor, [])\n"+
111 " }\n"+ 111 " }\n"+
112 ".\n"+ 112 ".\n"+
113 -// "public define List(JsonValue)\n"+  
114 -// " _get_all_"+name+"_to_json\n"+  
115 -// " (\n"+  
116 -// " SQLite3DataBase db,\n"+  
117 -// " One -> SQLite3Row table_cursor,\n"+  
118 -// " List(JsonValue) so_far\n"+  
119 -// " ) =\n"+  
120 -// " if extract_"+name+"_cursor_to_json(db, table_cursor) is\n"+  
121 -// " {\n"+  
122 -// " failure then reverse(so_far),\n"+  
123 -// " success(data) then _get_all_"+name+"_to_json(db, table_cursor, [data . so_far])\n"+  
124 -// " }\n"+  
125 -// ".\n"+  
126 113
127 -"public define List(JsonValue)\n"+  
128 -" _get_all_"+name+"_to_json\n"+  
129 -" (\n"+  
130 -" SQLite3DataBase db,\n"+  
131 -" List(((Int -> SQLite3Datum) -> JsonMember)) extractors,\n"+  
132 -" One -> SQLite3Row table_cursor,\n"+  
133 -" List(JsonValue) so_far\n"+  
134 -" ) =\n"+  
135 -" if extract_"+name+"_cursor_to_json(db, extractors, table_cursor) is\n"+  
136 -" {\n"+  
137 -" failure then reverse(so_far),\n"+  
138 -" success(data) then _get_all_"+name+"_to_json(db, extractors, table_cursor, [data . so_far])\n"+  
139 -" }\n"+  
140 -".\n"+ 114 +//"public define List(JsonValue)\n"+
  115 +//" _get_all_"+name+"_to_json\n"+
  116 +//" (\n"+
  117 +//" SQLite3DataBase db,\n"+
  118 +//" List(((Int -> SQLite3Datum) -> JsonMember)) extractors,\n"+
  119 +//" One -> SQLite3Row table_cursor,\n"+
  120 +//" List(JsonValue) so_far\n"+
  121 +//" ) =\n"+
  122 +//" if extract_"+name+"_cursor_to_json(db, extractors, table_cursor) is\n"+
  123 +//" {\n"+
  124 +//" failure then reverse(so_far),\n"+
  125 +//" success(data) then _get_all_"+name+"_to_json(db, extractors, table_cursor, [data . so_far])\n"+
  126 +//" }\n"+
  127 +//".\n"+
141 128
142 "public define JsonValue\n"+ 129 "public define JsonValue\n"+
143 " get_all_"+name+"_by_clause_to_json\n"+ 130 " get_all_"+name+"_by_clause_to_json\n"+
@@ -157,10 +144,8 @@ public define Maybe(One) @@ -157,10 +144,8 @@ public define Maybe(One)
157 " failure then json_array([]),\n"+ 144 " failure then json_array([]),\n"+
158 " success(cursor) then\n"+ 145 " success(cursor) then\n"+
159 " json_array(\n"+ 146 " json_array(\n"+
160 -//" if length(columns) = 0 then\n"+  
161 -//" _get_all_"+name+"_to_json(db, cursor, [])\n"+  
162 -//" else\n"+  
163 -" _get_all_"+name+"_to_json(db, make_json_extractor(db, final_columns, resolve_fk), cursor, [])\n"+ 147 +//" _get_all_"+name+"_to_json(db, make_"+name+"_json_extractor(db, final_columns, resolve_fk), cursor, [])\n"+
  148 +" get_all_to_json(db, make_"+name+"_json_extractor(db, final_columns, resolve_fk), cursor, [])\n"+
164 " )\n"+ 149 " )\n"+
165 " }\n"+ 150 " }\n"+
166 ".\n" 151 ".\n"
src/generation/extractor.anubis
@@ -177,10 +177,12 @@ public define Maybe(One) @@ -177,10 +177,12 @@ public define Maybe(One)
177 //generate the type of the table that contain all components 177 //generate the type of the table that contain all components
178 if write_string(stream, 178 if write_string(stream,
179 "\n\n"+ 179 "\n\n"+
  180 +
180 // "public define Maybe(JsonValue)\n"+ 181 // "public define Maybe(JsonValue)\n"+
181 // " extract_"+name+"_cursor_to_json\n"+ 182 // " extract_"+name+"_cursor_to_json\n"+
182 // " (\n"+ 183 // " (\n"+
183 // " SQLite3DataBase db,\n"+ 184 // " SQLite3DataBase db,\n"+
  185 +// " List(((Int -> SQLite3Datum) -> JsonMember)) extractors,\n"+
184 // " One -> SQLite3Row table_cursor\n"+ 186 // " One -> SQLite3Row table_cursor\n"+
185 // " ) =\n"+ 187 // " ) =\n"+
186 // " if table_cursor(unique) is\n"+ 188 // " if table_cursor(unique) is\n"+
@@ -188,26 +190,11 @@ public define Maybe(One) @@ -188,26 +190,11 @@ public define Maybe(One)
188 // " error(sql_error) then println(db_error(sql_error, \"extract_"+name+"\")); failure,\n"+ 190 // " error(sql_error) then println(db_error(sql_error, \"extract_"+name+"\")); failure,\n"+
189 // " no_more_row then failure,\n"+ 191 // " no_more_row then failure,\n"+
190 // " row(cursor) then\n"+ 192 // " row(cursor) then\n"+
191 -// " success("+generate_json_object_from_cursor(name, "cursor", columns, " ")+")\n"+ //generate type construction with values got from web arg  
192 -// " }\n.\n"+  
193 -// "\n\n"+  
194 - "public define Maybe(JsonValue)\n"+  
195 - " extract_"+name+"_cursor_to_json\n"+  
196 - " (\n"+  
197 - " SQLite3DataBase db,\n"+  
198 - " List(((Int -> SQLite3Datum) -> JsonMember)) extractors,\n"+  
199 - " One -> SQLite3Row table_cursor\n"+  
200 - " ) =\n"+  
201 - " if table_cursor(unique) is\n"+  
202 - " {\n"+  
203 - " error(sql_error) then println(db_error(sql_error, \"extract_"+name+"\")); failure,\n"+  
204 - " no_more_row then failure,\n"+  
205 - " row(cursor) then\n"+  
206 - " success(\n"+  
207 - " json_object(\n"+  
208 - " map(((Int -> SQLite3Datum) -> JsonMember extractor) |-> extractor(cursor) , extractors)\n"+  
209 - " ))\n"+  
210 - " }\n.\n\n"+ 193 +// " success(\n"+
  194 +// " json_object(\n"+
  195 +// " map(((Int -> SQLite3Datum) -> JsonMember extractor) |-> extractor(cursor) , extractors)\n"+
  196 +// " ))\n"+
  197 +// " }\n.\n\n"+
211 198
212 "public define String get_"+name+"_show_string(SQLite3DataBase db, DB_id _idx).\n\n"+ 199 "public define String get_"+name+"_show_string(SQLite3DataBase db, DB_id _idx).\n\n"+
213 "define (Int -> SQLite3Datum) -> JsonMember\n"+ 200 "define (Int -> SQLite3Datum) -> JsonMember\n"+
@@ -219,8 +206,8 @@ public define Maybe(One) @@ -219,8 +206,8 @@ public define Maybe(One)
219 " )=\n"+generate_json_extractor(name, "cursor", columns, " ")+ 206 " )=\n"+generate_json_extractor(name, "cursor", columns, " ")+
220 "\n.\n\n"+ 207 "\n.\n\n"+
221 208
222 -"define List(((Int -> SQLite3Datum) -> JsonMember))\n"+  
223 -" make_json_extractor\n"+ 209 +"public define List(((Int -> SQLite3Datum) -> JsonMember))\n"+
  210 +" make_"+name+"_json_extractor\n"+
224 " (\n"+ 211 " (\n"+
225 " SQLite3DataBase db,\n"+ 212 " SQLite3DataBase db,\n"+
226 " List(String) columns,\n"+ 213 " List(String) columns,\n"+
src/generation/files.anubis
@@ -208,11 +208,15 @@ define One @@ -208,11 +208,15 @@ define One
208 // with delete = "tm_delete(\""+name+"\", delete_"+name+")", 208 // with delete = "tm_delete(\""+name+"\", delete_"+name+")",
209 with controller = 209 with controller =
210 "hk_table_controller(\""+name+"\", 210 "hk_table_controller(\""+name+"\",
  211 + //Column's name
  212 + "+name+"_columns,
  213 + "+name+"_select_fields,
211 //Create 214 //Create
212 update_"+name+"_from_type, 215 update_"+name+"_from_type,
213 update_"+name+"_from_fields, 216 update_"+name+"_from_fields,
214 //Read 217 //Read
215 (SQLite3DataBase db, String clause) |-> get_count_by_clause(db, \""+name+"\", clause), 218 (SQLite3DataBase db, String clause) |-> get_count_by_clause(db, \""+name+"\", clause),
  219 + make_"+name+"_json_extractor,
216 get_one_"+name+"_to_json, 220 get_one_"+name+"_to_json,
217 get_all_"+name+"_by_clause_to_json, 221 get_all_"+name+"_by_clause_to_json,
218 //Delete 222 //Delete
src/generation/types.anubis
@@ -231,14 +231,8 @@ public define Maybe(One) @@ -231,14 +231,8 @@ public define Maybe(One)
231 " {\n"+ 231 " {\n"+
232 " failure then error,\n"+ 232 " failure then error,\n"+
233 " success(cursor) then\n"+ 233 " success(cursor) then\n"+
234 -//" if length(columns) = 0 then\n"+  
235 -//" if extract_"+name+"_cursor_to_json(db, cursor) is\n"+  
236 -//" {\n"+  
237 -//" failure then error,\n"+  
238 -//" success(result) then result\n"+  
239 -//" }\n"+  
240 -//" else\n"+  
241 -" if extract_"+name+"_cursor_to_json(db, make_json_extractor(db, final_columns, resolve_fk), cursor) is\n"+ 234 +//" if extract_"+name+"_cursor_to_json(db, make_"+name+"_json_extractor(db, final_columns, resolve_fk), cursor) is\n"+
  235 +" if extract_cursor_to_json(db, make_"+name+"_json_extractor(db, final_columns, resolve_fk), cursor) is\n"+
242 " {\n"+ 236 " {\n"+
243 " failure then error,\n"+ 237 " failure then error,\n"+
244 " success(result) then result\n"+ 238 " success(result) then result\n"+