sequel_core 2.2.0 → 3.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. metadata +30 -101
  2. data/CHANGELOG +0 -1519
  3. data/COPYING +0 -19
  4. data/README +0 -313
  5. data/Rakefile +0 -158
  6. data/bin/sequel +0 -117
  7. data/doc/cheat_sheet.rdoc +0 -225
  8. data/doc/dataset_filtering.rdoc +0 -182
  9. data/lib/sequel_core.rb +0 -136
  10. data/lib/sequel_core/adapters/adapter_skeleton.rb +0 -68
  11. data/lib/sequel_core/adapters/ado.rb +0 -90
  12. data/lib/sequel_core/adapters/db2.rb +0 -160
  13. data/lib/sequel_core/adapters/dbi.rb +0 -127
  14. data/lib/sequel_core/adapters/informix.rb +0 -89
  15. data/lib/sequel_core/adapters/jdbc.rb +0 -110
  16. data/lib/sequel_core/adapters/mysql.rb +0 -486
  17. data/lib/sequel_core/adapters/odbc.rb +0 -167
  18. data/lib/sequel_core/adapters/odbc_mssql.rb +0 -106
  19. data/lib/sequel_core/adapters/openbase.rb +0 -76
  20. data/lib/sequel_core/adapters/oracle.rb +0 -182
  21. data/lib/sequel_core/adapters/postgres.rb +0 -560
  22. data/lib/sequel_core/adapters/sqlite.rb +0 -270
  23. data/lib/sequel_core/connection_pool.rb +0 -194
  24. data/lib/sequel_core/core_ext.rb +0 -197
  25. data/lib/sequel_core/core_sql.rb +0 -184
  26. data/lib/sequel_core/database.rb +0 -462
  27. data/lib/sequel_core/database/schema.rb +0 -156
  28. data/lib/sequel_core/dataset.rb +0 -457
  29. data/lib/sequel_core/dataset/callback.rb +0 -13
  30. data/lib/sequel_core/dataset/convenience.rb +0 -245
  31. data/lib/sequel_core/dataset/pagination.rb +0 -96
  32. data/lib/sequel_core/dataset/query.rb +0 -41
  33. data/lib/sequel_core/dataset/schema.rb +0 -15
  34. data/lib/sequel_core/dataset/sql.rb +0 -889
  35. data/lib/sequel_core/deprecated.rb +0 -26
  36. data/lib/sequel_core/exceptions.rb +0 -42
  37. data/lib/sequel_core/migration.rb +0 -187
  38. data/lib/sequel_core/object_graph.rb +0 -216
  39. data/lib/sequel_core/pretty_table.rb +0 -71
  40. data/lib/sequel_core/schema.rb +0 -2
  41. data/lib/sequel_core/schema/generator.rb +0 -239
  42. data/lib/sequel_core/schema/sql.rb +0 -326
  43. data/lib/sequel_core/sql.rb +0 -812
  44. data/lib/sequel_core/worker.rb +0 -68
  45. data/spec/adapters/informix_spec.rb +0 -96
  46. data/spec/adapters/mysql_spec.rb +0 -765
  47. data/spec/adapters/oracle_spec.rb +0 -222
  48. data/spec/adapters/postgres_spec.rb +0 -441
  49. data/spec/adapters/sqlite_spec.rb +0 -413
  50. data/spec/connection_pool_spec.rb +0 -363
  51. data/spec/core_ext_spec.rb +0 -156
  52. data/spec/core_sql_spec.rb +0 -427
  53. data/spec/database_spec.rb +0 -963
  54. data/spec/dataset_spec.rb +0 -2933
  55. data/spec/expression_filters_spec.rb +0 -316
  56. data/spec/migration_spec.rb +0 -261
  57. data/spec/object_graph_spec.rb +0 -230
  58. data/spec/pretty_table_spec.rb +0 -58
  59. data/spec/rcov.opts +0 -6
  60. data/spec/schema_generator_spec.rb +0 -122
  61. data/spec/schema_spec.rb +0 -422
  62. data/spec/spec.opts +0 -0
  63. data/spec/spec_config.rb +0 -7
  64. data/spec/spec_config.rb.example +0 -8
  65. data/spec/spec_helper.rb +0 -55
  66. data/spec/worker_spec.rb +0 -96
data/COPYING DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2007-2008 Sharon Rosner
2
- Copyright (c) 2008 Jeremy Evans
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to
6
- deal in the Software without restriction, including without limitation the
7
- rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8
- sell copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
- THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README DELETED
@@ -1,313 +0,0 @@
1
- == Sequel: The Database Toolkit for Ruby
2
-
3
- Sequel is a database access toolkit for Ruby. Sequel provides thread safety, connection pooling, and a concise DSL for constructing queries and table schemas.
4
-
5
- Sequel makes it easy to deal with multiple records without having to break your teeth on SQL.
6
-
7
- == Resources
8
-
9
- * {Source code}[http://github.com/jeremyevans/sequel]
10
- * {Bug tracking}[http://code.google.com/p/ruby-sequel/issues/list]
11
- * {Google group}[http://groups.google.com/group/sequel-talk]
12
- * {RDoc}[http://sequel.rubyforge.org]
13
-
14
- To check out the source code:
15
-
16
- git clone git://github.com/jeremyevans/sequel.git
17
-
18
- === Contact
19
-
20
- If you have any comments or suggestions please post to the Google group.
21
-
22
- == Installation
23
-
24
- sudo gem install sequel
25
-
26
- == Supported Databases
27
-
28
- Sequel currently supports:
29
-
30
- * ADO (on Windows)
31
- * DBI
32
- * Informix
33
- * MySQL
34
- * ODBC
35
- * Oracle
36
- * PostgreSQL
37
- * SQLite 3
38
-
39
- There are also experimental adapters for DB2, OpenBase and JDBC (on JRuby).
40
-
41
- == A Short Example
42
-
43
- require 'rubygems'
44
- require 'sequel'
45
-
46
- DB = Sequel.sqlite # memory database
47
-
48
- DB.create_table :items do # Create a new table
49
- column :name, :text
50
- column :price, :float
51
- end
52
-
53
- items = DB[:items] # Create a dataset
54
-
55
- # Populate the table
56
- items << {:name => 'abc', :price => rand * 100}
57
- items << {:name => 'def', :price => rand * 100}
58
- items << {:name => 'ghi', :price => rand * 100}
59
-
60
- # Print out the number of records
61
- puts "Item count: #{items.count}"
62
-
63
- # Print out the records in descending order by price
64
- items.reverse_order(:price).print
65
-
66
- # Print out the average price
67
- puts "The average price is: #{items.avg(:price)}"
68
-
69
- == The Sequel Console
70
-
71
- Sequel includes an IRB console for quick'n'dirty access to databases. You can use it like this:
72
-
73
- sequel sqlite://test.db # test.db in current directory
74
-
75
- You get an IRB session with the database object stored in DB.
76
-
77
- == An Introduction
78
-
79
- Sequel is designed to take the hassle away from connecting to databases and manipulating them. Sequel deals with all the boring stuff like maintaining connections, formatting SQL correctly and fetching records so you can concentrate on your application.
80
-
81
- Sequel uses the concept of datasets to retrieve data. A Dataset object encapsulates an SQL query and supports chainability, letting you fetch data using a convenient Ruby DSL that is both concise and infinitely flexible.
82
-
83
- For example, the following one-liner returns the average GDP for the five biggest countries in the middle east region:
84
-
85
- DB[:countries].filter(:region => 'Middle East').reverse_order(:area).limit(5).avg(:GDP)
86
-
87
- Which is equivalent to:
88
-
89
- SELECT avg(GDP) FROM countries WHERE region = 'Middle East' ORDER BY area DESC LIMIT 5
90
-
91
- Since datasets retrieve records only when needed, they can be stored and later reused. Records are fetched as hashes (they can also be fetched as custom model objects), and are accessed using an Enumerable interface:
92
-
93
- middle_east = DB[:countries].filter(:region => 'Middle East')
94
- middle_east.order(:name).each {|r| puts r[:name]}
95
-
96
- Sequel also offers convenience methods for extracting data from Datasets, such as an extended map method:
97
-
98
- middle_east.map(:name) #=> ['Egypt', 'Greece', 'Israel', ...]
99
-
100
- Or getting results as a transposed hash, with one column as key and another as value:
101
-
102
- middle_east.to_hash(:name, :area) #=> {'Israel' => 20000, 'Greece' => 120000, ...}
103
-
104
- == Getting Started
105
-
106
- === Connecting to a database
107
-
108
- To connect to a database you simply provide Sequel with a URL:
109
-
110
- require 'sequel'
111
- DB = Sequel.connect('sqlite://blog.db')
112
-
113
- The connection URL can also include such stuff as the user name and password:
114
-
115
- DB = Sequel.connect('postgres://cico:12345@localhost:5432/mydb')
116
-
117
- You can also specify optional parameters, such as the connection pool size, or loggers for logging SQL queries:
118
-
119
- DB = Sequel.connect("postgres://postgres:postgres@localhost/my_db",
120
- :max_connections => 10, :loggers => [Logger.new('log/db.log']))
121
-
122
- You can specify a block to connect, which will disconnect from the database after it completes:
123
-
124
- Sequel.connect('postgres://cico:12345@localhost:5432/mydb'){|db| db[:posts].delete}
125
-
126
- === Arbitrary SQL queries
127
-
128
- DB.execute("create table t (a text, b text)")
129
- DB.execute("insert into t values ('a', 'b')")
130
-
131
- Or more succinctly:
132
-
133
- DB << "create table t (a text, b text)"
134
- DB << "insert into t values ('a', 'b')"
135
-
136
- You can also create datasets based on raw SQL:
137
-
138
- dataset = DB['select * from items']
139
- dataset.count # will return the number of records in the result set
140
- dataset.map(:id) # will return an array containing all values of the id column in the result set
141
-
142
- You can also fetch records with raw SQL through the dataset:
143
-
144
- DB['select * from items'].each do |row|
145
- p row
146
- end
147
-
148
- === Getting Dataset Instances
149
-
150
- Dataset is the primary means through which records are retrieved and manipulated. You can create an blank dataset by using the dataset method:
151
-
152
- dataset = DB.dataset
153
-
154
- Or by using the from methods:
155
-
156
- posts = DB.from(:posts)
157
-
158
- The recommended way is the equivalent shorthand:
159
-
160
- posts = DB[:posts]
161
-
162
- Datasets will only fetch records when you explicitly ask for them. Datasets can be manipulated to filter through records, change record order, join tables, etc..
163
-
164
- === Retrieving Records
165
-
166
- You can retrieve records by using the all method:
167
-
168
- posts.all
169
-
170
- The all method returns an array of hashes, where each hash corresponds to a record.
171
-
172
- You can also iterate through records one at a time:
173
-
174
- posts.each{|row| p row}
175
-
176
- Or perform more advanced stuff:
177
-
178
- posts.map(:id)
179
- posts.inject({}){|h, r| h[r[:id]] = r[:name]}
180
-
181
- You can also retrieve the first record in a dataset:
182
-
183
- posts.first
184
-
185
- Or retrieve a single record with a specific value:
186
-
187
- posts[:id => 1]
188
-
189
- If the dataset is ordered, you can also ask for the last record:
190
-
191
- posts.order(:stamp).last
192
-
193
- === Filtering Records
194
-
195
- The simplest way to filter records is to provide a hash of values to match:
196
-
197
- my_posts = posts.filter(:category => 'ruby', :author => 'david')
198
-
199
- You can also specify ranges:
200
-
201
- my_posts = posts.filter(:stamp => (Date.today - 14)..(Date.today - 7))
202
-
203
- Or lists of values:
204
-
205
- my_posts = posts.filter(:category => ['ruby', 'postgres', 'linux'])
206
-
207
- Sequel also accepts expressions:
208
-
209
- my_posts = posts.filter(:stamp > Date.today << 1)
210
-
211
- Some adapters (like postgresql) will also let you specify Regexps:
212
-
213
- my_posts = posts.filter(:category => /ruby/i)
214
-
215
- You can also use an inverse filter:
216
-
217
- my_posts = posts.exclude(:category => /ruby/i)
218
- my_posts = posts.filter(:category => /ruby/i).invert # same as above
219
-
220
- You can also specify a custom WHERE clause using a string:
221
-
222
- posts.filter('stamp IS NOT NULL')
223
-
224
- You can use parameters in your string, as well (ActiveRecord style):
225
-
226
- posts.filter('(stamp < ?) AND (author != ?)', Date.today - 3, author_name)
227
- posts.filter((:stamp < Date.today - 3) & ~(:author => author_name)) # same as above
228
-
229
- Datasets can also be used as subqueries:
230
-
231
- DB[:items].filter('price > ?', DB[:items].select('AVG(price) + 100'))
232
-
233
- After filtering you can retrieve the matching records by using any of the retrieval methods:
234
-
235
- my_posts.each{|row| p row}
236
-
237
- See the doc/dataset_filtering.rdoc file for more details.
238
-
239
- === Summarizing Records
240
-
241
- Counting records is easy:
242
- posts.filter(:category => /ruby/i).count
243
-
244
- And you can also query maximum/minimum values:
245
- max_value = DB[:history].max(:value)
246
-
247
- Or calculate a sum:
248
- total = DB[:items].sum(:price)
249
-
250
- === Ordering Records
251
-
252
- Ordering datasets is simple:
253
-
254
- posts.order(:stamp) # ORDER BY stamp
255
- posts.order(:stamp, :name) # ORDER BY stamp, name
256
-
257
- You can also specify descending order
258
-
259
- posts.order(:stamp.desc) # ORDER BY stamp DESC
260
-
261
- === Deleting Records
262
-
263
- Deleting records from the table is done with delete:
264
-
265
- posts.filter('stamp < ?', Date.today - 3).delete
266
-
267
- === Inserting Records
268
-
269
- Inserting records into the table is done with insert:
270
-
271
- posts.insert(:category => 'ruby', :author => 'david')
272
- posts << {:category => 'ruby', :author => 'david'} # same as above
273
-
274
- === Updating Records
275
-
276
- Updating records in the table is done with update:
277
-
278
- posts.filter('stamp < ?', Date.today - 7).update(:state => 'archived')
279
-
280
- === Joining Tables
281
-
282
- Joining is very useful in a variety of scenarios, for example many-to-many relationships. With Sequel it's really easy:
283
-
284
- order_items = DB[:items].join(:order_items, :item_id => :id).
285
- filter(:order_items__order_id => 1234)
286
-
287
- This is equivalent to the SQL:
288
-
289
- SELECT * FROM items LEFT OUTER JOIN order_items
290
- ON order_items.item_id = items.id
291
- WHERE order_items.order_id = 1234
292
-
293
- You can then do anything you like with the dataset:
294
-
295
- order_total = order_items.sum(:price)
296
-
297
- Which is equivalent to the SQL:
298
-
299
- SELECT sum(price) FROM items LEFT OUTER JOIN order_items
300
- ON order_items.item_id = items.id
301
- WHERE order_items.order_id = 1234
302
-
303
- === Graphing Datasets
304
-
305
- When retrieving records from joined datasets, you get the results in a single hash, which is subject to clobbering:
306
-
307
- DB[:items].join(:order_items, :item_id => :id).first
308
- => {:id=>(could be items.id or order_items.id), :item_id=>order_items.order_id}
309
-
310
- Using graph, you can split the result hashes into subhashes, one per join:
311
-
312
- DB[:items].graph(:order_items, :item_id => :id).first
313
- => {:items=>{:id=>items.id}, :order_items=>{:id=>order_items.id, :item_id=>order_items.item_id}}
data/Rakefile DELETED
@@ -1,158 +0,0 @@
1
- require "rake"
2
- require "rake/clean"
3
- require "rake/gempackagetask"
4
- require "rake/rdoctask"
5
- require "fileutils"
6
- include FileUtils
7
-
8
- ##############################################################################
9
- # Configuration
10
- ##############################################################################
11
- NAME = "sequel_core"
12
- VERS = "2.2.0"
13
- CLEAN.include ["**/.*.sw?", "pkg", ".config", "rdoc", "coverage"]
14
- RDOC_OPTS = ["--quiet", "--line-numbers", "--inline-source", '--title', \
15
- 'Sequel: The Database Toolkit for Ruby: Core Library and Adapters', \
16
- '--main', 'README']
17
-
18
- ##############################################################################
19
- # RDoc
20
- ##############################################################################
21
- Rake::RDocTask.new do |rdoc|
22
- rdoc.rdoc_dir = "rdoc"
23
- rdoc.options += RDOC_OPTS
24
- rdoc.rdoc_files.add ["README", "COPYING", "doc/*.rdoc", "lib/**/*.rb"]
25
- end
26
-
27
- ##############################################################################
28
- # Gem packaging
29
- ##############################################################################
30
- desc "Packages up Sequel."
31
- task :package => [:clean]
32
-
33
- spec = Gem::Specification.new do |s|
34
- s.name = NAME
35
- s.rubyforge_project = 'sequel'
36
- s.version = VERS
37
- s.platform = Gem::Platform::RUBY
38
- s.has_rdoc = true
39
- s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"] + Dir["doc/*.rdoc"]
40
- s.rdoc_options += RDOC_OPTS + ["--exclude", "^(examples|extras)\/"]
41
- s.summary = "The Database Toolkit for Ruby: Core Library and Adapters"
42
- s.description = s.summary
43
- s.author = "Jeremy Evans"
44
- s.email = "code@jeremyevans.net"
45
- s.homepage = "http://sequel.rubyforge.org"
46
- s.executables = ["sequel"]
47
- s.required_ruby_version = ">= 1.8.4"
48
- s.files = %w(COPYING README Rakefile) + Dir.glob("{bin,doc,spec,lib}/**/*")
49
- s.require_path = "lib"
50
- s.bindir = "bin"
51
- end
52
-
53
- Rake::GemPackageTask.new(spec) do |p|
54
- p.need_tar = true
55
- p.gem_spec = spec
56
- end
57
-
58
- ##############################################################################
59
- # installation & removal
60
- ##############################################################################
61
- desc "Install sequel_core gem"
62
- task :install do
63
- sh %{rake package}
64
- sh %{sudo gem install pkg/#{NAME}-#{VERS}}
65
- end
66
-
67
- desc "Install sequel_core gem without docs"
68
- task :install_no_docs do
69
- sh %{rake package}
70
- sh %{sudo gem install pkg/#{NAME}-#{VERS} --no-rdoc --no-ri}
71
- end
72
-
73
- desc "Uninstall sequel_core gem"
74
- task :uninstall => [:clean] do
75
- sh %{sudo gem uninstall #{NAME}}
76
- end
77
-
78
- ##############################################################################
79
- # gem and rdoc release
80
- ##############################################################################
81
- desc "Upload sequel_core gem to rubyforge"
82
- task :release => [:package] do
83
- sh %{rubyforge login}
84
- sh %{rubyforge add_release sequel #{NAME} #{VERS} pkg/#{NAME}-#{VERS}.tgz}
85
- sh %{rubyforge add_file sequel #{NAME} #{VERS} pkg/#{NAME}-#{VERS}.gem}
86
- end
87
-
88
- ##############################################################################
89
- # specs
90
- ##############################################################################
91
- require "spec/rake/spectask"
92
-
93
- desc "Run specs with coverage"
94
- Spec::Rake::SpecTask.new("spec") do |t|
95
- t.spec_files = FileList["spec/*_spec.rb"]
96
- t.spec_opts = File.read("spec/spec.opts").split("\n")
97
- t.rcov_opts = File.read("spec/rcov.opts").split("\n")
98
- t.rcov = true
99
- end
100
-
101
- desc "Run specs without coverage"
102
- task :default => [:spec_no_cov]
103
- Spec::Rake::SpecTask.new("spec_no_cov") do |t|
104
- t.spec_files = FileList["spec/*_spec.rb"]
105
- t.spec_opts = File.read("spec/spec.opts").split("\n")
106
- end
107
-
108
- desc "Run adapter specs without coverage"
109
- Spec::Rake::SpecTask.new("spec_adapters") do |t|
110
- t.spec_files = FileList["spec/adapters/*_spec.rb"]
111
- t.spec_opts = File.read("spec/spec.opts").split("\n")
112
- end
113
-
114
- %w'postgres sqlite mysql informix oracle'.each do |adapter|
115
- desc "Run #{adapter} specs without coverage"
116
- Spec::Rake::SpecTask.new("spec_#{adapter}") do |t|
117
- t.spec_files = "spec/adapters/#{adapter}_spec.rb"
118
- t.spec_opts = File.read("spec/spec.opts").split("\n")
119
- end
120
- end
121
-
122
- desc "Run all specs with coverage"
123
- Spec::Rake::SpecTask.new("spec_all") do |t|
124
- t.spec_files = FileList["spec/*_spec.rb", "spec/adapters/*_spec.rb"]
125
- t.rcov_opts = File.read("spec/rcov.opts").split("\n")
126
- t.spec_opts = File.read("spec/spec.opts").split("\n")
127
- t.rcov = true
128
- end
129
-
130
- desc "Run rcov only"
131
- Spec::Rake::SpecTask.new("rcov") do |t|
132
- t.rcov_opts = File.read("spec/rcov.opts").split("\n")
133
- t.spec_opts = File.read("spec/spec.opts").split("\n")
134
- t.spec_files = FileList["spec/*_spec.rb"]
135
- t.rcov = true
136
- end
137
-
138
- desc "check documentation coverage"
139
- task :dcov do
140
- sh "find lib -name '*.rb' | xargs dcov"
141
- end
142
-
143
- ##############################################################################
144
- # Statistics
145
- ##############################################################################
146
-
147
- STATS_DIRECTORIES = [
148
- %w(Code lib/),
149
- %w(Spec spec/)
150
- ].collect { |name, dir| [ name, "./#{dir}" ] }.select { |name, dir| File.directory?(dir) }
151
-
152
- desc "Report code statistics (KLOCs, etc) from the application"
153
- task :stats do
154
- require "../extra/stats"
155
- verbose = true
156
- CodeStatistics.new(*STATS_DIRECTORIES).to_s
157
- end
158
-