crate_ruby 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72fb2668765dffdf58642563d96e75aa751e8c3c
4
- data.tar.gz: f071d33f570d3108a9a34f4899a3f6ac63666f28
3
+ metadata.gz: 7e341cd1fe4282c3dedd29e547b99d0b21c47dff
4
+ data.tar.gz: 8bab3933fea54fbaa6026c1226d37842a241803a
5
5
  SHA512:
6
- metadata.gz: 95523cb97d5db61f189a383330e0d42e4877a9fb893ee6e6ec1ad11a156fc89a1836de17cba8446f4c18523b94b4b20b5fca8bdb6f40aca2e44a9f0389832a9e
7
- data.tar.gz: 759a5002f9498893ea8c888ee3bcf9974c8e53620b5e3ef78f78b076481505404bec3dc63fd750069cab7c7192856a9b974b27f4f8fb40a5769917b42448e574
6
+ metadata.gz: 4be61df43ff7bfe34d8098523a9096bcb2e6ebdf99913d17834b12a9e372c4ee3a4fc87d772acb052353b87d491a6f6563601b35e0f845346ccdf3bd97bf6b4a
7
+ data.tar.gz: 79e1e90745e375d1aa8c4aaa7600d18ed6c0e44e708ffd2391e9eeaa855f8024fb00682025015553bb1d7b9aa8c53ca0f2cbaa802b0355d6c64440eafcb0f9e8
data/.gitignore CHANGED
@@ -18,4 +18,7 @@ tmp
18
18
  .idea/*
19
19
  .rvmrc
20
20
  log/crate.log
21
- crate_test_server.*
21
+ crate_test_server.*
22
+ parts/
23
+
24
+ .byebug_history
@@ -3,12 +3,12 @@ rvm:
3
3
  - "2.0.0"
4
4
  - "2.1.5"
5
5
  - "2.2.0"
6
+ - "2.4.2"
6
7
  sudo:
7
8
  false
8
-
9
9
  before_script:
10
- - wget https://cdn.crate.io/downloads/releases/crate-0.48.2.tar.gz -O /tmp/crate.tar.gz
11
- - tar -xvf /tmp/crate.tar.gz
12
- - bundle exec ruby spec/test_server.rb $PWD/crate-0.48.2/ true
13
-
14
- script: bundle exec rspec spec
10
+ - bundle exec ruby spec/bootstrap.rb
11
+ script:
12
+ bundle exec rspec spec
13
+ before_install:
14
+ - gem update bundler
@@ -1,93 +1,10 @@
1
- Contributing to Crate Ruby
2
- ==========================
1
+ ============
2
+ Contributing
3
+ ============
3
4
 
4
- Thanks for considering contributing to the Crate Data Ruby library.
5
+ Thank you for your interest in contributing.
5
6
 
7
+ Please see the CrateDB `contribution guide`_ for more information. Everything in
8
+ the CrateDB contribution guide applies to this repository.
6
9
 
7
- Reporting an issue
8
- ------------------
9
-
10
- - Search existing issues before raising a new one.
11
-
12
- - include as much details as possible. This might include:
13
-
14
- - Which OS you're using.
15
-
16
- - Which version you've been running.
17
-
18
- - Logs/Stacktrace of the error that occurred.
19
-
20
- - Steps to reproduce.
21
-
22
-
23
- Pull requests
24
- -------------
25
-
26
- Before we can accept any pull requests to the Crate Data Ruby library
27
- we need you to agree to our CLA_. Once that is done, we suggest to
28
- continue as follows:
29
-
30
- - Add an issue on Github and let us know that you're working on something.
31
-
32
- - Use a feature branch, not master.
33
-
34
- - Rebase your feature branch onto origin/master before raising the PR
35
-
36
- - Be descriptive in your PR and commit messages. What is it for, why is it
37
- needed, etc.
38
-
39
- - Make sure the tests pass.
40
-
41
- - Squash related commits
42
-
43
- .. _CLA: https://crate.io/community/contribute/
44
-
45
-
46
- Rebase
47
- ------
48
-
49
- If while you've been working in the feature branch new commits were added to
50
- the master branch please don't merge them but use rebase::
51
-
52
- git fetch origin
53
- git rebase origin/master
54
-
55
- This will apply all commits on your feature branch on top of the master branch.
56
- Any conflicts can be resolved just the same as if ``git merge`` was used. After
57
- the conflict has been resolved use ``git rebase --continue`` to continue the
58
- rebase process.
59
-
60
-
61
- Squash
62
- ------
63
-
64
- Minor commits that only fix typos or rename variables that are related to a
65
- bigger change should be squashed into that commit.
66
-
67
- This can be done using ``git rebase -i ( <hash> | <branch> )``
68
-
69
- For example while working on a feature branch you'd use::
70
-
71
- git add .
72
- git commit -m "implemented feature XY"
73
-
74
- # push and ask for a merge/review
75
-
76
- git add .
77
- git commit --fixup $(git rev-parse HEAD)
78
-
79
- # push and ask for a merge/review
80
-
81
- git add .
82
- git commit --fixup $(git rev-parse HEAD)
83
-
84
- git rebase -i origin/master
85
-
86
- ``git commit --fixup`` will mark the commit as a fixup relating to the commit
87
- HEAD currently points to.
88
-
89
- This is useful because ``git rebase -i`` will then automatically recognize the
90
- fixup commits and mark them to squash. But in order for that to work the
91
- ``autosquash`` setting has to be enabled in the ``.gitconfig``::
92
-
93
- git config --global rebase.autosquash true
10
+ .. _contribution guide: https://github.com/crate/crate/blob/master/CONTRIBUTING.rst
@@ -0,0 +1,46 @@
1
+ ===============
2
+ Developer Guide
3
+ ===============
4
+
5
+ Tests
6
+ =====
7
+
8
+ First, download and install CrateDB locally::
9
+
10
+ $ ruby spec/bootstrap.rb
11
+
12
+ Then, run tests like so::
13
+
14
+ $ bundle exec rspec spec
15
+
16
+ Preparing a Release
17
+ ===================
18
+
19
+ To create a new release, you must:
20
+
21
+ - Update ``CrateRuby.version`` in ``lib/crate_ruby/version.rb``
22
+
23
+ - Add a section for the new version in the ``history.txt`` file
24
+
25
+ - Commit your changes with a message like "prepare release x.y.z"
26
+
27
+ - Push to origin
28
+
29
+ - Create a tag by running ``./devtools/create_tag.sh``
30
+
31
+ RubyGems Deployment
32
+ ===================
33
+
34
+ Update your package manager::
35
+
36
+ $ gem update --system
37
+
38
+ Build the new gem::
39
+
40
+ $ gem build crate_ruby.gemspec
41
+
42
+ Publish the new gem::
43
+
44
+ $ gem push crate_ruby-<VERISON>.gem
45
+
46
+ Here, ``<VERISON>`` is the version you are releasing.
@@ -0,0 +1,109 @@
1
+ ===================
2
+ CrateDB Ruby Client
3
+ ===================
4
+
5
+ .. image:: https://badge.fury.io/rb/crate_ruby.svg
6
+ :target: http://badge.fury.io/rb/crate_ruby
7
+ :alt: Gem Version
8
+
9
+ .. image:: https://travis-ci.org/crate/crate_ruby.svg?branch=master
10
+ :target: https://travis-ci.org/crate/crate_ruby
11
+ :alt: Build Status
12
+
13
+ .. image:: https://codeclimate.com/github/crate/crate_ruby.png
14
+ :target: https://codeclimate.com/github/crate/crate_ruby
15
+ :alt: Code Climate
16
+
17
+ |
18
+
19
+ A Ruby client library for CrateDB_.
20
+
21
+ Prerequisites
22
+ =============
23
+
24
+ You will need Ruby 2.0 or greater.
25
+
26
+ Installation
27
+ ============
28
+
29
+ The CrateDB Ruby client is available as a Ruby gem_.
30
+
31
+ Add this line to your application's ``Gemfile``::
32
+
33
+ gem 'crate_ruby'
34
+
35
+ Or, install it manually, like so::
36
+
37
+ $ gem install crate_ruby
38
+
39
+ Examples
40
+ ========
41
+
42
+ Set up the client like so::
43
+
44
+ require 'crate_ruby'
45
+
46
+ client = CrateRuby::Client.new
47
+
48
+ Execute SQL queries like so::
49
+
50
+ result = client.execute("Select * from posts")
51
+ => #<CrateRuby::ResultSet:0x00000002a9c5e8 @rowcount=1, @duration=5>
52
+
53
+ result.each do |row|
54
+ puts row.inspect
55
+ end
56
+ => [1, "test", 5]
57
+
58
+ result.cols
59
+ => ["id", "my_column", "my_integer_col"]
60
+
61
+
62
+ Perform parameter substitution like so::
63
+
64
+ client.execute(
65
+ "INSERT INTO posts (id, title, tags) VALUES (\$1, \$2, \$3)",
66
+ [1, "My life with crate", ['awesome', 'cool']])
67
+
68
+ Manipulate BLOBs like so::
69
+
70
+ digest = Digest::SHA1.file(file_path).hexdigest
71
+
72
+ # upload
73
+ f = File.read(file_path)
74
+ client.blob_put(table_name, digest, f)
75
+
76
+ # download
77
+ data = client.blob_get(table_name, digest)
78
+ open(file_path, "wb") do |file|
79
+ file.write(data)
80
+ end
81
+
82
+ # deletion
83
+ client.blob_delete(table_name, digest)
84
+
85
+ Contributing
86
+ ============
87
+
88
+ This project is primarily maintained by Crate.io_, but we welcome community
89
+ contributions!
90
+
91
+ See the `developer docs`_ and the `contribution docs`_ for more information.
92
+
93
+ Help
94
+ ====
95
+
96
+ Looking for more help?
97
+
98
+ - Check `StackOverflow`_ for common problems
99
+ - Chat with us on `Slack`_
100
+ - Get `paid support`_
101
+
102
+ .. _contribution docs: CONTRIBUTING.rst
103
+ .. _Crate.io: https://crate.io
104
+ .. _CrateDB: https://github.com/crate/crate
105
+ .. _developer docs: DEVELOP.rst
106
+ .. _gem: https://rubygems.org/
107
+ .. _paid support: https://crate.io/pricing/
108
+ .. _Slack: https://crate.io/docs/support/slackin/
109
+ .. _StackOverflow: https://stackoverflow.com/tags/crate
@@ -28,8 +28,8 @@ Gem::Specification.new do |spec|
28
28
  spec.version = CrateRuby::VERSION
29
29
  spec.authors = ["Christoph Klocker", "CRATE Technology GmbH"]
30
30
  spec.email = ["office@crate.io"]
31
- spec.summary = "A simple interface for the Crate database"
32
- spec.description = "A Ruby interface for Crate, the distributed database for Docker."
31
+ spec.summary = "A simple interface for the Crate.IO database."
32
+ spec.description = "A Ruby interface for Crate.IO. Put your data to work. Simply."
33
33
  spec.homepage = "http://crate.io"
34
34
  spec.license = "Apache License, v2.0"
35
35
  spec.required_ruby_version = '>= 2.0'
@@ -39,7 +39,6 @@ Gem::Specification.new do |spec|
39
39
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
40
40
  spec.require_paths = ["lib"]
41
41
 
42
- spec.add_development_dependency "bundler", "~> 1.5"
43
42
  spec.add_development_dependency "rake"
44
- spec.add_development_dependency "rspec", "~> 2.14"
43
+ spec.add_development_dependency "rspec", "~> 2.99"
45
44
  end
@@ -0,0 +1,77 @@
1
+ #!/bin/bash
2
+ #
3
+ # Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
4
+ # license agreements. See the NOTICE file distributed with this work for
5
+ # additional information regarding copyright ownership. Crate licenses
6
+ # this file to you under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License. You may
8
+ # obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ # License for the specific language governing permissions and limitations
16
+ # under the License.
17
+ #
18
+ # However, if you have executed another commercial license agreement
19
+ # with Crate these terms will supersede the license and you may use the
20
+ # software solely pursuant to the terms of the relevant commercial agreement.
21
+
22
+ # check if everything is committed
23
+ CLEAN=`git status -s`
24
+ if [ ! -z "$CLEAN" ]
25
+ then
26
+ echo "Working directory not clean. Please commit all changes before tagging"
27
+ echo "Aborting."
28
+ exit -1
29
+ fi
30
+
31
+ echo "Fetching origin..."
32
+ git fetch origin > /dev/null
33
+
34
+ # get current branch
35
+ BRANCH=`git branch | grep "^*" | cut -d " " -f 2`
36
+ echo "Current branch is $BRANCH."
37
+
38
+ # check if master == origin/master
39
+ LOCAL_COMMIT=`git show --format="%H" $BRANCH`
40
+ ORIGIN_COMMIT=`git show --format="%H" origin/$BRANCH`
41
+
42
+ if [ "$LOCAL_COMMIT" != "$ORIGIN_COMMIT" ]
43
+ then
44
+ echo "Local $BRANCH is not up to date. "
45
+ echo "Aborting."
46
+ exit -1
47
+ fi
48
+
49
+ # get version from version.rb
50
+ VERSION=$(grep "VERSION =" lib/crate_ruby/version.rb | \
51
+ cut -d' ' -f5 | tr -d "\'")
52
+ echo "Version: $VERSION"
53
+
54
+ # check if tag to create has already been created
55
+ EXISTS=`git tag | grep $VERSION`
56
+
57
+ if [ "$VERSION" == "$EXISTS" ]
58
+ then
59
+ echo "Revision $VERSION already tagged."
60
+ echo "Aborting."
61
+ exit -1
62
+ fi
63
+
64
+ # check if VERSION is in head of CHANGES.txt
65
+ REV_NOTE=`grep "=== $VERSION" history.txt`
66
+ if [ -z "$REV_NOTE" ]
67
+ then
68
+ echo "No notes for revision $VERSION found in history.txt"
69
+ echo "Aborting."
70
+ exit -1
71
+ fi
72
+
73
+ echo "Creating tag $VERSION..."
74
+ git tag -a "$VERSION" -m "Tag release for revision $VERSION"
75
+ git push --tags
76
+ echo "Done."
77
+
@@ -1,13 +1,16 @@
1
1
  # coding: UTF-8
2
2
 
3
- === unreleased
4
-
5
- === 0.0.8
3
+ === 0.0.9
6
4
 
5
+ * fixed breaking changes that kept driver from working with crate > v2.0
7
6
  * removed ruby 1.9.3 from travis.yml
8
7
  * client now supports HTTP options
9
8
  * update travis.yml and fix broken test
10
9
 
10
+ === 0.0.8
11
+
12
+ * undocumented gem release
13
+
11
14
  === 0.0.7
12
15
 
13
16
  * use prepared statements for insert
@@ -23,14 +23,16 @@ require "crate_ruby/version"
23
23
  require "crate_ruby/error"
24
24
  require 'crate_ruby/result_set'
25
25
  require 'crate_ruby/client'
26
+ require 'crate_ruby/utils'
26
27
 
27
28
  include CrateRuby
28
29
 
29
30
  module CrateRuby
31
+
30
32
  def self.logger
31
33
  @logger ||= begin
32
34
  require 'logger'
33
- log = Logger.new(File.join(File.dirname(__FILE__), "../log/crate.log"), 10, 1024000)
35
+ log = Logger.new(STDERR)
34
36
  log.level = Logger::INFO
35
37
  log
36
38
  end
@@ -40,4 +42,4 @@ module CrateRuby
40
42
  @logger = logger
41
43
  end
42
44
 
43
- end
45
+ end
@@ -83,13 +83,13 @@ module CrateRuby
83
83
  # List all user tables
84
84
  # @return [ResultSet]
85
85
  def show_tables
86
- execute("select table_name from information_schema.tables where schema_name = 'doc'")
86
+ execute("select table_name from information_schema.tables where table_schema = 'doc'")
87
87
  end
88
88
 
89
89
  # Returns all tables in schema 'doc'
90
90
  # @return [Array] Array of table names
91
91
  def tables
92
- execute("select table_name from information_schema.tables where schema_name = 'doc'").map(&:first)
92
+ execute("select table_name from information_schema.tables where table_schema = 'doc'").map(&:first)
93
93
  end
94
94
 
95
95
  # Executes a SQL statement against the Crate HTTP REST endpoint.
@@ -97,11 +97,12 @@ module CrateRuby
97
97
  # @param [Array] args Array of values used for parameter substitution
98
98
  # @param [Hash] Net::HTTP options (open_timeout, read_timeout)
99
99
  # @return [ResultSet]
100
- def execute(sql, args = nil, http_options = {})
100
+ def execute(sql, args = nil, bulk_args = nil, http_options = {})
101
101
  @logger.debug sql
102
102
  req = Net::HTTP::Post.new("/_sql", initheader = {'Content-Type' => 'application/json'})
103
103
  body = {"stmt" => sql}
104
- body.merge!({'args' => args}) if args
104
+ body.merge!({'args' => args}) if args
105
+ body.merge!({'bulk_args' => bulk_args}) if bulk_args
105
106
  req.body = body.to_json
106
107
  response = request(req, http_options)
107
108
  @logger.debug response.body
@@ -179,7 +180,7 @@ module CrateRuby
179
180
  # @param [String] table_name Table name to get structure
180
181
  # @param [ResultSet]
181
182
  def table_structure(table_name)
182
- execute("select * from information_schema.columns where schema_name = 'doc' AND table_name = '#{table_name}'")
183
+ execute("select * from information_schema.columns where table_schema = 'doc' AND table_name = '#{table_name}'")
183
184
  end
184
185
 
185
186
 
@@ -0,0 +1,117 @@
1
+ # -*- coding: utf-8; -*-
2
+ #
3
+ # Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
4
+ # license agreements. See the NOTICE file distributed with this work for
5
+ # additional information regarding copyright ownership. Crate licenses
6
+ # this file to you under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License. You may
8
+ # obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ # License for the specific language governing permissions and limitations
16
+ # under the License.
17
+ #
18
+ # However, if you have executed another commercial license agreement
19
+ # with Crate these terms will supersede the license and you may use the
20
+ # software solely pursuant to the terms of the relevant commercial agreement.
21
+
22
+ require 'net/http'
23
+
24
+ module CrateRuby
25
+
26
+ class TestCluster
27
+
28
+ def initialize(num_nodes = 1, http_port=44200)
29
+ @nodes = []
30
+ idx = 0
31
+ while idx < num_nodes do
32
+ name = "crate#{idx-1}"
33
+ port = http_port + idx
34
+ @nodes << TestServer.new(name, port)
35
+ idx += 1
36
+ end
37
+ end
38
+
39
+ def start_nodes
40
+ @nodes.each do |node|
41
+ node.start
42
+ end
43
+ end
44
+
45
+ def stop_nodes
46
+ @nodes.each do |node|
47
+ node.stop
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ class TestServer
54
+
55
+ STARTUP_TIMEOUT = 30
56
+
57
+ def initialize(name, http_port)
58
+ @node_name = name
59
+ @http_port = http_port
60
+
61
+ @crate_bin = File.join('parts', 'crate', 'bin', 'crate')
62
+ if !File.file?(@crate_bin)
63
+ puts "Crate is not available. Please run 'bundle exec ruby spec/bootstrap.rb' first."
64
+ exit 1
65
+ end
66
+ end
67
+
68
+ def start
69
+ cmd = "sh #{@crate_bin} #{start_params}"
70
+ @pid = spawn(cmd)
71
+ wait_for
72
+ Process.detach(@pid)
73
+ end
74
+
75
+ def wait_for
76
+ time_slept = 0
77
+ interval = 1
78
+ while true
79
+ if !alive? and time_slept > STARTUP_TIMEOUT
80
+ puts "Crate hasn't started for #{STARTUP_TIMEOUT} seconds. Giving up now..."
81
+ exit 1
82
+ end
83
+ if alive?
84
+ break
85
+ else
86
+ sleep(interval)
87
+ time_slept += interval
88
+ end
89
+ end
90
+ end
91
+
92
+ def stop
93
+ Process.kill('HUP', @pid)
94
+ end
95
+
96
+ private
97
+
98
+ def start_params
99
+ "-Cnode.name=#{@node_name} " +
100
+ "-Chttp.port=#{@http_port} " +
101
+ "-Cnetwork.host=localhost "
102
+ end
103
+
104
+ def alive?
105
+ req = Net::HTTP::Get.new('/')
106
+ resp = Net::HTTP.new('localhost', @http_port)
107
+ begin
108
+ response = resp.start { |http| http.request(req) }
109
+ response.code == "200" ? true : false
110
+ rescue Errno::ECONNREFUSED
111
+ false
112
+ end
113
+ end
114
+ end
115
+
116
+ end
117
+
@@ -20,5 +20,5 @@
20
20
  # software solely pursuant to the terms of the relevant commercial agreement.
21
21
 
22
22
  module CrateRuby
23
- VERSION = "0.0.8"
23
+ VERSION = '0.0.9'
24
24
  end
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8; -*-
3
+ #
4
+ # Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
5
+ # license agreements. See the NOTICE file distributed with this work for
6
+ # additional information regarding copyright ownership. Crate licenses
7
+ # this file to you under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License. You may
9
+ # obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
+ # License for the specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+ # However, if you have executed another commercial license agreement
20
+ # with Crate these terms will supersede the license and you may use the
21
+ # software solely pursuant to the terms of the relevant commercial agreement.
22
+
23
+ require 'rubygems/package'
24
+ require 'net/http'
25
+ require 'zlib'
26
+
27
+ class Bootstrap
28
+
29
+ VERSION = '2.1.8'
30
+
31
+ def initialize
32
+ @fname = "crate-#{VERSION}.tar.gz"
33
+ @crate_bin = File.join('parts', 'crate' 'bin', 'crate')
34
+ end
35
+
36
+ def run
37
+ if !File.file?(@crate_bin)
38
+ if !File.file?(@fname)
39
+ download
40
+ end
41
+ extract
42
+ end
43
+ end
44
+
45
+ def download
46
+ uri = URI("https://cdn.crate.io/downloads/releases/#{@fname}")
47
+ puts "Downloading Crate from #{uri} ..."
48
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
49
+ request = Net::HTTP::Get.new uri
50
+ resp = http.request request
51
+ open(@fname, "wb") do |file|
52
+ file.write(resp.body)
53
+ end
54
+ end
55
+ end
56
+
57
+ def extract
58
+ tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(@fname))
59
+ tar_extract.rewind # The extract has to be rewinded after every iteration
60
+ tar_extract.each do |entry|
61
+ dest_file = File.join 'parts', entry.full_name.gsub(/^(crate)(\-\d+\.\d+\.\d+)(.*)/, '\1\3')
62
+ puts dest_file
63
+ if entry.directory?
64
+ FileUtils.mkdir_p dest_file
65
+ else
66
+ dest_dir = File.dirname(dest_file)
67
+ FileUtils.mkdir_p dest_dir unless File.directory?(dest_dir)
68
+ File.open dest_file, "wb" do |f|
69
+ f.print entry.read
70
+ end
71
+ end
72
+ end
73
+ tar_extract.close
74
+ end
75
+ end
76
+
77
+ bootstrap = Bootstrap.new(*ARGV)
78
+ bootstrap.run()
79
+
@@ -20,13 +20,21 @@
20
20
  # software solely pursuant to the terms of the relevant commercial agreement.
21
21
 
22
22
  require_relative '../spec_helper'
23
+ require 'securerandom'
23
24
 
24
25
  describe CrateRuby::Client do
25
- TABLE_NAME = 'blob_table'
26
- CRATE_HOST = "localhost:44200"
26
+ let(:client) { CrateRuby::Client.new(['localhost:44200']) }
27
+
28
+ before(:all) do
29
+ @cluster = CrateRuby::TestCluster.new(1)
30
+ @cluster.start_nodes
31
+ end
32
+
33
+ after(:all) do
34
+ @cluster.stop_nodes
35
+ end
27
36
 
28
37
  describe '#create_table' do
29
- let(:client) { CrateRuby::Client.new([CRATE_HOST]) }
30
38
 
31
39
  describe 'blob management' do
32
40
  let(:file) { 'logo-crate.png' }
@@ -35,110 +43,106 @@ describe CrateRuby::Client do
35
43
  let(:digest) { Digest::SHA1.file(file_path).hexdigest }
36
44
  let(:store_location) { File.join(path, "get_#{file}") }
37
45
 
38
- before(:all) do
39
- CrateRuby::Client.new([CRATE_HOST]).execute("create blob TABLE #{TABLE_NAME}")
46
+ before do
47
+ @blob_table = 'my_blobs'
48
+ client.execute("create blob table #{@blob_table} clustered into 1 shards with (number_of_replicas=0)")
40
49
  end
41
50
 
42
- after(:all) do
43
- CrateRuby::Client.new([CRATE_HOST]).execute("drop blob TABLE #{TABLE_NAME}")
51
+ after do
52
+ client.execute("drop blob table #{@blob_table}")
44
53
  end
45
54
 
46
55
  describe '#blob_put' do
47
-
48
- after do
49
- client.blob_delete(TABLE_NAME, digest)
50
- end
51
-
52
56
  context 'file' do
53
-
54
57
  it 'should upload a file to the blob table' do
55
58
  f = File.read(file_path)
56
- client.blob_put(TABLE_NAME, digest, f).should be_truthy
59
+ client.blob_put(@blob_table, digest, f).should be_truthy
57
60
  end
58
61
  end
59
-
60
62
  context '#string' do
61
63
  let(:string) { "my crazy" }
62
64
  let(:digest) { Digest::SHA1.hexdigest(string) }
63
-
64
65
  it 'should upload a string to the blob table' do
65
- client.blob_delete(TABLE_NAME, digest)
66
- client.blob_put TABLE_NAME, digest, string
66
+ client.blob_put(@blob_table, digest, string).should be_truthy
67
67
  end
68
68
  end
69
69
  end
70
70
 
71
71
  describe '#blob_get' do
72
-
73
72
  before do
74
73
  f = File.read(file_path)
75
- client.blob_put(TABLE_NAME, digest, f)
74
+ client.blob_put(@blob_table, digest, f)
76
75
  end
77
-
78
76
  it 'should download a blob' do
79
- data = client.blob_get(TABLE_NAME, digest)
77
+ data = client.blob_get(@blob_table, digest)
80
78
  data.should_not be_falsey
81
79
  open(store_location, "wb") { |file|
82
80
  file.write(data)
83
81
  }
84
82
  end
85
-
86
- after do
87
- client.blob_delete(TABLE_NAME, digest)
88
- end
89
83
  end
90
84
 
91
85
  describe '#blob_delete' do
92
86
  before do
93
87
  f = File.read(file_path)
94
- client.blob_put(TABLE_NAME, digest, f)
88
+ client.blob_put(@blob_table, digest, f)
95
89
  end
96
-
97
90
  it 'should delete a blob' do
98
- client.blob_delete(TABLE_NAME, digest)
91
+ client.blob_delete(@blob_table, digest)
99
92
  end
100
93
  end
101
94
  end
102
95
 
96
+
103
97
  describe '#execute' do
104
- let(:table_name) { "post" }
98
+ let(:table_name) { "t_test" }
105
99
 
106
- after do
107
- client.execute("drop TABLE #{table_name}").should be_truthy
100
+ before do
101
+ client.execute("create table #{table_name} (id integer primary key, name string, address object, tags array(string)) ")
108
102
  end
109
103
 
110
- it 'should create a new table' do
111
- client.execute("CREATE TABLE #{table_name} (id int)").should be_truthy
104
+ after do
105
+ client.execute("drop table #{table_name}")
112
106
  end
113
107
 
114
- it 'should allow parameter substitution' do
115
- client.execute("CREATE TABLE #{table_name} (id int, title string, tags array(string) )").should be_truthy
116
- client.execute("INSERT INTO #{table_name} (id, title, tags) VALUES (\$1, \$2, \$3)",
117
- [1, "My life with crate", ['awesome', 'freaky']]).should be_truthy
108
+ it 'should allow parameters' do
109
+ client.execute("insert into #{table_name} (id, name, address, tags) VALUES (?, ?, ?, ?)",
110
+ [1, "Post 1", {:street=>'1010 W 2nd Ave', :city=>'Vancouver'}, ['awesome', 'freaky']]).should be_truthy
111
+ client.refresh_table table_name
112
+ client.execute("select * from #{table_name}").rowcount.should eq(1)
118
113
  end
119
114
 
120
- it 'should create an object' do
121
- client.execute("CREATE TABLE #{table_name} (id STRING PRIMARY KEY, name string, address object) ")
122
- client.execute(%Q{INSERT INTO #{table_name} (address, id, name) VALUES ({street='1010 W 2nd Ave',city='Vancouver'}, 'fb7183ac-d049-462c-85a9-732aca59a1c1', 'Mad Max')})
115
+ it 'should allow bulk parameters' do
116
+ bulk_args = [
117
+ [1, "Post 1", {:street=>'1010 W 2nd Ave', :city=>'New York'}, ['foo','bar']],
118
+ [2, "Post 2", {:street=>'1010 W 2nd Ave', :city=>'San Fran'}, []]
119
+ ]
120
+ client.execute("insert into #{table_name} (id, name, address, tags) VALUES (?, ?, ?, ?)", nil, bulk_args).should be_truthy
123
121
  client.refresh_table table_name
124
- client.execute(%Q{select * from #{table_name}})
122
+ client.execute("select * from #{table_name}").rowcount.should eq(2)
123
+ client.execute("select count(*) from #{table_name}")[0][0].should eq(2)
125
124
  end
126
125
 
127
126
  it 'should accept http options' do
128
- client.execute("CREATE TABLE #{table_name} (id STRING PRIMARY KEY, name string, address object) ")
129
- client.execute(%Q{INSERT INTO #{table_name} (address, id, name) VALUES ({street='1010 W 2nd Ave',city='Vancouver'}, 'fb7183ac-d049-462c-85a9-732aca59a1c1', 'Mad Max')})
130
- client.refresh_table table_name
131
- expect { client.execute("SELECT * FROM #{table_name}", nil, {read_timeout: 0}) }.to raise_error Net::ReadTimeout
127
+ expect { client.execute("select * from #{table_name}", nil, nil, {'read_timeout'=>0}) }.to raise_error Net::ReadTimeout
132
128
  end
133
129
  end
134
130
 
135
131
 
136
132
  describe '#initialize' do
137
-
138
133
  it 'should use host and ports parameters' do
139
134
  logger = double()
140
- client = CrateRuby::Client.new ["10.0.0.1:5000"], logger: logger
141
- client.instance_variable_get(:@servers).should eq(["10.0.0.1:5000"])
135
+ client = CrateRuby::Client.new ["10.0.0.1:4200"], logger: logger
136
+ client.instance_variable_get(:@servers).should eq(["10.0.0.1:4200"])
137
+ end
138
+ it 'should use default request parameters' do
139
+ client = CrateRuby::Client.new
140
+ client.instance_variable_get(:@http_options).should eq({:read_timeout=>3600})
141
+ end
142
+ it 'should use request parameters' do
143
+ client = CrateRuby::Client.new ['10.0.0.1:4200'],
144
+ http_options: {:read_timeout=>60}
145
+ client.instance_variable_get(:@http_options).should eq({:read_timeout=>60})
142
146
  end
143
147
  end
144
148
 
@@ -155,7 +159,7 @@ describe CrateRuby::Client do
155
159
  end
156
160
 
157
161
  it 'should return all user tables as an array of string values' do
158
- client.tables.should eq ['posts', 'comments']
162
+ client.tables.should eq %w(comments posts)
159
163
  end
160
164
  end
161
165
 
@@ -163,8 +167,8 @@ describe CrateRuby::Client do
163
167
  describe '#insert' do
164
168
  before do
165
169
  client.create_table("posts", id: [:string, "primary key"],
166
- title: :string,
167
- views: :integer)
170
+ title: :string,
171
+ views: :integer)
168
172
  end
169
173
 
170
174
  after do
@@ -21,3 +21,4 @@
21
21
 
22
22
  require_relative '../lib/crate_ruby'
23
23
  require 'net/http'
24
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crate_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Klocker
@@ -9,22 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-28 00:00:00.000000000 Z
12
+ date: 2017-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: bundler
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '1.5'
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '1.5'
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: rake
30
16
  requirement: !ruby/object:Gem::Requirement
@@ -45,15 +31,15 @@ dependencies:
45
31
  requirements:
46
32
  - - "~>"
47
33
  - !ruby/object:Gem::Version
48
- version: '2.14'
34
+ version: '2.99'
49
35
  type: :development
50
36
  prerelease: false
51
37
  version_requirements: !ruby/object:Gem::Requirement
52
38
  requirements:
53
39
  - - "~>"
54
40
  - !ruby/object:Gem::Version
55
- version: '2.14'
56
- description: A Ruby interface for Crate, the distributed database for Docker.
41
+ version: '2.99'
42
+ description: A Ruby interface for Crate.IO. Put your data to work. Simply.
57
43
  email:
58
44
  - office@crate.io
59
45
  executables: []
@@ -63,24 +49,26 @@ files:
63
49
  - ".gitignore"
64
50
  - ".travis.yml"
65
51
  - CONTRIBUTING.rst
66
- - DEVELOP.md
52
+ - DEVELOP.rst
67
53
  - Gemfile
68
54
  - LICENSE
69
55
  - NOTICE
70
- - README.md
56
+ - README.rst
71
57
  - Rakefile
72
58
  - crate_ruby.gemspec
59
+ - devtools/create_tag.sh
73
60
  - history.txt
74
61
  - lib/crate_ruby.rb
75
62
  - lib/crate_ruby/client.rb
76
63
  - lib/crate_ruby/error.rb
77
64
  - lib/crate_ruby/result_set.rb
65
+ - lib/crate_ruby/utils.rb
78
66
  - lib/crate_ruby/version.rb
79
67
  - log/.keep
68
+ - spec/bootstrap.rb
80
69
  - spec/crate_ruby/client_spec.rb
81
70
  - spec/crate_ruby/result_set_spec.rb
82
71
  - spec/spec_helper.rb
83
- - spec/test_server.rb
84
72
  - spec/uploads/get_logo-crate.png
85
73
  - spec/uploads/logo-crate.png
86
74
  - spec/uploads/text.txt
@@ -104,15 +92,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
92
  version: '0'
105
93
  requirements: []
106
94
  rubyforge_project:
107
- rubygems_version: 2.4.6
95
+ rubygems_version: 2.6.14
108
96
  signing_key:
109
97
  specification_version: 4
110
- summary: A simple interface for the Crate database
98
+ summary: A simple interface for the Crate.IO database.
111
99
  test_files:
100
+ - spec/bootstrap.rb
112
101
  - spec/crate_ruby/client_spec.rb
113
102
  - spec/crate_ruby/result_set_spec.rb
114
103
  - spec/spec_helper.rb
115
- - spec/test_server.rb
116
104
  - spec/uploads/get_logo-crate.png
117
105
  - spec/uploads/logo-crate.png
118
106
  - spec/uploads/text.txt
data/DEVELOP.md DELETED
@@ -1,13 +0,0 @@
1
- # Release Process
2
-
3
- Business as usual, but in case you forgot, here it is.
4
-
5
- * update ``CrateRuby.version`` in ``lib/crate_ruby/version.rb``
6
- * update history.txt to reflect the changes of this release
7
- * Do the traditional trinity of:
8
-
9
- ```ruby
10
- gem update --system
11
- gem build crate_ruby.gemspec
12
- gem push crate_ruby-<version>.gem
13
- ```
data/README.md DELETED
@@ -1,85 +0,0 @@
1
- [![Gem Version](https://badge.fury.io/rb/crate_ruby.svg)](http://badge.fury.io/rb/crate_ruby)
2
- [![Build Status](https://travis-ci.org/crate/crate_ruby.svg?branch=master)](https://travis-ci.org/crate/crate_ruby)
3
- [![Code Climate](https://codeclimate.com/github/crate/crate_ruby.png)](https://codeclimate.com/github/crate/crate_ruby)
4
-
5
-
6
- # CrateRuby
7
-
8
- Official Ruby library to access a [Crate](http://crate.io) database.
9
-
10
- ## Installation
11
-
12
- This gem requires Ruby 2.0 or greater.
13
-
14
- Add this line to your application's Gemfile:
15
-
16
- gem 'crate_ruby'
17
-
18
- Or install it yourself as:
19
-
20
- $ gem install crate_ruby
21
-
22
- ## Usage
23
-
24
- ### Issueing SQL statements
25
- require 'crate_ruby'
26
-
27
- client = CrateRuby::Client.new
28
-
29
- result = client.execute("Select * from posts")
30
- => #<CrateRuby::ResultSet:0x00000002a9c5e8 @rowcount=1, @duration=5>
31
-
32
- result.each do |row|
33
- puts row.inspect
34
- end
35
- => [1, "test", 5]
36
-
37
- result.cols
38
- => ["id", "my_column", "my_integer_col"]
39
-
40
-
41
- #### Using parameter substitution
42
-
43
- client.execute("INSERT INTO posts (id, title, tags) VALUES (\$1, \$2, \$3)",
44
- [1, "My life with crate", ['awesome', 'freaky']])
45
-
46
- ### Up/Downloading data
47
-
48
- digest = Digest::SHA1.file(file_path).hexdigest
49
-
50
- # upload
51
- f = File.read(file_path)
52
- client.blob_put(table_name, digest, f)
53
-
54
- # download
55
- data = client.blob_get(table_name, digest)
56
- open(file_path, "wb") do |file|
57
- file.write(data)
58
- end
59
-
60
- # deletion
61
- client.blob_delete(table_name, digest)
62
-
63
- ## Tests
64
-
65
- Start up the crate server before running the tests
66
-
67
- ruby spec/test_server.rb /path/to/crate
68
-
69
- Then run tests with
70
-
71
- bundle exec rspec spec
72
-
73
- ## Contributing
74
-
75
- If you think something is missing, either create a pull request
76
- or log a new issue, so someone else can tackle it.
77
- Please refer to CONTRIBUTING.rst for further information.
78
-
79
- ##Maintainer
80
-
81
- * [CRATE Technology GmbH](http://crate.io)
82
- * [Christoph Klocker](http://www.vedanova.com), [@corck](http://www.twitter.com/corck)
83
-
84
- ##License & Copyright
85
- See LICENSE for details.
@@ -1,81 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8; -*-
3
- #
4
- # Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
5
- # license agreements. See the NOTICE file distributed with this work for
6
- # additional information regarding copyright ownership. Crate licenses
7
- # this file to you under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License. You may
9
- # obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
- # License for the specific language governing permissions and limitations
17
- # under the License.
18
- #
19
- # However, if you have executed another commercial license agreement
20
- # with Crate these terms will supersede the license and you may use the
21
- # software solely pursuant to the terms of the relevant commercial agreement.
22
-
23
- require 'net/http'
24
-
25
- class TestServer
26
- NAME = "TestCluster"
27
- HOST = "127.0.0.1"
28
- PORT = 44200
29
- TIMEOUT = 30
30
-
31
- def initialize(crate_home = '~/crate', run_in_background = false)
32
- @crate_home = crate_home
33
- @run_in_background = run_in_background
34
- end
35
-
36
- def start
37
- cmd = "sh #{File.join(@crate_home, 'bin', 'crate')} #{start_params}"
38
- @pid = spawn(cmd, out: "/tmp/crate_test_server.out",
39
- err: "/tmp/crate_test_server.err")
40
- Process.detach(@pid)
41
- puts 'Starting Crate... (this will take a few seconds)'
42
- time_slept = 0
43
- interval = 2
44
- while true
45
- if !alive? and time_slept > TIMEOUT
46
- puts "Crate hasn't started for #{TIMEOUT} seconds. Giving up now..."
47
- exit
48
- end
49
- if alive? and @run_in_background
50
- exit
51
- end
52
- sleep(interval)
53
- time_slept += interval
54
- end
55
- end
56
-
57
- private
58
-
59
- def start_params
60
- "-Des.index.storage.type=memory " +
61
- "-Des.node.name=#{NAME} " +
62
- "-Des.cluster.name=Testing#{PORT} " +
63
- "-Des.http.port=#{PORT}-#{PORT} " +
64
- "-Des.network.host=localhost " +
65
- "-Des.discovery.zen.ping.multicast.enabled=false"
66
- end
67
-
68
- def alive?
69
- req = Net::HTTP::Get.new('/')
70
- resp = Net::HTTP.new(HOST, PORT)
71
- begin
72
- response = resp.start { |http| http.request(req) }
73
- response.code == "200" ? true : false
74
- rescue Errno::ECONNREFUSED
75
- false
76
- end
77
- end
78
- end
79
-
80
- server = TestServer.new(*ARGV)
81
- server.start