mirror of
https://github.com/csehviktor/status-monitor.git
synced 2025-08-08 18:06:14 +02:00
fix sql
This commit is contained in:
@@ -44,19 +44,31 @@ impl TryFrom<&Row<'_>> for UptimeStorageModel {
|
||||
type Error = rusqlite::Error;
|
||||
|
||||
fn try_from(row: &Row) -> Result<Self, Self::Error> {
|
||||
let first_seen: DateTime<Utc> = row.get::<_, String>(1)?.parse().map_err(|e| {
|
||||
rusqlite::Error::FromSqlConversionFailure(1, rusqlite::types::Type::Text, Box::new(e))
|
||||
let first_seen = DateTime::parse_from_rfc3339(&row.get::<_, String>(2)?)
|
||||
.map(|dt| dt.with_timezone(&Utc))
|
||||
.map_err(|e| {
|
||||
rusqlite::Error::FromSqlConversionFailure(
|
||||
1,
|
||||
rusqlite::types::Type::Text,
|
||||
Box::new(e),
|
||||
)
|
||||
})?;
|
||||
|
||||
let last_seen: DateTime<Utc> = row.get::<_, String>(2)?.parse().map_err(|e| {
|
||||
rusqlite::Error::FromSqlConversionFailure(2, rusqlite::types::Type::Text, Box::new(e))
|
||||
let last_seen = DateTime::parse_from_rfc3339(&row.get::<_, String>(2)?)
|
||||
.map(|dt| dt.with_timezone(&Utc))
|
||||
.map_err(|e| {
|
||||
rusqlite::Error::FromSqlConversionFailure(
|
||||
2,
|
||||
rusqlite::types::Type::Text,
|
||||
Box::new(e),
|
||||
)
|
||||
})?;
|
||||
|
||||
Ok(UptimeStorageModel {
|
||||
id: row.get(0)?,
|
||||
first_seen,
|
||||
last_seen,
|
||||
message_count: row.get(1)?,
|
||||
message_count: row.get(3)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,11 @@ impl SQLiteRepository {
|
||||
message_count INTEGER NOT NULL DEFAULT 0
|
||||
) STRICT;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS agents (
|
||||
id TEXT PRIMARY KEY AUTO_INCREMENT,
|
||||
CREATE TABLE IF NOT EXISTS messages (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
agent_id TEXT NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
timestamp TEXT NOT NULL
|
||||
timestamp TEXT NOT NULL,
|
||||
|
||||
FOREIGN KEY (agent_id) REFERENCES agents(id) ON DELETE CASCADE
|
||||
) STRICT;
|
||||
@@ -101,7 +101,7 @@ impl StorageRepository for SQLiteRepository {
|
||||
|
||||
let (sql, params) = if let Some(duration) = duration {
|
||||
(
|
||||
"SELECT agent_id, message, timestamp FROM messages WHERE agent_id = ? AND timestamp <= ?",
|
||||
"SELECT agent_id, message, timestamp FROM messages WHERE agent_id = ? AND timestamp >= ?",
|
||||
vec![agent.to_string(), duration.to_rfc3339()],
|
||||
)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user