Created
September 8, 2018 18:58
-
-
Save skade/8f0dc97229d96743e83158de6dd82bd5 to your computer and use it in GitHub Desktop.
Code demo of an API experiment for a database mapper.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mut changeset = BlogRepository::change().inserts::<Posts>(); | |
for id in 1..=3 { | |
let post = Post { id: id, content: format!("Post number {}", id) }; | |
changeset.push(post); | |
} | |
let mut changeset = changeset.inserts::<Comments>(); | |
for id in 1..=9 { | |
let post_id = id % 3; | |
changeset.push( | |
Comment { | |
id: id, | |
content: format!("Comment number {} on post {}", id, post_id + 1), | |
post_id: post_id + 1 | |
} | |
) | |
} | |
let gateway = Sqlite3Gateway { connection: conn }; | |
let repos = BlogRepository { gateway: gateway }; | |
changeset.commit(&repos); | |
let query = select::<Post>().from::<Posts>(); | |
let e1 = query.execute(&repos).for_each(|item| { | |
println!("{:?}", item); | |
future::ready(()) | |
}); | |
await!(e1); | |
let query2 = select::<Comment>().from::<Comments>(); | |
let e2 = query2.execute(&repos).for_each(|item| { | |
println!("{:?}", item); | |
future::ready(()) | |
}); | |
await!(e2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment