From afbc38858cac276414d4cb286e69b061548923f8 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sun, 9 Feb 2020 15:06:15 +0000 Subject: Testing --- src/main.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 8b7af53..d9a8272 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,59 @@ fn main() { // .client_secret("this-is-my-client-secret") // .redirect_uri("http://localhost:8888/callback") // .build(); + // + let mut db = noria::ControllerHandle::from_zk("127.0.0.1:2181").unwrap(); + + //db.ready(); + println!("test {:?}", db.url()); + db.install_recipe( + " + CREATE TABLE Article (aid int, title varchar(255), url text, PRIMARY KEY(aid)); + CREATE TABLE Vote (aid int, uid int); +", + ); + 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's make a new article + let aid = 42; + let title = "I love Soup"; + let url = "https://pdos.csail.mit.edu"; + article + .insert(vec![aid.into(), title.into(), url.into()]) + .unwrap(); + + // and then vote for it + vote.insert(vec![aid.into(), 1.into()]).unwrap(); + println!("test"); + + // we can also declare views that we want want to query + db.extend_recipe( + " + VoteCount: \ + SELECT Vote.aid, COUNT(uid) AS votes \ + FROM Vote GROUP BY Vote.aid; + QUERY ArticleWithVoteCount: \ + SELECT Article.aid, title, url, VoteCount.votes AS votes \ + FROM Article LEFT JOIN VoteCount ON (Article.aid = VoteCount.aid) \ + WHERE Article.aid = ?;", + ); + + // 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 + assert_eq!( + awvc.lookup(&[aid.into()], true).unwrap(), + vec![vec![ + noria::DataType::from(aid), + title.into(), + url.into(), + 1.into() + ]] + ); + rocket::ignite() .mount("/", routes![serve::token, serve::get_tracks]) .launch(); -- cgit v1.2.3-54-g00ecf