store
¶
SQLite-backed storage and querying of records.
RecordStore
dataclass
¶
RecordStore(_conn: Connection)
SQLite-backed store for Records, grouped by run and queryable by tag/type.
Usage
with RecordStore.open(db_path) as store: store.write_run(run_path, records) traces = store.get_records_of_type(Trace2D, tag="my_tag")
write_run
¶
Replaces all records for run_path in a single transaction. Idempotent: calling this
again for the same run_path (e.g. re-running a generator on the same input directory)
deletes and replaces that run's rows rather than accumulating duplicates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_path
|
Path
|
the raw-data run directory these records were generated from |
required |
records
|
Iterable[Record]
|
records returned by the user's |
required |
Returns:
| Type | Description |
|---|---|
int
|
number of records written |
Source code in src/trendify/store/record_store.py
| Python | |
|---|---|
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
get_tags
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_type
|
type[Record] | None
|
restrict to tags used by records of this
type (or any registered subclass of it); |
None
|
Returns:
| Type | Description |
|---|---|
set[Tag]
|
the set of tags in use |
Source code in src/trendify/store/record_store.py
get_tag_byte_sizes
¶
Total payload size in bytes for each tag, summed across every record carrying that
tag. A record with N tags counts its full payload size toward all N (matches how
write_run stores one payload row referenced by N record_tags rows, not divided
N ways). Backs the viewer's background-hydration prioritization (viewer.tag_tree),
which starts prefetching the largest tag at the level the user is browsing.
Returns:
| Type | Description |
|---|---|
dict[Tag, int]
|
total payload bytes per tag |
Source code in src/trendify/store/record_store.py
tag_tree
¶
get_records
¶
Streams matching records, deserialized to their concrete pydantic type. Filtering by
tag and/or object_type happens in SQL (indexed tag lookup, record_type IN (...)
for the type hierarchy) before anything is deserialized, so this only ever parses JSON
for rows that actually match.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
Tag | None
|
tag to filter by; |
None
|
object_type
|
type[R] | None
|
type (or base type) to filter by; |
None
|
Yields:
| Type | Description |
|---|---|
R
|
matching records, in insertion order |
Source code in src/trendify/store/record_store.py
get_records_of_type
¶
Same as get_records, but eager (a list), for callers that don't need streaming.
Source code in src/trendify/store/record_store.py
has_records
¶
Cheap existence check for get_records's same (tag, object_type) filter: stops at
the first matching row instead of deserializing every one, for callers (like the
viewer's tag tree, viewer.tag_tree._record_kinds) that only need to know whether
any record matches, not what it is.
Source code in src/trendify/store/record_store.py
get_table_entries
¶
get_table_entries(tag: Tag) -> DataFrame
Fetches TableEntry rows for tag directly from the table_entries table, skipping
full Record payload deserialization entirely since row/col/value/unit are already
real columns.
Note: value is resolved to a single Python value per row (whichever of
value_num/value_text/value_bool is populated) before handing rows to Polars,
rather than asking Polars/SQLite to reconcile a mixed-type SQL column. Polars expects
one dtype per column, so resolving the union type in Python first is the well-defined
choice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
Tag
|
tag to filter by |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
a "melted" table with columns |
Source code in src/trendify/store/record_store.py
has_table_entries
¶
Cheap existence check for get_table_entries's same tag filter, without building a
pl.DataFrame (or resolving each row's value union) just to check whether it's empty.
Source code in src/trendify/store/record_store.py
connect
¶
connect(
db_path: Path, *, readonly: bool = False
) -> Connection
Opens a WAL-mode SQLite connection to db_path, bootstrapping the schema on first use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path
|
Path
|
path to the trendify output directory's |
required |
readonly
|
bool
|
open in read-only mode ( |
False
|
Returns:
| Type | Description |
|---|---|
Connection
|
a configured connection, with row access by column name. |
Source code in src/trendify/store/db.py
decode_tag
¶
Inverse of encode_tag. JSON arrays decode back to tuples (the Tag type never uses
plain lists) so round-tripping a tag through the store reproduces the original shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag_key
|
str
|
canonical string key, as produced by |
required |
Returns:
| Type | Description |
|---|---|
Tag
|
decoded tag |
Source code in src/trendify/store/tags.py
encode_tag
¶
Canonicalizes a Tag (str, int, or tuple[str | int, ...]) into the tag_key string
used for indexed storage/lookup. Scalars and tuples produce distinguishable encodings
(json.dumps renders a tuple as a JSON array), so "foo" and ("foo",) never collide.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
Tag
|
tag to encode |
required |
Returns:
| Type | Description |
|---|---|
str
|
canonical, indexable string key |
Source code in src/trendify/store/tags.py
tag_to_path_parts
¶
Converts a Tag into output-path parts: a tuple tag ("a", "b") becomes nested path
segments ("a", "b"), and a scalar tag "a" becomes a single segment ("a",).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
Tag
|
tag to convert |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
path parts, last one being the file stem |