file_db 1.0.0 → 1.1.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 +3 -3
- data/lib/file_db/query.rb +6 -2
- data/lib/file_db/system/table.rb +19 -0
- data/lib/file_db/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc4e8dd718db7789387f56d6284c765a7998676f
|
4
|
+
data.tar.gz: 4ca6334901b89f66146b8fcbaa9ca88b45d8d1bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b27f62a9ba6677a138ceb7952301af59341023e1b41e7aeda81b69ecbebe6069835edc0d639aaf91327d7abee790c315457afdbe7dd15e0df56d55f79e51eb1
|
7
|
+
data.tar.gz: f4d2aff276e4d3300a246d4a9e293f4bb6e795f858bf2b4948781a17867a3b2d9dc5385b0c1cc858eb235904022511baef9adf4da6dbc07cce5d396821c453c3
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ FileDb is a small type of database. It stores all data for a model into CSV file
|
|
7
7
|
hm, yeah. just add this to your Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'file_db', '~> 1.
|
10
|
+
gem 'file_db', '~> 1.1.0'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -44,7 +44,7 @@ And:
|
|
44
44
|
|
45
45
|
| Action | Time in Milliseconds |
|
46
46
|
|---|---|
|
47
|
-
|getting the first|
|
47
|
+
|getting the first|0.031|
|
48
48
|
|update record|4.629|
|
49
49
|
|create record|3.673|
|
50
50
|
|using where with 1 parameter|0.535|
|
@@ -66,7 +66,7 @@ And:
|
|
66
66
|
|
67
67
|
| Action | Time in Milliseconds |
|
68
68
|
|---|---|
|
69
|
-
|getting the first|
|
69
|
+
|getting the first|0.037|
|
70
70
|
|update record|14.405|
|
71
71
|
|create record|9.705|
|
72
72
|
|using where with 1 parameter|1.846|
|
data/lib/file_db/query.rb
CHANGED
@@ -8,11 +8,15 @@ module FileDb
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def first
|
11
|
-
|
11
|
+
found_element = table.first
|
12
|
+
return unless found_element
|
13
|
+
new found_element
|
12
14
|
end
|
13
15
|
|
14
16
|
def last
|
15
|
-
|
17
|
+
found_element = table.last
|
18
|
+
return unless found_element
|
19
|
+
new found_element
|
16
20
|
end
|
17
21
|
|
18
22
|
def all
|
data/lib/file_db/system/table.rb
CHANGED
@@ -5,6 +5,7 @@ module FileDb
|
|
5
5
|
def initialize filename, database
|
6
6
|
@filename = filename
|
7
7
|
@database = database
|
8
|
+
@specific_records = {}
|
8
9
|
@entries_index_by = {}
|
9
10
|
@entries_index_by[:id] = {}
|
10
11
|
@fields = {}
|
@@ -30,6 +31,14 @@ module FileDb
|
|
30
31
|
hashed_by_id.values
|
31
32
|
end
|
32
33
|
|
34
|
+
def first
|
35
|
+
hashed_by_id[@specific_records[:first_id]]
|
36
|
+
end
|
37
|
+
|
38
|
+
def last
|
39
|
+
hashed_by_id[@specific_records[:last_id]]
|
40
|
+
end
|
41
|
+
|
33
42
|
def where conditions
|
34
43
|
found_elements = all
|
35
44
|
conditions.each do |key, value|
|
@@ -65,6 +74,7 @@ module FileDb
|
|
65
74
|
object.id = data_to_save[:id]
|
66
75
|
end
|
67
76
|
@entries_index_by[:id][object.id.to_s] = data_to_save
|
77
|
+
set_specific_index object.id
|
68
78
|
save_records!
|
69
79
|
end
|
70
80
|
|
@@ -102,6 +112,15 @@ module FileDb
|
|
102
112
|
key_name = remove_line_break(entry[@fieldnames[:id]])
|
103
113
|
|
104
114
|
@entries_index_by[:id][key_name.to_s] = t_entry
|
115
|
+
set_specific_index key_name
|
116
|
+
end
|
117
|
+
|
118
|
+
def set_specific_index id
|
119
|
+
@specific_records[:first_id] ||= id.to_s
|
120
|
+
@specific_records[:last_id] ||= id.to_s
|
121
|
+
if @specific_records[:last_id].to_i < id.to_i
|
122
|
+
@specific_records[:last_id] = id.to_s
|
123
|
+
end
|
105
124
|
end
|
106
125
|
|
107
126
|
def remove_line_break value
|
data/lib/file_db/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Starke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|