feat(lsm): add entry data reading
This commit is contained in:
parent
1461956d98
commit
fc4187e6ce
4 changed files with 86 additions and 1 deletions
|
|
@ -1,5 +1,46 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "lsm.h"
|
||||
#include "lsm/store.h"
|
||||
#include "lsm/str.h"
|
||||
|
||||
int main() { printf("yuh"); }
|
||||
int main() {
|
||||
lsm_str *db_path, *data_dir;
|
||||
lsm_str_init_copy(&db_path, "data/data.db");
|
||||
lsm_str_init_copy(&data_dir, "data");
|
||||
|
||||
lsm_store *store;
|
||||
lsm_store_load(&store, db_path, data_dir);
|
||||
|
||||
lsm_str *key;
|
||||
lsm_str_init_copy(&key, "key");
|
||||
|
||||
lsm_entry_handle *handle;
|
||||
assert(lsm_store_insert(&handle, store, key) == lsm_error_ok);
|
||||
|
||||
lsm_str *data;
|
||||
lsm_str_init_copy(&data, "hello");
|
||||
|
||||
for (int i = 0; i < 50; i++) {
|
||||
lsm_entry_data_append(store, handle, data);
|
||||
}
|
||||
|
||||
lsm_entry_close(handle);
|
||||
|
||||
assert(lsm_store_open_read(&handle, store, key) == lsm_error_ok);
|
||||
|
||||
char buf[24];
|
||||
uint64_t read;
|
||||
uint64_t total = 0;
|
||||
|
||||
lsm_entry_data_read(&read, buf, handle, 24);
|
||||
total += read;
|
||||
|
||||
while (read > 0) {
|
||||
printf("%.*s", read, buf);
|
||||
lsm_entry_data_read(&read, buf, handle, 24);
|
||||
total += read;
|
||||
}
|
||||
printf("\n%lu", total);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue