sequel 5.28.0 → 5.33.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +64 -1922
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/doc/advanced_associations.rdoc +4 -4
- data/doc/association_basics.rdoc +3 -3
- data/doc/code_order.rdoc +12 -2
- data/doc/model_dataset_method_design.rdoc +1 -1
- data/doc/postgresql.rdoc +71 -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/testing.rdoc +1 -1
- data/lib/sequel/adapters/postgres.rb +5 -1
- data/lib/sequel/adapters/shared/access.rb +6 -6
- data/lib/sequel/adapters/shared/mssql.rb +5 -5
- data/lib/sequel/adapters/shared/mysql.rb +10 -10
- data/lib/sequel/adapters/shared/oracle.rb +16 -16
- data/lib/sequel/adapters/shared/postgres.rb +169 -14
- data/lib/sequel/adapters/shared/sqlanywhere.rb +9 -9
- data/lib/sequel/adapters/shared/sqlite.rb +32 -5
- data/lib/sequel/adapters/tinytds.rb +1 -1
- data/lib/sequel/connection_pool/sharded_threaded.rb +2 -2
- data/lib/sequel/connection_pool/threaded.rb +1 -1
- data/lib/sequel/core.rb +318 -314
- data/lib/sequel/database/query.rb +1 -1
- data/lib/sequel/database/schema_generator.rb +1 -1
- data/lib/sequel/database/transactions.rb +8 -12
- data/lib/sequel/dataset/misc.rb +2 -2
- data/lib/sequel/extensions/connection_expiration.rb +2 -2
- data/lib/sequel/extensions/connection_validator.rb +2 -2
- data/lib/sequel/extensions/fiber_concurrency.rb +24 -0
- data/lib/sequel/extensions/index_caching.rb +9 -7
- data/lib/sequel/extensions/integer64.rb +2 -0
- data/lib/sequel/extensions/migration.rb +1 -1
- data/lib/sequel/extensions/pg_enum.rb +5 -2
- data/lib/sequel/extensions/pg_hstore.rb +6 -0
- data/lib/sequel/extensions/pg_inet.rb +13 -5
- data/lib/sequel/extensions/pg_interval.rb +2 -0
- data/lib/sequel/extensions/pg_range.rb +2 -0
- data/lib/sequel/extensions/pg_timestamptz.rb +2 -0
- data/lib/sequel/extensions/run_transaction_hooks.rb +72 -0
- data/lib/sequel/extensions/schema_dumper.rb +10 -4
- data/lib/sequel/extensions/server_block.rb +3 -3
- data/lib/sequel/model/associations.rb +18 -5
- data/lib/sequel/model/base.rb +60 -53
- data/lib/sequel/model/plugins.rb +1 -0
- data/lib/sequel/plugins/association_lazy_eager_option.rb +66 -0
- data/lib/sequel/plugins/association_multi_add_remove.rb +2 -0
- data/lib/sequel/plugins/association_proxies.rb +2 -0
- data/lib/sequel/plugins/boolean_subsets.rb +4 -1
- data/lib/sequel/plugins/class_table_inheritance.rb +26 -26
- data/lib/sequel/plugins/dirty.rb +13 -13
- data/lib/sequel/plugins/empty_failure_backtraces.rb +38 -0
- data/lib/sequel/plugins/forbid_lazy_load.rb +214 -0
- data/lib/sequel/plugins/json_serializer.rb +18 -11
- data/lib/sequel/plugins/single_table_inheritance.rb +15 -15
- data/lib/sequel/plugins/skip_saving_columns.rb +108 -0
- data/lib/sequel/plugins/subclasses.rb +2 -0
- data/lib/sequel/plugins/throw_failures.rb +1 -1
- data/lib/sequel/timezones.rb +6 -4
- data/lib/sequel/version.rb +1 -1
- metadata +18 -367
- 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 -828
- data/spec/adapters/mysql_spec.rb +0 -1060
- data/spec/adapters/oracle_spec.rb +0 -371
- data/spec/adapters/postgres_spec.rb +0 -4476
- 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 -2915
- data/spec/core/dataset_spec.rb +0 -5547
- data/spec/core/deprecated_spec.rb +0 -70
- data/spec/core/expression_filters_spec.rb +0 -1498
- 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 -1844
- 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/any_not_empty_spec.rb +0 -23
- data/spec/extensions/arbitrary_servers_spec.rb +0 -109
- data/spec/extensions/association_dependencies_spec.rb +0 -125
- data/spec/extensions/association_multi_add_remove_spec.rb +0 -1041
- 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 -222
- 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/exclude_or_null_spec.rb +0 -15
- 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_conflict_spec.rb +0 -103
- 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 -218
- data/spec/extensions/nested_attributes_spec.rb +0 -815
- 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 -209
- 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 -356
- data/spec/extensions/pg_json_spec.rb +0 -451
- 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 -600
- 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 -387
- 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 -135
- data/spec/extensions/server_logging_spec.rb +0 -45
- data/spec/extensions/sharding_spec.rb +0 -197
- 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 -70
- 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_cache_spec.rb +0 -35
- 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 -2037
- 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 -2423
- data/spec/integration/prepared_statement_test.rb +0 -405
- data/spec/integration/schema_test.rb +0 -903
- data/spec/integration/spec_helper.rb +0 -71
- 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
@@ -14,6 +14,7 @@ module Sequel
|
|
14
14
|
def schema_parse_table(*)
|
15
15
|
[]
|
16
16
|
end
|
17
|
+
singleton_class.send(:private, :schema_parse_table)
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
@@ -37,6 +38,10 @@ module Sequel
|
|
37
38
|
# booleans be stored as integers, but historically Sequel has used 't'/'f'.
|
38
39
|
attr_accessor :integer_booleans
|
39
40
|
|
41
|
+
# Whether to keep CURRENT_TIMESTAMP and similar expressions in UTC. By
|
42
|
+
# default, the expressions are converted to localtime.
|
43
|
+
attr_accessor :current_timestamp_utc
|
44
|
+
|
40
45
|
# A symbol signifying the value of the default transaction mode
|
41
46
|
attr_reader :transaction_mode
|
42
47
|
|
@@ -184,7 +189,7 @@ module Sequel
|
|
184
189
|
|
185
190
|
# Dataset used for parsing schema
|
186
191
|
def _parse_pragma_ds(table_name, opts)
|
187
|
-
metadata_dataset.with_sql("PRAGMA
|
192
|
+
metadata_dataset.with_sql("PRAGMA table_#{'x' if sqlite_version > 33100}info(?)", input_identifier_meth(opts[:dataset]).call(table_name))
|
188
193
|
end
|
189
194
|
|
190
195
|
# Run all alter_table commands in a transaction. This is technically only
|
@@ -252,7 +257,12 @@ module Sequel
|
|
252
257
|
when :drop_constraint
|
253
258
|
case op[:type]
|
254
259
|
when :primary_key
|
255
|
-
duplicate_table(table)
|
260
|
+
duplicate_table(table) do |columns|
|
261
|
+
columns.each do |s|
|
262
|
+
s[:unique] = false if s[:primary_key]
|
263
|
+
s[:primary_key] = s[:auto_increment] = nil
|
264
|
+
end
|
265
|
+
end
|
256
266
|
when :foreign_key
|
257
267
|
if op[:columns]
|
258
268
|
duplicate_table(table, :skip_foreign_key_columns=>op[:columns])
|
@@ -293,9 +303,15 @@ module Sequel
|
|
293
303
|
false
|
294
304
|
end
|
295
305
|
|
296
|
-
# Surround default with parens to appease SQLite
|
306
|
+
# Surround default with parens to appease SQLite. Add support for GENERATED ALWAYS AS.
|
297
307
|
def column_definition_default_sql(sql, column)
|
298
308
|
sql << " DEFAULT (#{literal(column[:default])})" if column.include?(:default)
|
309
|
+
if (generated = column[:generated_always_as])
|
310
|
+
if (generated_type = column[:generated_type]) && (generated_type == :stored || generated_type == :virtual)
|
311
|
+
generated_type = generated_type.to_s.upcase
|
312
|
+
end
|
313
|
+
sql << " GENERATED ALWAYS AS (#{literal(generated)}) #{generated_type}"
|
314
|
+
end
|
299
315
|
end
|
300
316
|
|
301
317
|
# Array of PRAGMA SQL statements based on the Database options that should be applied to
|
@@ -414,7 +430,7 @@ module Sequel
|
|
414
430
|
unless unique_columns.empty?
|
415
431
|
unique_columns.map!{|c| quote_identifier(c)}
|
416
432
|
def_columns.each do |c|
|
417
|
-
c[:unique] = true if unique_columns.include?(quote_identifier(c[:name]))
|
433
|
+
c[:unique] = true if unique_columns.include?(quote_identifier(c[:name])) && c[:unique] != false
|
418
434
|
end
|
419
435
|
end
|
420
436
|
|
@@ -460,6 +476,15 @@ module Sequel
|
|
460
476
|
def parse_pragma(table_name, opts)
|
461
477
|
pks = 0
|
462
478
|
sch = _parse_pragma_ds(table_name, opts).map do |row|
|
479
|
+
if sqlite_version > 33100
|
480
|
+
# table_xinfo PRAGMA used, remove hidden columns
|
481
|
+
# that are not generated columns
|
482
|
+
if row[:generated] = (row.delete(:hidden) != 0)
|
483
|
+
next unless row[:type].end_with?(' GENERATED ALWAYS')
|
484
|
+
row[:type] = row[:type].sub(' GENERATED ALWAYS', '')
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
463
488
|
row.delete(:cid)
|
464
489
|
row[:allow_null] = row.delete(:notnull).to_i == 0
|
465
490
|
row[:default] = row.delete(:dflt_value)
|
@@ -476,6 +501,8 @@ module Sequel
|
|
476
501
|
row
|
477
502
|
end
|
478
503
|
|
504
|
+
sch.compact!
|
505
|
+
|
479
506
|
if pks > 1
|
480
507
|
# SQLite does not allow use of auto increment for tables
|
481
508
|
# with composite primary keys, so remove auto_increment
|
@@ -592,7 +619,7 @@ module Sequel
|
|
592
619
|
# SQLite has CURRENT_TIMESTAMP and related constants in UTC instead
|
593
620
|
# of in localtime, so convert those constants to local time.
|
594
621
|
def constant_sql_append(sql, constant)
|
595
|
-
if c = CONSTANT_MAP[constant]
|
622
|
+
if (c = CONSTANT_MAP[constant]) && !db.current_timestamp_utc
|
596
623
|
sql << c
|
597
624
|
else
|
598
625
|
super
|
@@ -145,7 +145,7 @@ module Sequel
|
|
145
145
|
|
146
146
|
# Return true if the :conn argument is present and not active.
|
147
147
|
def disconnect_error?(e, opts)
|
148
|
-
super || (opts[:conn] && !opts[:conn].active?) || ((e.is_a?(::TinyTds::Error) && /\A(Attempt to initiate a new Adaptive Server operation with results pending|The request failed to run because the batch is aborted, this can be caused by abort signal sent from client|Adaptive Server connection timed out)/.match(e.message)))
|
148
|
+
super || (opts[:conn] && !opts[:conn].active?) || ((e.is_a?(::TinyTds::Error) && /\A(Attempt to initiate a new Adaptive Server operation with results pending|The request failed to run because the batch is aborted, this can be caused by abort signal sent from client|Adaptive Server connection timed out|DBPROCESS is dead or not enabled)/.match(e.message)))
|
149
149
|
end
|
150
150
|
|
151
151
|
# Dispose of any possible results of execution.
|
@@ -57,7 +57,7 @@ class Sequel::ShardedThreadedConnectionPool < Sequel::ThreadedConnectionPool
|
|
57
57
|
# it is yielding all of the connections, which means that until
|
58
58
|
# the method's block returns, the pool is locked.
|
59
59
|
def all_connections
|
60
|
-
t =
|
60
|
+
t = Sequel.current
|
61
61
|
sync do
|
62
62
|
@allocated.values.each do |threads|
|
63
63
|
threads.each do |thread, conn|
|
@@ -121,7 +121,7 @@ class Sequel::ShardedThreadedConnectionPool < Sequel::ThreadedConnectionPool
|
|
121
121
|
# connection can be acquired, a Sequel::PoolTimeout is raised.
|
122
122
|
def hold(server=:default)
|
123
123
|
server = pick_server(server)
|
124
|
-
t =
|
124
|
+
t = Sequel.current
|
125
125
|
if conn = owned_connection(t, server)
|
126
126
|
return yield(conn)
|
127
127
|
end
|
@@ -83,7 +83,7 @@ class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
|
|
83
83
|
# is available or the timeout expires. If the timeout expires before a
|
84
84
|
# connection can be acquired, a Sequel::PoolTimeout is raised.
|
85
85
|
def hold(server=nil)
|
86
|
-
t =
|
86
|
+
t = Sequel.current
|
87
87
|
if conn = owned_connection(t)
|
88
88
|
return yield(conn)
|
89
89
|
end
|
data/lib/sequel/core.rb
CHANGED
@@ -30,7 +30,15 @@ module Sequel
|
|
30
30
|
@split_symbols = false
|
31
31
|
@single_threaded = false
|
32
32
|
|
33
|
-
|
33
|
+
# Mutex used to protect mutable data structures
|
34
|
+
@data_mutex = Mutex.new
|
35
|
+
|
36
|
+
# Frozen hash used as the default options hash for most options.
|
37
|
+
OPTS = {}.freeze
|
38
|
+
|
39
|
+
SPLIT_SYMBOL_CACHE = {}
|
40
|
+
|
41
|
+
module SequelMethods
|
34
42
|
# Sequel converts two digit years in <tt>Date</tt>s and <tt>DateTime</tt>s by default,
|
35
43
|
# so 01/02/03 is interpreted at January 2nd, 2003, and 12/13/99 is interpreted
|
36
44
|
# as December 13, 1999. You can override this to treat those dates as
|
@@ -63,361 +71,357 @@ module Sequel
|
|
63
71
|
# require for backwards compatibility.
|
64
72
|
alias orig_require require
|
65
73
|
private :orig_require
|
66
|
-
end
|
67
74
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
75
|
+
# Returns true if the passed object could be a specifier of conditions, false otherwise.
|
76
|
+
# Currently, Sequel considers hashes and arrays of two element arrays as
|
77
|
+
# condition specifiers.
|
78
|
+
#
|
79
|
+
# Sequel.condition_specifier?({}) # => true
|
80
|
+
# Sequel.condition_specifier?([[1, 2]]) # => true
|
81
|
+
# Sequel.condition_specifier?([]) # => false
|
82
|
+
# Sequel.condition_specifier?([1]) # => false
|
83
|
+
# Sequel.condition_specifier?(1) # => false
|
84
|
+
def condition_specifier?(obj)
|
85
|
+
case obj
|
86
|
+
when Hash
|
87
|
+
true
|
88
|
+
when Array
|
89
|
+
!obj.empty? && !obj.is_a?(SQL::ValueList) && obj.all?{|i| i.is_a?(Array) && (i.length == 2)}
|
90
|
+
else
|
91
|
+
false
|
92
|
+
end
|
85
93
|
end
|
86
|
-
end
|
87
94
|
|
88
|
-
|
89
|
-
|
95
|
+
# Creates a new database object based on the supplied connection string
|
96
|
+
# and optional arguments. The specified scheme determines the database
|
97
|
+
# class used, and the rest of the string specifies the connection options.
|
98
|
+
# For example:
|
99
|
+
#
|
100
|
+
# DB = Sequel.connect('sqlite:/') # Memory database
|
101
|
+
# DB = Sequel.connect('sqlite://blog.db') # ./blog.db
|
102
|
+
# DB = Sequel.connect('sqlite:///blog.db') # /blog.db
|
103
|
+
# DB = Sequel.connect('postgres://user:password@host:port/database_name')
|
104
|
+
# DB = Sequel.connect('sqlite:///blog.db', max_connections: 10)
|
105
|
+
#
|
106
|
+
# You can also pass a single options hash:
|
107
|
+
#
|
108
|
+
# DB = Sequel.connect(adapter: 'sqlite', database: './blog.db')
|
109
|
+
#
|
110
|
+
# If a block is given, it is passed the opened +Database+ object, which is
|
111
|
+
# closed when the block exits. For example:
|
112
|
+
#
|
113
|
+
# Sequel.connect('sqlite://blog.db'){|db| puts db[:users].count}
|
114
|
+
#
|
115
|
+
# If a block is not given, a reference to this database will be held in
|
116
|
+
# <tt>Sequel::DATABASES</tt> until it is removed manually. This is by
|
117
|
+
# design, and used by <tt>Sequel::Model</tt> to pick the default
|
118
|
+
# database. It is recommended to pass a block if you do not want the
|
119
|
+
# resulting Database object to remain in memory until the process
|
120
|
+
# terminates, or use the <tt>keep_reference: false</tt> Database option.
|
121
|
+
#
|
122
|
+
# For details, see the {"Connecting to a Database" guide}[rdoc-ref:doc/opening_databases.rdoc].
|
123
|
+
# To set up a primary/replica or sharded database connection, see the {"Primary/Replica Database Configurations and Sharding" guide}[rdoc-ref:doc/sharding.rdoc].
|
124
|
+
def connect(*args, &block)
|
125
|
+
Database.connect(*args, &block)
|
126
|
+
end
|
90
127
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
# DB = Sequel.connect('sqlite:/') # Memory database
|
97
|
-
# DB = Sequel.connect('sqlite://blog.db') # ./blog.db
|
98
|
-
# DB = Sequel.connect('sqlite:///blog.db') # /blog.db
|
99
|
-
# DB = Sequel.connect('postgres://user:password@host:port/database_name')
|
100
|
-
# DB = Sequel.connect('sqlite:///blog.db', max_connections: 10)
|
101
|
-
#
|
102
|
-
# You can also pass a single options hash:
|
103
|
-
#
|
104
|
-
# DB = Sequel.connect(adapter: 'sqlite', database: './blog.db')
|
105
|
-
#
|
106
|
-
# If a block is given, it is passed the opened +Database+ object, which is
|
107
|
-
# closed when the block exits. For example:
|
108
|
-
#
|
109
|
-
# Sequel.connect('sqlite://blog.db'){|db| puts db[:users].count}
|
110
|
-
#
|
111
|
-
# If a block is not given, a reference to this database will be held in
|
112
|
-
# <tt>Sequel::DATABASES</tt> until it is removed manually. This is by
|
113
|
-
# design, and used by <tt>Sequel::Model</tt> to pick the default
|
114
|
-
# database. It is recommended to pass a block if you do not want the
|
115
|
-
# resulting Database object to remain in memory until the process
|
116
|
-
# terminates, or use the <tt>keep_reference: false</tt> Database option.
|
117
|
-
#
|
118
|
-
# For details, see the {"Connecting to a Database" guide}[rdoc-ref:doc/opening_databases.rdoc].
|
119
|
-
# To set up a primary/replica or sharded database connection, see the {"Primary/Replica Database Configurations and Sharding" guide}[rdoc-ref:doc/sharding.rdoc].
|
120
|
-
def self.connect(*args, &block)
|
121
|
-
Database.connect(*args, &block)
|
122
|
-
end
|
128
|
+
# Assume the core extensions are not loaded by default, if the core_extensions
|
129
|
+
# extension is loaded, this will be overridden.
|
130
|
+
def core_extensions?
|
131
|
+
false
|
132
|
+
end
|
123
133
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
134
|
+
# Convert the +exception+ to the given class. The given class should be
|
135
|
+
# <tt>Sequel::Error</tt> or a subclass. Returns an instance of +klass+ with
|
136
|
+
# the message and backtrace of +exception+.
|
137
|
+
def convert_exception_class(exception, klass)
|
138
|
+
return exception if exception.is_a?(klass)
|
139
|
+
e = klass.new("#{exception.class}: #{exception.message}")
|
140
|
+
e.wrapped_exception = exception
|
141
|
+
e.set_backtrace(exception.backtrace)
|
142
|
+
e
|
143
|
+
end
|
129
144
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
return exception if exception.is_a?(klass)
|
135
|
-
e = klass.new("#{exception.class}: #{exception.message}")
|
136
|
-
e.wrapped_exception = exception
|
137
|
-
e.set_backtrace(exception.backtrace)
|
138
|
-
e
|
139
|
-
end
|
145
|
+
# The current concurrency primitive, Thread.current by default.
|
146
|
+
def current
|
147
|
+
Thread.current
|
148
|
+
end
|
140
149
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
150
|
+
# Load all Sequel extensions given. Extensions are just files that exist under
|
151
|
+
# <tt>sequel/extensions</tt> in the load path, and are just required.
|
152
|
+
# In some cases, requiring an extension modifies classes directly, and in others,
|
153
|
+
# it just loads a module that you can extend other classes with. Consult the documentation
|
154
|
+
# for each extension you plan on using for usage.
|
155
|
+
#
|
156
|
+
# Sequel.extension(:blank)
|
157
|
+
# Sequel.extension(:core_extensions, :named_timezones)
|
158
|
+
def extension(*extensions)
|
159
|
+
extensions.each{|e| orig_require("sequel/extensions/#{e}")}
|
160
|
+
end
|
161
|
+
|
162
|
+
# The exception classed raised if there is an error parsing JSON.
|
163
|
+
# This can be overridden to use an alternative json implementation.
|
164
|
+
def json_parser_error_class
|
165
|
+
JSON::ParserError
|
166
|
+
end
|
158
167
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
168
|
+
# Convert given object to json and return the result.
|
169
|
+
# This can be overridden to use an alternative json implementation.
|
170
|
+
def object_to_json(obj, *args, &block)
|
171
|
+
obj.to_json(*args, &block)
|
172
|
+
end
|
164
173
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
174
|
+
# Parse the string as JSON and return the result.
|
175
|
+
# This can be overridden to use an alternative json implementation.
|
176
|
+
def parse_json(json)
|
177
|
+
JSON.parse(json, :create_additions=>false)
|
178
|
+
end
|
170
179
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
+
# Convert each item in the array to the correct type, handling multi-dimensional
|
181
|
+
# arrays. For each element in the array or subarrays, call the converter,
|
182
|
+
# unless the value is nil.
|
183
|
+
def recursive_map(array, converter)
|
184
|
+
array.map do |i|
|
185
|
+
if i.is_a?(Array)
|
186
|
+
recursive_map(i, converter)
|
187
|
+
elsif !i.nil?
|
188
|
+
converter.call(i)
|
189
|
+
end
|
180
190
|
end
|
181
191
|
end
|
182
|
-
end
|
183
|
-
|
184
|
-
# For backwards compatibility only. require_relative should be used instead.
|
185
|
-
def self.require(files, subdir=nil)
|
186
|
-
# Use Kernel.require_relative to work around JRuby 9.0 bug
|
187
|
-
Array(files).each{|f| Kernel.require_relative "#{"#{subdir}/" if subdir}#{f}"}
|
188
|
-
end
|
189
192
|
|
190
|
-
|
193
|
+
# For backwards compatibility only. require_relative should be used instead.
|
194
|
+
def require(files, subdir=nil)
|
195
|
+
# Use Kernel.require_relative to work around JRuby 9.0 bug
|
196
|
+
Array(files).each{|f| Kernel.require_relative "#{"#{subdir}/" if subdir}#{f}"}
|
197
|
+
end
|
191
198
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
199
|
+
# Splits the symbol into three parts, if symbol splitting is enabled (not the default).
|
200
|
+
# Each part will either be a string or nil. If symbol splitting
|
201
|
+
# is disabled, returns an array with the first and third parts
|
202
|
+
# being nil, and the second part beind a string version of the symbol.
|
203
|
+
#
|
204
|
+
# For columns, these parts are the table, column, and alias.
|
205
|
+
# For tables, these parts are the schema, table, and alias.
|
206
|
+
def split_symbol(sym)
|
207
|
+
unless v = Sequel.synchronize{SPLIT_SYMBOL_CACHE[sym]}
|
208
|
+
if split_symbols?
|
209
|
+
v = case s = sym.to_s
|
210
|
+
when /\A((?:(?!__).)+)__((?:(?!___).)+)___(.+)\z/
|
211
|
+
[$1.freeze, $2.freeze, $3.freeze].freeze
|
212
|
+
when /\A((?:(?!___).)+)___(.+)\z/
|
213
|
+
[nil, $1.freeze, $2.freeze].freeze
|
214
|
+
when /\A((?:(?!__).)+)__(.+)\z/
|
215
|
+
[$1.freeze, $2.freeze, nil].freeze
|
216
|
+
else
|
217
|
+
[nil, s.freeze, nil].freeze
|
218
|
+
end
|
209
219
|
else
|
210
|
-
[nil,
|
220
|
+
v = [nil,sym.to_s.freeze,nil].freeze
|
211
221
|
end
|
212
|
-
|
213
|
-
v = [nil,sym.to_s.freeze,nil].freeze
|
222
|
+
Sequel.synchronize{SPLIT_SYMBOL_CACHE[sym] = v}
|
214
223
|
end
|
215
|
-
|
224
|
+
v
|
216
225
|
end
|
217
|
-
v
|
218
|
-
end
|
219
|
-
|
220
|
-
# Setting this to true enables Sequel's historical behavior of splitting
|
221
|
-
# symbols on double or triple underscores:
|
222
|
-
#
|
223
|
-
# :table__column # table.column
|
224
|
-
# :column___alias # column AS alias
|
225
|
-
# :table__column___alias # table.column AS alias
|
226
|
-
#
|
227
|
-
# It is only recommended to turn this on for backwards compatibility until
|
228
|
-
# such symbols have been converted to use newer Sequel APIs such as:
|
229
|
-
#
|
230
|
-
# Sequel[:table][:column] # table.column
|
231
|
-
# Sequel[:column].as(:alias) # column AS alias
|
232
|
-
# Sequel[:table][:column].as(:alias) # table.column AS alias
|
233
|
-
#
|
234
|
-
# Sequel::Database instances do their own caching of literalized
|
235
|
-
# symbols, and changing this setting does not affect those caches. It is
|
236
|
-
# recommended that if you want to change this setting, you do so directly
|
237
|
-
# after requiring Sequel, before creating any Sequel::Database instances.
|
238
|
-
#
|
239
|
-
# Disabling symbol splitting will also disable the handling
|
240
|
-
# of double underscores in virtual row methods, causing such methods to
|
241
|
-
# yield regular identifers instead of qualified identifiers:
|
242
|
-
#
|
243
|
-
# # Sequel.split_symbols = true
|
244
|
-
# Sequel.expr{table__column} # table.column
|
245
|
-
# Sequel.expr{table[:column]} # table.column
|
246
|
-
#
|
247
|
-
# # Sequel.split_symbols = false
|
248
|
-
# Sequel.expr{table__column} # table__column
|
249
|
-
# Sequel.expr{table[:column]} # table.column
|
250
|
-
def self.split_symbols=(v)
|
251
|
-
Sequel.synchronize{SPLIT_SYMBOL_CACHE.clear}
|
252
|
-
@split_symbols = v
|
253
|
-
end
|
254
226
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
227
|
+
# Setting this to true enables Sequel's historical behavior of splitting
|
228
|
+
# symbols on double or triple underscores:
|
229
|
+
#
|
230
|
+
# :table__column # table.column
|
231
|
+
# :column___alias # column AS alias
|
232
|
+
# :table__column___alias # table.column AS alias
|
233
|
+
#
|
234
|
+
# It is only recommended to turn this on for backwards compatibility until
|
235
|
+
# such symbols have been converted to use newer Sequel APIs such as:
|
236
|
+
#
|
237
|
+
# Sequel[:table][:column] # table.column
|
238
|
+
# Sequel[:column].as(:alias) # column AS alias
|
239
|
+
# Sequel[:table][:column].as(:alias) # table.column AS alias
|
240
|
+
#
|
241
|
+
# Sequel::Database instances do their own caching of literalized
|
242
|
+
# symbols, and changing this setting does not affect those caches. It is
|
243
|
+
# recommended that if you want to change this setting, you do so directly
|
244
|
+
# after requiring Sequel, before creating any Sequel::Database instances.
|
245
|
+
#
|
246
|
+
# Disabling symbol splitting will also disable the handling
|
247
|
+
# of double underscores in virtual row methods, causing such methods to
|
248
|
+
# yield regular identifers instead of qualified identifiers:
|
249
|
+
#
|
250
|
+
# # Sequel.split_symbols = true
|
251
|
+
# Sequel.expr{table__column} # table.column
|
252
|
+
# Sequel.expr{table[:column]} # table.column
|
253
|
+
#
|
254
|
+
# # Sequel.split_symbols = false
|
255
|
+
# Sequel.expr{table__column} # table__column
|
256
|
+
# Sequel.expr{table[:column]} # table.column
|
257
|
+
def split_symbols=(v)
|
258
|
+
Sequel.synchronize{SPLIT_SYMBOL_CACHE.clear}
|
259
|
+
@split_symbols = v
|
260
|
+
end
|
259
261
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
def self.string_to_date(string)
|
264
|
-
begin
|
265
|
-
Date.parse(string, Sequel.convert_two_digit_years)
|
266
|
-
rescue => e
|
267
|
-
raise convert_exception_class(e, InvalidValue)
|
262
|
+
# Whether Sequel currently splits symbols into qualified/aliased identifiers.
|
263
|
+
def split_symbols?
|
264
|
+
@split_symbols
|
268
265
|
end
|
269
|
-
end
|
270
266
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
else
|
280
|
-
datetime_class.parse(string)
|
267
|
+
# Converts the given +string+ into a +Date+ object.
|
268
|
+
#
|
269
|
+
# Sequel.string_to_date('2010-09-10') # Date.civil(2010, 09, 10)
|
270
|
+
def string_to_date(string)
|
271
|
+
begin
|
272
|
+
Date.parse(string, Sequel.convert_two_digit_years)
|
273
|
+
rescue => e
|
274
|
+
raise convert_exception_class(e, InvalidValue)
|
281
275
|
end
|
282
|
-
rescue => e
|
283
|
-
raise convert_exception_class(e, InvalidValue)
|
284
276
|
end
|
285
|
-
end
|
286
277
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
278
|
+
# Converts the given +string+ into a +Time+ or +DateTime+ object, depending on the
|
279
|
+
# value of <tt>Sequel.datetime_class</tt>.
|
280
|
+
#
|
281
|
+
# Sequel.string_to_datetime('2010-09-10 10:20:30') # Time.local(2010, 09, 10, 10, 20, 30)
|
282
|
+
def string_to_datetime(string)
|
283
|
+
begin
|
284
|
+
if datetime_class == DateTime
|
285
|
+
DateTime.parse(string, convert_two_digit_years)
|
286
|
+
else
|
287
|
+
datetime_class.parse(string)
|
288
|
+
end
|
289
|
+
rescue => e
|
290
|
+
raise convert_exception_class(e, InvalidValue)
|
291
|
+
end
|
296
292
|
end
|
297
|
-
end
|
298
|
-
|
299
|
-
# Mutex used to protect mutable data structures
|
300
|
-
@data_mutex = Mutex.new
|
301
|
-
|
302
|
-
# Unless in single threaded mode, protects access to any mutable
|
303
|
-
# global data structure in Sequel.
|
304
|
-
# Uses a non-reentrant mutex, so calling code should be careful.
|
305
|
-
# In general, this should only be used around the minimal possible code
|
306
|
-
# such as Hash#[], Hash#[]=, Hash#delete, Array#<<, and Array#delete.
|
307
|
-
def self.synchronize(&block)
|
308
|
-
@single_threaded ? yield : @data_mutex.synchronize(&block)
|
309
|
-
end
|
310
293
|
|
311
|
-
|
312
|
-
#
|
313
|
-
#
|
314
|
-
|
315
|
-
|
294
|
+
# Converts the given +string+ into a <tt>Sequel::SQLTime</tt> object.
|
295
|
+
#
|
296
|
+
# v = Sequel.string_to_time('10:20:30') # Sequel::SQLTime.parse('10:20:30')
|
297
|
+
# DB.literal(v) # => '10:20:30'
|
298
|
+
def string_to_time(string)
|
299
|
+
begin
|
300
|
+
SQLTime.parse(string)
|
301
|
+
rescue => e
|
302
|
+
raise convert_exception_class(e, InvalidValue)
|
303
|
+
end
|
316
304
|
end
|
317
|
-
|
318
|
-
#
|
319
|
-
|
320
|
-
|
305
|
+
|
306
|
+
# Unless in single threaded mode, protects access to any mutable
|
307
|
+
# global data structure in Sequel.
|
308
|
+
# Uses a non-reentrant mutex, so calling code should be careful.
|
309
|
+
# In general, this should only be used around the minimal possible code
|
310
|
+
# such as Hash#[], Hash#[]=, Hash#delete, Array#<<, and Array#delete.
|
311
|
+
def synchronize(&block)
|
312
|
+
@single_threaded ? yield : @data_mutex.synchronize(&block)
|
321
313
|
end
|
322
|
-
# :nocov:
|
323
|
-
end
|
324
314
|
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
315
|
+
if RUBY_VERSION >= '2.1'
|
316
|
+
# A timer object that can be passed to Sequel.elapsed_seconds_since
|
317
|
+
# to return the number of seconds elapsed.
|
318
|
+
def start_timer
|
319
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
320
|
+
end
|
321
|
+
else
|
322
|
+
# :nocov:
|
323
|
+
def start_timer # :nodoc:
|
324
|
+
Time.now
|
325
|
+
end
|
326
|
+
# :nocov:
|
327
|
+
end
|
330
328
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
# is equivalent to:
|
336
|
-
#
|
337
|
-
# DB1.transaction do
|
338
|
-
# DB2.transaction do
|
339
|
-
# DB3.transaction do
|
340
|
-
# end
|
341
|
-
# end
|
342
|
-
# end
|
343
|
-
#
|
344
|
-
# except that if Sequel::Rollback is raised by the block, the transaction is
|
345
|
-
# rolled back on all databases instead of just the last one.
|
346
|
-
#
|
347
|
-
# Note that this method cannot guarantee that all databases will commit or
|
348
|
-
# rollback. For example, if DB3 commits but attempting to commit on DB2
|
349
|
-
# fails (maybe because foreign key checks are deferred), there is no way
|
350
|
-
# to uncommit the changes on DB3. For that kind of support, you need to
|
351
|
-
# have two-phase commit/prepared transactions (which Sequel supports on
|
352
|
-
# some databases).
|
353
|
-
def self.transaction(dbs, opts=OPTS, &block)
|
354
|
-
unless opts[:rollback]
|
355
|
-
rescue_rollback = true
|
356
|
-
opts = Hash[opts].merge!(:rollback=>:reraise)
|
329
|
+
# The elapsed seconds since the given timer object was created. The
|
330
|
+
# timer object should have been created via Sequel.start_timer.
|
331
|
+
def elapsed_seconds_since(timer)
|
332
|
+
start_timer - timer
|
357
333
|
end
|
358
|
-
|
359
|
-
|
360
|
-
|
334
|
+
|
335
|
+
# Uses a transaction on all given databases with the given options. This:
|
336
|
+
#
|
337
|
+
# Sequel.transaction([DB1, DB2, DB3]){}
|
338
|
+
#
|
339
|
+
# is equivalent to:
|
340
|
+
#
|
341
|
+
# DB1.transaction do
|
342
|
+
# DB2.transaction do
|
343
|
+
# DB3.transaction do
|
344
|
+
# end
|
345
|
+
# end
|
346
|
+
# end
|
347
|
+
#
|
348
|
+
# except that if Sequel::Rollback is raised by the block, the transaction is
|
349
|
+
# rolled back on all databases instead of just the last one.
|
350
|
+
#
|
351
|
+
# Note that this method cannot guarantee that all databases will commit or
|
352
|
+
# rollback. For example, if DB3 commits but attempting to commit on DB2
|
353
|
+
# fails (maybe because foreign key checks are deferred), there is no way
|
354
|
+
# to uncommit the changes on DB3. For that kind of support, you need to
|
355
|
+
# have two-phase commit/prepared transactions (which Sequel supports on
|
356
|
+
# some databases).
|
357
|
+
def transaction(dbs, opts=OPTS, &block)
|
358
|
+
unless opts[:rollback]
|
359
|
+
rescue_rollback = true
|
360
|
+
opts = Hash[opts].merge!(:rollback=>:reraise)
|
361
|
+
end
|
362
|
+
pr = dbs.reverse.inject(block){|bl, db| proc{db.transaction(opts, &bl)}}
|
363
|
+
if rescue_rollback
|
364
|
+
begin
|
365
|
+
pr.call
|
366
|
+
rescue Sequel::Rollback
|
367
|
+
nil
|
368
|
+
end
|
369
|
+
else
|
361
370
|
pr.call
|
362
|
-
rescue Sequel::Rollback
|
363
|
-
nil
|
364
371
|
end
|
365
|
-
else
|
366
|
-
pr.call
|
367
372
|
end
|
368
|
-
end
|
369
373
|
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
374
|
+
# If the supplied block takes a single argument,
|
375
|
+
# yield an <tt>SQL::VirtualRow</tt> instance to the block
|
376
|
+
# argument. Otherwise, evaluate the block in the context of a
|
377
|
+
# <tt>SQL::VirtualRow</tt> instance.
|
378
|
+
#
|
379
|
+
# Sequel.virtual_row{a} # Sequel::SQL::Identifier.new(:a)
|
380
|
+
# Sequel.virtual_row{|o| o.a} # Sequel::SQL::Function.new(:a)
|
381
|
+
def virtual_row(&block)
|
382
|
+
vr = VIRTUAL_ROW
|
383
|
+
case block.arity
|
384
|
+
when -1, 0
|
385
|
+
vr.instance_exec(&block)
|
386
|
+
else
|
387
|
+
block.call(vr)
|
388
|
+
end
|
389
|
+
end
|
386
390
|
|
387
|
-
|
391
|
+
private
|
388
392
|
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
393
|
+
# Helper method that the database adapter class methods that are added to Sequel via
|
394
|
+
# metaprogramming use to parse arguments.
|
395
|
+
def adapter_method(adapter, *args, &block)
|
396
|
+
options = args.last.is_a?(Hash) ? args.pop : OPTS
|
397
|
+
opts = {:adapter => adapter.to_sym}
|
398
|
+
opts[:database] = args.shift if args.first.is_a?(String)
|
399
|
+
if args.any?
|
400
|
+
raise ::Sequel::Error, "Wrong format of arguments, either use (), (String), (Hash), or (String, Hash)"
|
401
|
+
end
|
398
402
|
|
399
|
-
|
400
|
-
|
403
|
+
connect(opts.merge(options), &block)
|
404
|
+
end
|
401
405
|
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
406
|
+
# Method that adds a database adapter class method to Sequel that calls
|
407
|
+
# Sequel.adapter_method.
|
408
|
+
def def_adapter_method(*adapters) # :nodoc:
|
409
|
+
adapters.each do |adapter|
|
410
|
+
define_singleton_method(adapter){|*args, &block| adapter_method(adapter, *args, &block)}
|
411
|
+
end
|
407
412
|
end
|
408
413
|
end
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
require_relative "version"
|
414
|
+
extend SequelMethods
|
415
|
+
|
416
|
+
require_relative "deprecated"
|
417
|
+
require_relative "sql"
|
418
|
+
require_relative "connection_pool"
|
419
|
+
require_relative "exceptions"
|
420
|
+
require_relative "dataset"
|
421
|
+
require_relative "database"
|
422
|
+
require_relative "timezones"
|
423
|
+
require_relative "ast_transformer"
|
424
|
+
require_relative "version"
|
421
425
|
|
422
426
|
class << self
|
423
427
|
# Allow nicer syntax for creating Sequel expressions:
|