sequel 0.4.1 → 0.4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/README +2 -1
- data/Rakefile +1 -1
- data/lib/sequel/adapters/informix.rb +12 -0
- data/lib/sequel/model/base.rb +1 -1
- data/spec/adapters/informix_spec.rb +139 -0
- data/spec/adapters/mysql_spec.rb +1 -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
- metadata +3 -3
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
=== 0.4.1.1 (2007-11-27)
|
2
|
+
|
3
|
+
* Fixed #first and #last functionality in Informix::Dataset (thanks Gerardo Santana).
|
4
|
+
|
1
5
|
=== 0.4.1 (2007-11-25)
|
2
6
|
|
3
7
|
* Put adapter files in lib/sequel/adapters. Requiring sequel/<adapter> is now deprecated. Users can now just require 'sequel' and adapters are automagically loaded (#93).
|
data/README
CHANGED
@@ -30,13 +30,14 @@ Sequel currently supports:
|
|
30
30
|
|
31
31
|
* ADO (on Windows)
|
32
32
|
* DBI
|
33
|
+
* Informix
|
33
34
|
* MySQL
|
34
35
|
* ODBC
|
35
36
|
* Oracle
|
36
37
|
* PostgreSQL
|
37
38
|
* SQLite 3
|
38
39
|
|
39
|
-
There
|
40
|
+
There is also an experimental adapter for DB2.
|
40
41
|
|
41
42
|
== The Sequel Console
|
42
43
|
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require 'fileutils'
|
|
6
6
|
include FileUtils
|
7
7
|
|
8
8
|
NAME = "sequel"
|
9
|
-
VERS = "0.4.1"
|
9
|
+
VERS = "0.4.1.1"
|
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",
|
@@ -49,6 +49,18 @@ module Sequel
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
def select_sql(opts = nil)
|
53
|
+
limit = opts.delete(:limit)
|
54
|
+
offset = opts.delete(:offset)
|
55
|
+
sql = super
|
56
|
+
if limit
|
57
|
+
limit = "FIRST #{limit}"
|
58
|
+
offset = offset ? "SKIP #{offset}" : ""
|
59
|
+
sql.sub!(/^select /i,"SELECT #{offset} #{limit} ")
|
60
|
+
end
|
61
|
+
sql
|
62
|
+
end
|
63
|
+
|
52
64
|
def fetch_rows(sql, &block)
|
53
65
|
@db.synchronize do
|
54
66
|
@db.query(sql) do |cursor|
|
data/lib/sequel/model/base.rb
CHANGED
@@ -14,7 +14,7 @@ module Sequel
|
|
14
14
|
# Called when a database is opened in order to automatically associate the
|
15
15
|
# first opened database with model classes.
|
16
16
|
def self.database_opened(db)
|
17
|
-
@db = db if self == Model && !@db
|
17
|
+
@db = db if (self == Model) && !@db
|
18
18
|
end
|
19
19
|
|
20
20
|
# Returns the dataset associated with the Model class.
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../../lib/sequel')
|
2
|
+
|
3
|
+
INFORMIX_DB = Sequel('informix://localhost/mydb')
|
4
|
+
if INFORMIX_DB.table_exists?(:test)
|
5
|
+
INFORMIX_DB.drop_table :test
|
6
|
+
end
|
7
|
+
INFORMIX_DB.create_table :test do
|
8
|
+
text :name
|
9
|
+
integer :value
|
10
|
+
|
11
|
+
index :value
|
12
|
+
end
|
13
|
+
|
14
|
+
context "A Informix database" do
|
15
|
+
specify "should provide disconnect functionality" do
|
16
|
+
INFORMIX_DB.execute("select user from dual")
|
17
|
+
INFORMIX_DB.pool.size.should == 1
|
18
|
+
INFORMIX_DB.disconnect
|
19
|
+
INFORMIX_DB.pool.size.should == 0
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "A Informix dataset" do
|
24
|
+
setup do
|
25
|
+
@d = INFORMIX_DB[:test]
|
26
|
+
@d.delete # remove all records
|
27
|
+
end
|
28
|
+
|
29
|
+
specify "should return the correct record count" do
|
30
|
+
@d.count.should == 0
|
31
|
+
@d << {:name => 'abc', :value => 123}
|
32
|
+
@d << {:name => 'abc', :value => 456}
|
33
|
+
@d << {:name => 'def', :value => 789}
|
34
|
+
@d.count.should == 3
|
35
|
+
end
|
36
|
+
|
37
|
+
specify "should return the correct records" do
|
38
|
+
@d.to_a.should == []
|
39
|
+
@d << {:name => 'abc', :value => 123}
|
40
|
+
@d << {:name => 'abc', :value => 456}
|
41
|
+
@d << {:name => 'def', :value => 789}
|
42
|
+
|
43
|
+
@d.order(:value).to_a.should == [
|
44
|
+
{:name => 'abc', :value => 123},
|
45
|
+
{:name => 'abc', :value => 456},
|
46
|
+
{:name => 'def', :value => 789}
|
47
|
+
]
|
48
|
+
end
|
49
|
+
|
50
|
+
specify "should update records correctly" do
|
51
|
+
@d << {:name => 'abc', :value => 123}
|
52
|
+
@d << {:name => 'abc', :value => 456}
|
53
|
+
@d << {:name => 'def', :value => 789}
|
54
|
+
@d.filter(:name => 'abc').update(:value => 530)
|
55
|
+
|
56
|
+
# the third record should stay the same
|
57
|
+
# floating-point precision bullshit
|
58
|
+
@d[:name => 'def'][:value].should == 789
|
59
|
+
@d.filter(:value => 530).count.should == 2
|
60
|
+
end
|
61
|
+
|
62
|
+
specify "should delete records correctly" do
|
63
|
+
@d << {:name => 'abc', :value => 123}
|
64
|
+
@d << {:name => 'abc', :value => 456}
|
65
|
+
@d << {:name => 'def', :value => 789}
|
66
|
+
@d.filter(:name => 'abc').delete
|
67
|
+
|
68
|
+
@d.count.should == 1
|
69
|
+
@d.first[:name].should == 'def'
|
70
|
+
end
|
71
|
+
|
72
|
+
specify "should be able to literalize booleans" do
|
73
|
+
proc {@d.literal(true)}.should_not raise_error
|
74
|
+
proc {@d.literal(false)}.should_not raise_error
|
75
|
+
end
|
76
|
+
|
77
|
+
specify "should support transactions" do
|
78
|
+
INFORMIX_DB.transaction do
|
79
|
+
@d << {:name => 'abc', :value => 1}
|
80
|
+
end
|
81
|
+
|
82
|
+
@d.count.should == 1
|
83
|
+
end
|
84
|
+
|
85
|
+
specify "should support #first and #last" do
|
86
|
+
@d << {:name => 'abc', :value => 123}
|
87
|
+
@d << {:name => 'abc', :value => 456}
|
88
|
+
@d << {:name => 'def', :value => 789}
|
89
|
+
|
90
|
+
@d.order(:value).first.should == {:name => 'abc', :value => 123}
|
91
|
+
@d.order(:value).last.should == {:name => 'def', :value => 789}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "A Informix dataset in array tuples mode" do
|
96
|
+
setup do
|
97
|
+
@d = INFORMIX_DB[:test]
|
98
|
+
@d.delete # remove all records
|
99
|
+
Sequel.use_array_tuples
|
100
|
+
end
|
101
|
+
|
102
|
+
teardown do
|
103
|
+
Sequel.use_hash_tuples
|
104
|
+
end
|
105
|
+
|
106
|
+
specify "should return the correct records" do
|
107
|
+
@d.to_a.should == []
|
108
|
+
@d << {:name => 'abc', :value => 123}
|
109
|
+
@d << {:name => 'abc', :value => 456}
|
110
|
+
@d << {:name => 'def', :value => 789}
|
111
|
+
|
112
|
+
@d.order(:value).select(:name, :value).to_a.should == [
|
113
|
+
['abc', 123],
|
114
|
+
['abc', 456],
|
115
|
+
['def', 789]
|
116
|
+
]
|
117
|
+
end
|
118
|
+
|
119
|
+
specify "should work correctly with transforms" do
|
120
|
+
@d.transform(:value => [proc {|v| v.to_s}, proc {|v| v.to_i}])
|
121
|
+
|
122
|
+
@d.to_a.should == []
|
123
|
+
@d << {:name => 'abc', :value => 123}
|
124
|
+
@d << {:name => 'abc', :value => 456}
|
125
|
+
@d << {:name => 'def', :value => 789}
|
126
|
+
|
127
|
+
@d.order(:value).select(:name, :value).to_a.should == [
|
128
|
+
['abc', '123'],
|
129
|
+
['abc', '456'],
|
130
|
+
['def', '789']
|
131
|
+
]
|
132
|
+
|
133
|
+
a = @d.order(:value).first
|
134
|
+
a.values.should == ['abc', '123']
|
135
|
+
a.keys.should == [:name, :value]
|
136
|
+
a[:name].should == 'abc'
|
137
|
+
a[:value].should == '123'
|
138
|
+
end
|
139
|
+
end
|
data/spec/adapters/mysql_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.1
|
4
|
+
version: 0.4.1.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: 2007-11-
|
12
|
+
date: 2007-11-27 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -54,8 +54,8 @@ files:
|
|
54
54
|
- README
|
55
55
|
- Rakefile
|
56
56
|
- bin/sequel
|
57
|
-
- doc/rdoc
|
58
57
|
- spec/adapters
|
58
|
+
- spec/adapters/informix_spec.rb
|
59
59
|
- spec/adapters/mysql_spec.rb
|
60
60
|
- spec/adapters/oracle_spec.rb
|
61
61
|
- spec/adapters/postgres_spec.rb
|