blob: 734c63532795b59dd4caa884e6515a9a51c9f48c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
use crate::store::Store;
use miette::{IntoDiagnostic, Result};
use sqlite::Connection;
pub struct SQLite {
location: String,
connection: Option<Connection>,
}
impl Default for SQLite {
fn default() -> Self {
SQLite {
location: ":memory:".into(),
connection: Option::None,
}
}
}
impl Store for SQLite {
fn init(&mut self) -> Result<()> {
let conn_path = self.location.clone();
self.connection = sqlite::open(conn_path).into_diagnostic().ok();
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sqlite_default() {
let context = SQLite::default();
assert_eq!(context.location, ":memory:");
assert!(context.connection.is_none());
}
#[test]
fn sqlite_init() {
let mut context = SQLite::default();
let res = context.init();
assert!(res.is_ok());
assert!(context.connection.is_some());
}
}
|