sequel 3.48.0 → 4.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 +114 -0
- data/Rakefile +10 -7
- data/doc/association_basics.rdoc +25 -23
- data/doc/code_order.rdoc +7 -0
- data/doc/core_extensions.rdoc +0 -10
- data/doc/object_model.rdoc +4 -1
- data/doc/querying.rdoc +3 -3
- data/doc/release_notes/4.0.0.txt +262 -0
- data/doc/security.rdoc +0 -28
- data/doc/testing.rdoc +8 -14
- data/lib/sequel/adapters/ado.rb +7 -11
- data/lib/sequel/adapters/ado/access.rb +8 -8
- data/lib/sequel/adapters/ado/mssql.rb +4 -4
- data/lib/sequel/adapters/amalgalite.rb +6 -6
- data/lib/sequel/adapters/cubrid.rb +7 -7
- data/lib/sequel/adapters/db2.rb +5 -9
- data/lib/sequel/adapters/dbi.rb +2 -6
- data/lib/sequel/adapters/do.rb +4 -4
- data/lib/sequel/adapters/firebird.rb +4 -4
- data/lib/sequel/adapters/ibmdb.rb +8 -8
- data/lib/sequel/adapters/informix.rb +2 -10
- data/lib/sequel/adapters/jdbc.rb +17 -17
- data/lib/sequel/adapters/jdbc/as400.rb +2 -2
- data/lib/sequel/adapters/jdbc/cubrid.rb +1 -1
- data/lib/sequel/adapters/jdbc/db2.rb +1 -1
- data/lib/sequel/adapters/jdbc/derby.rb +1 -1
- data/lib/sequel/adapters/jdbc/h2.rb +2 -2
- data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
- data/lib/sequel/adapters/jdbc/informix.rb +1 -1
- data/lib/sequel/adapters/jdbc/mssql.rb +2 -2
- data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +5 -1
- data/lib/sequel/adapters/jdbc/postgresql.rb +3 -3
- data/lib/sequel/adapters/jdbc/sqlite.rb +3 -3
- data/lib/sequel/adapters/jdbc/transactions.rb +3 -3
- data/lib/sequel/adapters/mock.rb +7 -7
- data/lib/sequel/adapters/mysql.rb +3 -3
- data/lib/sequel/adapters/mysql2.rb +4 -4
- data/lib/sequel/adapters/odbc.rb +2 -6
- data/lib/sequel/adapters/odbc/mssql.rb +1 -1
- data/lib/sequel/adapters/openbase.rb +1 -5
- data/lib/sequel/adapters/oracle.rb +13 -17
- data/lib/sequel/adapters/postgres.rb +20 -25
- data/lib/sequel/adapters/shared/cubrid.rb +3 -3
- data/lib/sequel/adapters/shared/db2.rb +2 -2
- data/lib/sequel/adapters/shared/firebird.rb +7 -7
- data/lib/sequel/adapters/shared/mssql.rb +9 -9
- data/lib/sequel/adapters/shared/mysql.rb +29 -13
- data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +7 -7
- data/lib/sequel/adapters/shared/oracle.rb +22 -13
- data/lib/sequel/adapters/shared/postgres.rb +61 -46
- data/lib/sequel/adapters/shared/sqlite.rb +9 -9
- data/lib/sequel/adapters/sqlite.rb +17 -11
- data/lib/sequel/adapters/swift.rb +3 -3
- data/lib/sequel/adapters/swift/mysql.rb +1 -1
- data/lib/sequel/adapters/swift/sqlite.rb +1 -1
- data/lib/sequel/adapters/tinytds.rb +8 -8
- data/lib/sequel/ast_transformer.rb +3 -1
- data/lib/sequel/connection_pool.rb +4 -2
- data/lib/sequel/connection_pool/sharded_single.rb +2 -2
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -5
- data/lib/sequel/connection_pool/threaded.rb +7 -7
- data/lib/sequel/core.rb +4 -67
- data/lib/sequel/database.rb +1 -0
- data/lib/sequel/database/connecting.rb +2 -8
- data/lib/sequel/database/dataset.rb +2 -7
- data/lib/sequel/database/dataset_defaults.rb +0 -18
- data/lib/sequel/database/features.rb +4 -4
- data/lib/sequel/database/misc.rb +6 -8
- data/lib/sequel/database/query.rb +5 -61
- data/lib/sequel/database/schema_generator.rb +22 -20
- data/lib/sequel/database/schema_methods.rb +48 -20
- data/lib/sequel/database/transactions.rb +7 -17
- data/lib/sequel/dataset.rb +2 -0
- data/lib/sequel/dataset/actions.rb +23 -91
- data/lib/sequel/dataset/features.rb +1 -4
- data/lib/sequel/dataset/graph.rb +3 -47
- data/lib/sequel/dataset/misc.rb +4 -33
- data/lib/sequel/dataset/prepared_statements.rb +3 -1
- data/lib/sequel/dataset/query.rb +116 -240
- data/lib/sequel/dataset/sql.rb +19 -97
- data/lib/sequel/deprecated.rb +0 -16
- data/lib/sequel/exceptions.rb +0 -3
- data/lib/sequel/extensions/_pretty_table.rb +1 -1
- data/lib/sequel/extensions/columns_introspection.rb +1 -12
- data/lib/sequel/extensions/constraint_validations.rb +3 -3
- data/lib/sequel/extensions/core_extensions.rb +0 -9
- data/lib/sequel/extensions/date_arithmetic.rb +1 -2
- data/lib/sequel/extensions/graph_each.rb +11 -0
- data/lib/sequel/extensions/migration.rb +5 -5
- data/lib/sequel/extensions/null_dataset.rb +11 -13
- data/lib/sequel/extensions/pagination.rb +3 -6
- data/lib/sequel/extensions/pg_array.rb +6 -4
- data/lib/sequel/extensions/pg_array_ops.rb +35 -1
- data/lib/sequel/extensions/pg_json.rb +12 -2
- data/lib/sequel/extensions/pg_json_ops.rb +266 -0
- data/lib/sequel/extensions/pg_range.rb +2 -2
- data/lib/sequel/extensions/pg_range_ops.rb +0 -8
- data/lib/sequel/extensions/pg_row.rb +2 -2
- data/lib/sequel/extensions/pretty_table.rb +0 -4
- data/lib/sequel/extensions/query.rb +3 -8
- data/lib/sequel/extensions/schema_caching.rb +0 -7
- data/lib/sequel/extensions/schema_dumper.rb +10 -17
- data/lib/sequel/extensions/select_remove.rb +0 -4
- data/lib/sequel/extensions/set_overrides.rb +28 -0
- data/lib/sequel/extensions/to_dot.rb +6 -10
- data/lib/sequel/model.rb +6 -7
- data/lib/sequel/model/associations.rb +127 -182
- data/lib/sequel/model/base.rb +88 -211
- data/lib/sequel/model/errors.rb +0 -13
- data/lib/sequel/model/plugins.rb +2 -2
- data/lib/sequel/no_core_ext.rb +0 -1
- data/lib/sequel/plugins/after_initialize.rb +11 -17
- data/lib/sequel/plugins/association_autoreloading.rb +1 -47
- data/lib/sequel/plugins/association_dependencies.rb +2 -2
- data/lib/sequel/plugins/auto_validations.rb +2 -8
- data/lib/sequel/plugins/blacklist_security.rb +32 -2
- data/lib/sequel/plugins/caching.rb +1 -1
- data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
- data/lib/sequel/plugins/composition.rb +10 -8
- data/lib/sequel/plugins/constraint_validations.rb +2 -2
- data/lib/sequel/plugins/dataset_associations.rb +4 -0
- data/lib/sequel/plugins/defaults_setter.rb +8 -6
- data/lib/sequel/plugins/dirty.rb +6 -6
- data/lib/sequel/plugins/force_encoding.rb +13 -8
- data/lib/sequel/plugins/hook_class_methods.rb +1 -7
- data/lib/sequel/plugins/json_serializer.rb +13 -74
- data/lib/sequel/plugins/lazy_attributes.rb +2 -4
- data/lib/sequel/plugins/list.rb +1 -1
- data/lib/sequel/plugins/many_through_many.rb +4 -11
- data/lib/sequel/plugins/many_to_one_pk_lookup.rb +1 -49
- data/lib/sequel/plugins/nested_attributes.rb +1 -1
- data/lib/sequel/plugins/optimistic_locking.rb +3 -5
- data/lib/sequel/plugins/pg_array_associations.rb +453 -0
- data/lib/sequel/plugins/pg_typecast_on_load.rb +23 -7
- data/lib/sequel/plugins/prepared_statements.rb +1 -1
- data/lib/sequel/plugins/prepared_statements_associations.rb +20 -14
- data/lib/sequel/plugins/prepared_statements_safe.rb +2 -2
- data/lib/sequel/plugins/rcte_tree.rb +1 -1
- data/lib/sequel/plugins/serialization.rb +5 -4
- data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
- data/lib/sequel/plugins/sharding.rb +7 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
- data/lib/sequel/plugins/timestamps.rb +1 -1
- data/lib/sequel/plugins/touch.rb +2 -2
- data/lib/sequel/plugins/tree.rb +1 -1
- data/lib/sequel/plugins/typecast_on_load.rb +19 -4
- data/lib/sequel/plugins/validation_class_methods.rb +0 -30
- data/lib/sequel/plugins/validation_helpers.rb +13 -31
- data/lib/sequel/plugins/xml_serializer.rb +18 -57
- data/lib/sequel/sql.rb +20 -22
- data/lib/sequel/version.rb +2 -2
- data/spec/adapters/db2_spec.rb +14 -23
- data/spec/adapters/firebird_spec.rb +25 -29
- data/spec/adapters/informix_spec.rb +11 -14
- data/spec/adapters/mssql_spec.rb +71 -77
- data/spec/adapters/mysql_spec.rb +165 -172
- data/spec/adapters/oracle_spec.rb +36 -39
- data/spec/adapters/postgres_spec.rb +175 -100
- data/spec/adapters/spec_helper.rb +13 -11
- data/spec/adapters/sqlite_spec.rb +36 -44
- data/spec/core/connection_pool_spec.rb +2 -1
- data/spec/core/database_spec.rb +55 -55
- data/spec/core/dataset_spec.rb +45 -249
- data/spec/core/deprecated_spec.rb +0 -8
- data/spec/core/expression_filters_spec.rb +23 -5
- data/spec/core/object_graph_spec.rb +4 -66
- data/spec/core/schema_spec.rb +35 -12
- data/spec/core/spec_helper.rb +3 -2
- data/spec/core_extensions_spec.rb +17 -19
- data/spec/extensions/arbitrary_servers_spec.rb +2 -3
- data/spec/extensions/association_dependencies_spec.rb +14 -14
- data/spec/extensions/auto_validations_spec.rb +7 -0
- data/spec/extensions/blacklist_security_spec.rb +5 -5
- data/spec/extensions/blank_spec.rb +2 -0
- data/spec/extensions/class_table_inheritance_spec.rb +2 -2
- data/spec/extensions/columns_introspection_spec.rb +2 -29
- data/spec/extensions/composition_spec.rb +10 -17
- data/spec/extensions/core_refinements_spec.rb +5 -1
- data/spec/extensions/dataset_associations_spec.rb +18 -0
- data/spec/extensions/date_arithmetic_spec.rb +2 -2
- data/spec/extensions/defaults_setter_spec.rb +9 -9
- data/spec/extensions/dirty_spec.rb +0 -5
- data/spec/extensions/eval_inspect_spec.rb +2 -0
- data/spec/extensions/force_encoding_spec.rb +2 -18
- data/spec/extensions/hash_aliases_spec.rb +8 -0
- data/spec/extensions/hook_class_methods_spec.rb +39 -58
- data/spec/extensions/inflector_spec.rb +2 -0
- data/spec/extensions/instance_filters_spec.rb +8 -8
- data/spec/extensions/json_serializer_spec.rb +1 -41
- data/spec/extensions/list_spec.rb +1 -1
- data/spec/extensions/many_through_many_spec.rb +106 -109
- data/spec/extensions/migration_spec.rb +2 -0
- data/spec/extensions/named_timezones_spec.rb +1 -0
- data/spec/extensions/pg_array_associations_spec.rb +603 -0
- data/spec/extensions/pg_array_ops_spec.rb +25 -0
- data/spec/extensions/pg_array_spec.rb +9 -1
- data/spec/extensions/pg_hstore_ops_spec.rb +13 -0
- data/spec/extensions/pg_hstore_spec.rb +1 -0
- data/spec/extensions/pg_json_ops_spec.rb +131 -0
- data/spec/extensions/pg_json_spec.rb +10 -4
- data/spec/extensions/pg_range_ops_spec.rb +2 -5
- data/spec/extensions/pg_range_spec.rb +6 -2
- data/spec/extensions/pg_row_ops_spec.rb +2 -0
- data/spec/extensions/prepared_statements_associations_spec.rb +26 -5
- data/spec/extensions/rcte_tree_spec.rb +15 -15
- data/spec/extensions/schema_dumper_spec.rb +0 -1
- data/spec/extensions/schema_spec.rb +9 -9
- data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
- data/spec/extensions/serialization_spec.rb +18 -29
- data/spec/extensions/set_overrides_spec.rb +4 -0
- data/spec/extensions/{many_to_one_pk_lookup_spec.rb → shared_caching_spec.rb} +1 -4
- data/spec/extensions/single_table_inheritance_spec.rb +4 -4
- data/spec/extensions/spec_helper.rb +8 -9
- data/spec/extensions/sql_expr_spec.rb +2 -0
- data/spec/extensions/string_date_time_spec.rb +2 -0
- data/spec/extensions/string_stripper_spec.rb +2 -0
- data/spec/extensions/tactical_eager_loading_spec.rb +12 -12
- data/spec/extensions/thread_local_timezones_spec.rb +2 -0
- data/spec/extensions/timestamps_spec.rb +1 -1
- data/spec/extensions/to_dot_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +24 -24
- data/spec/extensions/tree_spec.rb +7 -7
- data/spec/extensions/typecast_on_load_spec.rb +8 -1
- data/spec/extensions/update_primary_key_spec.rb +10 -10
- data/spec/extensions/validation_class_methods_spec.rb +10 -39
- data/spec/extensions/validation_helpers_spec.rb +29 -47
- data/spec/extensions/xml_serializer_spec.rb +1 -23
- data/spec/integration/associations_test.rb +231 -40
- data/spec/integration/database_test.rb +1 -1
- data/spec/integration/dataset_test.rb +64 -64
- data/spec/integration/eager_loader_test.rb +28 -28
- data/spec/integration/migrator_test.rb +1 -1
- data/spec/integration/model_test.rb +2 -2
- data/spec/integration/plugin_test.rb +21 -21
- data/spec/integration/prepared_statement_test.rb +7 -7
- data/spec/integration/schema_test.rb +115 -110
- data/spec/integration/spec_helper.rb +17 -27
- data/spec/integration/timezone_test.rb +1 -1
- data/spec/integration/transaction_test.rb +10 -10
- data/spec/integration/type_test.rb +2 -2
- data/spec/model/association_reflection_spec.rb +2 -28
- data/spec/model/associations_spec.rb +239 -188
- data/spec/model/base_spec.rb +27 -68
- data/spec/model/dataset_methods_spec.rb +4 -4
- data/spec/model/eager_loading_spec.rb +160 -172
- data/spec/model/hooks_spec.rb +62 -79
- data/spec/model/model_spec.rb +36 -51
- data/spec/model/plugins_spec.rb +5 -19
- data/spec/model/record_spec.rb +125 -151
- data/spec/model/spec_helper.rb +8 -6
- data/spec/model/validations_spec.rb +4 -17
- data/spec/spec_config.rb +2 -10
- metadata +50 -56
- data/lib/sequel/deprecated_core_extensions.rb +0 -135
- data/lib/sequel/extensions/pg_auto_parameterize.rb +0 -185
- data/lib/sequel/extensions/pg_statement_cache.rb +0 -318
- data/lib/sequel/plugins/identity_map.rb +0 -260
- data/lib/sequel_core.rb +0 -2
- data/lib/sequel_model.rb +0 -2
- data/spec/extensions/association_autoreloading_spec.rb +0 -102
- data/spec/extensions/identity_map_spec.rb +0 -337
- data/spec/extensions/pg_auto_parameterize_spec.rb +0 -70
- data/spec/extensions/pg_statement_cache_spec.rb +0 -208
- data/spec/rcov.opts +0 -8
- data/spec/spec_config.rb.example +0 -10
data/lib/sequel/database.rb
CHANGED
@@ -13,6 +13,7 @@ module Sequel
|
|
13
13
|
# The Database class is meant to be subclassed by database adapters in order
|
14
14
|
# to provide the functionality needed for executing queries.
|
15
15
|
class Database
|
16
|
+
OPTS = Sequel::OPTS
|
16
17
|
end
|
17
18
|
|
18
19
|
require(%w"connecting dataset dataset_defaults logging features misc query transactions schema_generator schema_methods", 'database')
|
@@ -45,7 +45,7 @@ module Sequel
|
|
45
45
|
end
|
46
46
|
|
47
47
|
# Connects to a database. See Sequel.connect.
|
48
|
-
def self.connect(conn_string, opts =
|
48
|
+
def self.connect(conn_string, opts = OPTS)
|
49
49
|
case conn_string
|
50
50
|
when String
|
51
51
|
if match = /\A(jdbc|do):/o.match(conn_string)
|
@@ -138,12 +138,6 @@ module Sequel
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
# Connects to the database. This method should be overridden by descendants.
|
142
|
-
def connect(server)
|
143
|
-
Sequel::Deprecation.deprecate('Database#connect default implementation and Sequel::NotImplemented', 'All database instance can be assumed to implement connect.')
|
144
|
-
raise NotImplemented, "#connect should be overridden by adapters"
|
145
|
-
end
|
146
|
-
|
147
141
|
# The database type for this database object, the same as the adapter scheme
|
148
142
|
# by default. Should be overridden in adapters (especially shared adapters)
|
149
143
|
# to be the correct type, so that even if two separate Database objects are
|
@@ -167,7 +161,7 @@ module Sequel
|
|
167
161
|
# DB.disconnect # All servers
|
168
162
|
# DB.disconnect(:servers=>:server1) # Single server
|
169
163
|
# DB.disconnect(:servers=>[:server1, :server2]) # Multiple servers
|
170
|
-
def disconnect(opts =
|
164
|
+
def disconnect(opts = OPTS)
|
171
165
|
pool.disconnect(opts)
|
172
166
|
end
|
173
167
|
|
@@ -24,13 +24,8 @@ module Sequel
|
|
24
24
|
#
|
25
25
|
# DB.dataset # SELECT *
|
26
26
|
# DB.dataset.from(:items) # SELECT * FROM items
|
27
|
-
def dataset
|
28
|
-
|
29
|
-
if no_arg_given
|
30
|
-
@dataset_class.new(self)
|
31
|
-
else
|
32
|
-
@dataset_class.new(self, opts)
|
33
|
-
end
|
27
|
+
def dataset
|
28
|
+
@dataset_class.new(self)
|
34
29
|
end
|
35
30
|
|
36
31
|
# Fetches records for an arbitrary SQL statement. If a block is given,
|
@@ -44,19 +44,6 @@ module Sequel
|
|
44
44
|
# The identifier output method to use by default for this database (default: adapter default)
|
45
45
|
attr_reader :identifier_output_method
|
46
46
|
|
47
|
-
# REMOVE40
|
48
|
-
def _default_schema
|
49
|
-
@default_schema
|
50
|
-
end
|
51
|
-
def default_schema
|
52
|
-
Sequel::Deprecation.deprecate('Database#default_schema', 'Use qualified tables instead')
|
53
|
-
@default_schema
|
54
|
-
end
|
55
|
-
def default_schema=(v)
|
56
|
-
Sequel::Deprecation.deprecate('Database#default_schema=', 'Use qualified tables instead') if v
|
57
|
-
@default_schema = v
|
58
|
-
end
|
59
|
-
|
60
47
|
# If the database has any dataset modules associated with it,
|
61
48
|
# use a subclass of the given class that includes the modules
|
62
49
|
# as the dataset class.
|
@@ -146,11 +133,6 @@ module Sequel
|
|
146
133
|
self.class.const_get(:DatasetClass)
|
147
134
|
end
|
148
135
|
|
149
|
-
# REMOVE40
|
150
|
-
def default_schema_default
|
151
|
-
nil
|
152
|
-
end
|
153
|
-
|
154
136
|
# Reset the default dataset used by most Database methods that
|
155
137
|
# create datasets. Usually done after changes to the identifier
|
156
138
|
# mangling methods.
|
@@ -39,12 +39,12 @@ module Sequel
|
|
39
39
|
# Whether the database supports Database#foreign_key_list for
|
40
40
|
# parsing foreign keys.
|
41
41
|
def supports_foreign_key_parsing?
|
42
|
-
|
42
|
+
respond_to?(:foreign_key_list)
|
43
43
|
end
|
44
44
|
|
45
45
|
# Whether the database supports Database#indexes for parsing indexes.
|
46
46
|
def supports_index_parsing?
|
47
|
-
|
47
|
+
respond_to?(:indexes)
|
48
48
|
end
|
49
49
|
|
50
50
|
# Whether the database and adapter support prepared transactions
|
@@ -71,12 +71,12 @@ module Sequel
|
|
71
71
|
|
72
72
|
# Whether the database supports Database#tables for getting list of tables.
|
73
73
|
def supports_table_listing?
|
74
|
-
|
74
|
+
respond_to?(:tables)
|
75
75
|
end
|
76
76
|
#
|
77
77
|
# Whether the database supports Database#views for getting list of views.
|
78
78
|
def supports_view_listing?
|
79
|
-
|
79
|
+
respond_to?(:views)
|
80
80
|
end
|
81
81
|
|
82
82
|
# Whether the database and adapter support transaction isolation levels, false by default.
|
data/lib/sequel/database/misc.rb
CHANGED
@@ -110,7 +110,7 @@ module Sequel
|
|
110
110
|
# :sql_log_level :: Method to use to log SQL to a logger, :info by default.
|
111
111
|
#
|
112
112
|
# All options given are also passed to the connection pool.
|
113
|
-
def initialize(opts =
|
113
|
+
def initialize(opts = OPTS, &block)
|
114
114
|
@opts ||= opts
|
115
115
|
@opts = connection_pool_default_options.merge(@opts)
|
116
116
|
@loggers = Array(@opts[:logger]) + Array(@opts[:loggers])
|
@@ -121,7 +121,6 @@ module Sequel
|
|
121
121
|
|
122
122
|
@opts[:single_threaded] = @single_threaded = typecast_value_boolean(@opts.fetch(:single_threaded, Database.single_threaded))
|
123
123
|
@schemas = {}
|
124
|
-
@default_schema = @opts.fetch(:default_schema, default_schema_default)
|
125
124
|
@default_string_column_size = @opts[:default_string_column_size] || DEFAULT_STRING_COLUMN_SIZE
|
126
125
|
@prepared_statements = {}
|
127
126
|
@transactions = {}
|
@@ -150,7 +149,7 @@ module Sequel
|
|
150
149
|
# in progress transaction commits (and only if it commits).
|
151
150
|
# Options:
|
152
151
|
# :server :: The server/shard to use.
|
153
|
-
def after_commit(opts=
|
152
|
+
def after_commit(opts=OPTS, &block)
|
154
153
|
raise Error, "must provide block to after_commit" unless block
|
155
154
|
synchronize(opts[:server]) do |conn|
|
156
155
|
if h = _trans(conn)
|
@@ -167,7 +166,7 @@ module Sequel
|
|
167
166
|
# in progress transaction rolls back (and only if it rolls back).
|
168
167
|
# Options:
|
169
168
|
# :server :: The server/shard to use.
|
170
|
-
def after_rollback(opts=
|
169
|
+
def after_rollback(opts=OPTS, &block)
|
171
170
|
raise Error, "must provide block to after_rollback" unless block
|
172
171
|
synchronize(opts[:server]) do |conn|
|
173
172
|
if h = _trans(conn)
|
@@ -212,7 +211,7 @@ module Sequel
|
|
212
211
|
# Return true if already in a transaction given the options,
|
213
212
|
# false otherwise. Respects the :server option for selecting
|
214
213
|
# a shard.
|
215
|
-
def in_transaction?(opts=
|
214
|
+
def in_transaction?(opts=OPTS)
|
216
215
|
synchronize(opts[:server]){|conn| !!_trans(conn)}
|
217
216
|
end
|
218
217
|
|
@@ -398,7 +397,7 @@ module Sequel
|
|
398
397
|
|
399
398
|
# Convert the given exception to an appropriate Sequel::DatabaseError
|
400
399
|
# subclass, keeping message and traceback.
|
401
|
-
def raise_error(exception, opts=
|
400
|
+
def raise_error(exception, opts=OPTS)
|
402
401
|
if !opts[:classes] || Array(opts[:classes]).any?{|c| exception.is_a?(c)}
|
403
402
|
raise Sequel.convert_exception_class(exception, database_error_class(exception, opts))
|
404
403
|
else
|
@@ -495,8 +494,7 @@ module Sequel
|
|
495
494
|
def typecast_value_string(value)
|
496
495
|
case value
|
497
496
|
when Hash, Array
|
498
|
-
Sequel::
|
499
|
-
value.to_s
|
497
|
+
raise Sequel::InvalidValue, "invalid value for String: #{value.inspect}"
|
500
498
|
else
|
501
499
|
value.to_s
|
502
500
|
end
|
@@ -36,53 +36,27 @@ module Sequel
|
|
36
36
|
prepared_statement(ps_name).call(hash, &block)
|
37
37
|
end
|
38
38
|
|
39
|
-
# Executes the given SQL on the database. This method should be overridden in descendants.
|
40
|
-
# This method should not be called directly by user code.
|
41
|
-
def execute(sql, opts={})
|
42
|
-
Sequel::Deprecation.deprecate('Database#execute default implementation and Sequel::NotImplemented', 'All database instances can be assumed to implement execute')
|
43
|
-
raise NotImplemented, "#execute should be overridden by adapters"
|
44
|
-
end
|
45
|
-
|
46
39
|
# Method that should be used when submitting any DDL (Data Definition
|
47
40
|
# Language) SQL, such as +create_table+. By default, calls +execute_dui+.
|
48
41
|
# This method should not be called directly by user code.
|
49
|
-
def execute_ddl(sql, opts=
|
42
|
+
def execute_ddl(sql, opts=OPTS, &block)
|
50
43
|
execute_dui(sql, opts, &block)
|
51
44
|
end
|
52
45
|
|
53
46
|
# Method that should be used when issuing a DELETE, UPDATE, or INSERT
|
54
47
|
# statement. By default, calls execute.
|
55
48
|
# This method should not be called directly by user code.
|
56
|
-
def execute_dui(sql, opts=
|
49
|
+
def execute_dui(sql, opts=OPTS, &block)
|
57
50
|
execute(sql, opts, &block)
|
58
51
|
end
|
59
52
|
|
60
53
|
# Method that should be used when issuing a INSERT
|
61
54
|
# statement. By default, calls execute_dui.
|
62
55
|
# This method should not be called directly by user code.
|
63
|
-
def execute_insert(sql, opts=
|
56
|
+
def execute_insert(sql, opts=OPTS, &block)
|
64
57
|
execute_dui(sql, opts, &block)
|
65
58
|
end
|
66
59
|
|
67
|
-
# Returns an array of hashes containing foreign key information from the
|
68
|
-
# table. Each hash will contain at least the following fields:
|
69
|
-
#
|
70
|
-
# :columns :: An array of columns in the given table
|
71
|
-
# :table :: The table referenced by the columns
|
72
|
-
# :key :: An array of columns referenced (in the table specified by :table),
|
73
|
-
# but can be nil on certain adapters if the primary key is referenced.
|
74
|
-
#
|
75
|
-
# The hash may also contain entries for:
|
76
|
-
#
|
77
|
-
# :deferrable :: Whether the constraint is deferrable
|
78
|
-
# :name :: The name of the constraint
|
79
|
-
# :on_delete :: The action to take ON DELETE
|
80
|
-
# :on_update :: The action to take ON UPDATE
|
81
|
-
def foreign_key_list(table, opts={})
|
82
|
-
Sequel::Deprecation.deprecate('Database#foreign_key_list default implementation and Sequel::NotImplemented', 'Use Database#supports_foreign_key_parsing? to check for support')
|
83
|
-
raise NotImplemented, "#foreign_key_list should be overridden by adapters"
|
84
|
-
end
|
85
|
-
|
86
60
|
# Returns a single value from the database, e.g.:
|
87
61
|
#
|
88
62
|
# DB.get(1) # SELECT 1
|
@@ -92,26 +66,12 @@ module Sequel
|
|
92
66
|
@default_dataset.get(*args, &block)
|
93
67
|
end
|
94
68
|
|
95
|
-
# Return a hash containing index information for the table. Hash keys are index name symbols.
|
96
|
-
# Values are subhashes with two keys, :columns and :unique. The value of :columns
|
97
|
-
# is an array of symbols of column names. The value of :unique is true or false
|
98
|
-
# depending on if the index is unique.
|
99
|
-
#
|
100
|
-
# Should not include the primary key index, functional indexes, or partial indexes.
|
101
|
-
#
|
102
|
-
# DB.indexes(:artists)
|
103
|
-
# # => {:artists_name_ukey=>{:columns=>[:name], :unique=>true}}
|
104
|
-
def indexes(table, opts={})
|
105
|
-
Sequel::Deprecation.deprecate('Database#indexes default implementation and Sequel::NotImplemented', 'Use Database#supports_index_parsing? to check for support')
|
106
|
-
raise NotImplemented, "#indexes should be overridden by adapters"
|
107
|
-
end
|
108
|
-
|
109
69
|
# Runs the supplied SQL statement string on the database server. Returns nil.
|
110
70
|
# Options:
|
111
71
|
# :server :: The server to run the SQL on.
|
112
72
|
#
|
113
73
|
# DB.run("SET some_server_variable = 42")
|
114
|
-
def run(sql, opts=
|
74
|
+
def run(sql, opts=OPTS)
|
115
75
|
execute_ddl(sql, opts)
|
116
76
|
nil
|
117
77
|
end
|
@@ -156,7 +116,7 @@ module Sequel
|
|
156
116
|
# # :ruby_default=>nil,
|
157
117
|
# # :db_type=>"text",
|
158
118
|
# # :allow_null=>false}]]
|
159
|
-
def schema(table, opts=
|
119
|
+
def schema(table, opts=OPTS)
|
160
120
|
raise(Error, 'schema parsing is not implemented on this database') unless supports_schema_parsing?
|
161
121
|
|
162
122
|
opts = opts.dup
|
@@ -218,22 +178,6 @@ module Sequel
|
|
218
178
|
false
|
219
179
|
end
|
220
180
|
|
221
|
-
# Return all tables in the database as an array of symbols.
|
222
|
-
#
|
223
|
-
# DB.tables # => [:albums, :artists]
|
224
|
-
def tables(opts={})
|
225
|
-
Sequel::Deprecation.deprecate('Database#tables default implementation and Sequel::NotImplemented', 'Use Database#supports_table_listing? to check for support')
|
226
|
-
raise NotImplemented, "#tables should be overridden by adapters"
|
227
|
-
end
|
228
|
-
|
229
|
-
# Return all views in the database as an array of symbols.
|
230
|
-
#
|
231
|
-
# DB.views # => [:gold_albums, :artists_with_many_albums]
|
232
|
-
def views(opts={})
|
233
|
-
Sequel::Deprecation.deprecate('Database#views default implementation and Sequel::NotImplemented', 'Use Database#supports_view_listing? to check for support')
|
234
|
-
raise NotImplemented, "#views should be overridden by adapters"
|
235
|
-
end
|
236
|
-
|
237
181
|
private
|
238
182
|
|
239
183
|
# Should raise an error if the table doesn't not exist,
|
@@ -108,7 +108,7 @@ module Sequel
|
|
108
108
|
# :unique :: Mark the column as unique, generally has the same effect as
|
109
109
|
# creating a unique index on the column.
|
110
110
|
# :unique_constraint_name :: The name to give the unique key constraint
|
111
|
-
def column(name, type, opts =
|
111
|
+
def column(name, type, opts = OPTS)
|
112
112
|
columns << {:name => name, :type => type}.merge(opts)
|
113
113
|
if index_opts = opts[:index]
|
114
114
|
index(name, index_opts.is_a?(Hash) ? index_opts : {})
|
@@ -142,7 +142,7 @@ module Sequel
|
|
142
142
|
#
|
143
143
|
# foreign_key([:artist_name, :artist_location], :artists, :name=>:artist_fk)
|
144
144
|
# # ADD CONSTRAINT artist_fk FOREIGN KEY (artist_name, artist_location) REFERENCES artists
|
145
|
-
def foreign_key(name, table=nil, opts =
|
145
|
+
def foreign_key(name, table=nil, opts = OPTS)
|
146
146
|
opts = case table
|
147
147
|
when Hash
|
148
148
|
table.merge(opts)
|
@@ -160,11 +160,13 @@ module Sequel
|
|
160
160
|
# Add a full text index on the given columns to the DDL.
|
161
161
|
#
|
162
162
|
# PostgreSQL specific options:
|
163
|
+
# :index_type :: Can be set to :gist to use a GIST index instead of the
|
164
|
+
# default GIN index.
|
163
165
|
# :language :: Set a language to use for the index (default: simple).
|
164
166
|
#
|
165
167
|
# Microsoft SQL Server specific options:
|
166
168
|
# :key_index :: The KEY INDEX to use for the full text index.
|
167
|
-
def full_text_index(columns, opts =
|
169
|
+
def full_text_index(columns, opts = OPTS)
|
168
170
|
index(columns, opts.merge(:type => :full_text))
|
169
171
|
end
|
170
172
|
|
@@ -199,13 +201,13 @@ module Sequel
|
|
199
201
|
#
|
200
202
|
# index [:artist_id, :name]
|
201
203
|
# # CREATE INDEX table_artist_id_name_index ON table (artist_id, name)
|
202
|
-
def index(columns, opts =
|
204
|
+
def index(columns, opts = OPTS)
|
203
205
|
indexes << {:columns => Array(columns)}.merge(opts)
|
204
206
|
end
|
205
207
|
|
206
208
|
# Add a column with the given type, name, and opts to the DDL. See +column+ for available
|
207
209
|
# options.
|
208
|
-
def method_missing(type, name = nil, opts =
|
210
|
+
def method_missing(type, name = nil, opts = OPTS)
|
209
211
|
name ? column(name, type, opts) : super
|
210
212
|
end
|
211
213
|
|
@@ -250,7 +252,7 @@ module Sequel
|
|
250
252
|
end
|
251
253
|
|
252
254
|
# Add a spatial index on the given columns to the DDL.
|
253
|
-
def spatial_index(columns, opts =
|
255
|
+
def spatial_index(columns, opts = OPTS)
|
254
256
|
index(columns, opts.merge(:type => :spatial))
|
255
257
|
end
|
256
258
|
|
@@ -260,7 +262,7 @@ module Sequel
|
|
260
262
|
#
|
261
263
|
# Supports the same :deferrable option as #column. The :name option can be used
|
262
264
|
# to name the constraint.
|
263
|
-
def unique(columns, opts =
|
265
|
+
def unique(columns, opts = OPTS)
|
264
266
|
constraints << {:type => :unique, :columns => Array(columns)}.merge(opts)
|
265
267
|
end
|
266
268
|
|
@@ -308,7 +310,7 @@ module Sequel
|
|
308
310
|
# See CreateTableGenerator#column for the available options.
|
309
311
|
#
|
310
312
|
# add_column(:name, String) # ADD COLUMN name varchar(255)
|
311
|
-
def add_column(name, type, opts =
|
313
|
+
def add_column(name, type, opts = OPTS)
|
312
314
|
@operations << {:op => :add_column, :name => name, :type => type}.merge(opts)
|
313
315
|
end
|
314
316
|
|
@@ -327,7 +329,7 @@ module Sequel
|
|
327
329
|
# add_unique_constraint(:name, :name=>:unique_name) # ADD CONSTRAINT unique_name UNIQUE (name)
|
328
330
|
#
|
329
331
|
# Supports the same :deferrable option as CreateTableGenerator#column.
|
330
|
-
def add_unique_constraint(columns, opts =
|
332
|
+
def add_unique_constraint(columns, opts = OPTS)
|
331
333
|
@operations << {:op => :add_constraint, :type => :unique, :columns => Array(columns)}.merge(opts)
|
332
334
|
end
|
333
335
|
|
@@ -353,14 +355,14 @@ module Sequel
|
|
353
355
|
# existing data has been cleaned up, validate_constraint can be used
|
354
356
|
# to mark the constraint as valid. Note that this option only makes
|
355
357
|
# sense when using an array of columns.
|
356
|
-
def add_foreign_key(name, table, opts =
|
358
|
+
def add_foreign_key(name, table, opts = OPTS)
|
357
359
|
return add_composite_foreign_key(name, table, opts) if name.is_a?(Array)
|
358
360
|
add_column(name, Integer, {:table=>table}.merge(opts))
|
359
361
|
end
|
360
362
|
|
361
363
|
# Add a full text index on the given columns to the DDL for the table.
|
362
364
|
# See CreateTableGenerator#index for available options.
|
363
|
-
def add_full_text_index(columns, opts =
|
365
|
+
def add_full_text_index(columns, opts = OPTS)
|
364
366
|
add_index(columns, {:type=>:full_text}.merge(opts))
|
365
367
|
end
|
366
368
|
|
@@ -368,7 +370,7 @@ module Sequel
|
|
368
370
|
# CreateTableGenerator#index for available options.
|
369
371
|
#
|
370
372
|
# add_index(:artist_id) # CREATE INDEX table_artist_id_index ON table (artist_id)
|
371
|
-
def add_index(columns, opts =
|
373
|
+
def add_index(columns, opts = OPTS)
|
372
374
|
@operations << {:op => :add_index, :columns => Array(columns)}.merge(opts)
|
373
375
|
end
|
374
376
|
|
@@ -378,7 +380,7 @@ module Sequel
|
|
378
380
|
#
|
379
381
|
# add_primary_key(:id) # ADD COLUMN id serial PRIMARY KEY
|
380
382
|
# add_primary_key([:artist_id, :name]) # ADD PRIMARY KEY (artist_id, name)
|
381
|
-
def add_primary_key(name, opts =
|
383
|
+
def add_primary_key(name, opts = OPTS)
|
382
384
|
return add_composite_primary_key(name, opts) if name.is_a?(Array)
|
383
385
|
opts = @db.serial_primary_key_options.merge(opts)
|
384
386
|
add_column(name, opts.delete(:type), opts)
|
@@ -386,7 +388,7 @@ module Sequel
|
|
386
388
|
|
387
389
|
# Add a spatial index on the given columns to the DDL for the table.
|
388
390
|
# See CreateTableGenerator#index for available options.
|
389
|
-
def add_spatial_index(columns, opts =
|
391
|
+
def add_spatial_index(columns, opts = OPTS)
|
390
392
|
add_index(columns, {:type=>:spatial}.merge(opts))
|
391
393
|
end
|
392
394
|
|
@@ -394,7 +396,7 @@ module Sequel
|
|
394
396
|
#
|
395
397
|
# drop_column(:artist_id) # DROP COLUMN artist_id
|
396
398
|
# drop_column(:artist_id, :cascade=>true) # DROP COLUMN artist_id CASCADE
|
397
|
-
def drop_column(name, opts=
|
399
|
+
def drop_column(name, opts=OPTS)
|
398
400
|
@operations << {:op => :drop_column, :name => name}.merge(opts)
|
399
401
|
end
|
400
402
|
|
@@ -405,7 +407,7 @@ module Sequel
|
|
405
407
|
#
|
406
408
|
# drop_constraint(:unique_name) # DROP CONSTRAINT unique_name
|
407
409
|
# drop_constraint(:unique_name, :cascade=>true) # DROP CONSTRAINT unique_name CASCADE
|
408
|
-
def drop_constraint(name, opts=
|
410
|
+
def drop_constraint(name, opts=OPTS)
|
409
411
|
@operations << {:op => :drop_constraint, :name => name}.merge(opts)
|
410
412
|
end
|
411
413
|
|
@@ -419,7 +421,7 @@ module Sequel
|
|
419
421
|
#
|
420
422
|
# drop_foreign_key(:artist_id) # DROP CONSTRAINT table_artist_id_fkey, DROP COLUMN artist_id
|
421
423
|
# drop_foreign_key([:name]) # DROP CONSTRAINT table_name_fkey
|
422
|
-
def drop_foreign_key(name, opts=
|
424
|
+
def drop_foreign_key(name, opts=OPTS)
|
423
425
|
drop_composite_foreign_key(Array(name), opts)
|
424
426
|
drop_column(name) unless name.is_a?(Array)
|
425
427
|
end
|
@@ -439,14 +441,14 @@ module Sequel
|
|
439
441
|
# drop_index(:artist_id) # DROP INDEX table_artist_id_index
|
440
442
|
# drop_index([:a, :b]) # DROP INDEX table_a_b_index
|
441
443
|
# drop_index([:a, :b], :name=>:foo) # DROP INDEX foo
|
442
|
-
def drop_index(columns, options=
|
444
|
+
def drop_index(columns, options=OPTS)
|
443
445
|
@operations << {:op => :drop_index, :columns => Array(columns)}.merge(options)
|
444
446
|
end
|
445
447
|
|
446
448
|
# Modify a column's name in the DDL for the table.
|
447
449
|
#
|
448
450
|
# rename_column(:name, :artist_name) # RENAME COLUMN name TO artist_name
|
449
|
-
def rename_column(name, new_name, opts =
|
451
|
+
def rename_column(name, new_name, opts = OPTS)
|
450
452
|
@operations << {:op => :rename_column, :name => name, :new_name => new_name}.merge(opts)
|
451
453
|
end
|
452
454
|
|
@@ -464,7 +466,7 @@ module Sequel
|
|
464
466
|
# PostgreSQL specific options:
|
465
467
|
#
|
466
468
|
# :using :: Add a USING clause that specifies how to convert existing values to new values.
|
467
|
-
def set_column_type(name, type, opts=
|
469
|
+
def set_column_type(name, type, opts=OPTS)
|
468
470
|
@operations << {:op => :set_column_type, :name => name, :type => type}.merge(opts)
|
469
471
|
end
|
470
472
|
|