Skip to content

Commit ec22d17

Browse files
w4kpmdpgeorge
authored andcommitted
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.
1 parent bd476ac commit ec22d17

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

extmod/modbtree.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ STATIC void btree_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind
8181
mp_printf(print, "<btree %p>", self->db);
8282
}
8383

84+
STATIC mp_obj_t btree_sync(mp_obj_t self_in) {
85+
mp_obj_btree_t *self = MP_OBJ_TO_PTR(self_in);
86+
return MP_OBJ_NEW_SMALL_INT(__bt_sync(self->db, 0));
87+
}
88+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(btree_sync_obj, btree_sync);
89+
8490
STATIC mp_obj_t btree_close(mp_obj_t self_in) {
8591
mp_obj_btree_t *self = MP_OBJ_TO_PTR(self_in);
8692
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)
314320

315321
STATIC const mp_rom_map_elem_t btree_locals_dict_table[] = {
316322
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&btree_close_obj) },
323+
{ MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&btree_sync_obj) },
317324
{ MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&btree_get_obj) },
318325
{ MP_ROM_QSTR(MP_QSTR_put), MP_ROM_PTR(&btree_put_obj) },
319326
{ MP_ROM_QSTR(MP_QSTR_seq), MP_ROM_PTR(&btree_seq_obj) },

0 commit comments

Comments
 (0)