Skip to content

Instantly share code, notes, and snippets.

@skade skade/code_demo.rs
Created Sep 8, 2018

Embed
What would you like to do?
Code demo of an API experiment for a database mapper.
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
You can’t perform that action at this time.