40 lines
786 B
Rust
40 lines
786 B
Rust
use rusqlite::{Connection, Error};
|
|
|
|
#[derive(Debug)]
|
|
pub enum ActionKind {
|
|
Text,
|
|
Script,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct Action {
|
|
id: i32,
|
|
name: String,
|
|
kind: ActionKind,
|
|
source: String,
|
|
created_at: String,
|
|
updated_at: String,
|
|
}
|
|
|
|
pub struct Conn {
|
|
conn: Connection,
|
|
}
|
|
|
|
pub fn new_conn(db_path: &str) -> Result<Conn, Error> {
|
|
let conn = Connection::open(db_path).expect("failed to open database");
|
|
|
|
conn.execute(
|
|
"CREATE TABLE action (
|
|
id INTEGER PRIMARY KEY,
|
|
name TEXT NOT NULL,
|
|
kind TEXT NOT NULL,
|
|
source TEXT NOT NULL,
|
|
created_at TEXT NOT NULL,
|
|
updated_at TEXT NOT NULL
|
|
)",
|
|
(), // empty list of parameters.
|
|
)?;
|
|
|
|
Ok(Conn { conn })
|
|
}
|