sequel 4.46.0 → 4.49.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.
- checksums.yaml +4 -4
- data/CHANGELOG +210 -0
- data/Rakefile +1 -1
- data/doc/advanced_associations.rdoc +1 -1
- data/doc/opening_databases.rdoc +3 -2
- data/doc/release_notes/4.47.0.txt +56 -0
- data/doc/release_notes/4.48.0.txt +293 -0
- data/doc/release_notes/4.49.0.txt +222 -0
- data/lib/sequel/adapters/ado/access.rb +2 -1
- data/lib/sequel/adapters/do/postgres.rb +5 -2
- data/lib/sequel/adapters/ibmdb.rb +30 -8
- data/lib/sequel/adapters/jdbc/as400.rb +1 -1
- data/lib/sequel/adapters/jdbc/db2.rb +12 -3
- data/lib/sequel/adapters/jdbc/derby.rb +4 -5
- data/lib/sequel/adapters/jdbc/h2.rb +10 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +16 -2
- data/lib/sequel/adapters/jdbc/postgresql.rb +46 -20
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +9 -7
- data/lib/sequel/adapters/jdbc/sqlserver.rb +20 -6
- data/lib/sequel/adapters/jdbc.rb +39 -23
- data/lib/sequel/adapters/mock.rb +27 -19
- data/lib/sequel/adapters/mysql.rb +17 -16
- data/lib/sequel/adapters/mysql2.rb +5 -6
- data/lib/sequel/adapters/oracle.rb +5 -9
- data/lib/sequel/adapters/postgres.rb +91 -103
- data/lib/sequel/adapters/shared/db2.rb +22 -6
- data/lib/sequel/adapters/shared/mssql.rb +5 -4
- data/lib/sequel/adapters/shared/mysql.rb +79 -25
- data/lib/sequel/adapters/shared/oracle.rb +26 -3
- data/lib/sequel/adapters/shared/postgres.rb +199 -95
- data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
- data/lib/sequel/adapters/shared/sqlite.rb +72 -82
- data/lib/sequel/adapters/sqlanywhere.rb +4 -1
- data/lib/sequel/adapters/sqlite.rb +5 -3
- data/lib/sequel/adapters/swift/postgres.rb +5 -2
- data/lib/sequel/adapters/tinytds.rb +0 -5
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
- data/lib/sequel/adapters/utils/pg_types.rb +2 -76
- data/lib/sequel/ast_transformer.rb +1 -1
- data/lib/sequel/connection_pool/sharded_single.rb +1 -1
- data/lib/sequel/connection_pool/sharded_threaded.rb +1 -1
- data/lib/sequel/connection_pool/single.rb +2 -2
- data/lib/sequel/connection_pool/threaded.rb +2 -2
- data/lib/sequel/connection_pool.rb +9 -2
- data/lib/sequel/core.rb +2 -2
- data/lib/sequel/database/connecting.rb +8 -8
- data/lib/sequel/database/dataset.rb +6 -3
- data/lib/sequel/database/dataset_defaults.rb +14 -1
- data/lib/sequel/database/misc.rb +1 -1
- data/lib/sequel/database/query.rb +3 -0
- data/lib/sequel/database/schema_methods.rb +1 -1
- data/lib/sequel/dataset/actions.rb +72 -10
- data/lib/sequel/dataset/dataset_module.rb +58 -0
- data/lib/sequel/dataset/graph.rb +1 -1
- data/lib/sequel/dataset/misc.rb +1 -0
- data/lib/sequel/dataset/prepared_statements.rb +3 -3
- data/lib/sequel/dataset/query.rb +22 -11
- data/lib/sequel/dataset.rb +1 -1
- data/lib/sequel/exceptions.rb +8 -0
- data/lib/sequel/extensions/_model_pg_row.rb +5 -2
- data/lib/sequel/extensions/core_extensions.rb +4 -1
- data/lib/sequel/extensions/current_datetime_timestamp.rb +2 -1
- data/lib/sequel/extensions/date_arithmetic.rb +1 -0
- data/lib/sequel/extensions/duplicate_columns_handler.rb +3 -3
- data/lib/sequel/extensions/empty_array_ignore_nulls.rb +3 -0
- data/lib/sequel/extensions/filter_having.rb +2 -0
- data/lib/sequel/extensions/freeze_datasets.rb +2 -0
- data/lib/sequel/extensions/from_block.rb +1 -1
- data/lib/sequel/extensions/graph_each.rb +2 -2
- data/lib/sequel/extensions/hash_aliases.rb +2 -0
- data/lib/sequel/extensions/identifier_mangling.rb +0 -7
- data/lib/sequel/extensions/meta_def.rb +2 -0
- data/lib/sequel/extensions/migration.rb +11 -8
- data/lib/sequel/extensions/no_auto_literal_strings.rb +1 -1
- data/lib/sequel/extensions/null_dataset.rb +1 -0
- data/lib/sequel/extensions/pagination.rb +1 -1
- data/lib/sequel/extensions/pg_array.rb +207 -130
- data/lib/sequel/extensions/pg_hstore.rb +38 -20
- data/lib/sequel/extensions/pg_inet.rb +18 -6
- data/lib/sequel/extensions/pg_interval.rb +19 -12
- data/lib/sequel/extensions/pg_json.rb +25 -14
- data/lib/sequel/extensions/pg_json_ops.rb +2 -2
- data/lib/sequel/extensions/pg_range.rb +133 -100
- data/lib/sequel/extensions/pg_range_ops.rb +4 -3
- data/lib/sequel/extensions/pg_row.rb +68 -39
- data/lib/sequel/extensions/pg_row_ops.rb +11 -5
- data/lib/sequel/extensions/query_literals.rb +2 -0
- data/lib/sequel/extensions/ruby18_symbol_extensions.rb +2 -0
- data/lib/sequel/extensions/s.rb +1 -1
- data/lib/sequel/extensions/schema_dumper.rb +29 -25
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +3 -1
- data/lib/sequel/extensions/sequel_4_dataset_methods.rb +83 -0
- data/lib/sequel/extensions/server_block.rb +32 -15
- data/lib/sequel/extensions/set_overrides.rb +2 -2
- data/lib/sequel/extensions/string_agg.rb +0 -1
- data/lib/sequel/extensions/symbol_aref.rb +0 -4
- data/lib/sequel/model/associations.rb +35 -7
- data/lib/sequel/model/base.rb +113 -87
- data/lib/sequel/model/dataset_module.rb +5 -43
- data/lib/sequel/model/errors.rb +2 -1
- data/lib/sequel/model/inflections.rb +17 -5
- data/lib/sequel/model.rb +26 -58
- data/lib/sequel/plugins/active_model.rb +2 -2
- data/lib/sequel/plugins/association_autoreloading.rb +2 -0
- data/lib/sequel/plugins/association_dependencies.rb +3 -3
- data/lib/sequel/plugins/association_pks.rb +73 -46
- data/lib/sequel/plugins/association_proxies.rb +1 -1
- data/lib/sequel/plugins/auto_validations.rb +6 -2
- data/lib/sequel/plugins/boolean_readers.rb +2 -2
- data/lib/sequel/plugins/boolean_subsets.rb +1 -1
- data/lib/sequel/plugins/caching.rb +19 -13
- data/lib/sequel/plugins/class_table_inheritance.rb +24 -13
- data/lib/sequel/plugins/column_conflicts.rb +7 -2
- data/lib/sequel/plugins/column_select.rb +3 -3
- data/lib/sequel/plugins/composition.rb +2 -2
- data/lib/sequel/plugins/csv_serializer.rb +8 -8
- data/lib/sequel/plugins/dataset_associations.rb +25 -13
- data/lib/sequel/plugins/defaults_setter.rb +13 -1
- data/lib/sequel/plugins/eager_each.rb +1 -1
- data/lib/sequel/plugins/force_encoding.rb +2 -2
- data/lib/sequel/plugins/hook_class_methods.rb +9 -12
- data/lib/sequel/plugins/identifier_columns.rb +2 -0
- data/lib/sequel/plugins/instance_filters.rb +3 -1
- data/lib/sequel/plugins/instance_hooks.rb +17 -9
- data/lib/sequel/plugins/json_serializer.rb +19 -12
- data/lib/sequel/plugins/lazy_attributes.rb +8 -7
- data/lib/sequel/plugins/many_to_one_pk_lookup.rb +2 -0
- data/lib/sequel/plugins/modification_detection.rb +3 -0
- data/lib/sequel/plugins/nested_attributes.rb +6 -2
- data/lib/sequel/plugins/pg_array_associations.rb +5 -0
- data/lib/sequel/plugins/pg_row.rb +4 -2
- data/lib/sequel/plugins/pg_typecast_on_load.rb +2 -0
- data/lib/sequel/plugins/prepared_statements.rb +1 -0
- data/lib/sequel/plugins/rcte_tree.rb +4 -24
- data/lib/sequel/plugins/serialization.rb +9 -15
- data/lib/sequel/plugins/single_table_inheritance.rb +8 -3
- data/lib/sequel/plugins/split_values.rb +6 -5
- data/lib/sequel/plugins/static_cache.rb +31 -25
- data/lib/sequel/plugins/subset_conditions.rb +3 -1
- data/lib/sequel/plugins/table_select.rb +1 -1
- data/lib/sequel/plugins/touch.rb +4 -2
- data/lib/sequel/plugins/validation_class_methods.rb +5 -6
- data/lib/sequel/plugins/validation_helpers.rb +14 -8
- data/lib/sequel/plugins/xml_serializer.rb +4 -4
- data/lib/sequel/sql.rb +18 -9
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +115 -14
- data/spec/adapters/mssql_spec.rb +4 -4
- data/spec/adapters/mysql_spec.rb +83 -29
- data/spec/adapters/oracle_spec.rb +28 -24
- data/spec/adapters/postgres_spec.rb +40 -24
- data/spec/adapters/sqlanywhere_spec.rb +88 -86
- data/spec/adapters/sqlite_spec.rb +29 -24
- data/spec/bin_spec.rb +7 -1
- data/spec/core/connection_pool_spec.rb +45 -14
- data/spec/core/database_spec.rb +155 -0
- data/spec/core/dataset_spec.rb +219 -36
- data/spec/core/schema_spec.rb +16 -0
- data/spec/core/spec_helper.rb +1 -0
- data/spec/core_extensions_spec.rb +6 -2
- data/spec/extensions/active_model_spec.rb +1 -1
- data/spec/extensions/arbitrary_servers_spec.rb +1 -1
- data/spec/extensions/association_pks_spec.rb +34 -2
- data/spec/extensions/auto_literal_strings_spec.rb +5 -1
- data/spec/extensions/auto_validations_spec.rb +2 -0
- data/spec/extensions/boolean_readers_spec.rb +1 -1
- data/spec/extensions/boolean_subsets_spec.rb +1 -1
- data/spec/extensions/class_table_inheritance_spec.rb +106 -19
- data/spec/extensions/column_conflicts_spec.rb +11 -0
- data/spec/extensions/column_select_spec.rb +1 -0
- data/spec/extensions/composition_spec.rb +13 -0
- data/spec/extensions/connection_validator_spec.rb +1 -1
- data/spec/extensions/dataset_associations_spec.rb +20 -8
- data/spec/extensions/defaults_setter_spec.rb +15 -1
- data/spec/extensions/filter_having_spec.rb +5 -3
- data/spec/extensions/hash_aliases_spec.rb +3 -1
- data/spec/extensions/identifier_columns_spec.rb +3 -1
- data/spec/extensions/implicit_subquery_spec.rb +4 -2
- data/spec/extensions/json_serializer_spec.rb +18 -0
- data/spec/extensions/lazy_attributes_spec.rb +3 -3
- data/spec/extensions/many_through_many_spec.rb +4 -4
- data/spec/extensions/meta_def_spec.rb +9 -0
- data/spec/extensions/migration_spec.rb +3 -3
- data/spec/extensions/nested_attributes_spec.rb +14 -3
- data/spec/extensions/no_auto_literal_strings_spec.rb +8 -4
- data/spec/extensions/null_dataset_spec.rb +1 -1
- data/spec/extensions/pg_array_associations_spec.rb +29 -18
- data/spec/extensions/pg_array_spec.rb +44 -25
- data/spec/extensions/pg_hstore_spec.rb +10 -0
- data/spec/extensions/pg_inet_spec.rb +26 -0
- data/spec/extensions/pg_interval_spec.rb +20 -0
- data/spec/extensions/pg_json_spec.rb +24 -0
- data/spec/extensions/pg_range_spec.rb +98 -14
- data/spec/extensions/pg_row_spec.rb +14 -4
- data/spec/extensions/pg_typecast_on_load_spec.rb +11 -9
- data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
- data/spec/extensions/query_literals_spec.rb +3 -1
- data/spec/extensions/schema_dumper_spec.rb +108 -94
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +10 -6
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +121 -0
- data/spec/extensions/serialization_spec.rb +1 -1
- data/spec/extensions/server_block_spec.rb +7 -0
- data/spec/extensions/single_table_inheritance_spec.rb +17 -1
- data/spec/extensions/spec_helper.rb +7 -1
- data/spec/extensions/static_cache_spec.rb +75 -24
- data/spec/extensions/string_agg_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +9 -0
- data/spec/extensions/validation_helpers_spec.rb +10 -5
- data/spec/extensions/whitelist_security_spec.rb +26 -0
- data/spec/integration/associations_test.rb +8 -0
- data/spec/integration/dataset_test.rb +45 -44
- data/spec/integration/model_test.rb +53 -4
- data/spec/integration/plugin_test.rb +28 -4
- data/spec/integration/prepared_statement_test.rb +3 -0
- data/spec/integration/schema_test.rb +21 -1
- data/spec/integration/transaction_test.rb +40 -40
- data/spec/model/association_reflection_spec.rb +43 -1
- data/spec/model/associations_spec.rb +29 -9
- data/spec/model/class_dataset_methods_spec.rb +20 -4
- data/spec/model/dataset_methods_spec.rb +12 -3
- data/spec/model/eager_loading_spec.rb +8 -8
- data/spec/model/model_spec.rb +45 -1
- data/spec/model/plugins_spec.rb +34 -0
- data/spec/model/record_spec.rb +1 -1
- data/spec/spec_config.rb +2 -0
- metadata +11 -4
- data/spec/adapters/firebird_spec.rb +0 -405
- data/spec/adapters/informix_spec.rb +0 -100
|
@@ -75,8 +75,8 @@ end
|
|
|
75
75
|
describe "Sequel::Database dump methods" do
|
|
76
76
|
before do
|
|
77
77
|
@d = Sequel::Database.new.extension(:schema_dumper)
|
|
78
|
-
@d.
|
|
79
|
-
@d.
|
|
78
|
+
def @d.tables(o) o[:schema] ? [o[:schema]] : [:t1, :t2] end
|
|
79
|
+
def @d.schema(t, *o)
|
|
80
80
|
v = case t
|
|
81
81
|
when :t1, 't__t1', Sequel.identifier(:t__t1)
|
|
82
82
|
[[:c1, {:db_type=>'integer', :primary_key=>true, :auto_increment=>true, :allow_null=>false}],
|
|
@@ -116,12 +116,12 @@ describe "Sequel::Database dump methods" do
|
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
it "should dump non-Integer primary key columns with explicit :type" do
|
|
119
|
-
@d.
|
|
119
|
+
def @d.schema(*s) [[:c1, {:db_type=>'bigint', :primary_key=>true, :allow_null=>true, :auto_increment=>true}]] end
|
|
120
120
|
@d.dump_table_schema(:t6).must_equal "create_table(:t6) do\n primary_key :c1, :type=>:Bignum\nend"
|
|
121
121
|
end
|
|
122
122
|
|
|
123
123
|
it "should dump non-Integer primary key columns with explicit :type when using :same_db=>true" do
|
|
124
|
-
@d.
|
|
124
|
+
def @d.schema(*s) [[:c1, {:db_type=>'bigint', :primary_key=>true, :allow_null=>true, :auto_increment=>true}]] end
|
|
125
125
|
@d.dump_table_schema(:t6, :same_db=>true).must_equal "create_table(:t6) do\n primary_key :c1, :type=>:Bignum\nend"
|
|
126
126
|
end
|
|
127
127
|
|
|
@@ -130,16 +130,16 @@ describe "Sequel::Database dump methods" do
|
|
|
130
130
|
end
|
|
131
131
|
|
|
132
132
|
it "should handle foreign keys" do
|
|
133
|
-
@d.
|
|
134
|
-
@d.
|
|
135
|
-
@d.
|
|
133
|
+
def @d.schema(*s) [[:c1, {:db_type=>'integer', :allow_null=>true}]] end
|
|
134
|
+
def @d.supports_foreign_key_parsing?; true end
|
|
135
|
+
def @d.foreign_key_list(*s) [{:columns=>[:c1], :table=>:t2, :key=>[:c2]}] end
|
|
136
136
|
@d.dump_table_schema(:t6).must_equal "create_table(:t6) do\n foreign_key :c1, :t2, :key=>[:c2]\nend"
|
|
137
137
|
end
|
|
138
138
|
|
|
139
139
|
it "should handle primary keys that are also foreign keys" do
|
|
140
|
-
@d.
|
|
141
|
-
@d.
|
|
142
|
-
@d.
|
|
140
|
+
def @d.schema(*s) [[:c1, {:db_type=>'integer', :primary_key=>true, :allow_null=>true, :auto_increment=>true}]] end
|
|
141
|
+
def @d.supports_foreign_key_parsing?; true end
|
|
142
|
+
def @d.foreign_key_list(*s) [{:columns=>[:c1], :table=>:t2, :key=>[:c2]}] end
|
|
143
143
|
s = @d.dump_table_schema(:t6)
|
|
144
144
|
s.must_match(/create_table\(:t6\) do\n primary_key :c1, /)
|
|
145
145
|
s.must_match(/:table=>:t2/)
|
|
@@ -147,9 +147,9 @@ describe "Sequel::Database dump methods" do
|
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
it "should handle foreign key options" do
|
|
150
|
-
@d.
|
|
151
|
-
@d.
|
|
152
|
-
@d.
|
|
150
|
+
def @d.schema(*s) [[:c1, {:db_type=>'integer', :allow_null=>true}]] end
|
|
151
|
+
def @d.supports_foreign_key_parsing?; true end
|
|
152
|
+
def @d.foreign_key_list(*s) [{:columns=>[:c1], :table=>:t2, :key=>[:c2], :on_delete=>:restrict, :on_update=>:set_null, :deferrable=>true}] end
|
|
153
153
|
s = @d.dump_table_schema(:t6)
|
|
154
154
|
s.must_match(/create_table\(:t6\) do\n foreign_key :c1, :t2, /)
|
|
155
155
|
s.must_match(/:key=>\[:c2\]/)
|
|
@@ -159,9 +159,9 @@ describe "Sequel::Database dump methods" do
|
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
it "should handle foreign key options in the primary key" do
|
|
162
|
-
@d.
|
|
163
|
-
@d.
|
|
164
|
-
@d.
|
|
162
|
+
def @d.schema(*s) [[:c1, {:db_type=>'integer', :primary_key=>true, :allow_null=>true, :auto_increment=>true}]] end
|
|
163
|
+
def @d.supports_foreign_key_parsing?; true end
|
|
164
|
+
def @d.foreign_key_list(*s) [{:columns=>[:c1], :table=>:t2, :key=>[:c2], :on_delete=>:restrict, :on_update=>:set_null, :deferrable=>true}] end
|
|
165
165
|
s = @d.dump_table_schema(:t6)
|
|
166
166
|
s.must_match(/create_table\(:t6\) do\n primary_key :c1, /)
|
|
167
167
|
s.must_match(/:table=>:t2/)
|
|
@@ -172,9 +172,9 @@ describe "Sequel::Database dump methods" do
|
|
|
172
172
|
end
|
|
173
173
|
|
|
174
174
|
it "should omit foreign key options that are the same as defaults" do
|
|
175
|
-
@d.
|
|
176
|
-
@d.
|
|
177
|
-
@d.
|
|
175
|
+
def @d.schema(*s) [[:c1, {:db_type=>'integer', :allow_null=>true}]] end
|
|
176
|
+
def @d.supports_foreign_key_parsing?; true end
|
|
177
|
+
def @d.foreign_key_list(*s) [{:columns=>[:c1], :table=>:t2, :key=>[:c2], :on_delete=>:no_action, :on_update=>:no_action, :deferrable=>false}] end
|
|
178
178
|
s = @d.dump_table_schema(:t6)
|
|
179
179
|
s.must_match(/create_table\(:t6\) do\n foreign_key :c1, :t2, /)
|
|
180
180
|
s.must_match(/:key=>\[:c2\]/)
|
|
@@ -184,9 +184,9 @@ describe "Sequel::Database dump methods" do
|
|
|
184
184
|
end
|
|
185
185
|
|
|
186
186
|
it "should omit foreign key options that are the same as defaults in the primary key" do
|
|
187
|
-
@d.
|
|
188
|
-
@d.
|
|
189
|
-
@d.
|
|
187
|
+
def @d.schema(*s) [[:c1, {:db_type=>'integer', :primary_key=>true, :allow_null=>true, :auto_increment=>true}]] end
|
|
188
|
+
def @d.supports_foreign_key_parsing?; true end
|
|
189
|
+
def @d.foreign_key_list(*s) [{:columns=>[:c1], :table=>:t2, :key=>[:c2], :on_delete=>:no_action, :on_update=>:no_action, :deferrable=>false}] end
|
|
190
190
|
s = @d.dump_table_schema(:t6)
|
|
191
191
|
s.must_match(/create_table\(:t6\) do\n primary_key :c1, /)
|
|
192
192
|
s.must_match(/:table=>:t2/)
|
|
@@ -197,7 +197,7 @@ describe "Sequel::Database dump methods" do
|
|
|
197
197
|
end
|
|
198
198
|
|
|
199
199
|
it "should dump primary key columns with explicit type equal to the database type when :same_db option is passed" do
|
|
200
|
-
@d.
|
|
200
|
+
def @d.schema(*s) [[:c1, {:db_type=>'somedbspecifictype', :primary_key=>true, :allow_null=>false}]] end
|
|
201
201
|
@d.dump_table_schema(:t7, :same_db => true).must_equal "create_table(:t7) do\n column :c1, \"somedbspecifictype\", :null=>false\n \n primary_key [:c1]\nend"
|
|
202
202
|
end
|
|
203
203
|
|
|
@@ -206,15 +206,15 @@ describe "Sequel::Database dump methods" do
|
|
|
206
206
|
end
|
|
207
207
|
|
|
208
208
|
it "should use a composite foreign_key calls if there is a composite foreign key" do
|
|
209
|
-
@d.
|
|
210
|
-
@d.
|
|
211
|
-
@d.
|
|
209
|
+
def @d.schema(*s) [[:c1, {:db_type=>'integer'}], [:c2, {:db_type=>'integer'}]] end
|
|
210
|
+
def @d.supports_foreign_key_parsing?; true end
|
|
211
|
+
def @d.foreign_key_list(*s) [{:columns=>[:c1, :c2], :table=>:t2, :key=>[:c3, :c4]}] end
|
|
212
212
|
@d.dump_table_schema(:t1).must_equal "create_table(:t1) do\n Integer :c1\n Integer :c2\n \n foreign_key [:c1, :c2], :t2, :key=>[:c3, :c4]\nend"
|
|
213
213
|
end
|
|
214
214
|
|
|
215
215
|
it "should include index information if available" do
|
|
216
|
-
@d.
|
|
217
|
-
@d.
|
|
216
|
+
def @d.supports_index_parsing?; true end
|
|
217
|
+
def @d.indexes(t)
|
|
218
218
|
{:i1=>{:columns=>[:c1], :unique=>false},
|
|
219
219
|
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>true}}
|
|
220
220
|
end
|
|
@@ -255,7 +255,7 @@ END_MIG
|
|
|
255
255
|
end
|
|
256
256
|
|
|
257
257
|
it "should sort table names when dumping a migration" do
|
|
258
|
-
@d.
|
|
258
|
+
def @d.tables(o) [:t2, :t1] end
|
|
259
259
|
@d.dump_schema_migration.must_equal <<-END_MIG
|
|
260
260
|
Sequel.migration do
|
|
261
261
|
change do
|
|
@@ -276,12 +276,12 @@ END_MIG
|
|
|
276
276
|
end
|
|
277
277
|
|
|
278
278
|
it "should sort table names topologically when dumping a migration with foreign keys" do
|
|
279
|
-
@d.
|
|
280
|
-
@d.
|
|
279
|
+
def @d.tables(o) [:t1, :t2] end
|
|
280
|
+
def @d.schema(t, *o)
|
|
281
281
|
t == :t1 ? [[:c2, {:db_type=>'integer'}]] : [[:c1, {:db_type=>'integer', :primary_key=>true, :auto_increment=>true}]]
|
|
282
282
|
end
|
|
283
|
-
@d.
|
|
284
|
-
@d.
|
|
283
|
+
def @d.supports_foreign_key_parsing?; true end
|
|
284
|
+
def @d.foreign_key_list(t)
|
|
285
285
|
t == :t1 ? [{:columns=>[:c2], :table=>:t2, :key=>[:c1]}] : []
|
|
286
286
|
end
|
|
287
287
|
@d.dump_schema_migration.must_equal <<-END_MIG
|
|
@@ -300,12 +300,12 @@ END_MIG
|
|
|
300
300
|
end
|
|
301
301
|
|
|
302
302
|
it "should handle circular dependencies when dumping a migration with foreign keys" do
|
|
303
|
-
@d.
|
|
304
|
-
@d.
|
|
303
|
+
def @d.tables(o) [:t1, :t2] end
|
|
304
|
+
def @d.schema(t, *o)
|
|
305
305
|
t == :t1 ? [[:c2, {:db_type=>'integer'}]] : [[:c1, {:db_type=>'integer'}]]
|
|
306
306
|
end
|
|
307
|
-
@d.
|
|
308
|
-
@d.
|
|
307
|
+
def @d.supports_foreign_key_parsing?; true end
|
|
308
|
+
def @d.foreign_key_list(t)
|
|
309
309
|
t == :t1 ? [{:columns=>[:c2], :table=>:t2, :key=>[:c1]}] : [{:columns=>[:c1], :table=>:t1, :key=>[:c2]}]
|
|
310
310
|
end
|
|
311
311
|
@d.dump_schema_migration.must_equal <<-END_MIG
|
|
@@ -328,12 +328,12 @@ END_MIG
|
|
|
328
328
|
end
|
|
329
329
|
|
|
330
330
|
it "should sort topologically even if the database raises an error when trying to parse foreign keys for a non-existent table" do
|
|
331
|
-
@d.
|
|
332
|
-
@d.
|
|
331
|
+
def @d.tables(o) [:t1, :t2] end
|
|
332
|
+
def @d.schema(t, *o)
|
|
333
333
|
t == :t1 ? [[:c2, {:db_type=>'integer'}]] : [[:c1, {:db_type=>'integer', :primary_key=>true, :auto_increment=>true}]]
|
|
334
334
|
end
|
|
335
|
-
@d.
|
|
336
|
-
@d.
|
|
335
|
+
def @d.supports_foreign_key_parsing?; true end
|
|
336
|
+
def @d.foreign_key_list(t)
|
|
337
337
|
raise Sequel::DatabaseError unless [:t1, :t2].include?(t)
|
|
338
338
|
t == :t1 ? [{:columns=>[:c2], :table=>:t2, :key=>[:c1]}] : []
|
|
339
339
|
end
|
|
@@ -374,8 +374,8 @@ END_MIG
|
|
|
374
374
|
end
|
|
375
375
|
|
|
376
376
|
it "should honor the :index_names => false option to not include names of indexes" do
|
|
377
|
-
@d.
|
|
378
|
-
@d.
|
|
377
|
+
def @d.supports_index_parsing?; true end
|
|
378
|
+
def @d.indexes(t)
|
|
379
379
|
{:i1=>{:columns=>[:c1], :unique=>false},
|
|
380
380
|
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>true}}
|
|
381
381
|
end
|
|
@@ -406,8 +406,8 @@ END_MIG
|
|
|
406
406
|
end
|
|
407
407
|
|
|
408
408
|
it "should make :index_names => :namespace option a noop if there is a global index namespace" do
|
|
409
|
-
@d.
|
|
410
|
-
@d.
|
|
409
|
+
def @d.supports_index_parsing?; true end
|
|
410
|
+
def @d.indexes(t)
|
|
411
411
|
{:i1=>{:columns=>[:c1], :unique=>false},
|
|
412
412
|
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>false}}
|
|
413
413
|
end
|
|
@@ -438,9 +438,9 @@ END_MIG
|
|
|
438
438
|
end
|
|
439
439
|
|
|
440
440
|
it "should honor the :index_names => :namespace option to include names of indexes with prepended table name if there is no global index namespace" do
|
|
441
|
-
@d.
|
|
442
|
-
@d.
|
|
443
|
-
@d.
|
|
441
|
+
def @d.global_index_namespace?; false end
|
|
442
|
+
def @d.supports_index_parsing?; true end
|
|
443
|
+
def @d.indexes(t)
|
|
444
444
|
{:i1=>{:columns=>[:c1], :unique=>false},
|
|
445
445
|
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>false}}
|
|
446
446
|
end
|
|
@@ -471,8 +471,8 @@ END_MIG
|
|
|
471
471
|
end
|
|
472
472
|
|
|
473
473
|
it "should honor the :indexes => false option to not include indexes" do
|
|
474
|
-
@d.
|
|
475
|
-
@d.
|
|
474
|
+
def @d.supports_index_parsing?; true end
|
|
475
|
+
def @d.indexes(t)
|
|
476
476
|
{:i1=>{:columns=>[:c1], :unique=>false},
|
|
477
477
|
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>true}}
|
|
478
478
|
end
|
|
@@ -497,24 +497,24 @@ END_MIG
|
|
|
497
497
|
end
|
|
498
498
|
|
|
499
499
|
it "should have :indexes => false option disable foreign keys as well when dumping a whole migration" do
|
|
500
|
-
@d.
|
|
500
|
+
def @d.foreign_key_list(t)
|
|
501
501
|
t == :t1 ? [{:columns=>[:c2], :table=>:t2, :key=>[:c1]}] : []
|
|
502
502
|
end
|
|
503
503
|
@d.dump_schema_migration(:indexes=>false).wont_match(/foreign_key/)
|
|
504
504
|
end
|
|
505
505
|
|
|
506
506
|
it "should have :foreign_keys option override :indexes => false disabling of foreign keys" do
|
|
507
|
-
@d.
|
|
508
|
-
@d.
|
|
507
|
+
def @d.supports_foreign_key_parsing?; true end
|
|
508
|
+
def @d.foreign_key_list(t)
|
|
509
509
|
t == :t1 ? [{:columns=>[:c2], :table=>:t2, :key=>[:c1]}] : []
|
|
510
510
|
end
|
|
511
511
|
@d.dump_schema_migration(:indexes=>false, :foreign_keys=>true).must_match(/foreign_key/)
|
|
512
512
|
end
|
|
513
513
|
|
|
514
514
|
it "should support dumping just indexes as a migration" do
|
|
515
|
-
@d.
|
|
516
|
-
@d.
|
|
517
|
-
@d.
|
|
515
|
+
def @d.tables(o) [:t1] end
|
|
516
|
+
def @d.supports_index_parsing?; true end
|
|
517
|
+
def @d.indexes(t)
|
|
518
518
|
{:i1=>{:columns=>[:c1], :unique=>false},
|
|
519
519
|
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>true}}
|
|
520
520
|
end
|
|
@@ -529,9 +529,9 @@ END_MIG
|
|
|
529
529
|
end
|
|
530
530
|
|
|
531
531
|
it "should honor the :index_names => false option to not include names of indexes when dumping just indexes as a migration" do
|
|
532
|
-
@d.
|
|
533
|
-
@d.
|
|
534
|
-
@d.
|
|
532
|
+
def @d.tables(o) [:t1] end
|
|
533
|
+
def @d.supports_index_parsing?; true end
|
|
534
|
+
def @d.indexes(t)
|
|
535
535
|
{:i1=>{:columns=>[:c1], :unique=>false},
|
|
536
536
|
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>true}}
|
|
537
537
|
end
|
|
@@ -546,9 +546,9 @@ END_MIG
|
|
|
546
546
|
end
|
|
547
547
|
|
|
548
548
|
it "should honor the :index_names => :namespace option be a noop if there is a global index namespace" do
|
|
549
|
-
@d.
|
|
550
|
-
@d.
|
|
551
|
-
@d.
|
|
549
|
+
def @d.tables(o) [:t1, :t2] end
|
|
550
|
+
def @d.supports_index_parsing?; true end
|
|
551
|
+
def @d.indexes(t)
|
|
552
552
|
{:i1=>{:columns=>[:c1], :unique=>false},
|
|
553
553
|
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>false}}
|
|
554
554
|
end
|
|
@@ -566,10 +566,10 @@ END_MIG
|
|
|
566
566
|
end
|
|
567
567
|
|
|
568
568
|
it "should honor the :index_names => :namespace option to include names of indexes with prepended table name when dumping just indexes as a migration if there is no global index namespace" do
|
|
569
|
-
@d.
|
|
570
|
-
@d.
|
|
571
|
-
@d.
|
|
572
|
-
@d.
|
|
569
|
+
def @d.global_index_namespace?; false end
|
|
570
|
+
def @d.tables(o) [:t1, :t2] end
|
|
571
|
+
def @d.supports_index_parsing?; true end
|
|
572
|
+
def @d.indexes(t)
|
|
573
573
|
{:i1=>{:columns=>[:c1], :unique=>false},
|
|
574
574
|
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>false}}
|
|
575
575
|
end
|
|
@@ -587,7 +587,7 @@ END_MIG
|
|
|
587
587
|
end
|
|
588
588
|
|
|
589
589
|
it "should handle missing index parsing support when dumping index migration" do
|
|
590
|
-
@d.
|
|
590
|
+
def @d.tables(o) [:t1] end
|
|
591
591
|
@d.dump_indexes_migration.must_equal <<-END_MIG
|
|
592
592
|
Sequel.migration do
|
|
593
593
|
change do
|
|
@@ -598,7 +598,7 @@ END_MIG
|
|
|
598
598
|
end
|
|
599
599
|
|
|
600
600
|
it "should handle missing foreign key parsing support when dumping foreign key migration" do
|
|
601
|
-
@d.
|
|
601
|
+
def @d.tables(o) [:t1] end
|
|
602
602
|
@d.dump_foreign_key_migration.must_equal <<-END_MIG
|
|
603
603
|
Sequel.migration do
|
|
604
604
|
change do
|
|
@@ -609,12 +609,12 @@ END_MIG
|
|
|
609
609
|
end
|
|
610
610
|
|
|
611
611
|
it "should support dumping just foreign_keys as a migration" do
|
|
612
|
-
@d.
|
|
613
|
-
@d.
|
|
612
|
+
def @d.tables(o) [:t1, :t2, :t3] end
|
|
613
|
+
def @d.schema(t, *o)
|
|
614
614
|
t == :t1 ? [[:c2, {:db_type=>'integer'}]] : [[:c1, {:db_type=>'integer'}]]
|
|
615
615
|
end
|
|
616
|
-
@d.
|
|
617
|
-
@d.
|
|
616
|
+
def @d.supports_foreign_key_parsing?; true end
|
|
617
|
+
def @d.foreign_key_list(t, *a)
|
|
618
618
|
case t
|
|
619
619
|
when :t1
|
|
620
620
|
[{:columns=>[:c2], :table=>:t2, :key=>[:c1]}]
|
|
@@ -640,12 +640,12 @@ END_MIG
|
|
|
640
640
|
end
|
|
641
641
|
|
|
642
642
|
it "should handle not null values and defaults" do
|
|
643
|
-
@d.
|
|
643
|
+
def @d.schema(*s) [[:c1, {:db_type=>'date', :default=>"'now()'", :allow_null=>true}], [:c2, {:db_type=>'datetime', :allow_null=>false}]] end
|
|
644
644
|
@d.dump_table_schema(:t3).must_equal "create_table(:t3) do\n Date :c1\n DateTime :c2, :null=>false\nend"
|
|
645
645
|
end
|
|
646
646
|
|
|
647
647
|
it "should handle converting common defaults" do
|
|
648
|
-
@d.
|
|
648
|
+
def @d.schema(t, *os)
|
|
649
649
|
s = [[:c1, {:db_type=>'boolean', :default=>"false", :type=>:boolean, :allow_null=>true}],
|
|
650
650
|
[:c2, {:db_type=>'varchar', :default=>"'blah'", :type=>:string, :allow_null=>true}],
|
|
651
651
|
[:c3, {:db_type=>'integer', :default=>"-1", :type=>:integer, :allow_null=>true}],
|
|
@@ -667,10 +667,10 @@ END_MIG
|
|
|
667
667
|
end
|
|
668
668
|
|
|
669
669
|
it "should not use a literal string as a fallback if using MySQL with the :same_db option" do
|
|
670
|
-
@d.
|
|
671
|
-
@d.
|
|
672
|
-
@d.
|
|
673
|
-
@d.
|
|
670
|
+
def @d.database_type; :mysql end
|
|
671
|
+
def @d.supports_index_parsing?; false end
|
|
672
|
+
def @d.supports_foreign_key_parsing?; false end
|
|
673
|
+
def @d.schema(t, *os)
|
|
674
674
|
s = [[:c10, {:db_type=>'foo', :default=>"'6 weeks'", :type=>nil, :allow_null=>true}]]
|
|
675
675
|
s.each{|_, c| c[:ruby_default] = column_schema_to_ruby_default(c[:default], c[:type])}
|
|
676
676
|
s
|
|
@@ -683,7 +683,8 @@ END_MIG
|
|
|
683
683
|
end
|
|
684
684
|
|
|
685
685
|
it "should convert many database types to ruby types" do
|
|
686
|
-
|
|
686
|
+
def @d.schema(t, *o)
|
|
687
|
+
types = %w"mediumint smallint int integer mediumint(6) smallint(7) int(8) integer(9)
|
|
687
688
|
tinyint tinyint(2) bigint bigint(20) real float double boolean tinytext mediumtext
|
|
688
689
|
longtext text clob date datetime timestamp time char character
|
|
689
690
|
varchar varchar(255) varchar(30) bpchar string money
|
|
@@ -695,7 +696,6 @@ END_MIG
|
|
|
695
696
|
["timestamp(6) without time zone", "timestamp(6) with time zone", 'mediumint(10) unsigned', 'int(9) unsigned',
|
|
696
697
|
'int(10) unsigned', "int(12) unsigned", 'bigint unsigned', 'tinyint(3) unsigned', 'identity', 'int identity'] +
|
|
697
698
|
%w"integer(10) bit bool"
|
|
698
|
-
@d.meta_def(:schema) do |t, *o|
|
|
699
699
|
i = 0
|
|
700
700
|
types.map{|x| [:"c#{i+=1}", {:db_type=>x, :allow_null=>true}]}
|
|
701
701
|
end
|
|
@@ -787,10 +787,9 @@ END_MIG
|
|
|
787
787
|
end
|
|
788
788
|
|
|
789
789
|
it "should convert mysql types to ruby types" do
|
|
790
|
-
|
|
791
|
-
@d.meta_def(:schema) do |t, *o|
|
|
790
|
+
def @d.schema(t, *o)
|
|
792
791
|
i = 0
|
|
793
|
-
|
|
792
|
+
['double(15,2)', 'double(7,1) unsigned'].map{|x| [:"c#{i+=1}", {:db_type=>x, :allow_null=>true}]}
|
|
794
793
|
end
|
|
795
794
|
@d.dump_table_schema(:x).must_equal((<<END_MIG).chomp)
|
|
796
795
|
create_table(:x) do
|
|
@@ -802,25 +801,40 @@ end
|
|
|
802
801
|
END_MIG
|
|
803
802
|
end
|
|
804
803
|
|
|
804
|
+
it "should convert oracle special types to ruby types" do
|
|
805
|
+
def @d.database_type; :oracle end
|
|
806
|
+
def @d.schema(t, *o)
|
|
807
|
+
i = 0
|
|
808
|
+
['number not null', 'date not null', 'varchar2(4 byte) not null'].map{|x| [:"c#{i+=1}", {:db_type=>x, :allow_null=>false}]}
|
|
809
|
+
end
|
|
810
|
+
@d.dump_table_schema(:x).must_equal((<<END_MIG).chomp)
|
|
811
|
+
create_table(:x) do
|
|
812
|
+
BigDecimal :c1, :null=>false
|
|
813
|
+
Date :c2, :null=>false
|
|
814
|
+
String :c3, :null=>false
|
|
815
|
+
end
|
|
816
|
+
END_MIG
|
|
817
|
+
end
|
|
818
|
+
|
|
805
819
|
it "should force specify :null option for MySQL timestamp columns when using :same_db" do
|
|
806
|
-
@d.
|
|
807
|
-
@d.
|
|
820
|
+
def @d.database_type; :mysql end
|
|
821
|
+
def @d.schema(*s) [[:c1, {:db_type=>'timestamp', :primary_key=>true, :allow_null=>true}]] end
|
|
808
822
|
@d.dump_table_schema(:t3, :same_db=>true).must_equal "create_table(:t3) do\n column :c1, \"timestamp\", :null=>true\n \n primary_key [:c1]\nend"
|
|
809
823
|
|
|
810
|
-
@d.
|
|
824
|
+
def @d.schema(*s) [[:c1, {:db_type=>'timestamp', :primary_key=>true, :allow_null=>false}]] end
|
|
811
825
|
@d.dump_table_schema(:t3, :same_db=>true).must_equal "create_table(:t3) do\n column :c1, \"timestamp\", :null=>false\n \n primary_key [:c1]\nend"
|
|
812
826
|
end
|
|
813
827
|
|
|
814
828
|
it "should use separate primary_key call with non autoincrementable types" do
|
|
815
|
-
@d.
|
|
829
|
+
def @d.schema(*s) [[:c1, {:db_type=>'varchar(8)', :primary_key=>true, :auto_increment=>false}]] end
|
|
816
830
|
@d.dump_table_schema(:t3).must_equal "create_table(:t3) do\n String :c1, :size=>8\n \n primary_key [:c1]\nend"
|
|
817
831
|
@d.dump_table_schema(:t3, :same_db=>true).must_equal "create_table(:t3) do\n column :c1, \"varchar(8)\"\n \n primary_key [:c1]\nend"
|
|
818
832
|
end
|
|
819
833
|
|
|
820
834
|
it "should use explicit type for non integer foreign_key types" do
|
|
821
|
-
@d.
|
|
822
|
-
@d.
|
|
823
|
-
@d.
|
|
835
|
+
def @d.schema(*s) [[:c1, {:db_type=>'date', :primary_key=>true, :auto_increment=>false}]] end
|
|
836
|
+
def @d.supports_foreign_key_parsing?; true end
|
|
837
|
+
def @d.foreign_key_list(t, *a) [{:columns=>[:c1], :table=>:t3, :key=>[:c1]}] if t == :t4 end
|
|
824
838
|
["create_table(:t4) do\n foreign_key :c1, :t3, :type=>Date, :key=>[:c1]\n \n primary_key [:c1]\nend",
|
|
825
839
|
"create_table(:t4) do\n foreign_key :c1, :t3, :key=>[:c1], :type=>Date\n \n primary_key [:c1]\nend"].must_include(@d.dump_table_schema(:t4))
|
|
826
840
|
["create_table(:t4) do\n foreign_key :c1, :t3, :type=>\"date\", :key=>[:c1]\n \n primary_key [:c1]\nend",
|
|
@@ -828,16 +842,16 @@ END_MIG
|
|
|
828
842
|
end
|
|
829
843
|
|
|
830
844
|
it "should correctly handing autoincrementing primary keys that are also foreign keys" do
|
|
831
|
-
@d.
|
|
832
|
-
@d.
|
|
833
|
-
@d.
|
|
845
|
+
def @d.schema(*s) [[:c1, {:db_type=>'integer', :primary_key=>true, :auto_increment=>true}]] end
|
|
846
|
+
def @d.supports_foreign_key_parsing?; true end
|
|
847
|
+
def @d.foreign_key_list(t, *a) [{:columns=>[:c1], :table=>:t3, :key=>[:c1]}] if t == :t4 end
|
|
834
848
|
["create_table(:t4) do\n primary_key :c1, :table=>:t3, :key=>[:c1]\nend",
|
|
835
849
|
"create_table(:t4) do\n primary_key :c1, :key=>[:c1], :table=>:t3\nend"].must_include(@d.dump_table_schema(:t4))
|
|
836
850
|
end
|
|
837
851
|
|
|
838
852
|
it "should handle dumping on PostgreSQL using qualified tables" do
|
|
839
853
|
@d = Sequel.connect('mock://postgres').extension(:schema_dumper)
|
|
840
|
-
@d.
|
|
854
|
+
def @d.schema(*s) [[:c1, {:db_type=>'timestamp', :primary_key=>true, :allow_null=>true}]] end
|
|
841
855
|
@d.dump_table_schema(Sequel.qualify(:foo, :bar), :same_db=>true).must_equal "create_table(Sequel::SQL::QualifiedIdentifier.new(:foo, :bar)) do\n column :c1, \"timestamp\"\n \n primary_key [:c1]\nend"
|
|
842
856
|
end
|
|
843
857
|
end
|
|
@@ -2,7 +2,9 @@ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
|
|
2
2
|
|
|
3
3
|
describe "Dataset#to_csv" do
|
|
4
4
|
before do
|
|
5
|
-
|
|
5
|
+
deprecated do
|
|
6
|
+
@ds = Sequel.mock(:fetch=>[{:a=>1, :b=>2, :c=>3}, {:a=>4, :b=>5, :c=>6}, {:a=>7, :b=>8, :c=>9}])[:items].columns(:a, :b, :c).extension(:sequel_3_dataset_methods)
|
|
7
|
+
end
|
|
6
8
|
end
|
|
7
9
|
|
|
8
10
|
it "should format a CSV representation of the records" do
|
|
@@ -15,7 +17,7 @@ describe "Dataset#to_csv" do
|
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
describe "Dataset#[]=" do
|
|
18
|
-
|
|
20
|
+
deprecated "should perform an update on the specified filter" do
|
|
19
21
|
db = Sequel.mock
|
|
20
22
|
ds = db[:items].extension(:sequel_3_dataset_methods)
|
|
21
23
|
ds[:a => 1] = {:x => 3}
|
|
@@ -26,7 +28,9 @@ end
|
|
|
26
28
|
describe "Dataset#insert_multiple" do
|
|
27
29
|
before do
|
|
28
30
|
@db = Sequel.mock(:autoid=>2)
|
|
29
|
-
|
|
31
|
+
deprecated do
|
|
32
|
+
@ds = @db[:items].extension(:sequel_3_dataset_methods)
|
|
33
|
+
end
|
|
30
34
|
end
|
|
31
35
|
|
|
32
36
|
it "should insert all items in the supplied array" do
|
|
@@ -92,7 +96,7 @@ unless Sequel.mock.dataset.frozen?
|
|
|
92
96
|
end
|
|
93
97
|
|
|
94
98
|
describe "Dataset#set" do
|
|
95
|
-
|
|
99
|
+
deprecated "should act as alias to #update" do
|
|
96
100
|
db = Sequel.mock
|
|
97
101
|
ds = db[:items].extension(:sequel_3_dataset_methods)
|
|
98
102
|
ds.set({:x => 3})
|
|
@@ -101,13 +105,13 @@ describe "Dataset#set" do
|
|
|
101
105
|
end
|
|
102
106
|
|
|
103
107
|
describe "Sequel::Dataset#qualify_to_first_source" do
|
|
104
|
-
|
|
108
|
+
deprecated "should qualify to the first source" do
|
|
105
109
|
Sequel.mock.dataset.extension(:sequel_3_dataset_methods).from(:t).filter{a<b}.qualify_to_first_source.sql.must_equal 'SELECT t.* FROM t WHERE (t.a < t.b)'
|
|
106
110
|
end
|
|
107
111
|
end
|
|
108
112
|
|
|
109
113
|
describe "Sequel::Dataset#qualify_to" do
|
|
110
|
-
|
|
114
|
+
deprecated "should qualify to the given table" do
|
|
111
115
|
Sequel.mock.dataset.extension(:sequel_3_dataset_methods).from(:t).filter{a<b}.qualify_to(:e).sql.must_equal 'SELECT e.* FROM t WHERE (e.a < e.b)'
|
|
112
116
|
end
|
|
113
117
|
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
|
2
|
+
|
|
3
|
+
describe "Dataset#and" do
|
|
4
|
+
before do
|
|
5
|
+
@dataset = Sequel.mock.dataset.from(:test).extension(:sequel_4_dataset_methods)
|
|
6
|
+
@d1 = @dataset.where(:x => 1)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should add a WHERE filter if none exists" do
|
|
10
|
+
@dataset.and(:a => 1).sql.must_equal 'SELECT * FROM test WHERE (a = 1)'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should add an expression to the where clause" do
|
|
14
|
+
@d1.and(:y => 2).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (y = 2))'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should accept placeholder literal string filters" do
|
|
18
|
+
@d1.and(Sequel.lit('y > ?', 2)).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (y > 2))'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should accept expression filters" do
|
|
22
|
+
@d1.and(Sequel.expr(:yy) > 3).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (yy > 3))'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should accept string filters with placeholders" do
|
|
26
|
+
@d1.extension(:auto_literal_strings).and('y > ?', 2).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (y > 2))'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should accept blocks passed to filter" do
|
|
30
|
+
@d1.and{yy > 3}.sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (yy > 3))'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should correctly add parens to give predictable results" do
|
|
34
|
+
@d1.or(:y => 2).and(:z => 3).sql.must_equal 'SELECT * FROM test WHERE (((x = 1) OR (y = 2)) AND (z = 3))'
|
|
35
|
+
@d1.and(:y => 2).or(:z => 3).sql.must_equal 'SELECT * FROM test WHERE (((x = 1) AND (y = 2)) OR (z = 3))'
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "Dataset#exclude_where" do
|
|
40
|
+
before do
|
|
41
|
+
@dataset = Sequel.mock.dataset.from(:test).extension(:sequel_4_dataset_methods)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should correctly negate the expression and add it to the where clause" do
|
|
45
|
+
@dataset.exclude_where(:region=>'Asia').sql.must_equal "SELECT * FROM test WHERE (region != 'Asia')"
|
|
46
|
+
@dataset.exclude_where(:region=>'Asia').exclude_where(:region=>'NA').sql.must_equal "SELECT * FROM test WHERE ((region != 'Asia') AND (region != 'NA'))"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "should affect the where clause even if having clause is already used" do
|
|
50
|
+
@dataset.group_and_count(:name).having{count > 2}.exclude_where(:region=>'Asia').sql.
|
|
51
|
+
must_equal "SELECT name, count(*) AS count FROM test WHERE (region != 'Asia') GROUP BY name HAVING (count > 2)"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe "Dataset#interval" do
|
|
56
|
+
before do
|
|
57
|
+
@db = Sequel.mock(:fetch=>{:v => 1234}).extension(:sequel_4_dataset_methods)
|
|
58
|
+
@ds = @db[:test].freeze
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "should generate the correct SQL statement" do
|
|
62
|
+
5.times do
|
|
63
|
+
@ds.interval(:stamp)
|
|
64
|
+
@db.sqls.must_equal ["SELECT (max(stamp) - min(stamp)) AS interval FROM test LIMIT 1"]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
@ds.filter(Sequel.expr(:price) > 100).interval(:stamp)
|
|
68
|
+
@db.sqls.must_equal ["SELECT (max(stamp) - min(stamp)) AS interval FROM test WHERE (price > 100) LIMIT 1"]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should use a subselect for the same conditions as count" do
|
|
72
|
+
ds = @ds.order(:stamp).limit(5)
|
|
73
|
+
5.times do
|
|
74
|
+
ds.interval(:stamp).must_equal 1234
|
|
75
|
+
@db.sqls.must_equal ['SELECT (max(stamp) - min(stamp)) AS interval FROM (SELECT * FROM test ORDER BY stamp LIMIT 5) AS t1 LIMIT 1']
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should accept virtual row blocks" do
|
|
80
|
+
5.times do
|
|
81
|
+
@ds.interval{a(b)}
|
|
82
|
+
@db.sqls.must_equal ["SELECT (max(a(b)) - min(a(b))) AS interval FROM test LIMIT 1"]
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe "Dataset#range" do
|
|
88
|
+
before do
|
|
89
|
+
@db = Sequel.mock(:fetch=>{:v1 => 1, :v2 => 10}).extension(:sequel_4_dataset_methods)
|
|
90
|
+
@ds = @db[:test].freeze
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "should generate a correct SQL statement" do
|
|
94
|
+
5.times do
|
|
95
|
+
@ds.range(:stamp)
|
|
96
|
+
@db.sqls.must_equal ["SELECT min(stamp) AS v1, max(stamp) AS v2 FROM test LIMIT 1"]
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
@ds.filter(Sequel.expr(:price) > 100).range(:stamp)
|
|
100
|
+
@db.sqls.must_equal ["SELECT min(stamp) AS v1, max(stamp) AS v2 FROM test WHERE (price > 100) LIMIT 1"]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "should return a range object" do
|
|
104
|
+
5.times do
|
|
105
|
+
@ds.range(:tryme).must_equal(1..10)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "should use a subselect for the same conditions as count" do
|
|
110
|
+
@ds.order(:stamp).limit(5).range(:stamp).must_equal(1..10)
|
|
111
|
+
@db.sqls.must_equal ['SELECT min(stamp) AS v1, max(stamp) AS v2 FROM (SELECT * FROM test ORDER BY stamp LIMIT 5) AS t1 LIMIT 1']
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "should accept virtual row blocks" do
|
|
115
|
+
5.times do
|
|
116
|
+
@ds.range{a(b)}
|
|
117
|
+
@db.sqls.must_equal ["SELECT min(a(b)) AS v1, max(a(b)) AS v2 FROM test LIMIT 1"]
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
@@ -59,7 +59,7 @@ describe "Serialization plugin" do
|
|
|
59
59
|
DB.sqls.map{|s| s.sub("...\n", '')}.must_equal ["INSERT INTO items (abc) VALUES ('--- 1\n')", "INSERT INTO items (abc) VALUES ('--- hello\n')"]
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
deprecated "serialized_columns should be the columns serialized" do
|
|
63
63
|
@c.plugin :serialization, :yaml, :abc
|
|
64
64
|
@c.serialized_columns.must_equal [:abc]
|
|
65
65
|
end
|