feat: reorganize with remote
This commit is contained in:
parent
a74e5753fa
commit
dc7b8cbadd
28 changed files with 622 additions and 3024 deletions
|
|
@ -1,10 +1,11 @@
|
|||
use anyhow::{Context, Result};
|
||||
use rusqlite::Connection;
|
||||
|
||||
use crate::types::{DoorStatus, HistoryEntry, StatusResponse};
|
||||
use crate::types::{DoorStatus, StatusResponse};
|
||||
|
||||
pub fn init(path: &str) -> Result<Connection> {
|
||||
let conn = Connection::open(path).context("failed to open SQLite database")?;
|
||||
conn.execute_batch("PRAGMA journal_mode=WAL;")?;
|
||||
conn.execute_batch(
|
||||
"
|
||||
CREATE TABLE IF NOT EXISTS current_state (
|
||||
|
|
@ -96,16 +97,17 @@ pub fn get_current_status_str(conn: &Connection) -> Result<Option<String>> {
|
|||
Ok(status)
|
||||
}
|
||||
|
||||
pub fn get_history(conn: &Connection, limit: u32) -> Result<Vec<HistoryEntry>> {
|
||||
pub fn get_history(conn: &Connection, limit: u32) -> Result<Vec<noisebell_common::HistoryEntry>> {
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT status, timestamp, recorded_at FROM state_log ORDER BY id DESC LIMIT ?1",
|
||||
"SELECT id, status, timestamp, recorded_at FROM state_log ORDER BY id DESC LIMIT ?1",
|
||||
)?;
|
||||
let entries = stmt
|
||||
.query_map(rusqlite::params![limit], |row| {
|
||||
Ok(HistoryEntry {
|
||||
status: row.get(0)?,
|
||||
timestamp: row.get(1)?,
|
||||
recorded_at: row.get(2)?,
|
||||
Ok(noisebell_common::HistoryEntry {
|
||||
id: row.get(0)?,
|
||||
status: row.get(1)?,
|
||||
timestamp: row.get(2)?,
|
||||
recorded_at: row.get(3)?,
|
||||
})
|
||||
})?
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue