sequel 5.20.0 → 5.49.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +398 -1922
- data/MIT-LICENSE +1 -1
- data/README.rdoc +7 -7
- data/doc/advanced_associations.rdoc +4 -4
- data/doc/association_basics.rdoc +80 -16
- data/doc/cheat_sheet.rdoc +6 -5
- data/doc/code_order.rdoc +10 -12
- data/doc/dataset_filtering.rdoc +17 -2
- data/doc/fork_safety.rdoc +84 -0
- data/doc/migration.rdoc +11 -5
- data/doc/model_dataset_method_design.rdoc +1 -1
- data/doc/model_plugins.rdoc +1 -1
- data/doc/opening_databases.rdoc +10 -2
- data/doc/postgresql.rdoc +82 -3
- data/doc/querying.rdoc +4 -4
- data/doc/release_notes/5.21.0.txt +87 -0
- data/doc/release_notes/5.22.0.txt +48 -0
- data/doc/release_notes/5.23.0.txt +56 -0
- data/doc/release_notes/5.24.0.txt +56 -0
- data/doc/release_notes/5.25.0.txt +32 -0
- data/doc/release_notes/5.26.0.txt +35 -0
- data/doc/release_notes/5.27.0.txt +21 -0
- data/doc/release_notes/5.28.0.txt +16 -0
- data/doc/release_notes/5.29.0.txt +22 -0
- data/doc/release_notes/5.30.0.txt +20 -0
- data/doc/release_notes/5.31.0.txt +148 -0
- data/doc/release_notes/5.32.0.txt +46 -0
- data/doc/release_notes/5.33.0.txt +24 -0
- data/doc/release_notes/5.34.0.txt +40 -0
- data/doc/release_notes/5.35.0.txt +56 -0
- data/doc/release_notes/5.36.0.txt +60 -0
- data/doc/release_notes/5.37.0.txt +30 -0
- data/doc/release_notes/5.38.0.txt +28 -0
- data/doc/release_notes/5.39.0.txt +19 -0
- data/doc/release_notes/5.40.0.txt +40 -0
- data/doc/release_notes/5.41.0.txt +25 -0
- data/doc/release_notes/5.42.0.txt +136 -0
- data/doc/release_notes/5.43.0.txt +98 -0
- data/doc/release_notes/5.44.0.txt +32 -0
- data/doc/release_notes/5.45.0.txt +34 -0
- data/doc/release_notes/5.46.0.txt +87 -0
- data/doc/release_notes/5.47.0.txt +59 -0
- data/doc/release_notes/5.48.0.txt +14 -0
- data/doc/release_notes/5.49.0.txt +59 -0
- data/doc/sharding.rdoc +2 -0
- data/doc/sql.rdoc +13 -1
- data/doc/testing.rdoc +20 -7
- data/doc/transactions.rdoc +0 -8
- data/doc/validations.rdoc +1 -1
- data/doc/virtual_rows.rdoc +1 -1
- data/lib/sequel/adapters/ado/access.rb +1 -1
- data/lib/sequel/adapters/ado.rb +43 -35
- data/lib/sequel/adapters/ibmdb.rb +2 -2
- data/lib/sequel/adapters/jdbc/mysql.rb +6 -6
- data/lib/sequel/adapters/jdbc/postgresql.rb +11 -17
- data/lib/sequel/adapters/jdbc/sqlite.rb +29 -0
- data/lib/sequel/adapters/jdbc.rb +24 -6
- data/lib/sequel/adapters/mysql.rb +1 -1
- data/lib/sequel/adapters/mysql2.rb +2 -3
- data/lib/sequel/adapters/odbc.rb +8 -6
- data/lib/sequel/adapters/oracle.rb +5 -4
- data/lib/sequel/adapters/postgres.rb +15 -9
- data/lib/sequel/adapters/shared/access.rb +6 -6
- data/lib/sequel/adapters/shared/mssql.rb +66 -21
- data/lib/sequel/adapters/shared/mysql.rb +27 -10
- data/lib/sequel/adapters/shared/oracle.rb +29 -23
- data/lib/sequel/adapters/shared/postgres.rb +271 -32
- data/lib/sequel/adapters/shared/sqlanywhere.rb +9 -9
- data/lib/sequel/adapters/shared/sqlite.rb +161 -19
- data/lib/sequel/adapters/sqlanywhere.rb +1 -1
- data/lib/sequel/adapters/sqlite.rb +1 -1
- data/lib/sequel/adapters/tinytds.rb +15 -2
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +4 -1
- data/lib/sequel/ast_transformer.rb +6 -0
- data/lib/sequel/connection_pool/sharded_single.rb +4 -1
- data/lib/sequel/connection_pool/sharded_threaded.rb +12 -12
- data/lib/sequel/connection_pool/single.rb +1 -1
- data/lib/sequel/connection_pool/threaded.rb +2 -2
- data/lib/sequel/core.rb +333 -319
- data/lib/sequel/database/connecting.rb +3 -4
- data/lib/sequel/database/logging.rb +7 -1
- data/lib/sequel/database/misc.rb +31 -12
- data/lib/sequel/database/query.rb +3 -1
- data/lib/sequel/database/schema_generator.rb +53 -51
- data/lib/sequel/database/schema_methods.rb +38 -23
- data/lib/sequel/database/transactions.rb +17 -18
- data/lib/sequel/dataset/actions.rb +14 -9
- data/lib/sequel/dataset/features.rb +16 -0
- data/lib/sequel/dataset/misc.rb +2 -2
- data/lib/sequel/dataset/placeholder_literalizer.rb +3 -7
- data/lib/sequel/dataset/prepared_statements.rb +2 -0
- data/lib/sequel/dataset/query.rb +26 -9
- data/lib/sequel/dataset/sql.rb +76 -25
- data/lib/sequel/dataset.rb +4 -2
- data/lib/sequel/deprecated.rb +3 -1
- data/lib/sequel/exceptions.rb +2 -0
- data/lib/sequel/extensions/_pretty_table.rb +1 -2
- data/lib/sequel/extensions/any_not_empty.rb +45 -0
- data/lib/sequel/extensions/async_thread_pool.rb +438 -0
- data/lib/sequel/extensions/blank.rb +8 -0
- data/lib/sequel/extensions/columns_introspection.rb +1 -2
- data/lib/sequel/extensions/connection_expiration.rb +2 -2
- data/lib/sequel/extensions/connection_validator.rb +2 -2
- data/lib/sequel/extensions/core_refinements.rb +2 -0
- data/lib/sequel/extensions/date_arithmetic.rb +36 -24
- data/lib/sequel/extensions/duplicate_columns_handler.rb +3 -1
- data/lib/sequel/extensions/eval_inspect.rb +2 -0
- data/lib/sequel/extensions/exclude_or_null.rb +68 -0
- data/lib/sequel/extensions/fiber_concurrency.rb +24 -0
- data/lib/sequel/extensions/index_caching.rb +9 -7
- data/lib/sequel/extensions/inflector.rb +9 -1
- data/lib/sequel/extensions/integer64.rb +2 -0
- data/lib/sequel/extensions/migration.rb +11 -3
- data/lib/sequel/extensions/named_timezones.rb +56 -8
- data/lib/sequel/extensions/pagination.rb +1 -1
- data/lib/sequel/extensions/pg_array.rb +5 -0
- data/lib/sequel/extensions/pg_array_ops.rb +14 -6
- data/lib/sequel/extensions/pg_enum.rb +11 -3
- data/lib/sequel/extensions/pg_extended_date_support.rb +2 -2
- data/lib/sequel/extensions/pg_hstore.rb +6 -0
- data/lib/sequel/extensions/pg_hstore_ops.rb +54 -2
- data/lib/sequel/extensions/pg_inet.rb +15 -5
- data/lib/sequel/extensions/pg_interval.rb +36 -8
- data/lib/sequel/extensions/pg_json.rb +387 -123
- data/lib/sequel/extensions/pg_json_ops.rb +238 -0
- data/lib/sequel/extensions/pg_loose_count.rb +3 -1
- data/lib/sequel/extensions/pg_range.rb +17 -9
- data/lib/sequel/extensions/pg_range_ops.rb +2 -0
- data/lib/sequel/extensions/pg_row.rb +4 -2
- data/lib/sequel/extensions/pg_row_ops.rb +24 -0
- data/lib/sequel/extensions/pg_timestamptz.rb +2 -0
- data/lib/sequel/extensions/query.rb +3 -0
- data/lib/sequel/extensions/run_transaction_hooks.rb +72 -0
- data/lib/sequel/extensions/s.rb +2 -0
- data/lib/sequel/extensions/schema_dumper.rb +24 -7
- data/lib/sequel/extensions/server_block.rb +18 -7
- data/lib/sequel/extensions/sql_comments.rb +2 -2
- data/lib/sequel/extensions/string_agg.rb +1 -1
- data/lib/sequel/extensions/symbol_aref_refinement.rb +2 -0
- data/lib/sequel/extensions/symbol_as_refinement.rb +2 -0
- data/lib/sequel/extensions/to_dot.rb +9 -3
- data/lib/sequel/model/associations.rb +356 -117
- data/lib/sequel/model/base.rb +107 -68
- data/lib/sequel/model/errors.rb +10 -1
- data/lib/sequel/model/inflections.rb +1 -1
- data/lib/sequel/model/plugins.rb +9 -3
- data/lib/sequel/model.rb +3 -1
- data/lib/sequel/plugins/association_lazy_eager_option.rb +66 -0
- data/lib/sequel/plugins/association_multi_add_remove.rb +85 -0
- data/lib/sequel/plugins/association_pks.rb +60 -18
- data/lib/sequel/plugins/association_proxies.rb +8 -2
- data/lib/sequel/plugins/async_thread_pool.rb +39 -0
- data/lib/sequel/plugins/auto_validations.rb +39 -5
- data/lib/sequel/plugins/auto_validations_constraint_validations_presence_message.rb +68 -0
- data/lib/sequel/plugins/blacklist_security.rb +1 -2
- data/lib/sequel/plugins/boolean_subsets.rb +4 -1
- data/lib/sequel/plugins/caching.rb +3 -0
- data/lib/sequel/plugins/class_table_inheritance.rb +33 -28
- data/lib/sequel/plugins/column_encryption.rb +728 -0
- data/lib/sequel/plugins/composition.rb +7 -2
- data/lib/sequel/plugins/concurrent_eager_loading.rb +174 -0
- data/lib/sequel/plugins/constraint_validations.rb +2 -1
- data/lib/sequel/plugins/csv_serializer.rb +28 -9
- data/lib/sequel/plugins/dataset_associations.rb +4 -1
- data/lib/sequel/plugins/dirty.rb +60 -22
- data/lib/sequel/plugins/empty_failure_backtraces.rb +38 -0
- data/lib/sequel/plugins/forbid_lazy_load.rb +216 -0
- data/lib/sequel/plugins/insert_conflict.rb +72 -0
- data/lib/sequel/plugins/instance_specific_default.rb +113 -0
- data/lib/sequel/plugins/json_serializer.rb +57 -35
- data/lib/sequel/plugins/lazy_attributes.rb +1 -1
- data/lib/sequel/plugins/many_through_many.rb +108 -9
- data/lib/sequel/plugins/nested_attributes.rb +15 -3
- data/lib/sequel/plugins/pg_array_associations.rb +58 -41
- data/lib/sequel/plugins/pg_auto_constraint_validations.rb +91 -30
- data/lib/sequel/plugins/prepared_statements.rb +15 -12
- data/lib/sequel/plugins/prepared_statements_safe.rb +1 -3
- data/lib/sequel/plugins/rcte_tree.rb +43 -35
- data/lib/sequel/plugins/serialization.rb +8 -3
- data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
- data/lib/sequel/plugins/sharding.rb +11 -5
- data/lib/sequel/plugins/single_table_inheritance.rb +22 -15
- data/lib/sequel/plugins/skip_saving_columns.rb +108 -0
- data/lib/sequel/plugins/static_cache.rb +9 -4
- data/lib/sequel/plugins/static_cache_cache.rb +53 -0
- data/lib/sequel/plugins/string_stripper.rb +1 -1
- data/lib/sequel/plugins/subclasses.rb +2 -0
- data/lib/sequel/plugins/throw_failures.rb +1 -1
- data/lib/sequel/plugins/timestamps.rb +1 -1
- data/lib/sequel/plugins/tree.rb +9 -4
- data/lib/sequel/plugins/typecast_on_load.rb +3 -2
- data/lib/sequel/plugins/unused_associations.rb +521 -0
- data/lib/sequel/plugins/update_or_create.rb +1 -1
- data/lib/sequel/plugins/validation_class_methods.rb +5 -1
- data/lib/sequel/plugins/validation_helpers.rb +18 -11
- data/lib/sequel/plugins/xml_serializer.rb +1 -1
- data/lib/sequel/sql.rb +20 -5
- data/lib/sequel/timezones.rb +63 -17
- data/lib/sequel/version.rb +1 -1
- metadata +113 -381
- data/Rakefile +0 -151
- data/doc/release_notes/4.0.0.txt +0 -262
- data/doc/release_notes/4.1.0.txt +0 -85
- data/doc/release_notes/4.10.0.txt +0 -226
- data/doc/release_notes/4.11.0.txt +0 -147
- data/doc/release_notes/4.12.0.txt +0 -105
- data/doc/release_notes/4.13.0.txt +0 -169
- data/doc/release_notes/4.14.0.txt +0 -68
- data/doc/release_notes/4.15.0.txt +0 -56
- data/doc/release_notes/4.16.0.txt +0 -36
- data/doc/release_notes/4.17.0.txt +0 -38
- data/doc/release_notes/4.18.0.txt +0 -36
- data/doc/release_notes/4.19.0.txt +0 -45
- data/doc/release_notes/4.2.0.txt +0 -129
- data/doc/release_notes/4.20.0.txt +0 -79
- data/doc/release_notes/4.21.0.txt +0 -94
- data/doc/release_notes/4.22.0.txt +0 -72
- data/doc/release_notes/4.23.0.txt +0 -65
- data/doc/release_notes/4.24.0.txt +0 -99
- data/doc/release_notes/4.25.0.txt +0 -181
- data/doc/release_notes/4.26.0.txt +0 -44
- data/doc/release_notes/4.27.0.txt +0 -78
- data/doc/release_notes/4.28.0.txt +0 -57
- data/doc/release_notes/4.29.0.txt +0 -41
- data/doc/release_notes/4.3.0.txt +0 -40
- data/doc/release_notes/4.30.0.txt +0 -37
- data/doc/release_notes/4.31.0.txt +0 -57
- data/doc/release_notes/4.32.0.txt +0 -132
- data/doc/release_notes/4.33.0.txt +0 -88
- data/doc/release_notes/4.34.0.txt +0 -86
- data/doc/release_notes/4.35.0.txt +0 -130
- data/doc/release_notes/4.36.0.txt +0 -116
- data/doc/release_notes/4.37.0.txt +0 -50
- data/doc/release_notes/4.38.0.txt +0 -67
- data/doc/release_notes/4.39.0.txt +0 -127
- data/doc/release_notes/4.4.0.txt +0 -92
- data/doc/release_notes/4.40.0.txt +0 -179
- data/doc/release_notes/4.41.0.txt +0 -77
- data/doc/release_notes/4.42.0.txt +0 -221
- data/doc/release_notes/4.43.0.txt +0 -87
- data/doc/release_notes/4.44.0.txt +0 -125
- data/doc/release_notes/4.45.0.txt +0 -370
- data/doc/release_notes/4.46.0.txt +0 -404
- data/doc/release_notes/4.47.0.txt +0 -56
- data/doc/release_notes/4.48.0.txt +0 -293
- data/doc/release_notes/4.49.0.txt +0 -222
- data/doc/release_notes/4.5.0.txt +0 -34
- data/doc/release_notes/4.6.0.txt +0 -30
- data/doc/release_notes/4.7.0.txt +0 -103
- data/doc/release_notes/4.8.0.txt +0 -175
- data/doc/release_notes/4.9.0.txt +0 -190
- data/spec/adapter_spec.rb +0 -4
- data/spec/adapters/db2_spec.rb +0 -170
- data/spec/adapters/mssql_spec.rb +0 -804
- data/spec/adapters/mysql_spec.rb +0 -1065
- data/spec/adapters/oracle_spec.rb +0 -371
- data/spec/adapters/postgres_spec.rb +0 -4125
- data/spec/adapters/spec_helper.rb +0 -44
- data/spec/adapters/sqlanywhere_spec.rb +0 -97
- data/spec/adapters/sqlite_spec.rb +0 -652
- data/spec/bin_spec.rb +0 -278
- data/spec/core/connection_pool_spec.rb +0 -1250
- data/spec/core/database_spec.rb +0 -2865
- data/spec/core/dataset_spec.rb +0 -5515
- data/spec/core/deprecated_spec.rb +0 -70
- data/spec/core/expression_filters_spec.rb +0 -1455
- data/spec/core/mock_adapter_spec.rb +0 -722
- data/spec/core/object_graph_spec.rb +0 -336
- data/spec/core/placeholder_literalizer_spec.rb +0 -166
- data/spec/core/schema_generator_spec.rb +0 -214
- data/spec/core/schema_spec.rb +0 -1826
- data/spec/core/spec_helper.rb +0 -24
- data/spec/core/version_spec.rb +0 -14
- data/spec/core_extensions_spec.rb +0 -763
- data/spec/core_model_spec.rb +0 -2
- data/spec/core_spec.rb +0 -1
- data/spec/deprecation_helper.rb +0 -30
- data/spec/extensions/accessed_columns_spec.rb +0 -51
- data/spec/extensions/active_model_spec.rb +0 -99
- data/spec/extensions/after_initialize_spec.rb +0 -28
- data/spec/extensions/arbitrary_servers_spec.rb +0 -109
- data/spec/extensions/association_dependencies_spec.rb +0 -125
- data/spec/extensions/association_pks_spec.rb +0 -423
- data/spec/extensions/association_proxies_spec.rb +0 -100
- data/spec/extensions/auto_literal_strings_spec.rb +0 -205
- data/spec/extensions/auto_validations_spec.rb +0 -229
- data/spec/extensions/blacklist_security_spec.rb +0 -95
- data/spec/extensions/blank_spec.rb +0 -69
- data/spec/extensions/boolean_readers_spec.rb +0 -93
- data/spec/extensions/boolean_subsets_spec.rb +0 -47
- data/spec/extensions/caching_spec.rb +0 -273
- data/spec/extensions/caller_logging_spec.rb +0 -52
- data/spec/extensions/class_table_inheritance_spec.rb +0 -750
- data/spec/extensions/column_conflicts_spec.rb +0 -75
- data/spec/extensions/column_select_spec.rb +0 -129
- data/spec/extensions/columns_introspection_spec.rb +0 -90
- data/spec/extensions/columns_updated_spec.rb +0 -35
- data/spec/extensions/composition_spec.rb +0 -248
- data/spec/extensions/connection_expiration_spec.rb +0 -151
- data/spec/extensions/connection_validator_spec.rb +0 -144
- data/spec/extensions/constant_sql_override_spec.rb +0 -24
- data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
- data/spec/extensions/constraint_validations_spec.rb +0 -439
- data/spec/extensions/core_refinements_spec.rb +0 -528
- data/spec/extensions/csv_serializer_spec.rb +0 -183
- data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
- data/spec/extensions/dataset_associations_spec.rb +0 -365
- data/spec/extensions/dataset_source_alias_spec.rb +0 -51
- data/spec/extensions/date_arithmetic_spec.rb +0 -181
- data/spec/extensions/datetime_parse_to_time_spec.rb +0 -169
- data/spec/extensions/def_dataset_method_spec.rb +0 -100
- data/spec/extensions/defaults_setter_spec.rb +0 -150
- data/spec/extensions/delay_add_association_spec.rb +0 -73
- data/spec/extensions/dirty_spec.rb +0 -189
- data/spec/extensions/duplicate_columns_handler_spec.rb +0 -104
- data/spec/extensions/eager_each_spec.rb +0 -62
- data/spec/extensions/eager_graph_eager_spec.rb +0 -100
- data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
- data/spec/extensions/error_splitter_spec.rb +0 -18
- data/spec/extensions/error_sql_spec.rb +0 -20
- data/spec/extensions/escaped_like_spec.rb +0 -40
- data/spec/extensions/eval_inspect_spec.rb +0 -81
- data/spec/extensions/finder_spec.rb +0 -260
- data/spec/extensions/force_encoding_spec.rb +0 -126
- data/spec/extensions/freeze_datasets_spec.rb +0 -31
- data/spec/extensions/graph_each_spec.rb +0 -113
- data/spec/extensions/hook_class_methods_spec.rb +0 -402
- data/spec/extensions/identifier_mangling_spec.rb +0 -201
- data/spec/extensions/implicit_subquery_spec.rb +0 -58
- data/spec/extensions/index_caching_spec.rb +0 -66
- data/spec/extensions/inflector_spec.rb +0 -183
- data/spec/extensions/input_transformer_spec.rb +0 -69
- data/spec/extensions/insert_returning_select_spec.rb +0 -72
- data/spec/extensions/instance_filters_spec.rb +0 -79
- data/spec/extensions/instance_hooks_spec.rb +0 -246
- data/spec/extensions/integer64_spec.rb +0 -22
- data/spec/extensions/inverted_subsets_spec.rb +0 -33
- data/spec/extensions/json_serializer_spec.rb +0 -336
- data/spec/extensions/lazy_attributes_spec.rb +0 -183
- data/spec/extensions/list_spec.rb +0 -291
- data/spec/extensions/looser_typecasting_spec.rb +0 -43
- data/spec/extensions/many_through_many_spec.rb +0 -2177
- data/spec/extensions/migration_spec.rb +0 -864
- data/spec/extensions/modification_detection_spec.rb +0 -93
- data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -92
- data/spec/extensions/named_timezones_spec.rb +0 -111
- data/spec/extensions/nested_attributes_spec.rb +0 -767
- data/spec/extensions/null_dataset_spec.rb +0 -85
- data/spec/extensions/optimistic_locking_spec.rb +0 -127
- data/spec/extensions/pagination_spec.rb +0 -116
- data/spec/extensions/pg_array_associations_spec.rb +0 -802
- data/spec/extensions/pg_array_ops_spec.rb +0 -144
- data/spec/extensions/pg_array_spec.rb +0 -398
- data/spec/extensions/pg_auto_constraint_validations_spec.rb +0 -172
- data/spec/extensions/pg_enum_spec.rb +0 -118
- data/spec/extensions/pg_extended_date_support_spec.rb +0 -126
- data/spec/extensions/pg_hstore_ops_spec.rb +0 -238
- data/spec/extensions/pg_hstore_spec.rb +0 -219
- data/spec/extensions/pg_inet_ops_spec.rb +0 -102
- data/spec/extensions/pg_inet_spec.rb +0 -72
- data/spec/extensions/pg_interval_spec.rb +0 -103
- data/spec/extensions/pg_json_ops_spec.rb +0 -289
- data/spec/extensions/pg_json_spec.rb +0 -262
- data/spec/extensions/pg_loose_count_spec.rb +0 -23
- data/spec/extensions/pg_range_ops_spec.rb +0 -60
- data/spec/extensions/pg_range_spec.rb +0 -519
- data/spec/extensions/pg_row_ops_spec.rb +0 -61
- data/spec/extensions/pg_row_plugin_spec.rb +0 -60
- data/spec/extensions/pg_row_spec.rb +0 -363
- data/spec/extensions/pg_static_cache_updater_spec.rb +0 -93
- data/spec/extensions/pg_timestamptz_spec.rb +0 -17
- data/spec/extensions/prepared_statements_safe_spec.rb +0 -66
- data/spec/extensions/prepared_statements_spec.rb +0 -177
- data/spec/extensions/pretty_table_spec.rb +0 -123
- data/spec/extensions/query_spec.rb +0 -94
- data/spec/extensions/rcte_tree_spec.rb +0 -381
- data/spec/extensions/round_timestamps_spec.rb +0 -39
- data/spec/extensions/s_spec.rb +0 -60
- data/spec/extensions/schema_caching_spec.rb +0 -64
- data/spec/extensions/schema_dumper_spec.rb +0 -870
- data/spec/extensions/select_remove_spec.rb +0 -38
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +0 -121
- data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
- data/spec/extensions/serialization_spec.rb +0 -365
- data/spec/extensions/server_block_spec.rb +0 -97
- data/spec/extensions/server_logging_spec.rb +0 -45
- data/spec/extensions/sharding_spec.rb +0 -189
- data/spec/extensions/shared_caching_spec.rb +0 -151
- data/spec/extensions/single_table_inheritance_spec.rb +0 -347
- data/spec/extensions/singular_table_names_spec.rb +0 -22
- data/spec/extensions/skip_create_refresh_spec.rb +0 -18
- data/spec/extensions/spec_helper.rb +0 -63
- data/spec/extensions/split_array_nil_spec.rb +0 -24
- data/spec/extensions/split_values_spec.rb +0 -57
- data/spec/extensions/sql_comments_spec.rb +0 -33
- data/spec/extensions/sql_expr_spec.rb +0 -59
- data/spec/extensions/static_cache_spec.rb +0 -471
- data/spec/extensions/string_agg_spec.rb +0 -90
- data/spec/extensions/string_date_time_spec.rb +0 -95
- data/spec/extensions/string_stripper_spec.rb +0 -68
- data/spec/extensions/subclasses_spec.rb +0 -79
- data/spec/extensions/subset_conditions_spec.rb +0 -38
- data/spec/extensions/symbol_aref_refinement_spec.rb +0 -28
- data/spec/extensions/symbol_as_refinement_spec.rb +0 -21
- data/spec/extensions/synchronize_sql_spec.rb +0 -124
- data/spec/extensions/table_select_spec.rb +0 -83
- data/spec/extensions/tactical_eager_loading_spec.rb +0 -402
- data/spec/extensions/thread_local_timezones_spec.rb +0 -67
- data/spec/extensions/throw_failures_spec.rb +0 -74
- data/spec/extensions/timestamps_spec.rb +0 -209
- data/spec/extensions/to_dot_spec.rb +0 -153
- data/spec/extensions/touch_spec.rb +0 -226
- data/spec/extensions/tree_spec.rb +0 -334
- data/spec/extensions/typecast_on_load_spec.rb +0 -86
- data/spec/extensions/unlimited_update_spec.rb +0 -21
- data/spec/extensions/update_or_create_spec.rb +0 -83
- data/spec/extensions/update_primary_key_spec.rb +0 -105
- data/spec/extensions/update_refresh_spec.rb +0 -59
- data/spec/extensions/uuid_spec.rb +0 -101
- data/spec/extensions/validate_associated_spec.rb +0 -52
- data/spec/extensions/validation_class_methods_spec.rb +0 -1040
- data/spec/extensions/validation_contexts_spec.rb +0 -31
- data/spec/extensions/validation_helpers_spec.rb +0 -525
- data/spec/extensions/whitelist_security_spec.rb +0 -157
- data/spec/extensions/xml_serializer_spec.rb +0 -213
- data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
- data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
- data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
- data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
- data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/double_migration/001_create_sessions.rb +0 -9
- data/spec/files/double_migration/002_create_nodes.rb +0 -19
- data/spec/files/double_migration/003_3_create_users.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
- data/spec/files/empty_migration/001_create_sessions.rb +0 -9
- data/spec/files/empty_migration/002_create_nodes.rb +0 -0
- data/spec/files/empty_migration/003_3_create_users.rb +0 -4
- data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
- data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
- data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
- data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
- data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/reversible_migrations/001_reversible.rb +0 -5
- data/spec/files/reversible_migrations/002_reversible.rb +0 -5
- data/spec/files/reversible_migrations/003_reversible.rb +0 -5
- data/spec/files/reversible_migrations/004_reversible.rb +0 -5
- data/spec/files/reversible_migrations/005_reversible.rb +0 -10
- data/spec/files/reversible_migrations/006_reversible.rb +0 -10
- data/spec/files/reversible_migrations/007_reversible.rb +0 -10
- data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
- data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
- data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
- data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
- data/spec/guards_helper.rb +0 -59
- data/spec/integration/associations_test.rb +0 -2597
- data/spec/integration/database_test.rb +0 -113
- data/spec/integration/dataset_test.rb +0 -1981
- data/spec/integration/eager_loader_test.rb +0 -687
- data/spec/integration/migrator_test.rb +0 -262
- data/spec/integration/model_test.rb +0 -203
- data/spec/integration/plugin_test.rb +0 -2396
- data/spec/integration/prepared_statement_test.rb +0 -405
- data/spec/integration/schema_test.rb +0 -889
- data/spec/integration/spec_helper.rb +0 -65
- data/spec/integration/timezone_test.rb +0 -86
- data/spec/integration/transaction_test.rb +0 -603
- data/spec/integration/type_test.rb +0 -127
- data/spec/model/association_reflection_spec.rb +0 -803
- data/spec/model/associations_spec.rb +0 -4738
- data/spec/model/base_spec.rb +0 -875
- data/spec/model/class_dataset_methods_spec.rb +0 -146
- data/spec/model/dataset_methods_spec.rb +0 -198
- data/spec/model/eager_loading_spec.rb +0 -2377
- data/spec/model/hooks_spec.rb +0 -370
- data/spec/model/inflector_spec.rb +0 -26
- data/spec/model/model_spec.rb +0 -956
- data/spec/model/plugins_spec.rb +0 -429
- data/spec/model/record_spec.rb +0 -2118
- data/spec/model/spec_helper.rb +0 -46
- data/spec/model/validations_spec.rb +0 -220
- data/spec/model_no_assoc_spec.rb +0 -1
- data/spec/model_spec.rb +0 -1
- data/spec/plugin_spec.rb +0 -1
- data/spec/sequel_coverage.rb +0 -15
- data/spec/sequel_warning.rb +0 -4
- data/spec/spec_config.rb +0 -12
@@ -36,7 +36,7 @@ module Sequel
|
|
36
36
|
c = adapter_class(scheme)
|
37
37
|
uri_options = c.send(:uri_to_options, uri)
|
38
38
|
uri.query.split('&').map{|s| s.split('=')}.each{|k,v| uri_options[k.to_sym] = v if k && !k.empty?} unless uri.query.to_s.strip.empty?
|
39
|
-
uri_options.to_a.each{|k,v| uri_options[k] =
|
39
|
+
uri_options.to_a.each{|k,v| uri_options[k] = URI::DEFAULT_PARSER.unescape(v) if v.is_a?(String)}
|
40
40
|
opts = uri_options.merge(opts).merge!(:orig_opts=>opts.dup, :uri=>conn_string, :adapter=>scheme)
|
41
41
|
end
|
42
42
|
when Hash
|
@@ -55,12 +55,11 @@ module Sequel
|
|
55
55
|
|
56
56
|
begin
|
57
57
|
db = c.new(opts)
|
58
|
-
|
59
|
-
if block_given?
|
58
|
+
if defined?(yield)
|
60
59
|
return yield(db)
|
61
60
|
end
|
62
61
|
ensure
|
63
|
-
if
|
62
|
+
if defined?(yield)
|
64
63
|
db.disconnect if db
|
65
64
|
Sequel.synchronize{::Sequel::DATABASES.delete(db)}
|
66
65
|
end
|
@@ -35,7 +35,7 @@ module Sequel
|
|
35
35
|
# Yield to the block, logging any errors at error level to all loggers,
|
36
36
|
# and all other queries with the duration at warn or info level.
|
37
37
|
def log_connection_yield(sql, conn, args=nil)
|
38
|
-
return yield if
|
38
|
+
return yield if skip_logging?
|
39
39
|
sql = "#{connection_info(conn) if conn && log_connection_info}#{sql}#{"; #{args.inspect}" if args}"
|
40
40
|
timer = Sequel.start_timer
|
41
41
|
|
@@ -58,6 +58,12 @@ module Sequel
|
|
58
58
|
|
59
59
|
private
|
60
60
|
|
61
|
+
# Determine if logging should be skipped. Defaults to true if no loggers
|
62
|
+
# have been specified.
|
63
|
+
def skip_logging?
|
64
|
+
@loggers.empty?
|
65
|
+
end
|
66
|
+
|
61
67
|
# String including information about the connection, for use when logging
|
62
68
|
# connection info.
|
63
69
|
def connection_info(conn)
|
data/lib/sequel/database/misc.rb
CHANGED
@@ -153,19 +153,24 @@ module Sequel
|
|
153
153
|
reset_default_dataset
|
154
154
|
adapter_initialize
|
155
155
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
156
|
+
keep_reference = typecast_value_boolean(@opts[:keep_reference]) != false
|
157
|
+
begin
|
158
|
+
Sequel.synchronize{::Sequel::DATABASES.push(self)} if keep_reference
|
159
|
+
Sequel::Database.run_after_initialize(self)
|
160
160
|
|
161
|
-
|
161
|
+
initialize_load_extensions(:preconnect_extensions)
|
162
162
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
163
|
+
if typecast_value_boolean(@opts[:preconnect]) && @pool.respond_to?(:preconnect, true)
|
164
|
+
concurrent = typecast_value_string(@opts[:preconnect]) == "concurrently"
|
165
|
+
@pool.send(:preconnect, concurrent)
|
166
|
+
end
|
167
167
|
|
168
|
-
|
168
|
+
initialize_load_extensions(:extensions)
|
169
|
+
test_connection if typecast_value_boolean(@opts.fetch(:test, true)) && respond_to?(:connect, true)
|
170
|
+
rescue
|
171
|
+
Sequel.synchronize{::Sequel::DATABASES.delete(self)} if keep_reference
|
172
|
+
raise
|
173
|
+
end
|
169
174
|
end
|
170
175
|
|
171
176
|
# Freeze internal data structures for the Database instance.
|
@@ -185,7 +190,9 @@ module Sequel
|
|
185
190
|
|
186
191
|
# Disallow dup/clone for Database instances
|
187
192
|
undef_method :dup, :clone, :initialize_copy
|
193
|
+
# :nocov:
|
188
194
|
if RUBY_VERSION >= '1.9.3'
|
195
|
+
# :nocov:
|
189
196
|
undef_method :initialize_clone, :initialize_dup
|
190
197
|
end
|
191
198
|
|
@@ -206,8 +213,7 @@ module Sequel
|
|
206
213
|
Sequel.extension(*exts)
|
207
214
|
exts.each do |ext|
|
208
215
|
if pr = Sequel.synchronize{EXTENSIONS[ext]}
|
209
|
-
|
210
|
-
Sequel.synchronize{@loaded_extensions << ext}
|
216
|
+
if Sequel.synchronize{@loaded_extensions.include?(ext) ? false : (@loaded_extensions << ext)}
|
211
217
|
pr.call(self)
|
212
218
|
end
|
213
219
|
else
|
@@ -440,6 +446,19 @@ module Sequel
|
|
440
446
|
end
|
441
447
|
end
|
442
448
|
|
449
|
+
# Swallow database errors, unless they are connect/disconnect errors.
|
450
|
+
def swallow_database_error
|
451
|
+
yield
|
452
|
+
rescue Sequel::DatabaseDisconnectError, DatabaseConnectionError
|
453
|
+
# Always raise disconnect errors
|
454
|
+
raise
|
455
|
+
rescue Sequel::DatabaseError
|
456
|
+
# Don't raise other database errors.
|
457
|
+
nil
|
458
|
+
# else
|
459
|
+
# Don't rescue other exceptions, they will be raised normally.
|
460
|
+
end
|
461
|
+
|
443
462
|
# Typecast the value to an SQL::Blob
|
444
463
|
def typecast_value_blob(value)
|
445
464
|
value.is_a?(Sequel::SQL::Blob) ? value : Sequel::SQL::Blob.new(value)
|
@@ -325,7 +325,7 @@ module Sequel
|
|
325
325
|
:integer
|
326
326
|
when /\Adate\z/io
|
327
327
|
:date
|
328
|
-
when /\A((small)?datetime|timestamp( with(out)? time zone)?)
|
328
|
+
when /\A((small)?datetime|timestamp(\(\d\))?( with(out)? time zone)?)\z/io
|
329
329
|
:datetime
|
330
330
|
when /\Atime( with(out)? time zone)?\z/io
|
331
331
|
:time
|
@@ -344,7 +344,9 @@ module Sequel
|
|
344
344
|
|
345
345
|
# Post process the schema values.
|
346
346
|
def schema_post_process(cols)
|
347
|
+
# :nocov:
|
347
348
|
if RUBY_VERSION >= '2.5'
|
349
|
+
# :nocov:
|
348
350
|
cols.each do |_, h|
|
349
351
|
db_type = h[:db_type]
|
350
352
|
if db_type.is_a?(String)
|
@@ -38,7 +38,6 @@ module Sequel
|
|
38
38
|
@constraints = []
|
39
39
|
@primary_key = nil
|
40
40
|
instance_exec(&block) if block
|
41
|
-
@columns.unshift(@primary_key) if @primary_key && !has_column?(primary_key_name)
|
42
41
|
end
|
43
42
|
|
44
43
|
# Use custom Bignum method to use :Bignum instead of Bignum class, to work
|
@@ -110,6 +109,9 @@ module Sequel
|
|
110
109
|
# yet exist on referenced table (but will exist before the transaction commits).
|
111
110
|
# Basically it adds DEFERRABLE INITIALLY DEFERRED on key creation.
|
112
111
|
# If you use :immediate as the value, uses DEFERRABLE INITIALLY IMMEDIATE.
|
112
|
+
# :generated_always_as :: Specify a GENERATED ALWAYS AS column expression,
|
113
|
+
# if generated columns are supported (PostgreSQL 12+, MariaDB 5.2.0+,
|
114
|
+
# and MySQL 5.7.6+).
|
113
115
|
# :index :: Create an index on this column. If given a hash, use the hash as the
|
114
116
|
# options for the index.
|
115
117
|
# :key :: For foreign key columns, the column in the associated table
|
@@ -123,20 +125,32 @@ module Sequel
|
|
123
125
|
# :on_update :: Specify the behavior of this column when being updated
|
124
126
|
# (:restrict, :cascade, :set_null, :set_default, :no_action).
|
125
127
|
# :primary_key :: Make the column as a single primary key column. This should not
|
126
|
-
# be used if you
|
128
|
+
# be used if you want a single autoincrementing primary key column
|
127
129
|
# (use the primary_key method in that case).
|
128
130
|
# :primary_key_constraint_name :: The name to give the primary key constraint
|
131
|
+
# :primary_key_deferrable :: Similar to :deferrable, but for the primary key constraint
|
132
|
+
# if :primary_key is used.
|
129
133
|
# :type :: Overrides the type given as the argument. Generally not used by column
|
130
134
|
# itself, but can be passed as an option to other methods that call column.
|
131
135
|
# :unique :: Mark the column as unique, generally has the same effect as
|
132
136
|
# creating a unique index on the column.
|
133
137
|
# :unique_constraint_name :: The name to give the unique key constraint
|
138
|
+
# :unique_deferrable :: Similar to :deferrable, but for the unique constraint if :unique
|
139
|
+
# is used.
|
140
|
+
#
|
141
|
+
# PostgreSQL specific options:
|
142
|
+
#
|
143
|
+
# :identity :: Create an identity column.
|
134
144
|
#
|
135
145
|
# MySQL specific options:
|
136
|
-
#
|
137
|
-
# if generated columns are supported.
|
146
|
+
#
|
138
147
|
# :generated_type :: Set the type of column when using :generated_always_as,
|
139
148
|
# should be :virtual or :stored to force a type.
|
149
|
+
#
|
150
|
+
# Microsoft SQL Server specific options:
|
151
|
+
#
|
152
|
+
# :clustered :: When using :primary_key or :unique, marks the primary key or unique
|
153
|
+
# constraint as CLUSTERED (if true), or NONCLUSTERED (if false).
|
140
154
|
def column(name, type, opts = OPTS)
|
141
155
|
columns << {:name => name, :type => type}.merge!(opts)
|
142
156
|
if index_opts = opts[:index]
|
@@ -145,7 +159,7 @@ module Sequel
|
|
145
159
|
nil
|
146
160
|
end
|
147
161
|
|
148
|
-
# Adds a named constraint (or unnamed if name is nil),
|
162
|
+
# Adds a named CHECK constraint (or unnamed if name is nil),
|
149
163
|
# with the given block or args. To provide options for the constraint, pass
|
150
164
|
# a hash as the first argument.
|
151
165
|
#
|
@@ -153,6 +167,15 @@ module Sequel
|
|
153
167
|
# # CONSTRAINT blah CHECK num >= 1 AND num <= 5
|
154
168
|
# constraint({name: :blah, deferrable: true}, num: 1..5)
|
155
169
|
# # CONSTRAINT blah CHECK num >= 1 AND num <= 5 DEFERRABLE INITIALLY DEFERRED
|
170
|
+
#
|
171
|
+
# If the first argument is a hash, the following options are supported:
|
172
|
+
#
|
173
|
+
# Options:
|
174
|
+
# :name :: The name of the CHECK constraint
|
175
|
+
# :deferrable :: Whether the CHECK constraint should be marked DEFERRABLE.
|
176
|
+
#
|
177
|
+
# PostgreSQL specific options:
|
178
|
+
# :not_valid :: Whether the CHECK constraint should be marked NOT VALID.
|
156
179
|
def constraint(name, *args, &block)
|
157
180
|
opts = name.is_a?(Hash) ? name : {:name=>name}
|
158
181
|
constraints << opts.merge(:type=>:check, :check=>block || args)
|
@@ -191,14 +214,12 @@ module Sequel
|
|
191
214
|
end
|
192
215
|
|
193
216
|
# Add a full text index on the given columns.
|
217
|
+
# See #index for additional options.
|
194
218
|
#
|
195
219
|
# PostgreSQL specific options:
|
196
220
|
# :index_type :: Can be set to :gist to use a GIST index instead of the
|
197
221
|
# default GIN index.
|
198
222
|
# :language :: Set a language to use for the index (default: simple).
|
199
|
-
#
|
200
|
-
# Microsoft SQL Server specific options:
|
201
|
-
# :key_index :: The KEY INDEX to use for the full text index.
|
202
223
|
def full_text_index(columns, opts = OPTS)
|
203
224
|
index(columns, opts.merge(:type => :full_text))
|
204
225
|
end
|
@@ -208,35 +229,43 @@ module Sequel
|
|
208
229
|
columns.any?{|c| c[:name] == name}
|
209
230
|
end
|
210
231
|
|
211
|
-
# Add an index on the given column(s) with the given options.
|
232
|
+
# Add an index on the given column(s) with the given options. Examples:
|
233
|
+
#
|
234
|
+
# index :name
|
235
|
+
# # CREATE INDEX table_name_index ON table (name)
|
236
|
+
#
|
237
|
+
# index [:artist_id, :name]
|
238
|
+
# # CREATE INDEX table_artist_id_name_index ON table (artist_id, name)
|
239
|
+
#
|
240
|
+
# index [:artist_id, :name], name: :foo
|
241
|
+
# # CREATE INDEX foo ON table (artist_id, name)
|
242
|
+
#
|
212
243
|
# General options:
|
213
244
|
#
|
245
|
+
# :include :: Include additional column values in the index, without
|
246
|
+
# actually indexing on those values (only supported by
|
247
|
+
# some databases).
|
214
248
|
# :name :: The name to use for the index. If not given, a default name
|
215
249
|
# based on the table and columns is used.
|
216
|
-
# :type :: The type of index to use (only supported by some databases
|
250
|
+
# :type :: The type of index to use (only supported by some databases,
|
251
|
+
# :full_text and :spatial values are handled specially).
|
217
252
|
# :unique :: Make the index unique, so duplicate values are not allowed.
|
218
|
-
# :where ::
|
253
|
+
# :where :: A filter expression, used to create a partial index (only
|
254
|
+
# supported by some databases).
|
219
255
|
#
|
220
256
|
# PostgreSQL specific options:
|
221
257
|
#
|
222
258
|
# :concurrently :: Create the index concurrently, so it doesn't block
|
223
259
|
# operations on the table while the index is being
|
224
260
|
# built.
|
225
|
-
# :
|
226
|
-
# :
|
227
|
-
#
|
261
|
+
# :if_not_exists :: Only create the index if an index of the same name doesn't already exist.
|
262
|
+
# :opclass :: Set an opclass to use for all columns (per-column opclasses require
|
263
|
+
# custom SQL).
|
228
264
|
# :tablespace :: Specify tablespace for index.
|
229
265
|
#
|
230
266
|
# Microsoft SQL Server specific options:
|
231
267
|
#
|
232
|
-
# :
|
233
|
-
# actually indexing on those values.
|
234
|
-
#
|
235
|
-
# index :name
|
236
|
-
# # CREATE INDEX table_name_index ON table (name)
|
237
|
-
#
|
238
|
-
# index [:artist_id, :name]
|
239
|
-
# # CREATE INDEX table_artist_id_name_index ON table (artist_id, name)
|
268
|
+
# :key_index :: Sets the KEY INDEX to the given value.
|
240
269
|
def index(columns, opts = OPTS)
|
241
270
|
indexes << {:columns => Array(columns)}.merge!(opts)
|
242
271
|
nil
|
@@ -302,6 +331,7 @@ module Sequel
|
|
302
331
|
end
|
303
332
|
|
304
333
|
# Add a spatial index on the given columns.
|
334
|
+
# See #index for additional options.
|
305
335
|
def spatial_index(columns, opts = OPTS)
|
306
336
|
index(columns, opts.merge(:type => :spatial))
|
307
337
|
end
|
@@ -428,7 +458,7 @@ module Sequel
|
|
428
458
|
end
|
429
459
|
|
430
460
|
# Add a full text index on the given columns.
|
431
|
-
# See CreateTableGenerator#
|
461
|
+
# See CreateTableGenerator#full_text_index for available options.
|
432
462
|
def add_full_text_index(columns, opts = OPTS)
|
433
463
|
add_index(columns, {:type=>:full_text}.merge!(opts))
|
434
464
|
end
|
@@ -437,34 +467,6 @@ module Sequel
|
|
437
467
|
# CreateTableGenerator#index for available options.
|
438
468
|
#
|
439
469
|
# add_index(:artist_id) # CREATE INDEX table_artist_id_index ON table (artist_id)
|
440
|
-
#
|
441
|
-
# Options:
|
442
|
-
#
|
443
|
-
# :name :: Give a specific name for the index. Highly recommended if you plan on
|
444
|
-
# dropping the index later.
|
445
|
-
# :where :: A filter expression, used to setup a partial index (if supported).
|
446
|
-
# :unique :: Create a unique index.
|
447
|
-
#
|
448
|
-
# PostgreSQL specific options:
|
449
|
-
#
|
450
|
-
# :concurrently :: Create the index concurrently, so it doesn't require an exclusive lock
|
451
|
-
# on the table.
|
452
|
-
# :index_type :: The underlying index type to use for a full_text index, gin by default).
|
453
|
-
# :language :: The language to use for a full text index (simple by default).
|
454
|
-
# :opclass :: Set an opclass to use for all columns (per-column opclasses require
|
455
|
-
# custom SQL).
|
456
|
-
# :type :: Set the index type (e.g. full_text, spatial, hash, gin, gist, btree).
|
457
|
-
# :if_not_exists :: Only create the index if an index of the same name doesn't already exists
|
458
|
-
#
|
459
|
-
# MySQL specific options:
|
460
|
-
#
|
461
|
-
# :type :: Set the index type, with full_text and spatial indexes handled specially.
|
462
|
-
#
|
463
|
-
# Microsoft SQL Server specific options:
|
464
|
-
#
|
465
|
-
# :include :: Includes additional columns in the index.
|
466
|
-
# :key_index :: Sets the KEY INDEX to the given value.
|
467
|
-
# :type :: clustered uses a clustered index, full_text uses a full text index.
|
468
470
|
def add_index(columns, opts = OPTS)
|
469
471
|
@operations << {:op => :add_index, :columns => Array(columns)}.merge!(opts)
|
470
472
|
nil
|
@@ -63,7 +63,7 @@ module Sequel
|
|
63
63
|
# definitions using <tt>create_table</tt>, and +add_index+ accepts all the options
|
64
64
|
# available for index definition.
|
65
65
|
#
|
66
|
-
# See <tt>Schema::AlterTableGenerator</tt> and the {
|
66
|
+
# See <tt>Schema::AlterTableGenerator</tt> and the {Migrations guide}[rdoc-ref:doc/migration.rdoc].
|
67
67
|
def alter_table(name, &block)
|
68
68
|
generator = alter_table_generator(&block)
|
69
69
|
remove_cached_schema(name)
|
@@ -240,7 +240,7 @@ module Sequel
|
|
240
240
|
if supports_create_or_replace_view?
|
241
241
|
options = options.merge(:replace=>true)
|
242
242
|
else
|
243
|
-
drop_view(name)
|
243
|
+
swallow_database_error{drop_view(name)}
|
244
244
|
end
|
245
245
|
|
246
246
|
create_view(name, source, options)
|
@@ -262,6 +262,10 @@ module Sequel
|
|
262
262
|
# # SELECT * FROM items WHERE foo
|
263
263
|
# # WITH CHECK OPTION
|
264
264
|
#
|
265
|
+
# DB.create_view(:bar_items, DB[:items].select(:foo), columns: [:bar])
|
266
|
+
# # CREATE VIEW bar_items (bar) AS
|
267
|
+
# # SELECT foo FROM items
|
268
|
+
#
|
265
269
|
# Options:
|
266
270
|
# :columns :: The column names to use for the view. If not given,
|
267
271
|
# automatically determined based on the input dataset.
|
@@ -494,7 +498,9 @@ module Sequel
|
|
494
498
|
when :drop_index
|
495
499
|
drop_index_sql(table, op)
|
496
500
|
else
|
497
|
-
|
501
|
+
if sql = alter_table_op_sql(table, op)
|
502
|
+
"ALTER TABLE #{quote_schema_table(table)} #{sql}"
|
503
|
+
end
|
498
504
|
end
|
499
505
|
end
|
500
506
|
|
@@ -578,14 +584,15 @@ module Sequel
|
|
578
584
|
sql << ' NULL'
|
579
585
|
end
|
580
586
|
end
|
581
|
-
|
587
|
+
|
582
588
|
# Add primary key SQL fragment to column creation SQL.
|
583
589
|
def column_definition_primary_key_sql(sql, column)
|
584
590
|
if column[:primary_key]
|
585
591
|
if name = column[:primary_key_constraint_name]
|
586
592
|
sql << " CONSTRAINT #{quote_identifier(name)}"
|
587
593
|
end
|
588
|
-
sql <<
|
594
|
+
sql << " " << primary_key_constraint_sql_fragment(column)
|
595
|
+
constraint_deferrable_sql_append(sql, column[:primary_key_deferrable])
|
589
596
|
end
|
590
597
|
end
|
591
598
|
|
@@ -605,7 +612,8 @@ module Sequel
|
|
605
612
|
if name = column[:unique_constraint_name]
|
606
613
|
sql << " CONSTRAINT #{quote_identifier(name)}"
|
607
614
|
end
|
608
|
-
sql << '
|
615
|
+
sql << ' ' << unique_constraint_sql_fragment(column)
|
616
|
+
constraint_deferrable_sql_append(sql, column[:unique_deferrable])
|
609
617
|
end
|
610
618
|
end
|
611
619
|
|
@@ -652,11 +660,11 @@ module Sequel
|
|
652
660
|
check = "(#{check})" unless check[0..0] == '(' && check[-1..-1] == ')'
|
653
661
|
sql << "CHECK #{check}"
|
654
662
|
when :primary_key
|
655
|
-
sql << "
|
663
|
+
sql << "#{primary_key_constraint_sql_fragment(constraint)} #{literal(constraint[:columns])}"
|
656
664
|
when :foreign_key
|
657
665
|
sql << column_references_table_constraint_sql(constraint.merge(:deferrable=>nil))
|
658
666
|
when :unique
|
659
|
-
sql << "
|
667
|
+
sql << "#{unique_constraint_sql_fragment(constraint)} #{literal(constraint[:columns])}"
|
660
668
|
else
|
661
669
|
raise Error, "Invalid constraint type #{constraint[:type]}, should be :check, :primary_key, :foreign_key, or :unique"
|
662
670
|
end
|
@@ -809,23 +817,20 @@ module Sequel
|
|
809
817
|
# Proxy the filter_expr call to the dataset, used for creating constraints.
|
810
818
|
# Support passing Proc arguments as blocks, as well as treating plain strings
|
811
819
|
# as literal strings, so that previous migrations that used this API do not break.
|
812
|
-
def filter_expr(
|
813
|
-
if
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
elsif arg.length > 1
|
824
|
-
args = [Sequel.&(*arg)]
|
825
|
-
end
|
820
|
+
def filter_expr(arg=nil, &block)
|
821
|
+
if arg.is_a?(Proc) && !block
|
822
|
+
block = arg
|
823
|
+
arg = nil
|
824
|
+
elsif arg.is_a?(String)
|
825
|
+
arg = Sequel.lit(arg)
|
826
|
+
elsif arg.is_a?(Array)
|
827
|
+
if arg.first.is_a?(String)
|
828
|
+
arg = Sequel.lit(*arg)
|
829
|
+
elsif arg.length > 1
|
830
|
+
arg = Sequel.&(*arg)
|
826
831
|
end
|
827
832
|
end
|
828
|
-
schema_utility_dataset.literal(schema_utility_dataset.send(:filter_expr,
|
833
|
+
schema_utility_dataset.literal(schema_utility_dataset.send(:filter_expr, arg, &block))
|
829
834
|
end
|
830
835
|
|
831
836
|
# SQL statement for creating an index for the table with the given name
|
@@ -891,6 +896,11 @@ module Sequel
|
|
891
896
|
on_delete_clause(action)
|
892
897
|
end
|
893
898
|
|
899
|
+
# Add fragment for primary key specification, separated for easier overridding.
|
900
|
+
def primary_key_constraint_sql_fragment(_)
|
901
|
+
'PRIMARY KEY'
|
902
|
+
end
|
903
|
+
|
894
904
|
# Proxy the quote_schema_table method to the dataset
|
895
905
|
def quote_schema_table(table)
|
896
906
|
schema_utility_dataset.quote_schema_table(table)
|
@@ -1046,6 +1056,11 @@ module Sequel
|
|
1046
1056
|
"#{type}#{literal(Array(elements)) if elements}#{' UNSIGNED' if column[:unsigned]}"
|
1047
1057
|
end
|
1048
1058
|
|
1059
|
+
# Add fragment for unique specification, separated for easier overridding.
|
1060
|
+
def unique_constraint_sql_fragment(_)
|
1061
|
+
'UNIQUE'
|
1062
|
+
end
|
1063
|
+
|
1049
1064
|
# Whether clob should be used for String text: true columns.
|
1050
1065
|
def uses_clob_for_text?
|
1051
1066
|
false
|
@@ -82,7 +82,7 @@ module Sequel
|
|
82
82
|
# :server :: The server/shard the transaction is being executed on.
|
83
83
|
def rollback_on_exit(opts=OPTS)
|
84
84
|
synchronize(opts[:server]) do |conn|
|
85
|
-
raise Error, "Cannot call Sequel:: Database#rollback_on_exit
|
85
|
+
raise Error, "Cannot call Sequel:: Database#rollback_on_exit unless inside a transaction" unless h = _trans(conn)
|
86
86
|
rollback = !opts[:cancel]
|
87
87
|
|
88
88
|
if supports_savepoints?
|
@@ -142,7 +142,7 @@ module Sequel
|
|
142
142
|
# :num_retries :: The number of times to retry if the :retry_on option is used.
|
143
143
|
# The default is 5 times. Can be set to nil to retry indefinitely,
|
144
144
|
# but that is not recommended.
|
145
|
-
# :before_retry :: Proc to execute before
|
145
|
+
# :before_retry :: Proc to execute before retrying if the :retry_on option is used.
|
146
146
|
# Called with two arguments: the number of retry attempts (counting
|
147
147
|
# the current one) and the error the last attempt failed with.
|
148
148
|
# :prepare :: A string to use as the transaction identifier for a
|
@@ -154,7 +154,7 @@ module Sequel
|
|
154
154
|
# Note that this should not be used unless the entire transaction
|
155
155
|
# block is idempotent, as otherwise it can cause non-idempotent
|
156
156
|
# behavior to execute multiple times.
|
157
|
-
# :rollback :: Can
|
157
|
+
# :rollback :: Can be set to :reraise to reraise any Sequel::Rollback exceptions
|
158
158
|
# raised, or :always to always rollback even if no exceptions occur
|
159
159
|
# (useful for testing).
|
160
160
|
# :server :: The server to use for the transaction. Set to :default, :read_only, or
|
@@ -178,19 +178,15 @@ module Sequel
|
|
178
178
|
opts = Hash[opts]
|
179
179
|
if retry_on = opts[:retry_on]
|
180
180
|
tot_retries = opts.fetch(:num_retries, 5)
|
181
|
-
num_retries = 0
|
181
|
+
num_retries = 0
|
182
182
|
begin
|
183
183
|
opts[:retry_on] = nil
|
184
184
|
opts[:retrying] = true
|
185
185
|
transaction(opts, &block)
|
186
186
|
rescue *retry_on => e
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
opts[:before_retry].call(num_retries, e) if opts[:before_retry]
|
191
|
-
retry
|
192
|
-
end
|
193
|
-
else
|
187
|
+
num_retries += 1
|
188
|
+
if tot_retries.nil? || num_retries <= tot_retries
|
189
|
+
opts[:before_retry].call(num_retries, e) if opts[:before_retry]
|
194
190
|
retry
|
195
191
|
end
|
196
192
|
raise
|
@@ -209,6 +205,10 @@ module Sequel
|
|
209
205
|
end
|
210
206
|
end
|
211
207
|
|
208
|
+
if opts[:savepoint] && !supports_savepoints?
|
209
|
+
raise Sequel::InvalidOperation, "savepoints not supported on #{database_type}"
|
210
|
+
end
|
211
|
+
|
212
212
|
if already_in_transaction?(conn, opts)
|
213
213
|
if opts[:rollback] == :always && !opts.has_key?(:savepoint)
|
214
214
|
if supports_savepoints?
|
@@ -422,11 +422,10 @@ module Sequel
|
|
422
422
|
end
|
423
423
|
|
424
424
|
# Retrieve the savepoint hooks that should be run for the given
|
425
|
-
# connection and commit status.
|
425
|
+
# connection and commit status. This expacts that you are
|
426
|
+
# already inside a savepoint when calling.
|
426
427
|
def savepoint_hooks(conn, committed)
|
427
|
-
|
428
|
-
_trans(conn)[:savepoints].last[committed ? :after_commit : :after_rollback]
|
429
|
-
end
|
428
|
+
_trans(conn)[:savepoints].last[committed ? :after_commit : :after_rollback]
|
430
429
|
end
|
431
430
|
|
432
431
|
# Retrieve the transaction hooks that should be run for the given
|
@@ -439,13 +438,12 @@ module Sequel
|
|
439
438
|
|
440
439
|
# Remove the current thread from the list of active transactions
|
441
440
|
def remove_transaction(conn, committed)
|
441
|
+
callbacks = transaction_hooks(conn, committed)
|
442
442
|
if in_savepoint?(conn)
|
443
443
|
savepoint_callbacks = savepoint_hooks(conn, committed)
|
444
444
|
if committed
|
445
445
|
savepoint_rollback_callbacks = savepoint_hooks(conn, false)
|
446
446
|
end
|
447
|
-
else
|
448
|
-
callbacks = transaction_hooks(conn, committed)
|
449
447
|
end
|
450
448
|
|
451
449
|
if transaction_finished?(conn)
|
@@ -453,7 +451,6 @@ module Sequel
|
|
453
451
|
rolled_back = !committed
|
454
452
|
Sequel.synchronize{h[:rolled_back] = rolled_back}
|
455
453
|
Sequel.synchronize{@transactions.delete(conn)}
|
456
|
-
callbacks.each(&:call) if callbacks
|
457
454
|
elsif savepoint_callbacks || savepoint_rollback_callbacks
|
458
455
|
if committed
|
459
456
|
meth = in_savepoint?(conn) ? :add_savepoint_hook : :add_transaction_hook
|
@@ -473,6 +470,8 @@ module Sequel
|
|
473
470
|
savepoint_callbacks.each(&:call)
|
474
471
|
end
|
475
472
|
end
|
473
|
+
|
474
|
+
callbacks.each(&:call) if callbacks
|
476
475
|
end
|
477
476
|
|
478
477
|
# SQL to rollback to a savepoint
|
@@ -333,6 +333,7 @@ module Sequel
|
|
333
333
|
# after every 50 records.
|
334
334
|
# :return :: When this is set to :primary_key, returns an array of
|
335
335
|
# autoincremented primary key values for the rows inserted.
|
336
|
+
# This does not have an effect if +values+ is a Dataset.
|
336
337
|
# :server :: Set the server/shard to use for the transaction and insert
|
337
338
|
# queries.
|
338
339
|
# :slice :: Same as :commit_every, :commit_every takes precedence.
|
@@ -545,7 +546,7 @@ module Sequel
|
|
545
546
|
unless @opts[:order]
|
546
547
|
raise Sequel::Error, "Dataset#paged_each requires the dataset be ordered"
|
547
548
|
end
|
548
|
-
unless
|
549
|
+
unless defined?(yield)
|
549
550
|
return enum_for(:paged_each, opts)
|
550
551
|
end
|
551
552
|
|
@@ -606,14 +607,16 @@ module Sequel
|
|
606
607
|
# as_hash, it accepts an optional :hash parameter, into which entries will
|
607
608
|
# be merged.
|
608
609
|
#
|
609
|
-
# DB[:table].select_hash(:id, :name)
|
610
|
+
# DB[:table].select_hash(:id, :name)
|
611
|
+
# # SELECT id, name FROM table
|
610
612
|
# # => {1=>'a', 2=>'b', ...}
|
611
613
|
#
|
612
614
|
# You can also provide an array of column names for either the key_column,
|
613
615
|
# the value column, or both:
|
614
616
|
#
|
615
|
-
# DB[:table].select_hash([:id, :foo], [:name, :bar])
|
616
|
-
# #
|
617
|
+
# DB[:table].select_hash([:id, :foo], [:name, :bar])
|
618
|
+
# # SELECT id, foo, name, bar FROM table
|
619
|
+
# # => {[1, 3]=>['a', 'c'], [2, 4]=>['b', 'd'], ...}
|
617
620
|
#
|
618
621
|
# When using this method, you must be sure that each expression has an alias
|
619
622
|
# that Sequel can determine.
|
@@ -625,14 +628,16 @@ module Sequel
|
|
625
628
|
# Similar to to_hash_groups, but only selects the columns given. Like to_hash_groups,
|
626
629
|
# it accepts an optional :hash parameter, into which entries will be merged.
|
627
630
|
#
|
628
|
-
# DB[:table].select_hash_groups(:name, :id)
|
631
|
+
# DB[:table].select_hash_groups(:name, :id)
|
632
|
+
# # SELECT id, name FROM table
|
629
633
|
# # => {'a'=>[1, 4, ...], 'b'=>[2, ...], ...}
|
630
634
|
#
|
631
635
|
# You can also provide an array of column names for either the key_column,
|
632
636
|
# the value column, or both:
|
633
637
|
#
|
634
|
-
# DB[:table].select_hash_groups([:first, :middle], [:last, :id])
|
635
|
-
# #
|
638
|
+
# DB[:table].select_hash_groups([:first, :middle], [:last, :id])
|
639
|
+
# # SELECT first, middle, last, id FROM table
|
640
|
+
# # => {['a', 'b']=>[['c', 1], ['d', 2], ...], ...}
|
636
641
|
#
|
637
642
|
# When using this method, you must be sure that each expression has an alias
|
638
643
|
# that Sequel can determine.
|
@@ -1069,7 +1074,7 @@ module Sequel
|
|
1069
1074
|
|
1070
1075
|
# Set the server to use to :default unless it is already set in the passed opts
|
1071
1076
|
def default_server_opts(opts)
|
1072
|
-
if @db.sharded?
|
1077
|
+
if @db.sharded? && !opts.has_key?(:server)
|
1073
1078
|
opts = Hash[opts]
|
1074
1079
|
opts[:server] = @opts[:server] || :default
|
1075
1080
|
end
|
@@ -1080,7 +1085,7 @@ module Sequel
|
|
1080
1085
|
# :read_only server unless a specific server is set.
|
1081
1086
|
def execute(sql, opts=OPTS, &block)
|
1082
1087
|
db = @db
|
1083
|
-
if db.sharded?
|
1088
|
+
if db.sharded? && !opts.has_key?(:server)
|
1084
1089
|
opts = Hash[opts]
|
1085
1090
|
opts[:server] = @opts[:server] || (@opts[:lock] ? :default : :read_only)
|
1086
1091
|
opts
|