Guest User

Untitled

a guest
Nov 1st, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. extern crate reql;
  2. extern crate reql_types;
  3. extern crate futures;
  4. #[macro_use] extern crate serde_derive;
  5.  
  6. use {
  7. reql::{Config, Client, Run, Document},
  8. reql_types::Change,
  9. futures::Stream,
  10. std::{
  11. net::{IpAddr, SocketAddr},
  12. },
  13. };
  14.  
  15. #[derive(Serialize, Deserialize, Debug)]
  16. struct TestChange {
  17. id: u64,
  18. data: String,
  19. }
  20.  
  21. fn main() -> reql::Result<()>{
  22. let r = Client::new();
  23.  
  24. let mut conf = Config::default();
  25.  
  26. let addr = "127.0.0.1".parse::<IpAddr>().unwrap();
  27. let socket = SocketAddr::new(addr, 28015);
  28. conf.db = "test";
  29. conf.servers = vec!(socket);
  30. conf.user = "admin";
  31. conf.password = "";
  32.  
  33. let conn = r.connect(conf).unwrap();
  34. let query = r.db("test")
  35. .table("testdata")
  36. .changes()
  37. .run::<Change<TestChange, TestChange>>(conn)?;
  38.  
  39.  
  40.  
  41. let mut changes = query.wait();
  42.  
  43. loop {
  44. let change = changes.next();
  45. match change {
  46. Some(Ok(Some(Document::Expected(change)))) => {
  47. let results = change.new_val;
  48. match results {
  49. Some(results) => println!("Town ID: {}\nTown NAME: {}", results.id, results.data),
  50. _ => println!("Errors man"),
  51. }
  52. },
  53. Some(Err(e)) => {
  54. println!("Error: {}", e);
  55. },
  56. _ => {
  57. println!("Check whether the database exists and that it has data");
  58. },
  59. };
  60. }
  61. }
Add Comment
Please, Sign In to add comment