amalgalite 1.9.1 → 2.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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +26 -0
  3. data/Manifest.txt +4 -54
  4. data/README.md +1 -1
  5. data/TODO.md +4 -3
  6. data/amalgalite.gemspec +39 -0
  7. data/ext/amalgalite/c/amalgalite.c +0 -1
  8. data/ext/amalgalite/c/amalgalite_constants.c +155 -10
  9. data/ext/amalgalite/c/extconf.rb +5 -2
  10. data/ext/amalgalite/c/gen_constants.rb +32 -1
  11. data/ext/amalgalite/c/sqlite3.c +33715 -13095
  12. data/ext/amalgalite/c/sqlite3.h +1387 -389
  13. data/ext/amalgalite/c/sqlite3ext.h +21 -0
  14. data/lib/amalgalite/column.rb +20 -2
  15. data/lib/amalgalite/result/row.rb +83 -0
  16. data/lib/amalgalite/result.rb +15 -0
  17. data/lib/amalgalite/statement.rb +32 -24
  18. data/lib/amalgalite/type_maps/default_map.rb +48 -56
  19. data/lib/amalgalite/version.rb +1 -1
  20. metadata +32 -119
  21. data/Rakefile +0 -27
  22. data/bin/amalgalite-pack +0 -147
  23. data/examples/a.rb +0 -9
  24. data/examples/blob.rb +0 -88
  25. data/examples/bootstrap.rb +0 -36
  26. data/examples/define_aggregate.rb +0 -75
  27. data/examples/define_function.rb +0 -104
  28. data/examples/fts5.rb +0 -152
  29. data/examples/gem-db.rb +0 -94
  30. data/examples/require_me.rb +0 -11
  31. data/examples/requires.rb +0 -42
  32. data/examples/schema-info.rb +0 -34
  33. data/ext/amalgalite/c/amalgalite_requires_bootstrap.c +0 -283
  34. data/lib/amalgalite/core_ext/kernel/require.rb +0 -21
  35. data/lib/amalgalite/packer.rb +0 -231
  36. data/lib/amalgalite/requires.rb +0 -151
  37. data/spec/aggregate_spec.rb +0 -158
  38. data/spec/amalgalite_spec.rb +0 -4
  39. data/spec/blob_spec.rb +0 -78
  40. data/spec/boolean_spec.rb +0 -24
  41. data/spec/busy_handler.rb +0 -157
  42. data/spec/data/iso-3166-country.txt +0 -242
  43. data/spec/data/iso-3166-schema.sql +0 -22
  44. data/spec/data/iso-3166-subcountry.txt +0 -3995
  45. data/spec/data/make-iso-db.sh +0 -12
  46. data/spec/database_spec.rb +0 -505
  47. data/spec/default_map_spec.rb +0 -92
  48. data/spec/function_spec.rb +0 -78
  49. data/spec/integeration_spec.rb +0 -97
  50. data/spec/iso_3166_database.rb +0 -58
  51. data/spec/json_spec.rb +0 -24
  52. data/spec/packer_spec.rb +0 -60
  53. data/spec/paths_spec.rb +0 -28
  54. data/spec/progress_handler_spec.rb +0 -91
  55. data/spec/requires_spec.rb +0 -54
  56. data/spec/rtree_spec.rb +0 -66
  57. data/spec/schema_spec.rb +0 -131
  58. data/spec/spec_helper.rb +0 -48
  59. data/spec/sqlite3/constants_spec.rb +0 -108
  60. data/spec/sqlite3/database_status_spec.rb +0 -36
  61. data/spec/sqlite3/status_spec.rb +0 -22
  62. data/spec/sqlite3/version_spec.rb +0 -28
  63. data/spec/sqlite3_spec.rb +0 -53
  64. data/spec/statement_spec.rb +0 -168
  65. data/spec/storage_map_spec.rb +0 -38
  66. data/spec/tap_spec.rb +0 -57
  67. data/spec/text_map_spec.rb +0 -20
  68. data/spec/type_map_spec.rb +0 -14
  69. data/spec/version_spec.rb +0 -8
  70. data/tasks/custom.rake +0 -101
  71. data/tasks/default.rake +0 -257
  72. data/tasks/extension.rake +0 -28
  73. data/tasks/this.rb +0 -208
  74. /data/{LICENSE → LICENSE.txt} +0 -0
metadata CHANGED
@@ -1,43 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amalgalite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Hinegardner
8
- autorequire:
9
- bindir: bin
8
+ bindir: exe
10
9
  cert_chain: []
11
- date: 2023-04-27 00:00:00.000000000 Z
10
+ date: 2025-11-15 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: arrayfields
13
+ name: csv
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '4.9'
18
+ version: '3.3'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '4.9'
25
+ version: '3.3'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rspec
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '3.12'
32
+ version: '3.13'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '3.12'
39
+ version: '3.13'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: rspec_junit_formatter
43
42
  requirement: !ruby/object:Gem::Requirement
@@ -58,125 +57,112 @@ dependencies:
58
57
  requirements:
59
58
  - - "~>"
60
59
  - !ruby/object:Gem::Version
61
- version: '13.0'
60
+ version: '13.3'
62
61
  type: :development
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
65
  - - "~>"
67
66
  - !ruby/object:Gem::Version
68
- version: '13.0'
67
+ version: '13.3'
69
68
  - !ruby/object:Gem::Dependency
70
69
  name: rake-compiler
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
72
  - - "~>"
74
73
  - !ruby/object:Gem::Version
75
- version: '1.2'
74
+ version: '1.3'
76
75
  type: :development
77
76
  prerelease: false
78
77
  version_requirements: !ruby/object:Gem::Requirement
79
78
  requirements:
80
79
  - - "~>"
81
80
  - !ruby/object:Gem::Version
82
- version: '1.2'
81
+ version: '1.3'
83
82
  - !ruby/object:Gem::Dependency
84
83
  name: rake-compiler-dock
85
84
  requirement: !ruby/object:Gem::Requirement
86
85
  requirements:
87
86
  - - "~>"
88
87
  - !ruby/object:Gem::Version
89
- version: '1.2'
88
+ version: '1.10'
90
89
  type: :development
91
90
  prerelease: false
92
91
  version_requirements: !ruby/object:Gem::Requirement
93
92
  requirements:
94
93
  - - "~>"
95
94
  - !ruby/object:Gem::Version
96
- version: '1.2'
95
+ version: '1.10'
97
96
  - !ruby/object:Gem::Dependency
98
97
  name: rdoc
99
98
  requirement: !ruby/object:Gem::Requirement
100
99
  requirements:
101
100
  - - "~>"
102
101
  - !ruby/object:Gem::Version
103
- version: '6.5'
102
+ version: '6.15'
104
103
  type: :development
105
104
  prerelease: false
106
105
  version_requirements: !ruby/object:Gem::Requirement
107
106
  requirements:
108
107
  - - "~>"
109
108
  - !ruby/object:Gem::Version
110
- version: '6.5'
109
+ version: '6.15'
111
110
  - !ruby/object:Gem::Dependency
112
111
  name: simplecov
113
112
  requirement: !ruby/object:Gem::Requirement
114
113
  requirements:
115
114
  - - "~>"
116
115
  - !ruby/object:Gem::Version
117
- version: '0.21'
116
+ version: '0.22'
118
117
  type: :development
119
118
  prerelease: false
120
119
  version_requirements: !ruby/object:Gem::Requirement
121
120
  requirements:
122
121
  - - "~>"
123
122
  - !ruby/object:Gem::Version
124
- version: '0.21'
123
+ version: '0.22'
125
124
  - !ruby/object:Gem::Dependency
126
125
  name: archive-zip
127
126
  requirement: !ruby/object:Gem::Requirement
128
127
  requirements:
129
128
  - - "~>"
130
129
  - !ruby/object:Gem::Version
131
- version: '0.12'
130
+ version: '0.13'
132
131
  type: :development
133
132
  prerelease: false
134
133
  version_requirements: !ruby/object:Gem::Requirement
135
134
  requirements:
136
135
  - - "~>"
137
136
  - !ruby/object:Gem::Version
138
- version: '0.12'
139
- description: Amalgalite embeds the SQLite database engine as a ruby extension. There
140
- is no need to install SQLite separately.
137
+ version: '0.13'
138
+ description: |-
139
+ Amalgalite embeds the SQLite database engine as a ruby extension. There is no
140
+ need to install SQLite separately.
141
141
  email: jeremy@copiousfreetime.org
142
- executables:
143
- - amalgalite-pack
142
+ executables: []
144
143
  extensions:
145
144
  - ext/amalgalite/c/extconf.rb
146
145
  extra_rdoc_files:
147
146
  - CONTRIBUTING.md
148
147
  - HISTORY.md
148
+ - LICENSE.txt
149
149
  - Manifest.txt
150
150
  - README.md
151
151
  - TODO.md
152
152
  - ext/amalgalite/c/notes.txt
153
- - spec/data/iso-3166-country.txt
154
- - spec/data/iso-3166-subcountry.txt
155
153
  files:
156
154
  - CONTRIBUTING.md
157
155
  - HISTORY.md
158
- - LICENSE
156
+ - LICENSE.txt
159
157
  - Manifest.txt
160
158
  - README.md
161
- - Rakefile
162
159
  - TODO.md
163
- - bin/amalgalite-pack
164
- - examples/a.rb
165
- - examples/blob.rb
166
- - examples/bootstrap.rb
167
- - examples/define_aggregate.rb
168
- - examples/define_function.rb
169
- - examples/fts5.rb
170
- - examples/gem-db.rb
171
- - examples/require_me.rb
172
- - examples/requires.rb
173
- - examples/schema-info.rb
160
+ - amalgalite.gemspec
174
161
  - ext/amalgalite/c/amalgalite.c
175
162
  - ext/amalgalite/c/amalgalite.h
176
163
  - ext/amalgalite/c/amalgalite_blob.c
177
164
  - ext/amalgalite/c/amalgalite_constants.c
178
165
  - ext/amalgalite/c/amalgalite_database.c
179
- - ext/amalgalite/c/amalgalite_requires_bootstrap.c
180
166
  - ext/amalgalite/c/amalgalite_statement.c
181
167
  - ext/amalgalite/c/extconf.rb
182
168
  - ext/amalgalite/c/gen_constants.rb
@@ -191,17 +177,16 @@ files:
191
177
  - lib/amalgalite/boolean.rb
192
178
  - lib/amalgalite/busy_timeout.rb
193
179
  - lib/amalgalite/column.rb
194
- - lib/amalgalite/core_ext/kernel/require.rb
195
180
  - lib/amalgalite/csv_table_importer.rb
196
181
  - lib/amalgalite/database.rb
197
182
  - lib/amalgalite/function.rb
198
183
  - lib/amalgalite/index.rb
199
184
  - lib/amalgalite/memory_database.rb
200
- - lib/amalgalite/packer.rb
201
185
  - lib/amalgalite/paths.rb
202
186
  - lib/amalgalite/profile_tap.rb
203
187
  - lib/amalgalite/progress_handler.rb
204
- - lib/amalgalite/requires.rb
188
+ - lib/amalgalite/result.rb
189
+ - lib/amalgalite/result/row.rb
205
190
  - lib/amalgalite/schema.rb
206
191
  - lib/amalgalite/sqlite3.rb
207
192
  - lib/amalgalite/sqlite3/constants.rb
@@ -221,48 +206,10 @@ files:
221
206
  - lib/amalgalite/type_maps/text_map.rb
222
207
  - lib/amalgalite/version.rb
223
208
  - lib/amalgalite/view.rb
224
- - spec/aggregate_spec.rb
225
- - spec/amalgalite_spec.rb
226
- - spec/blob_spec.rb
227
- - spec/boolean_spec.rb
228
- - spec/busy_handler.rb
229
- - spec/data/iso-3166-country.txt
230
- - spec/data/iso-3166-schema.sql
231
- - spec/data/iso-3166-subcountry.txt
232
- - spec/data/make-iso-db.sh
233
- - spec/database_spec.rb
234
- - spec/default_map_spec.rb
235
- - spec/function_spec.rb
236
- - spec/integeration_spec.rb
237
- - spec/iso_3166_database.rb
238
- - spec/json_spec.rb
239
- - spec/packer_spec.rb
240
- - spec/paths_spec.rb
241
- - spec/progress_handler_spec.rb
242
- - spec/requires_spec.rb
243
- - spec/rtree_spec.rb
244
- - spec/schema_spec.rb
245
- - spec/spec_helper.rb
246
- - spec/sqlite3/constants_spec.rb
247
- - spec/sqlite3/database_status_spec.rb
248
- - spec/sqlite3/status_spec.rb
249
- - spec/sqlite3/version_spec.rb
250
- - spec/sqlite3_spec.rb
251
- - spec/statement_spec.rb
252
- - spec/storage_map_spec.rb
253
- - spec/tap_spec.rb
254
- - spec/text_map_spec.rb
255
- - spec/type_map_spec.rb
256
- - spec/version_spec.rb
257
- - tasks/custom.rake
258
- - tasks/default.rake
259
- - tasks/extension.rake
260
- - tasks/this.rb
261
209
  homepage: http://github.com/copiousfreetime/amalgalite
262
210
  licenses:
263
211
  - BSD-3-Clause
264
212
  metadata: {}
265
- post_install_message:
266
213
  rdoc_options:
267
214
  - "--main"
268
215
  - README.md
@@ -274,49 +221,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
274
221
  requirements:
275
222
  - - ">="
276
223
  - !ruby/object:Gem::Version
277
- version: 2.3.0
224
+ version: 3.1.0
278
225
  required_rubygems_version: !ruby/object:Gem::Requirement
279
226
  requirements:
280
227
  - - ">="
281
228
  - !ruby/object:Gem::Version
282
229
  version: '0'
283
230
  requirements: []
284
- rubygems_version: 3.4.10
285
- signing_key:
231
+ rubygems_version: 3.6.9
286
232
  specification_version: 4
287
233
  summary: Amalgalite embeds the SQLite database engine as a ruby extension. There is
288
234
  no need to install SQLite separately.
289
- test_files:
290
- - spec/aggregate_spec.rb
291
- - spec/amalgalite_spec.rb
292
- - spec/blob_spec.rb
293
- - spec/boolean_spec.rb
294
- - spec/busy_handler.rb
295
- - spec/data/iso-3166-country.txt
296
- - spec/data/iso-3166-schema.sql
297
- - spec/data/iso-3166-subcountry.txt
298
- - spec/data/make-iso-db.sh
299
- - spec/database_spec.rb
300
- - spec/default_map_spec.rb
301
- - spec/function_spec.rb
302
- - spec/integeration_spec.rb
303
- - spec/iso_3166_database.rb
304
- - spec/json_spec.rb
305
- - spec/packer_spec.rb
306
- - spec/paths_spec.rb
307
- - spec/progress_handler_spec.rb
308
- - spec/requires_spec.rb
309
- - spec/rtree_spec.rb
310
- - spec/schema_spec.rb
311
- - spec/spec_helper.rb
312
- - spec/sqlite3/constants_spec.rb
313
- - spec/sqlite3/database_status_spec.rb
314
- - spec/sqlite3/status_spec.rb
315
- - spec/sqlite3/version_spec.rb
316
- - spec/sqlite3_spec.rb
317
- - spec/statement_spec.rb
318
- - spec/storage_map_spec.rb
319
- - spec/tap_spec.rb
320
- - spec/text_map_spec.rb
321
- - spec/type_map_spec.rb
322
- - spec/version_spec.rb
235
+ test_files: []
data/Rakefile DELETED
@@ -1,27 +0,0 @@
1
- # vim: syntax=ruby
2
- load 'tasks/this.rb'
3
-
4
- This.name = "amalgalite"
5
- This.author = "Jeremy Hinegardner"
6
- This.email = "jeremy@copiousfreetime.org"
7
- This.homepage = "http://github.com/copiousfreetime/#{ This.name }"
8
-
9
- This.ruby_gemspec do |spec|
10
- spec.add_dependency( 'arrayfields', '~> 4.9' )
11
-
12
- spec.add_development_dependency( 'rspec', '~> 3.12' )
13
- spec.add_development_dependency( 'rspec_junit_formatter','~> 0.6' )
14
- spec.add_development_dependency( 'rake', '~> 13.0' )
15
- spec.add_development_dependency( 'rake-compiler', '~> 1.2' )
16
- spec.add_development_dependency( 'rake-compiler-dock', '~> 1.2' )
17
- spec.add_development_dependency( 'rdoc', '~> 6.5' )
18
- spec.add_development_dependency( 'simplecov', '~> 0.21' )
19
- spec.add_development_dependency( 'archive-zip', '~> 0.12' )
20
-
21
- spec.extensions.concat This.extension_conf_files
22
- spec.license = "BSD-3-Clause"
23
- end
24
-
25
- load 'tasks/default.rake'
26
- load 'tasks/extension.rake'
27
- load 'tasks/custom.rake'
data/bin/amalgalite-pack DELETED
@@ -1,147 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'optparse'
3
- require 'pathname'
4
-
5
- #
6
- # add relative paths to the load path if we are not a gem and calculate what the
7
- # strip path will be if we decide to pack --self
8
- #
9
- this_path = Pathname.new( File.expand_path( __FILE__ ) )
10
- gem_path = Pathname.new( Gem.dir )
11
- rel_path = this_path.relative_path_from( gem_path )
12
- if ".." == rel_path.to_s.split( File::SEPARATOR ).first then
13
- lib_path = File.join( File.dirname( __FILE__ ), "../lib" )
14
- $:.unshift lib_path
15
- $:.unshift File.join( File.dirname( __FILE__ ), "../ext" )
16
- end
17
-
18
- #
19
- # snapshot of what is needed for amalgalite requires, this info may only be used
20
- # when packing amalgalite itself
21
- #
22
- loaded_features_before = $LOADED_FEATURES.dup
23
- require 'amalgalite/packer'
24
- loaded_features_after = $LOADED_FEATURES.dup
25
- load_diff = loaded_features_after - loaded_features_before
26
-
27
- #
28
- # strip off any LOAD_PATH elements from the front of load_diff since that
29
- # will conflict with Amalgalite::Packer.amalgalite_require_order. Also
30
- # strip out any 'rubygems' items since those are not used by Amalgalite
31
- # and show as a side effect fo the "require 'amalgalite/packer'"
32
- #
33
- strip_paths = $LOAD_PATH.sort.reverse
34
- amalgalite_needs = []
35
- load_diff.each do |f|
36
- next if f.split( File::SEPARATOR ).include?( "rubygems" )
37
- appended = false
38
- strip_paths.each do |path|
39
- if 0 == f.index(path ) then
40
- rel_path = f.sub( path, '' ).sub(%r{\A#{File::SEPARATOR}},'')
41
- amalgalite_needs << rel_path
42
- appended = true
43
- break
44
- end
45
- end
46
- amalgalite_needs << f unless appended
47
- end
48
-
49
- #
50
- # Commandline parser
51
- #
52
- options = {}
53
- begin
54
- parser = OptionParser.new do |op|
55
- op.banner = "Usage: #{op.program_name} [options] <files>"
56
- op.separator ""
57
-
58
- op.on("--dbfile DB", "The Database file in which to pack files") do |d|
59
- options[:dbfile] = d
60
- end
61
-
62
- op.on("--drop-table", "Drop the table before inserting rows") do |t|
63
- options[:drop_table] = t
64
- end
65
-
66
- op.on("-m", "--merge", "Merge these files into the existing table overwriting rows that conflict") do |m|
67
- options[:merge] = true
68
- end
69
-
70
- op.on("--require-order", "Dump Amalgalite's require order" ) do |m|
71
- puts amalgalite_needs
72
- exit 0
73
- end
74
-
75
- op.on("--self", "pack amalgalite itself into the database") do |d|
76
- options[:self] = true
77
- end
78
-
79
- op.on("--strip-prefix PREFIX", "strip this path prefix off the front of each file") do |p|
80
- options[:strip_prefix] = File.expand_path( p )
81
- end
82
-
83
- op.on("-t", "--table TABLE", "the table name to pack into") do |t|
84
- options[:table_name] = t
85
- end
86
-
87
- op.on("--verbose", "Be verbose about output") do |v|
88
- options[:verbose] = v
89
- end
90
-
91
- op.on("-z", "--compressed", "compress the file contents on storage") do |z|
92
- options[:compressed] = true
93
- end
94
-
95
- end
96
-
97
- parser.parse!
98
- require 'amalgalite/packer'
99
- file_list = ARGV.dup
100
-
101
-
102
- if options[:self] then
103
- options[:table_name] = Amalgalite::Requires::Bootstrap::DEFAULT_BOOTSTRAP_TABLE
104
- core_libs = (amalgalite_needs - Amalgalite::Packer.amalgalite_require_order).delete_if { |l| l.index(".rb").nil? }
105
-
106
- #
107
- # check and make sure nothing is missed
108
- #
109
- core_libs.each do |l|
110
- if l.index("amalgalite") then
111
- STDERR.puts "ERROR! require_order needs an update #{l}"
112
- exit 2
113
- end
114
- end
115
- file_list = core_libs.concat( Amalgalite::Packer.amalgalite_require_order )
116
- if options[:compressed] then
117
- STDERR.puts "Compressing --self is not allowed, reverting to uncompressed"
118
- options[:compressed] = false
119
- end
120
- end
121
- STDERR.puts parser if file_list.empty?
122
-
123
- packer = Amalgalite::Packer.new( options )
124
- packer.pack( file_list )
125
-
126
- rescue OptionParser::ParseError => pe
127
- STDERR.puts "ERROR : #{pe}"
128
- STDERR.puts parser
129
- exit 1
130
- end
131
-
132
- __END__
133
-
134
- puts <<-text
135
-
136
- Packing complete. To utilize the bootstrapping in #{dbfile} you must do
137
- one of the following:
138
-
139
- * statically compile the amalgalite C extension into your application
140
- * require 'amalgalite/#{RUBY_VERSION.sub(/\.\d$/,'')}/amalgalite3'
141
-
142
- Once one of those is working you can boostrap the Amalgalite library with
143
- this line in your code:
144
-
145
- Amalgalite::Requries::Boostrap.lift( 'dbfile' => '#{dbfile}' )
146
-
147
- text
data/examples/a.rb DELETED
@@ -1,9 +0,0 @@
1
- class A
2
- def initialize
3
- puts "Initialized A"
4
- end
5
-
6
- def a
7
- puts "called a"
8
- end
9
- end
data/examples/blob.rb DELETED
@@ -1,88 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #
4
- # An Amalgalite example showing how Blob's can be utilized
5
- #
6
- # We'll make a database with one table, that we store files in. We'll use the
7
- # Blob incremental IO to store the files and retrieve them from the database
8
- #
9
- # This little program will store 1 or more files in the sqlite3 database when
10
- # the 'store' action is given, and cat a file to stdout on 'retrieve'
11
- #
12
- # e.g.
13
- #
14
- # ruby blob.rb store a.rb b.rb c.rb # => stores a.rb b.rb and c.rb in the db
15
- #
16
- # ruby blob.rb retrieve a.rb # => dumps a.rb to stdout
17
- #
18
-
19
- require 'rubygems'
20
- $: << "../lib"
21
- $: << "../ext"
22
- require 'amalgalite'
23
- require 'amalgalite/packer'
24
- VALID_ACTIONS = %w[ list retrieve store ]
25
- def usage
26
- STDERR.puts "Usage: #{File.basename($0)} ( #{VALID_ACTIONS.join(' | ')} ) file(s)"
27
- exit 1
28
- end
29
-
30
- #
31
- # This does the basic command line parsing
32
- #
33
- usage if ARGV.size < 1
34
- action = ARGV.shift
35
- usage unless VALID_ACTIONS.include? action
36
- file_list = ARGV
37
-
38
- #
39
- # create the database if it doesn't exist
40
- #
41
- db = Amalgalite::Database.new( "filestore.db" )
42
-
43
- case action
44
- #
45
- # list all the files that are stored in the database
46
- #
47
- when 'list'
48
- db.execute("SELECT filename FROM rubylibs") do |row|
49
- puts row['filename']
50
- end
51
-
52
- #
53
- # if we are doing the store action, then loop over the files and store them in
54
- # the database. This will use incremental IO to store the files directly from
55
- # the file names.
56
- #
57
- # It is slightly strange in that you have to tell the Blob object what column
58
- # it is going to, but that is necessary at this point to be able to hook
59
- # automatically into the lower level incremental blob IO api.
60
- #
61
- # This also shows using the $var syntax for binding name sql values in a
62
- # prepared statement.
63
- #
64
- when 'store'
65
- usage if file_list.empty?
66
- require 'amalgalite/packer'
67
-
68
- packer = Amalgalite::Packer.new( :dbfile => 'filestore.db',
69
- :compressed => false )
70
- packer.pack( file_list )
71
-
72
- #
73
- # dump the file that matches the right path to stdout. This also shows
74
- # positional sql varible binding using the '?' syntax.
75
- #
76
- when 'retrieve'
77
- usage if file_list.empty?
78
- db.execute("SELECT id, compressed, filename, contents FROM rubylibs WHERE filename = ?", file_list.first) do |row|
79
- STDERR.puts "Dumping #{row['filename']} to stdout"
80
- if row['compressed'] then
81
- s = row['contents'].to_s
82
- STDOUT.puts Amalgalite::Packer.gunzip( s )
83
- else
84
- row['contents'].write_to_io( STDOUT )
85
- end
86
- end
87
- end
88
- db.close
@@ -1,36 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # An example of requiring all the files in a table via the Bootstrap::lift
4
- # method.
5
- #
6
- # First use the blob.rb example in this same directory to load the a.rb file
7
- # into an example database:
8
- #
9
- # ruby blob.rb store a.rb
10
- #
11
- # Then run this example.
12
- #
13
-
14
- # Require "ONLY" then binary extension, do not +require+ the ruby based code
15
- $: << "../ext"
16
- require 'amalgalite/amalgalite3'
17
-
18
- # See what the load path is, notice that it is very small
19
- puts "Before $\" : #{$LOADED_FEATURES.inspect}"
20
-
21
- # tell the binary extension to "require" every file in the filestore.db in the
22
- # table 'files' orderd by column 'id'. The 'path' column is added to $LOADED_FEATURES and the
23
- # code in 'data' is evaled.
24
- Amalgalite::Requires::Bootstrap.lift( "dbfile" => "filestore.db",
25
- "table_name" => "rubylibs",
26
- "rowid_column" => "id",
27
- "filename_column" => "filename",
28
- "contents_column" => "contents" )
29
-
30
- # Notice that a.rb is in the list of files that has been required
31
- puts "After $\" : #{$LOADED_FEATURES.inspect}"
32
-
33
- # and look we prove that the code was eval'd appropriately
34
- a = A.new
35
- a.a
36
-