sqlite3_hash 1.0.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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/sqlite3_hash.rb +367 -0
- data/lib/sqlite3_hash/version.rb +3 -0
- data/sqlite3_hash.gemspec +35 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 07d1d1ce69db0d02ce3b805a4b052fe98054ee30
|
4
|
+
data.tar.gz: 8938ff1f168af62aa921688214839c4b9b789859
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 02b0ed65f1a3ef07cd6bd32152099e626d52b68cb1b8054f5337ce4b2f4b3b8b45d25d94ba816e5adfd5cfad6df7335725206cc792737753a2469d46d1c04eda
|
7
|
+
data.tar.gz: 9a9d574781ffce90a30b93eee82a05a8f60b7b089f8ea00952a3401b7798d465abf195c2fccecacaf3136ee87355dfc1164cc9614351479a634fe465aabb550e
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 David Ljung Madison Stellar
|
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,83 @@
|
|
1
|
+
# Sqlite3Hash
|
2
|
+
|
3
|
+
A persistent simple Hash backed by sqlite3
|
4
|
+
|
5
|
+
Contains (almost) the same features/API as the Ruby 2.0.0 Hash object
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'sqlite3_hash'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install sqlite3_hash
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
SQLite3Hash is a persistent simple Hash backed by sqlite3.
|
26
|
+
|
27
|
+
You can use it like a Hash object, but all data is stored in SQLite3,
|
28
|
+
which can be re-used over multiple instantiations of ruby.
|
29
|
+
|
30
|
+
Example case:
|
31
|
+
|
32
|
+
require 'sqlite3_hash'
|
33
|
+
|
34
|
+
shash = SQLite3Hash.new('tmpfile.db')
|
35
|
+
shash['int'] = 42
|
36
|
+
shash[:sym] = { a: 12, b: 32 }
|
37
|
+
shash[99.1] = [1,[10,20],3]
|
38
|
+
shash = nil
|
39
|
+
|
40
|
+
# Some point later.. or even in another ruby instance:
|
41
|
+
shash = SQLite3Hash.new('tmpfile.db')
|
42
|
+
shash['int'] # => 42
|
43
|
+
shash.to_s # => {"int"=>42, :sym=>{:a=>12, :b=>32}, 99.1=>[1, [10, 20], 3]}
|
44
|
+
|
45
|
+
Handles values of String, Fixnum, Float, and anything that can be Marshalled
|
46
|
+
|
47
|
+
Keys are anything that can be Marshalled.
|
48
|
+
|
49
|
+
This means, for example, that you *cannot* store Procs in an SQLite3Hash
|
50
|
+
|
51
|
+
Contains all the Hash class methods from 2.0.0 except:
|
52
|
+
|
53
|
+
1. No deprecated methods
|
54
|
+
2. Methods not implemented: rehash, compare_by_identity, SQLite3Hash[]
|
55
|
+
3. Methods that are supposed to return a hash do so (instead of returning an SQLite3Hash), for example 'to_h'
|
56
|
+
4. try_convert also requires db and other parameters as per SQLite3Hash.new
|
57
|
+
5. Uses the value of an object instead of the object as a key
|
58
|
+
|
59
|
+
For example:
|
60
|
+
|
61
|
+
a = [ "a", "b" ]
|
62
|
+
h = { a => 100 }
|
63
|
+
sh = SQLite3Hash('tmp.db')
|
64
|
+
a[0] = 'z'
|
65
|
+
h # => {["z", "b"]=>100}
|
66
|
+
sh # => {["a", "b"]=>100}
|
67
|
+
|
68
|
+
|
69
|
+
## Development
|
70
|
+
|
71
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
72
|
+
|
73
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/daveola/sqlite3_hash.
|
78
|
+
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
83
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
## Default directory to look in is `/specs`
|
5
|
+
## Run with `rake spec`
|
6
|
+
#RSpec::Core::RakeTask.new(:spec) do |task|
|
7
|
+
# #task.rspec_opts = ['--color', '--format', 'documentation']
|
8
|
+
#end
|
9
|
+
|
10
|
+
|
11
|
+
task :default => :spec
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sqlite3_hash"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/sqlite3_hash.rb
ADDED
@@ -0,0 +1,367 @@
|
|
1
|
+
require "sqlite3_hash/version"
|
2
|
+
|
3
|
+
# Filename: sqlite3hash.rb
|
4
|
+
# Author: David Ljung Madison <DaveSource.com>
|
5
|
+
# See License: http://MarginalHacks.com/License/
|
6
|
+
# Description: An sqlite3 backed simple hash in ruby
|
7
|
+
#
|
8
|
+
# Handles values of String, Fixnum, Float, and anything that can be Marshalled
|
9
|
+
# Keys are anything that can be Marshalled
|
10
|
+
# This means, for example, that you cannot store Procs in an SQLite3Hash
|
11
|
+
#
|
12
|
+
# Contains all the Hash class methods from 2.0.0 except:
|
13
|
+
# 1) No deprecated methods
|
14
|
+
# 2) Methods not implemented: rehash, compare_by_identity, SQLite3Hash[]
|
15
|
+
# 3) Methods that are supposed to return a hash do so (instead of
|
16
|
+
# returning an SQLite3Hash), for example 'to_h'
|
17
|
+
# 4) try_convert also requires db and other parameters as per SQLite3Hash.new
|
18
|
+
# 5) Uses the value of an object instead of the object as a key, i.e.:
|
19
|
+
# a = [ "a", "b" ]
|
20
|
+
# h = { a => 100 }
|
21
|
+
# sh = SQLite3Hash('tmp.db')
|
22
|
+
# a[0] = 'z'
|
23
|
+
# h # => {["z", "b"]=>100}
|
24
|
+
# sh # => {["a", "b"]=>100}
|
25
|
+
|
26
|
+
require 'sqlite3'
|
27
|
+
|
28
|
+
class SQLite3Hash
|
29
|
+
class MissingDBPath < StandardError
|
30
|
+
def initialize(msg="Need to specify DB path for SQLite3Hash") super; end
|
31
|
+
end
|
32
|
+
|
33
|
+
# new(db)
|
34
|
+
# new(db, default_obj)
|
35
|
+
# new(db, hash)
|
36
|
+
# new(db, default_obj, table_name)
|
37
|
+
# new(db, hash, table_name)
|
38
|
+
# All of the above with block specified (default_proc)
|
39
|
+
def initialize(db=nil, init=nil, table='sqlite3hash', &default_proc)
|
40
|
+
raise SQLite3Hash::MissingDBPath unless db
|
41
|
+
@db = db
|
42
|
+
|
43
|
+
@sqldb = SQLite3::Database.open(@db)
|
44
|
+
|
45
|
+
# Handle args
|
46
|
+
@default = (init.class==Hash) ? nil : init
|
47
|
+
@default_proc = block_given? ? default_proc : nil
|
48
|
+
|
49
|
+
# Safely quote table
|
50
|
+
@table = table
|
51
|
+
@table = table.gsub( /'/, "''" )
|
52
|
+
|
53
|
+
createTable
|
54
|
+
|
55
|
+
# Init from hash
|
56
|
+
init.each { |k,v| set(k,v) } if init.class==Hash
|
57
|
+
end
|
58
|
+
|
59
|
+
# Like 'new' but we call try_convert
|
60
|
+
def SQLite3Hash.try_convert(incoming, *args)
|
61
|
+
shash = SQLite3Hash.new(*args)
|
62
|
+
return shash unless incoming
|
63
|
+
h = Hash.try_convert(incoming)
|
64
|
+
return shash unless h
|
65
|
+
h.each { |k,v| shash[k]=v }
|
66
|
+
shash
|
67
|
+
end
|
68
|
+
|
69
|
+
def [](key)
|
70
|
+
return nil unless @sqldb
|
71
|
+
row = @sqldb.get_first_row( "select * from '#{@table}' where key = ?", Marshal.dump(key))
|
72
|
+
row ? (row2value(row)) : default(key)
|
73
|
+
end
|
74
|
+
alias :get :[]
|
75
|
+
alias :read :[]
|
76
|
+
def default(key=nil)
|
77
|
+
(key && @default_proc) ? @default_proc.call(self,key) : @default
|
78
|
+
end
|
79
|
+
def default=(v)
|
80
|
+
@default = v
|
81
|
+
end
|
82
|
+
def default_proc
|
83
|
+
@default_proc
|
84
|
+
end
|
85
|
+
def assoc(key)
|
86
|
+
has_key?(key) ? [key,get(key)] : nil
|
87
|
+
end
|
88
|
+
def rassoc(value)
|
89
|
+
key = key(value)
|
90
|
+
key ? [key,value] : nil
|
91
|
+
end
|
92
|
+
|
93
|
+
def []=(key,value)
|
94
|
+
return unless @sqldb
|
95
|
+
# Unlike a Hash, can't store with key nil, we could use quoting to change this if needed
|
96
|
+
return unless key
|
97
|
+
|
98
|
+
rows = {
|
99
|
+
'valueString' => nil,
|
100
|
+
'valueSymbol' => nil,
|
101
|
+
'valueFixnum' => nil,
|
102
|
+
'valueFloat' => nil,
|
103
|
+
'valueMarshal' => nil,
|
104
|
+
}
|
105
|
+
rowname,value = rowValue(value)
|
106
|
+
rows[rowname] = value
|
107
|
+
keys = ['key']
|
108
|
+
# Key is always marshalled - it can be many types and needs to be a unique index
|
109
|
+
values = [Marshal.dump(key)]
|
110
|
+
rows.each { |k,v|
|
111
|
+
keys.push(k)
|
112
|
+
values.push(v)
|
113
|
+
}
|
114
|
+
@sqldb.execute("insert or replace into '#{@table}'(#{keys.join(',')}) VALUES(#{(['?']*values.size).join(',')})",*values)
|
115
|
+
end
|
116
|
+
alias :set :[]=
|
117
|
+
alias :write :[]=
|
118
|
+
alias :hsh :[]=
|
119
|
+
alias :store :[]=
|
120
|
+
|
121
|
+
def fetch(key,default = nil)
|
122
|
+
v = get(key)
|
123
|
+
return v if v
|
124
|
+
return default if default
|
125
|
+
return yield(key) if block_given?
|
126
|
+
return raise KeyError
|
127
|
+
end
|
128
|
+
|
129
|
+
def each
|
130
|
+
return Enumerator.new { |y| rows { |row| y.yield(Marshal.load(row[0]),row2value(row)) } } unless block_given?
|
131
|
+
rows { |row| yield(Marshal.load(row[0]),row2value(row)) }
|
132
|
+
end
|
133
|
+
alias :each_pair :each
|
134
|
+
|
135
|
+
def each_key
|
136
|
+
return Enumerator.new { |y| rows { |row| y.yield(Marshal.load(row[0])) } } unless block_given?
|
137
|
+
rows { |row| yield(Marshal.load(row[0])) }
|
138
|
+
end
|
139
|
+
def each_value
|
140
|
+
return Enumerator.new { |y| rows { |row| y.yield(row2value(row)) } } unless block_given?
|
141
|
+
rows { |row| yield(row2value(row)) }
|
142
|
+
end
|
143
|
+
def keys
|
144
|
+
rows.map { |row| Marshal.load(row[0]) }
|
145
|
+
end
|
146
|
+
def values
|
147
|
+
rows.map { |row| row2value(row) }
|
148
|
+
end
|
149
|
+
# Values for a given set of keys
|
150
|
+
def values_at(*keys)
|
151
|
+
keys.map { |key| get(key) }
|
152
|
+
end
|
153
|
+
|
154
|
+
def flatten(level=1)
|
155
|
+
arr = []
|
156
|
+
each { |k,v| arr.push([k,v]) }
|
157
|
+
arr.flatten(level)
|
158
|
+
end
|
159
|
+
|
160
|
+
def size
|
161
|
+
got = @sqldb.get_first_row("select count(*) from '#{@table}'")
|
162
|
+
return got && got.class==Array ? got[0] : nil
|
163
|
+
end
|
164
|
+
alias :length :size
|
165
|
+
def empty?
|
166
|
+
size==0 ? true : false
|
167
|
+
end
|
168
|
+
|
169
|
+
def del(key)
|
170
|
+
#puts "delete key #{key}"
|
171
|
+
return unless @sqldb
|
172
|
+
@sqldb.execute("delete from '#{@table}' where key = ?",Marshal.dump(key))
|
173
|
+
end
|
174
|
+
alias :delete :del
|
175
|
+
def keep_if
|
176
|
+
return Enumerator.new { |y|
|
177
|
+
each { |k,v| delete(k) unless y.yield(k,v) }
|
178
|
+
self
|
179
|
+
} unless block_given?
|
180
|
+
each { |k,v| delete(k) unless yield(k,v) }
|
181
|
+
return self
|
182
|
+
end
|
183
|
+
def delete_if
|
184
|
+
return Enumerator.new { |y|
|
185
|
+
each { |k,v| delete(k) if y.yield(k,v) }
|
186
|
+
self
|
187
|
+
} unless block_given?
|
188
|
+
each { |k,v| delete(k) if yield(k,v) }
|
189
|
+
return self
|
190
|
+
end
|
191
|
+
def reject
|
192
|
+
hash = Hash.new
|
193
|
+
each { |k,v| hash[k] = v unless yield(k,v) }
|
194
|
+
return hash
|
195
|
+
end
|
196
|
+
def reject!
|
197
|
+
changes = 0
|
198
|
+
en = Enumerator.new { |y|
|
199
|
+
each { |k,v|
|
200
|
+
next unless y.yield(k,v)
|
201
|
+
delete(k)
|
202
|
+
changes += 1
|
203
|
+
}
|
204
|
+
changes==0 ? nil : self
|
205
|
+
}
|
206
|
+
return en unless block_given?
|
207
|
+
en.each { |k,v| yield(k,v) }
|
208
|
+
end
|
209
|
+
def select
|
210
|
+
hash = Hash.new
|
211
|
+
each { |k,v| hash[k] = v if yield(k,v) }
|
212
|
+
return hash
|
213
|
+
end
|
214
|
+
def select!
|
215
|
+
changes = 0
|
216
|
+
en = Enumerator.new { |y|
|
217
|
+
each { |k,v|
|
218
|
+
next if y.yield(k,v)
|
219
|
+
delete(k)
|
220
|
+
changes += 1
|
221
|
+
}
|
222
|
+
changes==0 ? nil : self
|
223
|
+
}
|
224
|
+
return en unless block_given?
|
225
|
+
en.each { |k,v| yield(k,v) }
|
226
|
+
end
|
227
|
+
|
228
|
+
def clear(replaceHash = nil)
|
229
|
+
@sqldb.execute("drop table '#{@table}'")
|
230
|
+
createTable(replaceHash)
|
231
|
+
end
|
232
|
+
alias :replace :clear
|
233
|
+
|
234
|
+
def has_key?(k)
|
235
|
+
@sqldb.get_first_row( "select * from '#{@table}' where key = ?", Marshal.dump(k)) ? true : false
|
236
|
+
end
|
237
|
+
alias :include? :has_key?
|
238
|
+
alias :key? :has_key?
|
239
|
+
alias :member? :has_key?
|
240
|
+
|
241
|
+
def index(value)
|
242
|
+
rowname,value = rowValue(value)
|
243
|
+
row = @sqldb.get_first_row( "select * from '#{@table}' where #{rowname} = ?", value)
|
244
|
+
row ? Marshal.load(row[0]) : nil
|
245
|
+
end
|
246
|
+
alias :key :index
|
247
|
+
def has_value?(v)
|
248
|
+
index(v) ? true : false
|
249
|
+
end
|
250
|
+
alias :value? :has_value?
|
251
|
+
|
252
|
+
def shift
|
253
|
+
row = @sqldb.get_first_row("select * from '#{@table}'")
|
254
|
+
# TODO - what if we have a default_proc and we shift out?
|
255
|
+
return default(nil) unless row
|
256
|
+
key = Marshal.load(row[0])
|
257
|
+
value = row2value(row)
|
258
|
+
delete(key)
|
259
|
+
[key,value]
|
260
|
+
end
|
261
|
+
|
262
|
+
def to_h
|
263
|
+
h = Hash.new
|
264
|
+
return h unless @sqldb
|
265
|
+
each { |k,v| h[k] = v }
|
266
|
+
h
|
267
|
+
end
|
268
|
+
alias :to_hash :to_h
|
269
|
+
def ==(otherHash)
|
270
|
+
to_hash.==(otherHash)
|
271
|
+
end
|
272
|
+
alias :eql? :==
|
273
|
+
def hash
|
274
|
+
to_hash.hash
|
275
|
+
end
|
276
|
+
def invert
|
277
|
+
to_hash.invert
|
278
|
+
end
|
279
|
+
def merge(otherHash,&block)
|
280
|
+
to_hash.merge(otherHash,&block)
|
281
|
+
end
|
282
|
+
def merge!(otherHash)
|
283
|
+
if block_given?
|
284
|
+
otherHash.each { |key,newval|
|
285
|
+
oldval = get(key)
|
286
|
+
set(key,oldval ? yield(key,oldval,newval) : newval)
|
287
|
+
}
|
288
|
+
else
|
289
|
+
otherHash.each { |k,v| set(k,v) }
|
290
|
+
end
|
291
|
+
end
|
292
|
+
alias :update :merge!
|
293
|
+
def replace(otherHash)
|
294
|
+
clear
|
295
|
+
merge!(otherHash)
|
296
|
+
end
|
297
|
+
|
298
|
+
def to_a
|
299
|
+
a = Array.new
|
300
|
+
return a unless @sqldb
|
301
|
+
each { |k,v| a.push([k,v]) }
|
302
|
+
a
|
303
|
+
end
|
304
|
+
def sort
|
305
|
+
to_a.sort
|
306
|
+
end
|
307
|
+
|
308
|
+
def inspect
|
309
|
+
inspect = "SQLite3Hash[#{@db}:#{@table}]"
|
310
|
+
return "#<#{inspect} - no database connection>" unless @sqldb
|
311
|
+
return "#<#{inspect} #{to_hash.inspect}>"
|
312
|
+
end
|
313
|
+
def to_s
|
314
|
+
to_hash.to_s
|
315
|
+
end
|
316
|
+
|
317
|
+
# For debug
|
318
|
+
def dumpTable
|
319
|
+
h = Hash.new
|
320
|
+
return puts "NO CONNECTION" unless @sqldb
|
321
|
+
@sqldb.execute("select * from '#{@table}'") { |row|
|
322
|
+
row[0] = Marshal.load(row[0])
|
323
|
+
p row
|
324
|
+
}
|
325
|
+
h
|
326
|
+
end
|
327
|
+
|
328
|
+
# Not implemented
|
329
|
+
def rehash
|
330
|
+
raise NotImplementedError
|
331
|
+
end
|
332
|
+
def compare_by_identity
|
333
|
+
raise NotImplementedError
|
334
|
+
end
|
335
|
+
def compare_by_identity?
|
336
|
+
false
|
337
|
+
end
|
338
|
+
def self.[](*a)
|
339
|
+
raise NotImplementedError
|
340
|
+
end
|
341
|
+
|
342
|
+
|
343
|
+
private
|
344
|
+
def rows
|
345
|
+
return @sqldb.execute("select * from '#{@table}'") unless block_given?
|
346
|
+
@sqldb.execute("select * from '#{@table}'") { |row|
|
347
|
+
yield row
|
348
|
+
}
|
349
|
+
end
|
350
|
+
def rowValue(value)
|
351
|
+
c = value.class
|
352
|
+
return ["value#{c.to_s}",value] if c==Fixnum || c==String || c==Float
|
353
|
+
return ["value#{c.to_s}",value.to_s] if c==Symbol
|
354
|
+
return ["valueMarshal",Marshal.dump(value)]
|
355
|
+
end
|
356
|
+
def row2value(row)
|
357
|
+
row[1] || row[2] || row[3] || (row[4] ? row[4].to_sym : Marshal.load(row[5]))
|
358
|
+
end
|
359
|
+
|
360
|
+
def createTable(h=Hash.new)
|
361
|
+
# Check if table exists
|
362
|
+
return if @sqldb.get_first_value( %{select name from sqlite_master where name = :name}, {:name => @table} )
|
363
|
+
@sqldb.execute("create table '#{@table}' (key TEXT not null unique, valueString TEXTS, valueFixnum INTEGER, valueFloat REAL, valueSymbol TEXTS, valueMarshal TEXTS)")
|
364
|
+
h.each { |k,v| set(k,v) } if h
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sqlite3_hash/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sqlite3_hash"
|
8
|
+
spec.version = Sqlite3Hash::VERSION
|
9
|
+
spec.authors = ["David Ljung Madison Stellar"]
|
10
|
+
spec.email = ["http://Contact.MarginalHacks.com/"]
|
11
|
+
|
12
|
+
spec.summary = %q{A persistent simple Hash backed by sqlite3}
|
13
|
+
spec.description = %q{A persistent simple Hash backed by sqlite3\n\nContains (almost) the same features/API as the Ruby 2.0.0 Hash object}
|
14
|
+
spec.homepage = "http://MarginalHacks.com/"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
#spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
#spec.add_development_dependency "true", "~> "
|
33
|
+
spec.add_development_dependency "rspec"
|
34
|
+
spec.add_dependency "sqlite3"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sqlite3_hash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Ljung Madison Stellar
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A persistent simple Hash backed by sqlite3\n\nContains (almost) the same
|
70
|
+
features/API as the Ruby 2.0.0 Hash object
|
71
|
+
email:
|
72
|
+
- http://Contact.MarginalHacks.com/
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/sqlite3_hash.rb
|
86
|
+
- lib/sqlite3_hash/version.rb
|
87
|
+
- sqlite3_hash.gemspec
|
88
|
+
homepage: http://MarginalHacks.com/
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.5.1
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: A persistent simple Hash backed by sqlite3
|
112
|
+
test_files: []
|