diff --git a/README.md b/README.md index af15e19..e4f962d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This is a [RethinkDB](http://rethinkdb.com/) Driver for the [Crystal Language](http://crystal-lang.org/). -[![Build Status](https://travis-ci.org/kingsleyh/crystal-rethinkdb.svg?branch=master)](https://travis-ci.org/kingsleyh/crystal-rethinkdb) [![Crystal Version](https://img.shields.io/badge/crystal%20-0.35.1-brightgreen.svg)](https://crystal-lang.org/api/0.35.1/) +[![Build Status](https://travis-ci.org/kingsleyh/crystal-rethinkdb.svg?branch=master)](https://travis-ci.org/kingsleyh/crystal-rethinkdb) [![Crystal Version](https://img.shields.io/badge/crystal%20-1.0.0-brightgreen.svg)](https://crystal-lang.org/api/1.0.0/) ## Installation diff --git a/shard.yml b/shard.yml index 781132a..03c580b 100644 --- a/shard.yml +++ b/shard.yml @@ -1,6 +1,6 @@ name: rethinkdb -version: 0.2.1 -crystal: ~> 0.34 +version: 0.2.2 +crystal: ">= 0.34" license: MIT dependencies: diff --git a/spec/reql_spec_generator.cr b/spec/reql_spec_generator.cr index 1328c1a..f421fd7 100644 --- a/spec/reql_spec_generator.cr +++ b/spec/reql_spec_generator.cr @@ -49,7 +49,7 @@ data = YAML.parse(yaml_fixes File.read(ARGV[0])) puts "describe #{data["desc"].inspect} do" if tables = data["table_variable_name"]? puts - tables.as_s.split(", ").map(&.split(" ")).flatten.each_with_index do |tablevar, i| + tables.as_s.split(", ").flat_map(&.split(' ')).each_with_index do |tablevar, i| random_name = "test_#{Time.utc.to_unix}_#{rand(10000)}_#{i + 1}" puts " r.db(\"test\").table_create(#{random_name.inspect}).run(Fixtures::TestDB.conn)" puts " #{tablevar} = r.db(\"test\").table(#{random_name.inspect})" diff --git a/src/rethinkdb/connection.cr b/src/rethinkdb/connection.cr index 2079a5c..6699ea4 100644 --- a/src/rethinkdb/connection.cr +++ b/src/rethinkdb/connection.cr @@ -255,11 +255,20 @@ module RethinkDB end struct Response < Message + {% if compare_versions(Crystal::VERSION, "0.36.1") == 1 %} + @[JSON::Field(converter: Enum::ValueConverter(RethinkDB::ResponseType))] + {% end %} getter t : RethinkDB::ResponseType getter r : Array(QueryResult) + {% if compare_versions(Crystal::VERSION, "0.36.1") == 1 %} + @[JSON::Field(converter: Enum::ValueConverter(RethinkDB::ErrorType))] + {% end %} getter e : ErrorType? getter b : Array(JSON::Any)? getter p : JSON::Any? + {% if compare_versions(Crystal::VERSION, "0.36.1") == 1 %} + @[JSON::Field(converter: ArrayConverter(Enum::ValueConverter(RethinkDB::ResponseNote)))] + {% end %} getter n : Array(RethinkDB::ResponseNote) = [] of RethinkDB::ResponseNote private FEED_NOTES = [ @@ -327,21 +336,21 @@ module RethinkDB end def query_term(term) - send_query [QueryType::START, term.to_reql, runopts].to_json + send_query QueryType::START, term.to_reql, runopts read_response end def query_continue - send_query [QueryType::CONTINUE].to_json + send_query QueryType::CONTINUE read_response end - private def send_query(query) + private def send_query(type : QueryType, *rest) if id == 0 raise ReqlDriverError.new("Bug: Using already finished stream.") end - query_slice = query.to_slice + query_slice = ({type.value} + rest).to_json.to_slice conn.try_write do conn.sock.write_bytes(id, IO::ByteFormat::LittleEndian) conn.sock.write_bytes(query_slice.size, IO::ByteFormat::LittleEndian) diff --git a/src/rethinkdb/serialization.cr b/src/rethinkdb/serialization.cr index 4a0abdd..961d084 100644 --- a/src/rethinkdb/serialization.cr +++ b/src/rethinkdb/serialization.cr @@ -8,7 +8,7 @@ class Array(T) def to_reql JSON.parse([ RethinkDB::TermType::MAKE_ARRAY.to_i64, - map { |x| x.to_reql }, + map &.to_reql, ].to_json) end end @@ -17,7 +17,7 @@ struct Tuple def to_reql JSON.parse([ RethinkDB::TermType::MAKE_ARRAY.to_i64, - to_a.map { |x| x.to_reql }, + to_a.map &.to_reql, ].to_json) end end