sequel 5.20.0 → 5.49.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +398 -1922
- data/MIT-LICENSE +1 -1
- data/README.rdoc +7 -7
- data/doc/advanced_associations.rdoc +4 -4
- data/doc/association_basics.rdoc +80 -16
- data/doc/cheat_sheet.rdoc +6 -5
- data/doc/code_order.rdoc +10 -12
- data/doc/dataset_filtering.rdoc +17 -2
- data/doc/fork_safety.rdoc +84 -0
- data/doc/migration.rdoc +11 -5
- data/doc/model_dataset_method_design.rdoc +1 -1
- data/doc/model_plugins.rdoc +1 -1
- data/doc/opening_databases.rdoc +10 -2
- data/doc/postgresql.rdoc +82 -3
- data/doc/querying.rdoc +4 -4
- data/doc/release_notes/5.21.0.txt +87 -0
- data/doc/release_notes/5.22.0.txt +48 -0
- data/doc/release_notes/5.23.0.txt +56 -0
- data/doc/release_notes/5.24.0.txt +56 -0
- data/doc/release_notes/5.25.0.txt +32 -0
- data/doc/release_notes/5.26.0.txt +35 -0
- data/doc/release_notes/5.27.0.txt +21 -0
- data/doc/release_notes/5.28.0.txt +16 -0
- data/doc/release_notes/5.29.0.txt +22 -0
- data/doc/release_notes/5.30.0.txt +20 -0
- data/doc/release_notes/5.31.0.txt +148 -0
- data/doc/release_notes/5.32.0.txt +46 -0
- data/doc/release_notes/5.33.0.txt +24 -0
- data/doc/release_notes/5.34.0.txt +40 -0
- data/doc/release_notes/5.35.0.txt +56 -0
- data/doc/release_notes/5.36.0.txt +60 -0
- data/doc/release_notes/5.37.0.txt +30 -0
- data/doc/release_notes/5.38.0.txt +28 -0
- data/doc/release_notes/5.39.0.txt +19 -0
- data/doc/release_notes/5.40.0.txt +40 -0
- data/doc/release_notes/5.41.0.txt +25 -0
- data/doc/release_notes/5.42.0.txt +136 -0
- data/doc/release_notes/5.43.0.txt +98 -0
- data/doc/release_notes/5.44.0.txt +32 -0
- data/doc/release_notes/5.45.0.txt +34 -0
- data/doc/release_notes/5.46.0.txt +87 -0
- data/doc/release_notes/5.47.0.txt +59 -0
- data/doc/release_notes/5.48.0.txt +14 -0
- data/doc/release_notes/5.49.0.txt +59 -0
- data/doc/sharding.rdoc +2 -0
- data/doc/sql.rdoc +13 -1
- data/doc/testing.rdoc +20 -7
- data/doc/transactions.rdoc +0 -8
- data/doc/validations.rdoc +1 -1
- data/doc/virtual_rows.rdoc +1 -1
- data/lib/sequel/adapters/ado/access.rb +1 -1
- data/lib/sequel/adapters/ado.rb +43 -35
- data/lib/sequel/adapters/ibmdb.rb +2 -2
- data/lib/sequel/adapters/jdbc/mysql.rb +6 -6
- data/lib/sequel/adapters/jdbc/postgresql.rb +11 -17
- data/lib/sequel/adapters/jdbc/sqlite.rb +29 -0
- data/lib/sequel/adapters/jdbc.rb +24 -6
- data/lib/sequel/adapters/mysql.rb +1 -1
- data/lib/sequel/adapters/mysql2.rb +2 -3
- data/lib/sequel/adapters/odbc.rb +8 -6
- data/lib/sequel/adapters/oracle.rb +5 -4
- data/lib/sequel/adapters/postgres.rb +15 -9
- data/lib/sequel/adapters/shared/access.rb +6 -6
- data/lib/sequel/adapters/shared/mssql.rb +66 -21
- data/lib/sequel/adapters/shared/mysql.rb +27 -10
- data/lib/sequel/adapters/shared/oracle.rb +29 -23
- data/lib/sequel/adapters/shared/postgres.rb +271 -32
- data/lib/sequel/adapters/shared/sqlanywhere.rb +9 -9
- data/lib/sequel/adapters/shared/sqlite.rb +161 -19
- data/lib/sequel/adapters/sqlanywhere.rb +1 -1
- data/lib/sequel/adapters/sqlite.rb +1 -1
- data/lib/sequel/adapters/tinytds.rb +15 -2
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +4 -1
- data/lib/sequel/ast_transformer.rb +6 -0
- data/lib/sequel/connection_pool/sharded_single.rb +4 -1
- data/lib/sequel/connection_pool/sharded_threaded.rb +12 -12
- data/lib/sequel/connection_pool/single.rb +1 -1
- data/lib/sequel/connection_pool/threaded.rb +2 -2
- data/lib/sequel/core.rb +333 -319
- data/lib/sequel/database/connecting.rb +3 -4
- data/lib/sequel/database/logging.rb +7 -1
- data/lib/sequel/database/misc.rb +31 -12
- data/lib/sequel/database/query.rb +3 -1
- data/lib/sequel/database/schema_generator.rb +53 -51
- data/lib/sequel/database/schema_methods.rb +38 -23
- data/lib/sequel/database/transactions.rb +17 -18
- data/lib/sequel/dataset/actions.rb +14 -9
- data/lib/sequel/dataset/features.rb +16 -0
- data/lib/sequel/dataset/misc.rb +2 -2
- data/lib/sequel/dataset/placeholder_literalizer.rb +3 -7
- data/lib/sequel/dataset/prepared_statements.rb +2 -0
- data/lib/sequel/dataset/query.rb +26 -9
- data/lib/sequel/dataset/sql.rb +76 -25
- data/lib/sequel/dataset.rb +4 -2
- data/lib/sequel/deprecated.rb +3 -1
- data/lib/sequel/exceptions.rb +2 -0
- data/lib/sequel/extensions/_pretty_table.rb +1 -2
- data/lib/sequel/extensions/any_not_empty.rb +45 -0
- data/lib/sequel/extensions/async_thread_pool.rb +438 -0
- data/lib/sequel/extensions/blank.rb +8 -0
- data/lib/sequel/extensions/columns_introspection.rb +1 -2
- data/lib/sequel/extensions/connection_expiration.rb +2 -2
- data/lib/sequel/extensions/connection_validator.rb +2 -2
- data/lib/sequel/extensions/core_refinements.rb +2 -0
- data/lib/sequel/extensions/date_arithmetic.rb +36 -24
- data/lib/sequel/extensions/duplicate_columns_handler.rb +3 -1
- data/lib/sequel/extensions/eval_inspect.rb +2 -0
- data/lib/sequel/extensions/exclude_or_null.rb +68 -0
- data/lib/sequel/extensions/fiber_concurrency.rb +24 -0
- data/lib/sequel/extensions/index_caching.rb +9 -7
- data/lib/sequel/extensions/inflector.rb +9 -1
- data/lib/sequel/extensions/integer64.rb +2 -0
- data/lib/sequel/extensions/migration.rb +11 -3
- data/lib/sequel/extensions/named_timezones.rb +56 -8
- data/lib/sequel/extensions/pagination.rb +1 -1
- data/lib/sequel/extensions/pg_array.rb +5 -0
- data/lib/sequel/extensions/pg_array_ops.rb +14 -6
- data/lib/sequel/extensions/pg_enum.rb +11 -3
- data/lib/sequel/extensions/pg_extended_date_support.rb +2 -2
- data/lib/sequel/extensions/pg_hstore.rb +6 -0
- data/lib/sequel/extensions/pg_hstore_ops.rb +54 -2
- data/lib/sequel/extensions/pg_inet.rb +15 -5
- data/lib/sequel/extensions/pg_interval.rb +36 -8
- data/lib/sequel/extensions/pg_json.rb +387 -123
- data/lib/sequel/extensions/pg_json_ops.rb +238 -0
- data/lib/sequel/extensions/pg_loose_count.rb +3 -1
- data/lib/sequel/extensions/pg_range.rb +17 -9
- data/lib/sequel/extensions/pg_range_ops.rb +2 -0
- data/lib/sequel/extensions/pg_row.rb +4 -2
- data/lib/sequel/extensions/pg_row_ops.rb +24 -0
- data/lib/sequel/extensions/pg_timestamptz.rb +2 -0
- data/lib/sequel/extensions/query.rb +3 -0
- data/lib/sequel/extensions/run_transaction_hooks.rb +72 -0
- data/lib/sequel/extensions/s.rb +2 -0
- data/lib/sequel/extensions/schema_dumper.rb +24 -7
- data/lib/sequel/extensions/server_block.rb +18 -7
- data/lib/sequel/extensions/sql_comments.rb +2 -2
- data/lib/sequel/extensions/string_agg.rb +1 -1
- data/lib/sequel/extensions/symbol_aref_refinement.rb +2 -0
- data/lib/sequel/extensions/symbol_as_refinement.rb +2 -0
- data/lib/sequel/extensions/to_dot.rb +9 -3
- data/lib/sequel/model/associations.rb +356 -117
- data/lib/sequel/model/base.rb +107 -68
- data/lib/sequel/model/errors.rb +10 -1
- data/lib/sequel/model/inflections.rb +1 -1
- data/lib/sequel/model/plugins.rb +9 -3
- data/lib/sequel/model.rb +3 -1
- data/lib/sequel/plugins/association_lazy_eager_option.rb +66 -0
- data/lib/sequel/plugins/association_multi_add_remove.rb +85 -0
- data/lib/sequel/plugins/association_pks.rb +60 -18
- data/lib/sequel/plugins/association_proxies.rb +8 -2
- data/lib/sequel/plugins/async_thread_pool.rb +39 -0
- data/lib/sequel/plugins/auto_validations.rb +39 -5
- data/lib/sequel/plugins/auto_validations_constraint_validations_presence_message.rb +68 -0
- data/lib/sequel/plugins/blacklist_security.rb +1 -2
- data/lib/sequel/plugins/boolean_subsets.rb +4 -1
- data/lib/sequel/plugins/caching.rb +3 -0
- data/lib/sequel/plugins/class_table_inheritance.rb +33 -28
- data/lib/sequel/plugins/column_encryption.rb +728 -0
- data/lib/sequel/plugins/composition.rb +7 -2
- data/lib/sequel/plugins/concurrent_eager_loading.rb +174 -0
- data/lib/sequel/plugins/constraint_validations.rb +2 -1
- data/lib/sequel/plugins/csv_serializer.rb +28 -9
- data/lib/sequel/plugins/dataset_associations.rb +4 -1
- data/lib/sequel/plugins/dirty.rb +60 -22
- data/lib/sequel/plugins/empty_failure_backtraces.rb +38 -0
- data/lib/sequel/plugins/forbid_lazy_load.rb +216 -0
- data/lib/sequel/plugins/insert_conflict.rb +72 -0
- data/lib/sequel/plugins/instance_specific_default.rb +113 -0
- data/lib/sequel/plugins/json_serializer.rb +57 -35
- data/lib/sequel/plugins/lazy_attributes.rb +1 -1
- data/lib/sequel/plugins/many_through_many.rb +108 -9
- data/lib/sequel/plugins/nested_attributes.rb +15 -3
- data/lib/sequel/plugins/pg_array_associations.rb +58 -41
- data/lib/sequel/plugins/pg_auto_constraint_validations.rb +91 -30
- data/lib/sequel/plugins/prepared_statements.rb +15 -12
- data/lib/sequel/plugins/prepared_statements_safe.rb +1 -3
- data/lib/sequel/plugins/rcte_tree.rb +43 -35
- data/lib/sequel/plugins/serialization.rb +8 -3
- data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
- data/lib/sequel/plugins/sharding.rb +11 -5
- data/lib/sequel/plugins/single_table_inheritance.rb +22 -15
- data/lib/sequel/plugins/skip_saving_columns.rb +108 -0
- data/lib/sequel/plugins/static_cache.rb +9 -4
- data/lib/sequel/plugins/static_cache_cache.rb +53 -0
- data/lib/sequel/plugins/string_stripper.rb +1 -1
- data/lib/sequel/plugins/subclasses.rb +2 -0
- data/lib/sequel/plugins/throw_failures.rb +1 -1
- data/lib/sequel/plugins/timestamps.rb +1 -1
- data/lib/sequel/plugins/tree.rb +9 -4
- data/lib/sequel/plugins/typecast_on_load.rb +3 -2
- data/lib/sequel/plugins/unused_associations.rb +521 -0
- data/lib/sequel/plugins/update_or_create.rb +1 -1
- data/lib/sequel/plugins/validation_class_methods.rb +5 -1
- data/lib/sequel/plugins/validation_helpers.rb +18 -11
- data/lib/sequel/plugins/xml_serializer.rb +1 -1
- data/lib/sequel/sql.rb +20 -5
- data/lib/sequel/timezones.rb +63 -17
- data/lib/sequel/version.rb +1 -1
- metadata +113 -381
- data/Rakefile +0 -151
- data/doc/release_notes/4.0.0.txt +0 -262
- data/doc/release_notes/4.1.0.txt +0 -85
- data/doc/release_notes/4.10.0.txt +0 -226
- data/doc/release_notes/4.11.0.txt +0 -147
- data/doc/release_notes/4.12.0.txt +0 -105
- data/doc/release_notes/4.13.0.txt +0 -169
- data/doc/release_notes/4.14.0.txt +0 -68
- data/doc/release_notes/4.15.0.txt +0 -56
- data/doc/release_notes/4.16.0.txt +0 -36
- data/doc/release_notes/4.17.0.txt +0 -38
- data/doc/release_notes/4.18.0.txt +0 -36
- data/doc/release_notes/4.19.0.txt +0 -45
- data/doc/release_notes/4.2.0.txt +0 -129
- data/doc/release_notes/4.20.0.txt +0 -79
- data/doc/release_notes/4.21.0.txt +0 -94
- data/doc/release_notes/4.22.0.txt +0 -72
- data/doc/release_notes/4.23.0.txt +0 -65
- data/doc/release_notes/4.24.0.txt +0 -99
- data/doc/release_notes/4.25.0.txt +0 -181
- data/doc/release_notes/4.26.0.txt +0 -44
- data/doc/release_notes/4.27.0.txt +0 -78
- data/doc/release_notes/4.28.0.txt +0 -57
- data/doc/release_notes/4.29.0.txt +0 -41
- data/doc/release_notes/4.3.0.txt +0 -40
- data/doc/release_notes/4.30.0.txt +0 -37
- data/doc/release_notes/4.31.0.txt +0 -57
- data/doc/release_notes/4.32.0.txt +0 -132
- data/doc/release_notes/4.33.0.txt +0 -88
- data/doc/release_notes/4.34.0.txt +0 -86
- data/doc/release_notes/4.35.0.txt +0 -130
- data/doc/release_notes/4.36.0.txt +0 -116
- data/doc/release_notes/4.37.0.txt +0 -50
- data/doc/release_notes/4.38.0.txt +0 -67
- data/doc/release_notes/4.39.0.txt +0 -127
- data/doc/release_notes/4.4.0.txt +0 -92
- data/doc/release_notes/4.40.0.txt +0 -179
- data/doc/release_notes/4.41.0.txt +0 -77
- data/doc/release_notes/4.42.0.txt +0 -221
- data/doc/release_notes/4.43.0.txt +0 -87
- data/doc/release_notes/4.44.0.txt +0 -125
- data/doc/release_notes/4.45.0.txt +0 -370
- data/doc/release_notes/4.46.0.txt +0 -404
- data/doc/release_notes/4.47.0.txt +0 -56
- data/doc/release_notes/4.48.0.txt +0 -293
- data/doc/release_notes/4.49.0.txt +0 -222
- data/doc/release_notes/4.5.0.txt +0 -34
- data/doc/release_notes/4.6.0.txt +0 -30
- data/doc/release_notes/4.7.0.txt +0 -103
- data/doc/release_notes/4.8.0.txt +0 -175
- data/doc/release_notes/4.9.0.txt +0 -190
- data/spec/adapter_spec.rb +0 -4
- data/spec/adapters/db2_spec.rb +0 -170
- data/spec/adapters/mssql_spec.rb +0 -804
- data/spec/adapters/mysql_spec.rb +0 -1065
- data/spec/adapters/oracle_spec.rb +0 -371
- data/spec/adapters/postgres_spec.rb +0 -4125
- data/spec/adapters/spec_helper.rb +0 -44
- data/spec/adapters/sqlanywhere_spec.rb +0 -97
- data/spec/adapters/sqlite_spec.rb +0 -652
- data/spec/bin_spec.rb +0 -278
- data/spec/core/connection_pool_spec.rb +0 -1250
- data/spec/core/database_spec.rb +0 -2865
- data/spec/core/dataset_spec.rb +0 -5515
- data/spec/core/deprecated_spec.rb +0 -70
- data/spec/core/expression_filters_spec.rb +0 -1455
- data/spec/core/mock_adapter_spec.rb +0 -722
- data/spec/core/object_graph_spec.rb +0 -336
- data/spec/core/placeholder_literalizer_spec.rb +0 -166
- data/spec/core/schema_generator_spec.rb +0 -214
- data/spec/core/schema_spec.rb +0 -1826
- data/spec/core/spec_helper.rb +0 -24
- data/spec/core/version_spec.rb +0 -14
- data/spec/core_extensions_spec.rb +0 -763
- data/spec/core_model_spec.rb +0 -2
- data/spec/core_spec.rb +0 -1
- data/spec/deprecation_helper.rb +0 -30
- data/spec/extensions/accessed_columns_spec.rb +0 -51
- data/spec/extensions/active_model_spec.rb +0 -99
- data/spec/extensions/after_initialize_spec.rb +0 -28
- data/spec/extensions/arbitrary_servers_spec.rb +0 -109
- data/spec/extensions/association_dependencies_spec.rb +0 -125
- data/spec/extensions/association_pks_spec.rb +0 -423
- data/spec/extensions/association_proxies_spec.rb +0 -100
- data/spec/extensions/auto_literal_strings_spec.rb +0 -205
- data/spec/extensions/auto_validations_spec.rb +0 -229
- data/spec/extensions/blacklist_security_spec.rb +0 -95
- data/spec/extensions/blank_spec.rb +0 -69
- data/spec/extensions/boolean_readers_spec.rb +0 -93
- data/spec/extensions/boolean_subsets_spec.rb +0 -47
- data/spec/extensions/caching_spec.rb +0 -273
- data/spec/extensions/caller_logging_spec.rb +0 -52
- data/spec/extensions/class_table_inheritance_spec.rb +0 -750
- data/spec/extensions/column_conflicts_spec.rb +0 -75
- data/spec/extensions/column_select_spec.rb +0 -129
- data/spec/extensions/columns_introspection_spec.rb +0 -90
- data/spec/extensions/columns_updated_spec.rb +0 -35
- data/spec/extensions/composition_spec.rb +0 -248
- data/spec/extensions/connection_expiration_spec.rb +0 -151
- data/spec/extensions/connection_validator_spec.rb +0 -144
- data/spec/extensions/constant_sql_override_spec.rb +0 -24
- data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
- data/spec/extensions/constraint_validations_spec.rb +0 -439
- data/spec/extensions/core_refinements_spec.rb +0 -528
- data/spec/extensions/csv_serializer_spec.rb +0 -183
- data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
- data/spec/extensions/dataset_associations_spec.rb +0 -365
- data/spec/extensions/dataset_source_alias_spec.rb +0 -51
- data/spec/extensions/date_arithmetic_spec.rb +0 -181
- data/spec/extensions/datetime_parse_to_time_spec.rb +0 -169
- data/spec/extensions/def_dataset_method_spec.rb +0 -100
- data/spec/extensions/defaults_setter_spec.rb +0 -150
- data/spec/extensions/delay_add_association_spec.rb +0 -73
- data/spec/extensions/dirty_spec.rb +0 -189
- data/spec/extensions/duplicate_columns_handler_spec.rb +0 -104
- data/spec/extensions/eager_each_spec.rb +0 -62
- data/spec/extensions/eager_graph_eager_spec.rb +0 -100
- data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
- data/spec/extensions/error_splitter_spec.rb +0 -18
- data/spec/extensions/error_sql_spec.rb +0 -20
- data/spec/extensions/escaped_like_spec.rb +0 -40
- data/spec/extensions/eval_inspect_spec.rb +0 -81
- data/spec/extensions/finder_spec.rb +0 -260
- data/spec/extensions/force_encoding_spec.rb +0 -126
- data/spec/extensions/freeze_datasets_spec.rb +0 -31
- data/spec/extensions/graph_each_spec.rb +0 -113
- data/spec/extensions/hook_class_methods_spec.rb +0 -402
- data/spec/extensions/identifier_mangling_spec.rb +0 -201
- data/spec/extensions/implicit_subquery_spec.rb +0 -58
- data/spec/extensions/index_caching_spec.rb +0 -66
- data/spec/extensions/inflector_spec.rb +0 -183
- data/spec/extensions/input_transformer_spec.rb +0 -69
- data/spec/extensions/insert_returning_select_spec.rb +0 -72
- data/spec/extensions/instance_filters_spec.rb +0 -79
- data/spec/extensions/instance_hooks_spec.rb +0 -246
- data/spec/extensions/integer64_spec.rb +0 -22
- data/spec/extensions/inverted_subsets_spec.rb +0 -33
- data/spec/extensions/json_serializer_spec.rb +0 -336
- data/spec/extensions/lazy_attributes_spec.rb +0 -183
- data/spec/extensions/list_spec.rb +0 -291
- data/spec/extensions/looser_typecasting_spec.rb +0 -43
- data/spec/extensions/many_through_many_spec.rb +0 -2177
- data/spec/extensions/migration_spec.rb +0 -864
- data/spec/extensions/modification_detection_spec.rb +0 -93
- data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -92
- data/spec/extensions/named_timezones_spec.rb +0 -111
- data/spec/extensions/nested_attributes_spec.rb +0 -767
- data/spec/extensions/null_dataset_spec.rb +0 -85
- data/spec/extensions/optimistic_locking_spec.rb +0 -127
- data/spec/extensions/pagination_spec.rb +0 -116
- data/spec/extensions/pg_array_associations_spec.rb +0 -802
- data/spec/extensions/pg_array_ops_spec.rb +0 -144
- data/spec/extensions/pg_array_spec.rb +0 -398
- data/spec/extensions/pg_auto_constraint_validations_spec.rb +0 -172
- data/spec/extensions/pg_enum_spec.rb +0 -118
- data/spec/extensions/pg_extended_date_support_spec.rb +0 -126
- data/spec/extensions/pg_hstore_ops_spec.rb +0 -238
- data/spec/extensions/pg_hstore_spec.rb +0 -219
- data/spec/extensions/pg_inet_ops_spec.rb +0 -102
- data/spec/extensions/pg_inet_spec.rb +0 -72
- data/spec/extensions/pg_interval_spec.rb +0 -103
- data/spec/extensions/pg_json_ops_spec.rb +0 -289
- data/spec/extensions/pg_json_spec.rb +0 -262
- data/spec/extensions/pg_loose_count_spec.rb +0 -23
- data/spec/extensions/pg_range_ops_spec.rb +0 -60
- data/spec/extensions/pg_range_spec.rb +0 -519
- data/spec/extensions/pg_row_ops_spec.rb +0 -61
- data/spec/extensions/pg_row_plugin_spec.rb +0 -60
- data/spec/extensions/pg_row_spec.rb +0 -363
- data/spec/extensions/pg_static_cache_updater_spec.rb +0 -93
- data/spec/extensions/pg_timestamptz_spec.rb +0 -17
- data/spec/extensions/prepared_statements_safe_spec.rb +0 -66
- data/spec/extensions/prepared_statements_spec.rb +0 -177
- data/spec/extensions/pretty_table_spec.rb +0 -123
- data/spec/extensions/query_spec.rb +0 -94
- data/spec/extensions/rcte_tree_spec.rb +0 -381
- data/spec/extensions/round_timestamps_spec.rb +0 -39
- data/spec/extensions/s_spec.rb +0 -60
- data/spec/extensions/schema_caching_spec.rb +0 -64
- data/spec/extensions/schema_dumper_spec.rb +0 -870
- data/spec/extensions/select_remove_spec.rb +0 -38
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +0 -121
- data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
- data/spec/extensions/serialization_spec.rb +0 -365
- data/spec/extensions/server_block_spec.rb +0 -97
- data/spec/extensions/server_logging_spec.rb +0 -45
- data/spec/extensions/sharding_spec.rb +0 -189
- data/spec/extensions/shared_caching_spec.rb +0 -151
- data/spec/extensions/single_table_inheritance_spec.rb +0 -347
- data/spec/extensions/singular_table_names_spec.rb +0 -22
- data/spec/extensions/skip_create_refresh_spec.rb +0 -18
- data/spec/extensions/spec_helper.rb +0 -63
- data/spec/extensions/split_array_nil_spec.rb +0 -24
- data/spec/extensions/split_values_spec.rb +0 -57
- data/spec/extensions/sql_comments_spec.rb +0 -33
- data/spec/extensions/sql_expr_spec.rb +0 -59
- data/spec/extensions/static_cache_spec.rb +0 -471
- data/spec/extensions/string_agg_spec.rb +0 -90
- data/spec/extensions/string_date_time_spec.rb +0 -95
- data/spec/extensions/string_stripper_spec.rb +0 -68
- data/spec/extensions/subclasses_spec.rb +0 -79
- data/spec/extensions/subset_conditions_spec.rb +0 -38
- data/spec/extensions/symbol_aref_refinement_spec.rb +0 -28
- data/spec/extensions/symbol_as_refinement_spec.rb +0 -21
- data/spec/extensions/synchronize_sql_spec.rb +0 -124
- data/spec/extensions/table_select_spec.rb +0 -83
- data/spec/extensions/tactical_eager_loading_spec.rb +0 -402
- data/spec/extensions/thread_local_timezones_spec.rb +0 -67
- data/spec/extensions/throw_failures_spec.rb +0 -74
- data/spec/extensions/timestamps_spec.rb +0 -209
- data/spec/extensions/to_dot_spec.rb +0 -153
- data/spec/extensions/touch_spec.rb +0 -226
- data/spec/extensions/tree_spec.rb +0 -334
- data/spec/extensions/typecast_on_load_spec.rb +0 -86
- data/spec/extensions/unlimited_update_spec.rb +0 -21
- data/spec/extensions/update_or_create_spec.rb +0 -83
- data/spec/extensions/update_primary_key_spec.rb +0 -105
- data/spec/extensions/update_refresh_spec.rb +0 -59
- data/spec/extensions/uuid_spec.rb +0 -101
- data/spec/extensions/validate_associated_spec.rb +0 -52
- data/spec/extensions/validation_class_methods_spec.rb +0 -1040
- data/spec/extensions/validation_contexts_spec.rb +0 -31
- data/spec/extensions/validation_helpers_spec.rb +0 -525
- data/spec/extensions/whitelist_security_spec.rb +0 -157
- data/spec/extensions/xml_serializer_spec.rb +0 -213
- data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
- data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
- data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
- data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
- data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/double_migration/001_create_sessions.rb +0 -9
- data/spec/files/double_migration/002_create_nodes.rb +0 -19
- data/spec/files/double_migration/003_3_create_users.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
- data/spec/files/empty_migration/001_create_sessions.rb +0 -9
- data/spec/files/empty_migration/002_create_nodes.rb +0 -0
- data/spec/files/empty_migration/003_3_create_users.rb +0 -4
- data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
- data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
- data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
- data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
- data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/reversible_migrations/001_reversible.rb +0 -5
- data/spec/files/reversible_migrations/002_reversible.rb +0 -5
- data/spec/files/reversible_migrations/003_reversible.rb +0 -5
- data/spec/files/reversible_migrations/004_reversible.rb +0 -5
- data/spec/files/reversible_migrations/005_reversible.rb +0 -10
- data/spec/files/reversible_migrations/006_reversible.rb +0 -10
- data/spec/files/reversible_migrations/007_reversible.rb +0 -10
- data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
- data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
- data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
- data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
- data/spec/guards_helper.rb +0 -59
- data/spec/integration/associations_test.rb +0 -2597
- data/spec/integration/database_test.rb +0 -113
- data/spec/integration/dataset_test.rb +0 -1981
- data/spec/integration/eager_loader_test.rb +0 -687
- data/spec/integration/migrator_test.rb +0 -262
- data/spec/integration/model_test.rb +0 -203
- data/spec/integration/plugin_test.rb +0 -2396
- data/spec/integration/prepared_statement_test.rb +0 -405
- data/spec/integration/schema_test.rb +0 -889
- data/spec/integration/spec_helper.rb +0 -65
- data/spec/integration/timezone_test.rb +0 -86
- data/spec/integration/transaction_test.rb +0 -603
- data/spec/integration/type_test.rb +0 -127
- data/spec/model/association_reflection_spec.rb +0 -803
- data/spec/model/associations_spec.rb +0 -4738
- data/spec/model/base_spec.rb +0 -875
- data/spec/model/class_dataset_methods_spec.rb +0 -146
- data/spec/model/dataset_methods_spec.rb +0 -198
- data/spec/model/eager_loading_spec.rb +0 -2377
- data/spec/model/hooks_spec.rb +0 -370
- data/spec/model/inflector_spec.rb +0 -26
- data/spec/model/model_spec.rb +0 -956
- data/spec/model/plugins_spec.rb +0 -429
- data/spec/model/record_spec.rb +0 -2118
- data/spec/model/spec_helper.rb +0 -46
- data/spec/model/validations_spec.rb +0 -220
- data/spec/model_no_assoc_spec.rb +0 -1
- data/spec/model_spec.rb +0 -1
- data/spec/plugin_spec.rb +0 -1
- data/spec/sequel_coverage.rb +0 -15
- data/spec/sequel_warning.rb +0 -4
- data/spec/spec_config.rb +0 -12
data/MIT-LICENSE
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
Copyright (c) 2007-2008 Sharon Rosner
|
2
|
-
Copyright (c) 2008-
|
2
|
+
Copyright (c) 2008-2021 Jeremy Evans
|
3
3
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
of this software and associated documentation files (the "Software"), to
|
data/README.rdoc
CHANGED
@@ -22,10 +22,9 @@ RDoc Documentation :: http://sequel.jeremyevans.net/rdoc
|
|
22
22
|
Source Code :: https://github.com/jeremyevans/sequel
|
23
23
|
Bug tracking (GitHub Issues) :: http://github.com/jeremyevans/sequel/issues
|
24
24
|
Discussion Forum (sequel-talk Google Group) :: http://groups.google.com/group/sequel-talk
|
25
|
-
IRC Channel (#sequel) :: irc://irc.freenode.net/sequel
|
26
25
|
|
27
26
|
If you have questions about how to use Sequel, please ask on the
|
28
|
-
sequel-talk Google Group
|
27
|
+
sequel-talk Google Group. Only use the the bug tracker to report
|
29
28
|
bugs in Sequel, not to ask for help on using Sequel.
|
30
29
|
|
31
30
|
To check out the source code:
|
@@ -172,7 +171,7 @@ Datasets are the primary way records are retrieved and manipulated. They are ge
|
|
172
171
|
posts = DB.from(:posts)
|
173
172
|
posts = DB[:posts] # same
|
174
173
|
|
175
|
-
Datasets will only fetch records when you tell them to. They can be manipulated to filter records, change ordering, join tables, etc
|
174
|
+
Datasets will only fetch records when you tell them to. They can be manipulated to filter records, change ordering, join tables, etc. Datasets are always frozen, and they are safe to use by multiple threads concurrently.
|
176
175
|
|
177
176
|
=== Retrieving Records
|
178
177
|
|
@@ -578,7 +577,7 @@ A single model instance can also be fetched by specifying a condition:
|
|
578
577
|
post = Post.first(title: 'hello world')
|
579
578
|
post = Post.first{num_comments < 10}
|
580
579
|
|
581
|
-
The dataset for a model class returns rows
|
580
|
+
The dataset for a model class returns rows of model instances instead of plain hashes:
|
582
581
|
|
583
582
|
DB[:posts].first.class # => Hash
|
584
583
|
Post.first.class # => Post
|
@@ -883,7 +882,7 @@ raise an error by default:
|
|
883
882
|
== Sequel Release Policy
|
884
883
|
|
885
884
|
New major versions of Sequel do not have a defined release policy, but historically have
|
886
|
-
occurred once
|
885
|
+
occurred once every few years.
|
887
886
|
|
888
887
|
New minor versions of Sequel are released around once a month near the start of the month.
|
889
888
|
|
@@ -894,8 +893,9 @@ in the most current release.
|
|
894
893
|
|
895
894
|
Sequel fully supports the currently supported versions of Ruby (MRI) and JRuby. It may
|
896
895
|
support unsupported versions of Ruby or JRuby, but such support may be dropped in any
|
897
|
-
minor version
|
898
|
-
required to run the current version of Sequel is 1.9.2
|
896
|
+
minor version if keeping it becomes a support issue. The minimum Ruby version
|
897
|
+
required to run the current version of Sequel is 1.9.2, and the minimum JRuby version is
|
898
|
+
9.0.0.0.
|
899
899
|
|
900
900
|
== Maintainer
|
901
901
|
|
@@ -731,7 +731,7 @@ associations:
|
|
731
731
|
one_to_one :tracks, key: [:disc_number, :number, :album_id], primary_key: [:disc_number, :number, :album_id]
|
732
732
|
end
|
733
733
|
|
734
|
-
=== Tree - All Ancestors and
|
734
|
+
=== Tree - All Ancestors and Descendants
|
735
735
|
|
736
736
|
Let's say you want to store a tree relationship in your database, it's pretty
|
737
737
|
simple:
|
@@ -749,7 +749,7 @@ node.children. You can even eager load the relationship up to a certain depth:
|
|
749
749
|
# Load parents and grandparents for a group of nodes
|
750
750
|
Node.where{id < 10}.eager(parent: :parent).all
|
751
751
|
|
752
|
-
What if you want to get all ancestors up to the root node, or all
|
752
|
+
What if you want to get all ancestors up to the root node, or all descendants,
|
753
753
|
without knowing the depth of the tree?
|
754
754
|
|
755
755
|
class Node < Sequel::Model
|
@@ -770,7 +770,7 @@ without knowing the depth of the tree?
|
|
770
770
|
id_map = {}
|
771
771
|
# Create an map of parent_ids to nodes that have that parent id
|
772
772
|
non_root_nodes.each{|n| (id_map[n.parent_id] ||= []) << n}
|
773
|
-
# Doesn't cause an
|
773
|
+
# Doesn't cause an infinite loop, because when only the root node
|
774
774
|
# is left, this is not called.
|
775
775
|
Node.where(id: id_map.keys).eager(:ancestors).all do |node|
|
776
776
|
# Populate the parent association for each node
|
@@ -879,4 +879,4 @@ associated tickets.
|
|
879
879
|
end
|
880
880
|
|
881
881
|
Note that it is often better to use a sum cache instead of this approach. You can implement
|
882
|
-
a sum cache using +after_create+, +after_update+, and +after_delete+ hooks, or
|
882
|
+
a sum cache using +after_create+, +after_update+, and +after_delete+ hooks, or preferably using a database trigger.
|
data/doc/association_basics.rdoc
CHANGED
@@ -41,7 +41,7 @@ As is the code to add a related album to an artist:
|
|
41
41
|
|
42
42
|
@artist.add_album(name: 'RF')
|
43
43
|
|
44
|
-
It also makes it easier to
|
44
|
+
It also makes it easier to create queries that use joins based on the association:
|
45
45
|
|
46
46
|
Artist.association_join(:albums)
|
47
47
|
# SELECT * FROM artists
|
@@ -63,8 +63,8 @@ It ships with additional association types via plugins.
|
|
63
63
|
|
64
64
|
The many_to_one association is used when the table for the current class
|
65
65
|
contains a foreign key that references the primary key in the table for the
|
66
|
-
associated class. It is named because there can be many rows
|
67
|
-
table for each row in the associated table.
|
66
|
+
associated class. It is named 'many_to_one' because there can be many rows
|
67
|
+
in the current table for each row in the associated table.
|
68
68
|
|
69
69
|
# Database schema:
|
70
70
|
# albums artists
|
@@ -81,8 +81,8 @@ table for each row in the associated table.
|
|
81
81
|
|
82
82
|
The one_to_many association is used when the table for the associated class
|
83
83
|
contains a foreign key that references the primary key in the table for the
|
84
|
-
current class. It is named because for each row in the
|
85
|
-
can be many rows in the associated table:
|
84
|
+
current class. It is named 'one_to_many' because for each row in the
|
85
|
+
current table there can be many rows in the associated table:
|
86
86
|
|
87
87
|
The one_to_one association can be thought of as a subset of the one_to_many association,
|
88
88
|
but where there can only be either 0 or 1 records in the associated table. This is
|
@@ -113,7 +113,7 @@ many rows in the current table, by using a join table to associate the two table
|
|
113
113
|
The one_through_one association can be thought of as a subset of the many_to_many
|
114
114
|
association, but where there can only be 0 or 1 records in the associated table.
|
115
115
|
This is useful if there is a unique constraint on the foreign key in the join table
|
116
|
-
that
|
116
|
+
that references the current table. It's also useful if you want to impose an order
|
117
117
|
on the association and just want the first record returned. The one_through_one
|
118
118
|
association is so named because it sets up a one-to-one association through a
|
119
119
|
single join table.
|
@@ -344,7 +344,7 @@ instance method:
|
|
344
344
|
|
345
345
|
== Dataset Method
|
346
346
|
|
347
|
-
In addition to the above methods, associations also add
|
347
|
+
In addition to the above methods, associations also add an instance method
|
348
348
|
ending in +_dataset+ that returns a dataset representing the objects in the associated table:
|
349
349
|
|
350
350
|
@album.artist_id
|
@@ -781,7 +781,7 @@ Sequel is designed to be very flexible. If the default behavior of the
|
|
781
781
|
association modification methods isn't what you desire, you can override
|
782
782
|
the methods in your classes. However, you should be aware that for each
|
783
783
|
of the association modification methods described, there is a private
|
784
|
-
method that is
|
784
|
+
method that is preceded by an underscore that does the actual
|
785
785
|
modification. The public method without the underscore handles caching
|
786
786
|
and callbacks, and shouldn't be overridden by the user.
|
787
787
|
|
@@ -826,6 +826,8 @@ you also wanted to handle the Artist#add_album method:
|
|
826
826
|
end)
|
827
827
|
end
|
828
828
|
|
829
|
+
You can set this to +nil+ to not create a add_<i>association</i> method.
|
830
|
+
|
829
831
|
=== :remover (\_remove_<i>association</i> method)
|
830
832
|
|
831
833
|
Continuing with the same example, here's how you would handle the same case if
|
@@ -837,6 +839,8 @@ you also wanted to handle the Artist#remove_album method:
|
|
837
839
|
end)
|
838
840
|
end
|
839
841
|
|
842
|
+
You can set this to +nil+ to not create a remove_<i>association</i> method.
|
843
|
+
|
840
844
|
=== :clearer (\_remove_all_<i>association</i> method)
|
841
845
|
|
842
846
|
Continuing with the same example, here's how you would handle the same case if
|
@@ -850,6 +854,22 @@ you also wanted to handle the Artist#remove_all_albums method:
|
|
850
854
|
end)
|
851
855
|
end
|
852
856
|
|
857
|
+
You can set this to +nil+ to not create a remove_all_<i>association</i> method.
|
858
|
+
|
859
|
+
=== :no_dataset_method
|
860
|
+
|
861
|
+
Setting this to true will not result in the <i>association</i>_dataset method
|
862
|
+
not being defined. This can save memory if you only use the <i>association</i>
|
863
|
+
method and do not call the <i>association</i>_dataset method directly or
|
864
|
+
indirectly.
|
865
|
+
|
866
|
+
=== :no_association_method
|
867
|
+
|
868
|
+
Setting this to true will not result in the <i>association</i> method
|
869
|
+
not being defined. This can save memory if you only use the
|
870
|
+
<i>association</i>_dataset method and do not call the <i>association</i> method
|
871
|
+
directly or indirectly.
|
872
|
+
|
853
873
|
== Association Options
|
854
874
|
|
855
875
|
Sequel's associations mostly share the same options. For ease of understanding,
|
@@ -1069,7 +1089,7 @@ option of the first association, it doesn't attempt to merge them.
|
|
1069
1089
|
In addition to the options hash, the :clone option will copy a block argument
|
1070
1090
|
from the existing situation. If you want a cloned association to not have the
|
1071
1091
|
same block as the association you are cloning from, specify the block: nil option
|
1072
|
-
in
|
1092
|
+
in addition to the :clone option.
|
1073
1093
|
|
1074
1094
|
==== :dataset
|
1075
1095
|
|
@@ -1087,7 +1107,7 @@ already applied, and the proc should return a modified copy of this dataset.
|
|
1087
1107
|
Here's an example of an association of songs to artists through lyrics, where
|
1088
1108
|
the artist can perform any one of four tasks for the lyric:
|
1089
1109
|
|
1090
|
-
|
1110
|
+
Artist.one_to_many :songs, dataset: (lambda do |r|
|
1091
1111
|
r.associated_dataset.select_all(:songs).
|
1092
1112
|
join(:lyrics, id: :lyricid, id=>[:composer_id, :arranger_id, :vocalist_id, :lyricist_id])
|
1093
1113
|
end)
|
@@ -1146,6 +1166,23 @@ when deleting.
|
|
1146
1166
|
ds.where(instrument_id: 5)
|
1147
1167
|
end)
|
1148
1168
|
|
1169
|
+
==== :join_table_db [+many_to_many+, +one_through_one+]
|
1170
|
+
|
1171
|
+
A Sequel::Database to use for the join table. Specifying this option switches the
|
1172
|
+
loading to use a separate query for the join table. This is useful if the
|
1173
|
+
join table is not located in the same database as the associated table, or
|
1174
|
+
if the database account with access to the associated table doesn't have
|
1175
|
+
access to the join table.
|
1176
|
+
|
1177
|
+
For example, if the Album class uses a different Sequel::Database than the Artist
|
1178
|
+
class, and the join table is in the database that the Artist class uses:
|
1179
|
+
|
1180
|
+
Artist.many_to_many :lead_guitar_albums, class: :Album, :join_table_db=>Artist.db
|
1181
|
+
|
1182
|
+
This option also affects the add/remove/remove_all methods, by changing
|
1183
|
+
which database is used for inserts/deletes from the join table (add/remove/remove_all
|
1184
|
+
defaults to use the current model's database instead of the associated model's database).
|
1185
|
+
|
1149
1186
|
=== Callback Options
|
1150
1187
|
|
1151
1188
|
All callbacks can be specified as a Symbol, Proc, or array of both/either
|
@@ -1638,9 +1675,8 @@ For +many_to_one+ and +one_to_one+ associations, do not add a setter method.
|
|
1638
1675
|
For +one_to_many+ and +many_to_many+, do not add the add_<i>association</i>,
|
1639
1676
|
remove_<i>association</i>, or remove_all_<i>association</i> methods.
|
1640
1677
|
|
1641
|
-
If
|
1642
|
-
|
1643
|
-
want, it may be best to set this option to true.
|
1678
|
+
If you are not using the association modification methods, setting this
|
1679
|
+
value to true will save memory.
|
1644
1680
|
|
1645
1681
|
==== :validate
|
1646
1682
|
|
@@ -1667,20 +1703,48 @@ If set to false, you cannot load the association eagerly via eager or
|
|
1667
1703
|
eager_graph.
|
1668
1704
|
|
1669
1705
|
Artist.one_to_many :albums, allow_eager: false
|
1670
|
-
Artist.eager(:albums)
|
1706
|
+
Artist.eager(:albums) # Raises Sequel::Error
|
1707
|
+
Artist.eager_graph(:albums) # Raises Sequel::Error
|
1671
1708
|
|
1672
1709
|
This is usually used if the association dataset depends on specific values in
|
1673
1710
|
model instance that would not be valid when eager loading for multiple
|
1674
1711
|
instances.
|
1675
1712
|
|
1713
|
+
==== :allow_eager_graph
|
1714
|
+
|
1715
|
+
If set to false, you cannot load the association eagerly via eager_graph.
|
1716
|
+
|
1717
|
+
Artist.one_to_many :albums, allow_eager_graph: false
|
1718
|
+
Artist.eager(:albums) # Allowed
|
1719
|
+
Artist.eager_graph(:albums) # Raises Sequel::Error
|
1720
|
+
|
1721
|
+
This is useful if you still want to allow loading via eager, but do not want
|
1722
|
+
to allow loading via eager graph, possibly because the association does not
|
1723
|
+
support joins.
|
1724
|
+
|
1725
|
+
==== :allow_filtering_by
|
1726
|
+
|
1727
|
+
If set to false, you cannot use the association when filtering.
|
1728
|
+
|
1729
|
+
Artist.one_to_many :albums, allow_filtering_by: false
|
1730
|
+
Artist.where(:albums=>Album.where(:name=>'A')).all # Raises Sequel::Error
|
1731
|
+
|
1732
|
+
This is useful if such filtering cannot work, such as when a subquery cannot
|
1733
|
+
be used because the necessary tables are not in the same database.
|
1734
|
+
|
1676
1735
|
==== :instance_specific
|
1677
1736
|
|
1678
1737
|
This allows you to override the setting of whether the dataset contains instance
|
1679
|
-
specific code.
|
1738
|
+
specific code. If you are passing a block to the association,
|
1680
1739
|
Sequel sets this to true by default, which disables some optimizations that
|
1681
1740
|
would be invalid if the association is instance specific. If you know that the
|
1682
1741
|
block does not contain instance specific code, you can set this to false to
|
1683
|
-
reenable the optimizations.
|
1742
|
+
reenable the optimizations. Instance specific code is mostly commonly calling
|
1743
|
+
model instance methods inside an association block, but also
|
1744
|
+
includes cases where the association block can return different values based
|
1745
|
+
on the runtime environment, such as calls to <tt>Time.now</tt> in the block.
|
1746
|
+
Associations that use the :dataset option are always considered instance specific,
|
1747
|
+
even if explicitly specified otherwise.
|
1684
1748
|
|
1685
1749
|
==== :cartesian_product_number
|
1686
1750
|
|
data/doc/cheat_sheet.rdoc
CHANGED
@@ -55,6 +55,7 @@ Without a filename argument, the sqlite adapter will setup a new sqlite database
|
|
55
55
|
|
56
56
|
dataset.exclude(:active).delete
|
57
57
|
dataset.where{price < 100}.update(:active => true)
|
58
|
+
dataset.where(:active).update(:price => Sequel[:price] * 0.90)
|
58
59
|
|
59
60
|
== Datasets are Enumerable
|
60
61
|
|
@@ -94,18 +95,18 @@ Without a filename argument, the sqlite adapter will setup a new sqlite database
|
|
94
95
|
|
95
96
|
=== AND/OR/NOT
|
96
97
|
|
97
|
-
DB[:items].where{(x > 5) & (y > 10)}
|
98
|
+
DB[:items].where{(x > 5) & (y > 10)}
|
98
99
|
# SELECT * FROM items WHERE ((x > 5) AND (y > 10))
|
99
100
|
|
100
|
-
DB[:items].where(Sequel.or(x: 1, y: 2) & Sequel.~(z: 3))
|
101
|
+
DB[:items].where(Sequel.or(x: 1, y: 2) & Sequel.~(z: 3))
|
101
102
|
# SELECT * FROM items WHERE (((x = 1) OR (y = 2)) AND (z != 3))
|
102
103
|
|
103
104
|
=== Mathematical operators
|
104
105
|
|
105
|
-
DB[:items].where{x + y > z}
|
106
|
+
DB[:items].where{x + y > z}
|
106
107
|
# SELECT * FROM items WHERE ((x + y) > z)
|
107
108
|
|
108
|
-
DB[:items].where{price - 100 < avg(price)}
|
109
|
+
DB[:items].where{price - 100 < avg(price)}
|
109
110
|
# SELECT * FROM items WHERE ((price - 100) < avg(price))
|
110
111
|
|
111
112
|
=== Raw SQL Fragments
|
@@ -129,7 +130,7 @@ Without a filename argument, the sqlite adapter will setup a new sqlite database
|
|
129
130
|
|
130
131
|
== Joins
|
131
132
|
|
132
|
-
DB[:items].left_outer_join(:categories, id: :category_id)
|
133
|
+
DB[:items].left_outer_join(:categories, id: :category_id)
|
133
134
|
# SELECT * FROM items
|
134
135
|
# LEFT OUTER JOIN categories ON categories.id = items.category_id
|
135
136
|
|
data/doc/code_order.rdoc
CHANGED
@@ -7,7 +7,7 @@ this guide will be specific about which are strictly necessary.
|
|
7
7
|
|
8
8
|
== Require Sequel
|
9
9
|
|
10
|
-
This is sort of a no
|
10
|
+
This is sort of a no-brainer, but you need to require the library
|
11
11
|
first. This is a strict requirement, none of the other code can
|
12
12
|
be executed unless the library has been required first. Example:
|
13
13
|
|
@@ -70,7 +70,7 @@ copied into the subclass when model subclasses are created. Example:
|
|
70
70
|
== Load Model Classes
|
71
71
|
|
72
72
|
After you have established a database connection, and configured your
|
73
|
-
global model
|
73
|
+
global model configuration and global plugins, you can load your model
|
74
74
|
classes. It's recommended to have a separate file for each model class,
|
75
75
|
unless the model classes are very simple. Example:
|
76
76
|
|
@@ -91,14 +91,12 @@ unsafe runtime modification of the configuration:
|
|
91
91
|
model_classes.each(&:freeze)
|
92
92
|
DB.freeze
|
93
93
|
|
94
|
-
|
94
|
+
The `subclasses` plugin can be used to keep track of all model classes
|
95
|
+
that have been setup in your application. Finalizing their associations
|
96
|
+
and freezing them can easily be achieved through the plugin:
|
95
97
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
will automatically reconnect on an as needed basis in the child
|
102
|
-
processes, so you only need to do the following in the parent process:
|
103
|
-
|
104
|
-
DB.disconnect
|
98
|
+
# Register the plugin before setting up the models
|
99
|
+
Sequel::Model.plugin :subclasses
|
100
|
+
# ... setup models
|
101
|
+
# Now finalize associations & freeze models by calling the plugin:
|
102
|
+
Sequel::Model.freeze_descendents
|
data/doc/dataset_filtering.rdoc
CHANGED
@@ -36,8 +36,8 @@ Ranges (both inclusive and exclusive) can also be used:
|
|
36
36
|
|
37
37
|
If you need to select multiple items from a dataset, you can supply an array:
|
38
38
|
|
39
|
-
|
40
|
-
|
39
|
+
items.where(id: [1, 38, 47, 99]).sql
|
40
|
+
# "SELECT * FROM items WHERE (id IN (1, 38, 47, 99))"
|
41
41
|
|
42
42
|
== Filtering using expressions
|
43
43
|
|
@@ -106,6 +106,21 @@ You can also use placeholders with :placeholder and a hash of placeholder values
|
|
106
106
|
items.where(Sequel.lit('category = :category', category: "ruby")).sql
|
107
107
|
# "SELECT * FROM items WHERE category = 'ruby'"
|
108
108
|
|
109
|
+
In order to combine AND and OR together, you have a few options:
|
110
|
+
|
111
|
+
items.where(category: nil).or(category: "ruby")
|
112
|
+
# SELECT * FROM items WHERE (category IS NULL) OR (category = 'ruby')
|
113
|
+
|
114
|
+
This won't work if you add other conditions:
|
115
|
+
|
116
|
+
items.where(name: "Programming in Ruby").where(category: nil).or(category: 'ruby')
|
117
|
+
# SELECT * FROM items WHERE ((name = 'Programming in Ruby') AND (category IS NULL)) OR (category = 'ruby')
|
118
|
+
|
119
|
+
The OR applies globally and not locally. To fix this, use & and |:
|
120
|
+
|
121
|
+
items.where(Sequel[name: "Programming in Ruby"] & (Sequel[category: nil] | Sequel[category: "ruby"]))
|
122
|
+
# SELECT * FROM items WHERE ((name = 'Programming in Ruby') AND ((category IS NULL) OR (category = 'ruby')))
|
123
|
+
|
109
124
|
=== Specifying SQL functions
|
110
125
|
|
111
126
|
Sequel also allows you to specify functions by using the Sequel.function method:
|
@@ -0,0 +1,84 @@
|
|
1
|
+
= Fork Safety
|
2
|
+
|
3
|
+
If you are forking or using a library that forks after you have created a
|
4
|
+
Sequel::Database instance, then you must disconnect database connections before forking. If you
|
5
|
+
don't do this, you can end up with child processes sharing database connections
|
6
|
+
and all sorts of weird behavior, including crashes. Sequel will automatically create new
|
7
|
+
connections on an as needed basis in the child processes, so you only need to do the following in
|
8
|
+
the parent process:
|
9
|
+
|
10
|
+
DB.disconnect
|
11
|
+
|
12
|
+
Or if you have connections to multiple databases:
|
13
|
+
|
14
|
+
Sequel::DATABASES.each(&:disconnect)
|
15
|
+
|
16
|
+
== Puma
|
17
|
+
|
18
|
+
When using the Puma web server in clustered mode (which is the default behavior in Puma 5+ when
|
19
|
+
using multiple processes), you should disconnect inside the +before_fork+ hook in your
|
20
|
+
Puma config:
|
21
|
+
|
22
|
+
before_fork do
|
23
|
+
Sequel::DATABASES.each(&:disconnect)
|
24
|
+
end
|
25
|
+
|
26
|
+
== Unicorn
|
27
|
+
|
28
|
+
When using the Unicorn web server and preloading the application (+preload_app true+ in the Unicorn
|
29
|
+
config), you should disconnect inside the +before_fork+ hook in the Unicorn config:
|
30
|
+
|
31
|
+
before_fork do
|
32
|
+
Sequel::DATABASES.each(&:disconnect)
|
33
|
+
end
|
34
|
+
|
35
|
+
== Passenger
|
36
|
+
|
37
|
+
In Passenger web server, you should disconnect inside the
|
38
|
+
+starting_worker_process+ event hook:
|
39
|
+
|
40
|
+
if defined?(PhusionPassenger)
|
41
|
+
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
42
|
+
Sequel::DATABASES.each(&:disconnect) if forked
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
Note that this disconnects after forking instead of before forking. Passenger does not
|
47
|
+
offer a before fork hook.
|
48
|
+
|
49
|
+
== Spring
|
50
|
+
|
51
|
+
In Spring application preloader, you should disconnect inside the +after_fork+ hook:
|
52
|
+
|
53
|
+
if defined?(Spring)
|
54
|
+
Spring.after_fork do
|
55
|
+
Sequel::DATABASES.each(&:disconnect)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
As the method indicates, this disconnects after forking instead of before forking.
|
60
|
+
Spring does not offer a before fork hook.
|
61
|
+
|
62
|
+
== Resque
|
63
|
+
|
64
|
+
In Resque, you should disconnect inside the +before_fork+ hook:
|
65
|
+
|
66
|
+
Resque.before_fork do |job|
|
67
|
+
Sequel::DATABASES.each(&:disconnect)
|
68
|
+
end
|
69
|
+
|
70
|
+
== Parallel
|
71
|
+
|
72
|
+
If you're using the Parallel gem with processes, you should disconnect before
|
73
|
+
calling it:
|
74
|
+
|
75
|
+
Sequel::DATABASES.each(&:disconnect)
|
76
|
+
Parallel.map(['a','b','c'], in_processes: 3) { |one_letter| }
|
77
|
+
|
78
|
+
== Other Libraries Calling fork
|
79
|
+
|
80
|
+
For any other library that calls fork, you should disconnect before calling
|
81
|
+
a method that forks:
|
82
|
+
|
83
|
+
Sequel::DATABASES.each(&:disconnect)
|
84
|
+
SomeLibrary.method_that_forks
|
data/doc/migration.rdoc
CHANGED
@@ -543,16 +543,22 @@ The main difference between the two is that <tt>-d</tt> will use the type method
|
|
543
543
|
with the database independent ruby class types, while <tt>-D</tt> will use
|
544
544
|
the +column+ method with string types.
|
545
545
|
|
546
|
-
Note that Sequel cannot dump constraints other than primary key and possibly
|
547
|
-
foreign key constraints. If you are using database features such
|
548
|
-
as constraints or triggers, you should use your database's dump and restore
|
549
|
-
programs instead of Sequel's schema dumper.
|
550
|
-
|
551
546
|
You can take the migration created by the schema dumper to another computer
|
552
547
|
with an empty database, and attempt to recreate the schema using:
|
553
548
|
|
554
549
|
sequel -m db/migrations postgres://host/database
|
555
550
|
|
551
|
+
The schema_dumper extension is quite limited in what types of
|
552
|
+
database objects it supports. In general, it only supports
|
553
|
+
dumping tables, columns, primary key and foreign key constraints,
|
554
|
+
and some indexes. It does not support most table options, CHECK
|
555
|
+
constraints, partial indexes, database functions, triggers,
|
556
|
+
security grants/revokes, and a wide variety of other useful
|
557
|
+
database properties. Be aware of the limitations when using the
|
558
|
+
schema_dumper extension. If you are dumping the schema to restore
|
559
|
+
to the same database type, it is recommended to use your database's
|
560
|
+
dump and restore programs instead of the schema_dumper extension.
|
561
|
+
|
556
562
|
== Checking for Current Migrations
|
557
563
|
|
558
564
|
In your application code, you may want to check that you are up to date in
|
@@ -4,7 +4,7 @@ How you design your model dataset methods can significantly affect the flexibili
|
|
4
4
|
|
5
5
|
== Flexibility: Use Single Method Per Task
|
6
6
|
|
7
|
-
In general, it is recommended that you have a single method per task for maximum
|
7
|
+
In general, it is recommended that you have a single method per task for maximum flexibility. For example, let's say you need to retrieve all albums released in a given year, ordered by number of units sold descending, and only care about the id, name and number of units sold. One way to do this is in your application code (outside the model), you can
|
8
8
|
call the dataset methods directly:
|
9
9
|
|
10
10
|
Album.
|
data/doc/model_plugins.rdoc
CHANGED
@@ -212,7 +212,7 @@ In general you should only require plugin arguments if you absolutely must have
|
|
212
212
|
|
213
213
|
== Handling Subclasses
|
214
214
|
|
215
|
-
Sequel::Model uses a copy-on-subclassing approach to model state. So instead of model
|
215
|
+
Sequel::Model uses a copy-on-subclassing approach to model state. So instead of having a model subclass ask its superclass for a value if the subclass don't have the value defined, the value should be copied from the parent class to the subclass when the subclass is created. While this can be implemented by overriding the +inherited+ class method, there is an available shortcut that handles most cases:
|
216
216
|
|
217
217
|
module Sequel::Plugins::Foo
|
218
218
|
module ClassMethods
|
data/doc/opening_databases.rdoc
CHANGED
@@ -208,7 +208,7 @@ Example connection strings:
|
|
208
208
|
|
209
209
|
jdbc:sqlite::memory:
|
210
210
|
jdbc:postgresql://localhost/database?user=username
|
211
|
-
jdbc:mysql://localhost/test?user=root&password=root
|
211
|
+
jdbc:mysql://localhost/test?user=root&password=root&serverTimezone=UTC
|
212
212
|
jdbc:h2:mem:
|
213
213
|
jdbc:hsqldb:mem:mymemdb
|
214
214
|
jdbc:derby:memory:myDb;create=true
|
@@ -240,6 +240,10 @@ The following additional options are supported:
|
|
240
240
|
There are a few issues with specific jdbc driver gems:
|
241
241
|
|
242
242
|
jdbc-h2 :: jdbc-h2 versions greater than 1.3.175 have issues with ORDER BY not working correctly in some cases.
|
243
|
+
jdbc-mysql :: Depending on the configuration of the MySQL server, jdbc-mysql versions greater 8 may complain
|
244
|
+
about the server time zone being unrecognized. You can either use an older jdbc-mysql version,
|
245
|
+
or you can specify the +serverTimezone+ option in the connection string, as shown in the example
|
246
|
+
jdbc:mysql connection string above.
|
243
247
|
|
244
248
|
=== mysql
|
245
249
|
|
@@ -264,7 +268,8 @@ The following additional options are supported:
|
|
264
268
|
or an array of symbols or strings (e.g. <tt>:sql_mode=>[:no_zero_date, :pipes_as_concat]</tt>).
|
265
269
|
:timeout :: Sets the wait_timeout for the connection, defaults to 1 month.
|
266
270
|
:read_timeout :: Set the timeout in seconds for reading back results to a query.
|
267
|
-
:connect_timeout :: Set the timeout in seconds before a connection attempt is abandoned
|
271
|
+
:connect_timeout :: Set the timeout in seconds before a connection attempt is abandoned
|
272
|
+
(may not be supported when using MariaDB 10.2+ client libraries).
|
268
273
|
|
269
274
|
The :sslkey, :sslcert, :sslca, :sslcapath, and :sslca options (in that order) are passed to Mysql#ssl_set method
|
270
275
|
if either the :sslca or :sslkey option is given.
|
@@ -400,6 +405,9 @@ options that you may want to set are :login_timeout, :timeout, :tds_version, :az
|
|
400
405
|
|
401
406
|
Other Sequel specific options:
|
402
407
|
|
408
|
+
:ansi :: Set to true to enable the ANSI compatibility settings when connecting
|
409
|
+
(ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ANSI_NULL_DFLT_ON, QUOTED_IDENTIFIER,
|
410
|
+
CONCAT_NULL_YIELDS_NULL).
|
403
411
|
:server_version :: Override the server version to use (9000000 = SQL Server 2005).
|
404
412
|
This also works on any other adapter that connects to Microsoft
|
405
413
|
SQL Server.
|