sequel 5.8.0 → 5.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +409 -1795
- data/MIT-LICENSE +1 -1
- data/README.rdoc +4 -4
- data/bin/sequel +4 -0
- data/doc/advanced_associations.rdoc +136 -18
- data/doc/association_basics.rdoc +10 -5
- data/doc/cheat_sheet.rdoc +1 -0
- data/doc/code_order.rdoc +12 -2
- data/doc/dataset_filtering.rdoc +17 -2
- data/doc/mass_assignment.rdoc +3 -3
- data/doc/model_dataset_method_design.rdoc +1 -1
- data/doc/model_plugins.rdoc +1 -1
- data/doc/opening_databases.rdoc +30 -8
- data/doc/postgresql.rdoc +107 -2
- data/doc/release_notes/5.10.0.txt +84 -0
- data/doc/release_notes/5.11.0.txt +83 -0
- data/doc/release_notes/5.12.0.txt +141 -0
- data/doc/release_notes/5.13.0.txt +27 -0
- data/doc/release_notes/5.14.0.txt +63 -0
- data/doc/release_notes/5.15.0.txt +39 -0
- data/doc/release_notes/5.16.0.txt +110 -0
- data/doc/release_notes/5.17.0.txt +31 -0
- data/doc/release_notes/5.18.0.txt +69 -0
- data/doc/release_notes/5.19.0.txt +28 -0
- data/doc/release_notes/5.20.0.txt +89 -0
- data/doc/release_notes/5.21.0.txt +87 -0
- data/doc/release_notes/5.22.0.txt +48 -0
- data/doc/release_notes/5.23.0.txt +56 -0
- data/doc/release_notes/5.24.0.txt +56 -0
- data/doc/release_notes/5.25.0.txt +32 -0
- data/doc/release_notes/5.26.0.txt +35 -0
- data/doc/release_notes/5.27.0.txt +21 -0
- data/doc/release_notes/5.28.0.txt +16 -0
- data/doc/release_notes/5.29.0.txt +22 -0
- data/doc/release_notes/5.30.0.txt +20 -0
- data/doc/release_notes/5.31.0.txt +148 -0
- data/doc/release_notes/5.32.0.txt +46 -0
- data/doc/release_notes/5.33.0.txt +24 -0
- data/doc/release_notes/5.34.0.txt +40 -0
- data/doc/release_notes/5.35.0.txt +56 -0
- data/doc/release_notes/5.36.0.txt +60 -0
- data/doc/release_notes/5.37.0.txt +30 -0
- data/doc/release_notes/5.38.0.txt +28 -0
- data/doc/release_notes/5.9.0.txt +99 -0
- data/doc/security.rdoc +10 -0
- data/doc/sharding.rdoc +42 -28
- data/doc/sql.rdoc +12 -0
- data/doc/testing.rdoc +24 -17
- data/doc/transactions.rdoc +78 -0
- data/doc/validations.rdoc +2 -2
- data/lib/sequel/adapters/ado.rb +26 -18
- data/lib/sequel/adapters/ado/access.rb +2 -2
- data/lib/sequel/adapters/ado/mssql.rb +5 -8
- data/lib/sequel/adapters/amalgalite.rb +1 -1
- data/lib/sequel/adapters/jdbc.rb +71 -27
- data/lib/sequel/adapters/jdbc/mysql.rb +6 -6
- data/lib/sequel/adapters/jdbc/oracle.rb +7 -6
- data/lib/sequel/adapters/jdbc/postgresql.rb +17 -28
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +5 -6
- data/lib/sequel/adapters/jdbc/sqlite.rb +33 -2
- data/lib/sequel/adapters/jdbc/sqlserver.rb +4 -3
- data/lib/sequel/adapters/jdbc/transactions.rb +14 -28
- data/lib/sequel/adapters/mysql.rb +14 -15
- data/lib/sequel/adapters/mysql2.rb +5 -3
- data/lib/sequel/adapters/odbc.rb +4 -6
- data/lib/sequel/adapters/oracle.rb +7 -7
- data/lib/sequel/adapters/postgres.rb +52 -16
- data/lib/sequel/adapters/shared/access.rb +16 -12
- data/lib/sequel/adapters/shared/db2.rb +5 -0
- data/lib/sequel/adapters/shared/mssql.rb +41 -18
- data/lib/sequel/adapters/shared/mysql.rb +66 -19
- data/lib/sequel/adapters/shared/oracle.rb +29 -23
- data/lib/sequel/adapters/shared/postgres.rb +341 -95
- data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
- data/lib/sequel/adapters/shared/sqlite.rb +174 -21
- data/lib/sequel/adapters/sqlanywhere.rb +33 -17
- data/lib/sequel/adapters/sqlite.rb +78 -68
- data/lib/sequel/adapters/tinytds.rb +14 -6
- data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +2 -5
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +5 -1
- data/lib/sequel/connection_pool.rb +2 -6
- data/lib/sequel/connection_pool/sharded_single.rb +7 -4
- data/lib/sequel/connection_pool/sharded_threaded.rb +32 -21
- data/lib/sequel/connection_pool/single.rb +1 -1
- data/lib/sequel/connection_pool/threaded.rb +26 -11
- data/lib/sequel/core.rb +327 -319
- data/lib/sequel/database/connecting.rb +7 -8
- data/lib/sequel/database/logging.rb +7 -1
- data/lib/sequel/database/misc.rb +68 -34
- data/lib/sequel/database/query.rb +6 -4
- data/lib/sequel/database/schema_generator.rb +31 -11
- data/lib/sequel/database/schema_methods.rb +32 -22
- data/lib/sequel/database/transactions.rb +129 -25
- data/lib/sequel/dataset.rb +4 -2
- data/lib/sequel/dataset/actions.rb +34 -23
- data/lib/sequel/dataset/features.rb +34 -0
- data/lib/sequel/dataset/graph.rb +27 -11
- data/lib/sequel/dataset/misc.rb +17 -3
- data/lib/sequel/dataset/placeholder_literalizer.rb +50 -21
- data/lib/sequel/dataset/prepared_statements.rb +96 -26
- data/lib/sequel/dataset/query.rb +43 -8
- data/lib/sequel/dataset/sql.rb +189 -41
- data/lib/sequel/deprecated.rb +3 -1
- data/lib/sequel/exceptions.rb +2 -0
- data/lib/sequel/extensions/_pretty_table.rb +1 -2
- data/lib/sequel/extensions/any_not_empty.rb +45 -0
- data/lib/sequel/extensions/caller_logging.rb +79 -0
- data/lib/sequel/extensions/columns_introspection.rb +1 -2
- data/lib/sequel/extensions/connection_expiration.rb +6 -6
- data/lib/sequel/extensions/connection_validator.rb +7 -6
- data/lib/sequel/extensions/constant_sql_override.rb +65 -0
- data/lib/sequel/extensions/constraint_validations.rb +53 -28
- data/lib/sequel/extensions/core_refinements.rb +2 -0
- data/lib/sequel/extensions/duplicate_columns_handler.rb +2 -0
- data/lib/sequel/extensions/escaped_like.rb +100 -0
- data/lib/sequel/extensions/eval_inspect.rb +3 -1
- data/lib/sequel/extensions/exclude_or_null.rb +68 -0
- data/lib/sequel/extensions/fiber_concurrency.rb +24 -0
- data/lib/sequel/extensions/index_caching.rb +9 -7
- data/lib/sequel/extensions/integer64.rb +3 -1
- data/lib/sequel/extensions/looser_typecasting.rb +3 -3
- data/lib/sequel/extensions/migration.rb +13 -6
- data/lib/sequel/extensions/named_timezones.rb +84 -23
- data/lib/sequel/extensions/pg_array.rb +87 -79
- data/lib/sequel/extensions/pg_array_ops.rb +14 -6
- data/lib/sequel/extensions/pg_enum.rb +34 -18
- data/lib/sequel/extensions/pg_extended_date_support.rb +34 -14
- data/lib/sequel/extensions/pg_hstore.rb +6 -0
- data/lib/sequel/extensions/pg_hstore_ops.rb +2 -0
- data/lib/sequel/extensions/pg_inet.rb +15 -5
- data/lib/sequel/extensions/pg_interval.rb +2 -0
- data/lib/sequel/extensions/pg_json.rb +387 -123
- data/lib/sequel/extensions/pg_json_ops.rb +168 -0
- data/lib/sequel/extensions/pg_range.rb +20 -10
- data/lib/sequel/extensions/pg_range_ops.rb +2 -0
- data/lib/sequel/extensions/pg_row.rb +3 -2
- data/lib/sequel/extensions/pg_row_ops.rb +24 -0
- data/lib/sequel/extensions/pg_static_cache_updater.rb +2 -2
- data/lib/sequel/extensions/pg_timestamptz.rb +2 -0
- data/lib/sequel/extensions/query.rb +1 -0
- data/lib/sequel/extensions/run_transaction_hooks.rb +72 -0
- data/lib/sequel/extensions/s.rb +2 -0
- data/lib/sequel/extensions/schema_dumper.rb +13 -7
- data/lib/sequel/extensions/sequel_4_dataset_methods.rb +4 -2
- data/lib/sequel/extensions/server_block.rb +18 -7
- data/lib/sequel/extensions/sql_comments.rb +2 -2
- data/lib/sequel/extensions/symbol_aref_refinement.rb +2 -0
- data/lib/sequel/extensions/symbol_as_refinement.rb +2 -0
- data/lib/sequel/extensions/to_dot.rb +9 -3
- data/lib/sequel/model.rb +3 -1
- data/lib/sequel/model/associations.rb +403 -69
- data/lib/sequel/model/base.rb +170 -90
- data/lib/sequel/model/plugins.rb +105 -0
- data/lib/sequel/plugins/after_initialize.rb +1 -1
- data/lib/sequel/plugins/association_dependencies.rb +3 -3
- data/lib/sequel/plugins/association_lazy_eager_option.rb +66 -0
- data/lib/sequel/plugins/association_multi_add_remove.rb +85 -0
- data/lib/sequel/plugins/association_pks.rb +74 -22
- data/lib/sequel/plugins/association_proxies.rb +6 -2
- data/lib/sequel/plugins/auto_validations.rb +36 -17
- data/lib/sequel/plugins/blacklist_security.rb +1 -2
- data/lib/sequel/plugins/boolean_subsets.rb +4 -1
- data/lib/sequel/plugins/caching.rb +3 -0
- data/lib/sequel/plugins/class_table_inheritance.rb +62 -34
- data/lib/sequel/plugins/composition.rb +13 -9
- data/lib/sequel/plugins/csv_serializer.rb +28 -9
- data/lib/sequel/plugins/defaults_setter.rb +2 -2
- data/lib/sequel/plugins/dirty.rb +60 -22
- data/lib/sequel/plugins/eager_graph_eager.rb +139 -0
- data/lib/sequel/plugins/empty_failure_backtraces.rb +38 -0
- data/lib/sequel/plugins/finder.rb +2 -2
- data/lib/sequel/plugins/forbid_lazy_load.rb +216 -0
- data/lib/sequel/plugins/hook_class_methods.rb +17 -5
- data/lib/sequel/plugins/insert_conflict.rb +72 -0
- data/lib/sequel/plugins/instance_specific_default.rb +113 -0
- data/lib/sequel/plugins/inverted_subsets.rb +2 -2
- data/lib/sequel/plugins/json_serializer.rb +21 -14
- data/lib/sequel/plugins/lazy_attributes.rb +1 -1
- data/lib/sequel/plugins/list.rb +22 -10
- data/lib/sequel/plugins/many_through_many.rb +1 -1
- data/lib/sequel/plugins/nested_attributes.rb +27 -5
- data/lib/sequel/plugins/pg_array_associations.rb +12 -9
- data/lib/sequel/plugins/pg_auto_constraint_validations.rb +149 -61
- data/lib/sequel/plugins/prepared_statements.rb +6 -12
- data/lib/sequel/plugins/prepared_statements_safe.rb +1 -3
- data/lib/sequel/plugins/rcte_tree.rb +20 -22
- data/lib/sequel/plugins/sharding.rb +13 -7
- data/lib/sequel/plugins/single_table_inheritance.rb +20 -15
- data/lib/sequel/plugins/skip_saving_columns.rb +108 -0
- data/lib/sequel/plugins/static_cache.rb +36 -17
- data/lib/sequel/plugins/static_cache_cache.rb +53 -0
- data/lib/sequel/plugins/string_stripper.rb +1 -1
- data/lib/sequel/plugins/subclasses.rb +2 -0
- data/lib/sequel/plugins/subset_conditions.rb +2 -2
- data/lib/sequel/plugins/tactical_eager_loading.rb +73 -2
- data/lib/sequel/plugins/throw_failures.rb +110 -0
- data/lib/sequel/plugins/tree.rb +49 -31
- data/lib/sequel/plugins/typecast_on_load.rb +3 -2
- data/lib/sequel/plugins/validation_class_methods.rb +11 -5
- data/lib/sequel/plugins/validation_helpers.rb +2 -2
- data/lib/sequel/sql.rb +120 -30
- data/lib/sequel/timezones.rb +55 -14
- data/lib/sequel/version.rb +6 -1
- metadata +101 -361
- data/Rakefile +0 -151
- data/doc/release_notes/4.0.0.txt +0 -262
- data/doc/release_notes/4.1.0.txt +0 -85
- data/doc/release_notes/4.10.0.txt +0 -226
- data/doc/release_notes/4.11.0.txt +0 -147
- data/doc/release_notes/4.12.0.txt +0 -105
- data/doc/release_notes/4.13.0.txt +0 -169
- data/doc/release_notes/4.14.0.txt +0 -68
- data/doc/release_notes/4.15.0.txt +0 -56
- data/doc/release_notes/4.16.0.txt +0 -36
- data/doc/release_notes/4.17.0.txt +0 -38
- data/doc/release_notes/4.18.0.txt +0 -36
- data/doc/release_notes/4.19.0.txt +0 -45
- data/doc/release_notes/4.2.0.txt +0 -129
- data/doc/release_notes/4.20.0.txt +0 -79
- data/doc/release_notes/4.21.0.txt +0 -94
- data/doc/release_notes/4.22.0.txt +0 -72
- data/doc/release_notes/4.23.0.txt +0 -65
- data/doc/release_notes/4.24.0.txt +0 -99
- data/doc/release_notes/4.25.0.txt +0 -181
- data/doc/release_notes/4.26.0.txt +0 -44
- data/doc/release_notes/4.27.0.txt +0 -78
- data/doc/release_notes/4.28.0.txt +0 -57
- data/doc/release_notes/4.29.0.txt +0 -41
- data/doc/release_notes/4.3.0.txt +0 -40
- data/doc/release_notes/4.30.0.txt +0 -37
- data/doc/release_notes/4.31.0.txt +0 -57
- data/doc/release_notes/4.32.0.txt +0 -132
- data/doc/release_notes/4.33.0.txt +0 -88
- data/doc/release_notes/4.34.0.txt +0 -86
- data/doc/release_notes/4.35.0.txt +0 -130
- data/doc/release_notes/4.36.0.txt +0 -116
- data/doc/release_notes/4.37.0.txt +0 -50
- data/doc/release_notes/4.38.0.txt +0 -67
- data/doc/release_notes/4.39.0.txt +0 -127
- data/doc/release_notes/4.4.0.txt +0 -92
- data/doc/release_notes/4.40.0.txt +0 -179
- data/doc/release_notes/4.41.0.txt +0 -77
- data/doc/release_notes/4.42.0.txt +0 -221
- data/doc/release_notes/4.43.0.txt +0 -87
- data/doc/release_notes/4.44.0.txt +0 -125
- data/doc/release_notes/4.45.0.txt +0 -370
- data/doc/release_notes/4.46.0.txt +0 -404
- data/doc/release_notes/4.47.0.txt +0 -56
- data/doc/release_notes/4.48.0.txt +0 -293
- data/doc/release_notes/4.49.0.txt +0 -222
- data/doc/release_notes/4.5.0.txt +0 -34
- data/doc/release_notes/4.6.0.txt +0 -30
- data/doc/release_notes/4.7.0.txt +0 -103
- data/doc/release_notes/4.8.0.txt +0 -175
- data/doc/release_notes/4.9.0.txt +0 -190
- data/spec/adapter_spec.rb +0 -4
- data/spec/adapters/db2_spec.rb +0 -170
- data/spec/adapters/mssql_spec.rb +0 -804
- data/spec/adapters/mysql_spec.rb +0 -1041
- data/spec/adapters/oracle_spec.rb +0 -327
- data/spec/adapters/postgres_spec.rb +0 -4000
- data/spec/adapters/spec_helper.rb +0 -43
- data/spec/adapters/sqlanywhere_spec.rb +0 -97
- data/spec/adapters/sqlite_spec.rb +0 -600
- data/spec/bin_spec.rb +0 -269
- data/spec/core/connection_pool_spec.rb +0 -1228
- data/spec/core/database_spec.rb +0 -2673
- data/spec/core/dataset_spec.rb +0 -5419
- data/spec/core/deprecated_spec.rb +0 -70
- data/spec/core/expression_filters_spec.rb +0 -1344
- data/spec/core/mock_adapter_spec.rb +0 -722
- data/spec/core/object_graph_spec.rb +0 -306
- data/spec/core/placeholder_literalizer_spec.rb +0 -166
- data/spec/core/schema_generator_spec.rb +0 -214
- data/spec/core/schema_spec.rb +0 -1820
- data/spec/core/spec_helper.rb +0 -23
- data/spec/core/version_spec.rb +0 -7
- data/spec/core_extensions_spec.rb +0 -762
- data/spec/core_model_spec.rb +0 -2
- data/spec/core_spec.rb +0 -1
- data/spec/deprecation_helper.rb +0 -30
- data/spec/extensions/accessed_columns_spec.rb +0 -51
- data/spec/extensions/active_model_spec.rb +0 -99
- data/spec/extensions/after_initialize_spec.rb +0 -24
- data/spec/extensions/arbitrary_servers_spec.rb +0 -109
- data/spec/extensions/association_dependencies_spec.rb +0 -125
- data/spec/extensions/association_pks_spec.rb +0 -423
- data/spec/extensions/association_proxies_spec.rb +0 -100
- data/spec/extensions/auto_literal_strings_spec.rb +0 -205
- data/spec/extensions/auto_validations_spec.rb +0 -202
- data/spec/extensions/blacklist_security_spec.rb +0 -95
- data/spec/extensions/blank_spec.rb +0 -69
- data/spec/extensions/boolean_readers_spec.rb +0 -93
- data/spec/extensions/boolean_subsets_spec.rb +0 -47
- data/spec/extensions/caching_spec.rb +0 -273
- data/spec/extensions/class_table_inheritance_spec.rb +0 -568
- data/spec/extensions/column_conflicts_spec.rb +0 -75
- data/spec/extensions/column_select_spec.rb +0 -129
- data/spec/extensions/columns_introspection_spec.rb +0 -90
- data/spec/extensions/columns_updated_spec.rb +0 -35
- data/spec/extensions/composition_spec.rb +0 -248
- data/spec/extensions/connection_expiration_spec.rb +0 -133
- data/spec/extensions/connection_validator_spec.rb +0 -127
- data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
- data/spec/extensions/constraint_validations_spec.rb +0 -395
- data/spec/extensions/core_refinements_spec.rb +0 -528
- data/spec/extensions/csv_serializer_spec.rb +0 -183
- data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
- data/spec/extensions/dataset_associations_spec.rb +0 -365
- data/spec/extensions/dataset_source_alias_spec.rb +0 -51
- data/spec/extensions/date_arithmetic_spec.rb +0 -181
- data/spec/extensions/datetime_parse_to_time_spec.rb +0 -169
- data/spec/extensions/def_dataset_method_spec.rb +0 -100
- data/spec/extensions/defaults_setter_spec.rb +0 -141
- data/spec/extensions/delay_add_association_spec.rb +0 -73
- data/spec/extensions/dirty_spec.rb +0 -189
- data/spec/extensions/duplicate_columns_handler_spec.rb +0 -104
- data/spec/extensions/eager_each_spec.rb +0 -62
- data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
- data/spec/extensions/error_splitter_spec.rb +0 -18
- data/spec/extensions/error_sql_spec.rb +0 -20
- data/spec/extensions/eval_inspect_spec.rb +0 -74
- data/spec/extensions/finder_spec.rb +0 -260
- data/spec/extensions/force_encoding_spec.rb +0 -126
- data/spec/extensions/freeze_datasets_spec.rb +0 -31
- data/spec/extensions/graph_each_spec.rb +0 -113
- data/spec/extensions/hook_class_methods_spec.rb +0 -380
- data/spec/extensions/identifier_mangling_spec.rb +0 -201
- data/spec/extensions/implicit_subquery_spec.rb +0 -58
- data/spec/extensions/index_caching_spec.rb +0 -66
- data/spec/extensions/inflector_spec.rb +0 -183
- data/spec/extensions/input_transformer_spec.rb +0 -69
- data/spec/extensions/insert_returning_select_spec.rb +0 -72
- data/spec/extensions/instance_filters_spec.rb +0 -79
- data/spec/extensions/instance_hooks_spec.rb +0 -246
- data/spec/extensions/integer64_spec.rb +0 -22
- data/spec/extensions/inverted_subsets_spec.rb +0 -33
- data/spec/extensions/json_serializer_spec.rb +0 -336
- data/spec/extensions/lazy_attributes_spec.rb +0 -183
- data/spec/extensions/list_spec.rb +0 -275
- data/spec/extensions/looser_typecasting_spec.rb +0 -43
- data/spec/extensions/many_through_many_spec.rb +0 -2177
- data/spec/extensions/migration_spec.rb +0 -840
- data/spec/extensions/modification_detection_spec.rb +0 -93
- data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -92
- data/spec/extensions/named_timezones_spec.rb +0 -109
- data/spec/extensions/nested_attributes_spec.rb +0 -703
- data/spec/extensions/null_dataset_spec.rb +0 -85
- data/spec/extensions/optimistic_locking_spec.rb +0 -127
- data/spec/extensions/pagination_spec.rb +0 -116
- data/spec/extensions/pg_array_associations_spec.rb +0 -802
- data/spec/extensions/pg_array_ops_spec.rb +0 -144
- data/spec/extensions/pg_array_spec.rb +0 -398
- data/spec/extensions/pg_auto_constraint_validations_spec.rb +0 -165
- data/spec/extensions/pg_enum_spec.rb +0 -113
- data/spec/extensions/pg_extended_date_support_spec.rb +0 -126
- data/spec/extensions/pg_hstore_ops_spec.rb +0 -238
- data/spec/extensions/pg_hstore_spec.rb +0 -219
- data/spec/extensions/pg_inet_ops_spec.rb +0 -102
- data/spec/extensions/pg_inet_spec.rb +0 -72
- data/spec/extensions/pg_interval_spec.rb +0 -103
- data/spec/extensions/pg_json_ops_spec.rb +0 -289
- data/spec/extensions/pg_json_spec.rb +0 -262
- data/spec/extensions/pg_loose_count_spec.rb +0 -23
- data/spec/extensions/pg_range_ops_spec.rb +0 -60
- data/spec/extensions/pg_range_spec.rb +0 -487
- data/spec/extensions/pg_row_ops_spec.rb +0 -61
- data/spec/extensions/pg_row_plugin_spec.rb +0 -60
- data/spec/extensions/pg_row_spec.rb +0 -363
- data/spec/extensions/pg_static_cache_updater_spec.rb +0 -93
- data/spec/extensions/pg_timestamptz_spec.rb +0 -17
- data/spec/extensions/prepared_statements_safe_spec.rb +0 -66
- data/spec/extensions/prepared_statements_spec.rb +0 -182
- data/spec/extensions/pretty_table_spec.rb +0 -123
- data/spec/extensions/query_spec.rb +0 -94
- data/spec/extensions/rcte_tree_spec.rb +0 -381
- data/spec/extensions/round_timestamps_spec.rb +0 -39
- data/spec/extensions/s_spec.rb +0 -60
- data/spec/extensions/schema_caching_spec.rb +0 -64
- data/spec/extensions/schema_dumper_spec.rb +0 -868
- data/spec/extensions/select_remove_spec.rb +0 -38
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +0 -121
- data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
- data/spec/extensions/serialization_spec.rb +0 -365
- data/spec/extensions/server_block_spec.rb +0 -97
- data/spec/extensions/server_logging_spec.rb +0 -45
- data/spec/extensions/sharding_spec.rb +0 -189
- data/spec/extensions/shared_caching_spec.rb +0 -151
- data/spec/extensions/single_table_inheritance_spec.rb +0 -347
- data/spec/extensions/singular_table_names_spec.rb +0 -22
- data/spec/extensions/skip_create_refresh_spec.rb +0 -18
- data/spec/extensions/spec_helper.rb +0 -61
- data/spec/extensions/split_array_nil_spec.rb +0 -24
- data/spec/extensions/split_values_spec.rb +0 -57
- data/spec/extensions/sql_comments_spec.rb +0 -33
- data/spec/extensions/sql_expr_spec.rb +0 -59
- data/spec/extensions/static_cache_spec.rb +0 -410
- data/spec/extensions/string_agg_spec.rb +0 -90
- data/spec/extensions/string_date_time_spec.rb +0 -95
- data/spec/extensions/string_stripper_spec.rb +0 -68
- data/spec/extensions/subclasses_spec.rb +0 -79
- data/spec/extensions/subset_conditions_spec.rb +0 -38
- data/spec/extensions/symbol_aref_refinement_spec.rb +0 -28
- data/spec/extensions/symbol_as_refinement_spec.rb +0 -21
- data/spec/extensions/synchronize_sql_spec.rb +0 -124
- data/spec/extensions/table_select_spec.rb +0 -83
- data/spec/extensions/tactical_eager_loading_spec.rb +0 -141
- data/spec/extensions/thread_local_timezones_spec.rb +0 -67
- data/spec/extensions/timestamps_spec.rb +0 -209
- data/spec/extensions/to_dot_spec.rb +0 -153
- data/spec/extensions/touch_spec.rb +0 -226
- data/spec/extensions/tree_spec.rb +0 -284
- data/spec/extensions/typecast_on_load_spec.rb +0 -86
- data/spec/extensions/unlimited_update_spec.rb +0 -21
- data/spec/extensions/update_or_create_spec.rb +0 -83
- data/spec/extensions/update_primary_key_spec.rb +0 -105
- data/spec/extensions/update_refresh_spec.rb +0 -59
- data/spec/extensions/uuid_spec.rb +0 -101
- data/spec/extensions/validate_associated_spec.rb +0 -52
- data/spec/extensions/validation_class_methods_spec.rb +0 -1040
- data/spec/extensions/validation_contexts_spec.rb +0 -31
- data/spec/extensions/validation_helpers_spec.rb +0 -525
- data/spec/extensions/whitelist_security_spec.rb +0 -157
- data/spec/extensions/xml_serializer_spec.rb +0 -213
- data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
- data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
- data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
- data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
- data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/double_migration/001_create_sessions.rb +0 -9
- data/spec/files/double_migration/002_create_nodes.rb +0 -19
- data/spec/files/double_migration/003_3_create_users.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
- data/spec/files/empty_migration/001_create_sessions.rb +0 -9
- data/spec/files/empty_migration/002_create_nodes.rb +0 -0
- data/spec/files/empty_migration/003_3_create_users.rb +0 -4
- data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
- data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
- data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
- data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
- data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/reversible_migrations/001_reversible.rb +0 -5
- data/spec/files/reversible_migrations/002_reversible.rb +0 -5
- data/spec/files/reversible_migrations/003_reversible.rb +0 -5
- data/spec/files/reversible_migrations/004_reversible.rb +0 -5
- data/spec/files/reversible_migrations/005_reversible.rb +0 -10
- data/spec/files/reversible_migrations/006_reversible.rb +0 -10
- data/spec/files/reversible_migrations/007_reversible.rb +0 -10
- data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
- data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
- data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
- data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
- data/spec/guards_helper.rb +0 -58
- data/spec/integration/associations_test.rb +0 -2513
- data/spec/integration/database_test.rb +0 -113
- data/spec/integration/dataset_test.rb +0 -1880
- data/spec/integration/eager_loader_test.rb +0 -687
- data/spec/integration/migrator_test.rb +0 -262
- data/spec/integration/model_test.rb +0 -203
- data/spec/integration/plugin_test.rb +0 -2302
- data/spec/integration/prepared_statement_test.rb +0 -398
- data/spec/integration/schema_test.rb +0 -869
- data/spec/integration/spec_helper.rb +0 -64
- data/spec/integration/timezone_test.rb +0 -86
- data/spec/integration/transaction_test.rb +0 -354
- data/spec/integration/type_test.rb +0 -127
- data/spec/model/association_reflection_spec.rb +0 -803
- data/spec/model/associations_spec.rb +0 -4538
- data/spec/model/base_spec.rb +0 -817
- data/spec/model/class_dataset_methods_spec.rb +0 -146
- data/spec/model/dataset_methods_spec.rb +0 -198
- data/spec/model/eager_loading_spec.rb +0 -2262
- data/spec/model/hooks_spec.rb +0 -370
- data/spec/model/inflector_spec.rb +0 -26
- data/spec/model/model_spec.rb +0 -953
- data/spec/model/plugins_spec.rb +0 -318
- data/spec/model/record_spec.rb +0 -2107
- data/spec/model/spec_helper.rb +0 -45
- data/spec/model/validations_spec.rb +0 -193
- data/spec/model_no_assoc_spec.rb +0 -1
- data/spec/model_spec.rb +0 -1
- data/spec/plugin_spec.rb +0 -1
- data/spec/sequel_coverage.rb +0 -15
- data/spec/sequel_warning.rb +0 -4
- data/spec/spec_config.rb +0 -12
|
@@ -21,7 +21,7 @@ module Sequel
|
|
|
21
21
|
module Sharding
|
|
22
22
|
module ClassMethods
|
|
23
23
|
# Create a new object on the given shard s.
|
|
24
|
-
def create_using_server(s, values=
|
|
24
|
+
def create_using_server(s, values=OPTS, &block)
|
|
25
25
|
new_using_server(s, values, &block).save
|
|
26
26
|
end
|
|
27
27
|
|
|
@@ -45,7 +45,7 @@ module Sequel
|
|
|
45
45
|
# Return a newly instantiated object that is tied to the given
|
|
46
46
|
# shard s. When the object is saved, a record will be inserted
|
|
47
47
|
# on shard s.
|
|
48
|
-
def new_using_server(s, values=
|
|
48
|
+
def new_using_server(s, values=OPTS, &block)
|
|
49
49
|
new(values, &block).set_server(s)
|
|
50
50
|
end
|
|
51
51
|
|
|
@@ -107,12 +107,18 @@ module Sequel
|
|
|
107
107
|
# previous row_proc, but calls set_server on the output of that row_proc,
|
|
108
108
|
# ensuring that objects retrieved by a specific shard know which shard they
|
|
109
109
|
# are tied to.
|
|
110
|
-
def
|
|
111
|
-
|
|
112
|
-
if rp
|
|
113
|
-
|
|
110
|
+
def row_proc
|
|
111
|
+
rp = super
|
|
112
|
+
if rp
|
|
113
|
+
case server = db.pool.send(:pick_server, opts[:server])
|
|
114
|
+
when nil, :default, :read_only
|
|
115
|
+
# nothing
|
|
116
|
+
else
|
|
117
|
+
old_rp = rp
|
|
118
|
+
rp = proc{|r| old_rp.call(r).set_server(server)}
|
|
119
|
+
end
|
|
114
120
|
end
|
|
115
|
-
|
|
121
|
+
rp
|
|
116
122
|
end
|
|
117
123
|
end
|
|
118
124
|
end
|
|
@@ -163,21 +163,6 @@ module Sequel
|
|
|
163
163
|
super
|
|
164
164
|
end
|
|
165
165
|
|
|
166
|
-
# Copy the necessary attributes to the subclasses, and filter the
|
|
167
|
-
# subclass's dataset based on the sti_kep_map entry for the class.
|
|
168
|
-
def inherited(subclass)
|
|
169
|
-
super
|
|
170
|
-
key = Array(sti_key_map[subclass]).dup
|
|
171
|
-
sti_subclass_added(key)
|
|
172
|
-
rp = dataset.row_proc
|
|
173
|
-
subclass.set_dataset(sti_subclass_dataset(key), :inherited=>true)
|
|
174
|
-
subclass.instance_exec do
|
|
175
|
-
@dataset = @dataset.with_row_proc(rp)
|
|
176
|
-
@sti_key_array = key
|
|
177
|
-
self.simple_table = nil
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
|
|
181
166
|
# Return an instance of the class specified by sti_key,
|
|
182
167
|
# used by the row_proc.
|
|
183
168
|
def sti_load(r)
|
|
@@ -208,6 +193,21 @@ module Sequel
|
|
|
208
193
|
super
|
|
209
194
|
end
|
|
210
195
|
|
|
196
|
+
# Copy the necessary attributes to the subclasses, and filter the
|
|
197
|
+
# subclass's dataset based on the sti_kep_map entry for the class.
|
|
198
|
+
def inherited(subclass)
|
|
199
|
+
super
|
|
200
|
+
key = Array(sti_key_map[subclass]).dup
|
|
201
|
+
sti_subclass_added(key)
|
|
202
|
+
rp = dataset.row_proc
|
|
203
|
+
subclass.set_dataset(sti_subclass_dataset(key), :inherited=>true)
|
|
204
|
+
subclass.instance_exec do
|
|
205
|
+
@dataset = @dataset.with_row_proc(rp)
|
|
206
|
+
@sti_key_array = key
|
|
207
|
+
self.simple_table = nil
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
211
|
# If calling set_dataset manually, make sure to set the dataset
|
|
212
212
|
# row proc to one that handles inheritance correctly.
|
|
213
213
|
def set_dataset_row_proc(ds)
|
|
@@ -250,6 +250,11 @@ module Sequel
|
|
|
250
250
|
end
|
|
251
251
|
super
|
|
252
252
|
end
|
|
253
|
+
|
|
254
|
+
# Don't allow use of prepared statements.
|
|
255
|
+
def use_prepared_statements_for?(type)
|
|
256
|
+
false
|
|
257
|
+
end
|
|
253
258
|
end
|
|
254
259
|
end
|
|
255
260
|
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
3
|
+
module Sequel
|
|
4
|
+
module Plugins
|
|
5
|
+
# The skip_saving_columms plugin allows skipping specific columns when
|
|
6
|
+
# saving. By default, it skips columns that the database schema
|
|
7
|
+
# indicates are generated columns:
|
|
8
|
+
#
|
|
9
|
+
# # Assume id column, name column, and id2 generated column
|
|
10
|
+
# album = Album[1]
|
|
11
|
+
# album.id # => 1
|
|
12
|
+
# album.name # => 'X'
|
|
13
|
+
# album.id2 # => 2
|
|
14
|
+
# album.save
|
|
15
|
+
# # UPDATE album SET name = 'X' WHERE (id = 1)
|
|
16
|
+
#
|
|
17
|
+
# You can override which columns will be skipped:
|
|
18
|
+
#
|
|
19
|
+
# Album.skip_saving_columns = [:name]
|
|
20
|
+
# album.save
|
|
21
|
+
# # UPDATE album SET id2 = 2 WHERE (id = 1)
|
|
22
|
+
#
|
|
23
|
+
# The skipping happens for all usage of Model#save and callers of it (e.g.
|
|
24
|
+
# Model.create, Model.update). When using the plugin, the only way to get
|
|
25
|
+
# it to save a column marked for skipping is to explicitly specify it:
|
|
26
|
+
#
|
|
27
|
+
# album.save(columns: [:name, :id2])
|
|
28
|
+
# album.save
|
|
29
|
+
# # UPDATE album SET name = 'X', id2 = 2 WHERE (id = 1)
|
|
30
|
+
#
|
|
31
|
+
# Usage:
|
|
32
|
+
#
|
|
33
|
+
# # Support skipping saving columns in all Sequel::Model subclasses
|
|
34
|
+
# # (called before loading subclasses)
|
|
35
|
+
# Sequel::Model.plugin :skip_saving_columns
|
|
36
|
+
#
|
|
37
|
+
# # Support skipping saving columns in the Album class
|
|
38
|
+
# Album.plugin :skip_saving_columns
|
|
39
|
+
module SkipSavingColumns
|
|
40
|
+
# Setup skipping of the generated columns for a model with an existing dataset.
|
|
41
|
+
def self.configure(mod)
|
|
42
|
+
mod.instance_exec do
|
|
43
|
+
set_skip_saving_generated_columns if @dataset
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
module ClassMethods
|
|
48
|
+
# An array of column symbols for columns to skip when saving.
|
|
49
|
+
attr_reader :skip_saving_columns
|
|
50
|
+
|
|
51
|
+
# Over the default array of columns to skip. Once overridden, future
|
|
52
|
+
# changes to the class's dataset and future subclasses will automatically
|
|
53
|
+
# use these overridden columns, instead of introspecting the database schema.
|
|
54
|
+
def skip_saving_columns=(v)
|
|
55
|
+
@_skip_saving_columns_no_override = true
|
|
56
|
+
@skip_saving_columns = v.dup.freeze
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
Plugins.after_set_dataset(self, :set_skip_saving_generated_columns)
|
|
60
|
+
Plugins.inherited_instance_variables(self, :@skip_saving_columns=>:dup, :@_skip_saving_columns_no_override=>nil)
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
# If the skip saving columns has not been overridden, check the database
|
|
65
|
+
# schema and automatically skip any generated columns.
|
|
66
|
+
def set_skip_saving_generated_columns
|
|
67
|
+
return if @_skip_saving_columns_no_override
|
|
68
|
+
s = []
|
|
69
|
+
db_schema.each do |k, v|
|
|
70
|
+
s << k if v[:generated]
|
|
71
|
+
end
|
|
72
|
+
@skip_saving_columns = s.freeze
|
|
73
|
+
nil
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
module InstanceMethods
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
# Skip the columns the model has marked to skip when inserting.
|
|
81
|
+
def _insert_values
|
|
82
|
+
_save_removed_skipped_columns(Hash[super])
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Skip the columns the model has marked to skip when updating
|
|
86
|
+
# all columns.
|
|
87
|
+
def _save_update_all_columns_hash
|
|
88
|
+
_save_removed_skipped_columns(super)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Skip the columns the model has marked to skip when updating
|
|
92
|
+
# only changed columns.
|
|
93
|
+
def _save_update_changed_colums_hash
|
|
94
|
+
_save_removed_skipped_columns(super)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Remove any columns the model has marked to skip when saving.
|
|
98
|
+
def _save_removed_skipped_columns(hash)
|
|
99
|
+
model.skip_saving_columns.each do |column|
|
|
100
|
+
hash.delete(column)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
hash
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -24,6 +24,7 @@ module Sequel
|
|
|
24
24
|
# * Primary key lookups (e.g. Model[1])
|
|
25
25
|
# * Model.all
|
|
26
26
|
# * Model.each
|
|
27
|
+
# * Model.first (without block, only supporting no arguments or single integer argument)
|
|
27
28
|
# * Model.count (without an argument or block)
|
|
28
29
|
# * Model.map
|
|
29
30
|
# * Model.as_hash
|
|
@@ -54,6 +55,7 @@ module Sequel
|
|
|
54
55
|
# Now if you +#dup+ a Model object (the resulting object is not frozen), you
|
|
55
56
|
# will be able to update and save the duplicate.
|
|
56
57
|
# Note the caveats around your responsibility to update the cache still applies.
|
|
58
|
+
# You can update the cache via `.load_cache` method.
|
|
57
59
|
module StaticCache
|
|
58
60
|
# Populate the static caches when loading the plugin. Options:
|
|
59
61
|
# :frozen :: Whether retrieved model objects are frozen. The default is true,
|
|
@@ -70,13 +72,25 @@ module Sequel
|
|
|
70
72
|
# A frozen ruby hash holding all of the model's frozen instances, keyed by frozen primary key.
|
|
71
73
|
attr_reader :cache
|
|
72
74
|
|
|
73
|
-
# An array of all of the model's
|
|
74
|
-
# query.
|
|
75
|
-
def all
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
# An array of all of the model's instances, without issuing a database
|
|
76
|
+
# query. If a block is given, yields each instance to the block.
|
|
77
|
+
def all(&block)
|
|
78
|
+
array = @static_cache_frozen ? @all.dup : to_a
|
|
79
|
+
array.each(&block) if block
|
|
80
|
+
array
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# If a block is given, multiple arguments are given, or a single
|
|
84
|
+
# non-Integer argument is given, performs the default behavior of
|
|
85
|
+
# issuing a database query. Otherwise, uses the cached values
|
|
86
|
+
# to return either the first cached instance (no arguments) or an
|
|
87
|
+
# array containing the number of instances specified (single integer
|
|
88
|
+
# argument).
|
|
89
|
+
def first(*args)
|
|
90
|
+
if block_given? || args.length > 1 || (args.length == 1 && !args[0].is_a?(Integer))
|
|
91
|
+
super
|
|
78
92
|
else
|
|
79
|
-
|
|
93
|
+
@all.first(*args)
|
|
80
94
|
end
|
|
81
95
|
end
|
|
82
96
|
|
|
@@ -194,27 +208,32 @@ module Sequel
|
|
|
194
208
|
!@static_cache_frozen
|
|
195
209
|
end
|
|
196
210
|
|
|
197
|
-
private
|
|
198
|
-
|
|
199
|
-
# Return the frozen object with the given pk, or nil if no such object exists
|
|
200
|
-
# in the cache, without issuing a database query.
|
|
201
|
-
def primary_key_lookup(pk)
|
|
202
|
-
static_cache_object(cache[pk])
|
|
203
|
-
end
|
|
204
|
-
|
|
205
211
|
# Reload the cache for this model by retrieving all of the instances in the dataset
|
|
206
212
|
# freezing them, and populating the cached array and hash.
|
|
207
213
|
def load_cache
|
|
208
|
-
|
|
214
|
+
@all = load_static_cache_rows
|
|
209
215
|
h = {}
|
|
210
|
-
|
|
216
|
+
@all.each do |o|
|
|
211
217
|
o.errors.freeze
|
|
212
218
|
h[o.pk.freeze] = o.freeze
|
|
213
219
|
end
|
|
214
|
-
@all = a.freeze
|
|
215
220
|
@cache = h.freeze
|
|
216
221
|
end
|
|
217
222
|
|
|
223
|
+
private
|
|
224
|
+
|
|
225
|
+
# Load the static cache rows from the database.
|
|
226
|
+
def load_static_cache_rows
|
|
227
|
+
ret = super if defined?(super)
|
|
228
|
+
ret || dataset.all.freeze
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
# Return the frozen object with the given pk, or nil if no such object exists
|
|
232
|
+
# in the cache, without issuing a database query.
|
|
233
|
+
def primary_key_lookup(pk)
|
|
234
|
+
static_cache_object(cache[pk])
|
|
235
|
+
end
|
|
236
|
+
|
|
218
237
|
# If frozen: false is not used, just return the argument. Otherwise,
|
|
219
238
|
# create a new instance with the arguments values if the argument is
|
|
220
239
|
# not nil.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
3
|
+
module Sequel
|
|
4
|
+
module Plugins
|
|
5
|
+
# The static_cache_cache plugin allows for caching the row content for subclasses
|
|
6
|
+
# that use the static cache plugin (or just the current class). Using this plugin
|
|
7
|
+
# can avoid the need to query the database every time loading the plugin into a
|
|
8
|
+
# model, which can save time when you have a lot of models using the static_cache
|
|
9
|
+
# plugin.
|
|
10
|
+
#
|
|
11
|
+
# Usage:
|
|
12
|
+
#
|
|
13
|
+
# # Make all model subclasses that use the static_cache plugin use
|
|
14
|
+
# # the cached values in the given file
|
|
15
|
+
# Sequel::Model.plugin :static_cache_cache, "static_cache.cache"
|
|
16
|
+
#
|
|
17
|
+
# # Make the AlbumType model the cached values in the given file,
|
|
18
|
+
# # should be loaded before the static_cache plugin
|
|
19
|
+
# AlbumType.plugin :static_cache_cache, "static_cache.cache"
|
|
20
|
+
module StaticCacheCache
|
|
21
|
+
def self.configure(model, file)
|
|
22
|
+
model.instance_variable_set(:@static_cache_cache_file, file)
|
|
23
|
+
model.instance_variable_set(:@static_cache_cache, File.exist?(file) ? Marshal.load(File.read(file)) : {})
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
module ClassMethods
|
|
27
|
+
# Dump the in-memory cached rows to the cache file.
|
|
28
|
+
def dump_static_cache_cache
|
|
29
|
+
File.open(@static_cache_cache_file, 'wb'){|f| f.write(Marshal.dump(@static_cache_cache))}
|
|
30
|
+
nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
Plugins.inherited_instance_variables(self, :@static_cache_cache_file=>nil, :@static_cache_cache=>nil)
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
# Load the rows for the model from the cache if available.
|
|
38
|
+
# If not available, load the rows from the database, and
|
|
39
|
+
# then update the cache with the raw rows.
|
|
40
|
+
def load_static_cache_rows
|
|
41
|
+
if rows = Sequel.synchronize{@static_cache_cache[name]}
|
|
42
|
+
rows.map{|row| call(row)}.freeze
|
|
43
|
+
else
|
|
44
|
+
rows = dataset.all.freeze
|
|
45
|
+
raw_rows = rows.map(&:values)
|
|
46
|
+
Sequel.synchronize{@static_cache_cache[name] = raw_rows}
|
|
47
|
+
rows
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -28,7 +28,7 @@ module Sequel
|
|
|
28
28
|
model.plugin(:input_transformer, :string_stripper){|v| (v.is_a?(String) && !v.is_a?(SQL::Blob)) ? v.strip : v}
|
|
29
29
|
end
|
|
30
30
|
def self.configure(model)
|
|
31
|
-
model.
|
|
31
|
+
model.send(:set_skipped_string_stripping_columns)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
module ClassMethods
|
|
@@ -63,6 +63,8 @@ module Sequel
|
|
|
63
63
|
|
|
64
64
|
Plugins.inherited_instance_variables(self, :@subclasses=>lambda{|v| []}, :@on_subclass=>nil)
|
|
65
65
|
|
|
66
|
+
private
|
|
67
|
+
|
|
66
68
|
# Add the subclass to this model's current subclasses,
|
|
67
69
|
# and initialize a new subclasses instance variable
|
|
68
70
|
# in the subclass.
|
|
@@ -26,8 +26,8 @@ module Sequel
|
|
|
26
26
|
# Album.where(Album.published_conditions | {ready: true}).sql
|
|
27
27
|
# # SELECT * FROM albums WHERE ((published IS TRUE) OR (ready IS TRUE))
|
|
28
28
|
module SubsetConditions
|
|
29
|
-
def self.apply(
|
|
30
|
-
|
|
29
|
+
def self.apply(model, &block)
|
|
30
|
+
model.instance_exec do
|
|
31
31
|
@dataset_module_class = Class.new(@dataset_module_class) do
|
|
32
32
|
include DatasetModuleMethods
|
|
33
33
|
end
|
|
@@ -60,6 +60,55 @@ module Sequel
|
|
|
60
60
|
# # SELECT * FROM artists WHERE name > 'N' AND id IN (...)
|
|
61
61
|
# albums.first.artists(eager: lambda{|ds| ds.where(Sequel[:name] > 'N')})
|
|
62
62
|
#
|
|
63
|
+
# Note that the :eager option only takes effect if the association
|
|
64
|
+
# has not already been loaded for the model.
|
|
65
|
+
#
|
|
66
|
+
# The tactical_eager_loading plugin also allows transparent eager
|
|
67
|
+
# loading when calling association methods on associated objects
|
|
68
|
+
# eagerly loaded via Dataset#eager_graph. This can reduce N queries
|
|
69
|
+
# to a single query when iterating over all associated objects.
|
|
70
|
+
# Consider the following code:
|
|
71
|
+
#
|
|
72
|
+
# artists = Artist.eager_graph(:albums).all
|
|
73
|
+
# artists.each do |artist|
|
|
74
|
+
# artist.albums.each do |album|
|
|
75
|
+
# album.tracks
|
|
76
|
+
# end
|
|
77
|
+
# end
|
|
78
|
+
#
|
|
79
|
+
# By default this will issue a single query to load the artists and
|
|
80
|
+
# albums, and then one query for each album to load the tracks for
|
|
81
|
+
# the album:
|
|
82
|
+
#
|
|
83
|
+
# # SELECT artists.id, ...
|
|
84
|
+
# albums.id, ...
|
|
85
|
+
# # FROM artists
|
|
86
|
+
# # LEFT OUTER JOIN albums ON (albums.artist_id = artists.id);
|
|
87
|
+
# # SELECT * FROM tracks WHERE album_id = 1;
|
|
88
|
+
# # SELECT * FROM tracks WHERE album_id = 2;
|
|
89
|
+
# # SELECT * FROM tracks WHERE album_id = 10;
|
|
90
|
+
# # ...
|
|
91
|
+
#
|
|
92
|
+
# With the tactical_eager_loading plugin, this uses the same
|
|
93
|
+
# query to load the artists and albums, but then issues a single query
|
|
94
|
+
# to load the tracks for all albums.
|
|
95
|
+
#
|
|
96
|
+
# # SELECT artists.id, ...
|
|
97
|
+
# albums.id, ...
|
|
98
|
+
# # FROM artists
|
|
99
|
+
# # LEFT OUTER JOIN albums ON (albums.artist_id = artists.id);
|
|
100
|
+
# # SELECT * FROM tracks WHERE (tracks.album_id IN (1, 2, 10, ...));
|
|
101
|
+
#
|
|
102
|
+
# Note that transparent eager loading for associated objects
|
|
103
|
+
# loaded by eager_graph will only take place if the associated classes
|
|
104
|
+
# also use the tactical_eager_loading plugin.
|
|
105
|
+
#
|
|
106
|
+
# When using this plugin, calling association methods on separate
|
|
107
|
+
# instances of the same result set is not thread-safe, because this
|
|
108
|
+
# plugin attempts to modify all instances of the same result set
|
|
109
|
+
# to eagerly set the associated objects, and having separate threads
|
|
110
|
+
# modify the same model instance is not thread-safe.
|
|
111
|
+
#
|
|
63
112
|
# Usage:
|
|
64
113
|
#
|
|
65
114
|
# # Make all model subclass instances use tactical eager loading (called before loading subclasses)
|
|
@@ -96,7 +145,7 @@ module Sequel
|
|
|
96
145
|
name = opts[:name]
|
|
97
146
|
if (!associations.include?(name) || dynamic_opts[:eager_reload]) && opts[:allow_eager] != false && retrieved_by && !frozen? && !dynamic_opts[:callback] && !dynamic_opts[:reload]
|
|
98
147
|
begin
|
|
99
|
-
retrieved_by.send(:eager_load, retrieved_with.reject(&:frozen?), name=>dynamic_opts[:eager] ||
|
|
148
|
+
retrieved_by.send(:eager_load, retrieved_with.reject(&:frozen?), name=>dynamic_opts[:eager] || OPTS)
|
|
100
149
|
rescue Sequel::UndefinedAssociation
|
|
101
150
|
# This can happen if class table inheritance is used and the association
|
|
102
151
|
# is only defined in a subclass. This particular instance can use the
|
|
@@ -112,7 +161,29 @@ module Sequel
|
|
|
112
161
|
module DatasetMethods
|
|
113
162
|
private
|
|
114
163
|
|
|
115
|
-
# Set the retrieved_with and retrieved_by attributes for the
|
|
164
|
+
# Set the retrieved_with and retrieved_by attributes for each of the associated objects
|
|
165
|
+
# created by the eager graph loader with the appropriate class dataset and array of objects.
|
|
166
|
+
def _eager_graph_build_associations(_, egl)
|
|
167
|
+
objects = super
|
|
168
|
+
|
|
169
|
+
master = egl.master
|
|
170
|
+
egl.records_map.each do |k, v|
|
|
171
|
+
next if k == master || v.empty?
|
|
172
|
+
|
|
173
|
+
by = opts[:graph][:table_aliases][k]
|
|
174
|
+
values = v.values
|
|
175
|
+
|
|
176
|
+
values.each do |o|
|
|
177
|
+
next unless o.is_a?(TacticalEagerLoading::InstanceMethods) && !o.retrieved_by
|
|
178
|
+
o.retrieved_by = by
|
|
179
|
+
o.retrieved_with = values
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
objects
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# Set the retrieved_with and retrieved_by attributes for each object
|
|
116
187
|
# with the current dataset and array of all objects.
|
|
117
188
|
def post_load(objects)
|
|
118
189
|
super
|