Skip to content

Commit eb0e74e

Browse files
authored
RCBC-391: SDK Support for Native KV Range Scans (#113)
1 parent 08a35ed commit eb0e74e

File tree

10 files changed

+1071
-5
lines changed

10 files changed

+1071
-5
lines changed

examples/range_scan.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2023. Couchbase, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
require 'couchbase'
16+
17+
include Couchbase # rubocop:disable Style/MixinUsage for brevity
18+
19+
options = Cluster::ClusterOptions.new
20+
options.authenticate("Administrator", "password")
21+
cluster = Cluster.connect("couchbase://localhost", options)
22+
23+
bucket = cluster.bucket("travel-sample")
24+
collection = bucket.scope("inventory").collection("airline")
25+
26+
options = Options::Scan.new(ids_only: false)
27+
28+
puts "Range Scan (from 'airline_1' to 'airline_11')"
29+
30+
scan_type = RangeScan.new(
31+
from: ScanTerm.new("airline_1"),
32+
to: ScanTerm.new("airline_11", exclusive: true)
33+
)
34+
res = collection.scan(scan_type, options)
35+
36+
res.each do |item|
37+
puts " (#{item.id}) #{item.content['icao']}: #{item.content['name']}"
38+
end
39+
40+
puts "\nPrefix Scan (with prefix 'airline_8')"
41+
42+
scan_type = PrefixScan.new("airline_8")
43+
res = collection.scan(scan_type, options)
44+
45+
res.each do |item|
46+
puts " (#{item.id}) #{item.content['icao']}: #{item.content['name']}"
47+
end
48+
49+
puts "\nSampling Scan (with limit 5)"
50+
51+
scan_type = SamplingScan.new(5)
52+
res = collection.scan(scan_type, options)
53+
54+
res.each do |item|
55+
puts " (#{item.id}) #{item.content['icao']}: #{item.content['name']}"
56+
end

ext/couchbase

0 commit comments

Comments
 (0)