A lightweight custom-format database engine for Flipper Zero.
Once upon a time, one girl tried to serialize and deserialize back a complex data structure in her very own FAP. She found it quite frustrating and suboptimal.
Frustrated and suboptimized, she went to the SQLite downloads page and got the amalgamation of the entire SQLite in a single C source file.
Soon enough she found out that uFBT, whatever she did, does not want to build this abomination for this embedded platform. And when she began to try to make a custom compatibility chassis, she had been flipped over once again.«Well, — she thought, — maybe running SQLite on a device with 256KB of RAM isn't a good idea. Maybe I just need to create something myself, at least remotely SQLite-ish, initially designing it for embedded systems».
So, this repo is her humble attempt to conquer this goal.
Docs WIP.
#include <furi.h>
#include "fzdb.h"
static bool print_row_cb(
const FzdbValue* values,
uint8_t column_count,
void* context
) {
UNUSED(column_count);
UNUSED(context);
FURI_LOG_I(
"FZDB", "ID: %lu; Label: %s; Key: %02X %02X",
values[0].value.u32,
values[1].value.str,
values[2].value.blob.data[0]
values[2].value.blob.data[1]
);
return true; // Continue reading
}
void fzdb_demo(void) {
Fzdb* db = NULL;
if (fzdb_open(APP_DATA_PATH("demo.fzdb"), &db) != FzdbStatusOk) return;
if (!fzdb_get_table(db, "ibuttons")) {
const FzdbColumn cols[] = {
{.name = "id", .type = FzdbTypeUint32},
{.name = "label", .type = FzdbTypeString},
{.name = "rom_data", .type = FzdbTypeBlob}
};
fzdb_create_table(db, "ibuttons", cols, COUNT_OF(cols));
}
const uint8_t sample_key[] = {0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x2f};
const FzdbValue row[] = {
FZDB_VAL_UINT32(1),
FZDB_VAL_STR("Master"),
FZDB_VAL_BLOB(sample_key, sizeof(sample_key))
};
fzdb_insert_row(db, "ibuttons", row);
fzdb_select_all(db, "ibuttons", print_row_cb, NULL);
fzdb_close(db);
}