Crate schemer_rusqlite
source ·Expand description
An adapter enabling use of the schemer schema migration library with SQLite3.
Examples:
extern crate rusqlite;
#[macro_use]
extern crate schemer;
extern crate schemer_rusqlite;
extern crate uuid;
use std::collections::HashSet;
use rusqlite::{params, Connection, Transaction, Error as RusqliteError};
use schemer::{Migration, Migrator};
use schemer_rusqlite::{RusqliteAdapter, RusqliteAdapterError, RusqliteMigration};
use uuid::Uuid;
struct MyExampleMigration;
migration!(
MyExampleMigration,
"4885e8ab-dafa-4d76-a565-2dee8b04ef60",
[],
"An example migration without dependencies.");
impl RusqliteMigration for MyExampleMigration {
type Error = RusqliteError;
fn up(&self, transaction: &Transaction) -> Result<(), RusqliteAdapterError> {
transaction.execute("CREATE TABLE my_example (id integer PRIMARY KEY);", params![])?;
Ok(())
}
fn down(&self, transaction: &Transaction) -> Result<(), RusqliteAdapterError> {
transaction.execute("DROP TABLE my_example;", params![])?;
Ok(())
}
}
fn main() {
let mut conn = Connection::open_in_memory().unwrap();
let adapter = RusqliteAdapter::new(&mut conn, None);
let mut migrator = Migrator::new(adapter);
let migration = Box::new(MyExampleMigration {});
migrator.register(migration);
migrator.up(None);
}
Structs
- Adapter between schemer and SQLite.
Traits
- SQlite-specific trait for schema migrations.