sequel 5.6.0 → 5.7.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.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +30 -5099
  3. data/Rakefile +1 -1
  4. data/doc/opening_databases.rdoc +0 -2
  5. data/doc/postgresql.rdoc +31 -0
  6. data/doc/querying.rdoc +2 -2
  7. data/doc/release_notes/5.7.0.txt +108 -0
  8. data/doc/testing.rdoc +1 -0
  9. data/lib/sequel/adapters/jdbc/derby.rb +1 -1
  10. data/lib/sequel/adapters/jdbc/oracle.rb +11 -0
  11. data/lib/sequel/adapters/postgres.rb +1 -0
  12. data/lib/sequel/adapters/shared/postgres.rb +117 -13
  13. data/lib/sequel/connection_pool/sharded_threaded.rb +7 -6
  14. data/lib/sequel/connection_pool/threaded.rb +6 -6
  15. data/lib/sequel/core.rb +20 -0
  16. data/lib/sequel/database/logging.rb +3 -2
  17. data/lib/sequel/database/schema_generator.rb +1 -2
  18. data/lib/sequel/dataset/actions.rb +15 -5
  19. data/lib/sequel/extensions/connection_expiration.rb +3 -3
  20. data/lib/sequel/extensions/connection_validator.rb +3 -3
  21. data/lib/sequel/extensions/integer64.rb +30 -0
  22. data/lib/sequel/extensions/migration.rb +2 -3
  23. data/lib/sequel/plugins/pg_array_associations.rb +5 -3
  24. data/lib/sequel/plugins/validate_associated.rb +18 -0
  25. data/lib/sequel/version.rb +1 -1
  26. data/spec/adapters/mssql_spec.rb +6 -6
  27. data/spec/adapters/mysql_spec.rb +1 -1
  28. data/spec/adapters/oracle_spec.rb +15 -1
  29. data/spec/adapters/postgres_spec.rb +78 -1
  30. data/spec/adapters/spec_helper.rb +3 -1
  31. data/spec/bin_spec.rb +1 -0
  32. data/spec/core/dataset_spec.rb +10 -0
  33. data/spec/extensions/integer64_spec.rb +22 -0
  34. data/spec/extensions/pg_array_associations_spec.rb +14 -2
  35. data/spec/extensions/spec_helper.rb +1 -0
  36. data/spec/integration/associations_test.rb +4 -4
  37. data/spec/integration/dataset_test.rb +2 -0
  38. data/spec/integration/spec_helper.rb +5 -11
  39. data/spec/model/spec_helper.rb +1 -0
  40. metadata +35 -165
  41. data/doc/release_notes/1.0.txt +0 -38
  42. data/doc/release_notes/1.1.txt +0 -143
  43. data/doc/release_notes/1.3.txt +0 -101
  44. data/doc/release_notes/1.4.0.txt +0 -53
  45. data/doc/release_notes/1.5.0.txt +0 -155
  46. data/doc/release_notes/2.0.0.txt +0 -298
  47. data/doc/release_notes/2.1.0.txt +0 -271
  48. data/doc/release_notes/2.10.0.txt +0 -328
  49. data/doc/release_notes/2.11.0.txt +0 -215
  50. data/doc/release_notes/2.12.0.txt +0 -534
  51. data/doc/release_notes/2.2.0.txt +0 -253
  52. data/doc/release_notes/2.3.0.txt +0 -88
  53. data/doc/release_notes/2.4.0.txt +0 -106
  54. data/doc/release_notes/2.5.0.txt +0 -137
  55. data/doc/release_notes/2.6.0.txt +0 -157
  56. data/doc/release_notes/2.7.0.txt +0 -166
  57. data/doc/release_notes/2.8.0.txt +0 -171
  58. data/doc/release_notes/2.9.0.txt +0 -97
  59. data/doc/release_notes/3.0.0.txt +0 -221
  60. data/doc/release_notes/3.1.0.txt +0 -406
  61. data/doc/release_notes/3.10.0.txt +0 -286
  62. data/doc/release_notes/3.11.0.txt +0 -254
  63. data/doc/release_notes/3.12.0.txt +0 -304
  64. data/doc/release_notes/3.13.0.txt +0 -210
  65. data/doc/release_notes/3.14.0.txt +0 -118
  66. data/doc/release_notes/3.15.0.txt +0 -78
  67. data/doc/release_notes/3.16.0.txt +0 -45
  68. data/doc/release_notes/3.17.0.txt +0 -58
  69. data/doc/release_notes/3.18.0.txt +0 -120
  70. data/doc/release_notes/3.19.0.txt +0 -67
  71. data/doc/release_notes/3.2.0.txt +0 -268
  72. data/doc/release_notes/3.20.0.txt +0 -41
  73. data/doc/release_notes/3.21.0.txt +0 -87
  74. data/doc/release_notes/3.22.0.txt +0 -39
  75. data/doc/release_notes/3.23.0.txt +0 -172
  76. data/doc/release_notes/3.24.0.txt +0 -420
  77. data/doc/release_notes/3.25.0.txt +0 -88
  78. data/doc/release_notes/3.26.0.txt +0 -88
  79. data/doc/release_notes/3.27.0.txt +0 -82
  80. data/doc/release_notes/3.28.0.txt +0 -304
  81. data/doc/release_notes/3.29.0.txt +0 -459
  82. data/doc/release_notes/3.3.0.txt +0 -192
  83. data/doc/release_notes/3.30.0.txt +0 -135
  84. data/doc/release_notes/3.31.0.txt +0 -146
  85. data/doc/release_notes/3.32.0.txt +0 -202
  86. data/doc/release_notes/3.33.0.txt +0 -157
  87. data/doc/release_notes/3.34.0.txt +0 -671
  88. data/doc/release_notes/3.35.0.txt +0 -144
  89. data/doc/release_notes/3.36.0.txt +0 -245
  90. data/doc/release_notes/3.37.0.txt +0 -338
  91. data/doc/release_notes/3.38.0.txt +0 -234
  92. data/doc/release_notes/3.39.0.txt +0 -237
  93. data/doc/release_notes/3.4.0.txt +0 -325
  94. data/doc/release_notes/3.40.0.txt +0 -73
  95. data/doc/release_notes/3.41.0.txt +0 -155
  96. data/doc/release_notes/3.42.0.txt +0 -74
  97. data/doc/release_notes/3.43.0.txt +0 -105
  98. data/doc/release_notes/3.44.0.txt +0 -152
  99. data/doc/release_notes/3.45.0.txt +0 -179
  100. data/doc/release_notes/3.46.0.txt +0 -122
  101. data/doc/release_notes/3.47.0.txt +0 -270
  102. data/doc/release_notes/3.48.0.txt +0 -477
  103. data/doc/release_notes/3.5.0.txt +0 -510
  104. data/doc/release_notes/3.6.0.txt +0 -366
  105. data/doc/release_notes/3.7.0.txt +0 -179
  106. data/doc/release_notes/3.8.0.txt +0 -151
  107. data/doc/release_notes/3.9.0.txt +0 -233
@@ -1,202 +0,0 @@
1
- = New Features
2
-
3
- * Prepared statements now support :map and :to_hash prepared
4
- statement types. The main reason for this is that certain
5
- extensions (e.g. sequel_pg) optimize map/to_hash calls, and
6
- there previously was not a way to use prepared statements
7
- with the map/to_hash optimizations.
8
-
9
- * Sequel.empty_array_handle_nulls has been added to change how
10
- IN/NOT IN operations with an empty array are handled. See
11
- the Backwards Compatibility section for details.
12
-
13
- * 5 new association options have been added that allow you to
14
- define associations where the underlying columns clash with
15
- standard ruby method names:
16
-
17
- many_to_one :primary_key_method
18
- one_to_many :key_method
19
- one_to_many :primary_key_column
20
- many_to_many :left_primary_key_column
21
- many_to_many :right_primary_key_method
22
-
23
- Using these new options, you can now define associations
24
- that work correctly when the underlying primary/foreign key
25
- columns clash with existing ruby method names. See the RDoc
26
- for details.
27
-
28
- * A use_after_commit_rollback setting has been added to models.
29
- This defaults to true, but can be set to false for performance
30
- or to allow models to be used in prepared transactions
31
- (which don't support after_commit/after_rollback).
32
-
33
- * Dataset#update_ignore has been added when connecting to MySQL,
34
- enabling use of the UPDATE IGNORE syntax to skip updating a row
35
- if the update would cause a unique constraint to be violated.
36
-
37
- * Database#indexes is now supported when connecting to Microsoft
38
- SQL Server.
39
-
40
- * On Microsoft SQL Server, the :include option is now supported
41
- when creating indexes, for storing column values in the index,
42
- which can be used by the query optimizer.
43
-
44
- = Other Improvements
45
-
46
- * The filtering/excluding by associations code now uses qualified
47
- identifiers instead of unqualified identifiers, which allows it
48
- to avoid ambiguous column names if you are doing your own joins.
49
-
50
- * Virtual row blocks that return arrays are now handled correctly
51
- in Dataset#select_map/select_order_map.
52
-
53
- * Dataset#select_map/select_order_map can now take both a block
54
- argument as well as a regular argument.
55
-
56
- * Dataset#select_order_map now handles virtual row blocks that
57
- return ordered expressions.
58
-
59
- * Database#table_exists? should no longer generate false negatives
60
- if you only have permission to retrieve some column values but
61
- not all. Note that if you lack permission to SELECT from the
62
- table itself, table_exists? can still generate false negatives.
63
-
64
- * The active_model plugin now supports ActiveModel 3.2, by adding
65
- support for to_partial_path.
66
-
67
- * The serialization_modification_detection plugin now handles
68
- changed_columns correctly both for new objects and after saving
69
- objects.
70
-
71
- * The serialization plugin now clears the deserialized values when
72
- it does the automatic refresh after saving a new object, mostly for
73
- consistency. You can use the skip_create_refresh plugin to skip
74
- refreshing when creating a new model object.
75
-
76
- * Column default values are now wrapped in parentheses on SQLite,
77
- which fixes some cases such as when the default is an SQL function
78
- call.
79
-
80
- * Alter table emulation now works correctly on SQLite when foreign
81
- keys reference the table being altered. The emulation requires
82
- a renaming/deleting the existing table and creating a new table,
83
- which can break foreign key references. Sequel now disables the
84
- foreign key PRAGMA when altering tables, so SQLite won't track
85
- the table renames and break the foreign key relationships.
86
-
87
- * The set_column_type table alteration method no longer modifies
88
- default values and NULL/NOT NULL settings on Microsoft SQL
89
- Server, H2, and SQLite.
90
-
91
- * On MySQL, Time/DateTime columns now use the timestamp type if the
92
- default value is Sequel::CURRENT_TIMESTAMP, since it is currently
93
- impossible for MySQL to have a non-constant default for a
94
- datetime column (without using a workaround like a trigger).
95
-
96
- * Metadata methods such as tables, views, and view_exists? are now
97
- handled correctly on Oracle if custom identifier input methods
98
- are used.
99
-
100
- * Sequel now ignores errors that occur when attempting to get
101
- information on column defaults in Oracle (which can happen if you
102
- lack permission to the appropriate table). Previously, such errors
103
- would cause the schema parser to raise an error, now, the schema
104
- information is just returned without default information.
105
-
106
- * Database#indexes now skips the primary key index when connecting to
107
- DB2, Derby, HSQLDB, and Oracle via the jdbc adapter.
108
-
109
- * Database#indexes now works correctly on DB2.
110
-
111
- * The progress adapter has been fixed, it had been broken since the
112
- dataset literalization refactoring.
113
-
114
- * Dataset#naked! now works correctly. Previously, it just returned
115
- the receiver unmodified.
116
-
117
- * Dataset#paginate! has been removed, as it was broken.
118
-
119
- * The query extension no longer breaks Dataset#clone if an argument
120
- is not given.
121
-
122
- * Transaction related queries are no longer logged twice in the mock
123
- adapter.
124
-
125
- = Backwards Compatibility
126
-
127
- * Sequel's default handling of NOT IN operators with an empty array
128
- of values has changed, which can change which rows are returned for
129
- such queries.
130
-
131
- Previously, Sequel was inconsistent in that it tried to handle NULL
132
- values correctly in the IN case, but not in the NOT IN case. Now,
133
- it defaults to handling NULL values correctly in both cases:
134
-
135
- # 3.31.0
136
- DB[:a].where(:b=>[])
137
- # SELECT * FROM a WHERE (b != b)
138
- DB[:a].exclude(:b=>[])
139
- # SELECT * FROM a WHERE (1 = 1)
140
-
141
- # 3.32.0
142
- DB[:a].where(:b=>[])
143
- # SELECT * FROM a WHERE (b != b)
144
- DB[:a].exclude(:b=>[])
145
- # SELECT * FROM a WHERE (b = b)
146
-
147
- The important change in behavior is that in the NOT IN case, if
148
- the left hand argument is NULL, the filter returns NULL instead
149
- of true. This has the potential to change query results.
150
-
151
- "Correct" here is really an opinion and not a fact, as there are
152
- valid arguments for the alternative behavior:
153
-
154
- DB[:a].where(:b=>[])
155
- # SELECT * FROM a WHERE (1 = 0)
156
- DB[:a].exclude(:b=>[])
157
- # SELECT * FROM a WHERE (1 = 1)
158
-
159
- The difference is that the "correct" NULL behavior is more
160
- consistent with the non-empty array cases. For example, if b is
161
- NULL:
162
-
163
- # "Correct" NULL handling
164
- # Empty array: where(:b=>[])
165
- WHERE (b != b) # NULL
166
- WHERE (b = b) # NULL
167
- # Non-empty array: where(:b=>[1, 2])
168
- WHERE (b IN (1, 2)) # NULL
169
- WHERE (b NOT IN (1, 2)) # NULL
170
-
171
- # Static boolean handling
172
- # Empty array: where(:b=>[])
173
- WHERE (1 = 0) # false
174
- WHERE (1 = 1) # true
175
- # Non-empty array: where(:b=>[1, 2])
176
- WHERE (b IN (1, 2)) # NULL
177
- WHERE (b NOT IN (1, 2)) # NULL
178
-
179
- Sequel chooses to default to behavior consistent with the non-empty
180
- array cases (similar to SQLAlchemy). However, there are two
181
- downsides to this handling. The first is that some databases with
182
- poor optimizers (e.g. MySQL) might do a full table scan with the
183
- default syntax. The second is that the static boolean handling may
184
- be generally perferable, if you believe that IN/NOT IN with an
185
- empty array should always be true or false and never NULL even if
186
- the left hand argument is NULL.
187
-
188
- As there really isn't a truly correct answer in this case, Sequel
189
- defaults to the "correct" NULL handling, and allows you to switch
190
- to the static boolean handling via:
191
-
192
- Sequel.empty_array_handle_nulls = false
193
-
194
- This is currently a global setting, it may be made Database or
195
- Dataset specific later if requested. Also, it is possible the
196
- default will switch in the future, so if you care about a specific
197
- handling, you should set your own default.
198
-
199
- * Database#table_exists? now only rescues Sequel::DatabaseErrors
200
- instead of StandardErrors, so it's possible it will raise errors
201
- instead of returning false on custom adapters that don't wrap
202
- their errors correctly.
@@ -1,157 +0,0 @@
1
- = New Features
2
-
3
- * A server_block extension has been added that makes Sequel's
4
- sharding support easier to use by scoping database access inside
5
- the block to a given server/shard:
6
-
7
- Sequel.extension :server_block
8
- DB.extend Sequel::ServerBlock
9
- DB.with_server(:shard_1) do
10
- # All of these will execute against shard_1
11
- DB.tables
12
- DB[:table].all
13
- DB.run 'SOME SQL'
14
- end
15
-
16
- * An arbitrary_servers extension has been added that extends
17
- Sequel's sharding support so that you can use arbitrary
18
- connection options instead of referencing an existing, predefined
19
- server/shard:
20
-
21
- Sequel.extension :arbitrary_servers
22
- DB.pool.extend Sequel::ArbitraryServers
23
- DB[:table].server(:host=>'foo', :database=>'bar').all
24
-
25
- You can use this extension in conjunction with the server_block
26
- extension:
27
-
28
- DB.with_server(:host=>'foo', :database=>'bar') do
29
- DB.synchronize do
30
- # All of these will execute on host foo, database bar
31
- DB.tables
32
- DB[:table].all
33
- DB.run 'SOME SQL'
34
- end
35
- end
36
-
37
- The combination of these two extensions makes it pretty easy to
38
- write a thread-safe Rack middleware that scopes each request
39
- to an arbitrary database.
40
-
41
- * The sqlite adapter now supports an integer_booleans setting
42
- for using 1/0 for true/false values, instead of the the 't'/'f'
43
- values used by default. As SQLite recommends using integers to
44
- store booleans, converting your existing database and enabling
45
- this setting is recommended, but for backwards compatibility it
46
- is set to false. You can convert you existing database by doing
47
- the following for each table/column that has booleans:
48
-
49
- DB[:table].update(:boolean_column=>{'t'=>1}.
50
- case(0, :boolean_column))
51
-
52
- The integer_booleans default setting may change in a future
53
- version of Sequel, so you should set it manually to false if you
54
- prefer the current default.
55
-
56
- * You can now disable transaction use in migrations, in one of two
57
- ways. You generally only need to do this if you are using an
58
- SQL query inside a migration that is specifically not supported
59
- inside a transaction, such as CREATE INDEX CONCURRENTLY on
60
- PostgreSQL.
61
-
62
- The first way to disable transactions is on a per-migration basis
63
- by calling the no_transaction method inside the Sequel.migration
64
- block:
65
-
66
- Sequel.migration do
67
- no_transaction
68
- change do
69
- # ...
70
- end
71
- end
72
-
73
- That will make it so that a transaction is not used for that
74
- particular migration. The second way is passing the
75
- :use_tranctions=>false option when calling Migrator.run (using
76
- the API), which will completely disable transactions for all
77
- migrations during the migrator run.
78
-
79
- * The postgres adapter now respects an :sslmode option when using
80
- pg as the underlying driver, you can set the value of this option to
81
- disable, allow, prefer, or require.
82
-
83
- * Database#create_schema and #drop_schema are now defined when
84
- connecting to PostgreSQL.
85
-
86
- * Database#supports_savepoints_in_prepared_transactions? has been
87
- added for checking if savepoints are supported inside prepared
88
- transactions. This is true if both savepoints and prepared
89
- transactions are both supported, except on MySQL > 5.5.12 (due to
90
- MySQL bug 64374).
91
-
92
- = Other Improvements
93
-
94
- * The mysql and mysql2 adapters now both provide an accurate number
95
- of rows matched, so Sequel::Model usage on those adapters will now
96
- raise a NoExistingObject exception by default if you attempt to
97
- delete or update an instance that no longer exists in the database.
98
-
99
- * Foreign key creation now works correctly without specifying the
100
- :key option when using MySQL with the InnoDB table engine. InnoDB
101
- requires that you list the column explicitly, even if you are
102
- referencing the primary key of the table, so if the :key option is
103
- not given, the database schema is introspected to find the primary
104
- key for the table. If you are attempting to create a table with
105
- a self-referential foreign key, it introspects the generator to
106
- get the primary key for the table.
107
-
108
- * The sqlite adapter will now return 1/0 stored in boolean columns as
109
- true/false. It will convert dates stored as Integers/Floats to
110
- Date objects by assuming they represent the julian date. It will
111
- convert times stored as Integers/Floats to Sequel::SQLTime objects
112
- by assuming they represent a number of seconds. It will convert
113
- datetimes stored as Integers by assuming they represent a unix
114
- epoch time integer, and datetimes stored as Floats by assuming the
115
- represent the julian date (with fractional part representing the
116
- time of day). These changes make Sequel handle SQLite's
117
- recommendations for boolean/date/time storage.
118
-
119
- * The instance_hooks plugin's (before|after)_*_hook methods now return
120
- self so they can be used in a method chain.
121
-
122
- * The list plugin now automatically adds new entries to the end of the
123
- list when creating the entries, if the position field is not
124
- specifically set.
125
-
126
- * An identifier_output_method is now respected in the mysql2 adapter.
127
-
128
- * NaN/Infinity Float values are now quoted correctly for input on
129
- PostgreSQL, and the postgres adapter correctly handles them on
130
- retrieval from the database.
131
-
132
- * The :collate column option is now respected when creating tables or
133
- altering columns on MySQL.
134
-
135
- * You can now force use of the TimestampMigrator when the
136
- IntegerMigrator would be used by default by calling
137
- TimestampMigrator.apply or .run.
138
-
139
- * Mock adapter usage with a specific SQL dialect now uses the
140
- appropriate defaults for quoting identifiers.
141
-
142
- * You can now disable the use of sudo in the rake install/uninstall
143
- tasks using the SUDO='' environment variable.
144
-
145
- * A very misleading error message has been fixed when attempting
146
- to constantize an invalid string in the model inflector.
147
-
148
- = Backwards Compatibility
149
-
150
- * The sqlite adapter now typecasts columns that SQLite stores as
151
- INTEGER/REAL. Previously, it only typecasted columns that
152
- SQLite stored as TEXT/BLOB. For details about SQLite storage, see
153
- http://www.sqlite.org/datatype3.html.
154
-
155
- Any custom type conversion procs used with the sqlite adapter should
156
- be modified to work with Integer/Float objects in addition to String
157
- objects.
@@ -1,671 +0,0 @@
1
- = New PostgreSQL Extensions
2
-
3
- * A pg_array extension has been added, supporting PostgreSQL's
4
- numeric and string array types. Both single dimensional and
5
- multi-dimensional array types are supported. Array values are
6
- returned as instances of Sequel::Postgres::PGArray, which is a
7
- delegate class of Array. You can turn an existing array into
8
- a PGArray using Array#pg_array.
9
-
10
- If you are using arrays in model objects, you need to load
11
- support for that:
12
-
13
- DB.extend Sequel::Postgres::PGArray::DatabaseMethods
14
-
15
- This makes schema parsing and typecasting of array columns work
16
- correctly.
17
-
18
- This extension also allows you to use PGArray objects and arrays
19
- in bound variables when using the postgres adapter with pg.
20
-
21
- * A pg_hstore extension has been added, supporting PostgreSQL's hstore
22
- type, which is a simple hash with string keys and string or NULL
23
- values. hstore values are retrieved as instances of
24
- Sequel::Postgres::HStore, which is a delegate class of Hash. You
25
- can turn an existing hash into an hstore using Hash#hstore.
26
-
27
- If you are using hstores in model objects, you need to load
28
- support for that:
29
-
30
- DB.extend Sequel::Postgres::HStore::DatabaseMethods
31
-
32
- This makes schema parsing and typecasting of hstore columns work
33
- correctly.
34
-
35
- This extension also allows you to use HStore objects and hashes
36
- in bound variables when using the postgres adapter with pg.
37
-
38
- * A pg_array_ops extension has been added, making it easier to call
39
- PostgreSQL array operators and functions using plain ruby code.
40
- Examples:
41
-
42
- a = :array_column.pg_array
43
- a[1] # array_column[1]
44
- a[1][2] # array_column[1][2]
45
- a.push(1) # array_column || 1
46
- a.unshift(1) # 1 || array_column
47
- a.any # ANY(array_column)
48
- a.join # array_to_string(array_column, '', NULL)
49
-
50
- If you are also using the pg_array extension, you can turn
51
- a PGArray object into a query object, which allows you to run
52
- operations on array literals:
53
-
54
- a = [1, 2].pg_array.op
55
- a.push(3) # ARRAY[1,2] || 3
56
-
57
- * A pg_hstore_ops extension has been added, making it easier to call
58
- PostgreSQL hstore operators and functions using plain ruby code.
59
- Examples:
60
-
61
- h = :hstore_column.hstore
62
- h['a'] # hstore_column -> 'a'
63
- h.has_key?('a') # hstore_column ? 'a'
64
- h.keys # akeys(hstore_column)
65
- h.to_array # hstore_to_array(hstore_column)
66
-
67
- If you are also using the pg_hstore extension, you can turn
68
- an HStore object into a query object, which allows you to run
69
- operations on hstore literals:
70
-
71
- h = {'a' => 'b'}.hstore.op
72
- h[a] # '"a"=>"b"'::hstore -> 'a'
73
-
74
- * A pg_auto_parameterize extension has been added for automatically
75
- using bound variables for all queries. For example, it can take
76
- code such as:
77
-
78
- DB[:table].where(:column=>1)
79
-
80
- and do:
81
-
82
- SELECT * FROM table WHERE column = $1; -- [1]
83
-
84
- Note that automatically parameterizing queries is not generally
85
- faster unless the bound variables are large (i.e. long text/bytea
86
- values). Also, there are multiple corner cases when automatically
87
- parameterizing queries, though most can be worked around by
88
- adding explicit casts.
89
-
90
- * A pg_statement_cache extension has been added that works with the
91
- pg_auto_parameterize extension for automatically caching prepared
92
- statements and reusing them when using the postgres adapter with
93
- pg. The combination of these two extensions makes it possible to
94
- take an entire Sequel application and turn most or all of the
95
- queries into prepared statements.
96
-
97
- Note that these two extensions do not necessarily improve
98
- performance. For simple queries, they actually hurt performance.
99
- They do help for complex queries, but in all cases, it's faster
100
- to use Sequel's prepared statements API manually.
101
-
102
- = Other New Extensions
103
-
104
- * A query_literals extension has been added that makes the select,
105
- group, and order methods operate similar to the filter methods in
106
- that if they are given a regular string as their first argument,
107
- they treat it as a literal string, with additional arguments, if
108
- any, used as placeholder values. This extension allows you to
109
- write code such as:
110
-
111
- DB[:table].select('a, b, ?' 2).group('a, b').order('c')
112
- # Without query_literals:
113
- # SELECT 'a, b, ?', 2 FROM table GROUP BY 'a, b' ORDER BY 'c'
114
- # With query_literals:
115
- # SELECT a, b, 2 FROM table GROUP BY a, b ORDER BY c
116
-
117
- Sequel's default handling in this case is to use literal strings,
118
- which is generally not desired and on some databases not even
119
- valid syntax. In general, you'll probably want to use this
120
- extension for all of a database's datasets, which you can do via:
121
-
122
- Sequel.extension :query_literals
123
- DB.extend_datasets(Sequel::QueryLiterals)
124
-
125
- The next major version of Sequel (4.0.0) will probably integrate
126
- this extension into the core library.
127
-
128
- * A select_remove extension has been added that adds
129
- Dataset#select_remove, for removing selected columns/expressions
130
- from a dataset:
131
-
132
- ds = DB[:table]
133
- # Assume table has columns a, b, and c
134
-
135
- ds.select_remove(:c)
136
- # SELECT a, b FROM table
137
-
138
- # Removal by column alias
139
- ds.select(:a, :b___c, :c___b).select_remove(:c)
140
- # SELECT a, c AS b FROM table
141
-
142
- # Removal by expression
143
- ds.select(:a, :b___c, :c___b).select_remove(:c___b)
144
- # SELECT a, b AS c FROM table
145
-
146
- This method makes it easier to select all columns except for the
147
- columns given. This is common in cases where a table has a few
148
- large columns that are expensive to retrieve. This method does
149
- have some corner cases, so read the documentation before using it.
150
-
151
- * A schema_caching extension has added that makes it possible for
152
- Database instances to dump the cached schema metadata to a
153
- marshalled file, and load the cached schema metadata from the file.
154
- This can be significantly faster than reparsing the schema from the
155
- database, especially for databases with high latency.
156
-
157
- bin/sequel -S has been added to dump the schema for the given
158
- database to a file, and DB.load_schema_cache(filename) can be used
159
- to populate the schema cache inside your application. This should
160
- be done after creating the Database object but before loading your
161
- model files.
162
-
163
- Note that Sequel does no checking to ensure that the cached schema
164
- currently reflects the state of the database. That is up to the
165
- application.
166
-
167
- * A null_dataset extension has been added, which adds
168
- Dataset#nullify for creating a dataset that will not issue a
169
- database query. It implements the null object pattern for
170
- datasets, and is probably most useful in methods that must return
171
- a dataset, but can determine that such a dataset will never return
172
- a row.
173
-
174
- = New Plugins
175
-
176
- * A static_cache plugin has been added, allowing you to cache a model
177
- statically. This plugin is useful for models whose tables do not
178
- change while the application is running, such as lookup tables.
179
- When using this plugin, the following methods will no longer require
180
- queries:
181
-
182
- * Primary key lookups (e.g. Model[1])
183
- * Model.all calls
184
- * Model.each calls
185
- * Model.map calls without an argument
186
- * Model.to_hash calls without an argument
187
-
188
- The statically cached model instances are frozen so they are not
189
- accidently modified.
190
-
191
- * A many_to_one_pk_lookup plugin has been added that changes the
192
- many_to_one association retrieval code to do a simple primary
193
- key lookup on the associated class in most cases. This results
194
- in significantly better performance, especially if the
195
- associated model is using a caching plugin (either caching
196
- or static_cache).
197
-
198
- = Core Extension Replacements
199
-
200
- * Most of Sequel's core extensions now have equivalent methods defined
201
- on the Sequel module:
202
-
203
- :column.as(:alias) -> Sequel.as(:column, :alias)
204
- :column.asc -> Sequel.asc(:column)
205
- :column.desc -> Sequel.desc(:column)
206
- :column.cast(Integer) -> Sequel.cast(:column, Integer)
207
- :column.cast_numeric -> Sequel.cast_numeric(:column)
208
- :column.cast_string -> Sequel.cast_string(:column)
209
- :column.extract(:year) -> Sequel.extract(:year, :column)
210
- :column.identifier -> Sequel.identifier(:column)
211
- :column.ilike('A%') -> Sequel.ilike(:column, 'A%')
212
- :column.like('A%') -> Sequel.like(:column, 'A%')
213
- :column.qualify(:table) -> Sequel.qualify(:table, :column)
214
- :column.sql_subscript(1) -> Sequel.subscript(:column, 1)
215
- :function.sql_function(1) -> Sequel.function(:function, 1)
216
- 'some SQL'.lit -> Sequel.lit('some SQL')
217
- 'string'.to_sequel_blob -> Sequel.blob('string')
218
- {:a=>1}.case(0) -> Sequel.case({:a=>1}, 0)
219
- {:a=>1}.sql_negate -> Sequel.negate(:a=>1)
220
- {:a=>1}.sql_or -> Sequel.or(:a=>1)
221
- [[1, 2]].sql_value_list -> Sequel.value_list([[1, 2]])
222
- [:a, :b].sql_string_join -> Sequel.join([:a, :b])
223
- ~{:a=>1} -> Sequel.~(:a=>1)
224
- :a + 1 -> Sequel.+(:a, 1)
225
- :a - 1 -> Sequel.-(:a, 1)
226
- :a * 1 -> Sequel.*(:a, 1)
227
- :a / 1 -> Sequel./(:a, 1)
228
- :a & 1 -> Sequel.&(:a, 1)
229
- :a | 1 -> Sequel.|(:a, 1)
230
-
231
- * You can now wrap any object in a Sequel expression using
232
- Sequel.expr. This is similar to the sql_expr extension, but
233
- without defining the sql_expr method on all objects:
234
-
235
- 1.sql_expr -> Sequel.expr(1)
236
-
237
- The sql_expr extension now just has Object#sql_expr call
238
- Sequel.expr.
239
-
240
- * Virtual Rows now have methods defined that handle the standard
241
- mathematical operators:
242
-
243
- select{|o| o.+(1, :a)} # SELECT (1 + a)
244
-
245
- the standard inequality operators:
246
-
247
- where{|o| o.>(2, :a)} # WHERE (2 > a)
248
-
249
- and the standard boolean operators:
250
-
251
- where{|o| o.&({:a=>1}, o.~(:b=>1))} # WHERE ((a = 1) AND (b != 1))
252
-
253
- Additionally, there is now direct support for creating literal
254
- strings in instance_evaled virtual row blocks using `:
255
-
256
- where{a > `some crazy SQL`} # WHERE (a > some crazy SQL)
257
-
258
- This doesn't override Kernel.`, since virtual rows use a BasicObject
259
- subclass. Previously, using ` would result in calling the SQL
260
- function named ` with the given string, which probably isn't valid
261
- syntax on most databases.
262
-
263
- * You can now require 'sequel/no_core_ext' to load Sequel without the
264
- core extensions. The previous way of setting the
265
- SEQUEL_NO_CORE_EXTENSIONS constant or environment variable before
266
- loading Sequel still works.
267
-
268
- * The core extensions have been moved from Sequel's core library into
269
- an extension that is loadable with Sequel.extension. This extension
270
- is still loaded by default for backwards compatibility. However,
271
- the next major version of Sequel will no longer load this extension
272
- by default (though it will still be available to load manually).
273
-
274
- * You can now check if the core extensions have been loaded by using
275
- Sequel.core_extensions?.
276
-
277
- = Foreign Keys in the Schema Dumper
278
-
279
- * Database#foreign_key_list has been added that gives an array of
280
- foreign key constraints on the table. It is currently implemented
281
- on MySQL, PostgreSQL, and SQLite, and may be implemented on other
282
- database types in the future. Each entry in the return array is
283
- a hash, with at least the following keys present:
284
-
285
- :columns :: An array of columns in the given table
286
- :table :: The table referenced by the columns
287
- :key :: An array of columns referenced (in the table specified by
288
- :table), but can be nil on certain adapters if the primary
289
- key is referenced.
290
-
291
- The hash may also contain entries for:
292
-
293
- :deferrable :: Whether the constraint is deferrable
294
- :name :: The name of the constraint
295
- :on_delete :: The action to take ON DELETE
296
- :on_update :: The action to take ON UPDATE
297
-
298
- * The schema_dumper extension now dumps foreign key constraints on
299
- databases that support Database#foreign_key_list. On such
300
- databases, dumping a schema migration will dump the tables in
301
- topological order, such that referenced tables always come before
302
- referencing tables.
303
-
304
- In case there is a circular dependency, Sequel breaks the
305
- dependency and adds separate foreign key constraints at the end
306
- of the migration. However, when a circular dependency is broken,
307
- the migration can probably not be migrated down.
308
-
309
- Foreign key constraints can also be dumped as a separate migration
310
- using Database#dump_foreign_key_migration, similar to how
311
- Database#dump_indexes_migration works.
312
-
313
- * When using bin/sequel -C to copy databases, foreign key constraints
314
- are now copied if the source database supports
315
- Database#foreign_key_list.
316
-
317
- = Other New Features
318
-
319
- * Dataset#to_hash_groups and #select_hash_groups have been added.
320
- These methods are similar to #to_hash and #select_hash in that they
321
- return a hash, but hashes returned by *_hash_groups methods have
322
- arrays of all matching values, unlike the *_hash methods which
323
- just use the last matching value. Example:
324
-
325
- DB[:table].all
326
- # => [{:a=>1, :b=>2}, {:a=>1, :b=>3}, {:a=>2, :b=>4}]
327
-
328
- DB[:table].to_hash(:a, :b)
329
- # => {1=>3, 2=>4}
330
-
331
- DB[:table].to_hash_groups(:a, :b)
332
- # => {1=>[2, 3], 2=>[4]}
333
-
334
- * Model#set_fields and #update_fields now accept :missing=>:skip and
335
- :missing=>:raise options, allowing them to be used in more cases.
336
- :missing=>:skip skips missing entries in the hash, instead of
337
- setting the field to the default hash value. :missing=>:raise
338
- raises an error for missing fields, similar to
339
- strict_param_setting = true. It's recommended that these options
340
- be used in new code in preference to #set_only and #update_only.
341
-
342
- * Database#drop_table? has been added, for dropping tables if they
343
- already exist. This uses DROP TABLE IF EXISTS on the databases that
344
- support it. Database#supports_drop_table_if_exists? has been added
345
- for checking whether the database supports that syntax.
346
-
347
- * Database#create_join_table has been added that allows easy
348
- creation of many_to_many join tables:
349
-
350
- DB.create_join_table(:album_id=>:albums, :artist_id=>:artists)
351
-
352
- This uses real foreign keys for both of the columns, uses a
353
- composite primary key of both of the columns, and adds an
354
- additional composite index of the columns in reverse order. The
355
- primary key and additional index should ensure that almost all
356
- operations on the join table can benefit from an index.
357
-
358
- In terms of customization, the values in the hash can be hashes
359
- themselves for column specific options, and an additional options
360
- hash can also be given to override some of the default settings.
361
-
362
- Database#drop_join_table also exists and takes the same options
363
- as create_join_table. It mostly exists to make it easy to
364
- reverse migrations that use create_join_table.
365
-
366
- * Model#freeze has been added that freezes a model such that it
367
- works correctly in a read-only state. Before, it used the standard
368
- Object#freeze, which broke some things that should work, and
369
- allowed changes that shouldn't be allowed (like modifying the
370
- instance's values).
371
-
372
- * ConnectionPool#all_connections has been added, which yields each
373
- available connection in the pool to the block. For threaded pools,
374
- it does not yield connections that are currently being used by
375
- other threads. When using this method, it is important to only
376
- operate on the yielded connection objects, and not make any
377
- modifications to the pool itself. The pool is also locked until
378
- the method returns.
379
-
380
- * ConnectionPool#after_connect= has been added, allowing you to
381
- change a connection pool's after_connect proc after instantiating
382
- the pool.
383
-
384
- * ConnectionPool#disconnection_proc= has been added, allowing you to
385
- change a connection pool's disconnection_proc after instantiating the
386
- pool.
387
-
388
- * A Model.cache_anonymous_models accessor has been added, and can be
389
- set to false to disable the caching of classes created by
390
- Sequel::Model(). This caching is only useful if you want to reload
391
- the model's file without getting a superclass mismatch. This
392
- setting is true by default for backwards compatibility, but may be
393
- changed to false in a later version, so you should manually set it to
394
- true if you are using code reloading.
395
-
396
- * Model.instance_dataset has been added for getting the dataset used
397
- for model instances (a naked dataset restricted to a single row).
398
-
399
- * Dataset#with_sql_delete has been added for running the given SQL
400
- string as a delete and returning the number of rows modified. It's
401
- designed as a replacement for with_sql(sql).delete, which is slower
402
- as it requires cloning the dataset.
403
-
404
- * The :on_update and :on_delete entries for foreign_key now accept
405
- string arguments which are used literally.
406
-
407
- * Prepared statement objects now have a log_sql accessor that can be
408
- turned on to log the entire SQL statement instead of just the
409
- prepared statement name.
410
-
411
- * Dataset#multi_replace has been added on MySQL. This is similar to
412
- multi_insert, but uses REPLACE instead of INSERT.
413
-
414
- * Dataset#explain has been added to MySQL. You can use an
415
- :extended=>true option to use EXPLAIN EXTENDED.
416
-
417
- * A Database#type_supported? method has been added on PostgreSQL to
418
- check if the database supports the given type:
419
-
420
- DB.type_supported?(:hstore)
421
-
422
- * Datatabase#reset_conversion_procs has been added to the postgres
423
- adapter, for use by extensions that modify the default conversion
424
- procs and want to have the database use the updated defaults.
425
-
426
- * A Database#convert_infinite_timestamps accessor has been added to
427
- the postgres adapter, allowing you to return infinite timestamps as
428
- nil, a string, or a float.
429
-
430
- * SQL::PlaceholderLiteralString objects can now use a placeholder
431
- array, where placeholder values are inserted between array elements.
432
- This is about 2.5-3x faster than using a string with ? placeholders,
433
- and allows usage of ? inside the array:
434
-
435
- Sequel.lit(["(", " ? ", ")"], 1, 2) # (1 ? 2)
436
-
437
- * SQL::Subscript#[] has been added for accessing members of a
438
- multi-dimensional array:
439
-
440
- Sequel.subscript(:column, 1)[2][3] # column[1][2][3]
441
-
442
- * SQL::Wrapper has been added for wrapping arbitrary objects in a
443
- Sequel expression object.
444
-
445
- * SQL::QualifiedIdentifier objects can now contain arbitrary Sequel
446
- expressions. Before, they could only contain a few expression
447
- types. This makes it easier to add extensions to support
448
- PostgreSQL row-valued types.
449
-
450
- = Performance Improvements
451
-
452
- * Model.[] when called with a primary key has been made about 110%
453
- faster for most models by avoiding cloning datasets.
454
-
455
- * Model.[] when called without arguments or with a single nil argument
456
- is much faster as it now returns nil immediately instead of issuing
457
- a database query.
458
-
459
- * Model#delete and Model#destroy have been made about 75% faster for
460
- most models by using a static SQL string.
461
-
462
- * Model.new is now twice as fast when passed an empty hash.
463
-
464
- * Model#set is now four times as fast when passed an empty hash.
465
-
466
- * Model#this has been made about 85% faster by reducing the number of
467
- dataset clones needed from 3 to 1.
468
-
469
- * Some proc activations have been removed, giving minor speedups when
470
- running on MRI.
471
-
472
- = Other Improvements
473
-
474
- * Database#uri and #url now return the connection string given
475
- to Sequel.connect. Previously, they tried to reconstruct the
476
- url using the database's options, but that didn't work well in
477
- corner cases.
478
-
479
- * Database#inspect now shows the URL and/or options given when
480
- connecting to the database. Previously, it showed the URL, or
481
- all of the databases options if constructing the URL raised an
482
- error.
483
-
484
- * Sequel no longer checks for prepared transactions support when
485
- using transactions unless a prepared transaction is specifically
486
- requested.
487
-
488
- * The schema utility dataset cached in the Database object is now
489
- reset if you use Database#extend_datasets, ensuring that the new
490
- value will use the given extension.
491
-
492
- * The prepared_statements* plugins now log the full SQL by default.
493
- Since the user doesn't choose the name of the prepared statements,
494
- it was often difficult to determine what SQL was actually run if
495
- you were only looking at a subsection of the SQL log.
496
-
497
- * The nested_attributes plugin's delete/remove support now works
498
- correctly when a false value is given for _delete/_remove and
499
- strict_param_setting is true.
500
-
501
- * The hook_class_methods and validation_class_methods plugins
502
- now work correctly when subclassing if the subclass attempts to
503
- create instances inside Model.inherited.
504
-
505
- * The caching plugin has been refactored. Model.cache_get_pk and
506
- cache_delete_pk have been added for retrieving/deleting from the
507
- cache by primary key. Model.cache_key is now a public method.
508
-
509
- * The typecast_on_load plugin now works correctly when saving
510
- new model objects when insert_select is supported.
511
-
512
- * In the sql_expr extension, nil.sql_expr is no longer treated as
513
- a boolean value. It is now treated as a value with generic type.
514
-
515
- * The postgres adapter no longer issues a query to map type names to
516
- type oids if no named conversion procs have been registered.
517
-
518
- * The postgres adapter now works around issues in ruby-pg by
519
- supporting fractional seconds for Time/DateTime values, and
520
- supporting SQL::Blob (bytea) values with embedded "\0" characters.
521
-
522
- * The postgres adapter now supports pre-defining the PG_NAMED_TYPES
523
- and PG_TYPES constants. This is so extensions can define them,
524
- so they don't have to load the postgres adapter file first. If
525
- extensions need to use these constants, they should do:
526
-
527
- PG_NAMED_TYPES = {} unless defined?(PG_NAMED_TYPES)
528
- PG_TYPES = {} unless defined?(PG_TYPES)
529
-
530
- That way they work whether they are loaded before or after the
531
- postgres adapter.
532
-
533
- * PostgreSQL 8.2-9.0 now correctly add the RETURNING clause when
534
- building queries. Sequel 3.31.0 added support for returning values
535
- from delete/update queries in PostgreSQL 8.2-9.0, but didn't change
536
- the literalization code to use the RETURNING clause on those
537
- versions.
538
-
539
- * The jdbc/postgres adapter now converts Java arrays
540
- (Java::OrgPostgresqlJdbc4::Jdbc4Array) to ruby arrays.
541
-
542
- * Tables and schemas with embedded ' characters are now handled
543
- correctly when parsing primary keys and sequences on PostgreSQL.
544
-
545
- * Identifiers are now escaped on MySQL and SQLite. Previously they
546
- were quoted, but internal ` characters were not doubled.
547
-
548
- * Fractional seconds for the time type are now returned correctly on
549
- jdbc (assuming they are returned as java.sql.Time values by JDBC).
550
-
551
- * Multiple changes were made to ensure that Sequel works correctly
552
- when the core extensions are not loaded.
553
-
554
- * Composite foreign key constraints are now retained when emulating
555
- alter_table operations on SQLite. Previously, only single
556
- foreign key constraints were retained.
557
-
558
- * An error is no longer raised when no indexes exist when calling
559
- Database#indexes on jdbc/sqlite.
560
-
561
- * A possible SystemStackError has been fixed in the SQLite adapter,
562
- when trying to delete a dataset that uses a having clause and no
563
- where clause.
564
-
565
- * ROLLUP/CUBE support now works correctly on Microsoft SQL Server
566
- 2005.
567
-
568
- * Unsigned tinyint types are now recognized in the schema dumper.
569
-
570
- * Using primary_key :column, :type=>Bignum now works correctly on H2.
571
- Previously, the column created was not autoincrementing.
572
-
573
- * Using a bound variable for a limit is now supported in the ibmdb
574
- adapter on ruby 1.9.
575
-
576
- * Connecting to PostgreSQL via the swift adapter has been fixed when
577
- using newer versions of swift.
578
-
579
- * The mock adapter now handles calling the Database#execute methods
580
- directly (instead of via a dataset).
581
-
582
- * The mock adapter now has the ability to have per-shared adapter
583
- specific initialization code executed. This has been used to fix
584
- some bugs when using the shared postgres adapter.
585
-
586
- * The pretty_table extension has been split into two extensions, one
587
- that adds a method to Dataset and one that just adds the
588
- PrettyTable class. Also, PrettyTable.string has been added to get
589
- a string copy of the table.
590
-
591
- * A spec_model_no_assoc task has been added for running model specs
592
- without the association plugin loaded. This is to check that the
593
- SEQUEL_NO_ASSOCIATIONS setting works correctly.
594
-
595
- = Deprecated Features to be Removed in Sequel 3.35.0
596
-
597
- * Ruby <1.8.7 support is now deprecated.
598
-
599
- * PostgreSQL <8.2 support is now deprecated.
600
-
601
- * Dataset#disable_insert_returning on PostgreSQL is now deprecated.
602
- Starting in 3.35.0, RETURNING will now always be used to get the
603
- primary key value when inserting.
604
-
605
- * Array#all_two_pairs? is now deprecated. It was part of the core
606
- extensions, but the core extensions have been refactored to no
607
- longer require it. As it doesn't specifically relate to creating
608
- Sequel expression objects, it is being removed. The private
609
- Array#sql_expr_if_all_two_pairs method is deprecated as well.
610
-
611
- = Other Backwards Compatibility Issues
612
-
613
- * The generic Bignum type now uses bigint on SQLite, similar to
614
- other databases. The integer type was previously used. The only
615
- exception is for auto incrementing primary keys, which still use
616
- integer for Bignum as SQLite doesn't support autoincrementing
617
- columns other than integer.
618
-
619
- * On SQLite, Dataset#explain now returns a string, similar to
620
- PostgreSQL (and now MySQL).
621
-
622
- * When using the JDBC adapter, Java::OrgPostgresqlUtil::PGobject
623
- objects are converted to ruby strings if the dataset is set to
624
- convert types (the default setting). This is to support the
625
- hstore extension, but it could have unforeseen effects if custom
626
- types were used.
627
-
628
- * For PostgreSQL connection objects, #primary_key and #sequence now
629
- require their arguments are provided as already literalized
630
- strings. Note that these methods are being removed in the next
631
- version because they will not be needed after PostgreSQL <8.2
632
- support is dropped.
633
-
634
- * Database#uri and #url now return a string or nil, but never raise
635
- an exception. Previously, they would either return a string
636
- or raise an exception.
637
-
638
- * The Model @simple_pk and @simple_table instance variables should
639
- no longer be modified directly. Instead, the setter methods should
640
- be used.
641
-
642
- * Model.primary_key_lookup should no longer be called with a nil
643
- value.
644
-
645
- * Logging of prepared statements on some adapters has been changed
646
- slightly, so log parsers might need to be updated.
647
-
648
- * Dataset#identifier_append and #table_ref_append no longer treat
649
- literal strings and blobs specially. Previously, they were treated
650
- as identifiers.
651
-
652
- * Dataset#qualified_identifier_sql_append now takes 3 arguments, so
653
- any extensions that override it should be modified accordingly.
654
-
655
- * Some internally used constants and private methods have been
656
- deleted:
657
-
658
- Database::CASCADE
659
- Database::NO_ACTION
660
- Database::SET_DEFAULTS
661
- Database::SET_NULL
662
- Database::RESTRICT
663
- Dataset::COLUMN_ALL
664
-
665
- or moved:
666
-
667
- MySQL::Dataset::AFFECTED_ROWS_RE -> MySQL::Database
668
- MySQL::Dataset#affected_rows -> MySQL::Database
669
-
670
- * The sql_expr extension no longer creates the
671
- Sequel::SQL::GenericComplexExpression class.