sequel 4.41.0 → 4.42.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +98 -0
- data/README.rdoc +23 -10
- data/doc/active_record.rdoc +4 -4
- data/doc/advanced_associations.rdoc +2 -2
- data/doc/association_basics.rdoc +5 -2
- data/doc/cheat_sheet.rdoc +3 -3
- data/doc/core_extensions.rdoc +2 -2
- data/doc/dataset_basics.rdoc +4 -4
- data/doc/dataset_filtering.rdoc +1 -1
- data/doc/migration.rdoc +19 -1
- data/doc/prepared_statements.rdoc +2 -2
- data/doc/release_notes/4.42.0.txt +221 -0
- data/doc/testing.rdoc +3 -1
- data/lib/sequel/adapters/ado/access.rb +0 -1
- data/lib/sequel/adapters/ado/mssql.rb +0 -1
- data/lib/sequel/adapters/do/mysql.rb +0 -1
- data/lib/sequel/adapters/do/postgres.rb +0 -1
- data/lib/sequel/adapters/do/sqlite3.rb +0 -1
- data/lib/sequel/adapters/ibmdb.rb +21 -25
- data/lib/sequel/adapters/jdbc.rb +8 -16
- data/lib/sequel/adapters/jdbc/as400.rb +0 -1
- data/lib/sequel/adapters/jdbc/cubrid.rb +0 -1
- data/lib/sequel/adapters/jdbc/db2.rb +0 -1
- data/lib/sequel/adapters/jdbc/derby.rb +0 -1
- data/lib/sequel/adapters/jdbc/firebirdsql.rb +0 -1
- data/lib/sequel/adapters/jdbc/h2.rb +0 -1
- data/lib/sequel/adapters/jdbc/hsqldb.rb +0 -1
- data/lib/sequel/adapters/jdbc/informix-sqli.rb +0 -1
- data/lib/sequel/adapters/jdbc/jdbcprogress.rb +0 -1
- data/lib/sequel/adapters/jdbc/jtds.rb +0 -1
- data/lib/sequel/adapters/jdbc/mssql.rb +0 -1
- data/lib/sequel/adapters/jdbc/mysql.rb +0 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +0 -1
- data/lib/sequel/adapters/jdbc/postgresql.rb +0 -13
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +0 -1
- data/lib/sequel/adapters/jdbc/sqlite.rb +0 -1
- data/lib/sequel/adapters/jdbc/sqlserver.rb +3 -4
- data/lib/sequel/adapters/mock.rb +54 -12
- data/lib/sequel/adapters/mysql.rb +1 -1
- data/lib/sequel/adapters/mysql2.rb +11 -17
- data/lib/sequel/adapters/odbc/mssql.rb +0 -1
- data/lib/sequel/adapters/oracle.rb +8 -20
- data/lib/sequel/adapters/postgres.rb +11 -29
- data/lib/sequel/adapters/shared/access.rb +5 -12
- data/lib/sequel/adapters/shared/cubrid.rb +4 -13
- data/lib/sequel/adapters/shared/db2.rb +4 -2
- data/lib/sequel/adapters/shared/firebird.rb +2 -4
- data/lib/sequel/adapters/shared/informix.rb +4 -2
- data/lib/sequel/adapters/shared/mssql.rb +3 -5
- data/lib/sequel/adapters/shared/mysql.rb +4 -14
- data/lib/sequel/adapters/shared/oracle.rb +1 -3
- data/lib/sequel/adapters/shared/postgres.rb +16 -38
- data/lib/sequel/adapters/shared/progress.rb +0 -2
- data/lib/sequel/adapters/shared/sqlanywhere.rb +0 -2
- data/lib/sequel/adapters/shared/sqlite.rb +20 -16
- data/lib/sequel/adapters/sqlite.rb +8 -20
- data/lib/sequel/adapters/swift/mysql.rb +0 -1
- data/lib/sequel/adapters/swift/postgres.rb +0 -1
- data/lib/sequel/adapters/swift/sqlite.rb +0 -1
- data/lib/sequel/adapters/tinytds.rb +4 -12
- data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +1 -1
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +2 -2
- data/lib/sequel/adapters/utils/mysql_prepared_statements.rb +11 -34
- data/lib/sequel/adapters/utils/stored_procedures.rb +9 -22
- data/lib/sequel/adapters/utils/unmodified_identifiers.rb +26 -0
- data/lib/sequel/ast_transformer.rb +2 -2
- data/lib/sequel/database/dataset.rb +1 -1
- data/lib/sequel/database/dataset_defaults.rb +0 -66
- data/lib/sequel/database/features.rb +6 -0
- data/lib/sequel/database/misc.rb +31 -17
- data/lib/sequel/database/query.rb +7 -4
- data/lib/sequel/database/schema_methods.rb +1 -1
- data/lib/sequel/dataset.rb +8 -8
- data/lib/sequel/dataset/actions.rb +140 -46
- data/lib/sequel/dataset/features.rb +1 -5
- data/lib/sequel/dataset/graph.rb +7 -8
- data/lib/sequel/dataset/misc.rb +127 -56
- data/lib/sequel/dataset/mutation.rb +9 -20
- data/lib/sequel/dataset/placeholder_literalizer.rb +10 -1
- data/lib/sequel/dataset/prepared_statements.rb +102 -46
- data/lib/sequel/dataset/query.rb +155 -72
- data/lib/sequel/dataset/sql.rb +26 -9
- data/lib/sequel/extensions/columns_introspection.rb +3 -1
- data/lib/sequel/extensions/core_extensions.rb +5 -5
- data/lib/sequel/extensions/core_refinements.rb +5 -5
- data/lib/sequel/extensions/duplicate_columns_handler.rb +4 -2
- data/lib/sequel/extensions/freeze_datasets.rb +69 -0
- data/lib/sequel/extensions/identifier_mangling.rb +196 -0
- data/lib/sequel/extensions/looser_typecasting.rb +11 -7
- data/lib/sequel/extensions/migration.rb +1 -1
- data/lib/sequel/extensions/null_dataset.rb +5 -2
- data/lib/sequel/extensions/pagination.rb +42 -23
- data/lib/sequel/extensions/pg_enum.rb +3 -3
- data/lib/sequel/extensions/query.rb +3 -3
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +15 -8
- data/lib/sequel/model/associations.rb +25 -8
- data/lib/sequel/model/base.rb +88 -29
- data/lib/sequel/model/dataset_module.rb +37 -0
- data/lib/sequel/plugins/association_pks.rb +4 -4
- data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
- data/lib/sequel/plugins/constraint_validations.rb +1 -2
- data/lib/sequel/plugins/csv_serializer.rb +2 -2
- data/lib/sequel/plugins/dataset_associations.rb +8 -8
- data/lib/sequel/plugins/eager_each.rb +2 -2
- data/lib/sequel/plugins/instance_filters.rb +1 -1
- data/lib/sequel/plugins/json_serializer.rb +2 -2
- data/lib/sequel/plugins/lazy_attributes.rb +1 -1
- data/lib/sequel/plugins/list.rb +4 -4
- data/lib/sequel/plugins/prepared_statements.rb +2 -4
- data/lib/sequel/plugins/prepared_statements_associations.rb +1 -3
- data/lib/sequel/plugins/prepared_statements_with_pk.rb +1 -1
- data/lib/sequel/plugins/rcte_tree.rb +13 -13
- data/lib/sequel/plugins/sharding.rb +1 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +9 -4
- data/lib/sequel/plugins/tactical_eager_loading.rb +4 -4
- data/lib/sequel/plugins/validation_class_methods.rb +1 -1
- data/lib/sequel/plugins/validation_helpers.rb +1 -1
- data/lib/sequel/plugins/xml_serializer.rb +2 -2
- data/lib/sequel/sql.rb +69 -36
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +10 -0
- data/spec/adapters/firebird_spec.rb +1 -1
- data/spec/adapters/mssql_spec.rb +4 -5
- data/spec/adapters/mysql_spec.rb +9 -9
- data/spec/adapters/postgres_spec.rb +67 -68
- data/spec/adapters/spec_helper.rb +6 -1
- data/spec/adapters/sqlite_spec.rb +29 -15
- data/spec/core/connection_pool_spec.rb +14 -14
- data/spec/core/database_spec.rb +38 -180
- data/spec/core/dataset_mutation_spec.rb +253 -0
- data/spec/core/dataset_spec.rb +394 -537
- data/spec/core/expression_filters_spec.rb +34 -32
- data/spec/core/mock_adapter_spec.rb +27 -35
- data/spec/core/placeholder_literalizer_spec.rb +2 -4
- data/spec/core/schema_generator_spec.rb +4 -4
- data/spec/core/schema_spec.rb +1 -2
- data/spec/core_extensions_spec.rb +22 -29
- data/spec/extensions/active_model_spec.rb +6 -6
- data/spec/extensions/association_dependencies_spec.rb +2 -2
- data/spec/extensions/blacklist_security_spec.rb +3 -3
- data/spec/extensions/boolean_readers_spec.rb +12 -12
- data/spec/extensions/caching_spec.rb +13 -10
- data/spec/extensions/class_table_inheritance_spec.rb +38 -43
- data/spec/extensions/column_conflicts_spec.rb +1 -3
- data/spec/extensions/columns_introspection_spec.rb +2 -3
- data/spec/extensions/composition_spec.rb +5 -3
- data/spec/extensions/constraint_validations_plugin_spec.rb +5 -5
- data/spec/extensions/constraint_validations_spec.rb +14 -8
- data/spec/extensions/core_refinements_spec.rb +22 -29
- data/spec/extensions/csv_serializer_spec.rb +7 -6
- data/spec/extensions/date_arithmetic_spec.rb +15 -15
- data/spec/extensions/defaults_setter_spec.rb +2 -2
- data/spec/extensions/delay_add_association_spec.rb +1 -1
- data/spec/extensions/dirty_spec.rb +19 -10
- data/spec/extensions/duplicate_columns_handler_spec.rb +12 -18
- data/spec/extensions/eager_each_spec.rb +12 -16
- data/spec/extensions/empty_array_consider_nulls_spec.rb +1 -1
- data/spec/extensions/eval_inspect_spec.rb +4 -3
- data/spec/extensions/force_encoding_spec.rb +12 -12
- data/spec/extensions/freeze_datasets_spec.rb +31 -0
- data/spec/extensions/graph_each_spec.rb +6 -18
- data/spec/extensions/hook_class_methods_spec.rb +7 -7
- data/spec/extensions/identifier_mangling_spec.rb +307 -0
- data/spec/extensions/instance_filters_spec.rb +5 -6
- data/spec/extensions/instance_hooks_spec.rb +12 -12
- data/spec/extensions/json_serializer_spec.rb +12 -15
- data/spec/extensions/lazy_attributes_spec.rb +4 -4
- data/spec/extensions/list_spec.rb +19 -21
- data/spec/extensions/many_through_many_spec.rb +108 -163
- data/spec/extensions/meta_def_spec.rb +7 -2
- data/spec/extensions/migration_spec.rb +10 -12
- data/spec/extensions/mssql_optimistic_locking_spec.rb +4 -3
- data/spec/extensions/named_timezones_spec.rb +4 -3
- data/spec/extensions/nested_attributes_spec.rb +2 -2
- data/spec/extensions/null_dataset_spec.rb +17 -12
- data/spec/extensions/optimistic_locking_spec.rb +4 -5
- data/spec/extensions/pagination_spec.rb +8 -10
- data/spec/extensions/pg_array_associations_spec.rb +28 -27
- data/spec/extensions/pg_array_ops_spec.rb +2 -1
- data/spec/extensions/pg_array_spec.rb +6 -2
- data/spec/extensions/pg_enum_spec.rb +5 -3
- data/spec/extensions/pg_hstore_ops_spec.rb +3 -1
- data/spec/extensions/pg_hstore_spec.rb +7 -6
- data/spec/extensions/pg_inet_ops_spec.rb +2 -1
- data/spec/extensions/pg_inet_spec.rb +2 -1
- data/spec/extensions/pg_interval_spec.rb +2 -1
- data/spec/extensions/pg_json_ops_spec.rb +2 -1
- data/spec/extensions/pg_json_spec.rb +6 -3
- data/spec/extensions/pg_loose_count_spec.rb +1 -0
- data/spec/extensions/pg_range_ops_spec.rb +3 -1
- data/spec/extensions/pg_range_spec.rb +9 -5
- data/spec/extensions/pg_row_ops_spec.rb +2 -1
- data/spec/extensions/pg_row_plugin_spec.rb +4 -6
- data/spec/extensions/pg_row_spec.rb +5 -3
- data/spec/extensions/pg_static_cache_updater_spec.rb +2 -1
- data/spec/extensions/pg_typecast_on_load_spec.rb +1 -1
- data/spec/extensions/prepared_statements_associations_spec.rb +1 -1
- data/spec/extensions/prepared_statements_spec.rb +12 -11
- data/spec/extensions/pretty_table_spec.rb +1 -1
- data/spec/extensions/query_spec.rb +8 -5
- data/spec/extensions/rcte_tree_spec.rb +39 -39
- data/spec/extensions/round_timestamps_spec.rb +2 -2
- data/spec/extensions/schema_dumper_spec.rb +3 -2
- data/spec/extensions/schema_spec.rb +2 -2
- data/spec/extensions/scissors_spec.rb +1 -2
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +30 -17
- data/spec/extensions/serialization_modification_detection_spec.rb +2 -2
- data/spec/extensions/serialization_spec.rb +15 -13
- data/spec/extensions/set_overrides_spec.rb +14 -8
- data/spec/extensions/sharding_spec.rb +9 -18
- data/spec/extensions/shared_caching_spec.rb +3 -4
- data/spec/extensions/single_table_inheritance_spec.rb +11 -11
- data/spec/extensions/skip_create_refresh_spec.rb +2 -1
- data/spec/extensions/spec_helper.rb +1 -1
- data/spec/extensions/split_values_spec.rb +2 -2
- data/spec/extensions/sql_comments_spec.rb +6 -0
- data/spec/extensions/static_cache_spec.rb +7 -9
- data/spec/extensions/string_agg_spec.rb +30 -29
- data/spec/extensions/tactical_eager_loading_spec.rb +4 -5
- data/spec/extensions/thread_local_timezones_spec.rb +2 -2
- data/spec/extensions/timestamps_spec.rb +28 -3
- data/spec/extensions/to_dot_spec.rb +1 -2
- data/spec/extensions/tree_spec.rb +33 -29
- data/spec/extensions/typecast_on_load_spec.rb +1 -1
- data/spec/extensions/unlimited_update_spec.rb +1 -0
- data/spec/extensions/update_primary_key_spec.rb +11 -7
- data/spec/extensions/update_refresh_spec.rb +1 -1
- data/spec/extensions/uuid_spec.rb +0 -1
- data/spec/extensions/validate_associated_spec.rb +1 -1
- data/spec/extensions/validation_class_methods_spec.rb +10 -10
- data/spec/extensions/validation_helpers_spec.rb +10 -10
- data/spec/extensions/xml_serializer_spec.rb +7 -3
- data/spec/integration/associations_test.rb +31 -31
- data/spec/integration/dataset_test.rb +17 -19
- data/spec/integration/eager_loader_test.rb +24 -24
- data/spec/integration/model_test.rb +6 -6
- data/spec/integration/plugin_test.rb +43 -43
- data/spec/integration/prepared_statement_test.rb +6 -6
- data/spec/integration/schema_test.rb +63 -52
- data/spec/integration/spec_helper.rb +6 -1
- data/spec/integration/transaction_test.rb +13 -13
- data/spec/model/association_reflection_spec.rb +17 -17
- data/spec/model/associations_spec.rb +101 -96
- data/spec/model/base_spec.rb +175 -49
- data/spec/model/class_dataset_methods_spec.rb +5 -9
- data/spec/model/dataset_methods_spec.rb +5 -5
- data/spec/model/eager_loading_spec.rb +209 -235
- data/spec/model/hooks_spec.rb +15 -15
- data/spec/model/model_spec.rb +28 -21
- data/spec/model/plugins_spec.rb +4 -5
- data/spec/model/record_spec.rb +59 -57
- data/spec/model/spec_helper.rb +1 -1
- data/spec/model/validations_spec.rb +6 -6
- data/spec/spec_config.rb +1 -1
- metadata +10 -2
@@ -4,7 +4,8 @@ Sequel.extension :pg_array, :pg_array_ops, :pg_hstore, :pg_hstore_ops
|
|
4
4
|
|
5
5
|
describe "Sequel::Postgres::ArrayOp" do
|
6
6
|
before do
|
7
|
-
@db = Sequel.connect('mock://postgres'
|
7
|
+
@db = Sequel.connect('mock://postgres')
|
8
|
+
@db.extend_datasets{def quote_identifiers?; false end}
|
8
9
|
@a = Sequel.pg_array_op(:a)
|
9
10
|
end
|
10
11
|
|
@@ -12,8 +12,12 @@ describe "pg_array extension" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
before do
|
15
|
-
@db = Sequel.connect('mock://postgres'
|
16
|
-
@db.extend_datasets(Module.new
|
15
|
+
@db = Sequel.connect('mock://postgres')
|
16
|
+
@db.extend_datasets(Module.new do
|
17
|
+
def supports_timestamp_timezones?; false end
|
18
|
+
def supports_timestamp_usecs?; false; end
|
19
|
+
def quote_identifiers?; false end
|
20
|
+
end)
|
17
21
|
@db.extension(:pg_array)
|
18
22
|
@m = Sequel::Postgres
|
19
23
|
@converter = @m::PG_TYPES
|
@@ -4,14 +4,16 @@ Sequel.extension :migration
|
|
4
4
|
|
5
5
|
describe "pg_enum extension" do
|
6
6
|
before do
|
7
|
-
@db = Sequel.connect('mock://postgres'
|
7
|
+
@db = Sequel.connect('mock://postgres')
|
8
|
+
@db.extend_datasets{def quote_identifiers?; false end}
|
8
9
|
@db.extend(Module.new do
|
9
10
|
def schema_parse_table(*)
|
10
11
|
[[:a, {:oid=>1}]]
|
11
12
|
end
|
13
|
+
def _metadata_dataset
|
14
|
+
super.with_fetch([[{:v=>1, :enumlabel=>'a'}, {:v=>1, :enumlabel=>'b'}, {:v=>1, :enumlabel=>'c'}], [{:typname=>'enum1', :v=>212389}]])
|
15
|
+
end
|
12
16
|
end)
|
13
|
-
@db.send(:metadata_dataset)._fetch = [[{:v=>1, :enumlabel=>'a'}, {:v=>1, :enumlabel=>'b'}, {:v=>1, :enumlabel=>'c'}],
|
14
|
-
[{:typname=>'enum1', :v=>212389}]]
|
15
17
|
@db.extension(:pg_array, :pg_enum)
|
16
18
|
@db.sqls
|
17
19
|
end
|
@@ -4,7 +4,9 @@ Sequel.extension :pg_array, :pg_array_ops, :pg_hstore, :pg_hstore_ops
|
|
4
4
|
|
5
5
|
describe "Sequel::Postgres::HStoreOp" do
|
6
6
|
before do
|
7
|
-
@
|
7
|
+
@db = Sequel.connect('mock://postgres')
|
8
|
+
@db.extend_datasets{def quote_identifiers?; false end}
|
9
|
+
@ds = @db.dataset
|
8
10
|
@h = Sequel.hstore_op(:h)
|
9
11
|
end
|
10
12
|
|
@@ -3,7 +3,8 @@ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
|
3
3
|
describe "pg_hstore extension" do
|
4
4
|
before do
|
5
5
|
Sequel.extension :pg_array, :pg_hstore
|
6
|
-
@db = Sequel.connect('mock://postgres'
|
6
|
+
@db = Sequel.connect('mock://postgres')
|
7
|
+
@db.extend_datasets{def quote_identifiers?; false end}
|
7
8
|
@m = Sequel::Postgres
|
8
9
|
@c = @m::HStore
|
9
10
|
@db.extension :pg_hstore
|
@@ -91,7 +92,7 @@ describe "pg_hstore extension" do
|
|
91
92
|
|
92
93
|
if RUBY_VERSION >= '1.9.0'
|
93
94
|
Sequel.hstore('foo'=>'bar').assoc(:foo).must_equal ['foo', 'bar']
|
94
|
-
Sequel.hstore('foo'=>'bar').assoc(:foo2).
|
95
|
+
Sequel.hstore('foo'=>'bar').assoc(:foo2).must_be_nil
|
95
96
|
end
|
96
97
|
end
|
97
98
|
|
@@ -116,23 +117,23 @@ describe "pg_hstore extension" do
|
|
116
117
|
if RUBY_VERSION >= '1.9.0'
|
117
118
|
it "should convert key lookups to string" do
|
118
119
|
Sequel.hstore('foo'=>'bar').key(:bar).must_equal 'foo'
|
119
|
-
Sequel.hstore('foo'=>'bar').key(:bar2).
|
120
|
+
Sequel.hstore('foo'=>'bar').key(:bar2).must_be_nil
|
120
121
|
end
|
121
122
|
|
122
123
|
it "should handle nil values in key lookups" do
|
123
124
|
Sequel.hstore('foo'=>'').key('').must_equal 'foo'
|
124
|
-
Sequel.hstore('foo'=>'').key(nil).
|
125
|
+
Sequel.hstore('foo'=>'').key(nil).must_be_nil
|
125
126
|
Sequel.hstore('foo'=>nil).key(nil).must_equal 'foo'
|
126
127
|
end
|
127
128
|
|
128
129
|
it "should convert rassoc lookups to string" do
|
129
130
|
Sequel.hstore('foo'=>'bar').rassoc(:bar).must_equal ['foo', 'bar']
|
130
|
-
Sequel.hstore('foo'=>'bar').rassoc(:bar2).
|
131
|
+
Sequel.hstore('foo'=>'bar').rassoc(:bar2).must_be_nil
|
131
132
|
end
|
132
133
|
|
133
134
|
it "should handle nil values in rassoc lookups" do
|
134
135
|
Sequel.hstore('foo'=>'').rassoc('').must_equal ['foo', '']
|
135
|
-
Sequel.hstore('foo'=>'').rassoc(nil).
|
136
|
+
Sequel.hstore('foo'=>'').rassoc(nil).must_be_nil
|
136
137
|
Sequel.hstore('foo'=>nil).rassoc(nil).must_equal ['foo', nil]
|
137
138
|
end
|
138
139
|
end
|
@@ -4,7 +4,8 @@ Sequel.extension :pg_inet_ops
|
|
4
4
|
|
5
5
|
describe "Sequel::Postgres::InetOp" do
|
6
6
|
before do
|
7
|
-
db = Sequel.connect('mock://postgres'
|
7
|
+
db = Sequel.connect('mock://postgres')
|
8
|
+
db.extend_datasets{def quote_identifiers?; false end}
|
8
9
|
db.extension :pg_inet
|
9
10
|
@ds = db.dataset
|
10
11
|
@h = Sequel.pg_inet_op(:h)
|
@@ -3,7 +3,8 @@ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
|
3
3
|
describe "pg_inet extension" do
|
4
4
|
ipv6_broken = (IPAddr.new('::1'); false) rescue true
|
5
5
|
before do
|
6
|
-
@db = Sequel.connect('mock://postgres'
|
6
|
+
@db = Sequel.connect('mock://postgres')
|
7
|
+
@db.extend_datasets{def quote_identifiers?; false end}
|
7
8
|
@db.extension(:pg_array, :pg_inet)
|
8
9
|
end
|
9
10
|
|
@@ -7,7 +7,8 @@ rescue LoadError => exc
|
|
7
7
|
else
|
8
8
|
describe "pg_interval extension" do
|
9
9
|
before do
|
10
|
-
@db = Sequel.connect('mock://postgres'
|
10
|
+
@db = Sequel.connect('mock://postgres')
|
11
|
+
@db.extend_datasets{def quote_identifiers?; false end}
|
11
12
|
@db.extension(:pg_array, :pg_interval)
|
12
13
|
end
|
13
14
|
|
@@ -4,7 +4,8 @@ Sequel.extension :pg_array, :pg_array_ops, :pg_json, :pg_json_ops
|
|
4
4
|
|
5
5
|
describe "Sequel::Postgres::JSONOp" do
|
6
6
|
before do
|
7
|
-
@db = Sequel.connect('mock://postgres'
|
7
|
+
@db = Sequel.connect('mock://postgres')
|
8
|
+
@db.extend_datasets{def quote_identifiers?; false end}
|
8
9
|
@j = Sequel.pg_json_op(:j)
|
9
10
|
@jb = Sequel.pg_jsonb_op(:j)
|
10
11
|
@l = proc{|o| @db.literal(o)}
|
@@ -12,7 +12,8 @@ describe "pg_json extension" do
|
|
12
12
|
@bac = m::JSONBArray
|
13
13
|
end
|
14
14
|
before do
|
15
|
-
@db = Sequel.connect('mock://postgres'
|
15
|
+
@db = Sequel.connect('mock://postgres')
|
16
|
+
@db.extend_datasets{def quote_identifiers?; false end}
|
16
17
|
@db.extension(:pg_array, :pg_json)
|
17
18
|
end
|
18
19
|
|
@@ -53,15 +54,17 @@ describe "pg_json extension" do
|
|
53
54
|
Sequel.instance_eval do
|
54
55
|
alias pj parse_json
|
55
56
|
def parse_json(v)
|
56
|
-
{'1'=>1, "'a'"=>'a', 'true'=>true, 'false'=>false, 'null'=>nil, 'o'=>Object.new}.fetch(v){pj(v)}
|
57
|
+
{'1'=>1, "'a'"=>'a', 'true'=>true, 'false'=>false, 'null'=>nil, 'o'=>Object.new, '[one]'=>[1]}.fetch(v){pj(v)}
|
57
58
|
end
|
58
59
|
end
|
59
60
|
@m.parse_json('1').must_equal 1
|
60
61
|
@m.parse_json("'a'").must_equal 'a'
|
61
62
|
@m.parse_json('true').must_equal true
|
62
63
|
@m.parse_json('false').must_equal false
|
63
|
-
@m.parse_json('null').
|
64
|
+
@m.parse_json('null').must_be_nil
|
64
65
|
proc{@m.parse_json('o')}.must_raise(Sequel::InvalidValue)
|
66
|
+
@m.db_parse_json('one').must_equal 1
|
67
|
+
@m.db_parse_jsonb('one').must_equal 1
|
65
68
|
ensure
|
66
69
|
Sequel.instance_eval do
|
67
70
|
alias parse_json pj
|
@@ -3,6 +3,7 @@ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
|
3
3
|
describe "pg_loose_count extension" do
|
4
4
|
before do
|
5
5
|
@db = Sequel.mock(:host=>'postgres', :fetch=>{:v=>1}).extension(:pg_loose_count)
|
6
|
+
@db.extend_datasets{def quote_identifiers?; false end}
|
6
7
|
end
|
7
8
|
|
8
9
|
it "should add loose_count method getting fast count for entire table using table statistics" do
|
@@ -4,7 +4,9 @@ Sequel.extension :pg_array, :pg_range, :pg_range_ops
|
|
4
4
|
|
5
5
|
describe "Sequel::Postgres::RangeOp" do
|
6
6
|
before do
|
7
|
-
|
7
|
+
db = Sequel.connect('mock://postgres')
|
8
|
+
db.extend_datasets{def quote_identifiers?; false end}
|
9
|
+
@ds = db.dataset
|
8
10
|
@h = Sequel.pg_range_op(:h)
|
9
11
|
end
|
10
12
|
|
@@ -11,9 +11,13 @@ describe "pg_range extension" do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
before do
|
14
|
-
@db = Sequel.connect('mock://postgres'
|
14
|
+
@db = Sequel.connect('mock://postgres')
|
15
15
|
@R = Sequel::Postgres::PGRange
|
16
|
-
@db.extend_datasets
|
16
|
+
@db.extend_datasets do
|
17
|
+
def supports_timestamp_timezones?; false end
|
18
|
+
def supports_timestamp_usecs?; false end
|
19
|
+
def quote_identifiers?; false end
|
20
|
+
end
|
17
21
|
@db.extension(:pg_array, :pg_range)
|
18
22
|
end
|
19
23
|
|
@@ -280,17 +284,17 @@ describe "pg_range extension" do
|
|
280
284
|
it "should have #begin return the beginning of the range" do
|
281
285
|
@r1.begin.must_equal 1
|
282
286
|
@r2.begin.must_equal 3
|
283
|
-
@r3.begin.
|
287
|
+
@r3.begin.must_be_nil
|
284
288
|
end
|
285
289
|
|
286
290
|
it "should have #end return the end of the range" do
|
287
291
|
@r1.end.must_equal 2
|
288
|
-
@r2.end.
|
292
|
+
@r2.end.must_be_nil
|
289
293
|
@r3.end.must_equal 4
|
290
294
|
end
|
291
295
|
|
292
296
|
it "should have #db_type return the range's database type" do
|
293
|
-
@r1.db_type.
|
297
|
+
@r1.db_type.must_be_nil
|
294
298
|
@r2.db_type.must_equal 'int4range'
|
295
299
|
@r3.db_type.must_equal 'int8range'
|
296
300
|
end
|
@@ -4,7 +4,8 @@ Sequel.extension :pg_array, :pg_array_ops, :pg_row, :pg_row_ops
|
|
4
4
|
|
5
5
|
describe "Sequel::Postgres::PGRowOp" do
|
6
6
|
before do
|
7
|
-
@db = Sequel.connect('mock://postgres'
|
7
|
+
@db = Sequel.connect('mock://postgres')
|
8
|
+
@db.extend_datasets{def quote_identifiers?; false end}
|
8
9
|
@a = Sequel.pg_row_op(:a)
|
9
10
|
end
|
10
11
|
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
2
2
|
|
3
3
|
describe "Sequel::Plugins::PgRow" do
|
4
|
-
before
|
5
|
-
@db = Sequel.connect('mock://postgres'
|
4
|
+
before do
|
5
|
+
@db = Sequel.connect('mock://postgres')
|
6
|
+
@db.extend_datasets{def quote_identifiers?; false end}
|
6
7
|
@db.extension(:pg_array)
|
7
8
|
@c = Class.new(Sequel::Model(@db[:address]))
|
8
9
|
@c.columns :street, :city
|
@@ -15,9 +16,6 @@ describe "Sequel::Plugins::PgRow" do
|
|
15
16
|
@c2.columns :address
|
16
17
|
@c2.db_schema[:address].merge!(:type=>:pg_row_address)
|
17
18
|
end
|
18
|
-
after do
|
19
|
-
@c.dataset.opts[:from] = [:address]
|
20
|
-
end
|
21
19
|
|
22
20
|
it "should have schema_type_class include Sequel::Model" do
|
23
21
|
@c2.new.send(:schema_type_class, :address).must_equal @c
|
@@ -42,7 +40,7 @@ describe "Sequel::Plugins::PgRow" do
|
|
42
40
|
end
|
43
41
|
|
44
42
|
it "should handle literalizing model instances when model table is aliased" do
|
45
|
-
@c.dataset
|
43
|
+
@c.dataset = @c.dataset.from(Sequel.as(:address, :a))
|
46
44
|
@db.literal(@c.load(:street=>'123 Foo St', :city=>'Bar City')).must_equal "ROW('123 Foo St', 'Bar City')::address"
|
47
45
|
end
|
48
46
|
|
@@ -2,7 +2,8 @@ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
|
2
2
|
|
3
3
|
describe "pg_row extension" do
|
4
4
|
before do
|
5
|
-
@db = Sequel.connect('mock://postgres'
|
5
|
+
@db = Sequel.connect('mock://postgres')
|
6
|
+
@db.extend_datasets{def quote_identifiers?; false end}
|
6
7
|
@db.extension(:pg_array, :pg_row)
|
7
8
|
@m = Sequel::Postgres::PGRow
|
8
9
|
@db.sqls
|
@@ -14,7 +15,7 @@ describe "pg_row extension" do
|
|
14
15
|
a.to_a.must_be_kind_of(Array)
|
15
16
|
a[0].must_equal 'a'
|
16
17
|
a.must_equal %w'a b c'
|
17
|
-
a.db_type.
|
18
|
+
a.db_type.must_be_nil
|
18
19
|
@db.literal(a).must_equal "ROW('a', 'b', 'c')"
|
19
20
|
end
|
20
21
|
|
@@ -24,7 +25,7 @@ describe "pg_row extension" do
|
|
24
25
|
as.each do |a|
|
25
26
|
a.class.must_equal(@m::ArrayRow)
|
26
27
|
a.to_a.must_be_kind_of(Array)
|
27
|
-
a.db_type.
|
28
|
+
a.db_type.must_be_nil
|
28
29
|
end
|
29
30
|
@db.literal(as).must_equal "ARRAY[ROW('a', 'b', 'c'),ROW('d', 'e', 'f')]::record[]"
|
30
31
|
end
|
@@ -136,6 +137,7 @@ describe "pg_row extension" do
|
|
136
137
|
|
137
138
|
it "should reload registered row types when reseting conversion procs" do
|
138
139
|
db = Sequel.mock(:host=>'postgres')
|
140
|
+
db.extend_datasets{def quote_identifiers?; false end}
|
139
141
|
db.extension(:pg_row)
|
140
142
|
db.conversion_procs[4] = proc{|s| s.to_i}
|
141
143
|
db.conversion_procs[5] = proc{|s| s * 2}
|
@@ -2,7 +2,8 @@ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
|
2
2
|
|
3
3
|
describe "pg_static_cache_updater extension" do
|
4
4
|
before do
|
5
|
-
@db = Sequel.
|
5
|
+
@db = Sequel.connect('mock://postgres')
|
6
|
+
@db.extend_datasets{def quote_identifiers?; false end}
|
6
7
|
def @db.listen(chan, opts={})
|
7
8
|
execute("LISTEN #{chan}")
|
8
9
|
yield(*opts[:yield])
|
@@ -24,7 +24,7 @@ describe Sequel::Model, "PgTypecastOnLoad plugin" do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should call the database conversion proc with value when automatically reloading the object on creation via insert_select" do
|
27
|
-
@c.dataset.
|
27
|
+
@c.dataset = @c.dataset.with_extend{def insert_select(h) insert(h); first end}
|
28
28
|
@c.create.values.must_equal(:id=>1, :b=>true, :y=>0)
|
29
29
|
end
|
30
30
|
|
@@ -86,7 +86,7 @@ describe "Sequel::Plugins::PreparedStatementsAssociations" do
|
|
86
86
|
|
87
87
|
it "should not run query if no objects can be associated" do
|
88
88
|
@Artist.new.albums.must_equal []
|
89
|
-
@Album.new.artist.
|
89
|
+
@Album.new.artist.must_be_nil
|
90
90
|
@db.sqls.must_equal []
|
91
91
|
end
|
92
92
|
|
@@ -49,7 +49,7 @@ describe "prepared_statements plugin" do
|
|
49
49
|
true
|
50
50
|
end
|
51
51
|
def insert_select(h)
|
52
|
-
|
52
|
+
cache_set(:_fetch, :id=>1, :name=>'foo', :i => 2)
|
53
53
|
server(:default).with_sql_first(insert_select_sql(h))
|
54
54
|
end
|
55
55
|
def insert_select_sql(*v)
|
@@ -80,7 +80,7 @@ describe "prepared_statements plugin" do
|
|
80
80
|
|
81
81
|
describe " with placeholder type specifiers" do
|
82
82
|
before do
|
83
|
-
@ds.
|
83
|
+
@ds = @ds.with_extend{def requires_placeholder_type_specifiers?; true end}
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should correctly handle without schema type" do
|
@@ -90,17 +90,18 @@ describe "prepared_statements plugin" do
|
|
90
90
|
|
91
91
|
it "should correctly handle with schema type" do
|
92
92
|
@c.db_schema[:id][:type] = :integer
|
93
|
-
ds = @c.send(:prepared_lookup)
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
93
|
+
ds = @c.send(:prepared_lookup).with_extend do
|
94
|
+
def literal_symbol_append(sql, v)
|
95
|
+
if @opts[:bind_vars] and match = /\A\$(.*)\z/.match(v.to_s)
|
96
|
+
s = match[1].split('__')[0].to_sym
|
97
|
+
if prepared_arg?(s)
|
98
|
+
literal_append(sql, prepared_arg(s))
|
99
|
+
else
|
100
|
+
sql << v.to_s
|
101
|
+
end
|
99
102
|
else
|
100
|
-
|
103
|
+
super
|
101
104
|
end
|
102
|
-
else
|
103
|
-
super
|
104
105
|
end
|
105
106
|
end
|
106
107
|
@c[1].must_equal @p
|
@@ -87,12 +87,15 @@ describe "Dataset#query" do
|
|
87
87
|
q.sql.must_equal "SELECT * FROM xyz"
|
88
88
|
end
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
90
|
+
# SEQUEL5: Remove
|
91
|
+
unless Sequel.mock.dataset.frozen?
|
92
|
+
it "should have an appropriate mutation method" do
|
93
|
+
@d.query! do
|
94
|
+
select :a, :b___mongo
|
95
|
+
from :yyy
|
96
|
+
end
|
97
|
+
@d.sql.must_equal "SELECT a, b AS mongo FROM yyy"
|
94
98
|
end
|
95
|
-
@d.sql.must_equal "SELECT a, b AS mongo FROM yyy"
|
96
99
|
end
|
97
100
|
|
98
101
|
it "should raise on non-chainable method calls" do
|
@@ -35,7 +35,7 @@ describe Sequel::Model, "rcte_tree" do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should use the correct SQL for lazy associations when recursive CTEs require column aliases" do
|
38
|
-
@c.dataset.
|
38
|
+
@c.dataset = @c.dataset.with_extend{def recursive_cte_requires_column_aliases?; true end}
|
39
39
|
@c.plugin :rcte_tree
|
40
40
|
@o.parent_dataset.sql.must_equal 'SELECT * FROM nodes WHERE (nodes.id = 1) LIMIT 1'
|
41
41
|
@o.children_dataset.sql.must_equal 'SELECT * FROM nodes WHERE (nodes.parent_id = 2)'
|
@@ -44,13 +44,13 @@ describe Sequel::Model, "rcte_tree" do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should use the correct SQL for eager loading when recursive CTEs require column aliases" do
|
47
|
-
@c.dataset.
|
47
|
+
@c.dataset = @c.dataset.with_extend{def recursive_cte_requires_column_aliases?; true end}
|
48
48
|
@c.plugin :rcte_tree
|
49
|
-
@
|
49
|
+
@c.dataset = @c.dataset.with_fetch([[{:id=>1, :name=>'A', :parent_id=>3}]])
|
50
50
|
@c.eager(:ancestors).all
|
51
51
|
@db.sqls.must_equal ["SELECT * FROM nodes", "WITH t(x_root_x, id, name, parent_id, i, pi) AS (SELECT id AS x_root_x, nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes WHERE (id IN (3)) UNION ALL SELECT t.x_root_x, nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes INNER JOIN t ON (t.parent_id = nodes.id)) SELECT * FROM t AS nodes"]
|
52
52
|
|
53
|
-
@
|
53
|
+
@c.dataset = @c.dataset.with_fetch([[{:id=>1, :name=>'A', :parent_id=>3}]])
|
54
54
|
@c.eager(:descendants).all
|
55
55
|
@db.sqls.must_equal ["SELECT * FROM nodes", "WITH t(x_root_x, id, name, parent_id, i, pi) AS (SELECT parent_id AS x_root_x, nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes WHERE (parent_id IN (1)) UNION ALL SELECT t.x_root_x, nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes INNER JOIN t ON (t.id = nodes.parent_id)) SELECT * FROM t AS nodes"]
|
56
56
|
end
|
@@ -73,27 +73,27 @@ describe Sequel::Model, "rcte_tree" do
|
|
73
73
|
|
74
74
|
it "should add all parent associations when lazily loading ancestors" do
|
75
75
|
@c.plugin :rcte_tree
|
76
|
-
@
|
76
|
+
@c.dataset = @c.dataset.with_fetch([[{:id=>1, :name=>'A', :parent_id=>3}, {:id=>4, :name=>'B', :parent_id=>nil}, {:id=>3, :name=>'?', :parent_id=>4}]])
|
77
77
|
@o.ancestors.must_equal [@c.load(:id=>1, :name=>'A', :parent_id=>3), @c.load(:id=>4, :name=>'B', :parent_id=>nil), @c.load(:id=>3, :name=>'?', :parent_id=>4)]
|
78
78
|
@o.associations[:parent].must_equal @c.load(:id=>1, :name=>'A', :parent_id=>3)
|
79
79
|
@o.associations[:parent].associations[:parent].must_equal @c.load(:id=>3, :name=>'?', :parent_id=>4)
|
80
80
|
@o.associations[:parent].associations[:parent].associations[:parent].must_equal @c.load(:id=>4, :name=>'B', :parent_id=>nil)
|
81
|
-
@o.associations[:parent].associations[:parent].associations[:parent].associations.fetch(:parent, 1).
|
81
|
+
@o.associations[:parent].associations[:parent].associations[:parent].associations.fetch(:parent, 1).must_be_nil
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should add all parent associations when lazily loading ancestors and giving options" do
|
85
85
|
@c.plugin :rcte_tree, :primary_key=>:i, :key=>:pi, :ancestors=>{:name=>:as}, :parent=>{:name=>:p}
|
86
|
-
@
|
86
|
+
@c.dataset = @c.dataset.with_fetch([[{:i=>4, :name=>'A', :pi=>5}, {:i=>6, :name=>'B', :pi=>nil}, {:i=>5, :name=>'?', :pi=>6}]])
|
87
87
|
@o.as.must_equal [@c.load(:i=>4, :name=>'A', :pi=>5), @c.load(:i=>6, :name=>'B', :pi=>nil), @c.load(:i=>5, :name=>'?', :pi=>6)]
|
88
88
|
@o.associations[:p].must_equal @c.load(:i=>4, :name=>'A', :pi=>5)
|
89
89
|
@o.associations[:p].associations[:p].must_equal @c.load(:i=>5, :name=>'?', :pi=>6)
|
90
90
|
@o.associations[:p].associations[:p].associations[:p].must_equal @c.load(:i=>6, :name=>'B', :pi=>nil)
|
91
|
-
@o.associations[:p].associations[:p].associations[:p].associations.fetch(:p, 1).
|
91
|
+
@o.associations[:p].associations[:p].associations[:p].associations.fetch(:p, 1).must_be_nil
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should add all parent and children associations when lazily loading descendants" do
|
95
95
|
@c.plugin :rcte_tree
|
96
|
-
@
|
96
|
+
@c.dataset = @c.dataset.with_fetch([[{:id=>3, :name=>'??', :parent_id=>1}, {:id=>1, :name=>'A', :parent_id=>2}, {:id=>4, :name=>'B', :parent_id=>2}, {:id=>5, :name=>'?', :parent_id=>3}]])
|
97
97
|
@o.descendants.must_equal [@c.load(:id=>3, :name=>'??', :parent_id=>1), @c.load(:id=>1, :name=>'A', :parent_id=>2), @c.load(:id=>4, :name=>'B', :parent_id=>2), @c.load(:id=>5, :name=>'?', :parent_id=>3)]
|
98
98
|
@o.associations[:children].must_equal [@c.load(:id=>1, :name=>'A', :parent_id=>2), @c.load(:id=>4, :name=>'B', :parent_id=>2)]
|
99
99
|
@o.associations[:children].map{|c1| c1.associations[:children]}.must_equal [[@c.load(:id=>3, :name=>'??', :parent_id=>1)], []]
|
@@ -106,7 +106,7 @@ describe Sequel::Model, "rcte_tree" do
|
|
106
106
|
|
107
107
|
it "should add all children associations when lazily loading descendants and giving options" do
|
108
108
|
@c.plugin :rcte_tree, :primary_key=>:i, :key=>:pi, :children=>{:name=>:cs}, :descendants=>{:name=>:ds}
|
109
|
-
@
|
109
|
+
@c.dataset = @c.dataset.with_fetch([[{:i=>7, :name=>'??', :pi=>5}, {:i=>5, :name=>'A', :pi=>3}, {:i=>6, :name=>'B', :pi=>3}, {:i=>8, :name=>'?', :pi=>7}]])
|
110
110
|
@o.ds.must_equal [@c.load(:i=>7, :name=>'??', :pi=>5), @c.load(:i=>5, :name=>'A', :pi=>3), @c.load(:i=>6, :name=>'B', :pi=>3), @c.load(:i=>8, :name=>'?', :pi=>7)]
|
111
111
|
@o.associations[:cs].must_equal [@c.load(:i=>5, :name=>'A', :pi=>3), @c.load(:i=>6, :name=>'B', :pi=>3)]
|
112
112
|
@o.associations[:cs].map{|c1| c1.associations[:cs]}.must_equal [[@c.load(:i=>7, :name=>'??', :pi=>5)], []]
|
@@ -116,10 +116,10 @@ describe Sequel::Model, "rcte_tree" do
|
|
116
116
|
|
117
117
|
it "should eagerly load ancestors" do
|
118
118
|
@c.plugin :rcte_tree
|
119
|
-
@ds.
|
119
|
+
@ds = @c.dataset = @c.dataset.with_fetch([[{:id=>2, :parent_id=>1, :name=>'AA'}, {:id=>6, :parent_id=>2, :name=>'C'}, {:id=>7, :parent_id=>1, :name=>'D'}, {:id=>9, :parent_id=>nil, :name=>'E'}],
|
120
120
|
[{:id=>2, :name=>'AA', :parent_id=>1, :x_root_x=>2},
|
121
121
|
{:id=>1, :name=>'00', :parent_id=>8, :x_root_x=>1}, {:id=>1, :name=>'00', :parent_id=>8, :x_root_x=>2},
|
122
|
-
{:id=>8, :name=>'?', :parent_id=>nil, :x_root_x=>2}, {:id=>8, :name=>'?', :parent_id=>nil, :x_root_x=>1}]]
|
122
|
+
{:id=>8, :name=>'?', :parent_id=>nil, :x_root_x=>2}, {:id=>8, :name=>'?', :parent_id=>nil, :x_root_x=>1}]])
|
123
123
|
os = @ds.eager(:ancestors).all
|
124
124
|
sqls = @db.sqls
|
125
125
|
sqls.first.must_equal "SELECT * FROM nodes"
|
@@ -138,10 +138,10 @@ describe Sequel::Model, "rcte_tree" do
|
|
138
138
|
|
139
139
|
it "should eagerly load ancestors when giving options" do
|
140
140
|
@c.plugin :rcte_tree, :primary_key=>:i, :key=>:pi, :key_alias=>:kal, :cte_name=>:cte, :ancestors=>{:name=>:as}, :parent=>{:name=>:p}
|
141
|
-
@ds.
|
141
|
+
@ds = @c.dataset = @c.dataset.with_fetch([[{:i=>2, :pi=>1, :name=>'AA'}, {:i=>6, :pi=>2, :name=>'C'}, {:i=>7, :pi=>1, :name=>'D'}, {:i=>9, :pi=>nil, :name=>'E'}],
|
142
142
|
[{:i=>2, :name=>'AA', :pi=>1, :kal=>2},
|
143
143
|
{:i=>1, :name=>'00', :pi=>8, :kal=>1}, {:i=>1, :name=>'00', :pi=>8, :kal=>2},
|
144
|
-
{:i=>8, :name=>'?', :pi=>nil, :kal=>2}, {:i=>8, :name=>'?', :pi=>nil, :kal=>1}]]
|
144
|
+
{:i=>8, :name=>'?', :pi=>nil, :kal=>2}, {:i=>8, :name=>'?', :pi=>nil, :kal=>1}]])
|
145
145
|
os = @ds.eager(:as).all
|
146
146
|
sqls = @db.sqls
|
147
147
|
sqls.first.must_equal "SELECT * FROM nodes"
|
@@ -159,10 +159,10 @@ describe Sequel::Model, "rcte_tree" do
|
|
159
159
|
|
160
160
|
it "should eagerly load ancestors respecting association option :conditions" do
|
161
161
|
@c.plugin :rcte_tree, :conditions => {:i => 1}
|
162
|
-
@ds.
|
162
|
+
@ds = @c.dataset = @c.dataset.with_fetch([[{:id=>2, :parent_id=>1, :name=>'AA'}, {:id=>6, :parent_id=>2, :name=>'C'}, {:id=>7, :parent_id=>1, :name=>'D'}, {:id=>9, :parent_id=>nil, :name=>'E'}],
|
163
163
|
[{:id=>2, :name=>'AA', :parent_id=>1, :x_root_x=>2},
|
164
164
|
{:id=>1, :name=>'00', :parent_id=>8, :x_root_x=>1}, {:id=>1, :name=>'00', :parent_id=>8, :x_root_x=>2},
|
165
|
-
{:id=>8, :name=>'?', :parent_id=>nil, :x_root_x=>2}, {:id=>8, :name=>'?', :parent_id=>nil, :x_root_x=>1}]]
|
165
|
+
{:id=>8, :name=>'?', :parent_id=>nil, :x_root_x=>2}, {:id=>8, :name=>'?', :parent_id=>nil, :x_root_x=>1}]])
|
166
166
|
@ds.eager(:ancestors).all
|
167
167
|
sqls = @db.sqls
|
168
168
|
sqls.first.must_equal "SELECT * FROM nodes"
|
@@ -171,10 +171,10 @@ describe Sequel::Model, "rcte_tree" do
|
|
171
171
|
|
172
172
|
it "should eagerly load descendants" do
|
173
173
|
@c.plugin :rcte_tree
|
174
|
-
@ds.
|
174
|
+
@ds = @c.dataset = @c.dataset.with_fetch([[{:id=>2, :parent_id=>1, :name=>'AA'}, {:id=>6, :parent_id=>2, :name=>'C'}, {:id=>7, :parent_id=>1, :name=>'D'}],
|
175
175
|
[{:id=>6, :parent_id=>2, :name=>'C', :x_root_x=>2}, {:id=>9, :parent_id=>2, :name=>'E', :x_root_x=>2},
|
176
176
|
{:id=>3, :name=>'00', :parent_id=>6, :x_root_x=>6}, {:id=>3, :name=>'00', :parent_id=>6, :x_root_x=>2},
|
177
|
-
{:id=>4, :name=>'?', :parent_id=>7, :x_root_x=>7}, {:id=>5, :name=>'?', :parent_id=>4, :x_root_x=>7}]]
|
177
|
+
{:id=>4, :name=>'?', :parent_id=>7, :x_root_x=>7}, {:id=>5, :name=>'?', :parent_id=>4, :x_root_x=>7}]])
|
178
178
|
os = @ds.eager(:descendants).all
|
179
179
|
sqls = @db.sqls
|
180
180
|
sqls.first.must_equal "SELECT * FROM nodes"
|
@@ -193,10 +193,10 @@ describe Sequel::Model, "rcte_tree" do
|
|
193
193
|
|
194
194
|
it "should eagerly load descendants when giving options" do
|
195
195
|
@c.plugin :rcte_tree, :primary_key=>:i, :key=>:pi, :key_alias=>:kal, :cte_name=>:cte, :children=>{:name=>:cs}, :descendants=>{:name=>:ds}
|
196
|
-
@ds.
|
196
|
+
@ds = @c.dataset = @c.dataset.with_fetch([[{:i=>2, :pi=>1, :name=>'AA'}, {:i=>6, :pi=>2, :name=>'C'}, {:i=>7, :pi=>1, :name=>'D'}],
|
197
197
|
[{:i=>6, :pi=>2, :name=>'C', :kal=>2}, {:i=>9, :pi=>2, :name=>'E', :kal=>2},
|
198
198
|
{:i=>3, :name=>'00', :pi=>6, :kal=>6}, {:i=>3, :name=>'00', :pi=>6, :kal=>2},
|
199
|
-
{:i=>4, :name=>'?', :pi=>7, :kal=>7}, {:i=>5, :name=>'?', :pi=>4, :kal=>7}]]
|
199
|
+
{:i=>4, :name=>'?', :pi=>7, :kal=>7}, {:i=>5, :name=>'?', :pi=>4, :kal=>7}]])
|
200
200
|
os = @ds.eager(:ds).all
|
201
201
|
sqls = @db.sqls
|
202
202
|
sqls.first.must_equal "SELECT * FROM nodes"
|
@@ -213,10 +213,10 @@ describe Sequel::Model, "rcte_tree" do
|
|
213
213
|
|
214
214
|
it "should eagerly load descendants to a given level" do
|
215
215
|
@c.plugin :rcte_tree
|
216
|
-
@ds.
|
216
|
+
@ds = @c.dataset = @c.dataset.with_fetch([[{:id=>2, :parent_id=>1, :name=>'AA'}, {:id=>6, :parent_id=>2, :name=>'C'}, {:id=>7, :parent_id=>1, :name=>'D'}],
|
217
217
|
[{:id=>6, :parent_id=>2, :name=>'C', :x_root_x=>2, :x_level_x=>0}, {:id=>9, :parent_id=>2, :name=>'E', :x_root_x=>2, :x_level_x=>0},
|
218
218
|
{:id=>3, :name=>'00', :parent_id=>6, :x_root_x=>6, :x_level_x=>0}, {:id=>3, :name=>'00', :parent_id=>6, :x_root_x=>2, :x_level_x=>1},
|
219
|
-
{:id=>4, :name=>'?', :parent_id=>7, :x_root_x=>7, :x_level_x=>0}, {:id=>5, :name=>'?', :parent_id=>4, :x_root_x=>7, :x_level_x=>1}]]
|
219
|
+
{:id=>4, :name=>'?', :parent_id=>7, :x_root_x=>7, :x_level_x=>0}, {:id=>5, :name=>'?', :parent_id=>4, :x_root_x=>7, :x_level_x=>1}]])
|
220
220
|
os = @ds.eager(:descendants=>2).all
|
221
221
|
sqls = @db.sqls
|
222
222
|
sqls.first.must_equal "SELECT * FROM nodes"
|
@@ -233,10 +233,10 @@ describe Sequel::Model, "rcte_tree" do
|
|
233
233
|
|
234
234
|
it "should eagerly load descendants to a given level when giving options" do
|
235
235
|
@c.plugin :rcte_tree, :primary_key=>:i, :key=>:pi, :key_alias=>:kal, :level_alias=>:lal, :cte_name=>:cte, :children=>{:name=>:cs}, :descendants=>{:name=>:ds}
|
236
|
-
@ds.
|
236
|
+
@ds = @c.dataset = @c.dataset.with_fetch([[{:i=>2, :pi=>1, :name=>'AA'}, {:i=>6, :pi=>2, :name=>'C'}, {:i=>7, :pi=>1, :name=>'D'}],
|
237
237
|
[{:i=>6, :pi=>2, :name=>'C', :kal=>2, :lal=>0}, {:i=>9, :pi=>2, :name=>'E', :kal=>2, :lal=>0},
|
238
238
|
{:i=>3, :name=>'00', :pi=>6, :kal=>6, :lal=>0}, {:i=>3, :name=>'00', :pi=>6, :kal=>2, :lal=>1},
|
239
|
-
{:i=>4, :name=>'?', :pi=>7, :kal=>7, :lal=>0}, {:i=>5, :name=>'?', :pi=>4, :kal=>7, :lal=>1}]]
|
239
|
+
{:i=>4, :name=>'?', :pi=>7, :kal=>7, :lal=>0}, {:i=>5, :name=>'?', :pi=>4, :kal=>7, :lal=>1}]])
|
240
240
|
os = @ds.eager(:ds=>2).all
|
241
241
|
sqls = @db.sqls
|
242
242
|
sqls.first.must_equal "SELECT * FROM nodes"
|
@@ -253,10 +253,10 @@ describe Sequel::Model, "rcte_tree" do
|
|
253
253
|
|
254
254
|
it "should eagerly load descendants respecting association option :conditions" do
|
255
255
|
@c.plugin :rcte_tree, :conditions => {:i => 1}
|
256
|
-
@ds.
|
256
|
+
@ds = @c.dataset = @c.dataset.with_fetch([[{:id=>2, :parent_id=>1, :name=>'AA'}, {:id=>6, :parent_id=>2, :name=>'C'}, {:id=>7, :parent_id=>1, :name=>'D'}],
|
257
257
|
[{:id=>6, :parent_id=>2, :name=>'C', :x_root_x=>2}, {:id=>9, :parent_id=>2, :name=>'E', :x_root_x=>2},
|
258
258
|
{:id=>3, :name=>'00', :parent_id=>6, :x_root_x=>6}, {:id=>3, :name=>'00', :parent_id=>6, :x_root_x=>2},
|
259
|
-
{:id=>4, :name=>'?', :parent_id=>7, :x_root_x=>7}, {:id=>5, :name=>'?', :parent_id=>4, :x_root_x=>7}]]
|
259
|
+
{:id=>4, :name=>'?', :parent_id=>7, :x_root_x=>7}, {:id=>5, :name=>'?', :parent_id=>4, :x_root_x=>7}]])
|
260
260
|
@ds.eager(:descendants).all
|
261
261
|
sqls = @db.sqls
|
262
262
|
sqls.first.must_equal "SELECT * FROM nodes"
|
@@ -290,37 +290,37 @@ describe Sequel::Model, "rcte_tree with composite keys" do
|
|
290
290
|
end
|
291
291
|
|
292
292
|
it "should use the correct SQL for lazy associations when recursive CTEs require column aliases" do
|
293
|
-
@c.dataset.
|
293
|
+
@c.dataset = @c.dataset.with_extend{def recursive_cte_requires_column_aliases?; true end}
|
294
294
|
@c.plugin :rcte_tree, :key=>[:parent_id, :parent_id2]
|
295
295
|
@o.ancestors_dataset.sql.must_equal 'WITH t(id, id2, name, parent_id, parent_id2, i, pi) AS (SELECT id, id2, name, parent_id, parent_id2, i, pi FROM nodes WHERE ((id = 1) AND (id2 = 6)) UNION ALL SELECT nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes INNER JOIN t ON ((t.parent_id = nodes.id) AND (t.parent_id2 = nodes.id2))) SELECT * FROM t AS nodes'
|
296
296
|
@o.descendants_dataset.sql.must_equal 'WITH t(id, id2, name, parent_id, parent_id2, i, pi) AS (SELECT id, id2, name, parent_id, parent_id2, i, pi FROM nodes WHERE ((parent_id = 2) AND (parent_id2 = 5)) UNION ALL SELECT nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes INNER JOIN t ON ((t.id = nodes.parent_id) AND (t.id2 = nodes.parent_id2))) SELECT * FROM t AS nodes'
|
297
297
|
end
|
298
298
|
|
299
299
|
it "should use the correct SQL for eager loading when recursive CTEs require column aliases" do
|
300
|
-
@c.dataset.
|
300
|
+
@c.dataset = @c.dataset.with_extend{def recursive_cte_requires_column_aliases?; true end}
|
301
301
|
@c.plugin :rcte_tree, :key=>[:parent_id, :parent_id2]
|
302
|
-
@
|
302
|
+
@c.dataset = @c.dataset.with_fetch([[{:id=>1, :id2=>2, :name=>'A', :parent_id=>3, :parent_id2=>4}]])
|
303
303
|
@c.eager(:ancestors).all
|
304
304
|
@db.sqls.must_equal ["SELECT * FROM nodes", "WITH t(x_root_x_0, x_root_x_1, id, id2, name, parent_id, parent_id2, i, pi) AS (SELECT id AS x_root_x_0, id2 AS x_root_x_1, nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes WHERE ((id, id2) IN ((3, 4))) UNION ALL SELECT t.x_root_x_0, t.x_root_x_1, nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes INNER JOIN t ON ((t.parent_id = nodes.id) AND (t.parent_id2 = nodes.id2))) SELECT * FROM t AS nodes"]
|
305
305
|
|
306
|
-
@
|
306
|
+
@c.dataset = @c.dataset.with_fetch([[{:id=>1, :id2=>2, :name=>'A', :parent_id=>3, :parent_id2=>4}]])
|
307
307
|
@c.eager(:descendants).all
|
308
308
|
@db.sqls.must_equal ["SELECT * FROM nodes", "WITH t(x_root_x_0, x_root_x_1, id, id2, name, parent_id, parent_id2, i, pi) AS (SELECT parent_id AS x_root_x_0, parent_id2 AS x_root_x_1, nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes WHERE ((parent_id, parent_id2) IN ((1, 2))) UNION ALL SELECT t.x_root_x_0, t.x_root_x_1, nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes INNER JOIN t ON ((t.id = nodes.parent_id) AND (t.id2 = nodes.parent_id2))) SELECT * FROM t AS nodes"]
|
309
309
|
end
|
310
310
|
|
311
311
|
it "should add all parent associations when lazily loading ancestors" do
|
312
312
|
@c.plugin :rcte_tree, :key=>[:parent_id, :parent_id2]
|
313
|
-
@
|
313
|
+
@c.dataset = @c.dataset.with_fetch([[{:id=>1, :id2=>6, :name=>'A', :parent_id=>3, :parent_id2=>5}, {:id=>4, :id2=>8, :name=>'B', :parent_id=>nil, :parent_id2=>nil}, {:id=>3, :id2=>5, :name=>'?', :parent_id=>4, :parent_id2=>8}]])
|
314
314
|
@o.ancestors.must_equal [@c.load(:id=>1, :id2=>6, :name=>'A', :parent_id=>3, :parent_id2=>5), @c.load(:id=>4, :id2=>8, :name=>'B', :parent_id=>nil, :parent_id2=>nil), @c.load(:id=>3, :id2=>5, :name=>'?', :parent_id=>4, :parent_id2=>8)]
|
315
315
|
@o.associations[:parent].must_equal @c.load(:id=>1, :id2=>6, :name=>'A', :parent_id=>3, :parent_id2=>5)
|
316
316
|
@o.associations[:parent].associations[:parent].must_equal @c.load(:id=>3, :id2=>5, :name=>'?', :parent_id=>4, :parent_id2=>8)
|
317
317
|
@o.associations[:parent].associations[:parent].associations[:parent].must_equal @c.load(:id=>4, :id2=>8, :name=>'B', :parent_id=>nil, :parent_id2=>nil)
|
318
|
-
@o.associations[:parent].associations[:parent].associations[:parent].associations.fetch(:parent, 1).
|
318
|
+
@o.associations[:parent].associations[:parent].associations[:parent].associations.fetch(:parent, 1).must_be_nil
|
319
319
|
end
|
320
320
|
|
321
321
|
it "should add all children associations when lazily loading descendants" do
|
322
322
|
@c.plugin :rcte_tree, :key=>[:parent_id, :parent_id2]
|
323
|
-
@
|
323
|
+
@c.dataset = @c.dataset.with_fetch([[{:id=>3, :id2=>4, :name=>'??', :parent_id=>1, :parent_id2=>2}, {:id=>1, :id2=>2, :name=>'A', :parent_id=>2, :parent_id2=>5}, {:id=>4, :id2=>5, :name=>'B', :parent_id=>2, :parent_id2=>5}, {:id=>5, :id2=>7, :name=>'?', :parent_id=>3, :parent_id2=>4}]])
|
324
324
|
@o.descendants.must_equal [@c.load(:id=>3, :id2=>4, :name=>'??', :parent_id=>1, :parent_id2=>2), @c.load(:id=>1, :id2=>2, :name=>'A', :parent_id=>2, :parent_id2=>5), @c.load(:id=>4, :id2=>5, :name=>'B', :parent_id=>2, :parent_id2=>5), @c.load(:id=>5, :id2=>7, :name=>'?', :parent_id=>3, :parent_id2=>4)]
|
325
325
|
@o.associations[:children].must_equal [@c.load(:id=>1, :id2=>2, :name=>'A', :parent_id=>2, :parent_id2=>5), @c.load(:id=>4, :id2=>5, :name=>'B', :parent_id=>2, :parent_id2=>5)]
|
326
326
|
@o.associations[:children].map{|c1| c1.associations[:children]}.must_equal [[@c.load(:id=>3, :id2=>4, :name=>'??', :parent_id=>1, :parent_id2=>2)], []]
|
@@ -330,10 +330,10 @@ describe Sequel::Model, "rcte_tree with composite keys" do
|
|
330
330
|
|
331
331
|
it "should eagerly load ancestors" do
|
332
332
|
@c.plugin :rcte_tree, :key=>[:parent_id, :parent_id2]
|
333
|
-
@ds.
|
333
|
+
@ds = @c.dataset = @c.dataset.with_fetch([[{:id=>2, :id2=>3, :parent_id=>1, :parent_id2=>2, :name=>'AA'}, {:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'}, {:id=>7, :id2=>8, :parent_id=>1, :parent_id2=>2, :name=>'D'}, {:id=>9, :id2=>10, :parent_id=>nil, :parent_id2=>nil, :name=>'E'}],
|
334
334
|
[{:id=>2, :id2=>3, :name=>'AA', :parent_id=>1, :parent_id2=>2, :x_root_x_0=>2, :x_root_x_1=>3},
|
335
335
|
{:id=>1, :id2=>2, :name=>'00', :parent_id=>8, :parent_id2=>9, :x_root_x_0=>1, :x_root_x_1=>2}, {:id=>1, :id2=>2, :name=>'00', :parent_id=>8, :parent_id2=>9, :x_root_x_0=>2, :x_root_x_1=>3},
|
336
|
-
{:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil, :x_root_x_0=>2, :x_root_x_1=>3}, {:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil, :x_root_x_0=>1, :x_root_x_1=>2}]]
|
336
|
+
{:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil, :x_root_x_0=>2, :x_root_x_1=>3}, {:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil, :x_root_x_0=>1, :x_root_x_1=>2}]])
|
337
337
|
os = @ds.eager(:ancestors).all
|
338
338
|
sqls = @db.sqls
|
339
339
|
sqls.first.must_equal "SELECT * FROM nodes"
|
@@ -352,10 +352,10 @@ describe Sequel::Model, "rcte_tree with composite keys" do
|
|
352
352
|
|
353
353
|
it "should eagerly load descendants" do
|
354
354
|
@c.plugin :rcte_tree, :key=>[:parent_id, :parent_id2]
|
355
|
-
@ds.
|
355
|
+
@ds = @c.dataset = @c.dataset.with_fetch([[{:id=>2, :id2=>3, :parent_id=>1, :parent_id2=>2, :name=>'AA'}, {:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'}, {:id=>7, :id2=>8, :parent_id=>1, :parent_id2=>2, :name=>'D'}],
|
356
356
|
[{:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C', :x_root_x_0=>2, :x_root_x_1=>3}, {:id=>9, :id2=>10, :parent_id=>2, :parent_id2=>3, :name=>'E', :x_root_x_0=>2, :x_root_x_1=>3},
|
357
357
|
{:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7, :x_root_x_0=>6, :x_root_x_1=>7}, {:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7, :x_root_x_0=>2, :x_root_x_1=>3},
|
358
|
-
{:id=>4, :id2=>5, :name=>'?', :parent_id=>7, :parent_id2=>8, :x_root_x_0=>7, :x_root_x_1=>8}, {:id=>5, :id2=>6, :name=>'?', :parent_id=>4, :parent_id2=>5, :x_root_x_0=>7, :x_root_x_1=>8}]]
|
358
|
+
{:id=>4, :id2=>5, :name=>'?', :parent_id=>7, :parent_id2=>8, :x_root_x_0=>7, :x_root_x_1=>8}, {:id=>5, :id2=>6, :name=>'?', :parent_id=>4, :parent_id2=>5, :x_root_x_0=>7, :x_root_x_1=>8}]])
|
359
359
|
os = @ds.eager(:descendants).all
|
360
360
|
sqls = @db.sqls
|
361
361
|
sqls.first.must_equal "SELECT * FROM nodes"
|
@@ -372,10 +372,10 @@ describe Sequel::Model, "rcte_tree with composite keys" do
|
|
372
372
|
|
373
373
|
it "should eagerly load descendants to a given level" do
|
374
374
|
@c.plugin :rcte_tree, :key=>[:parent_id, :parent_id2]
|
375
|
-
@ds.
|
375
|
+
@ds = @c.dataset = @c.dataset.with_fetch([[{:id=>2, :id2=>3, :parent_id=>1, :parent_id2=>2, :name=>'AA'}, {:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'}, {:id=>7, :id2=>8, :parent_id=>1, :parent_id2=>2, :name=>'D'}],
|
376
376
|
[{:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C', :x_root_x_0=>2, :x_root_x_1=>3, :x_level_x=>0}, {:id=>9, :id2=>10, :parent_id=>2, :parent_id2=>3, :name=>'E', :x_root_x_0=>2, :x_root_x_1=>3, :x_level_x=>0},
|
377
377
|
{:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7, :x_root_x_0=>6, :x_root_x_1=>7, :x_level_x=>0}, {:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7, :x_root_x_0=>2, :x_root_x_1=>3, :x_level_x=>1},
|
378
|
-
{:id=>4, :id2=>5, :name=>'?', :parent_id=>7, :parent_id2=>8, :x_root_x_0=>7, :x_root_x_1=>8, :x_level_x=>0}, {:id=>5, :id2=>6, :name=>'?', :parent_id=>4, :parent_id2=>5, :x_root_x_0=>7, :x_root_x_1=>8, :x_level_x=>1}]]
|
378
|
+
{:id=>4, :id2=>5, :name=>'?', :parent_id=>7, :parent_id2=>8, :x_root_x_0=>7, :x_root_x_1=>8, :x_level_x=>0}, {:id=>5, :id2=>6, :name=>'?', :parent_id=>4, :parent_id2=>5, :x_root_x_0=>7, :x_root_x_1=>8, :x_level_x=>1}]])
|
379
379
|
os = @ds.eager(:descendants=>2).all
|
380
380
|
sqls = @db.sqls
|
381
381
|
sqls.first.must_equal "SELECT * FROM nodes"
|