Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. require "crystal-monetdb-libmapi/monetdb"
  2. require "crystal-monetdb-libmapi/monetdb_data"
  3. require "colorize"
  4.  
  5. class ConnectionError < Exception; end
  6. class QueryError < Exception; end
  7. class InternalError < Exception; end
  8. class TimeoutError < Exception; end
  9.  
  10. mero = MonetDB::ClientJSON.new
  11. mero.host = "127.0.0.1"
  12. mero.port = 50000
  13. mero.username = "monetdb"
  14. mero.password = "monetdb"
  15. mero.db = "monetdb-example1"
  16.  
  17. query = "SELECT name, price FROM \"test\".fruits;"
  18. mid = mero.connect
  19. result_json = mero.query_json(query)
  20. result = mero.json_to_hash(result_json)
  21. puts "Hash Created:".colorize(:red)
  22. p result
  23. puts "Display specific fields".colorize(:red)
  24. result.each {|k,v|
  25. puts "Hash Key: #{k} Name: #{v["name"]} Price: #{v["price"]}"
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement