kpcli: adds 'db' subcommand for interacting with the database
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use anyhow::Result;
|
||||
use diesel::prelude::*;
|
||||
use diesel::{prelude::*, sqlite::Sqlite};
|
||||
use diesel::query_dsl::BelongingToDsl;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::{
|
||||
models::{
|
||||
@@ -20,7 +21,11 @@ pub struct ChatDatabase {
|
||||
|
||||
impl ChatDatabase {
|
||||
pub fn new_in_memory() -> Result<Self> {
|
||||
let mut db = SqliteConnection::establish(":memory:")?;
|
||||
Self::new(":memory:")
|
||||
}
|
||||
|
||||
pub fn new(db_path: &str) -> Result<Self> {
|
||||
let mut db = SqliteConnection::establish(db_path)?;
|
||||
db.run_pending_migrations(MIGRATIONS)
|
||||
.map_err(|e| anyhow::anyhow!("Error running migrations: {}", e))?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user