extmod/modbtree: Add method to sync the database.
If you have longish operations on the db (such as logging data) it may be desirable to periodically sync the database to the disk. The added btree.sync() method merely exposes the berkley __bt_sync function to the user.
This commit is contained in:
parent
bd476acd41
commit
ec22d1739d
@ -81,6 +81,12 @@ STATIC void btree_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind
|
|||||||
mp_printf(print, "<btree %p>", self->db);
|
mp_printf(print, "<btree %p>", self->db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STATIC mp_obj_t btree_sync(mp_obj_t self_in) {
|
||||||
|
mp_obj_btree_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
return MP_OBJ_NEW_SMALL_INT(__bt_sync(self->db, 0));
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(btree_sync_obj, btree_sync);
|
||||||
|
|
||||||
STATIC mp_obj_t btree_close(mp_obj_t self_in) {
|
STATIC mp_obj_t btree_close(mp_obj_t self_in) {
|
||||||
mp_obj_btree_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_btree_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
return MP_OBJ_NEW_SMALL_INT(__bt_close(self->db));
|
return MP_OBJ_NEW_SMALL_INT(__bt_close(self->db));
|
||||||
@ -314,6 +320,7 @@ STATIC mp_obj_t btree_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
|
|||||||
|
|
||||||
STATIC const mp_rom_map_elem_t btree_locals_dict_table[] = {
|
STATIC const mp_rom_map_elem_t btree_locals_dict_table[] = {
|
||||||
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&btree_close_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&btree_close_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&btree_sync_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&btree_get_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&btree_get_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_put), MP_ROM_PTR(&btree_put_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_put), MP_ROM_PTR(&btree_put_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_seq), MP_ROM_PTR(&btree_seq_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_seq), MP_ROM_PTR(&btree_seq_obj) },
|
||||||
|
Loading…
Reference in New Issue
Block a user