Skip to content

Commit

Permalink
added skip
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingsley Hendrickse committed Aug 6, 2019
1 parent 2e3805e commit 402330f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.28.0-brightgreen.svg)](https://crystal-lang.org/api/0.28.0/)
[![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.30.0-brightgreen.svg)](https://crystal-lang.org/api/0.30.0/)

### WARNING: This is only a basic driver a lot of functions are not implemented.

Expand Down
4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: crystal-rethinkdb
version: 0.1.6
version: 0.1.7

authors:
- Kingsley Hendrickse <[email protected]>

crystal: 0.28.0
crystal: 0.30.0

license: MIT
6 changes: 6 additions & 0 deletions spec/rethinkdb_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ describe RethinkDB do
end
end

it "skip" do
Generators.random_table_with_entries(20, ->(table : String) {
r.table(table).skip(10).run(Fixtures::TestDB.conn).to_a.size.should eq(10)
})
end

it "r#json" do
Generators.random_table do |table|
r.table_create(table).run Fixtures::TestDB.conn
Expand Down
23 changes: 23 additions & 0 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@ module Generators
def self.random_hash(num_keys = 4)
num_keys.times.map { |_| ({self.random_pk, rand(100)}) }.to_h
end

def self.random_table_with_entries(num_entries : Int32, block)
Generators.random_table do |table|
r.table_create(table).run(Fixtures::TestDB.conn)
num_entries.times do
document = {
"id" => Generators.random_pk,
"serial" => Generators.random_pk,
"array" => Generators.random_array,
"object" => Generators.random_hash,
}
response = r.json(document.to_json).do { |value|
r.table(table).insert(value, return_changes: true)
}.run(Fixtures::TestDB.conn)
end
begin
block.call(table)
ensure
r.table_drop(table).run Fixtures::TestDB.conn
end
end
end

end

module Fixtures
Expand Down
4 changes: 4 additions & 0 deletions src/rethinkdb/api-datum.cr
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ module RethinkDB
DatumTerm.new(TermType::REDUCE, [self, Func.arity2 { |a, b| yield(a, b) }])
end

def skip(count)
DatumTerm.new(TermType::SKIP, [self, count])
end

def limit(count)
DatumTerm.new(TermType::LIMIT, [self, count])
end
Expand Down
4 changes: 4 additions & 0 deletions src/rethinkdb/api-grouped.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ module RethinkDB
GroupedStreamTerm.new(TermType::LIMIT, [self, n])
end

def skip(n)
GroupedStreamTerm.new(TermType::SKIP, [self, n])
end

def [](key)
GroupedStreamTerm.new(TermType::BRACKET, [self, key])
end
Expand Down
4 changes: 4 additions & 0 deletions src/rethinkdb/api-stream.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ module RethinkDB
StreamTerm.new(TermType::LIMIT, [self, n])
end

def skip(n)
StreamTerm.new(TermType::SKIP, [self, n])
end

def zip
StreamTerm.new(TermType::ZIP, [self])
end
Expand Down

0 comments on commit 402330f

Please sign in to comment.