Commit 359f032306383f5da1938c4236da001f63cad708

Authored by Matthieu Herrmann
1 parent dc22d26d

maj sdbms4

Showing 1 changed file with 25 additions and 12 deletions   Show diff stats
anubis_dev/library/data_base/sdbms4.anubis
@@ -128,7 +128,7 @@ define (DBInfo -> One) create_storer(DBIndex($Key, $Row) my_idx) = @@ -128,7 +128,7 @@ define (DBInfo -> One) create_storer(DBIndex($Key, $Row) my_idx) =
128 with converter = (IDXData($Key, $Row) idxdata)|-> idx_data_save(version(idxdata), to_serialize(data_tree(idxdata))), 128 with converter = (IDXData($Key, $Row) idxdata)|-> idx_data_save(version(idxdata), to_serialize(data_tree(idxdata))),
129 // We also need an asynchronous writer (using default timings), configured for that index (using its name) 129 // We also need an asynchronous writer (using default timings), configured for that index (using its name)
130 with writing_fun = (IDXDataSave($Key, $Row) idx, String path) |-> safe_save(idx, path), 130 with writing_fun = (IDXDataSave($Key, $Row) idx, String path) |-> safe_save(idx, path),
131 - with asaver = make_AData(name(my_idx), writing_fun), 131 + with asaver = make_AData("",name(my_idx), writing_fun,0,0),
132 // When writing, we set the directory on the fly 132 // When writing, we set the directory on the fly
133 (DBInfo dbi)|-> 133 (DBInfo dbi)|->
134 set_prefix(directory(dbi), asaver); 134 set_prefix(directory(dbi), asaver);
@@ -258,7 +258,7 @@ define IDXData($Key, $Row) check_convert_rebuilt( @@ -258,7 +258,7 @@ define IDXData($Key, $Row) check_convert_rebuilt(
258 *** [3.2.2] Index initialisation 258 *** [3.2.2] Index initialisation
259 ============================================================================================================== 259 ==============================================================================================================
260 260
261 -define Result(DBLoadingError, DBIndex($Key, $Row)) init_index( 261 +public define Result(DBLoadingError, DBIndex($Key, $Row)) init_index(
262 DBInfo the_data_base, // The database and the table on which 262 DBInfo the_data_base, // The database and the table on which
263 DBTable($Row,$HRow) the_table, // the index must be installed. 263 DBTable($Row,$HRow) the_table, // the index must be installed.
264 String index_name, // Name of the index 264 String index_name, // Name of the index
@@ -295,6 +295,27 @@ define Result(DBLoadingError, DBIndex($Key, $Row)) init_index( @@ -295,6 +295,27 @@ define Result(DBLoadingError, DBIndex($Key, $Row)) init_index(
295 *** [3.3] Index consultation 295 *** [3.3] Index consultation
296 ================================================================================================================ 296 ================================================================================================================
297 297
  298 +public define Iterator( ($Key, List(DBRowId($Row))) ) take_key_ids( DBIndex($Key, $Row) my_idx) =
  299 + take_left(data_tree(*data(my_idx))).
  300 +
  301 +public define Iterator( $Key ) take_key( DBIndex($Key, $Row) my_idx) =
  302 + take_left_key(data_tree(*data(my_idx))).
  303 +
  304 +public define Iterator( DBRowId($Row) ) take_ids( DBIndex($Key, $Row) my_idx) =
  305 + fold_left( take_left_value(data_tree(*data(my_idx))), nil,
  306 + (Iterator(DBRowId($Row)) it, List(DBRowId($Row)) l)|-> append(take_left(l), it)
  307 + ).
  308 +
  309 +public define Iterator( DBRow($Row) ) take_rows( DBIndex($Key, $Row) my_idx) =
  310 + with table_data = data_tree(*table(my_idx)),
  311 + filter(
  312 + (DBRowId($Row) id) |-> get(id, table_data),
  313 + fold_left( take_left_value(data_tree(*data(my_idx))), nil,
  314 + (Iterator(DBRowId($Row)) it, List(DBRowId($Row)) l)|->
  315 + append(take_left(l), it)
  316 + )
  317 + ).
  318 +
298 public define Iterator(DBRowId($Row)) get_ids($Key key, DBIndex($Key, $Row) my_idx) = 319 public define Iterator(DBRowId($Row)) get_ids($Key key, DBIndex($Key, $Row) my_idx) =
299 if get(key, data_tree(*data(my_idx))) is 320 if get(key, data_tree(*data(my_idx))) is
300 { 321 {
@@ -304,15 +325,7 @@ public define Iterator(DBRowId($Row)) get_ids($Key key, DBIndex($Key, $Row) my_i @@ -304,15 +325,7 @@ public define Iterator(DBRowId($Row)) get_ids($Key key, DBIndex($Key, $Row) my_i
304 325
305 public define Iterator(DBRow($Row)) get_rows($Key key, DBIndex($Key, $Row) my_idx) = 326 public define Iterator(DBRow($Row)) get_rows($Key key, DBIndex($Key, $Row) my_idx) =
306 with table_data = data_tree(*table(my_idx)), 327 with table_data = data_tree(*table(my_idx)),
307 - fold_left(get_ids(key, my_idx), nil, (Iterator(DBRow($Row)) l, DBRowId($Row) id)|->  
308 - if get(id, table_data) is  
309 - {  
310 - failure then should_not_happen(l)  
311 - success(item) then item .. l  
312 - }  
313 - ).  
314 -  
315 - 328 + filter( (DBRowId($Row) id) |-> get(id, table_data), get_ids(key, my_idx) ).
316 329
317 *** [4] Database initialisation 330 *** [4] Database initialisation
318 ================================================================================================================== 331 ==================================================================================================================
@@ -390,7 +403,7 @@ public define Result(DBLoadingError, DBTable($Row,$HRow)) init_dbtable( @@ -390,7 +403,7 @@ public define Result(DBLoadingError, DBTable($Row,$HRow)) init_dbtable(
390 with tdata_v = var(tdata), // ** Dynamic variable created here ** 403 with tdata_v = var(tdata), // ** Dynamic variable created here **
391 // 4: Create the saving function (delegate writer + conversion) 404 // 4: Create the saving function (delegate writer + conversion)
392 with writing_fun = (DBTableDataSave($HRow) idx, String path) |-> safe_save(idx, path), 405 with writing_fun = (DBTableDataSave($HRow) idx, String path) |-> safe_save(idx, path),
393 - with asaver = make_AData(table_name, writing_fun), 406 + with asaver = make_AData("", table_name, writing_fun, 0, 0),
394 with saver = (DBInfo dbi)|-> 407 with saver = (DBInfo dbi)|->
395 set_prefix(directory(dbi), asaver); 408 set_prefix(directory(dbi), asaver);
396 if *tdata_v is dbtable_data(c_, v_, st_, _) then 409 if *tdata_v is dbtable_data(c_, v_, st_, _) then