Take on rusqlite dependency. Fixes #148. r=rnewman

This commit is contained in:
Brian Grinstead 2017-01-06 10:24:04 -06:00 committed by GitHub
parent fa3c99f550
commit 8a52015422
3 changed files with 49 additions and 10 deletions

View file

@ -4,6 +4,8 @@ version = "0.4.0"
authors = ["Richard Newman <rnewman@twinql.com>", "Nicholas Alexander <nalexander@mozilla.com>"]
[dependencies]
rusqlite = "0.8.0"
[dependencies.datomish-query-parser]
path = "query-parser"

View file

@ -9,6 +9,9 @@
// specific language governing permissions and limitations under the License.
extern crate datomish_query_parser;
extern crate rusqlite;
use rusqlite::Connection;
pub fn get_name() -> String {
return String::from("datomish");
@ -19,19 +22,15 @@ pub fn get_parser_name() -> String {
return datomish_query_parser::get_name();
}
pub fn add_two(a: i32) -> i32 {
a + 2
// Will ultimately not return the sqlite connection directly
pub fn get_connection() -> Connection {
return Connection::open_in_memory().unwrap();
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
assert_eq!(4, add_two(2));
}
#[test]
fn can_import_parser() {
assert_eq!(String::from("datomish-query-parser"), get_parser_name());

View file

@ -11,6 +11,44 @@
extern crate datomish;
#[test]
fn external_test() {
assert_eq!(4, datomish::add_two(2));
fn can_import_sqlite() {
// 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);
}
}