sequel 5.8.0 → 5.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +409 -1795
- data/MIT-LICENSE +1 -1
- data/README.rdoc +4 -4
- data/bin/sequel +4 -0
- data/doc/advanced_associations.rdoc +136 -18
- data/doc/association_basics.rdoc +10 -5
- data/doc/cheat_sheet.rdoc +1 -0
- data/doc/code_order.rdoc +12 -2
- data/doc/dataset_filtering.rdoc +17 -2
- data/doc/mass_assignment.rdoc +3 -3
- data/doc/model_dataset_method_design.rdoc +1 -1
- data/doc/model_plugins.rdoc +1 -1
- data/doc/opening_databases.rdoc +30 -8
- data/doc/postgresql.rdoc +107 -2
- data/doc/release_notes/5.10.0.txt +84 -0
- data/doc/release_notes/5.11.0.txt +83 -0
- data/doc/release_notes/5.12.0.txt +141 -0
- data/doc/release_notes/5.13.0.txt +27 -0
- data/doc/release_notes/5.14.0.txt +63 -0
- data/doc/release_notes/5.15.0.txt +39 -0
- data/doc/release_notes/5.16.0.txt +110 -0
- data/doc/release_notes/5.17.0.txt +31 -0
- data/doc/release_notes/5.18.0.txt +69 -0
- data/doc/release_notes/5.19.0.txt +28 -0
- data/doc/release_notes/5.20.0.txt +89 -0
- 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.9.0.txt +99 -0
- data/doc/security.rdoc +10 -0
- data/doc/sharding.rdoc +42 -28
- data/doc/sql.rdoc +12 -0
- data/doc/testing.rdoc +24 -17
- data/doc/transactions.rdoc +78 -0
- data/doc/validations.rdoc +2 -2
- data/lib/sequel/adapters/ado.rb +26 -18
- data/lib/sequel/adapters/ado/access.rb +2 -2
- data/lib/sequel/adapters/ado/mssql.rb +5 -8
- data/lib/sequel/adapters/amalgalite.rb +1 -1
- data/lib/sequel/adapters/jdbc.rb +71 -27
- data/lib/sequel/adapters/jdbc/mysql.rb +6 -6
- data/lib/sequel/adapters/jdbc/oracle.rb +7 -6
- data/lib/sequel/adapters/jdbc/postgresql.rb +17 -28
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +5 -6
- data/lib/sequel/adapters/jdbc/sqlite.rb +33 -2
- data/lib/sequel/adapters/jdbc/sqlserver.rb +4 -3
- data/lib/sequel/adapters/jdbc/transactions.rb +14 -28
- data/lib/sequel/adapters/mysql.rb +14 -15
- data/lib/sequel/adapters/mysql2.rb +5 -3
- data/lib/sequel/adapters/odbc.rb +4 -6
- data/lib/sequel/adapters/oracle.rb +7 -7
- data/lib/sequel/adapters/postgres.rb +52 -16
- data/lib/sequel/adapters/shared/access.rb +16 -12
- data/lib/sequel/adapters/shared/db2.rb +5 -0
- data/lib/sequel/adapters/shared/mssql.rb +41 -18
- data/lib/sequel/adapters/shared/mysql.rb +66 -19
- data/lib/sequel/adapters/shared/oracle.rb +29 -23
- data/lib/sequel/adapters/shared/postgres.rb +341 -95
- data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
- data/lib/sequel/adapters/shared/sqlite.rb +174 -21
- data/lib/sequel/adapters/sqlanywhere.rb +33 -17
- data/lib/sequel/adapters/sqlite.rb +78 -68
- data/lib/sequel/adapters/tinytds.rb +14 -6
- data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +2 -5
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +5 -1
- data/lib/sequel/connection_pool.rb +2 -6
- data/lib/sequel/connection_pool/sharded_single.rb +7 -4
- data/lib/sequel/connection_pool/sharded_threaded.rb +32 -21
- data/lib/sequel/connection_pool/single.rb +1 -1
- data/lib/sequel/connection_pool/threaded.rb +26 -11
- data/lib/sequel/core.rb +327 -319
- data/lib/sequel/database/connecting.rb +7 -8
- data/lib/sequel/database/logging.rb +7 -1
- data/lib/sequel/database/misc.rb +68 -34
- data/lib/sequel/database/query.rb +6 -4
- data/lib/sequel/database/schema_generator.rb +31 -11
- data/lib/sequel/database/schema_methods.rb +32 -22
- data/lib/sequel/database/transactions.rb +129 -25
- data/lib/sequel/dataset.rb +4 -2
- data/lib/sequel/dataset/actions.rb +34 -23
- data/lib/sequel/dataset/features.rb +34 -0
- data/lib/sequel/dataset/graph.rb +27 -11
- data/lib/sequel/dataset/misc.rb +17 -3
- data/lib/sequel/dataset/placeholder_literalizer.rb +50 -21
- data/lib/sequel/dataset/prepared_statements.rb +96 -26
- data/lib/sequel/dataset/query.rb +43 -8
- data/lib/sequel/dataset/sql.rb +189 -41
- 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/caller_logging.rb +79 -0
- data/lib/sequel/extensions/columns_introspection.rb +1 -2
- data/lib/sequel/extensions/connection_expiration.rb +6 -6
- data/lib/sequel/extensions/connection_validator.rb +7 -6
- data/lib/sequel/extensions/constant_sql_override.rb +65 -0
- data/lib/sequel/extensions/constraint_validations.rb +53 -28
- data/lib/sequel/extensions/core_refinements.rb +2 -0
- data/lib/sequel/extensions/duplicate_columns_handler.rb +2 -0
- data/lib/sequel/extensions/escaped_like.rb +100 -0
- data/lib/sequel/extensions/eval_inspect.rb +3 -1
- 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/integer64.rb +3 -1
- data/lib/sequel/extensions/looser_typecasting.rb +3 -3
- data/lib/sequel/extensions/migration.rb +13 -6
- data/lib/sequel/extensions/named_timezones.rb +84 -23
- data/lib/sequel/extensions/pg_array.rb +87 -79
- data/lib/sequel/extensions/pg_array_ops.rb +14 -6
- data/lib/sequel/extensions/pg_enum.rb +34 -18
- data/lib/sequel/extensions/pg_extended_date_support.rb +34 -14
- data/lib/sequel/extensions/pg_hstore.rb +6 -0
- data/lib/sequel/extensions/pg_hstore_ops.rb +2 -0
- data/lib/sequel/extensions/pg_inet.rb +15 -5
- data/lib/sequel/extensions/pg_interval.rb +2 -0
- data/lib/sequel/extensions/pg_json.rb +387 -123
- data/lib/sequel/extensions/pg_json_ops.rb +168 -0
- data/lib/sequel/extensions/pg_range.rb +20 -10
- data/lib/sequel/extensions/pg_range_ops.rb +2 -0
- data/lib/sequel/extensions/pg_row.rb +3 -2
- data/lib/sequel/extensions/pg_row_ops.rb +24 -0
- data/lib/sequel/extensions/pg_static_cache_updater.rb +2 -2
- data/lib/sequel/extensions/pg_timestamptz.rb +2 -0
- data/lib/sequel/extensions/query.rb +1 -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 +13 -7
- data/lib/sequel/extensions/sequel_4_dataset_methods.rb +4 -2
- data/lib/sequel/extensions/server_block.rb +18 -7
- data/lib/sequel/extensions/sql_comments.rb +2 -2
- 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.rb +3 -1
- data/lib/sequel/model/associations.rb +403 -69
- data/lib/sequel/model/base.rb +170 -90
- data/lib/sequel/model/plugins.rb +105 -0
- data/lib/sequel/plugins/after_initialize.rb +1 -1
- data/lib/sequel/plugins/association_dependencies.rb +3 -3
- 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 +74 -22
- data/lib/sequel/plugins/association_proxies.rb +6 -2
- data/lib/sequel/plugins/auto_validations.rb +36 -17
- 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 +62 -34
- data/lib/sequel/plugins/composition.rb +13 -9
- data/lib/sequel/plugins/csv_serializer.rb +28 -9
- data/lib/sequel/plugins/defaults_setter.rb +2 -2
- data/lib/sequel/plugins/dirty.rb +60 -22
- data/lib/sequel/plugins/eager_graph_eager.rb +139 -0
- data/lib/sequel/plugins/empty_failure_backtraces.rb +38 -0
- data/lib/sequel/plugins/finder.rb +2 -2
- data/lib/sequel/plugins/forbid_lazy_load.rb +216 -0
- data/lib/sequel/plugins/hook_class_methods.rb +17 -5
- data/lib/sequel/plugins/insert_conflict.rb +72 -0
- data/lib/sequel/plugins/instance_specific_default.rb +113 -0
- data/lib/sequel/plugins/inverted_subsets.rb +2 -2
- data/lib/sequel/plugins/json_serializer.rb +21 -14
- data/lib/sequel/plugins/lazy_attributes.rb +1 -1
- data/lib/sequel/plugins/list.rb +22 -10
- data/lib/sequel/plugins/many_through_many.rb +1 -1
- data/lib/sequel/plugins/nested_attributes.rb +27 -5
- data/lib/sequel/plugins/pg_array_associations.rb +12 -9
- data/lib/sequel/plugins/pg_auto_constraint_validations.rb +149 -61
- data/lib/sequel/plugins/prepared_statements.rb +6 -12
- data/lib/sequel/plugins/prepared_statements_safe.rb +1 -3
- data/lib/sequel/plugins/rcte_tree.rb +20 -22
- data/lib/sequel/plugins/sharding.rb +13 -7
- data/lib/sequel/plugins/single_table_inheritance.rb +20 -15
- data/lib/sequel/plugins/skip_saving_columns.rb +108 -0
- data/lib/sequel/plugins/static_cache.rb +36 -17
- 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/subset_conditions.rb +2 -2
- data/lib/sequel/plugins/tactical_eager_loading.rb +73 -2
- data/lib/sequel/plugins/throw_failures.rb +110 -0
- data/lib/sequel/plugins/tree.rb +49 -31
- data/lib/sequel/plugins/typecast_on_load.rb +3 -2
- data/lib/sequel/plugins/validation_class_methods.rb +11 -5
- data/lib/sequel/plugins/validation_helpers.rb +2 -2
- data/lib/sequel/sql.rb +120 -30
- data/lib/sequel/timezones.rb +55 -14
- data/lib/sequel/version.rb +6 -1
- metadata +101 -361
- 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 -1041
- data/spec/adapters/oracle_spec.rb +0 -327
- data/spec/adapters/postgres_spec.rb +0 -4000
- data/spec/adapters/spec_helper.rb +0 -43
- data/spec/adapters/sqlanywhere_spec.rb +0 -97
- data/spec/adapters/sqlite_spec.rb +0 -600
- data/spec/bin_spec.rb +0 -269
- data/spec/core/connection_pool_spec.rb +0 -1228
- data/spec/core/database_spec.rb +0 -2673
- data/spec/core/dataset_spec.rb +0 -5419
- data/spec/core/deprecated_spec.rb +0 -70
- data/spec/core/expression_filters_spec.rb +0 -1344
- data/spec/core/mock_adapter_spec.rb +0 -722
- data/spec/core/object_graph_spec.rb +0 -306
- 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 -1820
- data/spec/core/spec_helper.rb +0 -23
- data/spec/core/version_spec.rb +0 -7
- data/spec/core_extensions_spec.rb +0 -762
- 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 -24
- 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 -202
- 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/class_table_inheritance_spec.rb +0 -568
- 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 -133
- data/spec/extensions/connection_validator_spec.rb +0 -127
- data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
- data/spec/extensions/constraint_validations_spec.rb +0 -395
- 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 -141
- 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/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/eval_inspect_spec.rb +0 -74
- 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 -380
- 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 -275
- 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 -840
- 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 -109
- data/spec/extensions/nested_attributes_spec.rb +0 -703
- 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 -165
- data/spec/extensions/pg_enum_spec.rb +0 -113
- 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 -487
- 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 -182
- 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 -868
- 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 -61
- 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 -410
- 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 -141
- data/spec/extensions/thread_local_timezones_spec.rb +0 -67
- 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 -284
- 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 -58
- data/spec/integration/associations_test.rb +0 -2513
- data/spec/integration/database_test.rb +0 -113
- data/spec/integration/dataset_test.rb +0 -1880
- 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 -2302
- data/spec/integration/prepared_statement_test.rb +0 -398
- data/spec/integration/schema_test.rb +0 -869
- data/spec/integration/spec_helper.rb +0 -64
- data/spec/integration/timezone_test.rb +0 -86
- data/spec/integration/transaction_test.rb +0 -354
- data/spec/integration/type_test.rb +0 -127
- data/spec/model/association_reflection_spec.rb +0 -803
- data/spec/model/associations_spec.rb +0 -4538
- data/spec/model/base_spec.rb +0 -817
- 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 -2262
- data/spec/model/hooks_spec.rb +0 -370
- data/spec/model/inflector_spec.rb +0 -26
- data/spec/model/model_spec.rb +0 -953
- data/spec/model/plugins_spec.rb +0 -318
- data/spec/model/record_spec.rb +0 -2107
- data/spec/model/spec_helper.rb +0 -45
- data/spec/model/validations_spec.rb +0 -193
- 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,7 +55,6 @@ module Sequel
|
|
|
55
55
|
|
|
56
56
|
begin
|
|
57
57
|
db = c.new(opts)
|
|
58
|
-
db.test_connection if db.send(:typecast_value_boolean, opts.fetch(:test, true))
|
|
59
58
|
if block_given?
|
|
60
59
|
return yield(db)
|
|
61
60
|
end
|
|
@@ -248,6 +247,12 @@ module Sequel
|
|
|
248
247
|
end
|
|
249
248
|
|
|
250
249
|
if RUBY_ENGINE == 'ruby' && RUBY_VERSION < '2.5'
|
|
250
|
+
# :nocov:
|
|
251
|
+
def synchronize(server=nil)
|
|
252
|
+
@pool.hold(server || :default){|conn| yield conn}
|
|
253
|
+
end
|
|
254
|
+
# :nocov:
|
|
255
|
+
else
|
|
251
256
|
# Acquires a database connection, yielding it to the passed block. This is
|
|
252
257
|
# useful if you want to make sure the same connection is used for all
|
|
253
258
|
# database queries in the block. It is also useful if you want to gain
|
|
@@ -260,15 +265,9 @@ module Sequel
|
|
|
260
265
|
# DB.synchronize do |conn|
|
|
261
266
|
# # ...
|
|
262
267
|
# end
|
|
263
|
-
def synchronize(server=nil)
|
|
264
|
-
@pool.hold(server || :default){|conn| yield conn}
|
|
265
|
-
end
|
|
266
|
-
else
|
|
267
|
-
# :nocov:
|
|
268
268
|
def synchronize(server=nil, &block)
|
|
269
269
|
@pool.hold(server || :default, &block)
|
|
270
270
|
end
|
|
271
|
-
# :nocov:
|
|
272
271
|
end
|
|
273
272
|
|
|
274
273
|
# Attempts to acquire a database connection. Returns true if successful.
|
|
@@ -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
|
@@ -27,7 +27,7 @@ module Sequel
|
|
|
27
27
|
:blob=>Sequel::SQL::Blob}.freeze
|
|
28
28
|
|
|
29
29
|
# Nested hook Proc; each new hook Proc just wraps the previous one.
|
|
30
|
-
@initialize_hook =
|
|
30
|
+
@initialize_hook = proc{|db| }
|
|
31
31
|
|
|
32
32
|
# Register a hook that will be run when a new Database is instantiated. It is
|
|
33
33
|
# called with the new database handle.
|
|
@@ -35,7 +35,7 @@ module Sequel
|
|
|
35
35
|
raise Error, "must provide block to after_initialize" unless block
|
|
36
36
|
Sequel.synchronize do
|
|
37
37
|
previous = @initialize_hook
|
|
38
|
-
@initialize_hook =
|
|
38
|
+
@initialize_hook = proc do |db|
|
|
39
39
|
previous.call(db)
|
|
40
40
|
block.call(db)
|
|
41
41
|
end
|
|
@@ -97,20 +97,30 @@ module Sequel
|
|
|
97
97
|
# Accepts the following options:
|
|
98
98
|
# :cache_schema :: Whether schema should be cached for this Database instance
|
|
99
99
|
# :default_string_column_size :: The default size of string columns, 255 by default.
|
|
100
|
+
# :extensions :: Extensions to load into this Database instance. Can be a symbol, array of symbols,
|
|
101
|
+
# or string with extensions separated by columns. These extensions are loaded after
|
|
102
|
+
# connections are made by the :preconnect option.
|
|
100
103
|
# :keep_reference :: Whether to keep a reference to this instance in Sequel::DATABASES, true by default.
|
|
101
104
|
# :logger :: A specific logger to use.
|
|
102
105
|
# :loggers :: An array of loggers to use.
|
|
103
106
|
# :log_connection_info :: Whether connection information should be logged when logging queries.
|
|
104
107
|
# :log_warn_duration :: The number of elapsed seconds after which queries should be logged at warn level.
|
|
105
|
-
# :name :: A name to use for the Database object.
|
|
106
|
-
# :preconnect ::
|
|
107
|
-
#
|
|
108
|
+
# :name :: A name to use for the Database object, displayed in PoolTimeout .
|
|
109
|
+
# :preconnect :: Automatically create the maximum number of connections, so that they don't
|
|
110
|
+
# need to be created as needed. This is useful when connecting takes a long time
|
|
111
|
+
# and you want to avoid possible latency during runtime.
|
|
112
|
+
# Set to :concurrently to create the connections in separate threads. Otherwise
|
|
113
|
+
# they'll be created sequentially.
|
|
114
|
+
# :preconnect_extensions :: Similar to the :extensions option, but loads the extensions before the
|
|
115
|
+
# connections are made by the :preconnect option.
|
|
108
116
|
# :quote_identifiers :: Whether to quote identifiers.
|
|
109
117
|
# :servers :: A hash specifying a server/shard specific options, keyed by shard symbol .
|
|
110
118
|
# :single_threaded :: Whether to use a single-threaded connection pool.
|
|
111
119
|
# :sql_log_level :: Method to use to log SQL to a logger, :info by default.
|
|
112
120
|
#
|
|
113
|
-
# All options given are also passed to the connection pool.
|
|
121
|
+
# All options given are also passed to the connection pool. Additional options respected by
|
|
122
|
+
# the connection pool are :after_connect, :connect_sqls, :max_connections, :pool_timeout,
|
|
123
|
+
# :servers, and :servers_hash. See the connection pool documentation for details.
|
|
114
124
|
def initialize(opts = OPTS)
|
|
115
125
|
@opts ||= opts
|
|
116
126
|
@opts = connection_pool_default_options.merge(@opts)
|
|
@@ -143,26 +153,23 @@ module Sequel
|
|
|
143
153
|
reset_default_dataset
|
|
144
154
|
adapter_initialize
|
|
145
155
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if typecast_value_boolean(@opts[:preconnect]) && @pool.respond_to?(:preconnect, true)
|
|
151
|
-
concurrent = typecast_value_string(@opts[:preconnect]) == "concurrently"
|
|
152
|
-
@pool.send(:preconnect, concurrent)
|
|
153
|
-
end
|
|
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)
|
|
154
160
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
initialize_load_extensions(:preconnect_extensions)
|
|
162
|
+
|
|
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
|
+
|
|
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
|
|
166
173
|
end
|
|
167
174
|
end
|
|
168
175
|
|
|
@@ -183,7 +190,9 @@ module Sequel
|
|
|
183
190
|
|
|
184
191
|
# Disallow dup/clone for Database instances
|
|
185
192
|
undef_method :dup, :clone, :initialize_copy
|
|
193
|
+
# :nocov:
|
|
186
194
|
if RUBY_VERSION >= '1.9.3'
|
|
195
|
+
# :nocov:
|
|
187
196
|
undef_method :initialize_clone, :initialize_dup
|
|
188
197
|
end
|
|
189
198
|
|
|
@@ -281,7 +290,7 @@ module Sequel
|
|
|
281
290
|
end
|
|
282
291
|
|
|
283
292
|
# Whether this database instance uses multiple servers, either for sharding
|
|
284
|
-
# or for
|
|
293
|
+
# or for primary/replica configurations.
|
|
285
294
|
def sharded?
|
|
286
295
|
@sharded
|
|
287
296
|
end
|
|
@@ -412,6 +421,22 @@ module Sequel
|
|
|
412
421
|
opts[:disconnect]
|
|
413
422
|
end
|
|
414
423
|
|
|
424
|
+
# Load extensions during initialization from the given key in opts.
|
|
425
|
+
def initialize_load_extensions(key)
|
|
426
|
+
case exts = @opts[key]
|
|
427
|
+
when String
|
|
428
|
+
extension(*exts.split(',').map(&:to_sym))
|
|
429
|
+
when Array
|
|
430
|
+
extension(*exts)
|
|
431
|
+
when Symbol
|
|
432
|
+
extension(exts)
|
|
433
|
+
when nil
|
|
434
|
+
# nothing
|
|
435
|
+
else
|
|
436
|
+
raise Error, "unsupported Database #{key.inspect} option: #{@opts[key].inspect}"
|
|
437
|
+
end
|
|
438
|
+
end
|
|
439
|
+
|
|
415
440
|
# Convert the given exception to an appropriate Sequel::DatabaseError
|
|
416
441
|
# subclass, keeping message and backtrace.
|
|
417
442
|
def raise_error(exception, opts=OPTS)
|
|
@@ -422,6 +447,19 @@ module Sequel
|
|
|
422
447
|
end
|
|
423
448
|
end
|
|
424
449
|
|
|
450
|
+
# Swallow database errors, unless they are connect/disconnect errors.
|
|
451
|
+
def swallow_database_error
|
|
452
|
+
yield
|
|
453
|
+
rescue Sequel::DatabaseDisconnectError, DatabaseConnectionError
|
|
454
|
+
# Always raise disconnect errors
|
|
455
|
+
raise
|
|
456
|
+
rescue Sequel::DatabaseError
|
|
457
|
+
# Don't raise other database errors.
|
|
458
|
+
nil
|
|
459
|
+
# else
|
|
460
|
+
# Don't rescue other exceptions, they will be raised normally.
|
|
461
|
+
end
|
|
462
|
+
|
|
425
463
|
# Typecast the value to an SQL::Blob
|
|
426
464
|
def typecast_value_blob(value)
|
|
427
465
|
value.is_a?(Sequel::SQL::Blob) ? value : Sequel::SQL::Blob.new(value)
|
|
@@ -460,13 +498,11 @@ module Sequel
|
|
|
460
498
|
|
|
461
499
|
if RUBY_VERSION >= '2.4'
|
|
462
500
|
# Typecast a string to a BigDecimal
|
|
463
|
-
|
|
464
|
-
BigDecimal.new(value)
|
|
465
|
-
end
|
|
501
|
+
alias _typecast_value_string_to_decimal BigDecimal
|
|
466
502
|
else
|
|
467
503
|
# :nocov:
|
|
468
504
|
def _typecast_value_string_to_decimal(value)
|
|
469
|
-
d = BigDecimal
|
|
505
|
+
d = BigDecimal(value)
|
|
470
506
|
if d.zero?
|
|
471
507
|
# BigDecimal parsing is loose by default, returning a 0 value for
|
|
472
508
|
# invalid input. If a zero value is received, use Float to check
|
|
@@ -488,7 +524,7 @@ module Sequel
|
|
|
488
524
|
when BigDecimal
|
|
489
525
|
value
|
|
490
526
|
when Numeric
|
|
491
|
-
BigDecimal
|
|
527
|
+
BigDecimal(value.to_s)
|
|
492
528
|
when String
|
|
493
529
|
_typecast_value_string_to_decimal(value)
|
|
494
530
|
else
|
|
@@ -497,9 +533,7 @@ module Sequel
|
|
|
497
533
|
end
|
|
498
534
|
|
|
499
535
|
# Typecast the value to a Float
|
|
500
|
-
|
|
501
|
-
Float(value)
|
|
502
|
-
end
|
|
536
|
+
alias typecast_value_float Float
|
|
503
537
|
|
|
504
538
|
# Typecast the value to an Integer
|
|
505
539
|
def typecast_value_integer(value)
|
|
@@ -32,7 +32,7 @@ module Sequel
|
|
|
32
32
|
#
|
|
33
33
|
# DB[:items].where(id: 1).prepare(:first, :sa)
|
|
34
34
|
# DB.call(:sa) # SELECT * FROM items WHERE id = 1
|
|
35
|
-
def call(ps_name, hash=
|
|
35
|
+
def call(ps_name, hash=OPTS, &block)
|
|
36
36
|
prepared_statement(ps_name).call(hash, &block)
|
|
37
37
|
end
|
|
38
38
|
|
|
@@ -240,7 +240,7 @@ module Sequel
|
|
|
240
240
|
when :time
|
|
241
241
|
Sequel.string_to_time(default)
|
|
242
242
|
when :decimal
|
|
243
|
-
BigDecimal
|
|
243
|
+
BigDecimal(default)
|
|
244
244
|
end
|
|
245
245
|
end
|
|
246
246
|
|
|
@@ -325,13 +325,13 @@ 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
|
|
332
332
|
when /\A(bool(ean)?)\z/io
|
|
333
333
|
:boolean
|
|
334
|
-
when /\A(real|float
|
|
334
|
+
when /\A(real|float( unsigned)?|double( precision)?|double\(\d+,\d+\)( unsigned)?)\z/io
|
|
335
335
|
:float
|
|
336
336
|
when /\A(?:(?:(?:num(?:ber|eric)?|decimal)(?:\(\d+,\s*(\d+|false|true)\))?))\z/io
|
|
337
337
|
$1 && ['0', 'false'].include?($1) ? :integer : :decimal
|
|
@@ -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
|
|
@@ -67,7 +66,7 @@ module Sequel
|
|
|
67
66
|
method = type.to_s
|
|
68
67
|
end
|
|
69
68
|
|
|
70
|
-
define_method(method){|name, opts=
|
|
69
|
+
define_method(method){|name, opts=OPTS| column(name, type, opts)}
|
|
71
70
|
end
|
|
72
71
|
nil
|
|
73
72
|
end
|
|
@@ -81,7 +80,8 @@ module Sequel
|
|
|
81
80
|
constraint(nil, *args, &block)
|
|
82
81
|
end
|
|
83
82
|
|
|
84
|
-
# Add a column with the given name, type, and opts
|
|
83
|
+
# Add a column with the given name, type, and opts:
|
|
84
|
+
#
|
|
85
85
|
# column :num, :integer
|
|
86
86
|
# # num INTEGER
|
|
87
87
|
#
|
|
@@ -109,6 +109,9 @@ module Sequel
|
|
|
109
109
|
# yet exist on referenced table (but will exist before the transaction commits).
|
|
110
110
|
# Basically it adds DEFERRABLE INITIALLY DEFERRED on key creation.
|
|
111
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+).
|
|
112
115
|
# :index :: Create an index on this column. If given a hash, use the hash as the
|
|
113
116
|
# options for the index.
|
|
114
117
|
# :key :: For foreign key columns, the column in the associated table
|
|
@@ -122,18 +125,30 @@ module Sequel
|
|
|
122
125
|
# :on_update :: Specify the behavior of this column when being updated
|
|
123
126
|
# (:restrict, :cascade, :set_null, :set_default, :no_action).
|
|
124
127
|
# :primary_key :: Make the column as a single primary key column. This should not
|
|
125
|
-
# be used if you
|
|
128
|
+
# be used if you want a single autoincrementing primary key column
|
|
126
129
|
# (use the primary_key method in that case).
|
|
127
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.
|
|
128
133
|
# :type :: Overrides the type given as the argument. Generally not used by column
|
|
129
134
|
# itself, but can be passed as an option to other methods that call column.
|
|
130
135
|
# :unique :: Mark the column as unique, generally has the same effect as
|
|
131
136
|
# creating a unique index on the column.
|
|
132
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.
|
|
144
|
+
#
|
|
145
|
+
# MySQL specific options:
|
|
146
|
+
# :generated_type :: Set the type of column when using :generated_always_as,
|
|
147
|
+
# should be :virtual or :stored to force a type.
|
|
133
148
|
def column(name, type, opts = OPTS)
|
|
134
149
|
columns << {:name => name, :type => type}.merge!(opts)
|
|
135
150
|
if index_opts = opts[:index]
|
|
136
|
-
index(name, index_opts.is_a?(Hash) ? index_opts :
|
|
151
|
+
index(name, index_opts.is_a?(Hash) ? index_opts : OPTS)
|
|
137
152
|
end
|
|
138
153
|
nil
|
|
139
154
|
end
|
|
@@ -152,7 +167,7 @@ module Sequel
|
|
|
152
167
|
nil
|
|
153
168
|
end
|
|
154
169
|
|
|
155
|
-
# Add a foreign key in the table that references another table. See column
|
|
170
|
+
# Add a foreign key in the table that references another table. See #column
|
|
156
171
|
# for available options.
|
|
157
172
|
#
|
|
158
173
|
# foreign_key(:artist_id) # artist_id INTEGER
|
|
@@ -216,6 +231,9 @@ module Sequel
|
|
|
216
231
|
# operations on the table while the index is being
|
|
217
232
|
# built.
|
|
218
233
|
# :opclass :: Use a specific operator class in the index.
|
|
234
|
+
# :include :: Include additional column values in the index, without
|
|
235
|
+
# actually indexing on those values (PostgreSQL 11+).
|
|
236
|
+
# :tablespace :: Specify tablespace for index.
|
|
219
237
|
#
|
|
220
238
|
# Microsoft SQL Server specific options:
|
|
221
239
|
#
|
|
@@ -232,7 +250,7 @@ module Sequel
|
|
|
232
250
|
nil
|
|
233
251
|
end
|
|
234
252
|
|
|
235
|
-
# Add a column with the given type, name, and opts. See
|
|
253
|
+
# Add a column with the given type, name, and opts. See #column for available
|
|
236
254
|
# options.
|
|
237
255
|
def method_missing(type, name = nil, opts = OPTS)
|
|
238
256
|
name ? column(name, type, opts) : super
|
|
@@ -311,7 +329,7 @@ module Sequel
|
|
|
311
329
|
|
|
312
330
|
# Add a composite primary key constraint
|
|
313
331
|
def composite_primary_key(columns, *args)
|
|
314
|
-
opts = args.pop ||
|
|
332
|
+
opts = args.pop || OPTS
|
|
315
333
|
constraints << {:type => :primary_key, :columns => columns}.merge!(opts)
|
|
316
334
|
nil
|
|
317
335
|
end
|
|
@@ -347,7 +365,8 @@ module Sequel
|
|
|
347
365
|
end
|
|
348
366
|
|
|
349
367
|
# Add a column with the given name, type, and opts.
|
|
350
|
-
# See CreateTableGenerator#column for the available options
|
|
368
|
+
# See CreateTableGenerator#column for the available options (except for +:index+, use a
|
|
369
|
+
# separate +add_index+ call to add an index for the column).
|
|
351
370
|
#
|
|
352
371
|
# add_column(:name, String) # ADD COLUMN name varchar(255)
|
|
353
372
|
#
|
|
@@ -389,7 +408,8 @@ module Sequel
|
|
|
389
408
|
end
|
|
390
409
|
|
|
391
410
|
# Add a foreign key with the given name and referencing the given table.
|
|
392
|
-
# See CreateTableGenerator#column for the available options
|
|
411
|
+
# See CreateTableGenerator#column for the available options (except for +:index+, use a
|
|
412
|
+
# separate +add_index+ call to add an index for the column).
|
|
393
413
|
#
|
|
394
414
|
# You can also pass an array of column names for creating composite foreign
|
|
395
415
|
# keys. In this case, it will assume the columns exist and will only add
|
|
@@ -622,7 +642,7 @@ module Sequel
|
|
|
622
642
|
|
|
623
643
|
# Drop a composite foreign key constraint
|
|
624
644
|
def drop_composite_foreign_key(columns, opts)
|
|
625
|
-
@operations <<
|
|
645
|
+
@operations << opts.merge(:op => :drop_constraint, :type => :foreign_key, :columns => columns)
|
|
626
646
|
nil
|
|
627
647
|
end
|
|
628
648
|
end
|
|
@@ -80,7 +80,7 @@ module Sequel
|
|
|
80
80
|
# Create a join table using a hash of foreign keys to referenced
|
|
81
81
|
# table names. Example:
|
|
82
82
|
#
|
|
83
|
-
# create_join_table
|
|
83
|
+
# create_join_table(cat_id: :cats, dog_id: :dogs)
|
|
84
84
|
# # CREATE TABLE cats_dogs (
|
|
85
85
|
# # cat_id integer NOT NULL REFERENCES cats,
|
|
86
86
|
# # dog_id integer NOT NULL REFERENCES dogs,
|
|
@@ -93,6 +93,13 @@ module Sequel
|
|
|
93
93
|
# key ensures that entries in the table are unique, which is the typical
|
|
94
94
|
# desire for a join table.
|
|
95
95
|
#
|
|
96
|
+
# The default table name this will create is the sorted version of the two
|
|
97
|
+
# hash values, joined by an underscore. So the following two method calls
|
|
98
|
+
# create the same table:
|
|
99
|
+
#
|
|
100
|
+
# create_join_table(cat_id: :cats, dog_id: :dogs) # cats_dogs
|
|
101
|
+
# create_join_table(dog_id: :dogs, cat_id: :cats) # cats_dogs
|
|
102
|
+
#
|
|
96
103
|
# You can provide column options by making the values in the hash
|
|
97
104
|
# be option hashes, so long as the option hashes have a :table
|
|
98
105
|
# entry giving the table referenced:
|
|
@@ -121,7 +128,7 @@ module Sequel
|
|
|
121
128
|
foreign_key(key, v)
|
|
122
129
|
end
|
|
123
130
|
primary_key(keys) unless options[:no_primary_key]
|
|
124
|
-
index(keys.reverse, options[:index_options] ||
|
|
131
|
+
index(keys.reverse, options[:index_options] || OPTS) unless options[:no_index]
|
|
125
132
|
end
|
|
126
133
|
nil
|
|
127
134
|
end
|
|
@@ -174,6 +181,7 @@ module Sequel
|
|
|
174
181
|
# where keys are option names and values are option values. Note
|
|
175
182
|
# that option names are unquoted, so you should not use untrusted
|
|
176
183
|
# keys.
|
|
184
|
+
# :tablespace :: The tablespace to use for the table.
|
|
177
185
|
#
|
|
178
186
|
# See <tt>Schema::CreateTableGenerator</tt> and the {"Schema Modification" guide}[rdoc-ref:doc/schema_modification.rdoc].
|
|
179
187
|
def create_table(name, options=OPTS, &block)
|
|
@@ -232,7 +240,7 @@ module Sequel
|
|
|
232
240
|
if supports_create_or_replace_view?
|
|
233
241
|
options = options.merge(:replace=>true)
|
|
234
242
|
else
|
|
235
|
-
drop_view(name)
|
|
243
|
+
swallow_database_error{drop_view(name)}
|
|
236
244
|
end
|
|
237
245
|
|
|
238
246
|
create_view(name, source, options)
|
|
@@ -274,6 +282,7 @@ module Sequel
|
|
|
274
282
|
# in a subquery, if you are providing a Dataset as the source
|
|
275
283
|
# argument, if should probably call the union method with the
|
|
276
284
|
# all: true and from_self: false options.
|
|
285
|
+
# :tablespace :: The tablespace to use for materialized views.
|
|
277
286
|
def create_view(name, source, options = OPTS)
|
|
278
287
|
execute_ddl(create_view_sql(name, source, options))
|
|
279
288
|
remove_cached_schema(name)
|
|
@@ -314,7 +323,7 @@ module Sequel
|
|
|
314
323
|
# DB.drop_table(:posts, :comments)
|
|
315
324
|
# DB.drop_table(:posts, :comments, cascade: true)
|
|
316
325
|
def drop_table(*names)
|
|
317
|
-
options = names.last.is_a?(Hash) ? names.pop :
|
|
326
|
+
options = names.last.is_a?(Hash) ? names.pop : OPTS
|
|
318
327
|
names.each do |n|
|
|
319
328
|
execute_ddl(drop_table_sql(n, options))
|
|
320
329
|
remove_cached_schema(n)
|
|
@@ -329,7 +338,7 @@ module Sequel
|
|
|
329
338
|
# # SELECT NULL FROM a LIMIT 1 -- check existence
|
|
330
339
|
# # DROP TABLE a -- if it already exists
|
|
331
340
|
def drop_table?(*names)
|
|
332
|
-
options = names.last.is_a?(Hash) ? names.pop :
|
|
341
|
+
options = names.last.is_a?(Hash) ? names.pop : OPTS
|
|
333
342
|
if supports_drop_table_if_exists?
|
|
334
343
|
options = options.merge(:if_exists=>true)
|
|
335
344
|
names.each do |name|
|
|
@@ -357,7 +366,7 @@ module Sequel
|
|
|
357
366
|
# PostgreSQL specific options:
|
|
358
367
|
# :materialized :: Drop a materialized view.
|
|
359
368
|
def drop_view(*names)
|
|
360
|
-
options = names.last.is_a?(Hash) ? names.pop :
|
|
369
|
+
options = names.last.is_a?(Hash) ? names.pop : OPTS
|
|
361
370
|
names.each do |n|
|
|
362
371
|
execute_ddl(drop_view_sql(n, options))
|
|
363
372
|
remove_cached_schema(n)
|
|
@@ -485,7 +494,9 @@ module Sequel
|
|
|
485
494
|
when :drop_index
|
|
486
495
|
drop_index_sql(table, op)
|
|
487
496
|
else
|
|
488
|
-
|
|
497
|
+
if sql = alter_table_op_sql(table, op)
|
|
498
|
+
"ALTER TABLE #{quote_schema_table(table)} #{sql}"
|
|
499
|
+
end
|
|
489
500
|
end
|
|
490
501
|
end
|
|
491
502
|
|
|
@@ -577,6 +588,7 @@ module Sequel
|
|
|
577
588
|
sql << " CONSTRAINT #{quote_identifier(name)}"
|
|
578
589
|
end
|
|
579
590
|
sql << ' PRIMARY KEY'
|
|
591
|
+
constraint_deferrable_sql_append(sql, column[:primary_key_deferrable])
|
|
580
592
|
end
|
|
581
593
|
end
|
|
582
594
|
|
|
@@ -597,6 +609,7 @@ module Sequel
|
|
|
597
609
|
sql << " CONSTRAINT #{quote_identifier(name)}"
|
|
598
610
|
end
|
|
599
611
|
sql << ' UNIQUE'
|
|
612
|
+
constraint_deferrable_sql_append(sql, column[:unique_deferrable])
|
|
600
613
|
end
|
|
601
614
|
end
|
|
602
615
|
|
|
@@ -800,23 +813,20 @@ module Sequel
|
|
|
800
813
|
# Proxy the filter_expr call to the dataset, used for creating constraints.
|
|
801
814
|
# Support passing Proc arguments as blocks, as well as treating plain strings
|
|
802
815
|
# as literal strings, so that previous migrations that used this API do not break.
|
|
803
|
-
def filter_expr(
|
|
804
|
-
if
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
elsif arg.length > 1
|
|
815
|
-
args = [Sequel.&(*arg)]
|
|
816
|
-
end
|
|
816
|
+
def filter_expr(arg=nil, &block)
|
|
817
|
+
if arg.is_a?(Proc) && !block
|
|
818
|
+
block = arg
|
|
819
|
+
arg = nil
|
|
820
|
+
elsif arg.is_a?(String)
|
|
821
|
+
arg = Sequel.lit(arg)
|
|
822
|
+
elsif arg.is_a?(Array)
|
|
823
|
+
if arg.first.is_a?(String)
|
|
824
|
+
arg = Sequel.lit(*arg)
|
|
825
|
+
elsif arg.length > 1
|
|
826
|
+
arg = Sequel.&(*arg)
|
|
817
827
|
end
|
|
818
828
|
end
|
|
819
|
-
schema_utility_dataset.literal(schema_utility_dataset.send(:filter_expr,
|
|
829
|
+
schema_utility_dataset.literal(schema_utility_dataset.send(:filter_expr, arg, &block))
|
|
820
830
|
end
|
|
821
831
|
|
|
822
832
|
# SQL statement for creating an index for the table with the given name
|