Skip to content

Commit f4b54a5

Browse files
lxsaahCopilot
andauthored
74 add persistence backend sqlite for long term record history (#75)
* implement optional SQLite persistence backend for long-term record history * update persistence backend documentation and implementation details for SQLite integration * feat: add generic extension storage for AimDbBuilder and AimDb - Introduced `Extensions` struct for storing typed state during builder configuration and record setup. - Updated `AimDbBuilder` and `AimDb` to use the new `Extensions` for external crate integration. feat: implement record.query handler for persistence - Added `handle_record_query` function to process `record.query` requests. - Integrated a type-erased query handler mechanism to allow persistence backends to register query handlers. feat: create SQLite persistence backend - Added `aimdb-persistence-sqlite` crate with a `SqliteBackend` implementation. - Implemented asynchronous storage and querying of records using SQLite. feat: define persistence backend trait and extensions - Created `PersistenceBackend` trait for pluggable persistence backends. - Added builder and record registration extensions for persistence configuration. feat: implement query extensions for AimDb - Added `AimDbQueryExt` trait to provide query capabilities for latest and range queries. - Integrated error handling and deserialization for queried results. test: add unit tests for persistence functionality - Implemented tests for storing, querying, and cleaning up records in the SQLite backend. - Verified correct behavior for pattern matching and time range queries. * chore: update subproject commit reference for embassy * feat: add regex dependency for improved pattern matching * feat: enhance SQLite persistence backend with improved error handling and type safety * feat: add changelog and README for aimdb-persistence and aimdb-persistence-sqlite * feat: update query_range to accept optional limit_per_record parameter * format * Update aimdb-core/src/remote/handler.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update aimdb-core/src/remote/handler.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update aimdb-persistence-sqlite/src/lib.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update aimdb-persistence/src/ext.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add NoStdStartFnType for non-std environments and improve retention handling * Add integration tests for query handling --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent b9bb2e6 commit f4b54a5

25 files changed

Lines changed: 3322 additions & 4 deletions

Cargo.lock

Lines changed: 94 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ members = [
88
"aimdb-embassy-adapter",
99
"aimdb-tokio-adapter",
1010
"aimdb-sync",
11+
"aimdb-persistence",
12+
"aimdb-persistence-sqlite",
1113
"aimdb-mqtt-connector",
1214
"aimdb-knx-connector",
1315
"tools/aimdb-cli",

Makefile

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ build:
6060
cargo build --package aimdb-cli
6161
@printf "$(YELLOW) → Building MCP server$(NC)\n"
6262
cargo build --package aimdb-mcp
63+
@printf "$(YELLOW) → Building persistence backend$(NC)\n"
64+
cargo build --package aimdb-persistence
65+
@printf "$(YELLOW) → Building persistence SQLite backend$(NC)\n"
66+
cargo build --package aimdb-persistence-sqlite
6367
@printf "$(YELLOW) → Building KNX connector$(NC)\n"
6468
cargo build --package aimdb-knx-connector --features "std,tokio-runtime"
6569

@@ -85,14 +89,18 @@ test:
8589
cargo test --package aimdb-cli
8690
@printf "$(YELLOW) → Testing MCP server$(NC)\n"
8791
cargo test --package aimdb-mcp
92+
@printf "$(YELLOW) → Testing persistence backend$(NC)\n"
93+
cargo test --package aimdb-persistence
94+
@printf "$(YELLOW) → Testing persistence SQLite backend$(NC)\n"
95+
cargo test --package aimdb-persistence-sqlite
8896
@printf "$(YELLOW) → Testing MQTT connector$(NC)\n"
8997
cargo test --package aimdb-mqtt-connector --features "std,tokio-runtime"
9098
@printf "$(YELLOW) → Testing KNX connector$(NC)\n"
9199
cargo test --package aimdb-knx-connector --features "std,tokio-runtime"
92100

93101
fmt:
94102
@printf "$(GREEN)Formatting code (workspace members only)...$(NC)\n"
95-
@for pkg in aimdb-executor aimdb-derive aimdb-data-contracts aimdb-core aimdb-client aimdb-embassy-adapter aimdb-tokio-adapter aimdb-sync aimdb-mqtt-connector aimdb-knx-connector aimdb-cli aimdb-mcp sync-api-demo tokio-mqtt-connector-demo embassy-mqtt-connector-demo tokio-knx-connector-demo embassy-knx-connector-demo weather-mesh-common weather-hub weather-station-alpha weather-station-beta; do \
103+
@for pkg in aimdb-executor aimdb-derive aimdb-data-contracts aimdb-core aimdb-client aimdb-embassy-adapter aimdb-tokio-adapter aimdb-sync aimdb-persistence aimdb-persistence-sqlite aimdb-mqtt-connector aimdb-knx-connector aimdb-cli aimdb-mcp sync-api-demo tokio-mqtt-connector-demo embassy-mqtt-connector-demo tokio-knx-connector-demo embassy-knx-connector-demo weather-mesh-common weather-hub weather-station-alpha weather-station-beta; do \
96104
printf "$(YELLOW) → Formatting $$pkg$(NC)\n"; \
97105
cargo fmt -p $$pkg 2>/dev/null || true; \
98106
done
@@ -101,7 +109,7 @@ fmt:
101109
fmt-check:
102110
@printf "$(GREEN)Checking code formatting (workspace members only)...$(NC)\n"
103111
@FAILED=0; \
104-
for pkg in aimdb-executor aimdb-derive aimdb-data-contracts aimdb-core aimdb-client aimdb-embassy-adapter aimdb-tokio-adapter aimdb-sync aimdb-mqtt-connector aimdb-knx-connector aimdb-cli aimdb-mcp sync-api-demo tokio-mqtt-connector-demo embassy-mqtt-connector-demo tokio-knx-connector-demo embassy-knx-connector-demo weather-mesh-common weather-hub weather-station-alpha weather-station-beta; do \
112+
for pkg in aimdb-executor aimdb-derive aimdb-data-contracts aimdb-core aimdb-client aimdb-embassy-adapter aimdb-tokio-adapter aimdb-sync aimdb-persistence aimdb-persistence-sqlite aimdb-mqtt-connector aimdb-knx-connector aimdb-cli aimdb-mcp sync-api-demo tokio-mqtt-connector-demo embassy-mqtt-connector-demo tokio-knx-connector-demo embassy-knx-connector-demo weather-mesh-common weather-hub weather-station-alpha weather-station-beta; do \
105113
printf "$(YELLOW) → Checking $$pkg$(NC)\n"; \
106114
if ! cargo fmt -p $$pkg -- --check 2>&1; then \
107115
printf "$(RED)❌ Formatting check failed for $$pkg$(NC)\n"; \
@@ -140,6 +148,10 @@ clippy:
140148
cargo clippy --package aimdb-cli --all-targets -- -D warnings
141149
@printf "$(YELLOW) → Clippy on MCP server$(NC)\n"
142150
cargo clippy --package aimdb-mcp --all-targets -- -D warnings
151+
@printf "$(YELLOW) → Clippy on persistence backend$(NC)\n"
152+
cargo clippy --package aimdb-persistence --all-targets -- -D warnings
153+
@printf "$(YELLOW) → Clippy on persistence SQLite backend$(NC)\n"
154+
cargo clippy --package aimdb-persistence-sqlite --all-targets -- -D warnings
143155
@printf "$(YELLOW) → Clippy on KNX connector (std)$(NC)\n"
144156
cargo clippy --package aimdb-knx-connector --features "std,tokio-runtime" --all-targets -- -D warnings
145157
@printf "$(YELLOW) → Clippy on KNX connector (embassy)$(NC)\n"
@@ -163,6 +175,8 @@ doc:
163175
cargo doc --package aimdb-knx-connector --features "std,tokio-runtime" --no-deps
164176
cargo doc --package aimdb-cli --no-deps
165177
cargo doc --package aimdb-mcp --no-deps
178+
cargo doc --package aimdb-persistence --no-deps
179+
cargo doc --package aimdb-persistence-sqlite --no-deps
166180
@cp -r target/doc/* target/doc-final/cloud/
167181
@printf "$(YELLOW) → Building embedded documentation$(NC)\n"
168182
cargo doc --package aimdb-core --no-default-features --features alloc --no-deps

_external/embassy

Submodule embassy updated 49 files

0 commit comments

Comments
 (0)