diff options
author | Dennis Kobert <dennis@kobert.dev> | 2020-02-09 15:06:15 +0000 |
---|---|---|
committer | Dennis Kobert <dennis@kobert.dev> | 2020-02-09 15:06:15 +0000 |
commit | afbc38858cac276414d4cb286e69b061548923f8 (patch) | |
tree | 942a67aae0c90d5e08cf8eb093cfde896e22a2e7 /src | |
parent | 1ba3be90a6ef1d196c6ad45df79ee22608be0b04 (diff) |
Testing
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 53 |
1 files changed, 53 insertions, 0 deletions
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(); |