sequel_model 0.5.0.2 → 3.8.0

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,98 +1,51 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.2
4
+ version: 3.8.0
5
5
  platform: ruby
6
6
  authors:
7
- - Sharon Rosner
7
+ - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-12 00:00:00 +02:00
12
+ date: 2010-02-05 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: assistance
16
+ name: sequel
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
20
21
  - - ">="
21
22
  - !ruby/object:Gem::Version
22
- version: 0.1.2
23
+ version: 3.8.0
23
24
  version:
24
- - !ruby/object:Gem::Dependency
25
- name: sequel_core
26
- version_requirement:
27
- version_requirements: !ruby/object:Gem::Requirement
28
- requirements:
29
- - - ">="
30
- - !ruby/object:Gem::Version
31
- version: "1.0"
32
- version:
33
- description: Model classes for Sequel
34
- email: ciconia@gmail.com
25
+ description:
26
+ email: code@jeremyevans.net
35
27
  executables: []
36
28
 
37
29
  extensions: []
38
30
 
39
- extra_rdoc_files:
40
- - README
41
- - CHANGELOG
42
- - COPYING
43
- files:
44
- - COPYING
45
- - README
46
- - Rakefile
47
- - spec/associations_spec.rb
48
- - spec/base_spec.rb
49
- - spec/caching_spec.rb
50
- - spec/deprecated_relations_spec.rb
51
- - spec/hooks_spec.rb
52
- - spec/model_spec.rb
53
- - spec/plugins_spec.rb
54
- - spec/rcov.opts
55
- - spec/record_spec.rb
56
- - spec/schema_spec.rb
57
- - spec/spec.opts
58
- - spec/spec_helper.rb
59
- - spec/validations_spec.rb
60
- - lib/sequel_model
61
- - lib/sequel_model/associations.rb
62
- - lib/sequel_model/base.rb
63
- - lib/sequel_model/caching.rb
64
- - lib/sequel_model/hooks.rb
65
- - lib/sequel_model/plugins.rb
66
- - lib/sequel_model/pretty_table.rb
67
- - lib/sequel_model/record.rb
68
- - lib/sequel_model/schema.rb
69
- - lib/sequel_model/validations.rb
70
- - lib/sequel_model.rb
71
- - CHANGELOG
31
+ extra_rdoc_files: []
32
+
33
+ files: []
34
+
72
35
  has_rdoc: true
73
- homepage: http://sequel.rubyforge.org
36
+ homepage: http://sequel.rubyforge.org/
37
+ licenses: []
38
+
74
39
  post_install_message:
75
- rdoc_options:
76
- - --quiet
77
- - --title
78
- - "Sequel: The Database Toolkit for Ruby"
79
- - --opname
80
- - index.html
81
- - --line-numbers
82
- - --main
83
- - README
84
- - --inline-source
85
- - --exclude
86
- - ^(examples|extras)/
87
- - --exclude
88
- - lib/sequel_model.rb
40
+ rdoc_options: []
41
+
89
42
  require_paths:
90
43
  - lib
91
44
  required_ruby_version: !ruby/object:Gem::Requirement
92
45
  requirements:
93
46
  - - ">="
94
47
  - !ruby/object:Gem::Version
95
- version: 1.8.4
48
+ version: "0"
96
49
  version:
97
50
  required_rubygems_version: !ruby/object:Gem::Requirement
98
51
  requirements:
@@ -102,10 +55,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
55
  version:
103
56
  requirements: []
104
57
 
105
- rubyforge_project: sequel
106
- rubygems_version: 1.0.1
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.5
107
60
  signing_key:
108
- specification_version: 2
109
- summary: Model classes for Sequel
61
+ specification_version: 3
62
+ summary: "Old Name: sequel_model, New Name: sequel"
110
63
  test_files: []
111
64
 
data/CHANGELOG DELETED
@@ -1,111 +0,0 @@
1
- === 0.5.0.2 (2008-03-12)
2
-
3
- * More fixes for Model.associate to accept strings and symbols as class references.
4
-
5
- === 0.5.0.1 (2008-03-09)
6
-
7
- * Fixed Model.associate to accept class and class name in :class option.
8
-
9
- === 0.5 (2008-03-08)
10
-
11
- * Merged new associations branch into trunk.
12
-
13
- * Rewrote RDoc for associations.
14
-
15
- * Added has_and_belongs_to_many alias for many_to_many.
16
-
17
- * Added support for optional dataset block.
18
-
19
- * Added :order option to order association datasets.
20
-
21
- * Added :cache option to return and cache array of objects for association.
22
-
23
- * Changed one_to_many, many_to_many associations to return dataset by default.
24
-
25
- * Added has_many, belongs_to aliases.
26
-
27
- * Refactored associations code.
28
-
29
- * Added deprecations for old-style relations.
30
-
31
- * Completed specs for new associations code.
32
-
33
- * New associations code by Jeremy Evans (replaces relations code.)
34
-
35
- === 0.4.2 (2008-02-29)
36
-
37
- * Fixed one_to_many implicit key to work correctly for namespaced classes (#167).
38
-
39
- * Fixed Model.db= to affect the underlying dataset (#183).
40
-
41
- * Fixed Model.implicit_table_name to disregard namespaces.
42
-
43
- === 0.4.1 (2008-02-10)
44
-
45
- * Implemented Model#inspect (#151).
46
-
47
- * Changed Model#method_missing to short-circuit and bypass checking #columns if the values hash already contains the relevant column (#150).
48
-
49
- * Updated to reflect changes in sequel_core (Dataset#clone_merge renamed to Dataset#clone).
50
-
51
- === 0.4 (2008-02-05)
52
-
53
- * Fixed Model#set to work with string keys (#143).
54
-
55
- * Fixed Model.create to correctly initialize instances marked as new (#135).
56
-
57
- * Fixed Model#initialize to convert string keys into symbol keys. This also fixes problem with validating objects initialized with string keys (#136).
58
-
59
- === 0.3.3 (2008-01-25)
60
-
61
- * Finalized support for virtual attributes.
62
-
63
- === 0.3.2.1 (2008-01-24)
64
-
65
- * Fixed Model.dataset to correctly set the dataset if using implicit naming or inheriting the superclass dataset (thanks celldee).
66
-
67
- === 0.3.2 (2008-01-24)
68
-
69
- * Added Model#update_with_params method with support for virtual attributes and auto-filtering of unrelated parameters, and changed Model.create_with_params to support virtual attributes (#128).
70
-
71
- * Cleaned up gem spec (#132).
72
-
73
- * Removed validations code. Now relying on validations in assistance gem.
74
-
75
- === 0.3.1 (2008-01-21)
76
-
77
- * Changed Model.dataset to use inflector to pluralize the class name into the table name. Works in similar fashion to table names in AR or DM.
78
-
79
- === 0.3 (2008-01-18)
80
-
81
- * Implemented Validatable::Errors class.
82
-
83
- * Added Model#reload as alias to Model#refresh.
84
-
85
- * Changed Model.create to accept a block (#126).
86
-
87
- * Rewrote validations.
88
-
89
- * Fixed Model#initialize to accept nil values (#115).
90
-
91
- === 0.2 (2008-01-02)
92
-
93
- * Removed deprecated Model.recreate_table method.
94
-
95
- * Removed deprecated :class and :on options from one_to_many macro.
96
-
97
- * Removed deprecated :class option from one_to_one macro.
98
-
99
- * Removed deprecated Model#pkey method.
100
-
101
- * Changed dependency to sequel_core.
102
-
103
- * Removed examples from sequel core.
104
-
105
- * Additional specs. We're now at 100% coverage.
106
-
107
- * Refactored hooks code. Hooks are now inheritable, and can be defined by supplying a block or a method name, or by overriding the hook instance method. Hook chains can now be broken by returning false (#111, #112).
108
-
109
- === 0.1 (2007-12-30)
110
-
111
- * Moved model code from sequel into separate model sub-project.
data/COPYING DELETED
@@ -1,18 +0,0 @@
1
- Copyright (c) 2007-2008 Sharon Rosner
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to
5
- deal in the Software without restriction, including without limitation the
6
- rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
- sell copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
- THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README DELETED
@@ -1,251 +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
- * {Project page}[http://code.google.com/p/ruby-sequel/]
10
- * {Source code}[http://ruby-sequel.googlecode.com/svn/]
11
- * {Bug tracking}[http://code.google.com/p/ruby-sequel/issues/list]
12
- * {Google group}[http://groups.google.com/group/sequel-talk]
13
- * {RubyForge page}[http://rubyforge.org/projects/sequel/]
14
-
15
- To check out the source code:
16
-
17
- svn co http://ruby-sequel.googlecode.com/svn/trunk
18
-
19
- === Contact
20
-
21
- If you have any comments or suggestions please send an email to ciconia at gmail.com and I'll get back to you.
22
-
23
- == Installation
24
-
25
- sudo gem install sequel
26
-
27
- == Supported Databases
28
-
29
- Sequel currently supports:
30
-
31
- * ADO (on Windows)
32
- * DBI
33
- * Informix
34
- * MySQL
35
- * ODBC
36
- * Oracle
37
- * PostgreSQL
38
- * SQLite 3
39
-
40
- There are also experimental adapters for DB2, OpenBase and JDBC (on JRuby).
41
-
42
- == The Sequel Console
43
-
44
- Sequel includes an IRB console for quick'n'dirty access to databases. You can use it like this:
45
-
46
- sequel sqlite:///test.db
47
-
48
- You get an IRB session with the database object stored in DB.
49
-
50
- == An Introduction
51
-
52
- 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.
53
-
54
- 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.
55
-
56
- For example, the following one-liner returns the average GDP for the five biggest countries in the middle east region:
57
-
58
- DB[:countries].filter(:region => 'Middle East').reverse_order(:area).limit(5).avg(:GDP)
59
-
60
- Which is equivalent to:
61
-
62
- SELECT avg(GDP) FROM countries WHERE region = 'Middle East' ORDER BY area DESC LIMIT 5
63
-
64
- 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:
65
-
66
- middle_east = DB[:countries].filter(:region => 'Middle East')
67
- middle_east.order(:name).each {|r| puts r[:name]}
68
-
69
- Sequel also offers convenience methods for extracting data from Datasets, such as an extended map method:
70
-
71
- middle_east.map(:name) #=> ['Egypt', 'Greece', 'Israel', ...]
72
-
73
- Or getting results as a transposed hash, with one column as key and another as value:
74
-
75
- middle_east.to_hash(:name, :area) #=> {'Israel' => 20000, 'Greece' => 120000, ...}
76
-
77
- Much of Sequel is still undocumented (especially the part relating to model classes). The following section provides examples of common usage. Feel free to explore...
78
-
79
- == Getting Started
80
-
81
- === Connecting to a database
82
-
83
- To connect to a database you simply provide Sequel with a URL:
84
-
85
- require 'sequel'
86
- DB = Sequel.open 'sqlite:///blog.db'
87
-
88
- The connection URL can also include such stuff as the user name and password:
89
-
90
- DB = Sequel.open 'postgres://cico:12345@localhost:5432/mydb'
91
-
92
- You can also specify optional parameters, such as the connection pool size, or a logger for logging SQL queries:
93
-
94
- DB = Sequel.open("postgres://postgres:postgres@localhost/my_db",
95
- :max_connections => 10, :logger => Logger.new('log/db.log'))
96
-
97
- === Arbitrary SQL queries
98
-
99
- DB.execute("create table t (a text, b text)")
100
- DB.execute("insert into t values ('a', 'b')")
101
-
102
- Or more succinctly:
103
-
104
- DB << "create table t (a text, b text)"
105
- DB << "insert into t values ('a', 'b')"
106
-
107
- === Getting Dataset Instances
108
-
109
- Dataset is the primary means through which records are retrieved and manipulated. You can create an blank dataset by using the dataset method:
110
-
111
- dataset = DB.dataset
112
-
113
- Or by using the from methods:
114
-
115
- posts = DB.from(:posts)
116
-
117
- You can also use the equivalent shorthand:
118
-
119
- posts = DB[:posts]
120
-
121
- Note: the dataset will only fetch records when you explicitly ask for them, as will be shown below. Datasets can be manipulated to filter through records, change record order and even join tables, as will also be shown below.
122
-
123
- === Retrieving Records
124
-
125
- You can retrieve records by using the all method:
126
-
127
- posts.all
128
-
129
- The all method returns an array of hashes, where each hash corresponds to a record.
130
-
131
- You can also iterate through records one at a time:
132
-
133
- posts.each {|row| p row}
134
-
135
- Or perform more advanced stuff:
136
-
137
- posts.map(:id)
138
- posts.inject({}) {|h, r| h[r[:id]] = r[:name]}
139
-
140
- You can also retrieve the first record in a dataset:
141
-
142
- posts.first
143
-
144
- Or retrieve a single record with a specific value:
145
-
146
- posts[:id => 1]
147
-
148
- If the dataset is ordered, you can also ask for the last record:
149
-
150
- posts.order(:stamp).last
151
-
152
- === Filtering Records
153
-
154
- The simplest way to filter records is to provide a hash of values to match:
155
-
156
- my_posts = posts.filter(:category => 'ruby', :author => 'david')
157
-
158
- You can also specify ranges:
159
-
160
- my_posts = posts.filter(:stamp => (2.weeks.ago)..(1.week.ago))
161
-
162
- Or lists of values:
163
-
164
- my_posts = posts.filter(:category => ['ruby', 'postgres', 'linux'])
165
-
166
- Sequel now also accepts expressions as closures, AKA block filters:
167
-
168
- my_posts = posts.filter {:category == ['ruby', 'postgres', 'linux']}
169
-
170
- Which also lets you do stuff like:
171
-
172
- my_posts = posts.filter {:stamp > 1.month.ago}
173
-
174
- Some adapters (like postgresql) will also let you specify Regexps:
175
-
176
- my_posts = posts.filter(:category => /ruby/i)
177
-
178
- You can also use an inverse filter:
179
-
180
- my_posts = posts.exclude(:category => /ruby/i)
181
-
182
- You can then retrieve the records by using any of the retrieval methods:
183
-
184
- my_posts.each {|row| p row}
185
-
186
- You can also specify a custom WHERE clause:
187
-
188
- posts.filter('(stamp < ?) AND (author <> ?)', 3.days.ago, author_name)
189
-
190
- Datasets can also be used as subqueries:
191
-
192
- DB[:items].filter('price > ?', DB[:items].select('AVG(price) + 100'))
193
-
194
- === Summarizing Records
195
-
196
- Counting records is easy:
197
- posts.filter(:category => /ruby/i).count
198
-
199
- And you can also query maximum/minimum values:
200
- max_value = DB[:history].max(:value)
201
-
202
- Or calculate a sum:
203
- total = DB[:items].sum(:price)
204
-
205
- === Ordering Records
206
-
207
- posts.order(:stamp)
208
-
209
- You can also specify descending order
210
-
211
- posts.order(:stamp.DESC)
212
-
213
- === Deleting Records
214
-
215
- posts.filter('stamp < ?', 3.days.ago).delete
216
-
217
- === Inserting Records
218
-
219
- posts.insert(:category => 'ruby', :author => 'david')
220
-
221
- Or alternatively:
222
-
223
- posts << {:category => 'ruby', :author => 'david'}
224
-
225
- === Updating Records
226
-
227
- posts.filter('stamp < ?', 3.days.ago).update(:state => 'archived')
228
-
229
- === Joining Tables
230
-
231
- Joining is very useful in a variety of scenarios, for example many-to-many relationships. With Sequel it's really easy:
232
-
233
- order_items = DB[:items].join(:order_items, :item_id => :id).
234
- filter(:order_items__order_id => 1234)
235
-
236
- This is equivalent to the SQL:
237
-
238
- SELECT * FROM items LEFT OUTER JOIN order_items
239
- ON order_items.item_id = items.id
240
- WHERE order_items.order_id = 1234
241
-
242
- You can then do anything you like with the dataset:
243
-
244
- order_total = order_items.sum(:price)
245
-
246
- Which is equivalent to the SQL:
247
-
248
- SELECT sum(price) FROM items LEFT OUTER JOIN order_items
249
- ON order_items.item_id = items.id
250
- WHERE order_items.order_id = 1234
251
-