feat: sql migrations and daemon state endpoint
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use anyhow::Result;
|
||||
use directories::ProjectDirs;
|
||||
use shared::ai::ChatMessage as CMessage;
|
||||
use sqlx::sqlite::SqliteConnectOptions;
|
||||
use sqlx::Row;
|
||||
use sqlx::SqlitePool;
|
||||
@@ -20,14 +19,6 @@ pub trait ChatRepository {
|
||||
async fn get_latest_messages(&self) -> Result<Vec<ChatMessage>>;
|
||||
}
|
||||
|
||||
pub fn message_to_dto(msg: &ChatMessage) -> CMessage {
|
||||
CMessage {
|
||||
id: msg.id,
|
||||
text: msg.text.clone(),
|
||||
is_user: msg.is_user,
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SqliteChatRepository {
|
||||
pool: SqlitePool,
|
||||
}
|
||||
@@ -49,16 +40,10 @@ impl SqliteChatRepository {
|
||||
)
|
||||
.await?;
|
||||
|
||||
sqlx::query(
|
||||
"CREATE TABLE IF NOT EXISTS messages (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
text TEXT NOT NULL,
|
||||
is_user BOOL NOT NULL
|
||||
)",
|
||||
)
|
||||
.execute(&pool)
|
||||
.await
|
||||
.inspect_err(|e| println!("sql error: {}", e))?;
|
||||
sqlx::migrate!("./migrations")
|
||||
.run(&pool)
|
||||
.await
|
||||
.inspect_err(|e| eprintln!("Migration failed! {}", e))?;
|
||||
|
||||
Ok(Self { pool })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user