sequel 3.37.0 → 3.38.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.
Files changed (129) hide show
  1. data/CHANGELOG +56 -0
  2. data/README.rdoc +82 -58
  3. data/Rakefile +6 -5
  4. data/bin/sequel +1 -1
  5. data/doc/active_record.rdoc +67 -52
  6. data/doc/advanced_associations.rdoc +33 -48
  7. data/doc/association_basics.rdoc +41 -51
  8. data/doc/cheat_sheet.rdoc +21 -21
  9. data/doc/core_extensions.rdoc +374 -0
  10. data/doc/dataset_basics.rdoc +5 -5
  11. data/doc/dataset_filtering.rdoc +47 -43
  12. data/doc/mass_assignment.rdoc +1 -1
  13. data/doc/migration.rdoc +4 -5
  14. data/doc/model_hooks.rdoc +3 -3
  15. data/doc/object_model.rdoc +31 -25
  16. data/doc/opening_databases.rdoc +19 -5
  17. data/doc/prepared_statements.rdoc +2 -2
  18. data/doc/querying.rdoc +109 -52
  19. data/doc/reflection.rdoc +6 -6
  20. data/doc/release_notes/3.38.0.txt +234 -0
  21. data/doc/schema_modification.rdoc +22 -13
  22. data/doc/sharding.rdoc +8 -9
  23. data/doc/sql.rdoc +154 -112
  24. data/doc/testing.rdoc +47 -7
  25. data/doc/thread_safety.rdoc +1 -1
  26. data/doc/transactions.rdoc +1 -1
  27. data/doc/validations.rdoc +1 -1
  28. data/doc/virtual_rows.rdoc +29 -43
  29. data/lib/sequel/adapters/do/postgres.rb +1 -4
  30. data/lib/sequel/adapters/jdbc.rb +14 -3
  31. data/lib/sequel/adapters/jdbc/db2.rb +9 -0
  32. data/lib/sequel/adapters/jdbc/derby.rb +41 -4
  33. data/lib/sequel/adapters/jdbc/jtds.rb +11 -0
  34. data/lib/sequel/adapters/jdbc/postgresql.rb +3 -6
  35. data/lib/sequel/adapters/mock.rb +10 -4
  36. data/lib/sequel/adapters/postgres.rb +1 -28
  37. data/lib/sequel/adapters/shared/mssql.rb +23 -13
  38. data/lib/sequel/adapters/shared/postgres.rb +46 -0
  39. data/lib/sequel/adapters/swift.rb +21 -13
  40. data/lib/sequel/adapters/swift/mysql.rb +1 -0
  41. data/lib/sequel/adapters/swift/postgres.rb +4 -5
  42. data/lib/sequel/adapters/swift/sqlite.rb +2 -1
  43. data/lib/sequel/adapters/tinytds.rb +14 -2
  44. data/lib/sequel/adapters/utils/pg_types.rb +5 -0
  45. data/lib/sequel/core.rb +29 -17
  46. data/lib/sequel/database/query.rb +1 -1
  47. data/lib/sequel/database/schema_generator.rb +3 -0
  48. data/lib/sequel/dataset/actions.rb +5 -6
  49. data/lib/sequel/dataset/query.rb +7 -7
  50. data/lib/sequel/dataset/sql.rb +5 -18
  51. data/lib/sequel/extensions/core_extensions.rb +8 -12
  52. data/lib/sequel/extensions/pg_array.rb +59 -33
  53. data/lib/sequel/extensions/pg_array_ops.rb +32 -4
  54. data/lib/sequel/extensions/pg_auto_parameterize.rb +1 -1
  55. data/lib/sequel/extensions/pg_hstore.rb +32 -17
  56. data/lib/sequel/extensions/pg_hstore_ops.rb +32 -3
  57. data/lib/sequel/extensions/pg_inet.rb +1 -2
  58. data/lib/sequel/extensions/pg_interval.rb +0 -1
  59. data/lib/sequel/extensions/pg_json.rb +41 -23
  60. data/lib/sequel/extensions/pg_range.rb +36 -11
  61. data/lib/sequel/extensions/pg_range_ops.rb +32 -4
  62. data/lib/sequel/extensions/pg_row.rb +572 -0
  63. data/lib/sequel/extensions/pg_row_ops.rb +164 -0
  64. data/lib/sequel/extensions/query.rb +3 -3
  65. data/lib/sequel/extensions/schema_dumper.rb +7 -8
  66. data/lib/sequel/extensions/select_remove.rb +1 -1
  67. data/lib/sequel/model/base.rb +1 -0
  68. data/lib/sequel/no_core_ext.rb +1 -1
  69. data/lib/sequel/plugins/pg_row.rb +121 -0
  70. data/lib/sequel/plugins/pg_typecast_on_load.rb +65 -0
  71. data/lib/sequel/plugins/validation_helpers.rb +31 -0
  72. data/lib/sequel/sql.rb +64 -44
  73. data/lib/sequel/version.rb +1 -1
  74. data/spec/adapters/mssql_spec.rb +37 -12
  75. data/spec/adapters/mysql_spec.rb +39 -75
  76. data/spec/adapters/oracle_spec.rb +11 -11
  77. data/spec/adapters/postgres_spec.rb +414 -237
  78. data/spec/adapters/spec_helper.rb +1 -1
  79. data/spec/adapters/sqlite_spec.rb +14 -14
  80. data/spec/core/database_spec.rb +6 -6
  81. data/spec/core/dataset_spec.rb +169 -205
  82. data/spec/core/expression_filters_spec.rb +182 -295
  83. data/spec/core/object_graph_spec.rb +6 -6
  84. data/spec/core/schema_spec.rb +14 -14
  85. data/spec/core/spec_helper.rb +1 -0
  86. data/spec/{extensions/core_extensions_spec.rb → core_extensions_spec.rb} +208 -14
  87. data/spec/extensions/columns_introspection_spec.rb +5 -5
  88. data/spec/extensions/hook_class_methods_spec.rb +28 -36
  89. data/spec/extensions/many_through_many_spec.rb +4 -4
  90. data/spec/extensions/pg_array_ops_spec.rb +15 -7
  91. data/spec/extensions/pg_array_spec.rb +81 -48
  92. data/spec/extensions/pg_auto_parameterize_spec.rb +2 -2
  93. data/spec/extensions/pg_hstore_ops_spec.rb +13 -9
  94. data/spec/extensions/pg_hstore_spec.rb +66 -65
  95. data/spec/extensions/pg_inet_spec.rb +2 -4
  96. data/spec/extensions/pg_interval_spec.rb +2 -3
  97. data/spec/extensions/pg_json_spec.rb +20 -18
  98. data/spec/extensions/pg_range_ops_spec.rb +11 -4
  99. data/spec/extensions/pg_range_spec.rb +30 -7
  100. data/spec/extensions/pg_row_ops_spec.rb +48 -0
  101. data/spec/extensions/pg_row_plugin_spec.rb +45 -0
  102. data/spec/extensions/pg_row_spec.rb +323 -0
  103. data/spec/extensions/pg_typecast_on_load_spec.rb +58 -0
  104. data/spec/extensions/query_literals_spec.rb +11 -11
  105. data/spec/extensions/query_spec.rb +3 -3
  106. data/spec/extensions/schema_dumper_spec.rb +20 -4
  107. data/spec/extensions/schema_spec.rb +18 -41
  108. data/spec/extensions/select_remove_spec.rb +4 -4
  109. data/spec/extensions/spec_helper.rb +4 -8
  110. data/spec/extensions/to_dot_spec.rb +5 -5
  111. data/spec/extensions/validation_class_methods_spec.rb +28 -16
  112. data/spec/integration/associations_test.rb +20 -20
  113. data/spec/integration/dataset_test.rb +98 -98
  114. data/spec/integration/eager_loader_test.rb +13 -27
  115. data/spec/integration/plugin_test.rb +5 -5
  116. data/spec/integration/prepared_statement_test.rb +22 -13
  117. data/spec/integration/schema_test.rb +28 -18
  118. data/spec/integration/spec_helper.rb +1 -1
  119. data/spec/integration/timezone_test.rb +2 -2
  120. data/spec/integration/type_test.rb +15 -6
  121. data/spec/model/association_reflection_spec.rb +1 -1
  122. data/spec/model/associations_spec.rb +4 -4
  123. data/spec/model/base_spec.rb +5 -5
  124. data/spec/model/eager_loading_spec.rb +15 -15
  125. data/spec/model/model_spec.rb +32 -32
  126. data/spec/model/record_spec.rb +16 -0
  127. data/spec/model/spec_helper.rb +2 -6
  128. data/spec/model/validations_spec.rb +1 -1
  129. metadata +16 -4
@@ -115,7 +115,7 @@ describe "An Oracle dataset" do
115
115
  {:name => 'def'}
116
116
  ]
117
117
 
118
- @d.order(:value.desc).limit(1).to_a.should == [
118
+ @d.order(Sequel.desc(:value)).limit(1).to_a.should == [
119
119
  {:date_created=>nil, :name => 'def', :value => 789}
120
120
  ]
121
121
 
@@ -124,7 +124,7 @@ describe "An Oracle dataset" do
124
124
  {:date_created=>nil, :name => 'abc', :value => 456}
125
125
  ]
126
126
 
127
- @d.order(:value.desc).filter(:name => 'abc').to_a.should == [
127
+ @d.order(Sequel.desc(:value)).filter(:name => 'abc').to_a.should == [
128
128
  {:date_created=>nil, :name => 'abc', :value => 456},
129
129
  {:date_created=>nil, :name => 'abc', :value => 123}
130
130
  ]
@@ -133,7 +133,7 @@ describe "An Oracle dataset" do
133
133
  {:date_created=>nil, :name => 'abc', :value => 123}
134
134
  ]
135
135
 
136
- @d.filter(:name => 'abc').order(:value.desc).limit(1).to_a.should == [
136
+ @d.filter(:name => 'abc').order(Sequel.desc(:value)).limit(1).to_a.should == [
137
137
  {:date_created=>nil, :name => 'abc', :value => 456}
138
138
  ]
139
139
 
@@ -157,25 +157,25 @@ describe "An Oracle dataset" do
157
157
 
158
158
  @d.max(:value).to_i.should == 789
159
159
 
160
- @d.select(:name, :AVG.sql_function(:value).as(:avg)).filter(:name => 'abc').group(:name).to_a.should == [
160
+ @d.select(:name, Sequel.function(:AVG, :value).as(:avg)).filter(:name => 'abc').group(:name).to_a.should == [
161
161
  {:name => 'abc', :avg => (456+123)/2.0}
162
162
  ]
163
163
 
164
- @d.select(:AVG.sql_function(:value).as(:avg)).group(:name).order(:name).limit(1).to_a.should == [
164
+ @d.select(Sequel.function(:AVG, :value).as(:avg)).group(:name).order(:name).limit(1).to_a.should == [
165
165
  {:avg => (456+123)/2.0}
166
166
  ]
167
167
 
168
- @d.select(:name, :AVG.sql_function(:value).as(:avg)).group(:name).order(:name).to_a.should == [
168
+ @d.select(:name, Sequel.function(:AVG, :value).as(:avg)).group(:name).order(:name).to_a.should == [
169
169
  {:name => 'abc', :avg => (456+123)/2.0},
170
170
  {:name => 'def', :avg => 789*1.0}
171
171
  ]
172
172
 
173
- @d.select(:name, :AVG.sql_function(:value).as(:avg)).group(:name).order(:name).to_a.should == [
173
+ @d.select(:name, Sequel.function(:AVG, :value).as(:avg)).group(:name).order(:name).to_a.should == [
174
174
  {:name => 'abc', :avg => (456+123)/2.0},
175
175
  {:name => 'def', :avg => 789*1.0}
176
176
  ]
177
177
 
178
- @d.select(:name, :AVG.sql_function(:value).as(:avg)).group(:name).having(:name => ['abc', 'def']).order(:name).to_a.should == [
178
+ @d.select(:name, Sequel.function(:AVG, :value).as(:avg)).group(:name).having(:name => ['abc', 'def']).order(:name).to_a.should == [
179
179
  {:name => 'abc', :avg => (456+123)/2.0},
180
180
  {:name => 'def', :avg => 789*1.0}
181
181
  ]
@@ -203,7 +203,7 @@ describe "An Oracle dataset" do
203
203
  specify "should translate values correctly" do
204
204
  @d << {:name => 'abc', :value => 456}
205
205
  @d << {:name => 'def', :value => 789}
206
- @d.filter('value > 500').update(:date_created => "to_timestamp('2009-09-09', 'YYYY-MM-DD')".lit)
206
+ @d.filter('value > 500').update(:date_created => Sequel.lit("to_timestamp('2009-09-09', 'YYYY-MM-DD')"))
207
207
 
208
208
  @d[:name => 'def'][:date_created].strftime('%F').should == '2009-09-09'
209
209
  end
@@ -266,7 +266,7 @@ describe "Joined Oracle dataset" do
266
266
  {:id => 4, :title => 'ddd', :cat_name => nil}
267
267
  ]
268
268
 
269
- @d1.left_outer_join(:categories, :id => :category_id).select(:books__id, :title, :cat_name).order(:books__id.desc).limit(2, 0).to_a.should == [
269
+ @d1.left_outer_join(:categories, :id => :category_id).select(:books__id, :title, :cat_name).reverse_order(:books__id).limit(2, 0).to_a.should == [
270
270
  {:id => 4, :title => 'ddd', :cat_name => nil},
271
271
  {:id => 3, :title => 'ccc', :cat_name => 'rails'}
272
272
  ]
@@ -283,7 +283,7 @@ describe "Oracle aliasing" do
283
283
  end
284
284
 
285
285
  specify "should allow columns to be renamed" do
286
- @d1.select(:title.as(:name)).order_by(:id).to_a.should == [
286
+ @d1.select(Sequel.as(:title, :name)).order_by(:id).to_a.should == [
287
287
  { :name => 'aaa' },
288
288
  { :name => 'bbb' },
289
289
  { :name => 'bbb' },
@@ -52,12 +52,12 @@ describe "A PostgreSQL database" do
52
52
 
53
53
  specify "should correctly parse the schema" do
54
54
  @db.schema(:test3, :reload=>true).should == [
55
- [:value, {:type=>:integer, :allow_null=>true, :default=>nil, :ruby_default=>nil, :db_type=>"integer", :primary_key=>false}],
56
- [:time, {:type=>:datetime, :allow_null=>true, :default=>nil, :ruby_default=>nil, :db_type=>"timestamp without time zone", :primary_key=>false}]
55
+ [:value, {:oid=>23, :type=>:integer, :allow_null=>true, :default=>nil, :ruby_default=>nil, :db_type=>"integer", :primary_key=>false}],
56
+ [:time, {:oid=>1114, :type=>:datetime, :allow_null=>true, :default=>nil, :ruby_default=>nil, :db_type=>"timestamp without time zone", :primary_key=>false}]
57
57
  ]
58
58
  @db.schema(:test4, :reload=>true).should == [
59
- [:name, {:type=>:string, :allow_null=>true, :default=>nil, :ruby_default=>nil, :db_type=>"character varying(20)", :primary_key=>false}],
60
- [:value, {:type=>:blob, :allow_null=>true, :default=>nil, :ruby_default=>nil, :db_type=>"bytea", :primary_key=>false}]
59
+ [:name, {:oid=>1043, :type=>:string, :allow_null=>true, :default=>nil, :ruby_default=>nil, :db_type=>"character varying(20)", :primary_key=>false}],
60
+ [:value, {:oid=>17, :type=>:blob, :allow_null=>true, :default=>nil, :ruby_default=>nil, :db_type=>"bytea", :primary_key=>false}]
61
61
  ]
62
62
  end
63
63
 
@@ -69,73 +69,44 @@ describe "A PostgreSQL database" do
69
69
  @db.drop_table(:public__testfk)
70
70
  end
71
71
  end
72
+
73
+ specify "should return uuid fields as strings" do
74
+ @db.get(Sequel.cast('550e8400-e29b-41d4-a716-446655440000', :uuid)).should == '550e8400-e29b-41d4-a716-446655440000'
75
+ end
72
76
  end
73
77
 
74
78
  describe "A PostgreSQL dataset" do
75
79
  before do
76
80
  @d = POSTGRES_DB[:test]
77
- @d.delete # remove all records
81
+ @d.delete
78
82
  POSTGRES_DB.sqls.clear
79
83
  end
80
84
 
81
85
  specify "should quote columns and tables using double quotes if quoting identifiers" do
82
- @d.select(:name).sql.should == \
83
- 'SELECT "name" FROM "test"'
84
-
85
- @d.select('COUNT(*)'.lit).sql.should == \
86
- 'SELECT COUNT(*) FROM "test"'
87
-
88
- @d.select(:max.sql_function(:value)).sql.should == \
89
- 'SELECT max("value") FROM "test"'
90
-
91
- @d.select(:NOW.sql_function).sql.should == \
92
- 'SELECT NOW() FROM "test"'
93
-
94
- @d.select(:max.sql_function(:items__value)).sql.should == \
95
- 'SELECT max("items"."value") FROM "test"'
96
-
97
- @d.order(:name.desc).sql.should == \
98
- 'SELECT * FROM "test" ORDER BY "name" DESC'
99
-
100
- @d.select('test.name AS item_name'.lit).sql.should == \
101
- 'SELECT test.name AS item_name FROM "test"'
102
-
103
- @d.select('"name"'.lit).sql.should == \
104
- 'SELECT "name" FROM "test"'
105
-
106
- @d.select('max(test."name") AS "max_name"'.lit).sql.should == \
107
- 'SELECT max(test."name") AS "max_name" FROM "test"'
108
-
109
- @d.insert_sql(:x => :y).should =~ \
110
- /\AINSERT INTO "test" \("x"\) VALUES \("y"\)( RETURNING NULL)?\z/
86
+ @d.select(:name).sql.should == 'SELECT "name" FROM "test"'
87
+ @d.select(Sequel.lit('COUNT(*)')).sql.should == 'SELECT COUNT(*) FROM "test"'
88
+ @d.select(Sequel.function(:max, :value)).sql.should == 'SELECT max("value") FROM "test"'
89
+ @d.select(Sequel.function(:NOW)).sql.should == 'SELECT NOW() FROM "test"'
90
+ @d.select(Sequel.function(:max, :items__value)).sql.should == 'SELECT max("items"."value") FROM "test"'
91
+ @d.order(Sequel.desc(:name)).sql.should == 'SELECT * FROM "test" ORDER BY "name" DESC'
92
+ @d.select(Sequel.lit('test.name AS item_name')).sql.should == 'SELECT test.name AS item_name FROM "test"'
93
+ @d.select(Sequel.lit('"name"')).sql.should == 'SELECT "name" FROM "test"'
94
+ @d.select(Sequel.lit('max(test."name") AS "max_name"')).sql.should == 'SELECT max(test."name") AS "max_name" FROM "test"'
95
+ @d.insert_sql(:x => :y).should =~ /\AINSERT INTO "test" \("x"\) VALUES \("y"\)( RETURNING NULL)?\z/
111
96
 
112
97
  if check_sqls
113
- @d.select(:test.sql_function(:abc, 'hello')).sql.should == \
114
- "SELECT test(\"abc\", 'hello') FROM \"test\""
115
-
116
- @d.select(:test.sql_function(:abc__def, 'hello')).sql.should == \
117
- "SELECT test(\"abc\".\"def\", 'hello') FROM \"test\""
118
-
119
- @d.select(:test.sql_function(:abc__def, 'hello').as(:x2)).sql.should == \
120
- "SELECT test(\"abc\".\"def\", 'hello') AS \"x2\" FROM \"test\""
121
-
122
- @d.insert_sql(:value => 333).should =~ \
123
- /\AINSERT INTO "test" \("value"\) VALUES \(333\)( RETURNING NULL)?\z/
98
+ @d.select(Sequel.function(:test, :abc, 'hello')).sql.should == "SELECT test(\"abc\", 'hello') FROM \"test\""
99
+ @d.select(Sequel.function(:test, :abc__def, 'hello')).sql.should == "SELECT test(\"abc\".\"def\", 'hello') FROM \"test\""
100
+ @d.select(Sequel.function(:test, :abc__def, 'hello').as(:x2)).sql.should == "SELECT test(\"abc\".\"def\", 'hello') AS \"x2\" FROM \"test\""
101
+ @d.insert_sql(:value => 333).should =~ /\AINSERT INTO "test" \("value"\) VALUES \(333\)( RETURNING NULL)?\z/
124
102
  end
125
103
  end
126
104
 
127
105
  specify "should quote fields correctly when reversing the order if quoting identifiers" do
128
- @d.reverse_order(:name).sql.should == \
129
- 'SELECT * FROM "test" ORDER BY "name" DESC'
130
-
131
- @d.reverse_order(:name.desc).sql.should == \
132
- 'SELECT * FROM "test" ORDER BY "name" ASC'
133
-
134
- @d.reverse_order(:name, :test.desc).sql.should == \
135
- 'SELECT * FROM "test" ORDER BY "name" DESC, "test" ASC'
136
-
137
- @d.reverse_order(:name.desc, :test).sql.should == \
138
- 'SELECT * FROM "test" ORDER BY "name" ASC, "test" DESC'
106
+ @d.reverse_order(:name).sql.should == 'SELECT * FROM "test" ORDER BY "name" DESC'
107
+ @d.reverse_order(Sequel.desc(:name)).sql.should == 'SELECT * FROM "test" ORDER BY "name" ASC'
108
+ @d.reverse_order(:name, Sequel.desc(:test)).sql.should == 'SELECT * FROM "test" ORDER BY "name" DESC, "test" ASC'
109
+ @d.reverse_order(Sequel.desc(:name), :test).sql.should == 'SELECT * FROM "test" ORDER BY "name" ASC, "test" DESC'
139
110
  end
140
111
 
141
112
  specify "should support regexps" do
@@ -149,9 +120,9 @@ describe "A PostgreSQL dataset" do
149
120
  @d << {:name => 'abc'}
150
121
  @d << {:name => 'bcd'}
151
122
  @d << {:name => 'bcd', :value => 2}
152
- @d.order(:value.asc(:nulls=>:first), :name).select_map(:name).should == %w[abc bcd bcd]
153
- @d.order(:value.asc(:nulls=>:last), :name).select_map(:name).should == %w[bcd abc bcd]
154
- @d.order(:value.asc(:nulls=>:first), :name).reverse.select_map(:name).should == %w[bcd bcd abc]
123
+ @d.order(Sequel.asc(:value, :nulls=>:first), :name).select_map(:name).should == %w[abc bcd bcd]
124
+ @d.order(Sequel.asc(:value, :nulls=>:last), :name).select_map(:name).should == %w[bcd abc bcd]
125
+ @d.order(Sequel.asc(:value, :nulls=>:first), :name).reverse.select_map(:name).should == %w[bcd bcd abc]
155
126
  end
156
127
 
157
128
  specify "#lock should lock tables and yield if a block is given" do
@@ -161,7 +132,7 @@ describe "A PostgreSQL dataset" do
161
132
  specify "should support exclusion constraints when creating or altering tables" do
162
133
  begin
163
134
  @db = POSTGRES_DB
164
- @db.create_table!(:atest){Integer :t; exclude [[:t.desc(:nulls=>:last), '=']], :using=>:btree, :where=>proc{t > 0}}
135
+ @db.create_table!(:atest){Integer :t; exclude [[Sequel.desc(:t, :nulls=>:last), '=']], :using=>:btree, :where=>proc{t > 0}}
165
136
  @db[:atest].insert(1)
166
137
  @db[:atest].insert(2)
167
138
  proc{@db[:atest].insert(2)}.should raise_error(Sequel::DatabaseError)
@@ -200,8 +171,8 @@ describe "A PostgreSQL dataset" do
200
171
  @db = POSTGRES_DB
201
172
  @db.create_table!(:atest){Integer :t}
202
173
  @db[:atest].insert(1262304000)
203
- @db.alter_table(:atest){set_column_type :t, Time, :using=>'epoch'.cast(Time) + '1 second'.cast(:interval) * :t}
204
- @db[:atest].get(:t.extract(:year)).should == 2010
174
+ @db.alter_table(:atest){set_column_type :t, Time, :using=>Sequel.cast('epoch', Time) + Sequel.cast('1 second', :interval) * :t}
175
+ @db[:atest].get(Sequel.extract(:year, :t)).should == 2010
205
176
  ensure
206
177
  @db.drop_table?(:atest)
207
178
  end
@@ -213,7 +184,7 @@ describe "A PostgreSQL dataset" do
213
184
  @db.create_table!(:atest){Integer :t}
214
185
  @db[:atest].insert(1262304000)
215
186
  @db.alter_table(:atest){set_column_type :t, Time, :using=>"'epoch'::timestamp + '1 second'::interval * t"}
216
- @db[:atest].get(:t.extract(:year)).should == 2010
187
+ @db[:atest].get(Sequel.extract(:year, :t)).should == 2010
217
188
  ensure
218
189
  @db.drop_table?(:atest)
219
190
  end
@@ -341,9 +312,9 @@ describe "Dataset#distinct" do
341
312
  @ds.insert(20, 10)
342
313
  @ds.insert(30, 10)
343
314
  @ds.order(:b, :a).distinct.map(:a).should == [20, 30]
344
- @ds.order(:b, :a.desc).distinct.map(:a).should == [30, 20]
315
+ @ds.order(:b, Sequel.desc(:a)).distinct.map(:a).should == [30, 20]
345
316
  @ds.order(:b, :a).distinct(:b).map(:a).should == [20]
346
- @ds.order(:b, :a.desc).distinct(:b).map(:a).should == [30]
317
+ @ds.order(:b, Sequel.desc(:a)).distinct(:b).map(:a).should == [30]
347
318
  end
348
319
  end
349
320
 
@@ -435,7 +406,7 @@ describe "A PostgreSQL dataset with a timestamp field" do
435
406
 
436
407
  if POSTGRES_DB.adapter_scheme == :postgres
437
408
  specify "should handle infinite timestamps if convert_infinite_timestamps is set" do
438
- @d << {:time=>'infinity'.cast(:timestamp)}
409
+ @d << {:time=>Sequel.cast('infinity', :timestamp)}
439
410
  @db.convert_infinite_timestamps = :nil
440
411
  @db[:test3].get(:time).should == nil
441
412
  @db.convert_infinite_timestamps = :string
@@ -443,7 +414,7 @@ describe "A PostgreSQL dataset with a timestamp field" do
443
414
  @db.convert_infinite_timestamps = :float
444
415
  @db[:test3].get(:time).should == 1.0/0.0
445
416
 
446
- @d.update(:time=>'-infinity'.cast(:timestamp))
417
+ @d.update(:time=>Sequel.cast('-infinity', :timestamp))
447
418
  @db.convert_infinite_timestamps = :nil
448
419
  @db[:test3].get(:time).should == nil
449
420
  @db.convert_infinite_timestamps = :string
@@ -730,12 +701,12 @@ describe "Postgres::Database schema qualified tables" do
730
701
  POSTGRES_DB[:schema_test__schema_test].first.should == nil
731
702
  POSTGRES_DB[:schema_test__schema_test].insert(:i=>1).should == 1
732
703
  POSTGRES_DB[:schema_test__schema_test].first.should == {:i=>1}
733
- POSTGRES_DB.from('schema_test.schema_test'.lit).first.should == {:i=>1}
704
+ POSTGRES_DB.from(Sequel.lit('schema_test.schema_test')).first.should == {:i=>1}
734
705
  POSTGRES_DB.drop_table(:schema_test__schema_test)
735
- POSTGRES_DB.create_table(:schema_test.qualify(:schema_test)){integer :i}
706
+ POSTGRES_DB.create_table(Sequel.qualify(:schema_test, :schema_test)){integer :i}
736
707
  POSTGRES_DB[:schema_test__schema_test].first.should == nil
737
- POSTGRES_DB.from('schema_test.schema_test'.lit).first.should == nil
738
- POSTGRES_DB.drop_table(:schema_test.qualify(:schema_test))
708
+ POSTGRES_DB.from(Sequel.lit('schema_test.schema_test')).first.should == nil
709
+ POSTGRES_DB.drop_table(Sequel.qualify(:schema_test, :schema_test))
739
710
  end
740
711
 
741
712
  specify "#tables should not include tables in a default non-public schema" do
@@ -802,13 +773,13 @@ describe "Postgres::Database schema qualified tables" do
802
773
 
803
774
  specify "should be able to get custom sequences for tables in a given schema" do
804
775
  POSTGRES_DB << "CREATE SEQUENCE schema_test.kseq"
805
- POSTGRES_DB.create_table(:schema_test__schema_test){integer :j; primary_key :k, :type=>:integer, :default=>"nextval('schema_test.kseq'::regclass)".lit}
776
+ POSTGRES_DB.create_table(:schema_test__schema_test){integer :j; primary_key :k, :type=>:integer, :default=>Sequel.lit("nextval('schema_test.kseq'::regclass)")}
806
777
  POSTGRES_DB.primary_key_sequence(:schema_test__schema_test).should == '"schema_test".kseq'
807
778
  end
808
779
 
809
780
  specify "should be able to get custom sequences for tables that have spaces in the name in a given schema" do
810
781
  POSTGRES_DB << "CREATE SEQUENCE schema_test.\"ks eq\""
811
- POSTGRES_DB.create_table(:"schema_test__schema test"){integer :j; primary_key :k, :type=>:integer, :default=>"nextval('schema_test.\"ks eq\"'::regclass)".lit}
782
+ POSTGRES_DB.create_table(:"schema_test__schema test"){integer :j; primary_key :k, :type=>:integer, :default=>Sequel.lit("nextval('schema_test.\"ks eq\"'::regclass)")}
812
783
  POSTGRES_DB.primary_key_sequence(:"schema_test__schema test").should == '"schema_test"."ks eq"'
813
784
  end
814
785
 
@@ -889,14 +860,14 @@ describe "Postgres::Database schema qualified tables and eager graphing" do
889
860
  end
890
861
 
891
862
  specify "should have eager graphs work with previous joins" do
892
- bands = @Band.order(:bands__name).select(:s__bands.*).join(:s__members, :band_id=>:id).from_self(:alias=>:bands0).eager_graph(:albums=>:tracks).all
863
+ bands = @Band.order(:bands__name).select_all(:s__bands).join(:s__members, :band_id=>:id).from_self(:alias=>:bands0).eager_graph(:albums=>:tracks).all
893
864
  bands.should == [@b1, @b2]
894
865
  bands.map{|x| x.albums}.should == [[@a1, @a2], [@a3, @a4]]
895
866
  bands.map{|x| x.albums.map{|y| y.tracks}}.should == [[[@t1, @t2], [@t3, @t4]], [[], []]]
896
867
  end
897
868
 
898
869
  specify "should have eager graphs work with joins with the same tables" do
899
- bands = @Band.order(:bands__name).select(:s__bands.*).join(:s__members, :band_id=>:id).eager_graph({:albums=>:tracks}, :members).all
870
+ bands = @Band.order(:bands__name).select_all(:s__bands).join(:s__members, :band_id=>:id).eager_graph({:albums=>:tracks}, :members).all
900
871
  bands.should == [@b1, @b2]
901
872
  bands.map{|x| x.albums}.should == [[@a1, @a2], [@a3, @a4]]
902
873
  bands.map{|x| x.albums.map{|y| y.tracks}}.should == [[[@t1, @t2], [@t3, @t4]], [[], []]]
@@ -934,62 +905,62 @@ describe "Postgres::Database schema qualified tables and eager graphing" do
934
905
  bands.should == [@b1, @b2]
935
906
  bands.map{|x| x.tracks}.should == [[@t1, @t2, @t3, @t4], []]
936
907
 
937
- bands = @Band.order(:tracks__name).from(:s__bands.as(:tracks)).eager_graph(:tracks).all
908
+ bands = @Band.order(:tracks__name).from(Sequel.expr(:s__bands).as(:tracks)).eager_graph(:tracks).all
938
909
  bands.should == [@b1, @b2]
939
910
  bands.map{|x| x.tracks}.should == [[@t1, @t2, @t3, @t4], []]
940
911
 
941
- bands = @Band.order(:tracks__name).from(:s__bands.as(:tracks.identifier)).eager_graph(:tracks).all
912
+ bands = @Band.order(:tracks__name).from(Sequel.expr(:s__bands).as(Sequel.identifier(:tracks))).eager_graph(:tracks).all
942
913
  bands.should == [@b1, @b2]
943
914
  bands.map{|x| x.tracks}.should == [[@t1, @t2, @t3, @t4], []]
944
915
 
945
- bands = @Band.order(:tracks__name).from(:s__bands.as('tracks')).eager_graph(:tracks).all
916
+ bands = @Band.order(:tracks__name).from(Sequel.expr(:s__bands).as('tracks')).eager_graph(:tracks).all
946
917
  bands.should == [@b1, @b2]
947
918
  bands.map{|x| x.tracks}.should == [[@t1, @t2, @t3, @t4], []]
948
919
  end
949
920
 
950
921
  specify "should have eager graphs work with join tables with aliases" do
951
- bands = @Band.order(:bands__name).eager_graph(:members).join(:s__albums___tracks, :band_id=>:id.qualify(:s__bands)).eager_graph(:albums=>:tracks).all
922
+ bands = @Band.order(:bands__name).eager_graph(:members).join(:s__albums___tracks, :band_id=>Sequel.qualify(:s__bands, :id)).eager_graph(:albums=>:tracks).all
952
923
  bands.should == [@b1, @b2]
953
924
  bands.map{|x| x.albums}.should == [[@a1, @a2], [@a3, @a4]]
954
925
  bands.map{|x| x.members}.should == [[@m1, @m2], [@m4, @m3]]
955
926
 
956
- bands = @Band.order(:bands__name).eager_graph(:members).join(:s__albums.as(:tracks), :band_id=>:id.qualify(:s__bands)).eager_graph(:albums=>:tracks).all
927
+ bands = @Band.order(:bands__name).eager_graph(:members).join(Sequel.as(:s__albums, :tracks), :band_id=>Sequel.qualify(:s__bands, :id)).eager_graph(:albums=>:tracks).all
957
928
  bands.should == [@b1, @b2]
958
929
  bands.map{|x| x.albums}.should == [[@a1, @a2], [@a3, @a4]]
959
930
  bands.map{|x| x.members}.should == [[@m1, @m2], [@m4, @m3]]
960
931
 
961
- bands = @Band.order(:bands__name).eager_graph(:members).join(:s__albums.as('tracks'), :band_id=>:id.qualify(:s__bands)).eager_graph(:albums=>:tracks).all
932
+ bands = @Band.order(:bands__name).eager_graph(:members).join(Sequel.as(:s__albums, 'tracks'), :band_id=>Sequel.qualify(:s__bands, :id)).eager_graph(:albums=>:tracks).all
962
933
  bands.should == [@b1, @b2]
963
934
  bands.map{|x| x.albums}.should == [[@a1, @a2], [@a3, @a4]]
964
935
  bands.map{|x| x.members}.should == [[@m1, @m2], [@m4, @m3]]
965
936
 
966
- bands = @Band.order(:bands__name).eager_graph(:members).join(:s__albums.as(:tracks.identifier), :band_id=>:id.qualify(:s__bands)).eager_graph(:albums=>:tracks).all
937
+ bands = @Band.order(:bands__name).eager_graph(:members).join(Sequel.as(:s__albums, Sequel.identifier(:tracks)), :band_id=>Sequel.qualify(:s__bands, :id)).eager_graph(:albums=>:tracks).all
967
938
  bands.should == [@b1, @b2]
968
939
  bands.map{|x| x.albums}.should == [[@a1, @a2], [@a3, @a4]]
969
940
  bands.map{|x| x.members}.should == [[@m1, @m2], [@m4, @m3]]
970
941
 
971
- bands = @Band.order(:bands__name).eager_graph(:members).join(:s__albums, {:band_id=>:id.qualify(:s__bands)}, :table_alias=>:tracks).eager_graph(:albums=>:tracks).all
942
+ bands = @Band.order(:bands__name).eager_graph(:members).join(:s__albums, {:band_id=>Sequel.qualify(:s__bands, :id)}, :table_alias=>:tracks).eager_graph(:albums=>:tracks).all
972
943
  bands.should == [@b1, @b2]
973
944
  bands.map{|x| x.albums}.should == [[@a1, @a2], [@a3, @a4]]
974
945
  bands.map{|x| x.members}.should == [[@m1, @m2], [@m4, @m3]]
975
946
 
976
- bands = @Band.order(:bands__name).eager_graph(:members).join(:s__albums, {:band_id=>:id.qualify(:s__bands)}, :table_alias=>'tracks').eager_graph(:albums=>:tracks).all
947
+ bands = @Band.order(:bands__name).eager_graph(:members).join(:s__albums, {:band_id=>Sequel.qualify(:s__bands, :id)}, :table_alias=>'tracks').eager_graph(:albums=>:tracks).all
977
948
  bands.should == [@b1, @b2]
978
949
  bands.map{|x| x.albums}.should == [[@a1, @a2], [@a3, @a4]]
979
950
  bands.map{|x| x.members}.should == [[@m1, @m2], [@m4, @m3]]
980
951
 
981
- bands = @Band.order(:bands__name).eager_graph(:members).join(:s__albums, {:band_id=>:id.qualify(:s__bands)}, :table_alias=>:tracks.identifier).eager_graph(:albums=>:tracks).all
952
+ bands = @Band.order(:bands__name).eager_graph(:members).join(:s__albums, {:band_id=>Sequel.qualify(:s__bands, :id)}, :table_alias=>Sequel.identifier(:tracks)).eager_graph(:albums=>:tracks).all
982
953
  bands.should == [@b1, @b2]
983
954
  bands.map{|x| x.albums}.should == [[@a1, @a2], [@a3, @a4]]
984
955
  bands.map{|x| x.members}.should == [[@m1, @m2], [@m4, @m3]]
985
956
  end
986
957
 
987
958
  specify "should have eager graphs work with different types of qualified from tables" do
988
- bands = @Band.order(:bands__name).from(:bands.qualify(:s)).eager_graph(:tracks).all
959
+ bands = @Band.order(:bands__name).from(Sequel.qualify(:s, :bands)).eager_graph(:tracks).all
989
960
  bands.should == [@b1, @b2]
990
961
  bands.map{|x| x.tracks}.should == [[@t1, @t2, @t3, @t4], []]
991
962
 
992
- bands = @Band.order(:bands__name).from(:bands.identifier.qualify(:s)).eager_graph(:tracks).all
963
+ bands = @Band.order(:bands__name).from(Sequel.identifier(:bands).qualify(:s)).eager_graph(:tracks).all
993
964
  bands.should == [@b1, @b2]
994
965
  bands.map{|x| x.tracks}.should == [[@t1, @t2, @t3, @t4], []]
995
966
 
@@ -1195,7 +1166,7 @@ if POSTGRES_DB.adapter_scheme == :postgres
1195
1166
 
1196
1167
  specify "should look up conversion procs by name" do
1197
1168
  @db.create_table!(:foo){interval :bar}
1198
- @db[:foo].insert('21 days'.cast(:interval))
1169
+ @db[:foo].insert(Sequel.cast('21 days', :interval))
1199
1170
  @db[:foo].get(:bar).should == 'syad 12'
1200
1171
  end
1201
1172
  end
@@ -1406,7 +1377,7 @@ describe 'PostgreSQL array handling' do
1406
1377
  column :dp, 'double precision[]'
1407
1378
  end
1408
1379
  @tp.call.should == [:integer_array, :integer_array, :bigint_array, :float_array, :float_array]
1409
- @ds.insert([1].pg_array(:int2), [nil, 2].pg_array(:int4), [3, nil].pg_array(:int8), [4, nil, 4.5].pg_array(:real), [5, nil, 5.5].pg_array("double precision"))
1380
+ @ds.insert(Sequel.pg_array([1], :int2), Sequel.pg_array([nil, 2], :int4), Sequel.pg_array([3, nil], :int8), Sequel.pg_array([4, nil, 4.5], :real), Sequel.pg_array([5, nil, 5.5], "double precision"))
1410
1381
  @ds.count.should == 1
1411
1382
  rs = @ds.all
1412
1383
  if @jdbc || @native
@@ -1421,7 +1392,7 @@ describe 'PostgreSQL array handling' do
1421
1392
  end
1422
1393
 
1423
1394
  @ds.delete
1424
- @ds.insert([[1], [2]].pg_array(:int2), [[nil, 2], [3, 4]].pg_array(:int4), [[3, nil], [nil, nil]].pg_array(:int8), [[4, nil], [nil, 4.5]].pg_array(:real), [[5, nil], [nil, 5.5]].pg_array("double precision"))
1395
+ @ds.insert(Sequel.pg_array([[1], [2]], :int2), Sequel.pg_array([[nil, 2], [3, 4]], :int4), Sequel.pg_array([[3, nil], [nil, nil]], :int8), Sequel.pg_array([[4, nil], [nil, 4.5]], :real), Sequel.pg_array([[5, nil], [nil, 5.5]], "double precision"))
1425
1396
 
1426
1397
  rs = @ds.all
1427
1398
  if @jdbc || @native
@@ -1441,7 +1412,7 @@ describe 'PostgreSQL array handling' do
1441
1412
  column :n, 'numeric[]'
1442
1413
  end
1443
1414
  @tp.call.should == [:decimal_array]
1444
- @ds.insert([BigDecimal.new('1.000000000000000000001'), nil, BigDecimal.new('1')].pg_array(:numeric))
1415
+ @ds.insert(Sequel.pg_array([BigDecimal.new('1.000000000000000000001'), nil, BigDecimal.new('1')], :numeric))
1445
1416
  @ds.count.should == 1
1446
1417
  rs = @ds.all
1447
1418
  if @jdbc || @native
@@ -1456,7 +1427,7 @@ describe 'PostgreSQL array handling' do
1456
1427
  end
1457
1428
 
1458
1429
  @ds.delete
1459
- @ds.insert([[BigDecimal.new('1.0000000000000000000000000000001'), nil], [nil, BigDecimal.new('1')]].pg_array(:numeric))
1430
+ @ds.insert(Sequel.pg_array([[BigDecimal.new('1.0000000000000000000000000000001'), nil], [nil, BigDecimal.new('1')]], :numeric))
1460
1431
  rs = @ds.all
1461
1432
  if @jdbc || @native
1462
1433
  rs.should == [{:n=>[[BigDecimal.new('1.0000000000000000000000000000001'), nil], [nil, BigDecimal.new('1')]]}]
@@ -1477,7 +1448,7 @@ describe 'PostgreSQL array handling' do
1477
1448
  column :t, 'text[]'
1478
1449
  end
1479
1450
  @tp.call.should == [:string_array, :string_array, :string_array]
1480
- @ds.insert(['a', nil, 'NULL', 'b"\'c'].pg_array('char(4)'), ['a', nil, 'NULL', 'b"\'c'].pg_array(:varchar), ['a', nil, 'NULL', 'b"\'c'].pg_array(:text))
1451
+ @ds.insert(Sequel.pg_array(['a', nil, 'NULL', 'b"\'c'], 'char(4)'), Sequel.pg_array(['a', nil, 'NULL', 'b"\'c'], :varchar), Sequel.pg_array(['a', nil, 'NULL', 'b"\'c'], :text))
1481
1452
  @ds.count.should == 1
1482
1453
  rs = @ds.all
1483
1454
  if @jdbc || @native
@@ -1492,7 +1463,7 @@ describe 'PostgreSQL array handling' do
1492
1463
  end
1493
1464
 
1494
1465
  @ds.delete
1495
- @ds.insert([[['a'], [nil]], [['NULL'], ['b"\'c']]].pg_array('char(4)'), [[['a'], ['']], [['NULL'], ['b"\'c']]].pg_array(:varchar), [[['a'], [nil]], [['NULL'], ['b"\'c']]].pg_array(:text))
1466
+ @ds.insert(Sequel.pg_array([[['a'], [nil]], [['NULL'], ['b"\'c']]], 'char(4)'), Sequel.pg_array([[['a'], ['']], [['NULL'], ['b"\'c']]], :varchar), Sequel.pg_array([[['a'], [nil]], [['NULL'], ['b"\'c']]], :text))
1496
1467
  rs = @ds.all
1497
1468
  if @jdbc || @native
1498
1469
  rs.should == [{:c=>[[['a '], [nil]], [['NULL'], ['b"\'c']]], :vc=>[[['a'], ['']], [['NULL'], ['b"\'c']]], :t=>[[['a'], [nil]], [['NULL'], ['b"\'c']]]}]
@@ -1520,7 +1491,7 @@ describe 'PostgreSQL array handling' do
1520
1491
  t = Sequel::SQLTime.create(10, 20, 30)
1521
1492
  ts = Time.local(2011, 1, 2, 3, 4, 5)
1522
1493
 
1523
- @ds.insert([true, false].pg_array(:bool), [d, nil].pg_array(:date), [t, nil].pg_array(:time), [ts, nil].pg_array(:timestamp), [ts, nil].pg_array(:timestamptz))
1494
+ @ds.insert(Sequel.pg_array([true, false], :bool), Sequel.pg_array([d, nil], :date), Sequel.pg_array([t, nil], :time), Sequel.pg_array([ts, nil], :timestamp), Sequel.pg_array([ts, nil], :timestamptz))
1524
1495
  @ds.count.should == 1
1525
1496
  rs = @ds.all
1526
1497
  if @jdbc || @native
@@ -1540,7 +1511,7 @@ describe 'PostgreSQL array handling' do
1540
1511
  column :o, 'oid[]'
1541
1512
  end
1542
1513
  @tp.call.should == [:blob_array, :time_timezone_array, :integer_array]
1543
- @ds.insert( [Sequel.blob("a\0"), nil].pg_array(:bytea), [t, nil].pg_array(:timetz), [1, 2, 3].pg_array(:oid))
1514
+ @ds.insert(Sequel.pg_array([Sequel.blob("a\0"), nil], :bytea), Sequel.pg_array([t, nil], :timetz), Sequel.pg_array([1, 2, 3], :oid))
1544
1515
  @ds.count.should == 1
1545
1516
  if @native
1546
1517
  rs = @ds.all
@@ -1566,7 +1537,7 @@ describe 'PostgreSQL array handling' do
1566
1537
  column :i, 'text[]'
1567
1538
  end
1568
1539
  a = ["\"\\\\\"{}\n\t\r \v\b123afP", 'NULL', nil, '']
1569
- @ds.call(:insert, {:i=>:$i}, :i=>a.pg_array)
1540
+ @ds.call(:insert, {:i=>:$i}, :i=>Sequel.pg_array(a))
1570
1541
  @ds.get(:i).should == a
1571
1542
  @ds.filter(:i=>:$i).call(:first, :i=>a).should == {:i=>a}
1572
1543
  @ds.filter(:i=>:$i).call(:first, :i=>['', nil, nil, 'a']).should == nil
@@ -1575,37 +1546,37 @@ describe 'PostgreSQL array handling' do
1575
1546
  column :i, 'date[]'
1576
1547
  end
1577
1548
  a = [Date.today]
1578
- @ds.call(:insert, {:i=>:$i}, :i=>a.pg_array('date'))
1549
+ @ds.call(:insert, {:i=>:$i}, :i=>Sequel.pg_array(a, 'date'))
1579
1550
  @ds.get(:i).should == a
1580
1551
  @ds.filter(:i=>:$i).call(:first, :i=>a).should == {:i=>a}
1581
- @ds.filter(:i=>:$i).call(:first, :i=>[Date.today-1].pg_array('date')).should == nil
1552
+ @ds.filter(:i=>:$i).call(:first, :i=>Sequel.pg_array([Date.today-1], 'date')).should == nil
1582
1553
 
1583
1554
  @db.create_table!(:items) do
1584
1555
  column :i, 'timestamp[]'
1585
1556
  end
1586
1557
  a = [Time.local(2011, 1, 2, 3, 4, 5)]
1587
- @ds.call(:insert, {:i=>:$i}, :i=>a.pg_array('timestamp'))
1558
+ @ds.call(:insert, {:i=>:$i}, :i=>Sequel.pg_array(a, 'timestamp'))
1588
1559
  @ds.get(:i).should == a
1589
1560
  @ds.filter(:i=>:$i).call(:first, :i=>a).should == {:i=>a}
1590
- @ds.filter(:i=>:$i).call(:first, :i=>[a.first-1].pg_array('timestamp')).should == nil
1561
+ @ds.filter(:i=>:$i).call(:first, :i=>Sequel.pg_array([a.first-1], 'timestamp')).should == nil
1591
1562
 
1592
1563
  @db.create_table!(:items) do
1593
1564
  column :i, 'boolean[]'
1594
1565
  end
1595
1566
  a = [true, false]
1596
- @ds.call(:insert, {:i=>:$i}, :i=>a.pg_array('boolean'))
1567
+ @ds.call(:insert, {:i=>:$i}, :i=>Sequel.pg_array(a, 'boolean'))
1597
1568
  @ds.get(:i).should == a
1598
1569
  @ds.filter(:i=>:$i).call(:first, :i=>a).should == {:i=>a}
1599
- @ds.filter(:i=>:$i).call(:first, :i=>[false, true].pg_array('boolean')).should == nil
1570
+ @ds.filter(:i=>:$i).call(:first, :i=>Sequel.pg_array([false, true], 'boolean')).should == nil
1600
1571
 
1601
1572
  @db.create_table!(:items) do
1602
1573
  column :i, 'bytea[]'
1603
1574
  end
1604
1575
  a = [Sequel.blob("a\0'\"")]
1605
- @ds.call(:insert, {:i=>:$i}, :i=>a.pg_array('bytea'))
1576
+ @ds.call(:insert, {:i=>:$i}, :i=>Sequel.pg_array(a, 'bytea'))
1606
1577
  @ds.get(:i).should == a
1607
1578
  @ds.filter(:i=>:$i).call(:first, :i=>a).should == {:i=>a}
1608
- @ds.filter(:i=>:$i).call(:first, :i=>[Sequel.blob("b\0")].pg_array('bytea')).should == nil
1579
+ @ds.filter(:i=>:$i).call(:first, :i=>Sequel.pg_array([Sequel.blob("b\0")], 'bytea')).should == nil
1609
1580
  end if POSTGRES_DB.adapter_scheme == :postgres && SEQUEL_POSTGRES_USES_PG
1610
1581
 
1611
1582
  specify 'with models' do
@@ -1617,7 +1588,7 @@ describe 'PostgreSQL array handling' do
1617
1588
  column :t, 'text[]'
1618
1589
  end
1619
1590
  c = Class.new(Sequel::Model(@db[:items]))
1620
- c.plugin :typecast_on_load, :i, :f, :d, :t unless @native
1591
+ c.plugin :pg_typecast_on_load, :i, :f, :d, :t unless @native
1621
1592
  o = c.create(:i=>[1,2, nil], :f=>[[1, 2.5], [3, 4.5]], :d=>[1, BigDecimal.new('1.000000000000000000001')], :t=>[%w'a b c', ['NULL', nil, '1']])
1622
1593
  o.i.should == [1, 2, nil]
1623
1594
  o.f.should == [[1, 2.5], [3, 4.5]]
@@ -1628,56 +1599,56 @@ describe 'PostgreSQL array handling' do
1628
1599
  specify 'operations/functions with pg_array_ops' do
1629
1600
  Sequel.extension :pg_array_ops
1630
1601
  @db.create_table!(:items){column :i, 'integer[]'; column :i2, 'integer[]'; column :i3, 'integer[]'; column :i4, 'integer[]'; column :i5, 'integer[]'}
1631
- @ds.insert([1, 2, 3].pg_array, [2, 1].pg_array, [4, 4].pg_array, [[5, 5], [4, 3]].pg_array, [1, nil, 5].pg_array)
1602
+ @ds.insert(Sequel.pg_array([1, 2, 3]), Sequel.pg_array([2, 1]), Sequel.pg_array([4, 4]), Sequel.pg_array([[5, 5], [4, 3]]), Sequel.pg_array([1, nil, 5]))
1632
1603
 
1633
- @ds.get(:i.pg_array > :i3).should be_false
1634
- @ds.get(:i3.pg_array > :i).should be_true
1604
+ @ds.get(Sequel.pg_array(:i) > :i3).should be_false
1605
+ @ds.get(Sequel.pg_array(:i3) > :i).should be_true
1635
1606
 
1636
- @ds.get(:i.pg_array >= :i3).should be_false
1637
- @ds.get(:i.pg_array >= :i).should be_true
1607
+ @ds.get(Sequel.pg_array(:i) >= :i3).should be_false
1608
+ @ds.get(Sequel.pg_array(:i) >= :i).should be_true
1638
1609
 
1639
- @ds.get(:i3.pg_array < :i).should be_false
1640
- @ds.get(:i.pg_array < :i3).should be_true
1610
+ @ds.get(Sequel.pg_array(:i3) < :i).should be_false
1611
+ @ds.get(Sequel.pg_array(:i) < :i3).should be_true
1641
1612
 
1642
- @ds.get(:i3.pg_array <= :i).should be_false
1643
- @ds.get(:i.pg_array <= :i).should be_true
1613
+ @ds.get(Sequel.pg_array(:i3) <= :i).should be_false
1614
+ @ds.get(Sequel.pg_array(:i) <= :i).should be_true
1644
1615
 
1645
- @ds.get({5=>:i.pg_array.any}.sql_expr).should be_false
1646
- @ds.get({1=>:i.pg_array.any}.sql_expr).should be_true
1616
+ @ds.get(Sequel.expr(5=>Sequel.pg_array(:i).any)).should be_false
1617
+ @ds.get(Sequel.expr(1=>Sequel.pg_array(:i).any)).should be_true
1647
1618
 
1648
- @ds.get({1=>:i3.pg_array.all}.sql_expr).should be_false
1649
- @ds.get({4=>:i3.pg_array.all}.sql_expr).should be_true
1619
+ @ds.get(Sequel.expr(1=>Sequel.pg_array(:i3).all)).should be_false
1620
+ @ds.get(Sequel.expr(4=>Sequel.pg_array(:i3).all)).should be_true
1650
1621
 
1651
- @ds.get(:i2.pg_array[1]).should == 2
1652
- @ds.get(:i2.pg_array[2]).should == 1
1622
+ @ds.get(Sequel.pg_array(:i2)[1]).should == 2
1623
+ @ds.get(Sequel.pg_array(:i2)[2]).should == 1
1653
1624
 
1654
- @ds.get(:i4.pg_array[2][1]).should == 4
1655
- @ds.get(:i4.pg_array[2][2]).should == 3
1625
+ @ds.get(Sequel.pg_array(:i4)[2][1]).should == 4
1626
+ @ds.get(Sequel.pg_array(:i4)[2][2]).should == 3
1656
1627
 
1657
- @ds.get(:i.pg_array.contains(:i2)).should be_true
1658
- @ds.get(:i.pg_array.contains(:i3)).should be_false
1628
+ @ds.get(Sequel.pg_array(:i).contains(:i2)).should be_true
1629
+ @ds.get(Sequel.pg_array(:i).contains(:i3)).should be_false
1659
1630
 
1660
- @ds.get(:i2.pg_array.contained_by(:i)).should be_true
1661
- @ds.get(:i.pg_array.contained_by(:i2)).should be_false
1631
+ @ds.get(Sequel.pg_array(:i2).contained_by(:i)).should be_true
1632
+ @ds.get(Sequel.pg_array(:i).contained_by(:i2)).should be_false
1662
1633
 
1663
- @ds.get(:i.pg_array.overlaps(:i2)).should be_true
1664
- @ds.get(:i2.pg_array.overlaps(:i3)).should be_false
1634
+ @ds.get(Sequel.pg_array(:i).overlaps(:i2)).should be_true
1635
+ @ds.get(Sequel.pg_array(:i2).overlaps(:i3)).should be_false
1665
1636
 
1666
- @ds.get(:i.pg_array.dims).should == '[1:3]'
1667
- @ds.get(:i.pg_array.length).should == 3
1668
- @ds.get(:i.pg_array.lower).should == 1
1637
+ @ds.get(Sequel.pg_array(:i).dims).should == '[1:3]'
1638
+ @ds.get(Sequel.pg_array(:i).length).should == 3
1639
+ @ds.get(Sequel.pg_array(:i).lower).should == 1
1669
1640
 
1670
1641
  if @db.server_version >= 90000
1671
- @ds.get(:i5.pg_array.join).should == '15'
1672
- @ds.get(:i5.pg_array.join(':')).should == '1:5'
1673
- @ds.get(:i5.pg_array.join(':', '*')).should == '1:*:5'
1642
+ @ds.get(Sequel.pg_array(:i5).join).should == '15'
1643
+ @ds.get(Sequel.pg_array(:i5).join(':')).should == '1:5'
1644
+ @ds.get(Sequel.pg_array(:i5).join(':', '*')).should == '1:*:5'
1674
1645
  end
1675
- @ds.select(:i.pg_array.unnest).from_self.count.should == 3 if @db.server_version >= 80400
1646
+ @ds.select(Sequel.pg_array(:i).unnest).from_self.count.should == 3 if @db.server_version >= 80400
1676
1647
 
1677
1648
  if @native
1678
- @ds.get(:i.pg_array.push(4)).should == [1, 2, 3, 4]
1679
- @ds.get(:i.pg_array.unshift(4)).should == [4, 1, 2, 3]
1680
- @ds.get(:i.pg_array.concat(:i2)).should == [1, 2, 3, 2, 1]
1649
+ @ds.get(Sequel.pg_array(:i).push(4)).should == [1, 2, 3, 4]
1650
+ @ds.get(Sequel.pg_array(:i).unshift(4)).should == [4, 1, 2, 3]
1651
+ @ds.get(Sequel.pg_array(:i).concat(:i2)).should == [1, 2, 3, 2, 1]
1681
1652
  end
1682
1653
  end
1683
1654
  end
@@ -1698,7 +1669,7 @@ describe 'PostgreSQL hstore handling' do
1698
1669
  @db.create_table!(:items) do
1699
1670
  column :h, :hstore
1700
1671
  end
1701
- @ds.insert(@h.hstore)
1672
+ @ds.insert(Sequel.hstore(@h))
1702
1673
  @ds.count.should == 1
1703
1674
  if @native
1704
1675
  rs = @ds.all
@@ -1716,10 +1687,10 @@ describe 'PostgreSQL hstore handling' do
1716
1687
  @db.create_table!(:items) do
1717
1688
  column :i, :hstore
1718
1689
  end
1719
- @ds.call(:insert, {:i=>@h.hstore}, {:i=>:$i})
1690
+ @ds.call(:insert, {:i=>Sequel.hstore(@h)}, {:i=>:$i})
1720
1691
  @ds.get(:i).should == @h
1721
- @ds.filter(:i=>:$i).call(:first, :i=>@h.hstore).should == {:i=>@h}
1722
- @ds.filter(:i=>:$i).call(:first, :i=>{}.hstore).should == nil
1692
+ @ds.filter(:i=>:$i).call(:first, :i=>Sequel.hstore(@h)).should == {:i=>@h}
1693
+ @ds.filter(:i=>:$i).call(:first, :i=>Sequel.hstore({})).should == nil
1723
1694
 
1724
1695
  @ds.delete
1725
1696
  @ds.call(:insert, {:i=>@h}, {:i=>:$i})
@@ -1747,33 +1718,33 @@ describe 'PostgreSQL hstore handling' do
1747
1718
  end
1748
1719
  Sequel.extension :pg_hstore_ops
1749
1720
  c.plugin :many_through_many
1750
- c.plugin :typecast_on_load, :h unless @native
1721
+ c.plugin :pg_typecast_on_load, :h unless @native
1751
1722
 
1752
1723
  h = {'item_id'=>"2", 'left_item_id'=>"1"}
1753
1724
  o2 = c.create(:id=>2)
1754
1725
  o = c.create(:id=>1, :h=>h)
1755
1726
  o.h.should == h
1756
1727
 
1757
- c.many_to_one :item, :class=>c, :key_column=>Sequel.cast(:h.hstore['item_id'], Integer)
1758
- c.one_to_many :items, :class=>c, :key=>Sequel.cast(:h.hstore['item_id'], Integer), :key_method=>:item_id
1759
- c.many_to_many :related_items, :class=>c, :join_table=>:items___i, :left_key=>Sequel.cast(:h.hstore['left_item_id'], Integer), :right_key=>Sequel.cast(:h.hstore['item_id'], Integer)
1728
+ c.many_to_one :item, :class=>c, :key_column=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer)
1729
+ c.one_to_many :items, :class=>c, :key=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer), :key_method=>:item_id
1730
+ c.many_to_many :related_items, :class=>c, :join_table=>:items___i, :left_key=>Sequel.cast(Sequel.hstore(:h)['left_item_id'], Integer), :right_key=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer)
1760
1731
 
1761
- c.many_to_one :other_item, :class=>c, :key=>:id, :primary_key_method=>:item_id, :primary_key=>Sequel.cast(:h.hstore['item_id'], Integer)
1762
- c.one_to_many :other_items, :class=>c, :primary_key=>:item_id, :key=>:id, :primary_key_column=>Sequel.cast(:h.hstore['item_id'], Integer)
1732
+ c.many_to_one :other_item, :class=>c, :key=>:id, :primary_key_method=>:item_id, :primary_key=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer)
1733
+ c.one_to_many :other_items, :class=>c, :primary_key=>:item_id, :key=>:id, :primary_key_column=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer)
1763
1734
  c.many_to_many :other_related_items, :class=>c, :join_table=>:items___i, :left_key=>:id, :right_key=>:id,
1764
- :left_primary_key_column=>Sequel.cast(:h.hstore['left_item_id'], Integer),
1735
+ :left_primary_key_column=>Sequel.cast(Sequel.hstore(:h)['left_item_id'], Integer),
1765
1736
  :left_primary_key=>:left_item_id,
1766
- :right_primary_key=>Sequel.cast(:h.hstore['left_item_id'], Integer),
1737
+ :right_primary_key=>Sequel.cast(Sequel.hstore(:h)['left_item_id'], Integer),
1767
1738
  :right_primary_key_method=>:left_item_id
1768
1739
 
1769
1740
  c.many_through_many :mtm_items, [
1770
- [:items, Sequel.cast(:h.hstore['item_id'], Integer), Sequel.cast(:h.hstore['left_item_id'], Integer)],
1771
- [:items, Sequel.cast(:h.hstore['left_item_id'], Integer), Sequel.cast(:h.hstore['left_item_id'], Integer)]
1741
+ [:items, Sequel.cast(Sequel.hstore(:h)['item_id'], Integer), Sequel.cast(Sequel.hstore(:h)['left_item_id'], Integer)],
1742
+ [:items, Sequel.cast(Sequel.hstore(:h)['left_item_id'], Integer), Sequel.cast(Sequel.hstore(:h)['left_item_id'], Integer)]
1772
1743
  ],
1773
1744
  :class=>c,
1774
- :left_primary_key_column=>Sequel.cast(:h.hstore['item_id'], Integer),
1745
+ :left_primary_key_column=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer),
1775
1746
  :left_primary_key=>:item_id,
1776
- :right_primary_key=>Sequel.cast(:h.hstore['left_item_id'], Integer),
1747
+ :right_primary_key=>Sequel.cast(Sequel.hstore(:h)['left_item_id'], Integer),
1777
1748
  :right_primary_key_method=>:left_item_id
1778
1749
 
1779
1750
  # Lazily Loading
@@ -1827,10 +1798,10 @@ describe 'PostgreSQL hstore handling' do
1827
1798
  specify 'operations/functions with pg_hstore_ops' do
1828
1799
  Sequel.extension :pg_hstore_ops, :pg_array, :pg_array_ops
1829
1800
  @db.create_table!(:items){hstore :h1; hstore :h2; hstore :h3; String :t}
1830
- @ds.insert({'a'=>'b', 'c'=>nil}.hstore, {'a'=>'b'}.hstore, {'d'=>'e'}.hstore)
1831
- h1 = :h1.hstore
1832
- h2 = :h2.hstore
1833
- h3 = :h3.hstore
1801
+ @ds.insert(Sequel.hstore('a'=>'b', 'c'=>nil), Sequel.hstore('a'=>'b'), Sequel.hstore('d'=>'e'))
1802
+ h1 = Sequel.hstore(:h1)
1803
+ h2 = Sequel.hstore(:h2)
1804
+ h3 = Sequel.hstore(:h3)
1834
1805
 
1835
1806
  @ds.get(h1['a']).should == 'b'
1836
1807
  @ds.get(h1['d']).should == nil
@@ -1840,13 +1811,13 @@ describe 'PostgreSQL hstore handling' do
1840
1811
  @ds.get(h2.merge(h3).keys.pg_array.length).should == 2
1841
1812
  @ds.get(h1.merge(h3).keys.pg_array.length).should == 3
1842
1813
 
1843
- unless @db.adapter_scheme == :do
1814
+ unless [:do].include?(@db.adapter_scheme)
1844
1815
  # Broken DataObjects thinks operators with ? represent placeholders
1845
- @ds.get(h1.contain_all(%w'a c'.pg_array)).should == true
1846
- @ds.get(h1.contain_all(%w'a d'.pg_array)).should == false
1816
+ @ds.get(h1.contain_all(Sequel.pg_array(%w'a c'))).should == true
1817
+ @ds.get(h1.contain_all(Sequel.pg_array(%w'a d'))).should == false
1847
1818
 
1848
- @ds.get(h1.contain_any(%w'a d'.pg_array)).should == true
1849
- @ds.get(h1.contain_any(%w'e d'.pg_array)).should == false
1819
+ @ds.get(h1.contain_any(Sequel.pg_array(%w'a d'))).should == true
1820
+ @ds.get(h1.contain_any(Sequel.pg_array(%w'e d'))).should == false
1850
1821
  end
1851
1822
 
1852
1823
  @ds.get(h1.contains(h2)).should == true
@@ -1860,12 +1831,12 @@ describe 'PostgreSQL hstore handling' do
1860
1831
  @ds.get(h1.defined('d')).should == false
1861
1832
 
1862
1833
  @ds.get(h1.delete('a')['c']).should == nil
1863
- @ds.get(h1.delete(%w'a d'.pg_array)['c']).should == nil
1834
+ @ds.get(h1.delete(Sequel.pg_array(%w'a d'))['c']).should == nil
1864
1835
  @ds.get(h1.delete(h2)['c']).should == nil
1865
1836
 
1866
- @ds.from({'a'=>'b', 'c'=>nil}.hstore.op.each).order(:key).all.should == [{:key=>'a', :value=>'b'}, {:key=>'c', :value=>nil}]
1837
+ @ds.from(Sequel.hstore('a'=>'b', 'c'=>nil).op.each).order(:key).all.should == [{:key=>'a', :value=>'b'}, {:key=>'c', :value=>nil}]
1867
1838
 
1868
- unless @db.adapter_scheme == :do
1839
+ unless [:do].include?(@db.adapter_scheme)
1869
1840
  @ds.get(h1.has_key?('c')).should == true
1870
1841
  @ds.get(h1.include?('c')).should == true
1871
1842
  @ds.get(h1.key?('c')).should == true
@@ -1884,16 +1855,16 @@ describe 'PostgreSQL hstore handling' do
1884
1855
  @ds.get(h1.akeys.pg_array.length).should == 2
1885
1856
  @ds.get(h2.akeys.pg_array.length).should == 1
1886
1857
 
1887
- @ds.from({'t'=>'s'}.hstore.op.populate(Sequel::SQL::Cast.new(nil, :items))).select_map(:t).should == ['s']
1888
- @ds.from(:items___i).select({'t'=>'s'}.hstore.op.record_set(:i).as(:r)).from_self(:alias=>:s).select('(r).*'.lit).from_self.select_map(:t).should == ['s']
1858
+ @ds.from(Sequel.hstore('t'=>'s').op.populate(Sequel::SQL::Cast.new(nil, :items))).select_map(:t).should == ['s']
1859
+ @ds.from(:items___i).select(Sequel.hstore('t'=>'s').op.record_set(:i).as(:r)).from_self(:alias=>:s).select(Sequel.lit('(r).*')).from_self.select_map(:t).should == ['s']
1889
1860
 
1890
- @ds.from({'t'=>'s', 'a'=>'b'}.hstore.op.skeys.as(:s)).select_order_map(:s).should == %w'a t'
1861
+ @ds.from(Sequel.hstore('t'=>'s', 'a'=>'b').op.skeys.as(:s)).select_order_map(:s).should == %w'a t'
1891
1862
 
1892
- @ds.get(h1.slice(%w'a c'.pg_array).keys.pg_array.length).should == 2
1893
- @ds.get(h1.slice(%w'd c'.pg_array).keys.pg_array.length).should == 1
1894
- @ds.get(h1.slice(%w'd e'.pg_array).keys.pg_array.length).should == nil
1863
+ @ds.get(h1.slice(Sequel.pg_array(%w'a c')).keys.pg_array.length).should == 2
1864
+ @ds.get(h1.slice(Sequel.pg_array(%w'd c')).keys.pg_array.length).should == 1
1865
+ @ds.get(h1.slice(Sequel.pg_array(%w'd e')).keys.pg_array.length).should == nil
1895
1866
 
1896
- @ds.from({'t'=>'s', 'a'=>'b'}.hstore.op.svals.as(:s)).select_order_map(:s).should == %w'b s'
1867
+ @ds.from(Sequel.hstore('t'=>'s', 'a'=>'b').op.svals.as(:s)).select_order_map(:s).should == %w'b s'
1897
1868
 
1898
1869
  @ds.get(h1.to_array.pg_array.length).should == 4
1899
1870
  @ds.get(h2.to_array.pg_array.length).should == 2
@@ -1923,7 +1894,7 @@ describe 'PostgreSQL json type' do
1923
1894
 
1924
1895
  specify 'insert and retrieve json values' do
1925
1896
  @db.create_table!(:items){json :j}
1926
- @ds.insert(@h.pg_json)
1897
+ @ds.insert(Sequel.pg_json(@h))
1927
1898
  @ds.count.should == 1
1928
1899
  if @native
1929
1900
  rs = @ds.all
@@ -1938,7 +1909,7 @@ describe 'PostgreSQL json type' do
1938
1909
  end
1939
1910
 
1940
1911
  @ds.delete
1941
- @ds.insert(@a.pg_json)
1912
+ @ds.insert(Sequel.pg_json(@a))
1942
1913
  @ds.count.should == 1
1943
1914
  if @native
1944
1915
  rs = @ds.all
@@ -1955,7 +1926,7 @@ describe 'PostgreSQL json type' do
1955
1926
 
1956
1927
  specify 'insert and retrieve json[] values' do
1957
1928
  @db.create_table!(:items){column :j, 'json[]'}
1958
- j = [{'a'=>1}.pg_json, ['b', 2].pg_json].pg_array
1929
+ j = Sequel.pg_array([Sequel.pg_json('a'=>1), Sequel.pg_json(['b', 2])])
1959
1930
  @ds.insert(j)
1960
1931
  @ds.count.should == 1
1961
1932
  if @native
@@ -1973,23 +1944,23 @@ describe 'PostgreSQL json type' do
1973
1944
 
1974
1945
  specify 'use json in bound variables' do
1975
1946
  @db.create_table!(:items){json :i}
1976
- @ds.call(:insert, {:i=>@h.pg_json}, {:i=>:$i})
1947
+ @ds.call(:insert, {:i=>Sequel.pg_json(@h)}, {:i=>:$i})
1977
1948
  @ds.get(:i).should == @h
1978
- @ds.filter(:i.cast(String)=>:$i).call(:first, :i=>@h.pg_json).should == {:i=>@h}
1979
- @ds.filter(:i.cast(String)=>:$i).call(:first, :i=>{}.pg_json).should == nil
1980
- @ds.filter(:i.cast(String)=>:$i).call(:delete, :i=>@h.pg_json).should == 1
1949
+ @ds.filter(Sequel.cast(:i, String)=>:$i).call(:first, :i=>Sequel.pg_json(@h)).should == {:i=>@h}
1950
+ @ds.filter(Sequel.cast(:i, String)=>:$i).call(:first, :i=>Sequel.pg_json({})).should == nil
1951
+ @ds.filter(Sequel.cast(:i, String)=>:$i).call(:delete, :i=>Sequel.pg_json(@h)).should == 1
1981
1952
 
1982
- @ds.call(:insert, {:i=>@a.pg_json}, {:i=>:$i})
1953
+ @ds.call(:insert, {:i=>Sequel.pg_json(@a)}, {:i=>:$i})
1983
1954
  @ds.get(:i).should == @a
1984
- @ds.filter(:i.cast(String)=>:$i).call(:first, :i=>@a.pg_json).should == {:i=>@a}
1985
- @ds.filter(:i.cast(String)=>:$i).call(:first, :i=>[].pg_json).should == nil
1955
+ @ds.filter(Sequel.cast(:i, String)=>:$i).call(:first, :i=>Sequel.pg_json(@a)).should == {:i=>@a}
1956
+ @ds.filter(Sequel.cast(:i, String)=>:$i).call(:first, :i=>Sequel.pg_json([])).should == nil
1986
1957
 
1987
1958
  @db.create_table!(:items){column :i, 'json[]'}
1988
- j = [{'a'=>1}.pg_json, ['b', 2].pg_json].pg_array(:text)
1959
+ j = Sequel.pg_array([Sequel.pg_json('a'=>1), Sequel.pg_json(['b', 2])], :text)
1989
1960
  @ds.call(:insert, {:i=>j}, {:i=>:$i})
1990
1961
  @ds.get(:i).should == j
1991
- @ds.filter(:i.cast('text[]')=>:$i).call(:first, :i=>j).should == {:i=>j}
1992
- @ds.filter(:i.cast('text[]')=>:$i).call(:first, :i=>[].pg_array).should == nil
1962
+ @ds.filter(Sequel.cast(:i, 'text[]')=>:$i).call(:first, :i=>j).should == {:i=>j}
1963
+ @ds.filter(Sequel.cast(:i, 'text[]')=>:$i).call(:first, :i=>Sequel.pg_array([])).should == nil
1993
1964
  end if POSTGRES_DB.adapter_scheme == :postgres && SEQUEL_POSTGRES_USES_PG
1994
1965
 
1995
1966
  specify 'with models' do
@@ -1998,9 +1969,9 @@ describe 'PostgreSQL json type' do
1998
1969
  json :h
1999
1970
  end
2000
1971
  c = Class.new(Sequel::Model(@db[:items]))
2001
- c.plugin :typecast_on_load, :h unless @native
2002
- c.create(:h=>@h.pg_json).h.should == @h
2003
- c.create(:h=>@a.pg_json).h.should == @a
1972
+ c.plugin :pg_typecast_on_load, :h unless @native
1973
+ c.create(:h=>Sequel.pg_json(@h)).h.should == @h
1974
+ c.create(:h=>Sequel.pg_json(@a)).h.should == @a
2004
1975
  end
2005
1976
  end if POSTGRES_DB.server_version >= 90200
2006
1977
 
@@ -2062,7 +2033,7 @@ describe 'PostgreSQL inet/cidr types' do
2062
2033
 
2063
2034
  specify 'insert and retrieve inet/cidr/macaddr array values' do
2064
2035
  @db.create_table!(:items){column :i, 'inet[]'; column :c, 'cidr[]'; column :m, 'macaddr[]'}
2065
- @ds.insert([@ipv4].pg_array('inet'), [@ipv4nm].pg_array('cidr'), ['12:34:56:78:90:ab'].pg_array('macaddr'))
2036
+ @ds.insert(Sequel.pg_array([@ipv4], 'inet'), Sequel.pg_array([@ipv4nm], 'cidr'), Sequel.pg_array(['12:34:56:78:90:ab'], 'macaddr'))
2066
2037
  @ds.count.should == 1
2067
2038
  if @native
2068
2039
  rs = @ds.all
@@ -2111,7 +2082,7 @@ describe 'PostgreSQL inet/cidr types' do
2111
2082
  cidr :c
2112
2083
  end
2113
2084
  c = Class.new(Sequel::Model(@db[:items]))
2114
- c.plugin :typecast_on_load, :i, :c unless @native
2085
+ c.plugin :pg_typecast_on_load, :i, :c unless @native
2115
2086
  c.create(:i=>@v4, :c=>@v4nm).values.values_at(:i, :c).should == [@ipv4, @ipv4nm]
2116
2087
  unless ipv6_broken
2117
2088
  c.create(:i=>@ipv6, :c=>@ipv6nm).values.values_at(:i, :c).should == [@ipv6, @ipv6nm]
@@ -2129,9 +2100,9 @@ describe 'PostgreSQL range types' do
2129
2100
  @ra = {}
2130
2101
  @pgr = {}
2131
2102
  @pgra = {}
2132
- @r.each{|k, v| @ra[k] = [v].pg_array(@map[k])}
2133
- @r.each{|k, v| @pgr[k] = v.pg_range}
2134
- @r.each{|k, v| @pgra[k] = [v.pg_range].pg_array(@map[k])}
2103
+ @r.each{|k, v| @ra[k] = Sequel.pg_array([v], @map[k])}
2104
+ @r.each{|k, v| @pgr[k] = Sequel.pg_range(v)}
2105
+ @r.each{|k, v| @pgra[k] = Sequel.pg_array([Sequel.pg_range(v)], @map[k])}
2135
2106
  @native = POSTGRES_DB.adapter_scheme == :postgres
2136
2107
  end
2137
2108
  after do
@@ -2209,7 +2180,7 @@ describe 'PostgreSQL range types' do
2209
2180
  specify 'with models' do
2210
2181
  @db.create_table!(:items){primary_key :id; int4range :i4; int8range :i8; numrange :n; daterange :d; tsrange :t; tstzrange :tz}
2211
2182
  c = Class.new(Sequel::Model(@db[:items]))
2212
- c.plugin :typecast_on_load, :i4, :i8, :n, :d, :t, :tz unless @native
2183
+ c.plugin :pg_typecast_on_load, :i4, :i8, :n, :d, :t, :tz unless @native
2213
2184
  v = c.create(@r).values
2214
2185
  v.delete(:id)
2215
2186
  v.should == @r
@@ -2217,7 +2188,7 @@ describe 'PostgreSQL range types' do
2217
2188
  unless @db.adapter_scheme == :jdbc
2218
2189
  @db.create_table!(:items){primary_key :id; column :i4, 'int4range[]'; column :i8, 'int8range[]'; column :n, 'numrange[]'; column :d, 'daterange[]'; column :t, 'tsrange[]'; column :tz, 'tstzrange[]'}
2219
2190
  c = Class.new(Sequel::Model(@db[:items]))
2220
- c.plugin :typecast_on_load, :i4, :i8, :n, :d, :t, :tz unless @native
2191
+ c.plugin :pg_typecast_on_load, :i4, :i8, :n, :d, :t, :tz unless @native
2221
2192
  v = c.create(@ra).values
2222
2193
  v.delete(:id)
2223
2194
  v.each{|k,v| v.should == @ra[k].to_a}
@@ -2227,60 +2198,60 @@ describe 'PostgreSQL range types' do
2227
2198
  specify 'operations/functions with pg_range_ops' do
2228
2199
  Sequel.extension :pg_range_ops
2229
2200
 
2230
- @db.get((1..5).pg_range(:int4range).op.contains(2..4)).should be_true
2231
- @db.get((1..5).pg_range(:int4range).op.contains(3..6)).should be_false
2232
- @db.get((1..5).pg_range(:int4range).op.contains(0..6)).should be_false
2201
+ @db.get(Sequel.pg_range(1..5, :int4range).op.contains(2..4)).should be_true
2202
+ @db.get(Sequel.pg_range(1..5, :int4range).op.contains(3..6)).should be_false
2203
+ @db.get(Sequel.pg_range(1..5, :int4range).op.contains(0..6)).should be_false
2233
2204
 
2234
- @db.get((1..5).pg_range(:int4range).op.contained_by(0..6)).should be_true
2235
- @db.get((1..5).pg_range(:int4range).op.contained_by(3..6)).should be_false
2236
- @db.get((1..5).pg_range(:int4range).op.contained_by(2..4)).should be_false
2205
+ @db.get(Sequel.pg_range(1..5, :int4range).op.contained_by(0..6)).should be_true
2206
+ @db.get(Sequel.pg_range(1..5, :int4range).op.contained_by(3..6)).should be_false
2207
+ @db.get(Sequel.pg_range(1..5, :int4range).op.contained_by(2..4)).should be_false
2237
2208
 
2238
- @db.get((1..5).pg_range(:int4range).op.overlaps(5..6)).should be_true
2239
- @db.get((1...5).pg_range(:int4range).op.overlaps(5..6)).should be_false
2209
+ @db.get(Sequel.pg_range(1..5, :int4range).op.overlaps(5..6)).should be_true
2210
+ @db.get(Sequel.pg_range(1...5, :int4range).op.overlaps(5..6)).should be_false
2240
2211
 
2241
- @db.get((1..5).pg_range(:int4range).op.left_of(6..10)).should be_true
2242
- @db.get((1..5).pg_range(:int4range).op.left_of(5..10)).should be_false
2243
- @db.get((1..5).pg_range(:int4range).op.left_of(-1..0)).should be_false
2244
- @db.get((1..5).pg_range(:int4range).op.left_of(-1..3)).should be_false
2212
+ @db.get(Sequel.pg_range(1..5, :int4range).op.left_of(6..10)).should be_true
2213
+ @db.get(Sequel.pg_range(1..5, :int4range).op.left_of(5..10)).should be_false
2214
+ @db.get(Sequel.pg_range(1..5, :int4range).op.left_of(-1..0)).should be_false
2215
+ @db.get(Sequel.pg_range(1..5, :int4range).op.left_of(-1..3)).should be_false
2245
2216
 
2246
- @db.get((1..5).pg_range(:int4range).op.right_of(6..10)).should be_false
2247
- @db.get((1..5).pg_range(:int4range).op.right_of(5..10)).should be_false
2248
- @db.get((1..5).pg_range(:int4range).op.right_of(-1..0)).should be_true
2249
- @db.get((1..5).pg_range(:int4range).op.right_of(-1..3)).should be_false
2217
+ @db.get(Sequel.pg_range(1..5, :int4range).op.right_of(6..10)).should be_false
2218
+ @db.get(Sequel.pg_range(1..5, :int4range).op.right_of(5..10)).should be_false
2219
+ @db.get(Sequel.pg_range(1..5, :int4range).op.right_of(-1..0)).should be_true
2220
+ @db.get(Sequel.pg_range(1..5, :int4range).op.right_of(-1..3)).should be_false
2250
2221
 
2251
- @db.get((1..5).pg_range(:int4range).op.starts_before(6..10)).should be_true
2252
- @db.get((1..5).pg_range(:int4range).op.starts_before(5..10)).should be_true
2253
- @db.get((1..5).pg_range(:int4range).op.starts_before(-1..0)).should be_false
2254
- @db.get((1..5).pg_range(:int4range).op.starts_before(-1..3)).should be_false
2222
+ @db.get(Sequel.pg_range(1..5, :int4range).op.starts_before(6..10)).should be_true
2223
+ @db.get(Sequel.pg_range(1..5, :int4range).op.starts_before(5..10)).should be_true
2224
+ @db.get(Sequel.pg_range(1..5, :int4range).op.starts_before(-1..0)).should be_false
2225
+ @db.get(Sequel.pg_range(1..5, :int4range).op.starts_before(-1..3)).should be_false
2255
2226
 
2256
- @db.get((1..5).pg_range(:int4range).op.ends_after(6..10)).should be_false
2257
- @db.get((1..5).pg_range(:int4range).op.ends_after(5..10)).should be_false
2258
- @db.get((1..5).pg_range(:int4range).op.ends_after(-1..0)).should be_true
2259
- @db.get((1..5).pg_range(:int4range).op.ends_after(-1..3)).should be_true
2227
+ @db.get(Sequel.pg_range(1..5, :int4range).op.ends_after(6..10)).should be_false
2228
+ @db.get(Sequel.pg_range(1..5, :int4range).op.ends_after(5..10)).should be_false
2229
+ @db.get(Sequel.pg_range(1..5, :int4range).op.ends_after(-1..0)).should be_true
2230
+ @db.get(Sequel.pg_range(1..5, :int4range).op.ends_after(-1..3)).should be_true
2260
2231
 
2261
- @db.get((1..5).pg_range(:int4range).op.adjacent_to(6..10)).should be_true
2262
- @db.get((1...5).pg_range(:int4range).op.adjacent_to(6..10)).should be_false
2232
+ @db.get(Sequel.pg_range(1..5, :int4range).op.adjacent_to(6..10)).should be_true
2233
+ @db.get(Sequel.pg_range(1...5, :int4range).op.adjacent_to(6..10)).should be_false
2263
2234
 
2264
- @db.get(((1..5).pg_range(:int4range).op + (6..10)).adjacent_to(6..10)).should be_false
2265
- @db.get(((1..5).pg_range(:int4range).op + (6..10)).adjacent_to(11..20)).should be_true
2235
+ @db.get((Sequel.pg_range(1..5, :int4range).op + (6..10)).adjacent_to(6..10)).should be_false
2236
+ @db.get((Sequel.pg_range(1..5, :int4range).op + (6..10)).adjacent_to(11..20)).should be_true
2266
2237
 
2267
- @db.get(((1..5).pg_range(:int4range).op * (2..6)).adjacent_to(6..10)).should be_true
2268
- @db.get(((1..4).pg_range(:int4range).op * (2..6)).adjacent_to(6..10)).should be_false
2238
+ @db.get((Sequel.pg_range(1..5, :int4range).op * (2..6)).adjacent_to(6..10)).should be_true
2239
+ @db.get((Sequel.pg_range(1..4, :int4range).op * (2..6)).adjacent_to(6..10)).should be_false
2269
2240
 
2270
- @db.get(((1..5).pg_range(:int4range).op - (2..6)).adjacent_to(2..10)).should be_true
2271
- @db.get(((0..4).pg_range(:int4range).op - (3..6)).adjacent_to(4..10)).should be_false
2241
+ @db.get((Sequel.pg_range(1..5, :int4range).op - (2..6)).adjacent_to(2..10)).should be_true
2242
+ @db.get((Sequel.pg_range(0..4, :int4range).op - (3..6)).adjacent_to(4..10)).should be_false
2272
2243
 
2273
- @db.get((0..4).pg_range(:int4range).op.lower).should == 0
2274
- @db.get((0..4).pg_range(:int4range).op.upper).should == 5
2244
+ @db.get(Sequel.pg_range(0..4, :int4range).op.lower).should == 0
2245
+ @db.get(Sequel.pg_range(0..4, :int4range).op.upper).should == 5
2275
2246
 
2276
- @db.get((0..4).pg_range(:int4range).op.isempty).should be_false
2247
+ @db.get(Sequel.pg_range(0..4, :int4range).op.isempty).should be_false
2277
2248
  @db.get(Sequel::Postgres::PGRange.empty(:int4range).op.isempty).should be_true
2278
2249
 
2279
- @db.get((1..5).pg_range(:numrange).op.lower_inc).should be_true
2250
+ @db.get(Sequel.pg_range(1..5, :numrange).op.lower_inc).should be_true
2280
2251
  @db.get(Sequel::Postgres::PGRange.new(1, 5, :exclude_begin=>true, :db_type=>:numrange).op.lower_inc).should be_false
2281
2252
 
2282
- @db.get((1..5).pg_range(:numrange).op.upper_inc).should be_true
2283
- @db.get((1...5).pg_range(:numrange).op.upper_inc).should be_false
2253
+ @db.get(Sequel.pg_range(1..5, :numrange).op.upper_inc).should be_true
2254
+ @db.get(Sequel.pg_range(1...5, :numrange).op.upper_inc).should be_false
2284
2255
 
2285
2256
  @db.get(Sequel::Postgres::PGRange.new(1, 5, :db_type=>:int4range).op.lower_inf).should be_false
2286
2257
  @db.get(Sequel::Postgres::PGRange.new(nil, 5, :db_type=>:int4range).op.lower_inf).should be_true
@@ -2342,7 +2313,7 @@ describe 'PostgreSQL interval types' do
2342
2313
 
2343
2314
  specify 'insert and retrieve interval array values' do
2344
2315
  @db.create_table!(:items){column :i, 'interval[]'}
2345
- @ds.insert(['1 year 2 months 3 weeks 4 days 5 hours 6 minutes 7 seconds'].pg_array('interval'))
2316
+ @ds.insert(Sequel.pg_array(['1 year 2 months 3 weeks 4 days 5 hours 6 minutes 7 seconds'], 'interval'))
2346
2317
  @ds.count.should == 1
2347
2318
  if @native
2348
2319
  rs = @ds.all
@@ -2381,7 +2352,7 @@ describe 'PostgreSQL interval types' do
2381
2352
  interval :i
2382
2353
  end
2383
2354
  c = Class.new(Sequel::Model(@db[:items]))
2384
- c.plugin :typecast_on_load, :i, :c unless @native
2355
+ c.plugin :pg_typecast_on_load, :i, :c unless @native
2385
2356
  v = c.create(:i=>'1 year 2 mons 25 days 05:06:07').i
2386
2357
  v.is_a?(ActiveSupport::Duration).should be_true
2387
2358
  v.should == ActiveSupport::Duration.new(31557600 + 2*86400*30 + 3*86400*7 + 4*86400 + 5*3600 + 6*60 + 7, [[:years, 1], [:months, 2], [:days, 25], [:seconds, 18367]])
@@ -2389,3 +2360,209 @@ describe 'PostgreSQL interval types' do
2389
2360
  end
2390
2361
  end if ((require 'active_support/duration'; require 'active_support/inflector'; require 'active_support/core_ext/string/inflections'; true) rescue false)
2391
2362
 
2363
+ describe 'PostgreSQL row-valued/composite types' do
2364
+ before(:all) do
2365
+ @db = POSTGRES_DB
2366
+ @db.extension :pg_array, :pg_row
2367
+ @ds = @db[:person]
2368
+
2369
+ @db.create_table!(:address) do
2370
+ String :street
2371
+ String :city
2372
+ String :zip
2373
+ end
2374
+ @db.create_table!(:person) do
2375
+ Integer :id
2376
+ address :address
2377
+ end
2378
+ @db.create_table!(:company) do
2379
+ Integer :id
2380
+ column :employees, 'person[]'
2381
+ end
2382
+ @db.register_row_type(:address)
2383
+ @db.register_row_type(:person)
2384
+ @db.register_row_type(:company)
2385
+
2386
+ @native = POSTGRES_DB.adapter_scheme == :postgres
2387
+ end
2388
+ after(:all) do
2389
+ @db.drop_table?(:company, :person, :address)
2390
+ @db.row_types.clear
2391
+ @db.reset_conversion_procs if @native
2392
+ end
2393
+ after do
2394
+ [:company, :person, :address].each{|t| @db[t].delete}
2395
+ end
2396
+
2397
+ specify 'insert and retrieve row types' do
2398
+ @ds.insert(:id=>1, :address=>Sequel.pg_row(['123 Sesame St', 'Somewhere', '12345']))
2399
+ @ds.count.should == 1
2400
+ if @native
2401
+ # Single row valued type
2402
+ rs = @ds.all
2403
+ v = rs.first[:address]
2404
+ v.should_not be_a_kind_of(Hash)
2405
+ v.to_hash.should be_a_kind_of(Hash)
2406
+ v.to_hash.should == {:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'}
2407
+ @ds.delete
2408
+ @ds.insert(rs.first)
2409
+ @ds.all.should == rs
2410
+
2411
+ # Nested row value type
2412
+ p = @ds.get(:person)
2413
+ p[:id].should == 1
2414
+ p[:address].should == v
2415
+ end
2416
+ end
2417
+
2418
+ specify 'insert and retrieve arrays of row types' do
2419
+ @ds = @db[:company]
2420
+ @ds.insert(:id=>1, :employees=>Sequel.pg_array([@db.row_type(:person, [1, Sequel.pg_row(['123 Sesame St', 'Somewhere', '12345'])])]))
2421
+ @ds.count.should == 1
2422
+ if @native
2423
+ v = @ds.get(:company)
2424
+ v.should_not be_a_kind_of(Hash)
2425
+ v.to_hash.should be_a_kind_of(Hash)
2426
+ v[:id].should == 1
2427
+ employees = v[:employees]
2428
+ employees.should_not be_a_kind_of(Array)
2429
+ employees.to_a.should be_a_kind_of(Array)
2430
+ employees.should == [{:id=>1, :address=>{:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'}}]
2431
+ @ds.delete
2432
+ @ds.insert(v[:id], v[:employees])
2433
+ @ds.get(:company).should == v
2434
+ end
2435
+ end
2436
+
2437
+ specify 'use row types in bound variables' do
2438
+ @ds.call(:insert, {:address=>Sequel.pg_row(['123 Sesame St', 'Somewhere', '12345'])}, {:address=>:$address, :id=>1})
2439
+ @ds.get(:address).should == {:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'}
2440
+ @ds.filter(:address=>Sequel.cast(:$address, :address)).call(:first, :address=>Sequel.pg_row(['123 Sesame St', 'Somewhere', '12345']))[:id].should == 1
2441
+ @ds.filter(:address=>Sequel.cast(:$address, :address)).call(:first, :address=>Sequel.pg_row(['123 Sesame St', 'Somewhere', '12356'])).should == nil
2442
+ end if POSTGRES_DB.adapter_scheme == :postgres && SEQUEL_POSTGRES_USES_PG
2443
+
2444
+ specify 'use arrays of row types in bound variables' do
2445
+ @ds = @db[:company]
2446
+ @ds.call(:insert, {:employees=>Sequel.pg_array([@db.row_type(:person, [1, Sequel.pg_row(['123 Sesame St', 'Somewhere', '12345'])])])}, {:employees=>:$employees, :id=>1})
2447
+ @ds.get(:company).should == {:id=>1, :employees=>[{:id=>1, :address=>{:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'}}]}
2448
+ @ds.filter(:employees=>Sequel.cast(:$employees, 'person[]')).call(:first, :employees=>Sequel.pg_array([@db.row_type(:person, [1, Sequel.pg_row(['123 Sesame St', 'Somewhere', '12345'])])]))[:id].should == 1
2449
+ @ds.filter(:employees=>Sequel.cast(:$employees, 'person[]')).call(:first, :employees=>Sequel.pg_array([@db.row_type(:person, [1, Sequel.pg_row(['123 Sesame St', 'Somewhere', '12356'])])])).should == nil
2450
+ end if POSTGRES_DB.adapter_scheme == :postgres && SEQUEL_POSTGRES_USES_PG
2451
+
2452
+ specify 'operations/functions with pg_row_ops' do
2453
+ Sequel.extension :pg_row_ops, :pg_array_ops
2454
+ @ds.insert(:id=>1, :address=>Sequel.pg_row(['123 Sesame St', 'Somewhere', '12345']))
2455
+ @ds.get(Sequel.pg_row(:address)[:street]).should == '123 Sesame St'
2456
+ @ds.get(Sequel.pg_row(:address)[:city]).should == 'Somewhere'
2457
+ @ds.get(Sequel.pg_row(:address)[:zip]).should == '12345'
2458
+
2459
+ @ds = @db[:company]
2460
+ @ds.insert(:id=>1, :employees=>Sequel.pg_array([@db.row_type(:person, [1, Sequel.pg_row(['123 Sesame St', 'Somewhere', '12345'])])]))
2461
+ @ds.get(Sequel.pg_row(:company)[:id]).should == 1
2462
+ if @native
2463
+ @ds.get(Sequel.pg_row(:company)[:employees]).should == [{:id=>1, :address=>{:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'}}]
2464
+ @ds.get(Sequel.pg_row(:company)[:employees][1]).should == {:id=>1, :address=>{:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'}}
2465
+ @ds.get(Sequel.pg_row(:company)[:employees][1][:address]).should == {:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'}
2466
+ end
2467
+ @ds.get(Sequel.pg_row(:company)[:employees][1][:id]).should == 1
2468
+ @ds.get(Sequel.pg_row(:company)[:employees][1][:address][:street]).should == '123 Sesame St'
2469
+ @ds.get(Sequel.pg_row(:company)[:employees][1][:address][:city]).should == 'Somewhere'
2470
+ @ds.get(Sequel.pg_row(:company)[:employees][1][:address][:zip]).should == '12345'
2471
+ end
2472
+
2473
+ context "with models" do
2474
+ before(:all) do
2475
+ class Address < Sequel::Model(:address)
2476
+ plugin :pg_row
2477
+ end
2478
+ class Person < Sequel::Model(:person)
2479
+ plugin :pg_row
2480
+ end
2481
+ class Company < Sequel::Model(:company)
2482
+ plugin :pg_row
2483
+ end
2484
+ @a = Address.new(:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345')
2485
+ @es = Sequel.pg_array([Person.new(:id=>1, :address=>@a)])
2486
+ end
2487
+ after(:all) do
2488
+ Object.send(:remove_const, :Address) rescue nil
2489
+ Object.send(:remove_const, :Person) rescue nil
2490
+ Object.send(:remove_const, :Company) rescue nil
2491
+ end
2492
+
2493
+ specify 'insert and retrieve row types as model objects' do
2494
+ @ds.insert(:id=>1, :address=>@a)
2495
+ @ds.count.should == 1
2496
+ if @native
2497
+ # Single row valued type
2498
+ rs = @ds.all
2499
+ v = rs.first[:address]
2500
+ v.should be_a_kind_of(Address)
2501
+ v.should == @a
2502
+ @ds.delete
2503
+ @ds.insert(rs.first)
2504
+ @ds.all.should == rs
2505
+
2506
+ # Nested row value type
2507
+ p = @ds.get(:person)
2508
+ p.should be_a_kind_of(Person)
2509
+ p.id.should == 1
2510
+ p.address.should be_a_kind_of(Address)
2511
+ p.address.should == @a
2512
+ end
2513
+ end
2514
+
2515
+ specify 'insert and retrieve arrays of row types as model objects' do
2516
+ @ds = @db[:company]
2517
+ @ds.insert(:id=>1, :employees=>@es)
2518
+ @ds.count.should == 1
2519
+ if @native
2520
+ v = @ds.get(:company)
2521
+ v.should be_a_kind_of(Company)
2522
+ v.id.should == 1
2523
+ employees = v[:employees]
2524
+ employees.should_not be_a_kind_of(Array)
2525
+ employees.to_a.should be_a_kind_of(Array)
2526
+ employees.should == @es
2527
+ @ds.delete
2528
+ @ds.insert(v.id, v.employees)
2529
+ @ds.get(:company).should == v
2530
+ end
2531
+ end
2532
+
2533
+ specify 'use model objects in bound variables' do
2534
+ @ds.call(:insert, {:address=>@a}, {:address=>:$address, :id=>1})
2535
+ @ds.get(:address).should == @a
2536
+ @ds.filter(:address=>Sequel.cast(:$address, :address)).call(:first, :address=>@a)[:id].should == 1
2537
+ @ds.filter(:address=>Sequel.cast(:$address, :address)).call(:first, :address=>Address.new(:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12356')).should == nil
2538
+ end if POSTGRES_DB.adapter_scheme == :postgres && SEQUEL_POSTGRES_USES_PG
2539
+
2540
+ specify 'use arrays of model objects in bound variables' do
2541
+ @ds = @db[:company]
2542
+ @ds.call(:insert, {:employees=>@es}, {:employees=>:$employees, :id=>1})
2543
+ @ds.get(:company).should == Company.new(:id=>1, :employees=>@es)
2544
+ @ds.filter(:employees=>Sequel.cast(:$employees, 'person[]')).call(:first, :employees=>@es)[:id].should == 1
2545
+ @ds.filter(:employees=>Sequel.cast(:$employees, 'person[]')).call(:first, :employees=>Sequel.pg_array([@db.row_type(:person, [1, Sequel.pg_row(['123 Sesame St', 'Somewhere', '12356'])])])).should == nil
2546
+ end if POSTGRES_DB.adapter_scheme == :postgres && SEQUEL_POSTGRES_USES_PG
2547
+
2548
+ specify 'model typecasting' do
2549
+ Person.plugin :pg_typecast_on_load, :address unless @native
2550
+ a = Address.new(:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345')
2551
+ o = Person.create(:id=>1, :address=>['123 Sesame St', 'Somewhere', '12345'])
2552
+ o.address.should == a
2553
+ o = Person.create(:id=>1, :address=>{:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'})
2554
+ o.address.should == a
2555
+ o = Person.create(:id=>1, :address=>a)
2556
+ o.address.should == a
2557
+
2558
+ Company.plugin :pg_typecast_on_load, :employees unless @native
2559
+ e = Person.new(:id=>1, :address=>a)
2560
+ unless @db.adapter_scheme == :jdbc
2561
+ o = Company.create(:id=>1, :employees=>[{:id=>1, :address=>{:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'}}])
2562
+ o.employees.should == [e]
2563
+ o = Company.create(:id=>1, :employees=>[e])
2564
+ o.employees.should == [e]
2565
+ end
2566
+ end
2567
+ end
2568
+ end