relaxo 1.5.0 → 1.6.0

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
  SHA256:
3
- metadata.gz: b71fd8263f890a77bf20e18e6e3258edeee8954076452914cb35698a7827723b
4
- data.tar.gz: e502abf00e610646d5866868b23c931330b919ab5e3ab280128f82d070765c11
3
+ metadata.gz: ae1194ada958c694f278dd6340b8c910bf79e79f66735fb5e1f8c6acc7e8417a
4
+ data.tar.gz: fee89902ec4e5dc0a77c0642b47cc997d13a90f30f7ad51bf008f765aeccdeef
5
5
  SHA512:
6
- metadata.gz: 41ec8840e1a72cfa879045f2f22b7cf10e165d9e47e7f4cad72005785f0be3b3b6c6229f2c210888637903497ad74289f1fea8f72646f2ece2119537837da16f
7
- data.tar.gz: 69b6c7b790da0585527339c3b4ea593cd8da13c08ef751af82e83b0fa2af911015a4013a362479a4c2bc60f09d0ad4e992bcafa776463e783f423a56534943ac
6
+ metadata.gz: 8280b8de30982f10ac8753cf49a3e4e2149b82b387037a8038173f9f1c29e6aa1e61d417fb22789615db5b8907c16da25194c8073cf3e5e811ecb2b8764bb441
7
+ data.tar.gz: ed739652d8c5b8cd5e04b10f122faa426af7a8f9e7bf7d0e90643664c7677f52e96444e257b1611830e291de95fd2eb8395d5c4931546f8a8824c9fbd0af064f
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -28,11 +28,12 @@ module Relaxo
28
28
  HEAD = 'HEAD'.freeze
29
29
 
30
30
  class Database
31
- def initialize(path, branch, metadata = {})
31
+ def initialize(path, branch, metadata = {}, fsync: true)
32
32
  @path = path
33
33
  @metadata = metadata
34
34
 
35
35
  @repository = Rugged::Repository.new(path)
36
+ @repository.config['core.fsyncObjectFiles'] = fsync
36
37
 
37
38
  @branch = branch
38
39
  end
@@ -56,6 +57,10 @@ module Relaxo
56
57
  @repository.empty?
57
58
  end
58
59
 
60
+ def head
61
+ @repository.branches[@branch]
62
+ end
63
+
59
64
  def [] key
60
65
  @metadata[key]
61
66
  end
@@ -129,7 +134,7 @@ module Relaxo
129
134
  end_time = Time.now
130
135
  elapsed_time = end_time - start_time
131
136
 
132
- Relaxo.logger.debug("time") {"#{message.inspect}: %0.3fs" % elapsed_time}
137
+ Relaxo.logger.debug(self) {"#{message.inspect}: %0.3fs" % elapsed_time}
133
138
  end
134
139
 
135
140
  def apply(parent, changeset, **options)
@@ -147,7 +152,7 @@ module Relaxo
147
152
  end
148
153
 
149
154
  def latest_commit
150
- if head = @repository.branches[@branch]
155
+ if head = self.head
151
156
  return head.target, head.target.tree
152
157
  else
153
158
  return nil, empty_tree
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Relaxo
22
- VERSION = "1.5.0"
22
+ VERSION = "1.6.0"
23
23
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaxo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-09 00:00:00.000000000 Z
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rugged
14
+ name: console
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: console
28
+ name: rugged
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: covered
42
+ name: bake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,35 +53,63 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: bake-bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '3.6'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '3.6'
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bake-modernize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: '1.3'
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: covered
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
81
102
  - !ruby/object:Gem::Version
82
- version: '1.3'
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
- name: rake
112
+ name: msgpack
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
115
  - - ">="
@@ -94,25 +122,26 @@ dependencies:
94
122
  - - ">="
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
97
- description: "\t\tRelaxo provides a set of tools and interfaces for interacting with
98
- CouchDB.\n\t\tIt aims to be as simple and efficient as possible while still improving
99
- the\n\t\tusability of various CouchDB features.\n"
100
- email:
101
- - samuel.williams@oriontransfer.co.nz
102
- executables:
103
- - relaxo
104
- - relaxo-admin
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.6'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.6'
139
+ description:
140
+ email:
141
+ executables: []
105
142
  extensions: []
106
143
  extra_rdoc_files: []
107
144
  files:
108
- - ".gitignore"
109
- - ".rspec"
110
- - ".travis.yml"
111
- - Gemfile
112
- - README.md
113
- - Rakefile
114
- - bin/relaxo
115
- - bin/relaxo-admin
116
145
  - lib/relaxo.rb
117
146
  - lib/relaxo/changeset.rb
118
147
  - lib/relaxo/database.rb
@@ -120,18 +149,11 @@ files:
120
149
  - lib/relaxo/directory.rb
121
150
  - lib/relaxo/logger.rb
122
151
  - lib/relaxo/version.rb
123
- - relaxo.gemspec
124
- - spec/relaxo/changeset_spec.rb
125
- - spec/relaxo/concurrency_spec.rb
126
- - spec/relaxo/database_spec.rb
127
- - spec/relaxo/enumeration_spec.rb
128
- - spec/relaxo/performance_spec.rb
129
- - spec/relaxo/test_records.rb
130
- - spec/spec_helper.rb
131
- homepage: ''
152
+ homepage: https://github.com/ioquatix/relaxo
132
153
  licenses:
133
154
  - MIT
134
- metadata: {}
155
+ metadata:
156
+ funding_uri: https://github.com/sponsors/ioquatix/
135
157
  post_install_message:
136
158
  rdoc_options: []
137
159
  require_paths:
@@ -140,22 +162,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
162
  requirements:
141
163
  - - ">="
142
164
  - !ruby/object:Gem::Version
143
- version: '0'
165
+ version: '2.5'
144
166
  required_rubygems_version: !ruby/object:Gem::Requirement
145
167
  requirements:
146
168
  - - ">="
147
169
  - !ruby/object:Gem::Version
148
170
  version: '0'
149
171
  requirements: []
150
- rubygems_version: 3.0.3
172
+ rubygems_version: 3.1.2
151
173
  signing_key:
152
174
  specification_version: 4
153
- summary: Relaxo is a helper for loading and working with CouchDB.
154
- test_files:
155
- - spec/relaxo/changeset_spec.rb
156
- - spec/relaxo/concurrency_spec.rb
157
- - spec/relaxo/database_spec.rb
158
- - spec/relaxo/enumeration_spec.rb
159
- - spec/relaxo/performance_spec.rb
160
- - spec/relaxo/test_records.rb
161
- - spec/spec_helper.rb
175
+ summary: Relaxo is versioned document database built on top of git.
176
+ test_files: []
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- spec/relaxo/test
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --format documentation
2
- --backtrace
3
- --warnings
4
- --require spec_helper
@@ -1,20 +0,0 @@
1
- language: ruby
2
- dist: xenial
3
- cache: bundler
4
-
5
- matrix:
6
- include:
7
- - rvm: 2.4
8
- - rvm: 2.5
9
- - rvm: 2.6
10
- - rvm: 2.6
11
- env: COVERAGE=Summary,Coveralls
12
- - rvm: truffleruby
13
- - rvm: ruby-head
14
- - rvm: 2.6
15
- os: osx
16
- allow_failures:
17
- - rvm: truffleruby
18
- - rvm: ruby-head
19
- - rvm: jruby-head
20
- - rvm: truffleruby
data/Gemfile DELETED
@@ -1,20 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in relaxo.gemspec
4
- gemspec
5
-
6
- gem 'rugged', git: 'https://github.com/libgit2/rugged.git', submodules: true
7
-
8
- group :development do
9
- gem "pry"
10
- gem "msgpack"
11
- end
12
-
13
- group :test do
14
- gem 'benchmark-ips'
15
- gem 'ruby-prof'
16
-
17
- gem 'rack-test'
18
- gem 'simplecov'
19
- gem 'coveralls', require: false
20
- end
data/README.md DELETED
@@ -1,150 +0,0 @@
1
- # Relaxo
2
-
3
- Relaxo is a transactional database built on top of git. It's aim is to provide a robust interface for document storage and sorted indexes.
4
-
5
- [![Build Status](https://secure.travis-ci.org/ioquatix/relaxo.svg)](http://travis-ci.org/ioquatix/relaxo)
6
- [![Code Climate](https://codeclimate.com/github/ioquatix/relaxo.svg)](https://codeclimate.com/github/ioquatix/relaxo)
7
- [![Coverage Status](https://coveralls.io/repos/ioquatix/relaxo/badge.svg)](https://coveralls.io/r/ioquatix/relaxo)
8
-
9
- ## Installation
10
-
11
- Add this line to your application's Gemfile:
12
-
13
- gem 'relaxo'
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install relaxo
22
-
23
- ## Usage
24
-
25
- Connect to a local database and manipulate some documents.
26
-
27
- require 'relaxo'
28
- require 'msgpack'
29
-
30
- DB = Relaxo.connect("test")
31
-
32
- DB.commit(message: "Create test data") do |dataset|
33
- object = dataset.append(MessagePack.dump({bob: 'dole'}))
34
- dataset.write("doc1.msgpack", object)
35
- end
36
-
37
- DB.commit(message: "Update test data") do |dataset|
38
- doc = MessagePack.load dataset.read('doc1.msgpack').data
39
- doc[:foo] = 'bar'
40
-
41
- object = dataset.append(MessagePack.dump(doc))
42
- dataset.write("doc2.msgpack", object)
43
- end
44
-
45
- doc = MessagePack.load DB.current['doc2.msgpack'].data
46
- puts doc
47
- # => {"bob"=>"dole", "foo"=>"bar"}
48
-
49
- ### Document Storage
50
-
51
- Relaxo uses the git persistent data structure for storing documents. This data structure exposes a file-system like interface, which stores any kind of data. This means that you are free to use JSON, or BSON, or MessagePack, or JPEG, or XML, or any combination of those.
52
-
53
- Relaxo has a transactional model for both reading and writing.
54
-
55
- #### Reading Files
56
-
57
- path = "path/to/document"
58
-
59
- DB.current do |dataset|
60
- object = dataset.read(path)
61
-
62
- puts "The object id: #{object.oid}"
63
- puts "The object data size: #{object.size}"
64
- puts "The object data: #{object.data.inspect}"
65
- end
66
-
67
- #### Writing Files
68
-
69
- path = "path/to/document"
70
- data = MessagePack.dump(document)
71
-
72
- DB.commit(message: "Adding document") do |changeset|
73
- object = changeset.append(data)
74
- changeset.write(path, object)
75
- end
76
-
77
- ### Datasets and Transactions
78
-
79
- `Dataset`s and `Changeset`s are important concepts. Relaxo doesn't allow arbitrary access to data, but instead exposes the git persistent model for both reading and writing. The implications of this are that when reading or writing, you always see a consistent snapshot of the data store.
80
-
81
- ### Suitability
82
-
83
- Relaxo is designed to scale to the hundreds of thousands of documents. It's designed around the git persistent data store, and therefore has some performance and concurrency limitations due to the underlying implementation.
84
-
85
- Because it maintains a full history of all changes, the repository would continue to grow over time by default, but there are mechanisms to deal with that.
86
-
87
- #### Performance
88
-
89
- Relaxo can do anywhere from 1000-10,000 inserts per second depending on how you structure the workload.
90
-
91
- Relaxo Performance
92
- Warming up --------------------------------------
93
- single 129.000 i/100ms
94
- Calculating -------------------------------------
95
- single 6.224k (±14.7%) i/s - 114.036k in 20.000025s
96
- single transaction should be fast
97
- Warming up --------------------------------------
98
- multiple 152.000 i/100ms
99
- Calculating -------------------------------------
100
- multiple 1.452k (±15.2%) i/s - 28.120k in 20.101831s
101
- multiple transactions should be fast
102
-
103
- Reading data is lighting fast as it's loaded directly from disk and cached.
104
-
105
- ### Loading Data
106
-
107
- As Relaxo is unapologetically based on git, you can use git directly with a non-bare working directory to add any files you like. You can even point Relaxo at an existing git repository.
108
-
109
- ### Durability
110
-
111
- Relaxo is based on `libgit2` and asserts that it is a transactional database. We base this assertion on:
112
-
113
- - All writes into the object store using `libgit2` are atomic and synchronized to disk.
114
- - All updates to refs are atomic and synchronized to disk.
115
-
116
- Provided these two invariants are maintained, the operation of Relaxo will be safe, even if there are unexpected interruptions to the program.
117
-
118
- The durability guarantees of Relaxo depend on [`libgit2` calling `fsync`](https://github.com/libgit2/libgit2/pull/4030), and [this being respected by the underlying hardware](http://www.evanjones.ca/intel-ssd-durability.html). Otherwise, durability cannot be guaranteed.
119
-
120
- ## Contributing
121
-
122
- 1. Fork it
123
- 2. Create your feature branch (`git checkout -b my-new-feature`)
124
- 3. Commit your changes (`git commit -am 'Add some feature'`)
125
- 4. Push to the branch (`git push origin my-new-feature`)
126
- 5. Create new Pull Request
127
-
128
- ## License
129
-
130
- Released under the MIT license.
131
-
132
- Copyright, 2015, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
133
-
134
- Permission is hereby granted, free of charge, to any person obtaining a copy
135
- of this software and associated documentation files (the "Software"), to deal
136
- in the Software without restriction, including without limitation the rights
137
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
138
- copies of the Software, and to permit persons to whom the Software is
139
- furnished to do so, subject to the following conditions:
140
-
141
- The above copyright notice and this permission notice shall be included in
142
- all copies or substantial portions of the Software.
143
-
144
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
145
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
146
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
147
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
148
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
149
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
150
- THE SOFTWARE.
data/Rakefile DELETED
@@ -1,20 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec) do |task|
5
- task.rspec_opts = ["--require", "simplecov"] if ENV['COVERAGE']
6
- end
7
-
8
- task :default => :spec
9
-
10
- task :console do
11
- require 'pry'
12
- require 'msgpack'
13
- require 'securerandom'
14
-
15
- require_relative 'lib/relaxo'
16
-
17
- DB = Relaxo.connect(File.join(__dir__, '/tmp/relaxo-test-db'))
18
-
19
- Pry.start
20
- end
data/bin/relaxo DELETED
@@ -1,142 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'relaxo'
4
- require 'relaxo/version'
5
- require 'optparse'
6
- require 'yaml'
7
- require 'csv'
8
-
9
- OPTIONS = {
10
- :existing => :update, # :merge, :replace
11
- :format => :yaml,
12
- :transaction => true,
13
- }
14
-
15
- module Formats
16
- def self.yaml(io, &block)
17
- documents = YAML::load(io)
18
-
19
- unless Array === documents
20
- documents = [documents]
21
- end
22
-
23
- documents.each &block
24
- end
25
-
26
- def self.csv(io, &block)
27
- csv = CSV.new(io, :headers => :first_row)
28
-
29
- csv.each do |row|
30
- yield row.to_hash
31
- end
32
- end
33
- end
34
-
35
- ARGV.options do |o|
36
- script_name = File.basename($0)
37
-
38
- o.banner = "Usage: #{script_name} [options] [server-url] [files]"
39
- o.define_head "This script can be used to import data to CouchDB."
40
-
41
- o.separator ""
42
- o.separator "Document creation:"
43
-
44
- o.on("--existing [mode]", "Control whether to 'update (new document attributes takes priority), 'merge' (existing document attributes takes priority) or replace (old document attributes discarded) existing documents.") do |mode|
45
- OPTIONS[:existing] = mode.to_sym
46
- end
47
-
48
- o.on("--format [type]", "Control the input format. 'yaml' files are imported as a single document or array of documents. 'csv' files are imported as records using the first row as attribute keys.") do |format|
49
- OPTIONS[:format] = format.to_sym
50
- end
51
-
52
- o.on("--[no-]transaction", "Controls whether data is saved using the batch save operation. Not suitable for huge amounts of data.")
53
-
54
- o.separator ""
55
- o.separator "Help and Copyright information:"
56
-
57
- o.on_tail("--copy", "Display copyright and warranty information") do
58
- $stderr.puts "#{script_name} v#{Relaxo::VERSION}. Copyright (c) 2012 Samuel Williams."
59
- $stderr.puts "This software is released under the MIT license and comes with ABSOLUTELY NO WARRANTY."
60
- exit
61
- end
62
-
63
- o.on_tail("-h", "--help", "Show this help message.") do
64
- $stderr.puts o
65
- exit
66
- end
67
- end.parse!
68
-
69
- url = ARGV.shift
70
-
71
- $stderr.puts "Connecting to #{url}..."
72
- database = Relaxo.connect(url)
73
-
74
- begin
75
- info = database.info
76
-
77
- $stderr.puts "Connected to #{info['db_name']} which contains #{info['doc_count']} document(s)."
78
- rescue StandardError => error
79
- $stderr.puts "Could not fetch info from database server!"
80
-
81
- throw
82
- end
83
-
84
-
85
- format = Formats.method(OPTIONS[:format])
86
-
87
- @stats = {
88
- :saved => 0,
89
- :errors => 0,
90
- :total => 0
91
- }
92
-
93
- def process_document(database, document)
94
- begin
95
- existing_document = nil
96
-
97
- if document && document[Relaxo::ID]
98
- $stderr.puts "Loading #{document[Relaxo::ID]}"
99
- existing_document = database.get(document[Relaxo::ID]) rescue nil
100
- end
101
-
102
- if existing_document
103
- if OPTIONS[:existing] == :replace
104
- $stderr.puts "Replacing existing document..."
105
- # The document is replaced entirely with the incoming data.
106
- document[Relaxo::REV] = existing_document[Relaxo::REV]
107
- elsif OPTIONS[:existing] == :update
108
- $stderr.puts "Updating existing document..."
109
- # Values in `existing_document` take priority
110
- document.update(existing_document)
111
- elsif OPTIONS[:existing] == :merge
112
- $stderr.puts "Merging existing document..."
113
- # Values in `document` take priority, except for `_rev`.
114
- document.update(existing_document) do |key, oldval, newval|
115
- key == Relaxo::REV ? newval : oldval
116
- end
117
- end
118
- end
119
-
120
- $stderr.puts "Saving #{document.inspect}"
121
- result = database.save(document)
122
-
123
- @stats[:saved] += 1
124
- rescue RestClient::BadRequest => ex
125
- $stderr.puts ex.inspect
126
-
127
- @stats[:errors] += 1
128
- end
129
-
130
- @stats[:total] += 1
131
- end
132
-
133
- begin
134
- format.call(ARGF) do |document|
135
- process_document(database, document)
136
- end
137
- ensure
138
- $stderr.puts "#{@stats[:saved]} document(s) saved out of #{@stats[:total]}."
139
- if @stats[:errors] > 0
140
- $stderr.puts "#{@stats[:errors]} errors occurred!"
141
- end
142
- end
@@ -1,61 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'relaxo'
4
- require 'relaxo/version'
5
- require 'optparse'
6
- require 'digest/sha1'
7
-
8
- $url = ARGV.shift unless ARGV[0] =~ /^-/
9
- $connection = Relaxo::Connection.new($url)
10
-
11
- OPTIONS = {
12
- :roles => [],
13
- :password => nil
14
- }
15
-
16
- ARGV.options do |o|
17
- script_name = File.basename($0)
18
-
19
- o.banner = "Usage: #{script_name} [server-url] [options]"
20
- o.define_head "This script can be used to import data to CouchDB."
21
-
22
- o.on("--password password", "Specify the password for a new user") do |password|
23
- OPTIONS[:password] = password
24
- end
25
-
26
- o.on("--roles reader,writer", Array, "Specify the roles for a new user") do |roles|
27
- OPTIONS[:roles] = roles
28
- end
29
-
30
- o.on("--create-user name", "Create a new (non-admin) user") do |name|
31
- password = OPTIONS[:password]
32
-
33
- salt = Digest::SHA1.hexdigest(rand.to_s + name + Time.now.to_s + password)
34
-
35
- user = {
36
- Relaxo::ID => "org.couchdb.user:#{name}",
37
- :type => "user",
38
- :name => name,
39
- :roles => OPTIONS[:roles],
40
- :salt => salt,
41
- :password_sha => Digest::SHA1.hexdigest(password + salt)
42
- }
43
-
44
- database = Relaxo::Database.new($connection, "_users")
45
- puts database.save(user).inspect
46
- end
47
-
48
- o.separator ""
49
- o.separator "Help and Copyright information:"
50
-
51
- o.on_tail("--copy", "Display copyright and warranty information") do
52
- $stderr.puts "#{script_name} v#{Relaxo::VERSION}. Copyright (c) 2012 Samuel Williams."
53
- $stderr.puts "This software is released under the MIT license and comes with ABSOLUTELY NO WARRANTY."
54
- exit
55
- end
56
-
57
- o.on_tail("-h", "--help", "Show this help message.") do
58
- $stderr.puts o
59
- exit
60
- end
61
- end.parse!
@@ -1,32 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'relaxo/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "relaxo"
8
- spec.version = Relaxo::VERSION
9
- spec.authors = ["Samuel Williams"]
10
- spec.email = ["samuel.williams@oriontransfer.co.nz"]
11
- spec.description = <<-EOF
12
- Relaxo provides a set of tools and interfaces for interacting with CouchDB.
13
- It aims to be as simple and efficient as possible while still improving the
14
- usability of various CouchDB features.
15
- EOF
16
- spec.summary = %q{Relaxo is a helper for loading and working with CouchDB.}
17
- spec.homepage = ""
18
- spec.license = "MIT"
19
-
20
- spec.files = `git ls-files`.split($/)
21
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
- spec.require_paths = ["lib"]
24
-
25
- spec.add_dependency "rugged"
26
- spec.add_dependency "console"
27
-
28
- spec.add_development_dependency "covered"
29
- spec.add_development_dependency "rspec", "~> 3.6"
30
- spec.add_development_dependency "bundler", "~> 1.3"
31
- spec.add_development_dependency "rake"
32
- end
@@ -1,37 +0,0 @@
1
-
2
- require_relative 'test_records'
3
-
4
- RSpec.describe Relaxo::Changeset do
5
- include_context "test records"
6
-
7
- it "should enumerate all documents including writes" do
8
- records = []
9
-
10
- database.commit(message: "Testing Enumeration") do |dataset|
11
- 5.times do |i|
12
- object = dataset.append("extra-#{i}")
13
- dataset.write("#{prefix}/extra-#{i}", object)
14
- end
15
-
16
- expect(dataset.exist?("#{prefix}/extra-0")).to be_truthy
17
-
18
- records = dataset.each(prefix).to_a
19
- end
20
-
21
- expect(records.count).to be 25
22
- end
23
-
24
- it "should enumerate all documents excluding deletes" do
25
- records = database.commit(message: "Testing Enumeration") do |dataset|
26
- 5.times do |i|
27
- dataset.delete("#{prefix}/#{i}")
28
- end
29
-
30
- expect(dataset.exist?("#{prefix}/0")).to be_falsey
31
-
32
- dataset.each(prefix).to_a
33
- end
34
-
35
- expect(records.count).to be 15
36
- end
37
- end
@@ -1,39 +0,0 @@
1
-
2
- require_relative 'test_records'
3
-
4
- RSpec.describe Relaxo::Changeset do
5
- include_context "test records"
6
-
7
- it "should detect conflicts" do
8
- events = []
9
-
10
- alice = Fiber.new do
11
- database.commit(message: "Alice Data") do |changeset|
12
- events << :alice
13
-
14
- object = changeset.append("sample-data-1")
15
- changeset.write("conflict-path", object)
16
-
17
- Fiber.yield
18
- end
19
- end
20
-
21
- bob = Fiber.new do
22
- database.commit(message: "Bob Data") do |changeset|
23
- events << :bob
24
-
25
- object = changeset.append("sample-data-1")
26
- changeset.write("conflict-path", object)
27
-
28
- Fiber.yield
29
- end
30
- end
31
-
32
- alice.resume
33
- bob.resume
34
- alice.resume
35
- bob.resume
36
-
37
- expect(events).to be == [:alice, :bob, :bob]
38
- end
39
- end
@@ -1,129 +0,0 @@
1
-
2
- require 'relaxo'
3
-
4
- RSpec.describe Relaxo::Database do
5
- let(:database_path) {File.join(__dir__, 'test')}
6
-
7
- let(:database) {Relaxo.connect(database_path, test_key: "test_value")}
8
-
9
- let(:document_path) {'test/document.json'}
10
- let(:sample_json) {'[1, 2, 3]'}
11
-
12
- before(:each) {FileUtils.rm_rf(database_path)}
13
-
14
- it "should be initially empty" do
15
- expect(database).to be_empty
16
- end
17
-
18
- it "prepares user details in config" do
19
- expect(database.config).to include('user.name', 'user.email')
20
-
21
- puts database.config['user.name']
22
- puts database.config['user.email']
23
- end
24
-
25
- it "can clear database" do
26
- expect do
27
- database.clear!
28
- end.to_not raise_error
29
- end
30
-
31
- it "should not be empty with one document" do
32
- database.commit(message: "Create test document") do |dataset|
33
- oid = dataset.append(sample_json)
34
- dataset.write(document_path, oid)
35
- end
36
-
37
- expect(database).to_not be_empty
38
- end
39
-
40
- it "should be able to clear the database" do
41
- database.commit(message: "Create test document") do |dataset|
42
- oid = dataset.append(sample_json)
43
- dataset.write(document_path, oid)
44
- end
45
-
46
- expect(database).to_not be_empty
47
-
48
- database.clear!
49
-
50
- expect(database).to be_empty
51
- end
52
-
53
- it "should have metadata" do
54
- expect(database[:test_key]).to be == "test_value"
55
- end
56
-
57
- it "should create a document" do
58
- database.commit(message: "Create test document") do |dataset|
59
- oid = dataset.append(sample_json)
60
- dataset.write(document_path, oid)
61
- end
62
-
63
- database.current do |dataset|
64
- expect(dataset[document_path].data).to be == sample_json
65
- end
66
- end
67
-
68
- it "should erase a document" do
69
- database.commit(message: "Create test document") do |dataset|
70
- oid = dataset.append(sample_json)
71
- dataset.write(document_path, oid)
72
- end
73
-
74
- database.commit(message: "Delete test document") do |dataset|
75
- dataset.delete(document_path)
76
- end
77
-
78
- database.current do |dataset|
79
- expect(dataset[document_path]).to be nil
80
- end
81
- end
82
-
83
- it "should create multiple documents" do
84
- database.commit(message: "Create first document") do |dataset|
85
- oid = dataset.append(sample_json)
86
- dataset.write(document_path, oid)
87
- end
88
-
89
- database.commit(message: "Create second document") do |dataset|
90
- oid = dataset.append(sample_json)
91
- dataset.write(document_path + '2', oid)
92
- end
93
-
94
- database.current do |dataset|
95
- expect(dataset[document_path].data).to be == sample_json
96
- expect(dataset[document_path + '2'].data).to be == sample_json
97
- end
98
- end
99
-
100
- it "can enumerate documents" do
101
- database.commit(message: "Create first document") do |dataset|
102
- oid = dataset.append(sample_json)
103
-
104
- 10.times do |id|
105
- dataset.write(document_path + "-#{id}", oid)
106
- end
107
- end
108
-
109
- database.current do |dataset|
110
- expect(dataset.each('test').count).to be == 10
111
- end
112
- end
113
-
114
- it "can enumerate commit history of a document" do
115
- 10.times do |id|
116
- database.commit(message: "revising the document #{id}") do |changeset|
117
- oid = changeset.append("revision \##{id} of this document")
118
- changeset.write('test/doot.txt', oid)
119
- end
120
- end
121
-
122
- database.commit(message: "unrelated commit") do |changeset|
123
- oid = changeset.append("unrelated document")
124
- changeset.write('test/unrelated.txt', oid)
125
- end
126
-
127
- expect(database.history('test/doot.txt').count).to be == 10
128
- end
129
- end
@@ -1,30 +0,0 @@
1
-
2
- require_relative 'test_records'
3
-
4
- RSpec.describe Relaxo::Dataset do
5
- include_context "test records"
6
-
7
- it "should enumerate all documents" do
8
- records = []
9
-
10
- database.current do |dataset|
11
- records = dataset.each(prefix).to_a
12
- end
13
-
14
- expect(records.count).to be 20
15
- end
16
- end
17
-
18
- RSpec.describe Relaxo::Changeset do
19
- include_context "test records"
20
-
21
- it "should enumerate all documents" do
22
- records = []
23
-
24
- database.commit(message: "Testing Enumeration") do |dataset|
25
- records = dataset.each(prefix).to_a
26
- end
27
-
28
- expect(records.count).to be 20
29
- end
30
- end
@@ -1,78 +0,0 @@
1
-
2
- require 'benchmark/ips' if ENV['BENCHMARK']
3
- require 'ruby-prof' if ENV['PROFILE']
4
- require 'flamegraph' if ENV['FLAMEGRAPH']
5
-
6
- RSpec.describe "Relaxo Performance" do
7
- let(:database_path) {File.join(__dir__, 'test')}
8
- let(:database) {Relaxo.connect(database_path)}
9
-
10
- if defined? Benchmark
11
- def benchmark(name = nil)
12
- Benchmark.ips do |benchmark|
13
- # Collect more data for benchmark:
14
- benchmark.time = 20
15
- benchmark.warmup = 10
16
-
17
- benchmark.report(name) do |i|
18
- yield i
19
- end
20
-
21
- benchmark.compare!
22
- end
23
- end
24
- elsif defined? RubyProf
25
- def benchmark(name)
26
- result = RubyProf.profile do
27
- yield 1000
28
- end
29
-
30
- #result.eliminate_methods!([/^((?!Utopia).)*$/])
31
- printer = RubyProf::FlatPrinter.new(result)
32
- printer.print($stderr, min_percent: 1.0)
33
-
34
- printer = RubyProf::GraphHtmlPrinter.new(result)
35
- filename = name.gsub('/', '_') + '.html'
36
- File.open(filename, "w") do |file|
37
- printer.print(file)
38
- end
39
- end
40
- elsif defined? Flamegraph
41
- def benchmark(name)
42
- filename = name.gsub('/', '_') + '.html'
43
- Flamegraph.generate(filename) do
44
- yield 1
45
- end
46
- end
47
- else
48
- def benchmark(name)
49
- yield 1
50
- end
51
- end
52
-
53
- before(:each) do
54
- FileUtils.rm_rf(database_path)
55
- end
56
-
57
- it "single transaction should be fast" do
58
- benchmark("single") do |iterations|
59
- database.commit(message: "Some Documents") do |dataset|
60
- iterations.times do |i|
61
- object = dataset.append("good-#{i}")
62
- dataset.write("#{i%100}/#{i}", object)
63
- end
64
- end
65
- end
66
- end
67
-
68
- it "multiple transactions should be fast" do
69
- benchmark("multiple") do |iterations|
70
- iterations.times do |i|
71
- database.commit(message: "Some Documents") do |dataset|
72
- object = dataset.append("good-#{i}")
73
- dataset.write("#{i%100}/#{i}", object)
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,25 +0,0 @@
1
-
2
- require 'relaxo'
3
-
4
- RSpec.shared_context "test records" do
5
- let(:database_path) {File.join(__dir__, 'test')}
6
- let(:database) {Relaxo.connect(database_path)}
7
-
8
- let(:prefix) {"records"}
9
-
10
- before(:each) do
11
- FileUtils.rm_rf(database_path)
12
-
13
- database.commit(message: "Create Sample Data") do |dataset|
14
- 20.times do |i|
15
- object = dataset.append("good-#{i}")
16
- dataset.write("#{prefix}/#{i}", object)
17
- end
18
-
19
- 10.times do |i|
20
- object = dataset.append("bad-#{i}")
21
- dataset.write("#{prefix}/subdirectory/#{i}", object)
22
- end
23
- end
24
- end
25
- end
@@ -1,11 +0,0 @@
1
-
2
- require 'covered/rspec'
3
-
4
- RSpec.configure do |config|
5
- # Enable flags like --only-failures and --next-failure
6
- config.example_status_persistence_file_path = ".rspec_status"
7
-
8
- config.expect_with :rspec do |c|
9
- c.syntax = :expect
10
- end
11
- end