sequel_core 1.4.0 → 1.5.0
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 +74 -0
- data/COPYING +1 -0
- data/README +17 -6
- data/Rakefile +16 -21
- data/lib/sequel_core.rb +18 -28
- data/lib/sequel_core/adapters/ado.rb +3 -15
- data/lib/sequel_core/adapters/dbi.rb +1 -14
- data/lib/sequel_core/adapters/informix.rb +3 -3
- data/lib/sequel_core/adapters/jdbc.rb +2 -2
- data/lib/sequel_core/adapters/mysql.rb +39 -59
- data/lib/sequel_core/adapters/odbc.rb +18 -38
- data/lib/sequel_core/adapters/openbase.rb +1 -17
- data/lib/sequel_core/adapters/oracle.rb +1 -19
- data/lib/sequel_core/adapters/postgres.rb +20 -60
- data/lib/sequel_core/adapters/sqlite.rb +4 -8
- data/lib/sequel_core/connection_pool.rb +150 -0
- data/lib/sequel_core/core_ext.rb +41 -0
- data/lib/sequel_core/core_sql.rb +35 -38
- data/lib/sequel_core/database.rb +20 -17
- data/lib/sequel_core/dataset.rb +49 -80
- data/lib/sequel_core/dataset/callback.rb +11 -13
- data/lib/sequel_core/dataset/convenience.rb +18 -136
- data/lib/sequel_core/dataset/pagination.rb +81 -0
- data/lib/sequel_core/dataset/sequelizer.rb +5 -4
- data/lib/sequel_core/dataset/sql.rb +43 -33
- data/lib/sequel_core/deprecated.rb +200 -0
- data/lib/sequel_core/exceptions.rb +0 -14
- data/lib/sequel_core/object_graph.rb +199 -0
- data/lib/sequel_core/pretty_table.rb +27 -24
- data/lib/sequel_core/schema/generator.rb +16 -4
- data/lib/sequel_core/schema/sql.rb +5 -3
- data/lib/sequel_core/worker.rb +1 -1
- data/spec/adapters/informix_spec.rb +1 -47
- data/spec/adapters/mysql_spec.rb +85 -54
- data/spec/adapters/oracle_spec.rb +1 -57
- data/spec/adapters/postgres_spec.rb +66 -49
- data/spec/adapters/sqlite_spec.rb +4 -29
- data/spec/connection_pool_spec.rb +358 -0
- data/spec/core_sql_spec.rb +24 -19
- data/spec/database_spec.rb +13 -9
- data/spec/dataset_spec.rb +59 -78
- data/spec/object_graph_spec.rb +202 -0
- data/spec/pretty_table_spec.rb +1 -9
- data/spec/schema_generator_spec.rb +7 -1
- data/spec/schema_spec.rb +27 -0
- data/spec/sequelizer_spec.rb +2 -2
- data/spec/spec_helper.rb +4 -2
- metadata +16 -57
- data/lib/sequel_core/array_keys.rb +0 -322
- data/lib/sequel_core/model.rb +0 -8
- data/spec/array_keys_spec.rb +0 -682
data/spec/pretty_table_spec.rb
CHANGED
@@ -35,14 +35,6 @@ context "PrettyTable" do
|
|
35
35
|
/\n(\|x\|y\|)|(\|y\|x\|)\n/
|
36
36
|
end
|
37
37
|
|
38
|
-
specify "should infer columns from array with keys" do
|
39
|
-
a = [1, 2, 3]
|
40
|
-
a.keys = [:a, :b, :c]
|
41
|
-
Sequel::PrettyTable.print([a])
|
42
|
-
@output.rewind
|
43
|
-
@output.read.should =~ /\n\|a\|b\|c\|\n/
|
44
|
-
end
|
45
|
-
|
46
38
|
specify "should calculate the maximum width of each column correctly" do
|
47
39
|
Sequel::PrettyTable.print(@data2, [:a, :b])
|
48
40
|
@output.rewind
|
@@ -63,4 +55,4 @@ context "PrettyTable" do
|
|
63
55
|
@output.read.should == \
|
64
56
|
"+--+\n|a |\n+--+\n|23|\n|45|\n+--+\n"
|
65
57
|
end
|
66
|
-
end
|
58
|
+
end
|
@@ -82,6 +82,9 @@ describe Sequel::Schema::AlterTableGenerator do
|
|
82
82
|
add_index [:fff, :ggg]
|
83
83
|
drop_index :hhh
|
84
84
|
add_full_text_index :blah
|
85
|
+
add_spatial_index :geom
|
86
|
+
add_index :blah, :type => :hash
|
87
|
+
add_index :blah, :where => {:something => true}
|
85
88
|
add_constraint :con1, ':fred > 100'
|
86
89
|
drop_constraint :con2
|
87
90
|
end
|
@@ -96,7 +99,10 @@ describe Sequel::Schema::AlterTableGenerator do
|
|
96
99
|
{:op => :set_column_default, :name => :eee, :default => 1},
|
97
100
|
{:op => :add_index, :columns => [:fff, :ggg]},
|
98
101
|
{:op => :drop_index, :columns => [:hhh]},
|
99
|
-
{:op => :add_index, :columns => [:blah], :
|
102
|
+
{:op => :add_index, :columns => [:blah], :type => :full_text},
|
103
|
+
{:op => :add_index, :columns => [:geom], :type => :spatial},
|
104
|
+
{:op => :add_index, :columns => [:blah], :type => :hash},
|
105
|
+
{:op => :add_index, :columns => [:blah], :where => {:something => true}},
|
100
106
|
{:op => :add_constraint, :type => :check, :name => :con1, :check => [':fred > 100']},
|
101
107
|
{:op => :drop_constraint, :name => :con2}
|
102
108
|
]
|
data/spec/schema_spec.rb
CHANGED
@@ -204,6 +204,33 @@ context "DB#create_table" do
|
|
204
204
|
}.should raise_error(Sequel::Error)
|
205
205
|
end
|
206
206
|
|
207
|
+
specify "should raise on spatial index definitions" do
|
208
|
+
proc {
|
209
|
+
@db.create_table(:cats) do
|
210
|
+
point :geom
|
211
|
+
spatial_index :geom
|
212
|
+
end
|
213
|
+
}.should raise_error(Sequel::Error)
|
214
|
+
end
|
215
|
+
|
216
|
+
specify "should raise on partial index definitions" do
|
217
|
+
proc {
|
218
|
+
@db.create_table(:cats) do
|
219
|
+
text :name
|
220
|
+
index :name, :where => {:something => true}
|
221
|
+
end
|
222
|
+
}.should raise_error(Sequel::Error)
|
223
|
+
end
|
224
|
+
|
225
|
+
specify "should raise index definitions with type" do
|
226
|
+
proc {
|
227
|
+
@db.create_table(:cats) do
|
228
|
+
text :name
|
229
|
+
index :name, :type => :hash
|
230
|
+
end
|
231
|
+
}.should raise_error(Sequel::Error)
|
232
|
+
end
|
233
|
+
|
207
234
|
specify "should accept multiple index definitions" do
|
208
235
|
@db.create_table(:cats) do
|
209
236
|
integer :id
|
data/spec/sequelizer_spec.rb
CHANGED
@@ -247,8 +247,8 @@ context "Proc#to_sql" do
|
|
247
247
|
end
|
248
248
|
|
249
249
|
specify "should support functions on columns" do
|
250
|
-
proc {:x
|
251
|
-
proc {:x
|
250
|
+
proc {:max[:x] > 100}.sql.should == "(max(x) > 100)"
|
251
|
+
proc {:count[:x] > 100}.sql.should == "(count(x) > 100)"
|
252
252
|
end
|
253
253
|
|
254
254
|
specify "should support SQL functions" do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
|
3
|
-
|
2
|
+
unless Object.const_defined?('Sequel')
|
3
|
+
$:.unshift(File.join(File.dirname(__FILE__), "../lib/"))
|
4
|
+
require 'sequel_core'
|
5
|
+
end
|
4
6
|
if File.exists?(File.join(File.dirname(__FILE__), 'spec_config.rb'))
|
5
7
|
require File.join(File.dirname(__FILE__), 'spec_config.rb')
|
6
8
|
end
|
metadata
CHANGED
@@ -3,12 +3,12 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: sequel_core
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2008-04-
|
6
|
+
version: 1.5.0
|
7
|
+
date: 2008-04-29 00:00:00 -07:00
|
8
8
|
summary: "The Database Toolkit for Ruby: Core Library and Adapters"
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
|
-
email:
|
11
|
+
email: code@jeremyevans.net
|
12
12
|
homepage: http://sequel.rubyforge.org
|
13
13
|
rubyforge_project: sequel
|
14
14
|
description: "The Database Toolkit for Ruby: Core Library and Adapters"
|
@@ -27,28 +27,29 @@ signing_key:
|
|
27
27
|
cert_chain:
|
28
28
|
post_install_message:
|
29
29
|
authors:
|
30
|
-
-
|
30
|
+
- Jeremy Evans
|
31
31
|
files:
|
32
32
|
- COPYING
|
33
33
|
- README
|
34
34
|
- Rakefile
|
35
35
|
- bin/sequel
|
36
36
|
- spec/adapters
|
37
|
-
- spec/
|
37
|
+
- spec/dataset_spec.rb
|
38
38
|
- spec/core_ext_spec.rb
|
39
39
|
- spec/core_sql_spec.rb
|
40
40
|
- spec/database_spec.rb
|
41
|
-
- spec/
|
41
|
+
- spec/schema_spec.rb
|
42
42
|
- spec/migration_spec.rb
|
43
43
|
- spec/pretty_table_spec.rb
|
44
44
|
- spec/rcov.opts
|
45
45
|
- spec/schema_generator_spec.rb
|
46
|
-
- spec/
|
46
|
+
- spec/spec_helper.rb
|
47
47
|
- spec/sequelizer_spec.rb
|
48
48
|
- spec/spec.opts
|
49
49
|
- spec/spec_config.rb.example
|
50
|
-
- spec/spec_helper.rb
|
51
50
|
- spec/worker_spec.rb
|
51
|
+
- spec/connection_pool_spec.rb
|
52
|
+
- spec/object_graph_spec.rb
|
52
53
|
- spec/adapters/informix_spec.rb
|
53
54
|
- spec/adapters/mysql_spec.rb
|
54
55
|
- spec/adapters/oracle_spec.rb
|
@@ -57,19 +58,20 @@ files:
|
|
57
58
|
- lib/sequel_core.rb
|
58
59
|
- lib/sequel_core
|
59
60
|
- lib/sequel_core/adapters
|
60
|
-
- lib/sequel_core/
|
61
|
+
- lib/sequel_core/dataset.rb
|
61
62
|
- lib/sequel_core/core_ext.rb
|
62
63
|
- lib/sequel_core/core_sql.rb
|
63
64
|
- lib/sequel_core/database.rb
|
64
|
-
- lib/sequel_core/dataset.rb
|
65
|
-
- lib/sequel_core/dataset
|
66
65
|
- lib/sequel_core/exceptions.rb
|
66
|
+
- lib/sequel_core/dataset
|
67
|
+
- lib/sequel_core/object_graph.rb
|
67
68
|
- lib/sequel_core/migration.rb
|
68
|
-
- lib/sequel_core/
|
69
|
+
- lib/sequel_core/worker.rb
|
69
70
|
- lib/sequel_core/pretty_table.rb
|
70
71
|
- lib/sequel_core/schema.rb
|
71
72
|
- lib/sequel_core/schema
|
72
|
-
- lib/sequel_core/
|
73
|
+
- lib/sequel_core/connection_pool.rb
|
74
|
+
- lib/sequel_core/deprecated.rb
|
73
75
|
- lib/sequel_core/adapters/adapter_skeleton.rb
|
74
76
|
- lib/sequel_core/adapters/ado.rb
|
75
77
|
- lib/sequel_core/adapters/db2.rb
|
@@ -87,6 +89,7 @@ files:
|
|
87
89
|
- lib/sequel_core/dataset/convenience.rb
|
88
90
|
- lib/sequel_core/dataset/sequelizer.rb
|
89
91
|
- lib/sequel_core/dataset/sql.rb
|
92
|
+
- lib/sequel_core/dataset/pagination.rb
|
90
93
|
- lib/sequel_core/schema/generator.rb
|
91
94
|
- lib/sequel_core/schema/sql.rb
|
92
95
|
- CHANGELOG
|
@@ -94,18 +97,10 @@ test_files: []
|
|
94
97
|
|
95
98
|
rdoc_options:
|
96
99
|
- --quiet
|
97
|
-
- --title
|
98
|
-
- "Sequel: The Database Toolkit for Ruby"
|
99
|
-
- --opname
|
100
|
-
- index.html
|
101
100
|
- --line-numbers
|
102
|
-
- --main
|
103
|
-
- README
|
104
101
|
- --inline-source
|
105
102
|
- --exclude
|
106
103
|
- ^(examples|extras)/
|
107
|
-
- --exclude
|
108
|
-
- lib/sequel_core.rb
|
109
104
|
extra_rdoc_files:
|
110
105
|
- README
|
111
106
|
- CHANGELOG
|
@@ -126,39 +121,3 @@ dependencies:
|
|
126
121
|
- !ruby/object:Gem::Version
|
127
122
|
version: 0.0.0
|
128
123
|
version:
|
129
|
-
- !ruby/object:Gem::Dependency
|
130
|
-
name: assistance
|
131
|
-
version_requirement:
|
132
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
133
|
-
requirements:
|
134
|
-
- - ">="
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
version: "0.1"
|
137
|
-
version:
|
138
|
-
- !ruby/object:Gem::Dependency
|
139
|
-
name: RubyInline
|
140
|
-
version_requirement:
|
141
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: 3.6.6
|
146
|
-
version:
|
147
|
-
- !ruby/object:Gem::Dependency
|
148
|
-
name: ParseTree
|
149
|
-
version_requirement:
|
150
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
151
|
-
requirements:
|
152
|
-
- - ">="
|
153
|
-
- !ruby/object:Gem::Version
|
154
|
-
version: 2.1.1
|
155
|
-
version:
|
156
|
-
- !ruby/object:Gem::Dependency
|
157
|
-
name: ruby2ruby
|
158
|
-
version_requirement:
|
159
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
160
|
-
requirements:
|
161
|
-
- - ">"
|
162
|
-
- !ruby/object:Gem::Version
|
163
|
-
version: 0.0.0
|
164
|
-
version:
|
@@ -1,322 +0,0 @@
|
|
1
|
-
# ArrayKeys provide support for accessing array elements by keys. ArrayKeys are
|
2
|
-
# based on the arrayfields gem by Ara Howard, and can be used as substitutes
|
3
|
-
# for fetching records tuples as Ruby hashes.
|
4
|
-
#
|
5
|
-
# The main advantage offered by ArrayKeys over hashes is that the values are
|
6
|
-
# always ordered according to the column order in the query. Another purported
|
7
|
-
# advantage is that they reduce the memory footprint, but this has turned out
|
8
|
-
# to be a false claim.
|
9
|
-
module ArrayKeys
|
10
|
-
# The KeySet module contains methods that extend an array of keys to return
|
11
|
-
# a key's position in the key set.
|
12
|
-
module KeySet
|
13
|
-
# Returns the key's position in the key set. Provides indifferent access
|
14
|
-
# for symbols and strings.
|
15
|
-
def key_pos(key)
|
16
|
-
@key_indexes ||= inject({}) {|h, k| h[k.to_sym] = h.size; h}
|
17
|
-
@key_indexes[key] || @key_indexes[key.to_sym] || @key_indexes[key.to_s]
|
18
|
-
end
|
19
|
-
|
20
|
-
# Adds a key to the key set.
|
21
|
-
def add_key(key)
|
22
|
-
self << key
|
23
|
-
@key_indexes[key] = @key_indexes.size
|
24
|
-
end
|
25
|
-
|
26
|
-
# Removes a key from the key set by its index.
|
27
|
-
def del_key(idx)
|
28
|
-
delete_at(idx)
|
29
|
-
@key_indexes = nil # reset key indexes
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# The KeyAccess provides a large part of the Hash API for arrays with keys.
|
34
|
-
module KeyAccess
|
35
|
-
# Returns a value referenced by an array index or a key.
|
36
|
-
def [](idx, *args)
|
37
|
-
if String === idx or Symbol === idx
|
38
|
-
(idx = @keys.key_pos(idx)) ? super(idx, *args) : nil
|
39
|
-
else
|
40
|
-
super
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# Sets the value referenced by an array index or a key.
|
45
|
-
def []=(idx,*args)
|
46
|
-
if String === idx or Symbol === idx
|
47
|
-
idx = @keys.key_pos(idx) || @keys.add_key(idx.to_sym)
|
48
|
-
end
|
49
|
-
super(idx, *args)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Stores a value by index or key.
|
53
|
-
def store(k, v); self[k] = v; end
|
54
|
-
|
55
|
-
# Slices the array, and returns an array with its keys sliced accordingly.
|
56
|
-
def slice(*args)
|
57
|
-
s = super(*args)
|
58
|
-
s.keys = @keys.slice(*args)
|
59
|
-
s
|
60
|
-
end
|
61
|
-
|
62
|
-
# Converts the array into a hash.
|
63
|
-
def to_hash
|
64
|
-
h = {}
|
65
|
-
each_with_index {|v, i| h[(k = @keys[i]) ? k.to_sym : nil] = v}
|
66
|
-
h
|
67
|
-
end
|
68
|
-
alias_method :to_h, :to_hash
|
69
|
-
|
70
|
-
# Iterates over each key-value pair in the array.
|
71
|
-
def each_pair
|
72
|
-
each_with_index {|v, i| yield @keys[i], v}
|
73
|
-
end
|
74
|
-
|
75
|
-
# Iterates over the array's associated keys.
|
76
|
-
def each_key(&block)
|
77
|
-
@keys.each(&block)
|
78
|
-
end
|
79
|
-
|
80
|
-
# Iterates over the array's values.
|
81
|
-
def each_value(&block)
|
82
|
-
each(&block)
|
83
|
-
end
|
84
|
-
|
85
|
-
# Deletes a value by its key.
|
86
|
-
def delete(key, *args)
|
87
|
-
if (idx = @keys.key_pos(key))
|
88
|
-
delete_at(idx)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# Deletes a value by its index.
|
93
|
-
def delete_at(idx)
|
94
|
-
super(idx)
|
95
|
-
@keys = @keys.clone
|
96
|
-
@keys.del_key(idx)
|
97
|
-
end
|
98
|
-
|
99
|
-
# Returns true if the array's key set contains the given key.
|
100
|
-
def include?(k)
|
101
|
-
@keys.include?(k) || @keys.include?(k.to_sym) || @keys.include?(k.to_s)
|
102
|
-
end
|
103
|
-
|
104
|
-
# Returns true if the array's key set contains the given key.
|
105
|
-
def has_key?(k)
|
106
|
-
@keys.include?(k) || @keys.include?(k.to_sym) || @keys.include?(k.to_s)
|
107
|
-
end
|
108
|
-
alias_method :member?, :has_key?
|
109
|
-
alias_method :key?, :has_key?
|
110
|
-
|
111
|
-
# Returns true if the array contains the given value.
|
112
|
-
def has_value?(k); orig_include?(k); end
|
113
|
-
alias_method :value?, :has_value?
|
114
|
-
|
115
|
-
# Fetches a value by its key and optionally passes it through the given
|
116
|
-
# block:
|
117
|
-
#
|
118
|
-
# row.fetch(:name) {|v| v.to_sym}
|
119
|
-
#
|
120
|
-
# You can also give a default value
|
121
|
-
#
|
122
|
-
# row.fetch(:name, 'untitled')
|
123
|
-
#
|
124
|
-
def fetch(k, *args, &block)
|
125
|
-
if idx = @keys.key_pos(k)
|
126
|
-
v = at idx
|
127
|
-
else
|
128
|
-
!args.empty? ? (v = args.first) : (raise IndexError, "key not found")
|
129
|
-
end
|
130
|
-
block ? block[v] : v
|
131
|
-
end
|
132
|
-
|
133
|
-
# Returns self.
|
134
|
-
def values
|
135
|
-
self
|
136
|
-
end
|
137
|
-
|
138
|
-
# Creates a copy of self with the same key set.
|
139
|
-
def dup
|
140
|
-
copy = super
|
141
|
-
copy.keys = @keys
|
142
|
-
copy
|
143
|
-
end
|
144
|
-
|
145
|
-
# Creates a copy of self with a copy of the key set.
|
146
|
-
def clone
|
147
|
-
copy = super
|
148
|
-
copy.keys = @keys.clone
|
149
|
-
copy
|
150
|
-
end
|
151
|
-
|
152
|
-
# Returns an array merged from self and the given array.
|
153
|
-
def merge(values, &block)
|
154
|
-
clone.merge!(values, &block)
|
155
|
-
end
|
156
|
-
|
157
|
-
# Merges the given array with self, optionally passing the values from self
|
158
|
-
# through the given block:
|
159
|
-
#
|
160
|
-
# row.merge!(new_values) {|k, old, new| (k == :name) ? old : new}
|
161
|
-
#
|
162
|
-
def merge!(values, &block)
|
163
|
-
values.each_pair do |k, v|
|
164
|
-
self[k] = (has_key?(k) && block) ? block[k, self[k], v] : v
|
165
|
-
end
|
166
|
-
self
|
167
|
-
end
|
168
|
-
alias_method :update, :merge!
|
169
|
-
alias_method :update!, :merge!
|
170
|
-
end
|
171
|
-
|
172
|
-
# The ArrayExtensions module provides extensions for the Array class.
|
173
|
-
module ArrayExtensions
|
174
|
-
attr_reader :keys
|
175
|
-
|
176
|
-
# Sets the key set for the array. Once a key set has been set for an array,
|
177
|
-
# it is extended with the KeyAccess API
|
178
|
-
def keys=(keys)
|
179
|
-
extend ArrayKeys::KeyAccess if keys
|
180
|
-
@keys = keys.frozen? ? keys.dup : keys
|
181
|
-
unless @keys.respond_to?(:key_pos)
|
182
|
-
@keys.extend(ArrayKeys::KeySet)
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
alias_method :columns, :keys
|
187
|
-
alias_method :columns=, :keys=
|
188
|
-
end
|
189
|
-
|
190
|
-
# The DatasetExtensions module provides extensions that modify
|
191
|
-
# a dataset to return Array tuples instead of Hash tuples.
|
192
|
-
module DatasetExtensions
|
193
|
-
# Fetches a dataset's records, converting each tuple into an array with keys.
|
194
|
-
def array_tuples_each(opts = nil, &block)
|
195
|
-
fetch_rows(select_sql(opts)) {|h| block[Array.from_hash(h)]}
|
196
|
-
end
|
197
|
-
|
198
|
-
# Provides the corresponding behavior to Sequel::Dataset#update_each_method,
|
199
|
-
# using array tuples.
|
200
|
-
def array_tuples_update_each_method
|
201
|
-
# warning: ugly code generation ahead
|
202
|
-
if @row_proc && @transform
|
203
|
-
class << self
|
204
|
-
def each(opts = nil, &block)
|
205
|
-
if opts && opts[:naked]
|
206
|
-
fetch_rows(select_sql(opts)) {|r| block[transform_load(Array.from_hash(r))]}
|
207
|
-
else
|
208
|
-
fetch_rows(select_sql(opts)) {|r| block[@row_proc[transform_load(Array.from_hash(r))]]}
|
209
|
-
end
|
210
|
-
self
|
211
|
-
end
|
212
|
-
end
|
213
|
-
elsif @row_proc
|
214
|
-
class << self
|
215
|
-
def each(opts = nil, &block)
|
216
|
-
if opts && opts[:naked]
|
217
|
-
fetch_rows(select_sql(opts)) {|r| block[Array.from_hash(r)]}
|
218
|
-
else
|
219
|
-
fetch_rows(select_sql(opts)) {|r| block[@row_proc[Array.from_hash(r)]]}
|
220
|
-
end
|
221
|
-
self
|
222
|
-
end
|
223
|
-
end
|
224
|
-
elsif @transform
|
225
|
-
class << self
|
226
|
-
def each(opts = nil, &block)
|
227
|
-
fetch_rows(select_sql(opts)) {|r| block[transform_load(Array.from_hash(r))]}
|
228
|
-
self
|
229
|
-
end
|
230
|
-
end
|
231
|
-
else
|
232
|
-
class << self
|
233
|
-
def each(opts = nil, &block)
|
234
|
-
fetch_rows(select_sql(opts)) {|r| block[Array.from_hash(r)]}
|
235
|
-
self
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
def array_tuples_transform_load(r)
|
242
|
-
puts "transform_load"
|
243
|
-
|
244
|
-
a = []; a.keys = []
|
245
|
-
r.each_pair do |k, v|
|
246
|
-
a[k] = (tt = @transform[k]) ? tt[0][v] : v
|
247
|
-
end
|
248
|
-
a
|
249
|
-
end
|
250
|
-
|
251
|
-
# Applies the value transform for data saved to the database.
|
252
|
-
def array_tuples_transform_save(r)
|
253
|
-
a = []; a.keys = []
|
254
|
-
r.each_pair do |k, v|
|
255
|
-
a[k] = (tt = @transform[k]) ? tt[1][v] : v
|
256
|
-
end
|
257
|
-
a
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
# Array extensions.
|
263
|
-
class Array
|
264
|
-
alias_method :orig_include?, :include?
|
265
|
-
|
266
|
-
include ArrayKeys::ArrayExtensions
|
267
|
-
|
268
|
-
# Converts a hash into an array with keys.
|
269
|
-
def self.from_hash(h)
|
270
|
-
a = []; a.keys = []
|
271
|
-
a.merge!(h)
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
module Sequel
|
276
|
-
# Modifies all dataset classes to fetch records as arrays with keys. By
|
277
|
-
# default records are fetched as hashes.
|
278
|
-
def self.use_array_tuples
|
279
|
-
Dataset.dataset_classes.each do |c|
|
280
|
-
c.class_eval do
|
281
|
-
if method_defined?(:array_tuples_fetch_rows)
|
282
|
-
alias_method :hash_tuples_fetch_rows, :fetch_rows
|
283
|
-
alias_method :fetch_rows, :array_tuples_fetch_rows
|
284
|
-
else
|
285
|
-
alias_method :orig_each, :each
|
286
|
-
alias_method :orig_update_each_method, :update_each_method
|
287
|
-
|
288
|
-
include ArrayKeys::DatasetExtensions
|
289
|
-
alias_method :each, :array_tuples_each
|
290
|
-
alias_method :update_each_method, :array_tuples_update_each_method
|
291
|
-
end
|
292
|
-
|
293
|
-
if method_defined?(:array_tuples_transform_load)
|
294
|
-
alias_method :transform_load, :array_tuples_transform_load
|
295
|
-
end
|
296
|
-
if method_defined?(:array_tuples_transform_save)
|
297
|
-
alias_method :transform_save, :array_tuples_transform_save
|
298
|
-
end
|
299
|
-
end
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
# Modifies all dataset classes to fetch records as hashes.
|
304
|
-
def self.use_hash_tuples
|
305
|
-
Dataset.dataset_classes.each do |c|
|
306
|
-
c.class_eval do
|
307
|
-
if method_defined?(:hash_tuples_fetch_rows)
|
308
|
-
alias_method :fetch_rows, :hash_tuples_fetch_rows
|
309
|
-
else
|
310
|
-
if method_defined?(:orig_each)
|
311
|
-
alias_method :each, :orig_each
|
312
|
-
undef_method :orig_each
|
313
|
-
end
|
314
|
-
if method_defined?(:orig_update_each_method)
|
315
|
-
alias_method :update_each_method, :orig_update_each_method
|
316
|
-
undef_method :orig_update_each_method
|
317
|
-
end
|
318
|
-
end
|
319
|
-
end
|
320
|
-
end
|
321
|
-
end
|
322
|
-
end
|