lander/lsm/example/test.c

57 lines
1.2 KiB
C
Raw Permalink Normal View History

2023-10-29 14:41:40 +01:00
#include <assert.h>
#include <stdio.h>
#include "lsm.h"
2023-10-29 14:41:40 +01:00
#include "lsm/store.h"
#include "lsm/str.h"
2023-10-29 14:41:40 +01:00
int main() {
2023-11-07 17:43:15 +01:00
lsm_str *data_dir;
2023-10-29 14:41:40 +01:00
lsm_str_init_copy(&data_dir, "data");
lsm_store *store;
assert(lsm_store_load(&store, data_dir) == lsm_error_ok);
2023-10-29 14:41:40 +01:00
lsm_str *key;
lsm_str_init_copy(&key, "key");
lsm_entry_handle *handle;
assert(lsm_store_insert(&handle, store, key) == lsm_error_ok);
2023-11-08 08:47:24 +01:00
lsm_str *attr;
lsm_str_init_copy(&attr, "some attribute value");
2023-11-12 12:48:36 +01:00
lsm_entry_attr_insert(handle, 1, attr);
2023-10-29 14:41:40 +01:00
lsm_str *data;
lsm_str_init_copy(&data, "hello");
for (int i = 0; i < 50; i++) {
2023-11-12 12:48:36 +01:00
lsm_entry_data_append(handle, data);
2023-11-07 17:43:15 +01:00
}
2023-10-29 14:41:40 +01:00
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);
2023-11-12 12:48:36 +01:00
lsm_entry_close(handle);
assert(lsm_store_open_write(&handle, store, key) == lsm_error_ok);
lsm_entry_remove(handle);
lsm_entry_close(handle);
assert(lsm_store_open_read(&handle, store, key) == lsm_error_not_found);
2023-10-29 14:41:40 +01:00
}