cool tech zone zone
LevelDB database documentation - Printable Version

+- cool tech zone zone (https://forum.cooltech.zone)
+-- Forum: Tangara (https://forum.cooltech.zone/forumdisplay.php?fid=3)
+--- Forum: Firmware Development (https://forum.cooltech.zone/forumdisplay.php?fid=7)
+--- Thread: LevelDB database documentation (/showthread.php?tid=146)



LevelDB database documentation - ayumi - 2025-02-27

Is reading src/tangara/database/* the only way to figure out what exactly (and in what format) gets stored in the LevelDB database, or is this documented somewhere?


RE: LevelDB database documentation - jacqueline - 2025-02-28

There's just that, or reading database dumps atm (there's a few good tools out there for working with raw leveldb databases). Sorry! Actual documentation has been on my to-do list for a while, but time continues to escape from us Smile

The extremely short version is that all keys are prefixed with a letter, and use null bytes (written as '/' in docs+comments) to separate out different fields in the keys. This allows us to effectively separate out sections of the database into namespaces. Most of these namespaces are quite straightfoward; e.g. 'data' keys are like "D/1234" (a prefix, D, a null byte spearator, a CBOR-encoded track id) and have values that contain things like times played, the track's filepath, etc.

Indexes are more complicated, since they rely on LevelDB storing keys on disk in a sorted order. Index keys are formatted, very very abstractly, like

I / grouping info / text / track id

Where the 'grouping info' is some data that identifies, e.g., you're in the 'Albums by artist' index and are viewing the records under a particular artist
Text is a https://en.cppreference.com/w/c/string/byte/strxfrm transformed version of the human-readable text (transformed such that a bytewise comparison yields a collated text order)
And track id is the track id.

Index record values are then just the human-readable text shown for each record.

If you'd like to know more, this file defines all the different record types we use: https://codeberg.org/cool-tech-zone/tangara-fw/src/branch/main/src/tangara/database/records.cpp
And you may also be interested in the indexing logic; it's actually a fairly small little recursive algorithm, it's not as complicated as you might imagine: https://codeberg.org/cool-tech-zone/tangara-fw/src/branch/main/src/tangara/database/index.cpp#L226

Obviously we should write proper docs for this eventually, but in the meantime we are very happy to answer any questions about it.


RE: LevelDB database documentation - ayumi - 2025-03-02

That’s very helpful, thanks!


RE: LevelDB database documentation - ayumi - 2025-03-03

So um… first question, I guess: does the firmware actually use the tag hash entries of track/disc numbers or can I ignore those?