parent
6530658c3e
commit
a0cb6542ba
7 changed files with 287 additions and 126 deletions
|
@ -58,7 +58,7 @@ impl Connection {
|
|||
mod test {
|
||||
use indoc::indoc;
|
||||
|
||||
use crate::connection::Connection;
|
||||
use crate::{connection::Connection, thread_safe_connection::ThreadSafeConnection};
|
||||
|
||||
#[test]
|
||||
fn test_migrations_are_added_to_table() {
|
||||
|
|
|
@ -59,11 +59,11 @@ impl<'a> Statement<'a> {
|
|||
);
|
||||
remaining_sql = CStr::from_ptr(remaining_sql_ptr);
|
||||
statement.raw_statements.push(raw_statement);
|
||||
}
|
||||
|
||||
connection
|
||||
.last_error()
|
||||
.with_context(|| format!("Prepare call failed for query:\n{}", query.as_ref()))?;
|
||||
connection.last_error().with_context(|| {
|
||||
format!("Prepare call failed for query:\n{}", query.as_ref())
|
||||
})?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(statement)
|
||||
|
|
|
@ -109,3 +109,50 @@ impl<M: Migrator> Deref for ThreadSafeConnection<M> {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::ops::Deref;
|
||||
|
||||
use crate::domain::Domain;
|
||||
|
||||
use super::ThreadSafeConnection;
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn wild_zed_lost_failure() {
|
||||
enum TestWorkspace {}
|
||||
impl Domain for TestWorkspace {
|
||||
fn name() -> &'static str {
|
||||
"workspace"
|
||||
}
|
||||
|
||||
fn migrations() -> &'static [&'static str] {
|
||||
&["
|
||||
CREATE TABLE workspaces(
|
||||
workspace_id BLOB PRIMARY KEY,
|
||||
dock_visible INTEGER, -- Boolean
|
||||
dock_anchor TEXT, -- Enum: 'Bottom' / 'Right' / 'Expanded'
|
||||
dock_pane INTEGER, -- NULL indicates that we don't have a dock pane yet
|
||||
timestamp TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
FOREIGN KEY(dock_pane) REFERENCES panes(pane_id),
|
||||
FOREIGN KEY(active_pane) REFERENCES panes(pane_id)
|
||||
) STRICT;
|
||||
|
||||
CREATE TABLE panes(
|
||||
pane_id INTEGER PRIMARY KEY,
|
||||
workspace_id BLOB NOT NULL,
|
||||
active INTEGER NOT NULL, -- Boolean
|
||||
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE
|
||||
) STRICT;
|
||||
"]
|
||||
}
|
||||
}
|
||||
|
||||
let _ = ThreadSafeConnection::<TestWorkspace>::new(None, false)
|
||||
.with_initialize_query("PRAGMA FOREIGN_KEYS=true")
|
||||
.deref();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue