dbum 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.md +63 -1
- data/VERSION +1 -1
- data/dbum.gemspec +1 -0
- data/lib/dbum/app.rb +102 -2
- data/lib/dbum/main.rb +31 -2
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6440dbbd65d0459b357f33f43bbb0f949f453602
|
4
|
+
data.tar.gz: ef8eb85055d70699bc8fd9b17fd23aff4d7ef450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69bfb0964579921af41122ce9ccbb044a9aebcf08a25c2d69a5fddadbea2e80b1b71880f8164928736e6ca304f5225e379723076c782587f5860101091dabe27
|
7
|
+
data.tar.gz: 3238eac53926240c8bc3dbf9af5bdf8110462c9a8b52d3fa4884fe3a69003815d694b0e2982df66793d754a32414a51a1a314e3c7e3b674e0ac3edd9392b93b3
|
data/Readme.md
CHANGED
@@ -1,3 +1,65 @@
|
|
1
1
|
# DBum
|
2
2
|
|
3
|
-
A no-nonsense, JSON-based key-value store
|
3
|
+
A no-nonsense, JSON-based key-value store backed by [Daybreak](http://propublica.github.io/daybreak/)
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
DBum has few commands:
|
8
|
+
|
9
|
+
$ dbum help
|
10
|
+
Commands:
|
11
|
+
dbum art # View the application art
|
12
|
+
dbum help [COMMAND] # Describe available commands or one specific command
|
13
|
+
dbum server # Start the application Web server
|
14
|
+
dbum version # Echo the application version
|
15
|
+
|
16
|
+
You're probably most interested in the `server` command:
|
17
|
+
|
18
|
+
$ dbum help server
|
19
|
+
Usage:
|
20
|
+
dbum server
|
21
|
+
|
22
|
+
Options:
|
23
|
+
-p, [--port=N] # Set Sinatra port
|
24
|
+
# Default: 4567
|
25
|
+
-e, [--environment=ENVIRONMENT] # Set Sinatra environment
|
26
|
+
# Default: development
|
27
|
+
-b, [--bind=BIND] # Set Sinatra interface
|
28
|
+
# Default: 0.0.0.0
|
29
|
+
-t, [--database=DATABASE] # Location of application database
|
30
|
+
# Default: um.db
|
31
|
+
-d, [--debug], [--no-debug] # Enable debugging output
|
32
|
+
|
33
|
+
Start the application Web server
|
34
|
+
|
35
|
+
## API
|
36
|
+
|
37
|
+
The Web server has only a few endpoints:
|
38
|
+
|
39
|
+
### List keys `GET /`
|
40
|
+
|
41
|
+
Return the current list of keys.
|
42
|
+
|
43
|
+
### Lookup key `GET /:key`
|
44
|
+
|
45
|
+
Return the value associated with the given key. Returns `404` if the key does
|
46
|
+
not exist.
|
47
|
+
|
48
|
+
### Create key `POST /:key`
|
49
|
+
|
50
|
+
Associate the given key with the value contained in the request body, which must
|
51
|
+
be a valid JSON hash. Returns `404` if the key already exists.
|
52
|
+
|
53
|
+
### Replace key `PUT /:key`
|
54
|
+
|
55
|
+
Associate the given key with the value contained in the request body, which must
|
56
|
+
be a valid JSON hash. Returns `404` if the key does not exist.
|
57
|
+
|
58
|
+
### Update key `PATCH /:key`
|
59
|
+
|
60
|
+
Merge the value associated the given key with the contents of the request body,
|
61
|
+
which must be a valid JSON hash. Returns `404` if the key does not exist.
|
62
|
+
|
63
|
+
### Delete key `DELETE /:key`
|
64
|
+
|
65
|
+
Delete the key and its associated value.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/dbum.gemspec
CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_runtime_dependency 'slog', '~> 1.1'
|
18
18
|
s.add_runtime_dependency 'sinatra', '~> 1.4'
|
19
19
|
s.add_runtime_dependency 'daybreak', '~> 0.3'
|
20
|
+
s.add_runtime_dependency 'deep_merge', '~> 1'
|
20
21
|
|
21
22
|
s.files = `git ls-files`.split("\n")
|
22
23
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
data/lib/dbum/app.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
require 'pathname'
|
2
|
+
require 'logger'
|
2
3
|
require 'thread'
|
3
4
|
require 'json'
|
4
5
|
|
6
|
+
require 'slog'
|
7
|
+
require 'daybreak'
|
8
|
+
require 'deep_merge'
|
5
9
|
require 'sinatra/base'
|
6
10
|
|
7
11
|
require_relative 'helpers'
|
@@ -14,9 +18,105 @@ module DBum
|
|
14
18
|
class App < Sinatra::Application
|
15
19
|
include DBum::Helpers
|
16
20
|
|
21
|
+
def self.config! options
|
22
|
+
@@logger = Slog::Logger.new
|
23
|
+
@@db = Daybreak::DB.new options.database
|
24
|
+
|
25
|
+
self.set :environment, options.environment
|
26
|
+
self.set :port, options.port
|
27
|
+
self.set :bind, options.bind
|
28
|
+
self.set :raise_errors, options.debug?
|
29
|
+
self.set :dump_errors, options.debug?
|
30
|
+
self.set :show_exceptions, options.debug?
|
31
|
+
self.set :logging, ::Logger::DEBUG if options.debug?
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.close!
|
35
|
+
@@db.close
|
36
|
+
end
|
37
|
+
|
38
|
+
|
17
39
|
get '/' do
|
18
|
-
|
19
|
-
|
40
|
+
pretty_json map.keys
|
41
|
+
end
|
42
|
+
|
43
|
+
get '/:key' do
|
44
|
+
key = params[:key]
|
45
|
+
val = lookup key
|
46
|
+
return status(404) if val.nil?
|
47
|
+
pretty_json val
|
48
|
+
end
|
49
|
+
|
50
|
+
post '/:key' do
|
51
|
+
key = params[:key]
|
52
|
+
val = lookup key
|
53
|
+
return status(404) unless val.nil?
|
54
|
+
data = request_body
|
55
|
+
update key, data
|
56
|
+
pretty_json data
|
57
|
+
end
|
58
|
+
|
59
|
+
put '/:key' do
|
60
|
+
key = params[:key]
|
61
|
+
val = lookup key
|
62
|
+
return status(404) if val.nil?
|
63
|
+
data = request_body
|
64
|
+
update key, data
|
65
|
+
pretty_json data
|
66
|
+
end
|
67
|
+
|
68
|
+
patch '/:key' do
|
69
|
+
key = params[:key]
|
70
|
+
val = lookup key
|
71
|
+
return status(404) if val.nil?
|
72
|
+
val.deep_merge! request_body
|
73
|
+
update key, val
|
74
|
+
pretty_json val
|
75
|
+
end
|
76
|
+
|
77
|
+
delete '/:key' do
|
78
|
+
key = params[:key]
|
79
|
+
val = lookup key
|
80
|
+
return status(404) if val.nil?
|
81
|
+
remove key
|
82
|
+
pretty_json val
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def request_body
|
89
|
+
request.body.rewind
|
90
|
+
JSON.parse request.body.read
|
91
|
+
end
|
92
|
+
|
93
|
+
def pretty_json o
|
94
|
+
content_type :json
|
95
|
+
JSON.pretty_generate o
|
96
|
+
end
|
97
|
+
|
98
|
+
def map
|
99
|
+
@@db.lock do
|
100
|
+
@@db.keys.reduce({}) { |h, k| h[k] = @@db[k] ; h }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def lookup key
|
105
|
+
map[key]
|
106
|
+
end
|
107
|
+
|
108
|
+
def update key, val
|
109
|
+
@@db.lock do
|
110
|
+
@@db[key] = val
|
111
|
+
end
|
112
|
+
@@db.flush
|
113
|
+
end
|
114
|
+
|
115
|
+
def remove key
|
116
|
+
@@db.lock do
|
117
|
+
@@db.delete key
|
118
|
+
end
|
119
|
+
@@db.flush
|
20
120
|
end
|
21
121
|
|
22
122
|
end
|
data/lib/dbum/main.rb
CHANGED
@@ -29,9 +29,38 @@ module DBum
|
|
29
29
|
end
|
30
30
|
|
31
31
|
|
32
|
-
desc '
|
33
|
-
|
32
|
+
desc 'server', 'Start the application Web server'
|
33
|
+
option :port, \
|
34
|
+
type: :numeric,
|
35
|
+
aliases: %w[ -p ],
|
36
|
+
desc: 'Set Sinatra port',
|
37
|
+
default: 4567
|
38
|
+
option :environment, \
|
39
|
+
type: :string,
|
40
|
+
aliases: %w[ -e ],
|
41
|
+
desc: 'Set Sinatra environment',
|
42
|
+
default: 'development'
|
43
|
+
option :bind, \
|
44
|
+
type: :string,
|
45
|
+
aliases: %w[ -b ],
|
46
|
+
desc: 'Set Sinatra interface',
|
47
|
+
default: '0.0.0.0'
|
48
|
+
option :database, \
|
49
|
+
type: :string,
|
50
|
+
aliases: %w[ -t ],
|
51
|
+
desc: 'Location of application database',
|
52
|
+
default: 'um.db'
|
53
|
+
option :debug, \
|
54
|
+
type: :boolean,
|
55
|
+
aliases: %w[ -d ],
|
56
|
+
desc: 'Enable debugging output',
|
57
|
+
default: false
|
58
|
+
def server
|
59
|
+
App.config! options
|
34
60
|
App.run!
|
61
|
+
at_exit do
|
62
|
+
App.close!
|
63
|
+
end
|
35
64
|
end
|
36
65
|
|
37
66
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Clemmer
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: deep_merge
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1'
|
69
83
|
description: A no-nonsense, JSON-based key-value store.
|
70
84
|
email: sczizzo@gmail.com
|
71
85
|
executables:
|