sequel 4.49.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +70 -0
- data/README.rdoc +195 -136
- data/Rakefile +26 -42
- data/bin/sequel +3 -5
- data/doc/advanced_associations.rdoc +86 -163
- data/doc/association_basics.rdoc +197 -274
- data/doc/bin_sequel.rdoc +5 -3
- data/doc/cheat_sheet.rdoc +66 -43
- data/doc/code_order.rdoc +1 -8
- data/doc/core_extensions.rdoc +81 -56
- data/doc/dataset_basics.rdoc +8 -17
- data/doc/dataset_filtering.rdoc +81 -86
- data/doc/extensions.rdoc +3 -10
- data/doc/mass_assignment.rdoc +73 -30
- data/doc/migration.rdoc +19 -36
- data/doc/model_dataset_method_design.rdoc +14 -17
- data/doc/model_hooks.rdoc +15 -25
- data/doc/model_plugins.rdoc +10 -10
- data/doc/mssql_stored_procedures.rdoc +3 -3
- data/doc/object_model.rdoc +52 -70
- data/doc/opening_databases.rdoc +39 -32
- data/doc/postgresql.rdoc +48 -38
- data/doc/prepared_statements.rdoc +27 -22
- data/doc/querying.rdoc +173 -150
- data/doc/reflection.rdoc +5 -6
- data/doc/release_notes/5.0.0.txt +159 -0
- data/doc/schema_modification.rdoc +63 -60
- data/doc/security.rdoc +97 -88
- data/doc/sharding.rdoc +43 -30
- data/doc/sql.rdoc +53 -65
- data/doc/testing.rdoc +3 -5
- data/doc/thread_safety.rdoc +2 -4
- data/doc/transactions.rdoc +18 -17
- data/doc/validations.rdoc +48 -45
- data/doc/virtual_rows.rdoc +87 -115
- data/lib/sequel.rb +1 -1
- data/lib/sequel/adapters/ado.rb +9 -25
- data/lib/sequel/adapters/ado/access.rb +7 -13
- data/lib/sequel/adapters/ado/mssql.rb +2 -9
- data/lib/sequel/adapters/amalgalite.rb +3 -18
- data/lib/sequel/adapters/ibmdb.rb +9 -45
- data/lib/sequel/adapters/jdbc.rb +13 -73
- data/lib/sequel/adapters/jdbc/db2.rb +8 -37
- data/lib/sequel/adapters/jdbc/derby.rb +4 -50
- data/lib/sequel/adapters/jdbc/h2.rb +4 -25
- data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -26
- data/lib/sequel/adapters/jdbc/jtds.rb +2 -9
- data/lib/sequel/adapters/jdbc/mssql.rb +1 -11
- data/lib/sequel/adapters/jdbc/mysql.rb +1 -15
- data/lib/sequel/adapters/jdbc/oracle.rb +4 -26
- data/lib/sequel/adapters/jdbc/postgresql.rb +2 -31
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +4 -17
- data/lib/sequel/adapters/jdbc/sqlite.rb +1 -7
- data/lib/sequel/adapters/jdbc/sqlserver.rb +1 -13
- data/lib/sequel/adapters/jdbc/transactions.rb +1 -14
- data/lib/sequel/adapters/mock.rb +4 -30
- data/lib/sequel/adapters/mysql.rb +7 -44
- data/lib/sequel/adapters/mysql2.rb +5 -23
- data/lib/sequel/adapters/odbc.rb +0 -19
- data/lib/sequel/adapters/odbc/db2.rb +1 -1
- data/lib/sequel/adapters/odbc/mssql.rb +4 -12
- data/lib/sequel/adapters/odbc/oracle.rb +1 -1
- data/lib/sequel/adapters/oracle.rb +7 -13
- data/lib/sequel/adapters/postgres.rb +13 -57
- data/lib/sequel/adapters/postgresql.rb +1 -1
- data/lib/sequel/adapters/shared/access.rb +11 -51
- data/lib/sequel/adapters/shared/db2.rb +3 -61
- data/lib/sequel/adapters/shared/mssql.rb +21 -157
- data/lib/sequel/adapters/shared/mysql.rb +23 -224
- data/lib/sequel/adapters/shared/oracle.rb +13 -41
- data/lib/sequel/adapters/shared/postgres.rb +44 -259
- data/lib/sequel/adapters/shared/sqlanywhere.rb +4 -96
- data/lib/sequel/adapters/shared/sqlite.rb +12 -101
- data/lib/sequel/adapters/sqlanywhere.rb +4 -23
- data/lib/sequel/adapters/sqlite.rb +2 -19
- data/lib/sequel/adapters/tinytds.rb +5 -15
- data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +1 -1
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +2 -4
- data/lib/sequel/adapters/utils/mysql_prepared_statements.rb +3 -6
- data/lib/sequel/adapters/utils/replace.rb +0 -5
- data/lib/sequel/adapters/utils/stored_procedures.rb +0 -2
- data/lib/sequel/adapters/utils/unmodified_identifiers.rb +2 -0
- data/lib/sequel/ast_transformer.rb +3 -94
- data/lib/sequel/connection_pool.rb +26 -28
- data/lib/sequel/connection_pool/sharded_single.rb +1 -4
- data/lib/sequel/connection_pool/sharded_threaded.rb +97 -95
- data/lib/sequel/connection_pool/single.rb +0 -2
- data/lib/sequel/connection_pool/threaded.rb +94 -110
- data/lib/sequel/core.rb +42 -101
- data/lib/sequel/database.rb +12 -2
- data/lib/sequel/database/connecting.rb +23 -60
- data/lib/sequel/database/dataset.rb +6 -9
- data/lib/sequel/database/dataset_defaults.rb +4 -48
- data/lib/sequel/database/features.rb +5 -4
- data/lib/sequel/database/logging.rb +2 -9
- data/lib/sequel/database/misc.rb +23 -55
- data/lib/sequel/database/query.rb +8 -13
- data/lib/sequel/database/schema_generator.rb +89 -64
- data/lib/sequel/database/schema_methods.rb +61 -79
- data/lib/sequel/database/transactions.rb +4 -24
- data/lib/sequel/dataset.rb +18 -10
- data/lib/sequel/dataset/actions.rb +53 -107
- data/lib/sequel/dataset/dataset_module.rb +3 -15
- data/lib/sequel/dataset/features.rb +30 -30
- data/lib/sequel/dataset/graph.rb +40 -49
- data/lib/sequel/dataset/misc.rb +12 -37
- data/lib/sequel/dataset/placeholder_literalizer.rb +4 -4
- data/lib/sequel/dataset/prepared_statements.rb +23 -51
- data/lib/sequel/dataset/query.rb +71 -155
- data/lib/sequel/dataset/sql.rb +30 -225
- data/lib/sequel/deprecated.rb +18 -27
- data/lib/sequel/exceptions.rb +1 -17
- data/lib/sequel/extensions/_model_pg_row.rb +0 -7
- data/lib/sequel/extensions/_pretty_table.rb +1 -3
- data/lib/sequel/extensions/arbitrary_servers.rb +10 -10
- data/lib/sequel/extensions/connection_expiration.rb +1 -1
- data/lib/sequel/extensions/connection_validator.rb +1 -1
- data/lib/sequel/extensions/constraint_validations.rb +11 -11
- data/lib/sequel/extensions/core_extensions.rb +39 -49
- data/lib/sequel/extensions/core_refinements.rb +39 -45
- data/lib/sequel/extensions/current_datetime_timestamp.rb +0 -4
- data/lib/sequel/extensions/date_arithmetic.rb +7 -7
- data/lib/sequel/extensions/duplicate_columns_handler.rb +12 -9
- data/lib/sequel/extensions/empty_array_consider_nulls.rb +2 -2
- data/lib/sequel/extensions/eval_inspect.rb +4 -11
- data/lib/sequel/extensions/freeze_datasets.rb +1 -69
- data/lib/sequel/extensions/from_block.rb +1 -35
- data/lib/sequel/extensions/graph_each.rb +2 -2
- data/lib/sequel/extensions/identifier_mangling.rb +9 -19
- data/lib/sequel/extensions/implicit_subquery.rb +2 -2
- data/lib/sequel/extensions/inflector.rb +4 -4
- data/lib/sequel/extensions/migration.rb +23 -40
- data/lib/sequel/extensions/no_auto_literal_strings.rb +2 -84
- data/lib/sequel/extensions/null_dataset.rb +2 -8
- data/lib/sequel/extensions/pagination.rb +1 -17
- data/lib/sequel/extensions/pg_array.rb +20 -189
- data/lib/sequel/extensions/pg_hstore.rb +11 -50
- data/lib/sequel/extensions/pg_hstore_ops.rb +2 -2
- data/lib/sequel/extensions/pg_inet.rb +2 -15
- data/lib/sequel/extensions/pg_interval.rb +1 -20
- data/lib/sequel/extensions/pg_json.rb +7 -27
- data/lib/sequel/extensions/pg_loose_count.rb +1 -1
- data/lib/sequel/extensions/pg_range.rb +6 -121
- data/lib/sequel/extensions/pg_range_ops.rb +1 -3
- data/lib/sequel/extensions/pg_row.rb +5 -77
- data/lib/sequel/extensions/pg_row_ops.rb +2 -13
- data/lib/sequel/extensions/query.rb +3 -4
- data/lib/sequel/extensions/round_timestamps.rb +0 -6
- data/lib/sequel/extensions/schema_dumper.rb +13 -13
- data/lib/sequel/extensions/select_remove.rb +3 -3
- data/lib/sequel/extensions/split_array_nil.rb +2 -2
- data/lib/sequel/extensions/sql_comments.rb +2 -2
- data/lib/sequel/extensions/string_agg.rb +11 -8
- data/lib/sequel/extensions/symbol_aref.rb +6 -20
- data/lib/sequel/model.rb +27 -62
- data/lib/sequel/model/associations.rb +128 -131
- data/lib/sequel/model/base.rb +171 -711
- data/lib/sequel/model/default_inflections.rb +1 -1
- data/lib/sequel/model/errors.rb +0 -3
- data/lib/sequel/model/exceptions.rb +2 -6
- data/lib/sequel/model/inflections.rb +1 -26
- data/lib/sequel/model/plugins.rb +1 -0
- data/lib/sequel/plugins/active_model.rb +2 -5
- data/lib/sequel/plugins/association_dependencies.rb +15 -15
- data/lib/sequel/plugins/association_pks.rb +14 -28
- data/lib/sequel/plugins/association_proxies.rb +6 -7
- data/lib/sequel/plugins/auto_validations.rb +4 -4
- data/lib/sequel/plugins/before_after_save.rb +0 -43
- data/lib/sequel/plugins/blacklist_security.rb +9 -8
- data/lib/sequel/plugins/boolean_readers.rb +3 -3
- data/lib/sequel/plugins/boolean_subsets.rb +2 -2
- data/lib/sequel/plugins/caching.rb +5 -5
- data/lib/sequel/plugins/class_table_inheritance.rb +71 -102
- data/lib/sequel/plugins/column_conflicts.rb +2 -2
- data/lib/sequel/plugins/column_select.rb +2 -2
- data/lib/sequel/plugins/composition.rb +15 -24
- data/lib/sequel/plugins/constraint_validations.rb +4 -3
- data/lib/sequel/plugins/csv_serializer.rb +13 -20
- data/lib/sequel/plugins/dataset_associations.rb +2 -2
- data/lib/sequel/plugins/def_dataset_method.rb +5 -5
- data/lib/sequel/plugins/defaults_setter.rb +1 -1
- data/lib/sequel/plugins/delay_add_association.rb +1 -1
- data/lib/sequel/plugins/finder.rb +16 -10
- data/lib/sequel/plugins/force_encoding.rb +1 -7
- data/lib/sequel/plugins/hook_class_methods.rb +4 -106
- data/lib/sequel/plugins/input_transformer.rb +10 -11
- data/lib/sequel/plugins/insert_returning_select.rb +1 -9
- data/lib/sequel/plugins/instance_filters.rb +5 -5
- data/lib/sequel/plugins/instance_hooks.rb +7 -52
- data/lib/sequel/plugins/inverted_subsets.rb +3 -1
- data/lib/sequel/plugins/json_serializer.rb +19 -19
- data/lib/sequel/plugins/lazy_attributes.rb +1 -10
- data/lib/sequel/plugins/list.rb +6 -6
- data/lib/sequel/plugins/many_through_many.rb +11 -8
- data/lib/sequel/plugins/mssql_optimistic_locking.rb +3 -3
- data/lib/sequel/plugins/nested_attributes.rb +18 -31
- data/lib/sequel/plugins/optimistic_locking.rb +3 -3
- data/lib/sequel/plugins/pg_array_associations.rb +8 -2
- data/lib/sequel/plugins/pg_row.rb +2 -11
- data/lib/sequel/plugins/prepared_statements.rb +13 -66
- data/lib/sequel/plugins/prepared_statements_safe.rb +1 -1
- data/lib/sequel/plugins/rcte_tree.rb +7 -7
- data/lib/sequel/plugins/serialization.rb +15 -33
- data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
- data/lib/sequel/plugins/sharding.rb +2 -8
- data/lib/sequel/plugins/single_table_inheritance.rb +10 -13
- data/lib/sequel/plugins/skip_create_refresh.rb +3 -3
- data/lib/sequel/plugins/static_cache.rb +8 -9
- data/lib/sequel/plugins/string_stripper.rb +3 -3
- data/lib/sequel/plugins/subclasses.rb +1 -1
- data/lib/sequel/plugins/subset_conditions.rb +2 -2
- data/lib/sequel/plugins/table_select.rb +2 -2
- data/lib/sequel/plugins/tactical_eager_loading.rb +4 -4
- data/lib/sequel/plugins/timestamps.rb +6 -7
- data/lib/sequel/plugins/touch.rb +4 -8
- data/lib/sequel/plugins/tree.rb +3 -3
- data/lib/sequel/plugins/typecast_on_load.rb +2 -2
- data/lib/sequel/plugins/unlimited_update.rb +1 -7
- data/lib/sequel/plugins/update_or_create.rb +3 -3
- data/lib/sequel/plugins/update_refresh.rb +3 -3
- data/lib/sequel/plugins/uuid.rb +7 -11
- data/lib/sequel/plugins/validation_class_methods.rb +10 -9
- data/lib/sequel/plugins/validation_contexts.rb +4 -4
- data/lib/sequel/plugins/validation_helpers.rb +26 -25
- data/lib/sequel/plugins/whitelist_security.rb +13 -9
- data/lib/sequel/plugins/xml_serializer.rb +24 -25
- data/lib/sequel/sql.rb +145 -276
- data/lib/sequel/timezones.rb +8 -22
- data/lib/sequel/version.rb +2 -2
- data/spec/adapter_spec.rb +1 -1
- data/spec/adapters/db2_spec.rb +2 -103
- data/spec/adapters/mssql_spec.rb +89 -68
- data/spec/adapters/mysql_spec.rb +101 -480
- data/spec/adapters/oracle_spec.rb +1 -9
- data/spec/adapters/postgres_spec.rb +312 -565
- data/spec/adapters/spec_helper.rb +12 -31
- data/spec/adapters/sqlanywhere_spec.rb +2 -77
- data/spec/adapters/sqlite_spec.rb +8 -146
- data/spec/bin_spec.rb +11 -16
- data/spec/core/connection_pool_spec.rb +173 -74
- data/spec/core/database_spec.rb +64 -244
- data/spec/core/dataset_spec.rb +81 -415
- data/spec/core/deprecated_spec.rb +3 -3
- data/spec/core/expression_filters_spec.rb +37 -144
- data/spec/core/mock_adapter_spec.rb +176 -4
- data/spec/core/object_graph_spec.rb +11 -60
- data/spec/core/placeholder_literalizer_spec.rb +1 -14
- data/spec/core/schema_generator_spec.rb +51 -40
- data/spec/core/schema_spec.rb +74 -77
- data/spec/core/spec_helper.rb +6 -24
- data/spec/core/version_spec.rb +1 -1
- data/spec/core_extensions_spec.rb +7 -83
- data/spec/core_model_spec.rb +2 -2
- data/spec/deprecation_helper.rb +2 -14
- data/spec/extensions/accessed_columns_spec.rb +1 -1
- data/spec/extensions/active_model_spec.rb +3 -3
- data/spec/extensions/after_initialize_spec.rb +1 -1
- data/spec/extensions/arbitrary_servers_spec.rb +2 -2
- data/spec/extensions/association_dependencies_spec.rb +1 -1
- data/spec/extensions/association_pks_spec.rb +4 -59
- data/spec/extensions/association_proxies_spec.rb +1 -1
- data/spec/extensions/auto_literal_strings_spec.rb +1 -12
- data/spec/extensions/auto_validations_spec.rb +1 -1
- data/spec/extensions/blacklist_security_spec.rb +1 -1
- data/spec/extensions/blank_spec.rb +1 -1
- data/spec/extensions/boolean_readers_spec.rb +1 -1
- data/spec/extensions/boolean_subsets_spec.rb +1 -1
- data/spec/extensions/caching_spec.rb +1 -1
- data/spec/extensions/class_table_inheritance_spec.rb +35 -1086
- data/spec/extensions/column_conflicts_spec.rb +1 -1
- data/spec/extensions/column_select_spec.rb +4 -4
- data/spec/extensions/columns_introspection_spec.rb +1 -1
- data/spec/extensions/columns_updated_spec.rb +1 -1
- data/spec/extensions/composition_spec.rb +1 -7
- data/spec/extensions/connection_expiration_spec.rb +3 -3
- data/spec/extensions/connection_validator_spec.rb +3 -3
- data/spec/extensions/constraint_validations_plugin_spec.rb +1 -1
- data/spec/extensions/constraint_validations_spec.rb +1 -1
- data/spec/extensions/core_refinements_spec.rb +1 -3
- data/spec/extensions/csv_serializer_spec.rb +4 -9
- data/spec/extensions/current_datetime_timestamp_spec.rb +1 -1
- data/spec/extensions/dataset_associations_spec.rb +2 -1
- data/spec/extensions/dataset_source_alias_spec.rb +1 -1
- data/spec/extensions/date_arithmetic_spec.rb +3 -3
- data/spec/extensions/def_dataset_method_spec.rb +1 -1
- data/spec/extensions/defaults_setter_spec.rb +2 -2
- data/spec/extensions/delay_add_association_spec.rb +8 -9
- data/spec/extensions/dirty_spec.rb +1 -1
- data/spec/extensions/duplicate_columns_handler_spec.rb +1 -1
- data/spec/extensions/eager_each_spec.rb +2 -2
- data/spec/extensions/empty_array_consider_nulls_spec.rb +1 -1
- data/spec/extensions/error_splitter_spec.rb +1 -1
- data/spec/extensions/error_sql_spec.rb +1 -1
- data/spec/extensions/eval_inspect_spec.rb +1 -1
- data/spec/extensions/finder_spec.rb +1 -1
- data/spec/extensions/force_encoding_spec.rb +2 -5
- data/spec/extensions/freeze_datasets_spec.rb +1 -1
- data/spec/extensions/graph_each_spec.rb +5 -5
- data/spec/extensions/hook_class_methods_spec.rb +1 -194
- data/spec/extensions/identifier_mangling_spec.rb +17 -170
- data/spec/extensions/implicit_subquery_spec.rb +1 -5
- data/spec/extensions/inflector_spec.rb +1 -1
- data/spec/extensions/input_transformer_spec.rb +7 -2
- data/spec/extensions/insert_returning_select_spec.rb +1 -1
- data/spec/extensions/instance_filters_spec.rb +1 -1
- data/spec/extensions/instance_hooks_spec.rb +1 -95
- data/spec/extensions/inverted_subsets_spec.rb +1 -1
- data/spec/extensions/json_serializer_spec.rb +1 -1
- data/spec/extensions/lazy_attributes_spec.rb +1 -7
- data/spec/extensions/list_spec.rb +1 -1
- data/spec/extensions/looser_typecasting_spec.rb +1 -1
- data/spec/extensions/many_through_many_spec.rb +1 -1
- data/spec/extensions/migration_spec.rb +2 -2
- data/spec/extensions/modification_detection_spec.rb +1 -1
- data/spec/extensions/mssql_optimistic_locking_spec.rb +1 -1
- data/spec/extensions/named_timezones_spec.rb +3 -3
- data/spec/extensions/nested_attributes_spec.rb +1 -29
- data/spec/extensions/null_dataset_spec.rb +1 -11
- data/spec/extensions/optimistic_locking_spec.rb +1 -1
- data/spec/extensions/pagination_spec.rb +1 -1
- data/spec/extensions/pg_array_associations_spec.rb +4 -1
- data/spec/extensions/pg_array_ops_spec.rb +1 -1
- data/spec/extensions/pg_array_spec.rb +3 -48
- data/spec/extensions/pg_enum_spec.rb +1 -1
- data/spec/extensions/pg_hstore_ops_spec.rb +1 -1
- data/spec/extensions/pg_hstore_spec.rb +23 -32
- data/spec/extensions/pg_inet_ops_spec.rb +1 -1
- data/spec/extensions/pg_inet_spec.rb +1 -14
- data/spec/extensions/pg_interval_spec.rb +3 -13
- data/spec/extensions/pg_json_ops_spec.rb +1 -1
- data/spec/extensions/pg_json_spec.rb +1 -13
- data/spec/extensions/pg_loose_count_spec.rb +1 -1
- data/spec/extensions/pg_range_ops_spec.rb +1 -1
- data/spec/extensions/pg_range_spec.rb +3 -88
- data/spec/extensions/pg_row_ops_spec.rb +1 -1
- data/spec/extensions/pg_row_plugin_spec.rb +1 -1
- data/spec/extensions/pg_row_spec.rb +1 -44
- data/spec/extensions/pg_static_cache_updater_spec.rb +1 -1
- data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
- data/spec/extensions/prepared_statements_spec.rb +13 -48
- data/spec/extensions/pretty_table_spec.rb +1 -1
- data/spec/extensions/query_spec.rb +1 -12
- data/spec/extensions/rcte_tree_spec.rb +1 -1
- data/spec/extensions/round_timestamps_spec.rb +1 -5
- data/spec/extensions/s_spec.rb +1 -1
- data/spec/extensions/schema_caching_spec.rb +1 -1
- data/spec/extensions/schema_dumper_spec.rb +1 -1
- data/spec/extensions/select_remove_spec.rb +1 -1
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +1 -1
- data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
- data/spec/extensions/serialization_spec.rb +2 -14
- data/spec/extensions/server_block_spec.rb +1 -1
- data/spec/extensions/server_logging_spec.rb +2 -2
- data/spec/extensions/sharding_spec.rb +1 -1
- data/spec/extensions/shared_caching_spec.rb +1 -28
- data/spec/extensions/single_table_inheritance_spec.rb +2 -5
- data/spec/extensions/singular_table_names_spec.rb +1 -1
- data/spec/extensions/skip_create_refresh_spec.rb +1 -1
- data/spec/extensions/spec_helper.rb +5 -27
- data/spec/extensions/split_array_nil_spec.rb +1 -1
- data/spec/extensions/split_values_spec.rb +1 -1
- data/spec/extensions/sql_comments_spec.rb +1 -1
- data/spec/extensions/sql_expr_spec.rb +1 -1
- data/spec/extensions/static_cache_spec.rb +1 -1
- data/spec/extensions/string_agg_spec.rb +2 -2
- data/spec/extensions/string_date_time_spec.rb +1 -1
- data/spec/extensions/string_stripper_spec.rb +1 -1
- data/spec/extensions/subclasses_spec.rb +1 -1
- data/spec/extensions/subset_conditions_spec.rb +1 -1
- data/spec/extensions/symbol_aref_refinement_spec.rb +1 -1
- data/spec/extensions/symbol_as_refinement_spec.rb +1 -1
- data/spec/extensions/table_select_spec.rb +4 -4
- data/spec/extensions/tactical_eager_loading_spec.rb +1 -6
- data/spec/extensions/thread_local_timezones_spec.rb +1 -1
- data/spec/extensions/timestamps_spec.rb +3 -3
- data/spec/extensions/to_dot_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +1 -1
- data/spec/extensions/tree_spec.rb +1 -1
- data/spec/extensions/typecast_on_load_spec.rb +1 -1
- data/spec/extensions/unlimited_update_spec.rb +1 -1
- data/spec/extensions/update_or_create_spec.rb +1 -1
- data/spec/extensions/update_primary_key_spec.rb +4 -3
- data/spec/extensions/update_refresh_spec.rb +1 -1
- data/spec/extensions/uuid_spec.rb +10 -12
- data/spec/extensions/validate_associated_spec.rb +1 -1
- data/spec/extensions/validation_class_methods_spec.rb +3 -3
- data/spec/extensions/validation_contexts_spec.rb +1 -1
- data/spec/extensions/validation_helpers_spec.rb +10 -44
- data/spec/extensions/whitelist_security_spec.rb +5 -5
- data/spec/extensions/xml_serializer_spec.rb +3 -3
- data/spec/guards_helper.rb +2 -1
- data/spec/integration/associations_test.rb +1 -23
- data/spec/integration/database_test.rb +7 -7
- data/spec/integration/dataset_test.rb +5 -47
- data/spec/integration/eager_loader_test.rb +1 -1
- data/spec/integration/migrator_test.rb +1 -1
- data/spec/integration/model_test.rb +4 -82
- data/spec/integration/plugin_test.rb +6 -22
- data/spec/integration/prepared_statement_test.rb +8 -88
- data/spec/integration/schema_test.rb +6 -6
- data/spec/integration/spec_helper.rb +13 -21
- data/spec/integration/timezone_test.rb +5 -5
- data/spec/integration/transaction_test.rb +3 -55
- data/spec/integration/type_test.rb +9 -9
- data/spec/model/association_reflection_spec.rb +24 -9
- data/spec/model/associations_spec.rb +124 -303
- data/spec/model/base_spec.rb +18 -137
- data/spec/model/class_dataset_methods_spec.rb +2 -20
- data/spec/model/dataset_methods_spec.rb +1 -20
- data/spec/model/eager_loading_spec.rb +17 -11
- data/spec/model/hooks_spec.rb +5 -300
- data/spec/model/inflector_spec.rb +1 -1
- data/spec/model/model_spec.rb +15 -320
- data/spec/model/plugins_spec.rb +2 -16
- data/spec/model/record_spec.rb +29 -121
- data/spec/model/spec_helper.rb +5 -15
- data/spec/model/validations_spec.rb +1 -1
- data/spec/sequel_warning.rb +1 -12
- metadata +8 -64
- data/doc/active_record.rdoc +0 -927
- data/lib/sequel/adapters/cubrid.rb +0 -160
- data/lib/sequel/adapters/do.rb +0 -166
- data/lib/sequel/adapters/do/mysql.rb +0 -69
- data/lib/sequel/adapters/do/postgres.rb +0 -46
- data/lib/sequel/adapters/do/sqlite3.rb +0 -41
- data/lib/sequel/adapters/jdbc/as400.rb +0 -92
- data/lib/sequel/adapters/jdbc/cubrid.rb +0 -65
- data/lib/sequel/adapters/jdbc/firebirdsql.rb +0 -37
- data/lib/sequel/adapters/jdbc/informix-sqli.rb +0 -34
- data/lib/sequel/adapters/jdbc/jdbcprogress.rb +0 -34
- data/lib/sequel/adapters/odbc/progress.rb +0 -12
- data/lib/sequel/adapters/shared/cubrid.rb +0 -245
- data/lib/sequel/adapters/shared/firebird.rb +0 -261
- data/lib/sequel/adapters/shared/informix.rb +0 -63
- data/lib/sequel/adapters/shared/progress.rb +0 -40
- data/lib/sequel/adapters/swift.rb +0 -169
- data/lib/sequel/adapters/swift/mysql.rb +0 -50
- data/lib/sequel/adapters/swift/postgres.rb +0 -49
- data/lib/sequel/adapters/swift/sqlite.rb +0 -48
- data/lib/sequel/adapters/utils/pg_types.rb +0 -4
- data/lib/sequel/dataset/mutation.rb +0 -98
- data/lib/sequel/extensions/_deprecated_identifier_mangling.rb +0 -117
- data/lib/sequel/extensions/empty_array_ignore_nulls.rb +0 -8
- data/lib/sequel/extensions/filter_having.rb +0 -65
- data/lib/sequel/extensions/hash_aliases.rb +0 -51
- data/lib/sequel/extensions/meta_def.rb +0 -37
- data/lib/sequel/extensions/query_literals.rb +0 -86
- data/lib/sequel/extensions/ruby18_symbol_extensions.rb +0 -26
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +0 -133
- data/lib/sequel/extensions/set_overrides.rb +0 -82
- data/lib/sequel/no_core_ext.rb +0 -4
- data/lib/sequel/plugins/association_autoreloading.rb +0 -11
- data/lib/sequel/plugins/identifier_columns.rb +0 -49
- data/lib/sequel/plugins/many_to_one_pk_lookup.rb +0 -11
- data/lib/sequel/plugins/pg_typecast_on_load.rb +0 -90
- data/lib/sequel/plugins/prepared_statements_associations.rb +0 -137
- data/lib/sequel/plugins/prepared_statements_with_pk.rb +0 -71
- data/lib/sequel/plugins/schema.rb +0 -84
- data/lib/sequel/plugins/scissors.rb +0 -37
- data/spec/core/dataset_mutation_spec.rb +0 -253
- data/spec/extensions/_deprecated_identifier_mangling_spec.rb +0 -314
- data/spec/extensions/before_after_save_spec.rb +0 -40
- data/spec/extensions/filter_having_spec.rb +0 -42
- data/spec/extensions/from_block_spec.rb +0 -21
- data/spec/extensions/hash_aliases_spec.rb +0 -26
- data/spec/extensions/identifier_columns_spec.rb +0 -19
- data/spec/extensions/meta_def_spec.rb +0 -35
- data/spec/extensions/no_auto_literal_strings_spec.rb +0 -69
- data/spec/extensions/pg_typecast_on_load_spec.rb +0 -70
- data/spec/extensions/prepared_statements_associations_spec.rb +0 -212
- data/spec/extensions/prepared_statements_with_pk_spec.rb +0 -40
- data/spec/extensions/query_literals_spec.rb +0 -185
- data/spec/extensions/schema_spec.rb +0 -123
- data/spec/extensions/scissors_spec.rb +0 -27
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +0 -118
- data/spec/extensions/set_overrides_spec.rb +0 -75
@@ -1,11 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
|
3
|
-
Sequel::Deprecation.deprecate("The many_to_one_pk_lookup plugin", "This plugin was integrated into the default model behavior in Sequel 4.0, and no longer has an effect")
|
4
|
-
|
5
|
-
module Sequel
|
6
|
-
module Plugins
|
7
|
-
# Empty plugin module for backwards compatibility
|
8
|
-
module ManyToOnePkLookup
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
|
3
|
-
Sequel::Deprecation.deprecate("The pg_typecast_on_load plugin", "This plugin is only useful on the deprecated do and switch adapters")
|
4
|
-
|
5
|
-
module Sequel
|
6
|
-
module Plugins
|
7
|
-
# The PgTypecastOnLoad plugin exists because when you connect to PostgreSQL
|
8
|
-
# using the do and swift adapters, Sequel doesn't have complete
|
9
|
-
# control over typecasting, and may return columns as strings instead of how
|
10
|
-
# the native postgres adapter would typecast them. This is mostly needed for
|
11
|
-
# the additional support that the pg_* extensions add for advanced PostgreSQL
|
12
|
-
# types such as arrays. This plugin is not needed if using the postgres or
|
13
|
-
# jdbc/postgresql adapters.
|
14
|
-
#
|
15
|
-
# This plugin makes model loading to do the same conversion that the
|
16
|
-
# native postgres adapter would do for all columns given. You can either
|
17
|
-
# specify the columns to typecast on load in the plugin call itself, or
|
18
|
-
# afterwards using add_pg_typecast_on_load_columns:
|
19
|
-
#
|
20
|
-
# # aliases => text[] column
|
21
|
-
# # config => hstore column
|
22
|
-
#
|
23
|
-
# Album.plugin :pg_typecast_on_load, :aliases, :config
|
24
|
-
# # or:
|
25
|
-
# Album.plugin :pg_typecast_on_load
|
26
|
-
# Album.add_pg_typecast_on_load_columns :aliases, :config
|
27
|
-
#
|
28
|
-
# This plugin only handles values that the adapter returns as strings. If
|
29
|
-
# the adapter returns a value other than a string, this plugin will have no
|
30
|
-
# effect. You may be able to use the regular typecast_on_load plugin to
|
31
|
-
# handle those cases.
|
32
|
-
module PgTypecastOnLoad
|
33
|
-
# Call add_pg_typecast_on_load_columns on the passed column arguments.
|
34
|
-
def self.configure(model, *columns)
|
35
|
-
model.instance_eval do
|
36
|
-
@pg_typecast_on_load_columns ||= []
|
37
|
-
add_pg_typecast_on_load_columns(*columns)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
module ClassMethods
|
42
|
-
# The columns to typecast on load for this model.
|
43
|
-
attr_reader :pg_typecast_on_load_columns
|
44
|
-
|
45
|
-
# Add additional columns to typecast on load for this model.
|
46
|
-
def add_pg_typecast_on_load_columns(*columns)
|
47
|
-
@pg_typecast_on_load_columns.concat(columns)
|
48
|
-
end
|
49
|
-
|
50
|
-
def call(values)
|
51
|
-
super(load_typecast_pg(values))
|
52
|
-
end
|
53
|
-
|
54
|
-
# Freeze the typecast on load columns when freezing the model class.
|
55
|
-
def freeze
|
56
|
-
@pg_typecast_on_load_columns.freeze
|
57
|
-
|
58
|
-
super
|
59
|
-
end
|
60
|
-
|
61
|
-
# Lookup the conversion proc for the column's oid in the Database
|
62
|
-
# object, and use it to convert the value.
|
63
|
-
def load_typecast_pg(values)
|
64
|
-
pg_typecast_on_load_columns.each do |c|
|
65
|
-
if (v = values[c]).is_a?(String) && (oid = db_schema[c][:oid]) && (pr = db.conversion_procs[oid])
|
66
|
-
values[c] = pr.call(v)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
values
|
70
|
-
end
|
71
|
-
|
72
|
-
Plugins.inherited_instance_variables(self, :@pg_typecast_on_load_columns=>:dup)
|
73
|
-
end
|
74
|
-
|
75
|
-
module InstanceMethods
|
76
|
-
private
|
77
|
-
|
78
|
-
# Typecast specific columns using the conversion procs when manually refreshing.
|
79
|
-
def _refresh_set_values(values)
|
80
|
-
super(model.load_typecast_pg(values))
|
81
|
-
end
|
82
|
-
|
83
|
-
# Typecast specific columns using the conversion procs when refreshing after save.
|
84
|
-
def _save_set_values(values)
|
85
|
-
super(model.load_typecast_pg(values))
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
|
3
|
-
Sequel::Deprecation.deprecate("The prepared_statements_associations plugin", "Stop using the plugin, it is probably unneeded and making the application slower")
|
4
|
-
|
5
|
-
module Sequel
|
6
|
-
module Plugins
|
7
|
-
# The prepared_statements_associations plugin modifies the regular association
|
8
|
-
# load method to use a cached prepared statement to load the associations.
|
9
|
-
# It will not work on all associations, but it should skip the use of prepared
|
10
|
-
# statements for associations where it will not work, assuming you load the
|
11
|
-
# plugin before defining the associations.
|
12
|
-
#
|
13
|
-
# Note that in most cases, this plugin will probably make things slower,
|
14
|
-
# so you should only use it if you really want to use prepared statements
|
15
|
-
# to load associations.
|
16
|
-
#
|
17
|
-
# Usage:
|
18
|
-
#
|
19
|
-
# # Make all model subclasses more safe when using prepared statements (called before loading subclasses)
|
20
|
-
# Sequel::Model.plugin :prepared_statements_associations
|
21
|
-
#
|
22
|
-
# # Make the Album class more safe when using prepared statements
|
23
|
-
# Album.plugin :prepared_statements_associations
|
24
|
-
module PreparedStatementsAssociations
|
25
|
-
# Synchronize access to the integer sequence so that no two calls get the same integer.
|
26
|
-
MUTEX = Mutex.new
|
27
|
-
|
28
|
-
i = 0
|
29
|
-
# This plugin names prepared statements uniquely using an integer sequence, this
|
30
|
-
# lambda returns the next integer to use.
|
31
|
-
NEXT = lambda{MUTEX.synchronize{i += 1}}
|
32
|
-
|
33
|
-
module InstanceMethods
|
34
|
-
private
|
35
|
-
|
36
|
-
# Mark that associated objects should use the same server.
|
37
|
-
def _associated_objects_use_same_server?
|
38
|
-
return super if defined?(super)
|
39
|
-
false
|
40
|
-
end
|
41
|
-
|
42
|
-
# Return a bound variable hash that maps the keys in +ks+ (qualified by the +table+)
|
43
|
-
# to the values of the results of sending the methods in +vs+.
|
44
|
-
def association_bound_variable_hash(table, ks, vs)
|
45
|
-
Hash[*ks.zip(vs).map{|k, v| [:"#{table}.#{k}", get_column_value(v)]}.flatten]
|
46
|
-
end
|
47
|
-
|
48
|
-
# Given an association reflection, return a bound variable hash for the given
|
49
|
-
# association for this instance's values.
|
50
|
-
def association_bound_variables(opts)
|
51
|
-
return if opts[:instance_specific]
|
52
|
-
|
53
|
-
case opts[:type]
|
54
|
-
when :many_to_one
|
55
|
-
association_bound_variable_hash(opts.associated_class.table_name, opts.primary_keys, opts[:keys])
|
56
|
-
when :one_to_many, :one_to_one
|
57
|
-
association_bound_variable_hash(opts.associated_class.table_name, opts[:keys], opts[:primary_keys])
|
58
|
-
when :many_to_many, :one_through_one
|
59
|
-
association_bound_variable_hash(opts.join_table_alias, opts[:left_keys], opts[:left_primary_keys])
|
60
|
-
when :many_through_many, :one_through_many
|
61
|
-
association_bound_variable_hash(opts.final_reverse_edge[:alias], Array(opts[:left_key]), opts[:left_primary_keys])
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# Given an association reflection, return and cache a prepared statement for this association such
|
66
|
-
# that, given appropriate bound variables, the prepared statement will work correctly for any
|
67
|
-
# instance. Return false if such a prepared statement cannot be created.
|
68
|
-
def association_prepared_statement(opts, assoc_bv)
|
69
|
-
return unless model.cache_associations
|
70
|
-
ps = opts.send(:cached_fetch, :prepared_statement) do
|
71
|
-
unless opts[:instance_specific]
|
72
|
-
ds, bv = _associated_dataset(opts, {}).unbind
|
73
|
-
|
74
|
-
f = ds.opts[:from]
|
75
|
-
if f && f.length == 1
|
76
|
-
s = ds.opts[:select]
|
77
|
-
if ds.opts[:join]
|
78
|
-
if opts.eager_loading_use_associated_key? && s && s.length == 1 && s.first.is_a?(SQL::ColumnAll)
|
79
|
-
table = s.first.table
|
80
|
-
ds = ds.select(*opts.associated_class.columns.map{|c| Sequel.identifier(c).qualify(table)})
|
81
|
-
end
|
82
|
-
elsif !s || s.empty?
|
83
|
-
ds = ds.select(*opts.associated_class.columns.map{|c| Sequel.identifier(c)})
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
if bv.length != assoc_bv.length
|
88
|
-
h = {}
|
89
|
-
bv.each do |k,v|
|
90
|
-
h[k] = v unless assoc_bv.has_key?(k)
|
91
|
-
end
|
92
|
-
ds = ds.bind(h)
|
93
|
-
end
|
94
|
-
ds.clone(:log_sql=>true).prepare(opts.returns_array? ? :select : :first, :"smpsap_#{NEXT.call}")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
if ps && @server && _associated_objects_use_same_server?
|
99
|
-
ps = ps.server(@server)
|
100
|
-
end
|
101
|
-
|
102
|
-
ps
|
103
|
-
end
|
104
|
-
|
105
|
-
# Use a prepared statement if possible to load the associated object,
|
106
|
-
# unless a dynamic callback is given.
|
107
|
-
def _load_associated_object(opts, dynamic_opts)
|
108
|
-
if !dynamic_opts[:callback] && (bv = association_bound_variables(opts)) && (ps = association_prepared_statement(opts, bv))
|
109
|
-
ps.call(bv)
|
110
|
-
else
|
111
|
-
super
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# Use a prepared statement if possible to load the associated object,
|
116
|
-
# unless the associated model uses caching.
|
117
|
-
def _load_associated_object_via_primary_key(opts)
|
118
|
-
if !opts.associated_class.respond_to?(:cache_get_pk) && (bv = association_bound_variables(opts)) && (ps = association_prepared_statement(opts, bv))
|
119
|
-
ps.call(bv)
|
120
|
-
else
|
121
|
-
super
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
# Use a prepared statement if possible to load the associated objects,
|
126
|
-
# unless a dynamic callback is given.
|
127
|
-
def _load_associated_object_array(opts, dynamic_opts)
|
128
|
-
if !dynamic_opts[:callback] && (bv = association_bound_variables(opts)) && (ps = association_prepared_statement(opts, bv))
|
129
|
-
ps.call(bv)
|
130
|
-
else
|
131
|
-
super
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
|
3
|
-
Sequel::Deprecation.deprecate("The prepared_statements_with_pk plugin", "Stop using the plugin, it is probably unneeded and making the application slower")
|
4
|
-
|
5
|
-
module Sequel
|
6
|
-
module Plugins
|
7
|
-
# The prepared_statements_with_pk plugin allows Dataset#with_pk for model datasets
|
8
|
-
# to use prepared statements by extract the values of previously bound variables
|
9
|
-
# using <tt>Dataset#unbind</tt>, and attempting to use a prepared statement if the
|
10
|
-
# variables can be unbound correctly. See +Unbinder+ for details about what types of
|
11
|
-
# dataset filters can be unbound correctly.
|
12
|
-
#
|
13
|
-
# This plugin depends on the +prepared_statements+ plugin and should be considered unsafe.
|
14
|
-
# Unbinding dataset values cannot be done correctly in all cases, and use of this plugin
|
15
|
-
# in cases where not there are variables that are not unbound can lead to an denial of
|
16
|
-
# service attack by allocating an arbitrary number of prepared statements. You have been
|
17
|
-
# warned.
|
18
|
-
#
|
19
|
-
# Note that in most cases, this plugin will probably make things slower,
|
20
|
-
# so you should only use it if you really want to use prepared statements
|
21
|
-
# for Dataset#with_pk.
|
22
|
-
#
|
23
|
-
# Usage:
|
24
|
-
#
|
25
|
-
# # Make all model subclasses use prepared statements for Dataset#with_pk (called before loading subclasses)
|
26
|
-
# Sequel::Model.plugin :prepared_statements_with_pk
|
27
|
-
#
|
28
|
-
# # Make the Album class use prepared statements for Dataset#with_pk
|
29
|
-
# Album.plugin :prepared_statements_with_pk
|
30
|
-
module PreparedStatementsWithPk
|
31
|
-
# Depend on the prepared_statements plugin
|
32
|
-
def self.apply(model)
|
33
|
-
model.plugin(:prepared_statements)
|
34
|
-
end
|
35
|
-
|
36
|
-
module ClassMethods
|
37
|
-
private
|
38
|
-
|
39
|
-
# Return a prepared statement that can be used to lookup a row given a dataset for the row matching
|
40
|
-
# the primary key.
|
41
|
-
def prepared_lookup_dataset(ds)
|
42
|
-
cached_prepared_statement(:lookup_sql, ds.sql){prepare_statement(ds.where(prepared_statement_key_array(primary_key).map{|k, v| [SQL::QualifiedIdentifier.new(ds.model.table_name, k), v]}), :first)}
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
module DatasetMethods
|
47
|
-
# Use a prepared statement to find a row with the matching primary key
|
48
|
-
# inside this dataset.
|
49
|
-
def with_pk(pk)
|
50
|
-
begin
|
51
|
-
ds, bv = unbind
|
52
|
-
rescue UnbindDuplicate
|
53
|
-
super
|
54
|
-
else
|
55
|
-
begin
|
56
|
-
bv = bv.merge!(model.primary_key_hash(pk)){|k, v1, v2| ((v1 == v2) ? v1 : raise(UnbindDuplicate))}
|
57
|
-
rescue UnbindDuplicate
|
58
|
-
super
|
59
|
-
else
|
60
|
-
ps = model.send(:prepared_lookup_dataset, ds)
|
61
|
-
if server = @opts[:server]
|
62
|
-
ps = ps.server(server)
|
63
|
-
end
|
64
|
-
ps.call(bv)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
|
3
|
-
Sequel::Deprecation.deprecate("The schema plugin", "Switch to defining your schema using Database schema methods before creating your model classes")
|
4
|
-
|
5
|
-
module Sequel
|
6
|
-
module Plugins
|
7
|
-
# Sequel's built in schema plugin allows you to define your schema
|
8
|
-
# directly in the model using Model.set_schema (which takes a block
|
9
|
-
# similar to Database#create_table), and use Model.create_table to
|
10
|
-
# create a table using the schema information.
|
11
|
-
#
|
12
|
-
# This plugin is mostly suited to test code. If there is any
|
13
|
-
# chance that your application's schema could change, you should
|
14
|
-
# be using the migration extension instead.
|
15
|
-
#
|
16
|
-
# Usage:
|
17
|
-
#
|
18
|
-
# # Add the schema methods to all model subclasses (called before loading subclasses)
|
19
|
-
# Sequel::Model.plugin :schema
|
20
|
-
#
|
21
|
-
# # Add the schema methods to the Album class
|
22
|
-
# Album.plugin :schema
|
23
|
-
module Schema
|
24
|
-
module ClassMethods
|
25
|
-
# Creates table, using the column information from set_schema.
|
26
|
-
def create_table(*args, &block)
|
27
|
-
set_schema(*args, &block) if block
|
28
|
-
db.create_table(table_name, :generator=>@schema)
|
29
|
-
@db_schema = get_db_schema(true)
|
30
|
-
columns
|
31
|
-
end
|
32
|
-
|
33
|
-
# Drops the table if it exists and then runs create_table. Should probably
|
34
|
-
# not be used except in testing.
|
35
|
-
def create_table!(*args, &block)
|
36
|
-
drop_table?
|
37
|
-
create_table(*args, &block)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Creates the table unless the table already exists
|
41
|
-
def create_table?(*args, &block)
|
42
|
-
create_table(*args, &block) unless table_exists?
|
43
|
-
end
|
44
|
-
|
45
|
-
# Drops table. If the table doesn't exist, this will probably raise an error.
|
46
|
-
def drop_table
|
47
|
-
db.drop_table(table_name)
|
48
|
-
end
|
49
|
-
|
50
|
-
# Drops table if it already exists, do nothing if it doesn't exist.
|
51
|
-
def drop_table?
|
52
|
-
db.drop_table?(table_name)
|
53
|
-
end
|
54
|
-
|
55
|
-
# Returns table schema created with set_schema for direct descendant of Model.
|
56
|
-
# Does not retreive schema information from the database, see db_schema if you
|
57
|
-
# want that.
|
58
|
-
def schema
|
59
|
-
@schema || (superclass.schema unless superclass == Model)
|
60
|
-
end
|
61
|
-
|
62
|
-
# Defines a table schema (see Schema::CreateTableGenerator for more information).
|
63
|
-
#
|
64
|
-
# This is only needed if you want to use the create_table/create_table! methods.
|
65
|
-
# Will also set the dataset if you provide a name, as well as setting
|
66
|
-
# the primary key if you defined one in the passed block.
|
67
|
-
#
|
68
|
-
# In general, it is a better idea to use migrations for production code, as
|
69
|
-
# migrations allow changes to existing schema. set_schema is mostly useful for
|
70
|
-
# test code or simple examples.
|
71
|
-
def set_schema(name = nil, &block)
|
72
|
-
set_dataset(db[name]) if name
|
73
|
-
@schema = db.create_table_generator(&block)
|
74
|
-
set_primary_key(@schema.primary_key_name) if @schema.primary_key_name
|
75
|
-
end
|
76
|
-
|
77
|
-
# Returns true if table exists, false otherwise.
|
78
|
-
def table_exists?
|
79
|
-
db.table_exists?(table_name)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
|
3
|
-
Sequel::Deprecation.deprecate("The scissors plugin", "Running with scissors is dangerous")
|
4
|
-
|
5
|
-
module Sequel
|
6
|
-
module Plugins
|
7
|
-
# The scissors plugin adds class methods for update, delete, and destroy.
|
8
|
-
# It is so named because this is considered dangerous, since it is easy
|
9
|
-
# to write:
|
10
|
-
#
|
11
|
-
# Album.delete
|
12
|
-
#
|
13
|
-
# and delete all rows in the table, when you meant to write:
|
14
|
-
#
|
15
|
-
# album.delete
|
16
|
-
#
|
17
|
-
# and only delete a single row.
|
18
|
-
#
|
19
|
-
# This plugin is mostly useful for backwards compatibility, and not
|
20
|
-
# recommended for use in production. However, it can cut down on
|
21
|
-
# verbosity in non-transactional test code, so it may be appropriate
|
22
|
-
# to use when testing.
|
23
|
-
#
|
24
|
-
# Usage:
|
25
|
-
#
|
26
|
-
# # Make all model subclass run with scissors
|
27
|
-
# Sequel::Model.plugin :scissors
|
28
|
-
#
|
29
|
-
# # Make the Album class run with scissors
|
30
|
-
# Album.plugin :scissors
|
31
|
-
module Scissors
|
32
|
-
module ClassMethods
|
33
|
-
Plugins.def_dataset_methods(self, [:update, :delete, :destroy])
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,253 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
2
|
-
|
3
|
-
# SEQUEL5: Remove
|
4
|
-
unless Sequel.mock.dataset.frozen?
|
5
|
-
|
6
|
-
describe "Dataset" do
|
7
|
-
before do
|
8
|
-
@d = Sequel.mock.dataset.from(:x)
|
9
|
-
end
|
10
|
-
|
11
|
-
deprecated "should support self-changing select!" do
|
12
|
-
@d.select!(:y)
|
13
|
-
@d.sql.must_equal "SELECT y FROM x"
|
14
|
-
end
|
15
|
-
|
16
|
-
deprecated "should support self-changing from!" do
|
17
|
-
@d.from!(:y)
|
18
|
-
@d.sql.must_equal "SELECT * FROM y"
|
19
|
-
end
|
20
|
-
|
21
|
-
deprecated "should support self-changing order!" do
|
22
|
-
@d.order!(:y)
|
23
|
-
@d.sql.must_equal "SELECT * FROM x ORDER BY y"
|
24
|
-
end
|
25
|
-
|
26
|
-
deprecated "should support self-changing filter!" do
|
27
|
-
@d.filter!(:y => 1)
|
28
|
-
@d.sql.must_equal "SELECT * FROM x WHERE (y = 1)"
|
29
|
-
end
|
30
|
-
|
31
|
-
deprecated "should support self-changing filter! with block" do
|
32
|
-
@d.filter!{y < 2}
|
33
|
-
@d.sql.must_equal "SELECT * FROM x WHERE (y < 2)"
|
34
|
-
end
|
35
|
-
|
36
|
-
deprecated "should raise for ! methods that don't return a dataset" do
|
37
|
-
proc {@d.opts!}.must_raise(NoMethodError)
|
38
|
-
end
|
39
|
-
|
40
|
-
deprecated "should raise for missing methods" do
|
41
|
-
proc {@d.xuyz}.must_raise(NoMethodError)
|
42
|
-
proc {@d.xyz!}.must_raise(NoMethodError)
|
43
|
-
proc {@d.xyz?}.must_raise(NoMethodError)
|
44
|
-
end
|
45
|
-
|
46
|
-
deprecated "should support chaining of bang methods" do
|
47
|
-
@d.order!(:y).filter!(:y => 1).sql.must_equal "SELECT * FROM x WHERE (y = 1) ORDER BY y"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "Frozen Datasets" do
|
52
|
-
before do
|
53
|
-
@ds = Sequel.mock[:test].freeze
|
54
|
-
end
|
55
|
-
|
56
|
-
deprecated "should have dups not be frozen" do
|
57
|
-
@ds.dup.wont_be :frozen?
|
58
|
-
end
|
59
|
-
|
60
|
-
deprecated "should raise an error when calling mutation methods" do
|
61
|
-
proc{@ds.select!(:a)}.must_raise RuntimeError
|
62
|
-
proc{@ds.row_proc = proc{}}.must_raise RuntimeError
|
63
|
-
proc{@ds.extension! :query}.must_raise RuntimeError
|
64
|
-
proc{@ds.naked!}.must_raise RuntimeError
|
65
|
-
proc{@ds.from_self!}.must_raise RuntimeError
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "Dataset mutation methods" do
|
70
|
-
def m(&block)
|
71
|
-
ds = Sequel.mock[:t]
|
72
|
-
def ds.supports_cte?(*) true end
|
73
|
-
ds.instance_exec(&block)
|
74
|
-
ds.sql
|
75
|
-
end
|
76
|
-
|
77
|
-
deprecated "should modify the dataset in place" do
|
78
|
-
dsc = Sequel.mock[:u]
|
79
|
-
dsc.send(:columns=, [:v])
|
80
|
-
|
81
|
-
m{and!(:a=>1).or!(:b=>2)}.must_equal "SELECT * FROM t WHERE ((a = 1) OR (b = 2))"
|
82
|
-
m{select!(:f).graph!(dsc, :b=>:c).set_graph_aliases!(:e=>[:m, :n]).add_graph_aliases!(:d=>[:g, :c])}.must_equal "SELECT m.n AS e, g.c AS d FROM t LEFT OUTER JOIN u ON (u.b = t.c)"
|
83
|
-
m{cross_join!(:a)}.must_equal "SELECT * FROM t CROSS JOIN a"
|
84
|
-
m{distinct!}.must_equal "SELECT DISTINCT * FROM t"
|
85
|
-
m{except!(dsc)}.must_equal "SELECT * FROM (SELECT * FROM t EXCEPT SELECT * FROM u) AS t1"
|
86
|
-
m{exclude!(:a=>1)}.must_equal "SELECT * FROM t WHERE (a != 1)"
|
87
|
-
m{exclude_having!(:a=>1)}.must_equal "SELECT * FROM t HAVING (a != 1)"
|
88
|
-
m{exclude_where!(:a=>1)}.must_equal "SELECT * FROM t WHERE (a != 1)"
|
89
|
-
m{filter!(:a=>1)}.must_equal "SELECT * FROM t WHERE (a = 1)"
|
90
|
-
m{for_update!}.must_equal "SELECT * FROM t FOR UPDATE"
|
91
|
-
m{from!(:p)}.must_equal "SELECT * FROM p"
|
92
|
-
m{full_join!(:a, [:b])}.must_equal "SELECT * FROM t FULL JOIN a USING (b)"
|
93
|
-
m{full_outer_join!(:a, [:b])}.must_equal "SELECT * FROM t FULL OUTER JOIN a USING (b)"
|
94
|
-
m{grep!(:a, 'b')}.must_equal "SELECT * FROM t WHERE ((a LIKE 'b' ESCAPE '\\'))"
|
95
|
-
m{group!(:a)}.must_equal "SELECT * FROM t GROUP BY a"
|
96
|
-
m{group_and_count!(:a)}.must_equal "SELECT a, count(*) AS count FROM t GROUP BY a"
|
97
|
-
m{group_by!(:a)}.must_equal "SELECT * FROM t GROUP BY a"
|
98
|
-
m{having!(:a)}.must_equal "SELECT * FROM t HAVING a"
|
99
|
-
m{inner_join!(:a, [:b])}.must_equal "SELECT * FROM t INNER JOIN a USING (b)"
|
100
|
-
m{intersect!(dsc)}.must_equal "SELECT * FROM (SELECT * FROM t INTERSECT SELECT * FROM u) AS t1"
|
101
|
-
m{where!(:a).invert!}.must_equal "SELECT * FROM t WHERE NOT a"
|
102
|
-
m{join!(:a, [:b])}.must_equal "SELECT * FROM t INNER JOIN a USING (b)"
|
103
|
-
m{join_table!(:inner, :a, [:b])}.must_equal "SELECT * FROM t INNER JOIN a USING (b)"
|
104
|
-
m{left_join!(:a, [:b])}.must_equal "SELECT * FROM t LEFT JOIN a USING (b)"
|
105
|
-
m{left_outer_join!(:a, [:b])}.must_equal "SELECT * FROM t LEFT OUTER JOIN a USING (b)"
|
106
|
-
m{limit!(1)}.must_equal "SELECT * FROM t LIMIT 1"
|
107
|
-
m{lock_style!(:update)}.must_equal "SELECT * FROM t FOR UPDATE"
|
108
|
-
m{natural_full_join!(:a)}.must_equal "SELECT * FROM t NATURAL FULL JOIN a"
|
109
|
-
m{natural_join!(:a)}.must_equal "SELECT * FROM t NATURAL JOIN a"
|
110
|
-
m{natural_left_join!(:a)}.must_equal "SELECT * FROM t NATURAL LEFT JOIN a"
|
111
|
-
m{natural_right_join!(:a)}.must_equal "SELECT * FROM t NATURAL RIGHT JOIN a"
|
112
|
-
m{offset!(1)}.must_equal "SELECT * FROM t OFFSET 1"
|
113
|
-
m{order!(:a).reverse_order!}.must_equal "SELECT * FROM t ORDER BY a DESC"
|
114
|
-
m{order_by!(:a).order_more!(:b).order_append!(:c).order_prepend!(:d).reverse!}.must_equal "SELECT * FROM t ORDER BY d DESC, a DESC, b DESC, c DESC"
|
115
|
-
m{qualify!}.must_equal "SELECT t.* FROM t"
|
116
|
-
m{right_join!(:a, [:b])}.must_equal "SELECT * FROM t RIGHT JOIN a USING (b)"
|
117
|
-
m{right_outer_join!(:a, [:b])}.must_equal "SELECT * FROM t RIGHT OUTER JOIN a USING (b)"
|
118
|
-
m{select!(:a)}.must_equal "SELECT a FROM t"
|
119
|
-
m{select_all!(:t).select_more!(:b).select_append!(:c)}.must_equal "SELECT t.*, b, c FROM t"
|
120
|
-
m{select_group!(:a)}.must_equal "SELECT a FROM t GROUP BY a"
|
121
|
-
m{where!(:a).unfiltered!}.must_equal "SELECT * FROM t"
|
122
|
-
m{group!(:a).ungrouped!}.must_equal "SELECT * FROM t"
|
123
|
-
m{limit!(1).unlimited!}.must_equal "SELECT * FROM t"
|
124
|
-
m{order!(:a).unordered!}.must_equal "SELECT * FROM t"
|
125
|
-
m{union!(dsc)}.must_equal "SELECT * FROM (SELECT * FROM t UNION SELECT * FROM u) AS t1"
|
126
|
-
m{with!(:a, dsc)}.must_equal "WITH a AS (SELECT * FROM u) SELECT * FROM t"
|
127
|
-
m{with_recursive!(:a, dsc, dsc)}.must_equal "WITH a AS (SELECT * FROM u UNION ALL SELECT * FROM u) SELECT * FROM t"
|
128
|
-
m{with_sql!('SELECT foo')}.must_equal "SELECT foo"
|
129
|
-
|
130
|
-
dsc.server!(:a)
|
131
|
-
dsc.opts[:server].must_equal :a
|
132
|
-
dsc.graph!(dsc, {:b=>:c}, :table_alias=>:foo).ungraphed!.opts[:graph].must_be_nil
|
133
|
-
end
|
134
|
-
|
135
|
-
deprecated "should clear the cache" do
|
136
|
-
ds = Sequel.mock[:a]
|
137
|
-
ds.columns
|
138
|
-
ds.send(:cache_set, :columns, [:a])
|
139
|
-
ds.select!(:foo, :bar).send(:cache_get, :columns).must_be_nil
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe "Dataset#clone" do
|
144
|
-
before do
|
145
|
-
@dataset = Sequel.mock.dataset.from(:items)
|
146
|
-
end
|
147
|
-
|
148
|
-
deprecated "should copy the dataset opts" do
|
149
|
-
clone = @dataset.clone
|
150
|
-
clone.opts.must_equal @dataset.opts
|
151
|
-
@dataset.filter!(:a => 'b')
|
152
|
-
clone.opts[:filter].must_be_nil
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
describe "Dataset extensions" do
|
157
|
-
before(:all) do
|
158
|
-
class << Sequel
|
159
|
-
alias _extension extension
|
160
|
-
remove_method :extension
|
161
|
-
def extension(*)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
after(:all) do
|
166
|
-
class << Sequel
|
167
|
-
remove_method :extension
|
168
|
-
alias extension _extension
|
169
|
-
remove_method :_extension
|
170
|
-
end
|
171
|
-
end
|
172
|
-
before do
|
173
|
-
@ds = Sequel.mock.dataset
|
174
|
-
end
|
175
|
-
|
176
|
-
deprecated "should have #extension! modify the receiver" do
|
177
|
-
Sequel::Dataset.register_extension(:foo, Module.new{def a; 1; end})
|
178
|
-
@ds.extension!(:foo)
|
179
|
-
@ds.a.must_equal 1
|
180
|
-
end
|
181
|
-
|
182
|
-
deprecated "should have #extension! return the receiver" do
|
183
|
-
Sequel::Dataset.register_extension(:foo, Module.new{def a; 1; end})
|
184
|
-
@ds.extension!(:foo).must_be_same_as(@ds)
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
describe "Dataset#naked!" do
|
189
|
-
deprecated "should remove any existing row_proc" do
|
190
|
-
d = Sequel.mock.dataset.with_row_proc(Proc.new{|r| r})
|
191
|
-
d.naked!.row_proc.must_be_nil
|
192
|
-
d.row_proc.must_be_nil
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
describe "Dataset#row_proc=" do
|
197
|
-
deprecated "should set the row_proc" do
|
198
|
-
d = Sequel.mock.dataset.with_row_proc(Proc.new{|r| r})
|
199
|
-
d.row_proc.wont_be_nil
|
200
|
-
d.row_proc = nil
|
201
|
-
d.row_proc.must_be_nil
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
describe "Dataset#quote_identifiers=" do
|
206
|
-
deprecated "should change quote identifiers setting" do
|
207
|
-
d = Sequel.mock.dataset.with_quote_identifiers(true)
|
208
|
-
d.literal(:a).must_equal '"a"'
|
209
|
-
d.quote_identifiers = false
|
210
|
-
d.literal(:a).must_equal 'a'
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
describe "Dataset#from_self!" do
|
215
|
-
deprecated "should work" do
|
216
|
-
Sequel.mock.dataset.from(:test).select(:name).limit(1).from_self!.sql.must_equal 'SELECT * FROM (SELECT name FROM test LIMIT 1) AS t1'
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
describe "Sequel Mock Adapter" do
|
221
|
-
deprecated "should be able to set the rows returned by each on a per dataset basis using _fetch" do
|
222
|
-
rs = []
|
223
|
-
db = Sequel.mock(:fetch=>{:a=>1})
|
224
|
-
ds = db[:t]
|
225
|
-
ds.each{|r| rs << r}
|
226
|
-
rs.must_equal [{:a=>1}]
|
227
|
-
ds._fetch = {:b=>2}
|
228
|
-
ds.each{|r| rs << r}
|
229
|
-
rs.must_equal [{:a=>1}, {:b=>2}]
|
230
|
-
end
|
231
|
-
|
232
|
-
deprecated "should be able to set the number of rows modified by update and delete on a per dataset basis" do
|
233
|
-
db = Sequel.mock(:numrows=>2)
|
234
|
-
ds = db[:t]
|
235
|
-
ds.update(:a=>1).must_equal 2
|
236
|
-
ds.delete.must_equal 2
|
237
|
-
ds.numrows = 3
|
238
|
-
ds.update(:a=>1).must_equal 3
|
239
|
-
ds.delete.must_equal 3
|
240
|
-
end
|
241
|
-
|
242
|
-
deprecated "should be able to set the autogenerated primary key returned by insert on a per dataset basis" do
|
243
|
-
db = Sequel.mock(:autoid=>1)
|
244
|
-
ds = db[:t]
|
245
|
-
ds.insert(:a=>1).must_equal 1
|
246
|
-
ds.autoid = 5
|
247
|
-
ds.insert(:a=>1).must_equal 5
|
248
|
-
ds.insert(:a=>1).must_equal 6
|
249
|
-
db[:t].insert(:a=>1).must_equal 2
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
end
|