diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs index d9a8272..16e7bbd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,10 +21,20 @@ fn main() { // .redirect_uri("http://localhost:8888/callback") // .build(); // - let mut db = noria::ControllerHandle::from_zk("127.0.0.1:2181").unwrap(); + // looking up article 42 should yield the article we inserted with a vote count of 1 + init(); + + rocket::ignite() + .mount("/", routes![serve::token, serve::get_tracks]) + .launch(); +} + + +async fn init() { + let mut db = noria::ControllerHandle::from_zk("127.0.0.1:2181").await.unwrap(); //db.ready(); - println!("test {:?}", db.url()); + //println!("test {:?}", db.url()); db.install_recipe( " CREATE TABLE Article (aid int, title varchar(255), url text, PRIMARY KEY(aid)); @@ -33,8 +43,8 @@ fn main() { ); println!("test"); // we can then get handles that let us insert into the new tables - let mut article = db.table("Article").unwrap(); - let mut vote = db.table("Vote").unwrap(); + let mut article = db.table("Article").await.unwrap(); + let mut vote = db.table("Vote").await.unwrap(); // let's make a new article let aid = 42; @@ -42,10 +52,10 @@ fn main() { let url = "https://pdos.csail.mit.edu"; article .insert(vec![aid.into(), title.into(), url.into()]) - .unwrap(); + .await.unwrap(); // and then vote for it - vote.insert(vec![aid.into(), 1.into()]).unwrap(); + vote.insert(vec![aid.into(), 1.into()]).await.unwrap(); println!("test"); // we can also declare views that we want want to query @@ -61,10 +71,10 @@ fn main() { ); // and then get handles that let us execute those queries to fetch their results - let mut awvc = db.view("ArticleWithVoteCount").unwrap(); - // looking up article 42 should yield the article we inserted with a vote count of 1 + let mut awvc = db.view("ArticleWithVoteCount").await.unwrap(); + assert_eq!( - awvc.lookup(&[aid.into()], true).unwrap(), + awvc.lookup(&[aid.into()], true).await.unwrap(), vec![vec![ noria::DataType::from(aid), title.into(), @@ -72,8 +82,4 @@ fn main() { 1.into() ]] ); - - rocket::ignite() - .mount("/", routes![serve::token, serve::get_tracks]) - .launch(); } |