sequel 4.26.0 → 4.29.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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +62 -0
  3. data/README.rdoc +4 -4
  4. data/bin/sequel +8 -0
  5. data/doc/opening_databases.rdoc +5 -7
  6. data/doc/postgresql.rdoc +13 -0
  7. data/doc/release_notes/4.27.0.txt +78 -0
  8. data/doc/release_notes/4.28.0.txt +57 -0
  9. data/doc/release_notes/4.29.0.txt +41 -0
  10. data/doc/thread_safety.rdoc +1 -1
  11. data/doc/transactions.rdoc +4 -1
  12. data/doc/validations.rdoc +1 -1
  13. data/lib/sequel/adapters/jdbc/postgresql.rb +1 -1
  14. data/lib/sequel/adapters/oracle.rb +1 -1
  15. data/lib/sequel/adapters/postgres.rb +9 -3
  16. data/lib/sequel/adapters/shared/postgres.rb +2 -2
  17. data/lib/sequel/adapters/sqlanywhere.rb +3 -3
  18. data/lib/sequel/core.rb +8 -18
  19. data/lib/sequel/database/query.rb +7 -2
  20. data/lib/sequel/database/schema_generator.rb +17 -4
  21. data/lib/sequel/database/transactions.rb +3 -3
  22. data/lib/sequel/dataset/actions.rb +38 -9
  23. data/lib/sequel/dataset/sql.rb +8 -3
  24. data/lib/sequel/extensions/date_arithmetic.rb +3 -0
  25. data/lib/sequel/extensions/pg_json_ops.rb +58 -5
  26. data/lib/sequel/extensions/schema_dumper.rb +12 -1
  27. data/lib/sequel/model/base.rb +32 -16
  28. data/lib/sequel/plugins/active_model.rb +7 -0
  29. data/lib/sequel/plugins/before_after_save.rb +48 -0
  30. data/lib/sequel/plugins/boolean_subsets.rb +56 -0
  31. data/lib/sequel/plugins/csv_serializer.rb +1 -1
  32. data/lib/sequel/plugins/defaults_setter.rb +8 -4
  33. data/lib/sequel/plugins/json_serializer.rb +25 -4
  34. data/lib/sequel/plugins/list.rb +9 -9
  35. data/lib/sequel/plugins/subset_conditions.rb +36 -0
  36. data/lib/sequel/plugins/uuid.rb +72 -0
  37. data/lib/sequel/version.rb +1 -1
  38. data/spec/adapters/postgres_spec.rb +11 -1
  39. data/spec/bin_spec.rb +4 -0
  40. data/spec/core/database_spec.rb +35 -0
  41. data/spec/core/dataset_spec.rb +34 -0
  42. data/spec/core/schema_generator_spec.rb +13 -0
  43. data/spec/core/schema_spec.rb +17 -0
  44. data/spec/extensions/active_model_spec.rb +70 -108
  45. data/spec/extensions/before_after_save_spec.rb +40 -0
  46. data/spec/extensions/boolean_subsets_spec.rb +47 -0
  47. data/spec/extensions/date_arithmetic_spec.rb +17 -0
  48. data/spec/extensions/json_serializer_spec.rb +7 -0
  49. data/spec/extensions/list_spec.rb +11 -0
  50. data/spec/extensions/pg_json_ops_spec.rb +46 -0
  51. data/spec/extensions/schema_dumper_spec.rb +18 -0
  52. data/spec/extensions/subset_conditions_spec.rb +38 -0
  53. data/spec/extensions/uuid_spec.rb +106 -0
  54. data/spec/integration/dataset_test.rb +14 -0
  55. data/spec/integration/prepared_statement_test.rb +3 -3
  56. data/spec/integration/schema_test.rb +7 -1
  57. data/spec/integration/transaction_test.rb +22 -0
  58. data/spec/model/class_dataset_methods_spec.rb +4 -0
  59. data/spec/model/model_spec.rb +1 -1
  60. data/spec/model/record_spec.rb +7 -1
  61. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf4997b7f0149580e9838f7a7c1d0802ce9fdd6b
4
- data.tar.gz: 21d723dcf70b74e58a194e71c0d1fb31a6775917
3
+ metadata.gz: f1baf17a3ed5aedeadf0002e4e68ac8e2e27bdc2
4
+ data.tar.gz: 9ceec8f5898df4025b6cf5239f461dee5595ebeb
5
5
  SHA512:
6
- metadata.gz: 851a0cbbd200cffc7280a35168450fcfdb690af48b21c5adf6864289df9fa8eb2b7e7999b396598d0bf3db371e1e721db896bdb869288aa79b8d5db36467b2ed
7
- data.tar.gz: 806d66ebf5e196040b42bc023dc2ac13a374037df98e419cc1db69bc2a52c10cd4bae8e6e22c79681ed27256fbba81e109d3a0a593ae62831d3f0cd827c6e2f8
6
+ metadata.gz: a2c9116e35e8ff8a536530cff484f2d82fac1916db18d8d4b4666359c6ce1f6a67aeb855feb173128f874a179bc75ef10a22bd326ecf48ad6c3cfbe6f3f3b8d3
7
+ data.tar.gz: 07d8ee3fb38aeae9caa9344756826a7e43fa19bd5786948525b427e9d64c3714ee06d452299b310bb7d30666e16ee0af64f663de7bb9a3dbd3b2fd0f2c5255dd
data/CHANGELOG CHANGED
@@ -1,3 +1,65 @@
1
+ === 4.29.0 (2015-12-01)
2
+
3
+ * Add Model#json_serializer_opts method to json_serializer plugin, allowing for setting to_json defaults on per-instance basis (jeremyevans)
4
+
5
+ * Add uuid plugin for automatically setting UUID column when creating a model object (pdrakeweb, jeremyevans) (#1106)
6
+
7
+ * Allow the sqlanywhere adapter to work with sharding (jeremyevans)
8
+
9
+ * Support blobs as bound variables in the oracle adapter (jeremyevans) (#1104)
10
+
11
+ * Order by best results first when using the Database#full_text_search :rank option on PostgreSQL (chanks) (#1101)
12
+
13
+ * Run Database#table_exists? inside a savepoint if currently in a transaction and the database supports savepoints (jeremyevans) (#1100)
14
+
15
+ * Allow Database#transaction :retry_on option to work when using savepoints (jeremyevans)
16
+
17
+ * Allow for external adapters to implement Dataset#date_add_sql_append to integrate with the date_arithmetic extension (jeremyevans)
18
+
19
+ * Add Dataset#insert_empty_columns_values private method for easy overriding for databases that don't support INSERT with DEFAULT VALUES (jeremyevans)
20
+
21
+ === 4.28.0 (2015-11-02)
22
+
23
+ * Add boolean_subsets plugin, which adds a subset for each boolean column (jeremyevans)
24
+
25
+ * Add subset_conditions plugin, which adds a method for each subset returning the filter conditions for the subset (jeremyevans)
26
+
27
+ * Make the list plugin work better with the auto_validations plugin when there is a validation on the position column (jeremyevans)
28
+
29
+ * Make to_csv for model datasets call instance methods, just like Model#to_csv, in the csv_serializer plugin (skrobul) (#1088)
30
+
31
+ * Raise Sequel::NoExistingObject instead of generic error if Model#refresh can't find the related row (jeremyevans)
32
+
33
+ === 4.27.0 (2015-10-01)
34
+
35
+ * Don't stub Sequel.synchronize on MRI (YorickPeterse) (#1083)
36
+
37
+ * Make bin/sequel warn if given arguments that it doesn't use (jeremyevans)
38
+
39
+ * Fix the order of referenced composite keys returned by Database#foreign_key_list on PostgreSQL (jeremyevans) (#1081)
40
+
41
+ * Recognize another disconnect error in the jdbc/postgresql adapter (jeremyevans)
42
+
43
+ * In the active model plugin, make Model#persisted? return false if the transaction used for creation is rolled back (jeremyevans) (#1076)
44
+
45
+ * Use primary_key :keep_order option in the schema dumper if the auto incrementing column is not the first column in the table (jeremyevans)
46
+
47
+ * Set :auto_increment option correctly in the schema parser when the auto incrementing column is not the first column in the table (jeremyevans)
48
+
49
+ * Support :keep_order option to primary_key in schema generator, to not automatically make the primary key the first column (jeremyevans)
50
+
51
+ * Add new jsonb/json functions and operators supported in PostgreSQL 9.5+ (jeremyevans)
52
+
53
+ * Add before_after_save plugin, for refreshing created objects and resetting modified flag before calling after_create/update/save hooks (jeremyevans)
54
+
55
+ * Add Dataset#single_record! and #single_value! which don't require cloning the receiver (jeremyevans)
56
+
57
+ * Dataset#with_sql_single_value now works correctly for model datasets (jeremyevans)
58
+
59
+ * Optimize Dataset#single_value and #with_sql_single_value to not create an unnecessary array (jeremyevans)
60
+
61
+ * Make postgres adapter work with postgres-pr 0.7.0 (jeremyevans) (#1074)
62
+
1
63
  === 4.26.0 (2015-09-01)
2
64
 
3
65
  * Make Dataset#== not consider frozen status in determining equality (jeremyevans)
data/README.rdoc CHANGED
@@ -44,7 +44,7 @@ If you have any comments or suggestions please post to the Google group.
44
44
 
45
45
  require 'sequel'
46
46
 
47
- DB = Sequel.sqlite # memory database
47
+ DB = Sequel.sqlite # memory database, requires sqlite3
48
48
 
49
49
  DB.create_table :items do
50
50
  primary_key :id
@@ -109,11 +109,11 @@ Or getting results as a hash via +to_hash+, with one column as key and another a
109
109
  To connect to a database you simply provide <tt>Sequel.connect</tt> with a URL:
110
110
 
111
111
  require 'sequel'
112
- DB = Sequel.connect('sqlite://blog.db')
112
+ DB = Sequel.connect('sqlite://blog.db') # requires sqlite3
113
113
 
114
114
  The connection URL can also include such stuff as the user name, password, and port:
115
115
 
116
- DB = Sequel.connect('postgres://user:password@host:port/database_name')
116
+ DB = Sequel.connect('postgres://user:password@host:port/database_name') # requires pg
117
117
 
118
118
  You can also specify optional parameters, such as the connection pool size, or loggers for logging SQL queries:
119
119
 
@@ -267,7 +267,7 @@ issues that you should be aware of when using Sequel.
267
267
 
268
268
  Counting records is easy using +count+:
269
269
 
270
- posts.where(:category.like('%ruby%')).count
270
+ posts.where(Sequel.like(:category, '%ruby%')).count
271
271
  # SELECT COUNT(*) FROM posts WHERE category LIKE '%ruby%'
272
272
 
273
273
  And you can also query maximum/minimum values via +max+ and +min+:
data/bin/sequel CHANGED
@@ -116,6 +116,9 @@ error_proc = lambda do |msg|
116
116
  $stderr.puts(msg)
117
117
  exit 1
118
118
  end
119
+ extra_proc = lambda do
120
+ $stderr.puts("Warning: last #{ARGV.length} arguments ignored") unless ARGV.empty?
121
+ end
119
122
 
120
123
  error_proc["Error: Must specify -m if using -M"] if migrate_ver && !migrate_dir
121
124
  error_proc["Error: Cannot specify #{exclusive_options.map{|v| "-#{v}"}.join(' and ')} together"] if exclusive_options.length > 1
@@ -151,16 +154,19 @@ begin
151
154
  DB = connect_proc[db]
152
155
  load_dirs.each{|d| d.is_a?(Array) ? require(d.first) : Dir["#{d}/**/*.rb"].each{|f| load(f)}}
153
156
  if migrate_dir
157
+ extra_proc.call
154
158
  Sequel.extension :migration, :core_extensions
155
159
  Sequel::Migrator.apply(DB, migrate_dir, migrate_ver)
156
160
  exit
157
161
  end
158
162
  if dump_migration
163
+ extra_proc.call
159
164
  DB.extension :schema_dumper
160
165
  puts DB.dump_schema_migration(:same_db=>dump_migration==:same_db)
161
166
  exit
162
167
  end
163
168
  if dump_schema
169
+ extra_proc.call
164
170
  DB.extension :schema_caching
165
171
  DB.tables.each{|t| DB.schema(Sequel::SQL::Identifier.new(t))}
166
172
  DB.dump_schema_cache(dump_schema)
@@ -172,6 +178,7 @@ begin
172
178
 
173
179
  db2 = ARGV.shift
174
180
  error_proc["Error: Must specify database connection string or path to yaml file as second argument for database you want to copy to"] if db2.nil? || db2.empty?
181
+ extra_proc.call
175
182
  start_time = Time.now
176
183
  TO_DB = connect_proc[db2]
177
184
  same_db = DB.database_type==TO_DB.database_type
@@ -225,6 +232,7 @@ begin
225
232
  exit
226
233
  end
227
234
  if code
235
+ extra_proc.call
228
236
  eval(code)
229
237
  exit
230
238
  end
@@ -269,12 +269,8 @@ The following additional options are supported:
269
269
  === mysql2
270
270
 
271
271
  This is a newer MySQL adapter that does typecasting in C, so it is often faster than the
272
- mysql adapter. Supports the same additional options as the mysql adapter, except for :compress, and uses
273
- :timeout instead of :read_timeout and :connect_timeout.
274
-
275
- The following additional options are supported:
276
-
277
- :flags :: Override the flags to use for the connection (e.g. ::Mysql2::Client::MULTI_STATEMENTS)
272
+ mysql adapter. The options given are passed to Mysql2::Client.new, see the mysql2 documentation
273
+ for details on what options are supported.
278
274
 
279
275
  === odbc
280
276
 
@@ -309,7 +305,9 @@ The Sequel postgres adapter works with the pg, postgres, and postgres-pr ruby li
309
305
  The pg library is the best supported, as it supports real bound variables and prepared statements.
310
306
  If the pg library is being used, Sequel will also attempt to load the sequel_pg library, which is
311
307
  a C extension that optimizes performance when Sequel is used with pg. All users of Sequel who
312
- use pg are encouraged to install sequel_pg.
308
+ use pg are encouraged to install sequel_pg. For users who want to use postgres-pr to avoid issues
309
+ with C extensions, it is recommended to use jeremyevans-postgres-pr, which fixes many issues in
310
+ the upstream postgres-pr gem, and is regularly tested with Sequel.
313
311
 
314
312
  The following additional options are supported:
315
313
 
data/doc/postgresql.rdoc CHANGED
@@ -185,6 +185,19 @@ When returning is used, instead of returning the number of rows affected (for up
185
185
  or the serial primary key value (for insert), it will return an array of hashes with the
186
186
  returned results.
187
187
 
188
+ === VALUES Support
189
+
190
+ Sequel offers support for the +VALUES+ statement using <tt>Database#values</tt>:
191
+
192
+ DB.values([[1,2],[2,3],[3,4]])
193
+ # VALUES (1, 2), (2, 3), (3, 4)
194
+
195
+ DB.values([[1,2],[2,3],[3,4]]).order(2, 1)
196
+ # VALUES (1, 2), (2, 3), (3, 4) ORDER BY 2, 1
197
+
198
+ DB.values([[1,2],[2,3],[3,4]]).order(2, 1).limit(1,2)
199
+ # VALUES (1, 2), (2, 3), (3, 4) ORDER BY 2, 1 LIMIT 1 OFFSET 2
200
+
188
201
  === INSERT ON CONFLICT Support
189
202
 
190
203
  Starting with PostgreSQL 9.5, you can do an upsert or ignore unique or exclusion constraint
@@ -0,0 +1,78 @@
1
+ = New Features
2
+
3
+ * A before_after_save plugin has been added, which for newly
4
+ created objects refreshes the object before calling after_create,
5
+ and resets the modified flag before calling after_update.
6
+ Previously, these actions were not taken until after after_save
7
+ was called. This will be the default behavior in Sequel 5.
8
+
9
+ * In create_table blocks, primary_key now supports a :keep_order
10
+ option, which will not change the order in which the primary key
11
+ is added. Without this option, Sequel's historical behavior of
12
+ making the primary key column the first column is used.
13
+
14
+ DB.create_table(:foo) do
15
+ Integer :a
16
+ primary_key :b, :keep_order=>true
17
+ end
18
+ # CREATE TABLE foo
19
+ # (a integer, b integer PRIMARY KEY AUTOINCREMENT)
20
+
21
+ The schema dumper now uses this option if necessary, allowing it
22
+ to correctly dump tables where the primary key column is not the
23
+ first column.
24
+
25
+ * Dataset#single_record! and #single_value! have been added. These
26
+ are faster versions of #single_record and #single_value that
27
+ don't require cloning the dataset. If you are sure the dataset
28
+ will only return a single row or a single value, you can use
29
+ these methods for better performance.
30
+
31
+ * The new jsonb and json functions added in PostgreSQL 9.5 are now
32
+ supported by the pg_json_ops extension.
33
+
34
+ Sequel.pg_jsonb_op(:metadata).set(%w'a b', [1,2,3])
35
+ # jsonb_set("metadata", ARRAY['a','b'], '[1,2,3]'::jsonb, true)
36
+
37
+ = Other Improvements
38
+
39
+ * Sequel.synchronize is no longer a stub on MRI. Testing has shown
40
+ that relying on the global interpreter lock to protect
41
+ multi-threaded access to hashes is not safe in all environments,
42
+ so Sequel now uses a mutex on MRI just as it does on other ruby
43
+ interpreters.
44
+
45
+ * Database#schema now sets the :auto_increment option correctly for
46
+ auto incrementing primary keys if they are not the first column
47
+ in the table.
48
+
49
+ * Dataset#single_value and #with_sql_single_value are now slightly
50
+ faster by avoiding an array allocation.
51
+
52
+ * Model datasets can now use #with_sql_single_value and return a
53
+ single value, instead of an array in [:column_name, value] format.
54
+
55
+ * Model#persisted? in the active_model plugin will now return false
56
+ if the transaction that inserts the row for the object is rolled
57
+ back.
58
+
59
+ * bin/sequel now warns if additional arguments are passed that it
60
+ ignores. In Sequel 5, bin/sequel will raise an error in these
61
+ cases.
62
+
63
+ * Database#foreign_key_list on PostgreSQL now returns referenced
64
+ composite keys in the correct order.
65
+
66
+ * The postgres adapter now works with postgres-pr 0.7.0. Note that
67
+ postgres adapter users that want a pure-ruby driver are encouraged
68
+ to use jeremyevans-postgres-pr as that has many additional bugfixes
69
+ and is the version tested with Sequel on a regular basis.
70
+
71
+ * The jdbc/postgresql adapter now recognizes an additional disconnect
72
+ error.
73
+
74
+ = Backwards Compatibility
75
+
76
+ * Users who were relying on #with_sql_single_value returning an array
77
+ instead of a single value for model datasets need to update their
78
+ code.
@@ -0,0 +1,57 @@
1
+ = New Features
2
+
3
+ * A subset_conditions plugin has been added, which adds a method
4
+ for each subset that returns the filter conditions for the
5
+ subset. This makes it easier to reuse the subset conditions:
6
+
7
+ class Foo < Sequel::Model
8
+ plugin :subset_conditions
9
+ subset :active, :active=>true
10
+ end
11
+
12
+ Foo.exclude(Foo.active_conditions)
13
+ Foo.where(:a=>1).or(Foo.active_conditions)
14
+
15
+ * A boolean_subsets plugin has been added, which adds a subset for each
16
+ boolean column:
17
+
18
+ # Assume boolean column :active
19
+ Foo.plugin :boolean_subsets
20
+
21
+ Foo.active
22
+ # SELECT * FROM foos WHERE (active IS TRUE)
23
+
24
+ You can provide a block to the plugin to change the arguments passed
25
+ to subset:
26
+
27
+ Foo.plugin :boolean_subsets do |column|
28
+ [:"where_#{column}", column]
29
+ end
30
+
31
+ Foo.where_active
32
+ # SELECT * FROM foos WHERE active
33
+
34
+ As with similar plugins, you can add the boolean_subsets plugin to
35
+ Sequel::Model itself, and all subclasses created afterward will have
36
+ the boolean subset methods automatically created.
37
+
38
+ = Other Improvements
39
+
40
+ * If Model#refresh can't find the related row, Sequel now raises a
41
+ Sequel::NoExistingObject exception instead of a generic
42
+ Sequel::Error exception.
43
+
44
+ * In the csv_serializer plugin, when calling #to_csv on a model class
45
+ or dataset, instead of using #[] to access data, #send is used to
46
+ call methods. This is more similar to other plugins as well as
47
+ Model#to_csv.
48
+
49
+ * The list plugin now works better with the auto_validations plugin,
50
+ or any other time there is a validation on the position column.
51
+
52
+ = Backwards Compatibility
53
+
54
+ * The change to the csv_serializer plugin can change results if you
55
+ are overriding any of the column accessor methods. It can also
56
+ break existing code if one of the columns being used isn't defined
57
+ as a method or the method requires more than one argument.
@@ -0,0 +1,41 @@
1
+ = New Features
2
+
3
+ * A uuid plugin has now been added. This plugin will automatically
4
+ create a uuid for newly created model objects.
5
+
6
+ Model.plugin :uuid
7
+ Model.create.uuid => # some UUID
8
+
9
+ * Model#json_serializer_opts has been added to the json_serializer
10
+ plugin, allowing you to override the JSON serialization options
11
+ on a per instance basis without passing the options directly
12
+ to Model#to_json. This is useful if you are including the model
13
+ instance inside another datastructure that will be serialized
14
+ to JSON.
15
+
16
+ obj.json_serializer_opts(:root => true)
17
+ [obj].to_json
18
+ # => '[{"obj":{"id":1,"name":"Foo"}}]'
19
+
20
+ = Other Improvements
21
+
22
+ * The Database#transaction :retry_on option now works when using
23
+ savepoints.
24
+
25
+ * Calling Database#table_exists? inside a transaction will now use
26
+ a savepoint if the database supports it, so that if the table
27
+ doesn't exist, it will not affect the state of the transaction.
28
+
29
+ * Blobs can now be used as bound variables in the oracle adapter.
30
+
31
+ * The sqlanywhere adapter now works with database sharding.
32
+
33
+ * The Dataset#full_text_search :rank option has been fixed to order
34
+ by rank descending instead of ascending.
35
+
36
+ * External adapters that do not support INSERT with DEFAULT VALUES
37
+ can now override Dataset#insert_empty_columns_values to set
38
+ the columns and values to use for an empty INSERT.
39
+
40
+ * External adapters can now implement Dataset#date_add_sql_append
41
+ to integrate with the date_arithmetic extension.
@@ -4,7 +4,7 @@ Most Sequel usage (and all common Sequel usage) is thread safe by default. Spec
4
4
 
5
5
  == Connection Pool
6
6
 
7
- In order to allow multiple threads to operate on the same database at the same time, Sequel uses a connection pool. The connection pool is designed so that a thread uses a connection for the minimum amount of time, returning the connection to the pool as soon as it is done using the connection. If a thread requests a connection and the pool does not have an available connection, a new connection will be created. If the maximum number of connections in the pool has already been reached, the thread will block (actually busy-wait) until a connection is available or the connection pool timeout has elapsed (in which case a PoolTimeout error will be raised).
7
+ In order to allow multiple threads to operate on the same database at the same time, Sequel uses a connection pool. The connection pool is designed so that a thread uses a connection for the minimum amount of time, returning the connection to the pool as soon as it is done using the connection. If a thread requests a connection and the pool does not have an available connection, a new connection will be created. If the maximum number of connections in the pool has already been reached, the thread will block until a connection is available or the connection pool timeout has elapsed (in which case a PoolTimeout error will be raised).
8
8
 
9
9
  == Exceptions
10
10
 
@@ -6,7 +6,10 @@ Sequel uses autocommit mode by default for all of its database adapters, so in g
6
6
  * Model#save
7
7
  * Model#destroy
8
8
  * Migrations if the database supports transactional schema
9
- * A few model plugins
9
+ * Database#use_cursor in the postgres adapter
10
+ * Dataset#lock on PostgreSQL if given a block
11
+ * setter methods created by the association_pks plugin
12
+ * move* methods in the list plugin
10
13
 
11
14
  Everywhere else, it is up to you to use a database transaction if you want to.
12
15
 
data/doc/validations.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = Model Validations
2
2
 
3
- This guide is based on http://guides.rubyonrails.org/activerecord_validations_callbacks.html
3
+ This guide is based on http://guides.rubyonrails.org/active_record_validations.html
4
4
 
5
5
  == Overview
6
6
 
@@ -135,7 +135,7 @@ module Sequel
135
135
  end
136
136
 
137
137
  def disconnect_error?(exception, opts)
138
- super || exception.message =~ /\AThis connection has been closed\.\z|\AFATAL: terminating connection due to administrator command\z/
138
+ super || exception.message =~ /\A(This connection has been closed\.|FATAL: terminating connection due to administrator command|An I\/O error occurred while sending to the backend\.)\z/
139
139
  end
140
140
 
141
141
  # Use setNull for nil arguments as the default behavior of setString
@@ -122,7 +122,7 @@ module Sequel
122
122
  when BigDecimal
123
123
  arg = arg.to_f
124
124
  when ::Sequel::SQL::Blob
125
- raise Error, "Sequel's oracle adapter does not currently support using a blob in a bound variable"
125
+ arg = ::OCI8::BLOB.new(conn, arg)
126
126
  end
127
127
  if t = PS_TYPES[type]
128
128
  cursor.bind_param(i, arg, t)
@@ -2,6 +2,10 @@ Sequel.require 'adapters/shared/postgres'
2
2
 
3
3
  begin
4
4
  require 'pg'
5
+
6
+ # Work around postgres-pr 0.7.0+ which ships with a pg.rb file
7
+ raise LoadError unless defined?(PGconn::CONNECTION_OK)
8
+
5
9
  SEQUEL_POSTGRES_USES_PG = true
6
10
  rescue LoadError => e
7
11
  SEQUEL_POSTGRES_USES_PG = false
@@ -670,9 +674,11 @@ module Sequel
670
674
  end
671
675
 
672
676
  # Uses a cursor for fetching records, instead of fetching the entire result
673
- # set at once. Can be used to process large datasets without holding
674
- # all rows in memory (which is what the underlying drivers may do
675
- # by default). Options:
677
+ # set at once. Note this uses a transaction around the cursor usage by
678
+ # default and can be changed using `hold: true` as described below.
679
+ # Cursors can be used to process large datasets without holding all rows
680
+ # in memory (which is what the underlying drivers may do by default).
681
+ # Options:
676
682
  #
677
683
  # :cursor_name :: The name assigned to the cursor (default 'sequel_cursor').
678
684
  # Nested cursors require different names.
@@ -308,7 +308,7 @@ module Sequel
308
308
  ref_ds = base_ds.
309
309
  join(:pg_class___cl2, :oid=>:co__confrelid).
310
310
  join(:pg_attribute___att2, :attrelid=>:oid, :attnum=>SQL::Function.new(:ANY, :co__confkey)).
311
- order(:co__conname, SQL::CaseExpression.new(range.map{|x| [SQL::Subscript.new(:co__conkey, [x]), x]}, 32, :att2__attnum)).
311
+ order(:co__conname, SQL::CaseExpression.new(range.map{|x| [SQL::Subscript.new(:co__confkey, [x]), x]}, 32, :att2__attnum)).
312
312
  select(:co__conname___name, :cl2__relname___table, :att2__attname___refcolumn)
313
313
 
314
314
  # If a schema is given, we only search in that schema, and the returned :table
@@ -1331,7 +1331,7 @@ module Sequel
1331
1331
  end
1332
1332
 
1333
1333
  if opts[:rank]
1334
- ds = ds.order{ts_rank_cd(cols, terms)}
1334
+ ds = ds.reverse{ts_rank_cd(cols, terms)}
1335
1335
  end
1336
1336
 
1337
1337
  ds
@@ -79,19 +79,19 @@ module Sequel
79
79
 
80
80
  # Returns number of rows affected
81
81
  def execute_dui(sql, opts=OPTS)
82
- synchronize do |conn|
82
+ synchronize(opts[:server]) do |conn|
83
83
  _execute(conn, :rows, sql, opts)
84
84
  end
85
85
  end
86
86
 
87
87
  def execute(sql, opts=OPTS, &block)
88
- synchronize do |conn|
88
+ synchronize(opts[:server]) do |conn|
89
89
  _execute(conn, :select, sql, opts, &block)
90
90
  end
91
91
  end
92
92
 
93
93
  def execute_insert(sql, opts=OPTS)
94
- synchronize do |conn|
94
+ synchronize(opts[:server]) do |conn|
95
95
  _execute(conn, :insert, sql, opts)
96
96
  end
97
97
  end
data/lib/sequel/core.rb CHANGED
@@ -293,24 +293,14 @@ module Sequel
293
293
  end
294
294
  end
295
295
 
296
- if defined?(RUBY_ENGINE) && RUBY_ENGINE != 'ruby'
297
- # :nocov:
298
- # Mutex used to protect mutable data structures
299
- @data_mutex = Mutex.new
300
-
301
- # Unless in single threaded mode, protects access to any mutable
302
- # global data structure in Sequel.
303
- # Uses a non-reentrant mutex, so calling code should be careful.
304
- def self.synchronize(&block)
305
- @single_threaded ? yield : @data_mutex.synchronize(&block)
306
- end
307
- # :nocov:
308
- else
309
- # Yield directly to the block. You don't need to synchronize
310
- # access on MRI because the GVL makes certain methods atomic.
311
- def self.synchronize
312
- yield
313
- end
296
+ # Mutex used to protect mutable data structures
297
+ @data_mutex = Mutex.new
298
+
299
+ # Unless in single threaded mode, protects access to any mutable
300
+ # global data structure in Sequel.
301
+ # Uses a non-reentrant mutex, so calling code should be careful.
302
+ def self.synchronize(&block)
303
+ @single_threaded ? yield : @data_mutex.synchronize(&block)
314
304
  end
315
305
 
316
306
  # Uses a transaction on all given databases with the given options. This:
@@ -161,7 +161,7 @@ module Sequel
161
161
 
162
162
  primary_keys = 0
163
163
  auto_increment_set = false
164
- cols.all? do |_,c|
164
+ cols.each do |_,c|
165
165
  auto_increment_set = true if c.has_key?(:auto_increment)
166
166
  primary_keys += 1 if c[:primary_key]
167
167
  end
@@ -191,7 +191,12 @@ module Sequel
191
191
  def table_exists?(name)
192
192
  sch, table_name = schema_and_table(name)
193
193
  name = SQL::QualifiedIdentifier.new(sch, table_name) if sch
194
- _table_exists?(from(name))
194
+ ds = from(name)
195
+ if in_transaction? && supports_savepoints?
196
+ transaction(:savepoint=>true){_table_exists?(ds)}
197
+ else
198
+ _table_exists?(ds)
199
+ end
195
200
  true
196
201
  rescue DatabaseError
197
202
  false
@@ -236,22 +236,35 @@ module Sequel
236
236
  #
237
237
  # If an array of column symbols is used, you can specify the :name option
238
238
  # to name the constraint.
239
+ #
240
+ # Options:
241
+ # :keep_order :: For non-composite primary keys, respects the existing order of
242
+ # columns, overriding the default behavior of making the primary
243
+ # key the first column.
239
244
  #
240
245
  # Examples:
241
246
  # primary_key(:id)
247
+ # primary_key(:id, Bigint)
248
+ # primary_key(:id, Bigint, :keep_order=>true)
242
249
  # primary_key([:street_number, :house_number], :name=>:some constraint_name)
243
250
  def primary_key(name, *args)
244
251
  return composite_primary_key(name, *args) if name.is_a?(Array)
245
- @primary_key = @db.serial_primary_key_options.merge({:name => name})
252
+ column = @db.serial_primary_key_options.merge({:name => name})
246
253
 
247
254
  if opts = args.pop
248
255
  opts = {:type => opts} unless opts.is_a?(Hash)
249
256
  if type = args.pop
250
- opts.merge!(:type => type)
257
+ opts = opts.merge(:type => type)
251
258
  end
252
- @primary_key.merge!(opts)
259
+ column.merge!(opts)
260
+ end
261
+
262
+ @primary_key = column
263
+ if column[:keep_order]
264
+ columns << column
265
+ else
266
+ columns.unshift(column)
253
267
  end
254
- @primary_key
255
268
  end
256
269
 
257
270
  # The name of the primary key for this generator, if it has a primary key.
@@ -96,12 +96,12 @@ module Sequel
96
96
  else
97
97
  synchronize(opts[:server]) do |conn|
98
98
  if already_in_transaction?(conn, opts)
99
- if opts[:retrying]
100
- raise Sequel::Error, "cannot set :retry_on options if you are already inside a transaction"
101
- end
102
99
  if opts[:savepoint] != false && (stack = _trans(conn)[:savepoints]) && stack.last
103
100
  _transaction(conn, Hash[opts].merge!(:savepoint=>true), &block)
104
101
  else
102
+ if opts[:retrying]
103
+ raise Sequel::Error, "cannot set :retry_on options if you are already inside a transaction"
104
+ end
105
105
  return yield(conn)
106
106
  end
107
107
  else