sequel 0.0.11 → 0.0.12
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.
- data/CHANGELOG +14 -0
- data/Rakefile +1 -1
- data/lib/sequel/dataset.rb +11 -1
- data/lib/sequel/model.rb +26 -6
- metadata +8 -7
data/CHANGELOG
CHANGED
@@ -1,5 +1,19 @@
|
|
1
|
+
*0.0.12*
|
2
|
+
|
3
|
+
* Model#save now correctly performs an INSERT for new objects.
|
4
|
+
|
5
|
+
* Added Model#reload for reloading an object from the database.
|
6
|
+
|
7
|
+
* Added Dataset#naked method for getting a version of a dataset that fetches records as hashes.
|
8
|
+
|
9
|
+
* Implemented attribute accessors for column values ala ActiveRecord models.
|
10
|
+
|
11
|
+
* Fixed filtering using nil values (e.g. dataset.filter(:parent_id => nil)).
|
12
|
+
|
1
13
|
*0.0.11*
|
2
14
|
|
15
|
+
* Renamed Model.schema to Model.set_schema and Model.get_schema to Model.schema.
|
16
|
+
|
3
17
|
* Improved Model class to allow descendants of model clases (thanks Pedro Gutierrez.)
|
4
18
|
|
5
19
|
* Removed require 'postgres' in schema.rb (thanks Douglas Koszerek.)
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require 'fileutils'
|
|
6
6
|
include FileUtils
|
7
7
|
|
8
8
|
NAME = "sequel"
|
9
|
-
VERS = "0.0.
|
9
|
+
VERS = "0.0.12"
|
10
10
|
CLEAN.include ['**/.*.sw?', 'pkg/*', '.config', 'doc/*', 'coverage/*']
|
11
11
|
RDOC_OPTS = ['--quiet', '--title', "Sequel: Concise ORM for Ruby",
|
12
12
|
"--opname", "index.html",
|
data/lib/sequel/dataset.rb
CHANGED
@@ -47,6 +47,13 @@ module Sequel
|
|
47
47
|
self.class.new(@db, @opts.merge(opts), @record_class)
|
48
48
|
end
|
49
49
|
|
50
|
+
# Returns a dataset that fetches records as hashes (instead of model
|
51
|
+
# objects). If no record class is defined for the dataset, self is
|
52
|
+
# returned.
|
53
|
+
def naked
|
54
|
+
@record_class ? self.class.new(@db, @opts) : self
|
55
|
+
end
|
56
|
+
|
50
57
|
AS_REGEXP = /(.*)___(.*)/.freeze
|
51
58
|
AS_FORMAT = "%s AS %s".freeze
|
52
59
|
DOUBLE_UNDERSCORE = '__'.freeze
|
@@ -118,6 +125,7 @@ module Sequel
|
|
118
125
|
# BETWEEN_EXPR = "(%s BETWEEN %s AND %s)".freeze
|
119
126
|
INCLUSIVE_RANGE_EXPR = "(%s >= %s AND %s <= %s)".freeze
|
120
127
|
EXCLUSIVE_RANGE_EXPR = "(%s >= %s AND %s < %s)".freeze
|
128
|
+
NULL_EXPR = "(%s IS NULL)".freeze
|
121
129
|
|
122
130
|
# Formats an equality condition SQL expression.
|
123
131
|
def where_condition(left, right)
|
@@ -129,6 +137,8 @@ module Sequel
|
|
129
137
|
# BETWEEN_EXPR % [field_name(left), literal(right.begin), literal(right.end)]
|
130
138
|
when Array:
|
131
139
|
IN_EXPR % [left, literal(right)]
|
140
|
+
when NilClass:
|
141
|
+
NULL_EXPR % left
|
132
142
|
when self.class:
|
133
143
|
IN_EXPR % [left, right.sql]
|
134
144
|
else
|
@@ -415,7 +425,7 @@ module Sequel
|
|
415
425
|
end
|
416
426
|
|
417
427
|
def print(*columns)
|
418
|
-
Sequel::PrettyTable.print(all, columns.empty? ? nil : columns)
|
428
|
+
Sequel::PrettyTable.print(naked.all, columns.empty? ? nil : columns)
|
419
429
|
end
|
420
430
|
end
|
421
431
|
end
|
data/lib/sequel/model.rb
CHANGED
@@ -215,8 +215,34 @@ module Sequel
|
|
215
215
|
|
216
216
|
def db; @@db; end
|
217
217
|
|
218
|
+
ASSIGN_METHOD_REGEXP = /(.*)=$/.freeze
|
219
|
+
|
220
|
+
def method_missing(sym, value = nil)
|
221
|
+
if sym.to_s =~ ASSIGN_METHOD_REGEXP
|
222
|
+
@values[$1.to_sym] = value
|
223
|
+
else
|
224
|
+
@values[sym]
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def reload
|
229
|
+
temp = self.class[@pkey]
|
230
|
+
@values = self.class.dataset.naked[primary_key => @pkey]
|
231
|
+
end
|
232
|
+
|
218
233
|
def [](field); @values[field]; end
|
219
234
|
|
235
|
+
def []=(field, value); @values[field] = value; end
|
236
|
+
|
237
|
+
def save
|
238
|
+
if @pkey
|
239
|
+
model.dataset.filter(primary_key => @pkey).update(@values)
|
240
|
+
else
|
241
|
+
@pkey = model.dataset.insert(@values)
|
242
|
+
reload
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
220
246
|
def ==(obj)
|
221
247
|
(obj.class == model) && (obj.pkey == @pkey)
|
222
248
|
end
|
@@ -225,12 +251,6 @@ module Sequel
|
|
225
251
|
model.dataset.filter(primary_key => @pkey).update(values)
|
226
252
|
@values.merge!(values)
|
227
253
|
end
|
228
|
-
|
229
|
-
def []=(field, value); @values[field] = value; end
|
230
|
-
|
231
|
-
def save
|
232
|
-
model.dataset.filter(primary_key => @pkey).update(@values)
|
233
|
-
end
|
234
254
|
end
|
235
255
|
|
236
256
|
def self.Model(table_name)
|
metadata
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: sequel
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
6
|
+
version: 0.0.12
|
7
7
|
date: 2007-03-27 00:00:00 +02:00
|
8
8
|
summary: Concise ORM for Ruby.
|
9
9
|
require_paths:
|
@@ -33,18 +33,19 @@ files:
|
|
33
33
|
- README
|
34
34
|
- Rakefile
|
35
35
|
- bin/sequel
|
36
|
+
- doc/rdoc
|
36
37
|
- lib/sequel
|
37
38
|
- lib/sequel.rb
|
39
|
+
- lib/sequel/connection_pool.rb
|
40
|
+
- lib/sequel/core_ext.rb
|
41
|
+
- lib/sequel/database.rb
|
38
42
|
- lib/sequel/dataset.rb
|
39
43
|
- lib/sequel/model.rb
|
44
|
+
- lib/sequel/mysql.rb
|
40
45
|
- lib/sequel/postgres.rb
|
46
|
+
- lib/sequel/pretty_table.rb
|
41
47
|
- lib/sequel/schema.rb
|
42
48
|
- lib/sequel/sqlite.rb
|
43
|
-
- lib/sequel/connection_pool.rb
|
44
|
-
- lib/sequel/database.rb
|
45
|
-
- lib/sequel/core_ext.rb
|
46
|
-
- lib/sequel/mysql.rb
|
47
|
-
- lib/sequel/pretty_table.rb
|
48
49
|
- CHANGELOG
|
49
50
|
test_files: []
|
50
51
|
|