sequel_core 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -0
- data/COPYING +1 -1
- data/Rakefile +1 -1
- data/lib/sequel_core/adapters/postgres.rb +7 -1
- data/lib/sequel_core/dataset/sql.rb +39 -7
- data/lib/sequel_core/dataset.rb +2 -2
- data/spec/adapters/mysql_spec.rb +22 -0
- data/spec/database_spec.rb +1 -0
- data/spec/dataset_spec.rb +44 -0
- metadata +33 -33
data/CHANGELOG
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
=== 1.0.6 (2008-02-05)
|
2
|
+
|
3
|
+
* Removed code pollution introduced in revs 814, 817 (really bad patch, IMO).
|
4
|
+
|
5
|
+
* Fixed joining datasets using aliased tables (#140).
|
6
|
+
|
7
|
+
* Added support additional field types in postgresql adapter (#146).
|
8
|
+
|
9
|
+
* Added support for date field types in postgresql adapter (#145).
|
10
|
+
|
11
|
+
* Fixed Dataset#count to work correctly for grouped datasets (#144).
|
12
|
+
|
13
|
+
* Added Dataset#select_more, Dataset#order_more methods (#129).
|
14
|
+
|
1
15
|
=== 1.0.5 (2008-01-25)
|
2
16
|
|
3
17
|
* Added support for instantiating models by using the load constructor method.
|
data/COPYING
CHANGED
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ include FileUtils
|
|
9
9
|
# Configuration
|
10
10
|
##############################################################################
|
11
11
|
NAME = "sequel_core"
|
12
|
-
VERS = "1.0.
|
12
|
+
VERS = "1.0.6"
|
13
13
|
CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "doc/*", "coverage/*"]
|
14
14
|
RDOC_OPTS = [
|
15
15
|
"--quiet",
|
@@ -160,9 +160,15 @@ module Sequel
|
|
160
160
|
21 => :to_i,
|
161
161
|
22 => :to_i,
|
162
162
|
23 => :to_i,
|
163
|
+
26 => :to_i,
|
163
164
|
700 => :to_f,
|
164
165
|
701 => :to_f,
|
165
|
-
|
166
|
+
790 => :to_f,
|
167
|
+
1082 => :to_date,
|
168
|
+
1083 => :to_time,
|
169
|
+
1114 => :to_time,
|
170
|
+
1184 => :to_time,
|
171
|
+
1186 => :to_i
|
166
172
|
}
|
167
173
|
|
168
174
|
if PGconn.respond_to?(:translate_results=)
|
@@ -22,7 +22,6 @@ module Sequel
|
|
22
22
|
table = $2
|
23
23
|
end
|
24
24
|
Sequel::SQL::QualifiedColumnRef.new(table, column)
|
25
|
-
# "#{table}.#{column}"
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
@@ -62,6 +61,19 @@ module Sequel
|
|
62
61
|
end
|
63
62
|
m.join(COMMA_SEPARATOR)
|
64
63
|
end
|
64
|
+
|
65
|
+
def first_source
|
66
|
+
source = @opts[:from]
|
67
|
+
if source.nil? || source.empty?
|
68
|
+
raise Error, 'No source specified for query'
|
69
|
+
end
|
70
|
+
case s = source.first
|
71
|
+
when Hash
|
72
|
+
s.values.first
|
73
|
+
else
|
74
|
+
s
|
75
|
+
end
|
76
|
+
end
|
65
77
|
|
66
78
|
NULL = "NULL".freeze
|
67
79
|
TIMESTAMP_FORMAT = "TIMESTAMP '%Y-%m-%d %H:%M:%S'".freeze
|
@@ -147,9 +159,12 @@ module Sequel
|
|
147
159
|
#
|
148
160
|
# ds = DB[:items].order(:name)
|
149
161
|
# ds.sql #=> "SELECT * FROM items ORDER BY name"
|
150
|
-
# ds.from_self #=> "SELECT * FROM (SELECT * FROM items ORDER BY name)"
|
162
|
+
# ds.from_self.sql #=> "SELECT * FROM (SELECT * FROM items ORDER BY name)"
|
151
163
|
def from_self
|
152
|
-
clone_merge(:
|
164
|
+
clone_merge(:from => [self], :select => nil, :group => nil,
|
165
|
+
:sql => nil, :distinct => nil, :join => nil, :where => nil,
|
166
|
+
:order => nil, :having => nil, :limit => nil, :offset => nil,
|
167
|
+
:union => nil)
|
153
168
|
end
|
154
169
|
|
155
170
|
# Returns a copy of the dataset with the selected columns changed.
|
@@ -157,6 +172,15 @@ module Sequel
|
|
157
172
|
clone_merge(:select => columns)
|
158
173
|
end
|
159
174
|
|
175
|
+
# Returns a copy of the dataset with additional selected columns.
|
176
|
+
def select_more(*columns)
|
177
|
+
if @opts[:select]
|
178
|
+
clone_merge(:select => @opts[:select] + columns)
|
179
|
+
else
|
180
|
+
clone_merge(:select => columns)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
160
184
|
# Returns a copy of the dataset selecting the wildcard.
|
161
185
|
def select_all
|
162
186
|
clone_merge(:select => nil)
|
@@ -172,9 +196,17 @@ module Sequel
|
|
172
196
|
def order(*order)
|
173
197
|
clone_merge(:order => order)
|
174
198
|
end
|
175
|
-
|
176
199
|
alias_method :order_by, :order
|
177
|
-
|
200
|
+
|
201
|
+
# Returns a copy of the dataset with the order changed.
|
202
|
+
def order_more(*order)
|
203
|
+
if @opts[:order]
|
204
|
+
clone_merge(:order => @opts[:order] + order)
|
205
|
+
else
|
206
|
+
clone_merge(:order => order)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
178
210
|
# Returns a copy of the dataset with the order reversed. If no order is
|
179
211
|
# given, the existing order is inverted.
|
180
212
|
def reverse_order(*order)
|
@@ -340,7 +372,7 @@ module Sequel
|
|
340
372
|
join_conditions = {}
|
341
373
|
expr.each do |k, v|
|
342
374
|
k = qualified_column_name(k, table) if k.is_a?(Symbol)
|
343
|
-
v = qualified_column_name(v, @opts[:last_joined_table] ||
|
375
|
+
v = qualified_column_name(v, @opts[:last_joined_table] || first_source) if v.is_a?(Symbol)
|
344
376
|
join_conditions[k] = v
|
345
377
|
end
|
346
378
|
" #{join_type} #{table} ON #{expression_list(join_conditions)}"
|
@@ -592,7 +624,7 @@ module Sequel
|
|
592
624
|
|
593
625
|
# Returns the number of records in the dataset.
|
594
626
|
def count
|
595
|
-
if @opts[:sql]
|
627
|
+
if @opts[:sql] || @opts[:group]
|
596
628
|
from_self.count
|
597
629
|
else
|
598
630
|
single_value(STOCK_COUNT_OPTS).to_i
|
data/lib/sequel_core/dataset.rb
CHANGED
@@ -72,8 +72,8 @@ module Sequel
|
|
72
72
|
attr_reader :db
|
73
73
|
attr_accessor :opts
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
alias_method :all, :to_a
|
76
|
+
alias_method :size, :count
|
77
77
|
|
78
78
|
# Constructs a new instance of a dataset with a database instance, initial
|
79
79
|
# options and an optional record class. Datasets are usually constructed by
|
data/spec/adapters/mysql_spec.rb
CHANGED
@@ -379,4 +379,26 @@ context "A MySQL database" do
|
|
379
379
|
db = Sequel.mysql('sandbox', :host => 'localhost', :user => 'root', :socket => 'blah')
|
380
380
|
proc {db.test_connection}.should raise_error
|
381
381
|
end
|
382
|
+
end
|
383
|
+
|
384
|
+
context "A grouped MySQL dataset" do
|
385
|
+
setup do
|
386
|
+
MYSQL_DB[:test2].delete
|
387
|
+
MYSQL_DB[:test2] << {:name => '11', :value => 10}
|
388
|
+
MYSQL_DB[:test2] << {:name => '11', :value => 20}
|
389
|
+
MYSQL_DB[:test2] << {:name => '11', :value => 30}
|
390
|
+
MYSQL_DB[:test2] << {:name => '12', :value => 10}
|
391
|
+
MYSQL_DB[:test2] << {:name => '12', :value => 20}
|
392
|
+
MYSQL_DB[:test2] << {:name => '13', :value => 10}
|
393
|
+
end
|
394
|
+
|
395
|
+
specify "should return the correct count for raw sql query" do
|
396
|
+
ds = MYSQL_DB["select name FROM test2 WHERE name = '11' GROUP BY name"]
|
397
|
+
ds.count.should == 1
|
398
|
+
end
|
399
|
+
|
400
|
+
specify "should return the correct count for a normal dataset" do
|
401
|
+
ds = MYSQL_DB[:test2].select(:name).where(:name => '11').group(:name)
|
402
|
+
ds.count.should == 1
|
403
|
+
end
|
382
404
|
end
|
data/spec/database_spec.rb
CHANGED
data/spec/dataset_spec.rb
CHANGED
@@ -523,6 +523,12 @@ context "a grouped dataset" do
|
|
523
523
|
@dataset.select_sql.should ==
|
524
524
|
"SELECT * FROM test GROUP BY type_id"
|
525
525
|
end
|
526
|
+
|
527
|
+
specify "should format the right statement for counting (as a subquery)" do
|
528
|
+
db = MockDatabase.new
|
529
|
+
db[:test].select(:name).group(:name).count
|
530
|
+
db.sqls.should == ["SELECT COUNT(*) FROM (SELECT name FROM test GROUP BY name) t1"]
|
531
|
+
end
|
526
532
|
end
|
527
533
|
|
528
534
|
context "Dataset#group_by" do
|
@@ -716,6 +722,22 @@ context "Dataset#select_all" do
|
|
716
722
|
end
|
717
723
|
end
|
718
724
|
|
725
|
+
context "Dataset#select_more" do
|
726
|
+
setup do
|
727
|
+
@d = Sequel::Dataset.new(nil).from(:test)
|
728
|
+
end
|
729
|
+
|
730
|
+
specify "should act like #select for datasets with no selection" do
|
731
|
+
@d.select_more(:a, :b).sql.should == 'SELECT a, b FROM test'
|
732
|
+
@d.select_all.select_more(:a, :b).sql.should == 'SELECT a, b FROM test'
|
733
|
+
@d.select(:blah).select_all.select_more(:a, :b).sql.should == 'SELECT a, b FROM test'
|
734
|
+
end
|
735
|
+
|
736
|
+
specify "should add to the currently selected columns" do
|
737
|
+
@d.select(:a).select_more(:b).sql.should == 'SELECT a, b FROM test'
|
738
|
+
@d.select(:a.all).select_more(:b.all).sql.should == 'SELECT a.*, b.* FROM test'
|
739
|
+
end
|
740
|
+
end
|
719
741
|
|
720
742
|
context "Dataset#order" do
|
721
743
|
setup do
|
@@ -769,6 +791,22 @@ context "Dataset#order_by" do
|
|
769
791
|
end
|
770
792
|
end
|
771
793
|
|
794
|
+
context "Dataset#order_more" do
|
795
|
+
setup do
|
796
|
+
@dataset = Sequel::Dataset.new(nil).from(:test)
|
797
|
+
end
|
798
|
+
|
799
|
+
specify "should include an ORDER BY clause in the select statement" do
|
800
|
+
@dataset.order_more(:name).sql.should ==
|
801
|
+
'SELECT * FROM test ORDER BY name'
|
802
|
+
end
|
803
|
+
|
804
|
+
specify "should add to a previous ordering" do
|
805
|
+
@dataset.order(:name).order_more(:stamp.DESC).sql.should ==
|
806
|
+
'SELECT * FROM test ORDER BY name, stamp DESC'
|
807
|
+
end
|
808
|
+
end
|
809
|
+
|
772
810
|
context "Dataset#reverse_order" do
|
773
811
|
setup do
|
774
812
|
@dataset = Sequel::Dataset.new(nil).from(:test)
|
@@ -1094,6 +1132,12 @@ context "Dataset#join_table" do
|
|
1094
1132
|
@d.join_table(:left_outer, :categories, :status => [1, 2, 3]).sql.should ==
|
1095
1133
|
"SELECT * FROM items LEFT OUTER JOIN categories ON (categories.status IN (1, 2, 3))"
|
1096
1134
|
end
|
1135
|
+
|
1136
|
+
specify "should support aliased tables" do
|
1137
|
+
ds = Sequel::Dataset.new(nil).from(:foo => :f). \
|
1138
|
+
join_table(:inner, :bar, :id => :bar_id).sql.should ==
|
1139
|
+
'SELECT * FROM foo f INNER JOIN bar ON (bar.id = f.bar_id)'
|
1140
|
+
end
|
1097
1141
|
end
|
1098
1142
|
|
1099
1143
|
context "Dataset#[]=" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-02-05 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -73,59 +73,59 @@ files:
|
|
73
73
|
- Rakefile
|
74
74
|
- bin/sequel
|
75
75
|
- spec/adapters
|
76
|
-
- spec/adapters/informix_spec.rb
|
77
76
|
- spec/adapters/mysql_spec.rb
|
78
77
|
- spec/adapters/oracle_spec.rb
|
79
78
|
- spec/adapters/postgres_spec.rb
|
79
|
+
- spec/adapters/informix_spec.rb
|
80
80
|
- spec/adapters/sqlite_spec.rb
|
81
|
-
- spec/array_keys_spec.rb
|
82
|
-
- spec/core_ext_spec.rb
|
83
|
-
- spec/core_sql_spec.rb
|
84
81
|
- spec/database_spec.rb
|
82
|
+
- spec/schema_generator_spec.rb
|
83
|
+
- spec/core_sql_spec.rb
|
84
|
+
- spec/core_ext_spec.rb
|
85
|
+
- spec/array_keys_spec.rb
|
86
|
+
- spec/worker_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
- spec/rcov.opts
|
85
89
|
- spec/dataset_spec.rb
|
90
|
+
- spec/sequelizer_spec.rb
|
86
91
|
- spec/migration_spec.rb
|
87
92
|
- spec/pretty_table_spec.rb
|
88
|
-
- spec/rcov.opts
|
89
|
-
- spec/schema_generator_spec.rb
|
90
93
|
- spec/schema_spec.rb
|
91
|
-
- spec/sequelizer_spec.rb
|
92
94
|
- spec/spec.opts
|
93
|
-
-
|
94
|
-
- spec/worker_spec.rb
|
95
|
+
- lib/sequel_core.rb
|
95
96
|
- lib/sequel_core
|
97
|
+
- lib/sequel_core/schema
|
98
|
+
- lib/sequel_core/schema/schema_sql.rb
|
99
|
+
- lib/sequel_core/schema/schema_generator.rb
|
96
100
|
- lib/sequel_core/adapters
|
97
|
-
- lib/sequel_core/adapters/adapter_skeleton.rb
|
98
|
-
- lib/sequel_core/adapters/ado.rb
|
99
|
-
- lib/sequel_core/adapters/db2.rb
|
100
101
|
- lib/sequel_core/adapters/dbi.rb
|
101
|
-
- lib/sequel_core/adapters/
|
102
|
+
- lib/sequel_core/adapters/sqlite.rb
|
102
103
|
- lib/sequel_core/adapters/jdbc.rb
|
104
|
+
- lib/sequel_core/adapters/ado.rb
|
105
|
+
- lib/sequel_core/adapters/adapter_skeleton.rb
|
103
106
|
- lib/sequel_core/adapters/mysql.rb
|
104
|
-
- lib/sequel_core/adapters/odbc.rb
|
105
|
-
- lib/sequel_core/adapters/odbc_mssql.rb
|
106
|
-
- lib/sequel_core/adapters/openbase.rb
|
107
107
|
- lib/sequel_core/adapters/oracle.rb
|
108
108
|
- lib/sequel_core/adapters/postgres.rb
|
109
|
-
- lib/sequel_core/adapters/
|
110
|
-
- lib/sequel_core/
|
111
|
-
- lib/sequel_core/
|
112
|
-
- lib/sequel_core/
|
113
|
-
- lib/sequel_core/
|
109
|
+
- lib/sequel_core/adapters/odbc_mssql.rb
|
110
|
+
- lib/sequel_core/adapters/db2.rb
|
111
|
+
- lib/sequel_core/adapters/odbc.rb
|
112
|
+
- lib/sequel_core/adapters/informix.rb
|
113
|
+
- lib/sequel_core/adapters/openbase.rb
|
114
114
|
- lib/sequel_core/dataset
|
115
|
-
- lib/sequel_core/dataset/convenience.rb
|
116
|
-
- lib/sequel_core/dataset/sequelizer.rb
|
117
115
|
- lib/sequel_core/dataset/sql.rb
|
118
|
-
- lib/sequel_core/dataset.rb
|
119
|
-
- lib/sequel_core/
|
120
|
-
- lib/sequel_core/migration.rb
|
121
|
-
- lib/sequel_core/model.rb
|
116
|
+
- lib/sequel_core/dataset/sequelizer.rb
|
117
|
+
- lib/sequel_core/dataset/convenience.rb
|
122
118
|
- lib/sequel_core/pretty_table.rb
|
123
|
-
- lib/sequel_core/schema
|
124
|
-
- lib/sequel_core/schema/schema_generator.rb
|
125
|
-
- lib/sequel_core/schema/schema_sql.rb
|
126
119
|
- lib/sequel_core/schema.rb
|
120
|
+
- lib/sequel_core/model.rb
|
121
|
+
- lib/sequel_core/exceptions.rb
|
122
|
+
- lib/sequel_core/database.rb
|
123
|
+
- lib/sequel_core/dataset.rb
|
124
|
+
- lib/sequel_core/core_sql.rb
|
125
|
+
- lib/sequel_core/core_ext.rb
|
126
|
+
- lib/sequel_core/migration.rb
|
127
127
|
- lib/sequel_core/worker.rb
|
128
|
-
- lib/sequel_core.rb
|
128
|
+
- lib/sequel_core/array_keys.rb
|
129
129
|
- CHANGELOG
|
130
130
|
has_rdoc: true
|
131
131
|
homepage: http://sequel.rubyforge.org
|