sequel_core 1.0 → 1.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/Rakefile +1 -1
- data/lib/sequel_core/adapters/mysql.rb +1 -1
- data/lib/sequel_core/dataset/sql.rb +23 -8
- data/spec/adapters/informix_spec.rb +1 -1
- data/spec/adapters/mysql_spec.rb +13 -1
- data/spec/adapters/oracle_spec.rb +1 -1
- data/spec/adapters/postgres_spec.rb +1 -1
- data/spec/adapters/sqlite_spec.rb +1 -1
- data/spec/dataset_spec.rb +13 -1
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
=== 1.0.0.1 (2008-01-03)
|
2
|
+
|
3
|
+
* Changed MySQL adapter to support specifying socket option.
|
4
|
+
|
5
|
+
* Added support for limiting and paginating datasets with fixed SQL, gotten with DB#fetch (thanks Ruy Diaz).
|
6
|
+
|
7
|
+
* Added new Dataset#from_self method that returns a dataset selecting from the original dataset.
|
8
|
+
|
1
9
|
=== 1.0 (2008-01-02)
|
2
10
|
|
3
11
|
* Removed deprecated adapter stubs.
|
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.0.1"
|
13
13
|
CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "doc/*", "coverage/*"]
|
14
14
|
RDOC_OPTS = [
|
15
15
|
"--quiet",
|
@@ -87,7 +87,7 @@ module Sequel
|
|
87
87
|
|
88
88
|
def connect
|
89
89
|
conn = Mysql.real_connect(@opts[:host], @opts[:user], @opts[:password],
|
90
|
-
@opts[:database], @opts[:port],
|
90
|
+
@opts[:database], @opts[:port], @opts[:socket], Mysql::CLIENT_MULTI_RESULTS)
|
91
91
|
conn.query_with_result = false
|
92
92
|
if encoding = @opts[:encoding] || @opts[:charset]
|
93
93
|
conn.query("set character_set_connection = '#{encoding}'")
|
@@ -142,6 +142,15 @@ module Sequel
|
|
142
142
|
def from(*source)
|
143
143
|
clone_merge(:from => source)
|
144
144
|
end
|
145
|
+
|
146
|
+
# Returns a dataset selecting from the current dataset.
|
147
|
+
#
|
148
|
+
# ds = DB[:items].order(:name)
|
149
|
+
# ds.sql #=> "SELECT * FROM items ORDER BY name"
|
150
|
+
# ds.from_self #=> "SELECT * FROM (SELECT * FROM items ORDER BY name)"
|
151
|
+
def from_self
|
152
|
+
clone_merge(:sql => nil, :from => [self])
|
153
|
+
end
|
145
154
|
|
146
155
|
# Returns a copy of the dataset with the selected columns changed.
|
147
156
|
def select(*columns)
|
@@ -561,25 +570,31 @@ module Sequel
|
|
561
570
|
# If given a range, it will contain only those at offsets within that
|
562
571
|
# range. If a second argument is given, it is used as an offset.
|
563
572
|
def limit(l, o = nil)
|
573
|
+
if @opts[:sql]
|
574
|
+
return from_self.limit(l, o)
|
575
|
+
end
|
576
|
+
|
577
|
+
opts = {}
|
564
578
|
if l.is_a? Range
|
565
579
|
lim = (l.exclude_end? ? l.last - l.first : l.last + 1 - l.first)
|
566
|
-
|
580
|
+
opts = {:limit => lim, :offset=>l.first}
|
567
581
|
elsif o
|
568
|
-
|
582
|
+
opts = {:limit => l, :offset => o}
|
569
583
|
else
|
570
|
-
|
584
|
+
opts = {:limit => l}
|
571
585
|
end
|
586
|
+
clone_merge(opts)
|
572
587
|
end
|
573
588
|
|
574
589
|
STOCK_COUNT_OPTS = {:select => ["COUNT(*)".lit], :order => nil}.freeze
|
575
590
|
|
576
591
|
# Returns the number of records in the dataset.
|
577
592
|
def count
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
593
|
+
if @opts[:sql]
|
594
|
+
from_self.count
|
595
|
+
else
|
596
|
+
single_value(STOCK_COUNT_OPTS).to_i
|
597
|
+
end
|
583
598
|
end
|
584
599
|
end
|
585
600
|
end
|
data/spec/adapters/mysql_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../../lib/
|
1
|
+
require File.join(File.dirname(__FILE__), '../../lib/sequel_core')
|
2
2
|
require 'logger'
|
3
3
|
|
4
4
|
MYSQL_DB = Sequel('mysql://root@localhost/sandbox')
|
@@ -328,3 +328,15 @@ context "A MySQL database" do
|
|
328
328
|
]
|
329
329
|
end
|
330
330
|
end
|
331
|
+
|
332
|
+
context "A MySQL database" do
|
333
|
+
specify "should accept a socket option" do
|
334
|
+
db = Sequel.mysql('sandbox', :host => 'localhost', :user => 'root', :socket => '/tmp/mysql.sock')
|
335
|
+
proc {db.test_connection}.should_not raise_error
|
336
|
+
end
|
337
|
+
|
338
|
+
specify "should fail to connect with invalid socket" do
|
339
|
+
db = Sequel.mysql('sandbox', :host => 'localhost', :user => 'root', :socket => 'blah')
|
340
|
+
proc {db.test_connection}.should raise_error
|
341
|
+
end
|
342
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../../lib/
|
1
|
+
require File.join(File.dirname(__FILE__), '../../lib/sequel_core')
|
2
2
|
|
3
3
|
PGSQL_DB = Sequel('postgres://postgres:postgres@localhost:5432/reality_spec')
|
4
4
|
PGSQL_DB.drop_table(:test) if PGSQL_DB.table_exists?(:test)
|
data/spec/dataset_spec.rb
CHANGED
@@ -789,6 +789,12 @@ context "Dataset#limit" do
|
|
789
789
|
@dataset.limit(6, 10).sql.should ==
|
790
790
|
'SELECT * FROM test LIMIT 6 OFFSET 10'
|
791
791
|
end
|
792
|
+
|
793
|
+
specify "should work with fixed sql datasets" do
|
794
|
+
@dataset.opts[:sql] = 'select * from cccc'
|
795
|
+
@dataset.limit(6, 10).sql.should ==
|
796
|
+
'SELECT * FROM (select * from cccc) t1 LIMIT 6 OFFSET 10'
|
797
|
+
end
|
792
798
|
end
|
793
799
|
|
794
800
|
context "Dataset#naked" do
|
@@ -916,7 +922,7 @@ context "Dataset#count" do
|
|
916
922
|
specify "should count properly for datasets with fixed sql" do
|
917
923
|
@dataset.opts[:sql] = "select abc from xyz"
|
918
924
|
@dataset.count.should == 1
|
919
|
-
@c.sql.should == "SELECT COUNT(*) FROM (select abc from xyz)
|
925
|
+
@c.sql.should == "SELECT COUNT(*) FROM (select abc from xyz) t1"
|
920
926
|
end
|
921
927
|
end
|
922
928
|
|
@@ -1806,6 +1812,12 @@ context "A paginated dataset" do
|
|
1806
1812
|
@d.paginate(4, 50).current_page_record_count.should == 3
|
1807
1813
|
@d.paginate(5, 50).current_page_record_count.should == 0
|
1808
1814
|
end
|
1815
|
+
|
1816
|
+
specify "should work with fixed sql" do
|
1817
|
+
ds = @d.clone_merge(:sql => 'select * from blah')
|
1818
|
+
ds.meta_def(:count) {150}
|
1819
|
+
ds.paginate(2, 50).sql.should == 'SELECT * FROM (select * from blah) t1 LIMIT 50 OFFSET 50'
|
1820
|
+
end
|
1809
1821
|
end
|
1810
1822
|
|
1811
1823
|
context "Dataset#columns" 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:
|
4
|
+
version: 1.0.0.1
|
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-01-
|
12
|
+
date: 2008-01-04 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|