rbdb 0.2.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +47 -12
- data/lib/rbdb/db.rb +8 -0
- data/lib/rbdb/table.rb +41 -11
- data/lib/rbdb/version.rb +1 -1
- data/rbdb-0.2.0.gem +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e355fb7edc3680f0d9a53b35d9f960a3b182f9d3
|
|
4
|
+
data.tar.gz: 3c29645b7edc11d5d187f89c552be1719c4b6d4e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b794f599c1ce850ab55ad062c946775e507fa0c8f9d0caf1a784931d8c72d856391840e70dde7915dc819f49e0e4e26ab5a31726aeeeee695135e9f2d5ba2b64
|
|
7
|
+
data.tar.gz: 384ac02c507e0ab010c422516aa2f9e70d30b71517e6cdeb4d8f464d3b60590bac98bab4e29db242ddbe7756566d5ba5a8d17790750cbf28d8414f05692d3e32
|
data/README.md
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
# Rbdb
|
|
2
|
-
|
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rbdb`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
-
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
|
2
|
+
Simple in memory database for Ruby
|
|
6
3
|
|
|
7
4
|
## Installation
|
|
8
5
|
|
|
@@ -22,18 +19,56 @@ Or install it yourself as:
|
|
|
22
19
|
|
|
23
20
|
## Usage
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
```ruby
|
|
23
|
+
require 'rbdb'
|
|
24
|
+
|
|
25
|
+
db = Rbdb.create_db('app') # Create a DB
|
|
26
|
+
table = db.create_table('people') # And a table
|
|
27
|
+
table.fields = {name: :string, age: :integer} # Assign it a schema like field (Hash)
|
|
28
|
+
table.insert({name: 'John', age: 31}) # Give it some records
|
|
29
|
+
table.insert({name: 'Doe', age: 31})
|
|
30
|
+
table.find_all({age: 31})
|
|
31
|
+
=> [{:name=>"John", :age=>31, :id=>1}, {:name=>"Doe", :age=>31, :id=>2}]
|
|
32
|
+
```
|
|
33
|
+
Rbdb automatically assigns a unique id to each record inserted.
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
### Top level namespace
|
|
36
|
+
The top level namespace is meant to contain all databases.
|
|
37
|
+
```ruby
|
|
38
|
+
Rbdb.create_db(name, options = {})
|
|
39
|
+
```
|
|
40
|
+
creates a DB with name and adds it to the top level container and return it
|
|
41
|
+
name: The name to give to the database
|
|
42
|
+
options: force - If set to true, overwrites the DB with name if it exists and is not contained in the top level namespace.
|
|
43
|
+
```ruby
|
|
44
|
+
Rbdb.add_db(db, options = {})
|
|
45
|
+
```
|
|
46
|
+
add a DB to the top level container and return it
|
|
47
|
+
db: The database to add to the top level container
|
|
48
|
+
options: force - If set to true, overwrites the DB with db.name if it exists and is not in the top level namespace.
|
|
49
|
+
```ruby
|
|
50
|
+
Rbdb.databases
|
|
51
|
+
```
|
|
52
|
+
returns all databases
|
|
53
|
+
```ruby
|
|
54
|
+
Rbdb.find_db(name)
|
|
55
|
+
```
|
|
56
|
+
finds the database with name in the top level namespace
|
|
57
|
+
name: the name of the database to find.
|
|
58
|
+
```ruby
|
|
59
|
+
Rbdb.delete_db(name)
|
|
60
|
+
```
|
|
61
|
+
deletes the database with name in the top level namespace
|
|
62
|
+
name: the name of the database to delete.
|
|
63
|
+
```ruby
|
|
64
|
+
Rbdb.flush
|
|
65
|
+
```
|
|
66
|
+
Used for debugging and testing purposes. Deletes all DB's in the top level container.
|
|
32
67
|
|
|
33
68
|
## Contributing
|
|
34
69
|
|
|
35
|
-
1. Fork it ( https://github.com/
|
|
70
|
+
1. Fork it ( https://github.com/dibenso/rbdb/fork )
|
|
36
71
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
37
72
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
38
73
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
39
|
-
5. Create a new Pull Request
|
|
74
|
+
5. Create a new Pull Request
|
data/lib/rbdb/db.rb
CHANGED
data/lib/rbdb/table.rb
CHANGED
|
@@ -5,7 +5,7 @@ module Rbdb
|
|
|
5
5
|
ALLOWED_TYPES = [:string, :integer, :float, :boolean]
|
|
6
6
|
|
|
7
7
|
attr_reader :name, :options, :fields, :records
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
def initialize(name, options = {})
|
|
10
10
|
@name = name
|
|
11
11
|
@options = options
|
|
@@ -26,10 +26,18 @@ module Rbdb
|
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def find_by(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
def find_by(fields)
|
|
30
|
+
if fields.length == 1
|
|
31
|
+
return find_by_id(fields.values.first) if fields.keys.first.to_s == 'id'
|
|
32
|
+
find(fields) do |record|
|
|
33
|
+
return record
|
|
34
|
+
end
|
|
35
|
+
return nil
|
|
36
|
+
else
|
|
37
|
+
find_multiple_fields(fields) do |record|
|
|
38
|
+
return record
|
|
39
|
+
end
|
|
40
|
+
nil
|
|
33
41
|
end
|
|
34
42
|
end
|
|
35
43
|
|
|
@@ -37,12 +45,19 @@ module Rbdb
|
|
|
37
45
|
return @records["#{id}"]
|
|
38
46
|
end
|
|
39
47
|
|
|
40
|
-
def find_all(
|
|
41
|
-
return [find_by_id(kv_pair.values.first)] if kv_pair.keys.first == 'id'
|
|
48
|
+
def find_all(fields)
|
|
42
49
|
found = []
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
if fields.length == 1
|
|
51
|
+
return [find_by_id(fields.values.first)] if fields.keys.first == 'id'
|
|
52
|
+
find(fields) do |record|
|
|
53
|
+
found << record
|
|
54
|
+
end
|
|
55
|
+
else
|
|
56
|
+
find_multiple_fields(fields) do |record|
|
|
57
|
+
found << record
|
|
58
|
+
end
|
|
45
59
|
end
|
|
60
|
+
|
|
46
61
|
found
|
|
47
62
|
end
|
|
48
63
|
|
|
@@ -63,9 +78,24 @@ module Rbdb
|
|
|
63
78
|
|
|
64
79
|
private
|
|
65
80
|
|
|
66
|
-
def find(
|
|
81
|
+
def find(fields, &block)
|
|
67
82
|
@records.each do |key, v|
|
|
68
|
-
yield v if v[
|
|
83
|
+
yield v if v[fields.keys.first] == fields.values.first
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def find_multiple_fields(fields, &block)
|
|
88
|
+
@records.each do |k, v|
|
|
89
|
+
good = true
|
|
90
|
+
fields.each do |key, value|
|
|
91
|
+
if v[key] == value
|
|
92
|
+
next
|
|
93
|
+
else
|
|
94
|
+
good = false
|
|
95
|
+
break
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
yield v if good
|
|
69
99
|
end
|
|
70
100
|
end
|
|
71
101
|
|
data/lib/rbdb/version.rb
CHANGED
data/rbdb-0.2.0.gem
ADDED
|
Binary file
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rbdb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- dibenso
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-07-
|
|
11
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -71,6 +71,7 @@ files:
|
|
|
71
71
|
- lib/rbdb/util.rb
|
|
72
72
|
- lib/rbdb/version.rb
|
|
73
73
|
- rbdb-0.1.0.gem
|
|
74
|
+
- rbdb-0.2.0.gem
|
|
74
75
|
- rbdb.gemspec
|
|
75
76
|
homepage: https://github.com/dibenso/rbdb
|
|
76
77
|
licenses: []
|