Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate reql;
- extern crate reql_types;
- extern crate futures;
- #[macro_use] extern crate serde_derive;
- use {
- reql::{Config, Client, Run, Document},
- reql_types::Change,
- futures::Stream,
- std::{
- net::{IpAddr, SocketAddr},
- },
- };
- #[derive(Serialize, Deserialize, Debug)]
- struct TestChange {
- id: u64,
- data: String,
- }
- fn main() -> reql::Result<()>{
- let r = Client::new();
- let mut conf = Config::default();
- let addr = "127.0.0.1".parse::<IpAddr>().unwrap();
- let socket = SocketAddr::new(addr, 28015);
- conf.db = "test";
- conf.servers = vec!(socket);
- conf.user = "admin";
- conf.password = "";
- let conn = r.connect(conf).unwrap();
- let query = r.db("test")
- .table("testdata")
- .changes()
- .run::<Change<TestChange, TestChange>>(conn)?;
- let mut changes = query.wait();
- loop {
- let change = changes.next();
- match change {
- Some(Ok(Some(Document::Expected(change)))) => {
- let results = change.new_val;
- match results {
- Some(results) => println!("Town ID: {}\nTown NAME: {}", results.id, results.data),
- _ => println!("Errors man"),
- }
- },
- Some(Err(e)) => {
- println!("Error: {}", e);
- },
- _ => {
- println!("Check whether the database exists and that it has data");
- },
- };
- }
- }
Add Comment
Please, Sign In to add comment