slugdb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2395e205029cd093867c8593abab596f7565a4429c4aad35e5382f15d06fd32a
4
+ data.tar.gz: a7ba3d30db63551af9ccdaa602662071102a0cdc974e48a9943663396d6b044c
5
+ SHA512:
6
+ metadata.gz: 9ddf6f107a4a90c2e355330927e755804805b1c5a3b817a6423a5476ab54fe66af104a6d9e2255b32089618dca653285c9a7080a3fd79314fcdcb40478104599
7
+ data.tar.gz: 9c3009a21fff95f7d3bd472d55db792c6a2188ebf654826b8d74b573057edfa6f9e56c1e63fc3eede79973cf6e8eff54b55df106af4da27439a2a110b491c60f
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ NewCops: enable
4
+
5
+ Metrics/ClassLength:
6
+ Max: 150
7
+
8
+ Metrics/MethodLength:
9
+ Max: 15
10
+
11
+ Layout/LineLength:
12
+ Max: 120
13
+
14
+ Metrics/BlockLength:
15
+ Exclude:
16
+ - '**/*_spec.rb'
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 3.0.0
6
+ before_install: gem install bundler -v 2.2.3
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in slugdb.gemspec
6
+ gemspec
7
+
8
+ gem 'pry'
9
+ gem 'rake', '~> 13.0'
10
+ gem 'rspec', '~> 3.0'
11
+ gem 'rubocop', '~> 0.80'
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ slugdb (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ coderay (1.1.3)
11
+ diff-lcs (1.4.4)
12
+ gem-release (2.2.1)
13
+ method_source (1.0.0)
14
+ parallel (1.20.1)
15
+ parser (3.0.0.0)
16
+ ast (~> 2.4.1)
17
+ pry (0.14.0)
18
+ coderay (~> 1.1)
19
+ method_source (~> 1.0)
20
+ rainbow (3.0.0)
21
+ rake (13.0.3)
22
+ regexp_parser (2.1.1)
23
+ rexml (3.2.4)
24
+ rspec (3.10.0)
25
+ rspec-core (~> 3.10.0)
26
+ rspec-expectations (~> 3.10.0)
27
+ rspec-mocks (~> 3.10.0)
28
+ rspec-core (3.10.1)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-expectations (3.10.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.10.0)
33
+ rspec-mocks (3.10.2)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.10.0)
36
+ rspec-support (3.10.2)
37
+ rubocop (0.93.1)
38
+ parallel (~> 1.10)
39
+ parser (>= 2.7.1.5)
40
+ rainbow (>= 2.2.2, < 4.0)
41
+ regexp_parser (>= 1.8)
42
+ rexml
43
+ rubocop-ast (>= 0.6.0)
44
+ ruby-progressbar (~> 1.7)
45
+ unicode-display_width (>= 1.4.0, < 2.0)
46
+ rubocop-ast (1.4.1)
47
+ parser (>= 2.7.1.5)
48
+ ruby-progressbar (1.11.0)
49
+ unicode-display_width (1.7.0)
50
+
51
+ PLATFORMS
52
+ x86_64-linux
53
+
54
+ DEPENDENCIES
55
+ gem-release
56
+ pry
57
+ rake (~> 13.0)
58
+ rspec (~> 3.0)
59
+ rubocop (~> 0.80)
60
+ slugdb!
61
+
62
+ BUNDLED WITH
63
+ 2.2.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,666 @@
1
+ # Slugdb
2
+
3
+ A completely Ruby, lightweight, zero dependency, NoSQL, file based databased.
4
+
5
+ I wanted a tiny database for an embedded project that could follow the advanced data modelling techniques for NoSQL. This is basically a very slimmed down SQLite but for NoSQL without any C bindings.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'slugdb'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install slugdb
22
+
23
+ ## Usage
24
+
25
+ First, go watch this: [![AWS re:Invent 2019: Amazon DynamoDB deep dive: Advanced design patterns (DAT403-R1)](https://img.youtube.com/vi/6yqfmXiZTlM/0.jpg)](https://www.youtube.com/watch?v=6yqfmXiZTlM)
26
+
27
+ Then watch it like a dozen more times, it'll click.
28
+
29
+ Basic usage
30
+
31
+ ```ruby
32
+
33
+ require 'slugdb'
34
+ # => true
35
+
36
+ # Create a database
37
+
38
+ sdb = SlugDB.new('./data.slug')
39
+ # => #<SlugDB:0x000055bd9552c238
40
+ # @pstore=
41
+ # #<PStore:0x000055bd9552c210
42
+ # @abort=false,
43
+ # @filename="./data.slug",
44
+ # @lock=#<Thread::Mutex:0x000055bd9552c148>,
45
+ # @rdonly=false,
46
+ # @table={:main=>{}, :indexes=>{}},
47
+ # @thread_safe=false,
48
+ # @ultra_safe=false>>
49
+
50
+ # Put some data in it
51
+
52
+ sdb.put_item(pk: 'awesome#partition#1#', sk: 'metadata#')
53
+ # => {:pk=>"awesome#partition#1#", :sk=>"metadata#"}
54
+
55
+ # Read it back
56
+
57
+ sdb.get_item(pk: 'awesome#partition#1#', sk: 'metadata#')
58
+ # => {:pk=>"awesome#partition#1#", :sk=>"metadata#"}
59
+
60
+ # Put in some more data
61
+
62
+ sdb.put_item(pk: 'awesome#partition#1#', sk: 'something#useful#')
63
+ # => {:pk=>"awesome#partition#1#", :sk=>"something#useful#"}
64
+
65
+ # Query our records
66
+
67
+ sdb.query(pk: 'awesome#partition#1#')
68
+ # => [{:pk=>"awesome#partition#1#", :sk=>"metadata#"},
69
+ # {:pk=>"awesome#partition#1#", :sk=>"something#useful#"}]
70
+ ```
71
+
72
+ Ok, but like... this is useful, how exactly?..
73
+
74
+ > Clearly you didn't watch the YouTube video, it's fine, no one does. Let me read it to you.
75
+
76
+ We're about to solve the following:
77
+ - Get meetings
78
+ - by date and email
79
+ - by date and employee id
80
+ - by date and building/floor/room
81
+ - Load employee dashboard by email
82
+ - get employee data
83
+ - get meetings
84
+ - get tickets
85
+ - get reservations
86
+ - get time cards
87
+ - Get employee info
88
+ - by employed id
89
+ - by email
90
+ - Get ticket history
91
+ - by ticket id
92
+ - by employee email
93
+ - by assignee email
94
+ - Get employees
95
+ - by city, building, floor, aisle, desk
96
+ - by manager
97
+ - Get assigned tickets
98
+ - by email
99
+ - Get tickets
100
+ - by last touched greater than 24 hours ago
101
+ - Get projects
102
+ - by status, start and target date
103
+ - by name
104
+ - Get project history
105
+ - by date range
106
+ - by name
107
+ - Get rooms
108
+ - by building id
109
+ - by availability and time range
110
+
111
+ And like.. its really damn easy. Embrance the datas.
112
+
113
+ Let's go load all them datas into the bases.
114
+
115
+ ```ruby
116
+ ### Create a fresh table
117
+
118
+ sdb = SlugDB.new('./demo.slug')
119
+ # => #<SlugDB:0x00005612d2ad0120
120
+ # @pstore=
121
+ # #<PStore:0x00005612d2ad00f8
122
+ # @abort=false,
123
+ # @filename="./demo.slug",
124
+ # @lock=#<Thread::Mutex:0x00005612d2ad0030>,
125
+ # @rdonly=false,
126
+ # @table={:main=>{}, :indexes=>{}},
127
+ # @thread_safe=false,
128
+ # @ultra_safe=false>>
129
+
130
+ ### Create some indexes
131
+
132
+ sdb.add_index(name: :ski, pk: :sk, sk: :pk)
133
+ # => {:name=>{:pk=>:sk, :sk=>:pk}}
134
+ sdb.add_index(name: :gsi1, pk: :gsi1_pk, sk: :gsi1_sk)
135
+ # => {:name=>{:pk=>:gsi1_pk, :sk=>:gsi1_sk}}
136
+ sdb.add_index(name: :gsi2, pk: :gsi2_pk, sk: :gsi2_sk)
137
+ # => {:name=>{:pk=>:gsi2_pk, :sk=>:gsi2_sk}}
138
+ sdb.add_index(name: :gsi3, pk: :gsi3_pk, sk: :gsi3_sk)
139
+ # => {:name=>{:pk=>:gsi3_pk, :sk=>:gsi3_sk}}
140
+
141
+ ### Create some records
142
+
143
+ sdb.put_item(
144
+ pk: 'yxz58',
145
+ sk: '2021-03-04T10:00:00Z|10.106',
146
+ gsi1_pk: 'john@shields.wtf',
147
+ gsi1_sk: '2021-03-04T10:00:00Z|10.106',
148
+ duration: 30,
149
+ attendees: ['notjohn@shields.wtf', 'john@shields.wtf'],
150
+ subject: 'Discuss Project How does NoSQL?'
151
+ )
152
+ # => {:gsi1_pk=>"john@shields.wtf",
153
+ # :gsi1_sk=>"2021-03-04T10:00:00Z|10.106",
154
+ # :duration=>30,
155
+ # :attendees=>["notjohn@shields.wtf", "john@shields.wtf"],
156
+ # :subject=>"Discuss Project How does NoSQL?",
157
+ # :pk=>"yxz58",
158
+ # :sk=>"2021-03-04T10:00:00Z|10.106"}
159
+ sdb.put_item(
160
+ pk: 'yxz58',
161
+ sk: '2021-03-04T10:15:00Z|10.106',
162
+ attendees: ['notjohn@shields.wtf', 'john@shields.wtf'],
163
+ subject: 'Discuss Project How does NoSQL?',
164
+ organizer: 'john@shields.wtf'
165
+ )
166
+ # => {:attendees=>["notjohn@shields.wtf", "john@shields.wtf"],
167
+ # :subject=>"Discuss Project How does NoSQL?",
168
+ # :organizer=>"john@shields.wtf",
169
+ # :pk=>"yxz58",
170
+ # :sk=>"2021-03-04T10:15:00Z|10.106"}
171
+ sdb.put_item(
172
+ pk: 'yxz58',
173
+ sk: 'rooms',
174
+ room_spec: {
175
+ some: 'data',
176
+ more: 'and more'
177
+ }
178
+ )
179
+ # => {:room_spec=>{:some=>"data", :more=>"and more"}, :pk=>"yxz58", :sk=>"rooms"}
180
+
181
+ sdb.put_item(
182
+ pk: 'employee#1',
183
+ sk: '2021-03-04T10:00:00Z|10.106',
184
+ gsi1_pk: 'notjohn@shields.wtf',
185
+ gsi1_sk: '2021-03-04T10:00:00Z|10.106',
186
+ duration: 30,
187
+ attendees: ['notjohn@shields.wtf', 'john@shields.wtf'],
188
+ subject: 'Discuss Project How does NoSQL?'
189
+ )
190
+ # => {:gsi1_pk=>"notjohn@shields.wtf",
191
+ # :gsi1_sk=>"2021-03-04T10:00:00Z|10.106",
192
+ # :duration=>30,
193
+ # :attendees=>["notjohn@shields.wtf", "john@shields.wtf"],
194
+ # :subject=>"Discuss Project How does NoSQL?",
195
+ # :pk=>"employee#1",
196
+ # :sk=>"2021-03-04T10:00:00Z|10.106"}
197
+ sdb.put_item(
198
+ pk: 'employee#1',
199
+ sk: 'ext#965',
200
+ gsi1_pk: 'notjohn@shields.wtf',
201
+ gsi1_sk: 'ext#965',
202
+ gsi3_pk: 'yxz',
203
+ gsi3_sk: '10.11.123.G9',
204
+ name: 'Not John',
205
+ title: 'Imposter',
206
+ gsi2_pk: 'notjohn@shields.wtf',
207
+ gsi2_sk: nil
208
+ )
209
+ # => {:gsi1_pk=>"notjohn@shields.wtf",
210
+ # :gsi1_sk=>"ext#965",
211
+ # :gsi3_pk=>"yxz",
212
+ # :gsi3_sk=>"10.11.123.G9",
213
+ # :name=>"Not John",
214
+ # :title=>"Imposter",
215
+ # :gsi2_pk=>"notjohn@shields.wtf",
216
+ # :gsi2_sk=>nil,
217
+ # :pk=>"employee#1",
218
+ # :sk=>"ext#965"}
219
+
220
+ sdb.put_item(
221
+ pk: 'employee#2',
222
+ sk: 'ext#293',
223
+ gsi1_pk: 'john@shields.wtf',
224
+ gsi1_sk: 'ext#293',
225
+ gsi3_pk: 'yxz',
226
+ gsi3_sk: '11.10.123.G9',
227
+ name: 'Actual John',
228
+ title: 'Real',
229
+ gsi2_pk: 'john@shields.wtf',
230
+ gsi2_sk: nil
231
+ )
232
+ # => {:gsi1_pk=>"john@shields.wtf",
233
+ # :gsi1_sk=>"ext#293",
234
+ # :gsi3_pk=>"yxz",
235
+ # :gsi3_sk=>"11.10.123.G9",
236
+ # :name=>"Actual John",
237
+ # :title=>"Real",
238
+ # :gsi2_pk=>"john@shields.wtf",
239
+ # :gsi2_sk=>nil,
240
+ # :pk=>"employee#2",
241
+ # :sk=>"ext#293"}
242
+
243
+ sdb.put_item(
244
+ pk: 'Project How does NoSQL?',
245
+ sk: '2021-03-04#john@shields.wtf',
246
+ gsi1_pk: 'john@shields.wtf',
247
+ gsi1_sk: '2021-03-04',
248
+ hours: 12,
249
+ role: 'Lord of Data'
250
+ )
251
+ # => {:gsi1_pk=>"john@shields.wtf",
252
+ # :gsi1_sk=>"2021-03-04",
253
+ # :hours=>12,
254
+ # :role=>"Lord of Data",
255
+ # :pk=>"Project How does NoSQL?",
256
+ # :sk=>"2021-03-04#john@shields.wtf"}
257
+ sdb.put_item(
258
+ pk: 'Project How does NoSQL?',
259
+ sk: '2021-03-04#notjohn@shields.wtf',
260
+ gsi1_pk: 'notjohn@shields.wtf',
261
+ gsi1_sk: '2021-03-04',
262
+ hours: 24,
263
+ role: 'Not as cool'
264
+ )
265
+ # => {:gsi1_pk=>"notjohn@shields.wtf",
266
+ # :gsi1_sk=>"2021-03-04",
267
+ # :hours=>24,
268
+ # :role=>"Not as cool",
269
+ # :pk=>"Project How does NoSQL?",
270
+ # :sk=>"2021-03-04#notjohn@shields.wtf"}
271
+ sdb.put_item(
272
+ pk: 'Project How does NoSQL?',
273
+ sk: 'Project How does NoSQL?',
274
+ gsi1_pk: 'Active',
275
+ gsi1_sk: '2021-02-25',
276
+ description: 'A project, darkly',
277
+ target_delivery: '2021-04-15'
278
+ )
279
+ # => {:gsi1_pk=>"Active",
280
+ # :gsi1_sk=>"2021-02-25",
281
+ # :description=>"A project, darkly",
282
+ # :target_delivery=>"2021-04-15",
283
+ # :pk=>"Project How does NoSQL?",
284
+ # :sk=>"Project How does NoSQL?"}
285
+
286
+ sdb.put_item(
287
+ pk: 'ticket#1',
288
+ sk: '2021-03-04T10:30:29Z',
289
+ gsi1_pk: 'john@shields.wtf',
290
+ gsi1_sk: '2021-03-04T10:30:29Z',
291
+ subject: 'halp',
292
+ gsi3_pk: '7',
293
+ gsi3_sk: '2021-03-04T10:30:29Z',
294
+ gsi2_pk: 'notjohn@shields.wtf',
295
+ gsi2_sk: 'need halps, datas iz hard'
296
+ )
297
+ # => {:gsi1_pk=>"john@shields.wtf",
298
+ # :gsi1_sk=>"2021-03-04T10:30:29Z",
299
+ # :subject=>"halp",
300
+ # :gsi3_pk=>'7',
301
+ # :gsi3_sk=>"2021-03-04T10:30:29Z",
302
+ # :gsi2_pk=>"notjohn@shields.wtf",
303
+ # :gsi2_sk=>"need halps, datas iz hard",
304
+ # :pk=>"ticket#1",
305
+ # :sk=>"2021-03-04T10:30:29Z"}
306
+ sdb.put_item(
307
+ pk: 'ticket#1',
308
+ sk: '2021-03-04T10:35:46Z',
309
+ gsi1_pk: 'john@shields.wtf',
310
+ gsi1_sk: '2021-03-04T10:35:46Z',
311
+ gsi2_pk: 'notjohn@shields.wtf',
312
+ message: 'ack, halps requested'
313
+ )
314
+ # => {:gsi1_pk=>"john@shields.wtf",
315
+ # :gsi1_sk=>"2021-03-04T10:35:46Z",
316
+ # :gsi2_pk=>"notjohn@shields.wtf",
317
+ # :message=>"ack, halps requested",
318
+ # :pk=>"ticket#1",
319
+ # :sk=>"2021-03-04T10:35:46Z"}
320
+
321
+ ### Ok, let's get meetings by date and employee id and toss in a filter for greater than zero duration
322
+
323
+ sdb.query(
324
+ pk: 'employee#1',
325
+ select: ->(sk) { sk >= '2021-03-03T10:00:00Z' && sk <= '2021-03-05T10:00:00Z' },
326
+ filter: ->(item) { !item[:duration].nil? && item[:duration] > 0 }
327
+ )
328
+ # => [{:gsi1_pk=>"notjohn@shields.wtf",
329
+ # :gsi1_sk=>"2021-03-04T10:00:00Z|10.106",
330
+ # :duration=>30,
331
+ # :attendees=>["notjohn@shields.wtf", "john@shields.wtf"],
332
+ # :subject=>"Discuss Project How does NoSQL?",
333
+ # :pk=>"employee#1",
334
+ # :sk=>"2021-03-04T10:00:00Z|10.106"}]
335
+
336
+ ### Neat, now let's get meetings by date a building/floor/room
337
+
338
+ sdb.query(
339
+ pk: 'yxz58',
340
+ select: ->(sk) { sk >= '2021-03-03T10:00:00Z' && sk <= '2021-03-05T10:00:00Z' },
341
+ filter: ->(item) { item[:sk] =~ /\|10\./ }
342
+ )
343
+ # => [{:gsi1_pk=>"john@shields.wtf",
344
+ # :gsi1_sk=>"2021-03-04T10:00:00Z|10.106",
345
+ # :duration=>30,
346
+ # :attendees=>["notjohn@shields.wtf", "john@shields.wtf"],
347
+ # :subject=>"Discuss Project How does NoSQL?",
348
+ # :pk=>"yxz58",
349
+ # :sk=>"2021-03-04T10:00:00Z|10.106"},
350
+ # {:attendees=>["notjohn@shields.wtf", "john@shields.wtf"],
351
+ # :subject=>"Discuss Project How does NoSQL?",
352
+ # :organizer=>"john@shields.wtf",
353
+ # :pk=>"yxz58",
354
+ # :sk=>"2021-03-04T10:15:00Z|10.106"}]
355
+
356
+ ### I'm not a wizard, maybe a sorceror. How about getting employee info by employee id
357
+
358
+ sdb.query(
359
+ pk: 'employee#2',
360
+ select: ->(sk) { sk.start_with?('ext#') }
361
+ )
362
+ # => [{:gsi1_pk=>"john@shields.wtf",
363
+ # :gsi1_sk=>"ext#293",
364
+ # :gsi3_pk=>"yxz",
365
+ # :gsi3_sk=>"11.10.123.G9",
366
+ # :name=>"Actual John",
367
+ # :title=>"Real",
368
+ # :gsi2_pk=>"john@shields.wtf",
369
+ # :gsi2_sk=>nil,
370
+ # :pk=>"employee#2",
371
+ # :sk=>"ext#293"}]
372
+
373
+ ### That was a bit too easy, maybe not a sorceror. Some spell have a long cast time. Where's my ticket history?
374
+
375
+ sdb.query(pk: 'ticket#1')
376
+ # => [{:gsi1_pk=>"john@shields.wtf",
377
+ # :gsi1_sk=>"2021-03-04T10:30:29Z",
378
+ # :subject=>"halp",
379
+ # :gsi3_pk=>'7',
380
+ # :gsi3_sk=>"2021-03-04T10:30:29Z",
381
+ # :gsi2_pk=>"notjohn@shields.wtf",
382
+ # :gsi2_sk=>"need halps, datas iz hard",
383
+ # :pk=>"ticket#1",
384
+ # :sk=>"2021-03-04T10:30:29Z"},
385
+ # {:gsi1_pk=>"john@shields.wtf",
386
+ # :gsi1_sk=>"2021-03-04T10:35:46Z",
387
+ # :gsi2_pk=>"notjohn@shields.wtf",
388
+ # :message=>"ack, halps requested",
389
+ # :pk=>"ticket#1",
390
+ # :sk=>"2021-03-04T10:35:46Z"}]
391
+
392
+ ### Yeah.. a little **too** easy, right? Can I get project info?
393
+
394
+ sdb.query(
395
+ pk: 'Project How does NoSQL?',
396
+ select: ->(sk) { sk == 'Project How does NoSQL?' }
397
+ )
398
+ # => [{:gsi1_pk=>"Active",
399
+ # :gsi1_sk=>"2021-02-25",
400
+ # :description=>"A project, darkly",
401
+ # :target_delivery=>"2021-04-15",
402
+ # :pk=>"Project How does NoSQL?",
403
+ # :sk=>"Project How does NoSQL?"}]
404
+
405
+ ### I'm wondering if I even NoSQL? Can I get project history?
406
+
407
+ sdb.query(
408
+ pk: 'Project How does NoSQL?',
409
+ select: ->(sk) { sk >= '2021-03-03' && sk <= '2021-03-05' }
410
+ )
411
+ # => [{:gsi1_pk=>"john@shields.wtf",
412
+ # :gsi1_sk=>"2021-03-04",
413
+ # :hours=>12,
414
+ # :role=>"Lord of Data",
415
+ # :pk=>"Project How does NoSQL?",
416
+ # :sk=>"2021-03-04#john@shields.wtf"},
417
+ # {:gsi1_pk=>"notjohn@shields.wtf",
418
+ # :gsi1_sk=>"2021-03-04",
419
+ # :hours=>24,
420
+ # :role=>"Not as cool",
421
+ # :pk=>"Project How does NoSQL?",
422
+ # :sk=>"2021-03-04#notjohn@shields.wtf"}]
423
+
424
+ ### I think I can NoSQL, gimme dem projects by role
425
+
426
+ sdb.query(
427
+ pk: 'Project How does NoSQL?',
428
+ filter: ->(item) { item[:role] == 'Lord of Data' }
429
+ )
430
+ # => [{:gsi1_pk=>"john@shields.wtf",
431
+ # :gsi1_sk=>"2021-03-04",
432
+ # :hours=>12,
433
+ # :role=>"Lord of Data",
434
+ # :pk=>"Project How does NoSQL?",
435
+ # :sk=>"2021-03-04#john@shields.wtf"}]
436
+
437
+ ### I still have way more to, I need a seat, got a room that'll work?
438
+
439
+ sdb.query(
440
+ pk: 'yxz58',
441
+ select: ->(sk) { sk == 'rooms' }
442
+ )
443
+ # => [{:room_spec=>
444
+ # {:some=>"data",
445
+ # :more=>"and more"},
446
+ # :pk=>"yxz58",
447
+ # :sk=>"rooms"}]
448
+
449
+ ### Nice, is that room available?
450
+
451
+ sdb.query(
452
+ pk: 'yxz58',
453
+ select: ->(sk) { sk >= '2021-03-03T09:00:00Z' && sk <= '2021-03-05T18:00:00Z' }
454
+ )
455
+ # => [{:gsi1_pk=>"john@shields.wtf",
456
+ # :gsi1_sk=>"2021-03-04T10:00:00Z|10.106",
457
+ # :duration=>30,
458
+ # :attendees=>["notjohn@shields.wtf", "john@shields.wtf"],
459
+ # :subject=>"Discuss Project How does NoSQL?",
460
+ # :pk=>"yxz58",
461
+ # :sk=>"2021-03-04T10:00:00Z|10.106"},
462
+ # {:attendees=>["notjohn@shields.wtf", "john@shields.wtf"],
463
+ # :subject=>"Discuss Project How does NoSQL?",
464
+ # :organizer=>"john@shields.wtf",
465
+ # :pk=>"yxz58",
466
+ # :sk=>"2021-03-04T10:15:00Z|10.106"}]
467
+
468
+
469
+ ### Book it! But, am I busy? My sorcery is bubbling up...
470
+
471
+ sdb.query(
472
+ index: :gsi1,
473
+ pk: 'john@shields.wtf',
474
+ select: ->(sk) { sk >= '2021-03-03T09:00:00Z' && sk <= '2021-03-05T18:00:00Z' },
475
+ filter: ->(item) { !item[:duration].nil? && item[:duration] > 0 }
476
+ )
477
+ # => [{:gsi1_pk=>"john@shields.wtf",
478
+ # :gsi1_sk=>"2021-03-04T10:00:00Z|10.106",
479
+ # :duration=>30,
480
+ # :attendees=>["notjohn@shields.wtf", "john@shields.wtf"],
481
+ # :subject=>"Discuss Project How does NoSQL?",
482
+ # :pk=>"yxz58",
483
+ # :sk=>"2021-03-04T10:00:00Z|10.106"}]
484
+
485
+ ### MMMM.. Dems some good datas. Gimme more datas!! I need to render a dashbaord
486
+
487
+ sdb.query(
488
+ index: :gsi1,
489
+ pk: 'john@shields.wtf',
490
+ select: ->(sk) { sk >= '2021-02-03T09:00:00Z' }
491
+ )
492
+ # => [{:gsi1_pk=>"john@shields.wtf",
493
+ # :gsi1_sk=>"2021-03-04T10:00:00Z|10.106",
494
+ # :duration=>30,
495
+ # :attendees=>["notjohn@shields.wtf", "john@shields.wtf"],
496
+ # :subject=>"Discuss Project How does NoSQL?",
497
+ # :pk=>"yxz58",
498
+ # :sk=>"2021-03-04T10:00:00Z|10.106"},
499
+ # {:gsi1_pk=>"john@shields.wtf",
500
+ # :gsi1_sk=>"ext#293",
501
+ # :gsi3_pk=>"yxz",
502
+ # :gsi3_sk=>"11.10.123.G9",
503
+ # :name=>"Actual John",
504
+ # :title=>"Real",
505
+ # :gsi2_pk=>"john@shields.wtf",
506
+ # :gsi2_sk=>nil,
507
+ # :pk=>"employee#2",
508
+ # :sk=>"ext#293"},
509
+ # {:gsi1_pk=>"john@shields.wtf",
510
+ # :gsi1_sk=>"2021-03-04",
511
+ # :hours=>12,
512
+ # :role=>"Lord of Data",
513
+ # :pk=>"Project How does NoSQL?",
514
+ # :sk=>"2021-03-04#john@shields.wtf"},
515
+ # {:gsi1_pk=>"john@shields.wtf",
516
+ # :gsi1_sk=>"2021-03-04T10:30:29Z",
517
+ # :subject=>"halp",
518
+ # :gsi3_pk=>'7',
519
+ # :gsi3_sk=>"2021-03-04T10:30:29Z",
520
+ # :gsi2_pk=>"notjohn@shields.wtf",
521
+ # :gsi2_sk=>"need halps, datas iz hard",
522
+ # :pk=>"ticket#1",
523
+ # :sk=>"2021-03-04T10:30:29Z"},
524
+ # {:gsi1_pk=>"john@shields.wtf",
525
+ # :gsi1_sk=>"2021-03-04T10:35:46Z",
526
+ # :gsi2_pk=>"notjohn@shields.wtf",
527
+ # :message=>"ack, halps requested",
528
+ # :pk=>"ticket#1",
529
+ # :sk=>"2021-03-04T10:35:46Z"}]
530
+
531
+ ### Truly magical! Hit with some more info
532
+
533
+ sdb.query(
534
+ index: :gsi1,
535
+ pk: 'john@shields.wtf',
536
+ select: ->(sk) { sk.start_with?('ext#') }
537
+ )
538
+ # => [{:gsi1_pk=>"john@shields.wtf",
539
+ # :gsi1_sk=>"ext#293",
540
+ # :gsi3_pk=>"yxz",
541
+ # :gsi3_sk=>"11.10.123.G9",
542
+ # :name=>"Actual John",
543
+ # :title=>"Real",
544
+ # :gsi2_pk=>"john@shields.wtf",
545
+ # :gsi2_sk=>nil,
546
+ # :pk=>"employee#2",
547
+ # :sk=>"ext#293"}]
548
+
549
+ ### Delicious, how about some ticket history?
550
+
551
+ sdb.query(
552
+ index: :gsi1,
553
+ pk: 'john@shields.wtf',
554
+ filter: ->(item) { item[:pk] == 'ticket#1' }
555
+ )
556
+ # => [{:gsi1_pk=>"john@shields.wtf",
557
+ # :gsi1_sk=>"2021-03-04T10:30:29Z",
558
+ # :subject=>"halp",
559
+ # :gsi3_pk=>'7',
560
+ # :gsi3_sk=>"2021-03-04T10:30:29Z",
561
+ # :gsi2_pk=>"notjohn@shields.wtf",
562
+ # :gsi2_sk=>"need halps, datas iz hard",
563
+ # :pk=>"ticket#1",
564
+ # :sk=>"2021-03-04T10:30:29Z"},
565
+ # {:gsi1_pk=>"john@shields.wtf",
566
+ # :gsi1_sk=>"2021-03-04T10:35:46Z",
567
+ # :gsi2_pk=>"notjohn@shields.wtf",
568
+ # :message=>"ack, halps requested",
569
+ # :pk=>"ticket#1",
570
+ # :sk=>"2021-03-04T10:35:46Z"}]
571
+
572
+ ### Is it setting in yet? How much you totally don't know about NoSQL? Can you riddle me this? What active projects do I have?
573
+
574
+ sdb.query(
575
+ index: :gsi1,
576
+ pk: 'Active',
577
+ select: ->(sk) { sk >= '2021-02-25' },
578
+ filter: ->(item) { item[:target_delivery] < '2021-05-01' }
579
+ )
580
+ # => [{:gsi1_pk=>"Active",
581
+ # :gsi1_sk=>"2021-02-25",
582
+ # :description=>"A project, darkly",
583
+ # :target_delivery=>"2021-04-15",
584
+ # :pk=>"Project How does NoSQL?",
585
+ # :sk=>"Project How does NoSQL?"}]
586
+
587
+ ### We're still not done yet, we've only used a single index so far. Give me the ticket history by assignee
588
+
589
+ sdb.query(
590
+ index: :gsi2,
591
+ pk: 'notjohn@shields.wtf',
592
+ filter: ->(item) { item[:pk] == 'ticket#1' }
593
+ )
594
+ # => [{:gsi1_pk=>"john@shields.wtf",
595
+ # :gsi1_sk=>"2021-03-04T10:30:29Z",
596
+ # :subject=>"halp",
597
+ # :gsi3_pk=>'7',
598
+ # :gsi3_sk=>"2021-03-04T10:30:29Z",
599
+ # :gsi2_pk=>"notjohn@shields.wtf",
600
+ # :gsi2_sk=>"need halps, datas iz hard",
601
+ # :pk=>"ticket#1",
602
+ # :sk=>"2021-03-04T10:30:29Z"}]
603
+
604
+ ### Neato, I'm still not out of tricks. Can you give me all employees by location?
605
+
606
+ sdb.query(
607
+ index: :gsi3,
608
+ pk: 'yxz',
609
+ select: ->(sk) { sk.start_with?('10.11') }
610
+ )
611
+ # => [{:gsi1_pk=>"notjohn@shields.wtf",
612
+ # :gsi1_sk=>"ext#965",
613
+ # :gsi3_pk=>"yxz",
614
+ # :gsi3_sk=>"10.11.123.G9",
615
+ # :name=>"Not John",
616
+ # :title=>"Imposter",
617
+ # :gsi2_pk=>"notjohn@shields.wtf",
618
+ # :gsi2_sk=>nil,
619
+ # :pk=>"employee#1",
620
+ # :sk=>"ext#965"},
621
+ # {:gsi1_pk=>"john@shields.wtf",
622
+ # :gsi1_sk=>"ext#293",
623
+ # :gsi3_pk=>"yxz",
624
+ # :gsi3_sk=>"10.11.124.G9",
625
+ # :name=>"Actual John",
626
+ # :title=>"Real",
627
+ # :gsi2_pk=>"john@shields.wtf",
628
+ # :gsi2_sk=>nil,
629
+ # :pk=>"employee#2",
630
+ # :sk=>"ext#293"}]
631
+
632
+ ### Final trick.. for now.. show me all the tickets that haven't bene dealt with recently
633
+
634
+ sdb.query(
635
+ index: :gsi3,
636
+ pk: '7',
637
+ select: ->(sk) { sk < '2021-03-06T10:30:29Z' }
638
+ )
639
+ # => [{:gsi1_pk=>"john@shields.wtf",
640
+ # :gsi1_sk=>"2021-03-04T10:30:29Z",
641
+ # :subject=>"halp",
642
+ # :gsi3_pk=>'7',
643
+ # :gsi3_sk=>"2021-03-04T10:30:29Z",
644
+ # :gsi2_pk=>"notjohn@shields.wtf",
645
+ # :gsi2_sk=>"need halps, datas iz hard",
646
+ # :pk=>"ticket#1",
647
+ # :sk=>"2021-03-04T10:30:29Z"}]
648
+ ```
649
+
650
+ ## Development
651
+
652
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
653
+
654
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
655
+
656
+ ## Contributing
657
+
658
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/slugdb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/slugdb/blob/master/CODE_OF_CONDUCT.md).
659
+
660
+ ## License
661
+
662
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
663
+
664
+ ## Code of Conduct
665
+
666
+ Everyone interacting in the Slugdb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/slugdb/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ def empty_directory(directory)
8
+ FileUtils.remove_entry(directory)
9
+ FileUtils.mkdir(directory)
10
+ end
11
+
12
+ # clean up the workspace
13
+ task(:clean) do
14
+ empty_directory('doc')
15
+ empty_directory('out')
16
+ empty_directory('pkg')
17
+ end
18
+
19
+ RSpec::Core::RakeTask.new(:spec)
20
+ RuboCop::RakeTask.new
21
+
22
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'slugdb'
6
+
7
+ require 'tempfile'
8
+
9
+ # You can add fixtures and/or initialization code here to make experimenting
10
+ # with your gem easier. You can also use a different console, if you like.
11
+
12
+ Tempfile.create do |db_file|
13
+ @db = SlugDB.new(db_file)
14
+ require 'pry'
15
+ Pry.start
16
+ end
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/slugdb.rb ADDED
@@ -0,0 +1,142 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pstore'
4
+ require_relative 'slugdb/version'
5
+
6
+ ##
7
+ # Zero dependecy NoSQL, file based database
8
+ class SlugDB
9
+ def initialize(file, thread_safe: false, ultra_safe: false)
10
+ @pstore = PStore.new(file, thread_safe).tap { |s| s.ultra_safe = ultra_safe }
11
+ @pstore.transaction do |db|
12
+ db[:main] ||= {}
13
+ db[:indexes] ||= {}
14
+ end
15
+ end
16
+
17
+ def reindex!
18
+ indexes = list_indexes
19
+ @pstore.transaction { |db| db[:main] }.each do |pk, records|
20
+ records.each do |sk, record|
21
+ @pstore.transaction do |db|
22
+ indexes.each do |name, schema|
23
+ index_item(db, record.merge(pk: pk, sk: sk), name, schema)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ nil
30
+ end
31
+
32
+ def add_index(name:, pk:, sk:) # rubocop:disable Naming/MethodParameterName
33
+ @pstore.transaction do |db|
34
+ db[:indexes] ||= {}
35
+ db[:indexes][name] = { pk: pk, sk: sk }
36
+ end
37
+ reindex!
38
+
39
+ { name: { pk: pk, sk: sk } }
40
+ end
41
+
42
+ def list_indexes
43
+ @pstore.transaction { |db| db[:indexes] }
44
+ end
45
+
46
+ def list_partitions
47
+ @pstore.transaction { |db| db[:main].keys }
48
+ end
49
+
50
+ def get_item(pk:, sk:) # rubocop:disable Naming/MethodParameterName
51
+ @pstore.transaction do |db|
52
+ next if db[:main][pk].nil? || db[:main][pk][sk].nil?
53
+
54
+ db[:main][pk][sk]
55
+ end
56
+ end
57
+
58
+ def put_item(pk:, sk:, **attributes) # rubocop:disable Naming/MethodParameterName
59
+ item = attributes.merge(pk: pk, sk: sk)
60
+ indexes = list_indexes
61
+
62
+ @pstore.transaction do |db|
63
+ db[:main][pk] ||= {}
64
+ db[:main][pk][sk] = item
65
+ indexes.each { |name, schema| index_item(db, item, name, schema) }
66
+ end
67
+
68
+ item
69
+ end
70
+
71
+ # rubocop:disable Naming/MethodParameterName,Metrics/AbcSize
72
+ def delete_item(pk:, sk:, **_)
73
+ item = get_item(pk: pk, sk: sk)
74
+ return if item.nil?
75
+
76
+ indexes = list_indexes
77
+ @pstore.transaction do |db|
78
+ db[:main][pk].delete(sk)
79
+ db[:main].delete(pk) if db[:main][pk].empty?
80
+
81
+ indexes.each do |name, schema|
82
+ next unless item.key?(schema[:pk]) && item.key?(schema[:sk])
83
+
84
+ db[name][item[schema[:pk]]][item[schema[:sk]]][item[:pk]].delete(item[:sk])
85
+ delete_if_empty?(db[name][item[schema[:pk]]][item[schema[:sk]]], item[:pk])
86
+ delete_if_empty?(db[name][item[schema[:pk]]], item[schema[:sk]])
87
+ delete_if_empty?(db[name], item[schema[:pk]])
88
+ end
89
+ end
90
+
91
+ item
92
+ end
93
+ # rubocop:enable Naming/MethodParameterName,Metrics/AbcSize
94
+
95
+ # rubocop:disable Lint/UnusedBlockArgument,Naming/MethodParameterName
96
+ # rubocop:disable Metrics/PerceivedComplexity,Metrics/MethodLength
97
+ # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize,
98
+ def query(pk:, index: :main, select: ->(sk) { true }, filter: ->(item) { true })
99
+ if index == :main
100
+ @pstore.transaction do |db|
101
+ db[index]
102
+ .fetch(pk, {})
103
+ .map { |_, records| records }
104
+ .select { |item| select[item[:sk]] }
105
+ .filter { |item| filter[item] }
106
+ end
107
+ else
108
+ name, schema = list_indexes.find { |name,| name == index }
109
+ @pstore.transaction do |db|
110
+ db[name]
111
+ .fetch(pk, {})
112
+ .map do |_, isk_records|
113
+ isk_records.map do |_, pk_records|
114
+ pk_records.map { |_, sk_records| sk_records }
115
+ end
116
+ end # rubocop:disable Style/MultilineBlockChain
117
+ .flatten(2)
118
+ .select { |item| select[item[schema[:sk]]] }
119
+ .filter { |item| filter[item] }
120
+ end
121
+ end
122
+ end
123
+ # rubocop:enable Lint/UnusedBlockArgument,Naming/MethodParameterName
124
+ # rubocop:enable Metrics/PerceivedComplexity,Metrics/MethodLength
125
+ # rubocop:enable Metrics/CyclomaticComplexity,Metrics/AbcSize
126
+
127
+ private
128
+
129
+ def index_item(db, item, name, schema) # rubocop:disable Metrics/AbcSize
130
+ return unless item.key?(schema[:pk]) && item.key?(schema[:sk])
131
+
132
+ db[name] ||= {}
133
+ db[name][item[schema[:pk]]] ||= {}
134
+ db[name][item[schema[:pk]]][item[schema[:sk]]] ||= {}
135
+ db[name][item[schema[:pk]]][item[schema[:sk]]][item[:pk]] ||= {}
136
+ db[name][item[schema[:pk]]][item[schema[:sk]]][item[:pk]][item[:sk]] = item
137
+ end
138
+
139
+ def delete_if_empty?(hash, key)
140
+ hash.delete(key) if hash[key].empty?
141
+ end
142
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SlugDB
4
+ VERSION = '0.1.0'
5
+ end
data/slugdb.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/slugdb/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'slugdb'
7
+ spec.version = SlugDB::VERSION
8
+ spec.authors = ['John Shields <watmin>']
9
+ spec.email = ['john@shields.wtf']
10
+
11
+ spec.summary = 'A lightweight, opinionated, file based NoSQL database.'
12
+ spec.description = 'I wanted sqlite with a document store.'
13
+ spec.homepage = 'https://github.com/watmin/Ruby-slugdb'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
16
+
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_development_dependency 'gem-release'
29
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slugdb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John Shields <watmin>
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gem-release
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: I wanted sqlite with a document store.
28
+ email:
29
+ - john@shields.wtf
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - ".travis.yml"
38
+ - CODE_OF_CONDUCT.md
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - bin/console
45
+ - bin/setup
46
+ - lib/slugdb.rb
47
+ - lib/slugdb/version.rb
48
+ - slugdb.gemspec
49
+ homepage: https://github.com/watmin/Ruby-slugdb
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ allowed_push_host: https://rubygems.org
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.5.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.2.3
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: A lightweight, opinionated, file based NoSQL database.
73
+ test_files: []