Take on rusqlite dependency. Fixes #148. r=rnewman
This commit is contained in:
parent
fa3c99f550
commit
8a52015422
3 changed files with 49 additions and 10 deletions
|
@ -4,6 +4,8 @@ version = "0.4.0"
|
||||||
authors = ["Richard Newman <rnewman@twinql.com>", "Nicholas Alexander <nalexander@mozilla.com>"]
|
authors = ["Richard Newman <rnewman@twinql.com>", "Nicholas Alexander <nalexander@mozilla.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
rusqlite = "0.8.0"
|
||||||
|
|
||||||
[dependencies.datomish-query-parser]
|
[dependencies.datomish-query-parser]
|
||||||
path = "query-parser"
|
path = "query-parser"
|
||||||
|
|
||||||
|
|
13
src/lib.rs
13
src/lib.rs
|
@ -9,6 +9,9 @@
|
||||||
// specific language governing permissions and limitations under the License.
|
// specific language governing permissions and limitations under the License.
|
||||||
|
|
||||||
extern crate datomish_query_parser;
|
extern crate datomish_query_parser;
|
||||||
|
extern crate rusqlite;
|
||||||
|
|
||||||
|
use rusqlite::Connection;
|
||||||
|
|
||||||
pub fn get_name() -> String {
|
pub fn get_name() -> String {
|
||||||
return String::from("datomish");
|
return String::from("datomish");
|
||||||
|
@ -19,19 +22,15 @@ pub fn get_parser_name() -> String {
|
||||||
return datomish_query_parser::get_name();
|
return datomish_query_parser::get_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_two(a: i32) -> i32 {
|
// Will ultimately not return the sqlite connection directly
|
||||||
a + 2
|
pub fn get_connection() -> Connection {
|
||||||
|
return Connection::open_in_memory().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn it_works() {
|
|
||||||
assert_eq!(4, add_two(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_import_parser() {
|
fn can_import_parser() {
|
||||||
assert_eq!(String::from("datomish-query-parser"), get_parser_name());
|
assert_eq!(String::from("datomish-query-parser"), get_parser_name());
|
||||||
|
|
|
@ -11,6 +11,44 @@
|
||||||
extern crate datomish;
|
extern crate datomish;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn external_test() {
|
fn can_import_sqlite() {
|
||||||
assert_eq!(4, datomish::add_two(2));
|
// From https://github.com/jgallagher/rusqlite#rusqlite.
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Person {
|
||||||
|
id: i32,
|
||||||
|
name: String,
|
||||||
|
data: Option<Vec<u8>>
|
||||||
|
}
|
||||||
|
|
||||||
|
let conn = datomish::get_connection();
|
||||||
|
|
||||||
|
conn.execute("CREATE TABLE person (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
data BLOB
|
||||||
|
)", &[]).unwrap();
|
||||||
|
let me = Person {
|
||||||
|
id: 1,
|
||||||
|
name: "Steven".to_string(),
|
||||||
|
data: None
|
||||||
|
};
|
||||||
|
conn.execute("INSERT INTO person (name, data)
|
||||||
|
VALUES (?1, ?2)",
|
||||||
|
&[&me.name, &me.data]).unwrap();
|
||||||
|
|
||||||
|
let mut stmt = conn.prepare("SELECT id, name, data FROM person").unwrap();
|
||||||
|
let person_iter = stmt.query_map(&[], |row| {
|
||||||
|
Person {
|
||||||
|
id: row.get(0),
|
||||||
|
name: row.get(1),
|
||||||
|
data: row.get(2)
|
||||||
|
}
|
||||||
|
}).unwrap();
|
||||||
|
|
||||||
|
for person in person_iter {
|
||||||
|
let p = person.unwrap();
|
||||||
|
assert_eq!(me.id, p.id);
|
||||||
|
assert_eq!(me.data, p.data);
|
||||||
|
assert_eq!(me.data, p.data);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue