sequel 5.58.0 → 5.78.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +288 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +24 -23
- data/bin/sequel +11 -3
- data/doc/advanced_associations.rdoc +16 -14
- data/doc/association_basics.rdoc +53 -17
- data/doc/cheat_sheet.rdoc +3 -3
- data/doc/mass_assignment.rdoc +1 -1
- data/doc/migration.rdoc +15 -0
- data/doc/model_hooks.rdoc +1 -1
- data/doc/object_model.rdoc +8 -8
- data/doc/opening_databases.rdoc +20 -12
- data/doc/postgresql.rdoc +8 -8
- data/doc/querying.rdoc +1 -1
- data/doc/release_notes/5.59.0.txt +73 -0
- data/doc/release_notes/5.60.0.txt +22 -0
- data/doc/release_notes/5.61.0.txt +43 -0
- data/doc/release_notes/5.62.0.txt +132 -0
- data/doc/release_notes/5.63.0.txt +33 -0
- data/doc/release_notes/5.64.0.txt +50 -0
- data/doc/release_notes/5.65.0.txt +21 -0
- data/doc/release_notes/5.66.0.txt +24 -0
- data/doc/release_notes/5.67.0.txt +32 -0
- data/doc/release_notes/5.68.0.txt +61 -0
- data/doc/release_notes/5.69.0.txt +26 -0
- data/doc/release_notes/5.70.0.txt +35 -0
- data/doc/release_notes/5.71.0.txt +21 -0
- data/doc/release_notes/5.72.0.txt +33 -0
- data/doc/release_notes/5.73.0.txt +66 -0
- data/doc/release_notes/5.74.0.txt +45 -0
- data/doc/release_notes/5.75.0.txt +35 -0
- data/doc/release_notes/5.76.0.txt +86 -0
- data/doc/release_notes/5.77.0.txt +63 -0
- data/doc/release_notes/5.78.0.txt +67 -0
- data/doc/schema_modification.rdoc +3 -3
- data/doc/security.rdoc +9 -9
- data/doc/sharding.rdoc +3 -1
- data/doc/sql.rdoc +14 -14
- data/doc/testing.rdoc +16 -12
- data/doc/transactions.rdoc +6 -6
- data/doc/virtual_rows.rdoc +1 -1
- data/lib/sequel/adapters/ibmdb.rb +1 -1
- data/lib/sequel/adapters/jdbc/h2.rb +3 -0
- data/lib/sequel/adapters/jdbc/hsqldb.rb +2 -0
- data/lib/sequel/adapters/jdbc/postgresql.rb +3 -0
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +15 -0
- data/lib/sequel/adapters/jdbc/sqlserver.rb +4 -0
- data/lib/sequel/adapters/jdbc.rb +10 -6
- data/lib/sequel/adapters/mysql.rb +19 -7
- data/lib/sequel/adapters/mysql2.rb +2 -2
- data/lib/sequel/adapters/odbc/mssql.rb +1 -1
- data/lib/sequel/adapters/oracle.rb +1 -0
- data/lib/sequel/adapters/postgres.rb +62 -16
- data/lib/sequel/adapters/shared/access.rb +9 -1
- data/lib/sequel/adapters/shared/db2.rb +12 -0
- data/lib/sequel/adapters/shared/mssql.rb +71 -9
- data/lib/sequel/adapters/shared/mysql.rb +80 -1
- data/lib/sequel/adapters/shared/oracle.rb +17 -7
- data/lib/sequel/adapters/shared/postgres.rb +494 -164
- data/lib/sequel/adapters/shared/sqlanywhere.rb +18 -5
- data/lib/sequel/adapters/shared/sqlite.rb +40 -4
- data/lib/sequel/adapters/sqlite.rb +42 -3
- data/lib/sequel/adapters/trilogy.rb +117 -0
- data/lib/sequel/connection_pool/sharded_threaded.rb +16 -11
- data/lib/sequel/connection_pool/sharded_timed_queue.rb +374 -0
- data/lib/sequel/connection_pool/threaded.rb +14 -8
- data/lib/sequel/connection_pool/timed_queue.rb +270 -0
- data/lib/sequel/connection_pool.rb +57 -31
- data/lib/sequel/database/connecting.rb +25 -1
- data/lib/sequel/database/dataset.rb +16 -6
- data/lib/sequel/database/misc.rb +65 -14
- data/lib/sequel/database/query.rb +72 -1
- data/lib/sequel/database/schema_generator.rb +2 -1
- data/lib/sequel/database/schema_methods.rb +13 -3
- data/lib/sequel/database/transactions.rb +6 -0
- data/lib/sequel/dataset/actions.rb +60 -13
- data/lib/sequel/dataset/deprecated_singleton_class_methods.rb +42 -0
- data/lib/sequel/dataset/features.rb +15 -1
- data/lib/sequel/dataset/misc.rb +12 -2
- data/lib/sequel/dataset/placeholder_literalizer.rb +20 -9
- data/lib/sequel/dataset/query.rb +62 -37
- data/lib/sequel/dataset/sql.rb +58 -36
- data/lib/sequel/dataset.rb +4 -0
- data/lib/sequel/exceptions.rb +5 -0
- data/lib/sequel/extensions/_model_pg_row.rb +0 -12
- data/lib/sequel/extensions/_pretty_table.rb +1 -1
- data/lib/sequel/extensions/any_not_empty.rb +2 -2
- data/lib/sequel/extensions/async_thread_pool.rb +21 -13
- data/lib/sequel/extensions/auto_cast_date_and_time.rb +94 -0
- data/lib/sequel/extensions/auto_literal_strings.rb +1 -1
- data/lib/sequel/extensions/connection_expiration.rb +15 -9
- data/lib/sequel/extensions/connection_validator.rb +16 -11
- data/lib/sequel/extensions/constraint_validations.rb +1 -1
- data/lib/sequel/extensions/date_arithmetic.rb +36 -8
- data/lib/sequel/extensions/duplicate_columns_handler.rb +10 -9
- data/lib/sequel/extensions/index_caching.rb +5 -1
- data/lib/sequel/extensions/is_distinct_from.rb +3 -1
- data/lib/sequel/extensions/looser_typecasting.rb +3 -0
- data/lib/sequel/extensions/migration.rb +65 -15
- data/lib/sequel/extensions/named_timezones.rb +22 -6
- data/lib/sequel/extensions/pg_array.rb +33 -4
- data/lib/sequel/extensions/pg_auto_parameterize.rb +509 -0
- data/lib/sequel/extensions/pg_auto_parameterize_in_array.rb +110 -0
- data/lib/sequel/extensions/pg_enum.rb +1 -2
- data/lib/sequel/extensions/pg_extended_date_support.rb +38 -27
- data/lib/sequel/extensions/pg_extended_integer_support.rb +116 -0
- data/lib/sequel/extensions/pg_hstore.rb +5 -0
- data/lib/sequel/extensions/pg_inet.rb +10 -11
- data/lib/sequel/extensions/pg_interval.rb +10 -11
- data/lib/sequel/extensions/pg_json.rb +10 -10
- data/lib/sequel/extensions/pg_json_ops.rb +52 -0
- data/lib/sequel/extensions/pg_multirange.rb +6 -11
- data/lib/sequel/extensions/pg_range.rb +9 -14
- data/lib/sequel/extensions/pg_row.rb +20 -19
- data/lib/sequel/extensions/pg_timestamptz.rb +27 -3
- data/lib/sequel/extensions/round_timestamps.rb +1 -1
- data/lib/sequel/extensions/schema_caching.rb +1 -1
- data/lib/sequel/extensions/schema_dumper.rb +32 -9
- data/lib/sequel/extensions/server_block.rb +2 -1
- data/lib/sequel/extensions/set_literalizer.rb +58 -0
- data/lib/sequel/extensions/sqlite_json_ops.rb +76 -18
- data/lib/sequel/extensions/symbol_aref.rb +2 -0
- data/lib/sequel/extensions/transaction_connection_validator.rb +78 -0
- data/lib/sequel/model/associations.rb +50 -11
- data/lib/sequel/model/base.rb +45 -21
- data/lib/sequel/model/dataset_module.rb +3 -0
- data/lib/sequel/model/exceptions.rb +15 -3
- data/lib/sequel/plugins/auto_validations.rb +53 -15
- data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
- data/lib/sequel/plugins/column_encryption.rb +27 -6
- data/lib/sequel/plugins/composition.rb +2 -2
- data/lib/sequel/plugins/concurrent_eager_loading.rb +4 -4
- data/lib/sequel/plugins/constraint_validations.rb +8 -5
- data/lib/sequel/plugins/defaults_setter.rb +16 -0
- data/lib/sequel/plugins/dirty.rb +1 -1
- data/lib/sequel/plugins/finder.rb +4 -2
- data/lib/sequel/plugins/list.rb +8 -3
- data/lib/sequel/plugins/many_through_many.rb +1 -1
- data/lib/sequel/plugins/mssql_optimistic_locking.rb +8 -38
- data/lib/sequel/plugins/nested_attributes.rb +4 -4
- data/lib/sequel/plugins/optimistic_locking.rb +9 -42
- data/lib/sequel/plugins/optimistic_locking_base.rb +55 -0
- data/lib/sequel/plugins/paged_operations.rb +181 -0
- data/lib/sequel/plugins/pg_auto_constraint_validations.rb +9 -3
- data/lib/sequel/plugins/pg_xmin_optimistic_locking.rb +109 -0
- data/lib/sequel/plugins/prepared_statements.rb +2 -1
- data/lib/sequel/plugins/prepared_statements_safe.rb +2 -1
- data/lib/sequel/plugins/primary_key_lookup_check_values.rb +154 -0
- data/lib/sequel/plugins/rcte_tree.rb +7 -4
- data/lib/sequel/plugins/require_valid_schema.rb +67 -0
- data/lib/sequel/plugins/single_table_inheritance.rb +8 -0
- data/lib/sequel/plugins/sql_comments.rb +5 -5
- data/lib/sequel/plugins/static_cache.rb +38 -0
- data/lib/sequel/plugins/static_cache_cache.rb +5 -1
- data/lib/sequel/plugins/tactical_eager_loading.rb +21 -14
- data/lib/sequel/plugins/validate_associated.rb +22 -12
- data/lib/sequel/plugins/validation_helpers.rb +29 -2
- data/lib/sequel/plugins/validation_helpers_generic_type_messages.rb +73 -0
- data/lib/sequel/version.rb +1 -1
- metadata +76 -6
data/doc/association_basics.rdoc
CHANGED
@@ -320,11 +320,11 @@ Associations are cached after being retrieved:
|
|
320
320
|
@album.artists # Cached - No Database Query
|
321
321
|
|
322
322
|
You can choose to ignore the cached versions and do a database query to
|
323
|
-
retrieve results by passing a :
|
323
|
+
retrieve results by passing a <tt>reload: true</tt> option to the association method:
|
324
324
|
|
325
325
|
@album.artists # Not cached - Database Query
|
326
326
|
@album.artists # Cached - No Database Query
|
327
|
-
@album.artists(:
|
327
|
+
@album.artists(reload: true) # Ignore cache - Database Query
|
328
328
|
|
329
329
|
If you reload/refresh the object, it will automatically clear the
|
330
330
|
associations cache for the object:
|
@@ -342,6 +342,12 @@ instance method:
|
|
342
342
|
@album.artists # [<Artist ...>, ...]
|
343
343
|
@album.associations[:artists] # [<Artist ...>, ...]
|
344
344
|
|
345
|
+
=== Code Reloading
|
346
|
+
|
347
|
+
When declaring associations, Sequel caches association metadata in the association reflection. If you're doing any code reloading that doesn't involve restarting the related process, you should disable caching of the association reflection, to avoid stale model classes still being referenced after reloading:
|
348
|
+
|
349
|
+
Sequel::Model.cache_associations = false
|
350
|
+
|
345
351
|
== Dataset Method
|
346
352
|
|
347
353
|
In addition to the above methods, associations also add an instance method
|
@@ -532,14 +538,14 @@ Which could be created using the following Sequel code:
|
|
532
538
|
DB.create_table(:artists) do
|
533
539
|
# Primary key must be set explicitly
|
534
540
|
primary_key :id
|
535
|
-
String :name, :
|
541
|
+
String :name, null: false, unique: true
|
536
542
|
end
|
537
543
|
DB.create_table(:albums) do
|
538
544
|
primary_key :id
|
539
545
|
# Table that foreign key references needs to be set explicitly
|
540
546
|
# for a database foreign key reference to be created.
|
541
|
-
foreign_key :artist_id, :artists, :
|
542
|
-
String :name, :
|
547
|
+
foreign_key :artist_id, :artists, null: false
|
548
|
+
String :name, null: false, unique: true
|
543
549
|
end
|
544
550
|
|
545
551
|
If you already had a schema such as:
|
@@ -552,7 +558,7 @@ If you already had a schema such as:
|
|
552
558
|
Then you just need to add the column:
|
553
559
|
|
554
560
|
DB.alter_table(:albums) do
|
555
|
-
add_foreign_key :artist_id, :artists, :
|
561
|
+
add_foreign_key :artist_id, :artists, null: false
|
556
562
|
end
|
557
563
|
|
558
564
|
=== many_to_many
|
@@ -588,11 +594,11 @@ wanted to add an albums_artists join table to create the following schema:
|
|
588
594
|
|
589
595
|
You could use the following Sequel code:
|
590
596
|
|
591
|
-
DB.create_join_table(:
|
597
|
+
DB.create_join_table(album_id: :albums, artist_id: :artists)
|
592
598
|
# or
|
593
599
|
DB.create_table(:albums_artists) do
|
594
|
-
foreign_key :album_id, :albums, :
|
595
|
-
foreign_key :artist_id, :artists, :
|
600
|
+
foreign_key :album_id, :albums, null: false
|
601
|
+
foreign_key :artist_id, :artists, null: false
|
596
602
|
primary_key [:album_id, :artist_id]
|
597
603
|
index [:artist_id, :album_id]
|
598
604
|
end
|
@@ -713,7 +719,7 @@ saving the passed in (or newly created) object. However, to avoid
|
|
713
719
|
silent failures of these methods, they explicitly raise exceptions
|
714
720
|
even when raise_on_save_failure is false for the associated model.
|
715
721
|
You can disable this behavior (i.e. return nil instead of raising
|
716
|
-
exceptions on a save failure) by setting the <tt
|
722
|
+
exceptions on a save failure) by setting the <tt>raise_on_save_failure: false</tt>
|
717
723
|
option for the association.
|
718
724
|
|
719
725
|
=== remove_<i>association</i>(object_to_disassociate) (e.g. remove_album) [+one_to_many+ and +many_to_many+]
|
@@ -858,14 +864,14 @@ You can set this to +nil+ to not create a remove_all_<i>association</i> method.
|
|
858
864
|
|
859
865
|
=== :no_dataset_method
|
860
866
|
|
861
|
-
Setting this to true will
|
867
|
+
Setting this to true will result in the <i>association</i>_dataset method
|
862
868
|
not being defined. This can save memory if you only use the <i>association</i>
|
863
869
|
method and do not call the <i>association</i>_dataset method directly or
|
864
870
|
indirectly.
|
865
871
|
|
866
872
|
=== :no_association_method
|
867
873
|
|
868
|
-
Setting this to true will
|
874
|
+
Setting this to true will result in the <i>association</i> method
|
869
875
|
not being defined. This can save memory if you only use the
|
870
876
|
<i>association</i>_dataset method and do not call the <i>association</i> method
|
871
877
|
directly or indirectly.
|
@@ -981,7 +987,7 @@ If you do not use a hash or array of two element arrays, you should use the
|
|
981
987
|
:graph_conditions, :graph_only_conditions, or :graph_block option or you will not
|
982
988
|
be able to use eager_graph or association_join with the association.
|
983
989
|
|
984
|
-
Artist.one_to_many :good_albums, class: :Album, conditions: {:
|
990
|
+
Artist.one_to_many :good_albums, class: :Album, conditions: {good: true}
|
985
991
|
@artist.good_albums
|
986
992
|
# SELECT * FROM albums WHERE ((artist_id = 1) AND (good IS TRUE))
|
987
993
|
|
@@ -1162,7 +1168,7 @@ join of the join table and the associated table, whereas this option just
|
|
1162
1168
|
applies to the join table. It can be used to make sure that filters are used
|
1163
1169
|
when deleting.
|
1164
1170
|
|
1165
|
-
Artist.many_to_many :lead_guitar_albums, class: :Album, :
|
1171
|
+
Artist.many_to_many :lead_guitar_albums, class: :Album, join_table_block: (lambda do |ds|
|
1166
1172
|
ds.where(instrument_id: 5)
|
1167
1173
|
end)
|
1168
1174
|
|
@@ -1177,7 +1183,7 @@ access to the join table.
|
|
1177
1183
|
For example, if the Album class uses a different Sequel::Database than the Artist
|
1178
1184
|
class, and the join table is in the database that the Artist class uses:
|
1179
1185
|
|
1180
|
-
Artist.many_to_many :lead_guitar_albums, class: :Album, :
|
1186
|
+
Artist.many_to_many :lead_guitar_albums, class: :Album, join_table_db: Artist.db
|
1181
1187
|
|
1182
1188
|
This option also affects the add/remove/remove_all methods, by changing
|
1183
1189
|
which database is used for inserts/deletes from the join table (add/remove/remove_all
|
@@ -1470,7 +1476,7 @@ at least the following keys:
|
|
1470
1476
|
Example:
|
1471
1477
|
|
1472
1478
|
Artist.one_to_many :self_title_albums, class: :Album,
|
1473
|
-
:
|
1479
|
+
eager_grapher: (lambda do |eo|
|
1474
1480
|
eo[:self].graph(:albums, {artist_id: :id, name: :name},
|
1475
1481
|
table_alias: eo[:table_alias], implicit_qualifier: eo[:implicit_qualifier])
|
1476
1482
|
end)
|
@@ -1492,6 +1498,36 @@ as the qualifiers may not match the aliases automatically used by eager_graph.
|
|
1492
1498
|
This should contain unqualified identifiers, and eager_graph will automatically
|
1493
1499
|
qualify them with the appropriate alias.
|
1494
1500
|
|
1501
|
+
==== :graph_use_association_block
|
1502
|
+
|
1503
|
+
Setting this to true makes eager_graph apply the association block to the
|
1504
|
+
associated dataset before graphing the associated dataset into the receiver.
|
1505
|
+
In most cases when this option is used and the association has a block, the
|
1506
|
+
dataset returned by eager_graph will contain a JOIN to a subquery.
|
1507
|
+
|
1508
|
+
By default (when this option is not used), the association block will be ignored
|
1509
|
+
when using eager_graph:
|
1510
|
+
|
1511
|
+
Artist.one_to_many :tracks do |ds|
|
1512
|
+
ds.where(foo: 3)
|
1513
|
+
end
|
1514
|
+
Artist.eager_graph(:tracks)
|
1515
|
+
# SELECT albums.id, tracks.id AS tracks_id, tracks.album_id
|
1516
|
+
# FROM albums
|
1517
|
+
# LEFT OUTER JOIN tracks
|
1518
|
+
# ON (tracks.album_id = albums.id)
|
1519
|
+
|
1520
|
+
When this option is used, the block will be respected:
|
1521
|
+
|
1522
|
+
Artist.one_to_many :tracks, graph_use_association_block: true do |ds|
|
1523
|
+
ds.where(foo: 3)
|
1524
|
+
end
|
1525
|
+
Artist.eager_graph(:tracks)
|
1526
|
+
# SELECT albums.id, tracks.id AS tracks_id, tracks.album_id
|
1527
|
+
# FROM albums
|
1528
|
+
# LEFT OUTER JOIN (SELECT * FROM tracks WHERE (foo = 3)) AS tracks
|
1529
|
+
# ON (tracks.album_id = albums.id)
|
1530
|
+
|
1495
1531
|
==== :graph_join_table_conditions [+many_to_many+, +one_through_one+]
|
1496
1532
|
|
1497
1533
|
The additional conditions to use on the SQL join for the join table when
|
@@ -1727,7 +1763,7 @@ support joins.
|
|
1727
1763
|
If set to false, you cannot use the association when filtering.
|
1728
1764
|
|
1729
1765
|
Artist.one_to_many :albums, allow_filtering_by: false
|
1730
|
-
Artist.where(:
|
1766
|
+
Artist.where(albums: Album.where(name: 'A')).all # Raises Sequel::Error
|
1731
1767
|
|
1732
1768
|
This is useful if such filtering cannot work, such as when a subquery cannot
|
1733
1769
|
be used because the necessary tables are not in the same database.
|
data/doc/cheat_sheet.rdoc
CHANGED
@@ -54,8 +54,8 @@ Without a filename argument, the sqlite adapter will setup a new sqlite database
|
|
54
54
|
== Update/Delete rows
|
55
55
|
|
56
56
|
dataset.exclude(:active).delete
|
57
|
-
dataset.where{price < 100}.update(:
|
58
|
-
dataset.where(:active).update(:
|
57
|
+
dataset.where{price < 100}.update(active: true)
|
58
|
+
dataset.where(:active).update(price: Sequel[:price] * 0.90)
|
59
59
|
|
60
60
|
= Merge rows
|
61
61
|
|
@@ -174,7 +174,7 @@ Without a filename argument, the sqlite adapter will setup a new sqlite database
|
|
174
174
|
String :name, unique: true, null: false
|
175
175
|
TrueClass :active, default: true
|
176
176
|
foreign_key :category_id, :categories
|
177
|
-
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP, :
|
177
|
+
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP, index: true
|
178
178
|
|
179
179
|
index [:category_id, :active]
|
180
180
|
end
|
data/doc/mass_assignment.rdoc
CHANGED
@@ -48,7 +48,7 @@ If you want to change mass assignment so it ignores attempts to access restricte
|
|
48
48
|
Since mass assignment by default allows modification of all column values except for primary key columns, it can be a security risk in some cases.
|
49
49
|
If you are dealing with untrusted input, you are generally going to want to restrict what should be updated.
|
50
50
|
|
51
|
-
Sequel has <tt>Model#set_fields</tt> and <tt>Model#update_fields</tt> methods, which are designed to be used with
|
51
|
+
Sequel has <tt>Model#set_fields</tt> and <tt>Model#update_fields</tt> methods, which are designed to be used with untrusted input.
|
52
52
|
These methods take two arguments, the untrusted hash as the first argument, and a trusted array of field names as the second argument:
|
53
53
|
|
54
54
|
post.set_fields({title: 'T', body: 'B'}, [:title, :body])
|
data/doc/migration.rdoc
CHANGED
@@ -86,9 +86,24 @@ the following methods:
|
|
86
86
|
* +add_full_text_index+
|
87
87
|
* +add_spatial_index+
|
88
88
|
* +rename_column+
|
89
|
+
* +set_column_allow_null+
|
89
90
|
|
90
91
|
If you use any other methods, you should create your own +down+ block.
|
91
92
|
|
93
|
+
To revert a migration created with +change+, you can copy the migration to a new file, and
|
94
|
+
replace +change+ with +revert+. For example, if you no longer need the artists table, you
|
95
|
+
can use the following migration. This will drop the artists table when migrating up, and
|
96
|
+
recreate it when migrating down:
|
97
|
+
|
98
|
+
Sequel.migration do
|
99
|
+
revert do
|
100
|
+
create_table(:artists) do
|
101
|
+
primary_key :id
|
102
|
+
String :name, null: false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
92
107
|
In normal usage, when Sequel's migrator runs, it runs the +up+ blocks for all
|
93
108
|
migrations that have not yet been applied. However, you can use the <tt>-M</tt>
|
94
109
|
switch to specify the version to which to migrate, and if it is lower than the
|
data/doc/model_hooks.rdoc
CHANGED
data/doc/object_model.rdoc
CHANGED
@@ -36,7 +36,7 @@ schema modification,
|
|
36
36
|
and transactions:
|
37
37
|
|
38
38
|
DB.transaction do
|
39
|
-
DB[:table].insert(:
|
39
|
+
DB[:table].insert(column: value)
|
40
40
|
end
|
41
41
|
|
42
42
|
Sequel::Database#literal can be used to take any object that Sequel handles
|
@@ -468,7 +468,7 @@ objects:
|
|
468
468
|
Sequel.lit(['', ' = '], :a, 1)
|
469
469
|
|
470
470
|
'? = ?'.lit(:a, 1) # core_extensions extension
|
471
|
-
':b = :v'.lit(:
|
471
|
+
':b = :v'.lit(b: :a, v: 1) # core_extensions extension
|
472
472
|
|
473
473
|
=== Sequel::SQL::OrderedExpression
|
474
474
|
|
@@ -482,20 +482,20 @@ it ascending or descending:
|
|
482
482
|
Additionally, they take an options hash, which can be used to specify how nulls
|
483
483
|
can be sorted:
|
484
484
|
|
485
|
-
Sequel::SQL::OrderedExpression.new(:a, true, :
|
486
|
-
Sequel::SQL::OrderedExpression.new(:a, false, :
|
485
|
+
Sequel::SQL::OrderedExpression.new(:a, true, nulls: :first) # "a" DESC NULLS FIRST
|
486
|
+
Sequel::SQL::OrderedExpression.new(:a, false, nulls: :last) # "a" ASC NULLS LAST
|
487
487
|
|
488
488
|
The following shortcuts exist for creating Sequel::SQL::OrderedExpression objects:
|
489
489
|
|
490
490
|
Sequel.asc(:a)
|
491
491
|
Sequel.desc(:a)
|
492
|
-
Sequel.asc(:a, :
|
493
|
-
Sequel.desc(:a, :
|
492
|
+
Sequel.asc(:a, nulls: :first)
|
493
|
+
Sequel.desc(:a, nulls: :last)
|
494
494
|
|
495
495
|
:a.asc # core_extensions extension
|
496
496
|
:a.desc # core_extensions extension
|
497
|
-
:a.asc(:
|
498
|
-
:a.desc(:
|
497
|
+
:a.asc(nulls: :first) # core_extensions extension
|
498
|
+
:a.desc(nulls: :last) # core_extensions extension
|
499
499
|
|
500
500
|
=== Sequel::SQL::Subscript
|
501
501
|
|
data/doc/opening_databases.rdoc
CHANGED
@@ -268,7 +268,7 @@ The following additional options are supported:
|
|
268
268
|
to MySQL.
|
269
269
|
:socket :: Can be used to specify a Unix socket file to connect to instead of a TCP host and port.
|
270
270
|
:sql_mode :: Set the sql_mode(s) for a given connection. Can be single symbol or string,
|
271
|
-
or an array of symbols or strings (e.g. <tt
|
271
|
+
or an array of symbols or strings (e.g. <tt>sql_mode: [:no_zero_date, :pipes_as_concat]</tt>).
|
272
272
|
:timeout :: Sets the wait_timeout for the connection, defaults to 1 month.
|
273
273
|
:read_timeout :: Set the timeout in seconds for reading back results to a query.
|
274
274
|
:connect_timeout :: Set the timeout in seconds before a connection attempt is abandoned
|
@@ -279,7 +279,7 @@ if either the :sslca or :sslkey option is given.
|
|
279
279
|
|
280
280
|
=== mysql2
|
281
281
|
|
282
|
-
This is a
|
282
|
+
This is a MySQL adapter that does typecasting in C, so it is often faster than the
|
283
283
|
mysql adapter. The options given are passed to Mysql2::Client.new, see the mysql2 documentation
|
284
284
|
for details on what options are supported. The :timeout, :auto_is_null, :sql_mode, and :disable_split_materialized
|
285
285
|
options supported by the mysql adapter are also supported for mysql2 adapter (and any other adapters connecting to
|
@@ -290,13 +290,13 @@ mysql, such as the jdbc/mysql adapter).
|
|
290
290
|
The ODBC adapter allows you to connect to any database with the appropriate ODBC drivers installed.
|
291
291
|
The :database option given ODBC database should be the DSN (Descriptive Service Name) from the ODBC configuration.
|
292
292
|
|
293
|
-
Sequel.odbc('mydb', :
|
293
|
+
Sequel.odbc('mydb', user: "user", password: "password")
|
294
294
|
|
295
295
|
The :host and :port options are not respected. The following additional options are supported:
|
296
296
|
|
297
297
|
:db_type :: Can be specified as 'mssql', 'progress', or 'db2' to use SQL syntax specific to those databases.
|
298
298
|
:drvconnect :: Can be given an ODBC connection string, and will use ODBC::Database#drvconnect to
|
299
|
-
do the connection. Typical usage would be: <tt>Sequel.odbc(:
|
299
|
+
do the connection. Typical usage would be: <tt>Sequel.odbc(drvconnect: 'driver={...};...')</tt>
|
300
300
|
|
301
301
|
=== oracle
|
302
302
|
|
@@ -312,15 +312,14 @@ The following additional options are supported:
|
|
312
312
|
|
313
313
|
=== postgres
|
314
314
|
|
315
|
-
Requires: pg (or postgres-pr/postgres-compat if pg is not available)
|
315
|
+
Requires: pg (or sequel/postgres-pr or postgres-pr/postgres-compat if pg is not available)
|
316
316
|
|
317
|
-
The Sequel postgres adapter works with the pg and postgres-pr ruby libraries.
|
317
|
+
The Sequel postgres adapter works with the pg, sequel-postgres-pr, jeremyevans-postgres-pr, and postgres-pr ruby libraries.
|
318
318
|
The pg library is the best supported, as it supports real bound variables and prepared statements.
|
319
319
|
If the pg library is being used, Sequel will also attempt to load the sequel_pg library, which is
|
320
320
|
a C extension that optimizes performance when Sequel is used with pg. All users of Sequel who
|
321
|
-
use pg are encouraged to install sequel_pg. For users who want to use postgres-pr
|
322
|
-
with C extensions, it is recommended to use
|
323
|
-
the upstream postgres-pr gem, and is regularly tested with Sequel.
|
321
|
+
use pg are encouraged to install sequel_pg. For users who want to use one of the postgres-pr
|
322
|
+
libraries to avoid issues with C extensions, it is recommended to use sequel-postgres-pr.
|
324
323
|
|
325
324
|
The following additional options are supported:
|
326
325
|
|
@@ -346,7 +345,7 @@ The following additional options are supported:
|
|
346
345
|
:search_path :: Set to the schema search_path. This can either be a single string containing the schemas
|
347
346
|
separated by commas (for use via a URL: <tt>postgres:///?search_path=schema1,schema2</tt>), or it
|
348
347
|
can be an array of strings (for use via an option:
|
349
|
-
<tt>Sequel.postgres(:
|
348
|
+
<tt>Sequel.postgres(search_path: ['schema1', 'schema2'])</tt>).
|
350
349
|
:use_iso_date_format :: This can be set to false to not force the ISO date format. Sequel forces
|
351
350
|
it by default to allow for an optimization.
|
352
351
|
|
@@ -389,8 +388,10 @@ The following additional options are supported:
|
|
389
388
|
:readonly :: open database in read-only mode
|
390
389
|
:timeout :: the busy timeout to use in milliseconds (default: 5000).
|
391
390
|
:setup_regexp_function :: Whether to setup a REGEXP function in the underlying SQLite3::Database object. Doing so
|
392
|
-
allows you to use regexp support in dataset expressions.
|
393
|
-
|
391
|
+
allows you to use regexp support in dataset expressions. If +:cached+ or <tt>"cached"</tt>+, caches each
|
392
|
+
unique regex (more efficient but risk of memory leak). If a Proc is provided, it will be called with
|
393
|
+
a string for the regexp and a string for the value to compare, and should return whether the regexp
|
394
|
+
string matches the string value to compare. The default Proc used does <tt>Regexp.new(regexp_str).match(str)</tt>.
|
394
395
|
|
395
396
|
Note that SQLite memory databases are restricted to a single connection by
|
396
397
|
default. This is because SQLite does not allow multiple connections to
|
@@ -424,3 +425,10 @@ Other Sequel specific options:
|
|
424
425
|
This should be specified as an integer. If you plan on setting large
|
425
426
|
text or blob values via tinytds, you should use this option or modify
|
426
427
|
your freetds.conf file.
|
428
|
+
|
429
|
+
=== trilogy
|
430
|
+
|
431
|
+
This is a MySQL adapter that does typecasting in C, and does not require any mysql client libraries installed.
|
432
|
+
The options given are passed to Trilogy.new, see the trilogy documentation for details on what options are
|
433
|
+
supported. The :timeout, :auto_is_null, :sql_mode, and :disable_split_materialized
|
434
|
+
options supported by the mysql adapter are also supported for trilogy adapter.
|
data/doc/postgresql.rdoc
CHANGED
@@ -295,16 +295,16 @@ option to +foreign_key_list+:
|
|
295
295
|
primary_key :id
|
296
296
|
Integer :i
|
297
297
|
Integer :j
|
298
|
-
foreign_key :a_id, :a, :
|
298
|
+
foreign_key :a_id, :a, foreign_key_constraint_name: :a_a
|
299
299
|
unique [:i, :j]
|
300
300
|
end
|
301
301
|
DB.create_table!(:b) do
|
302
|
-
foreign_key :a_id, :a, :
|
302
|
+
foreign_key :a_id, :a, foreign_key_constraint_name: :a_a
|
303
303
|
Integer :c
|
304
304
|
Integer :d
|
305
|
-
foreign_key [:c, :d], :a, :
|
305
|
+
foreign_key [:c, :d], :a, key: [:j, :i], name: :a_c_d
|
306
306
|
end
|
307
|
-
DB.foreign_key_list(:a, :
|
307
|
+
DB.foreign_key_list(:a, reverse: true)
|
308
308
|
# => [
|
309
309
|
# {:name=>:a_a, :columns=>[:a_id], :key=>[:id], :on_update=>:no_action, :on_delete=>:no_action, :deferrable=>false, :table=>:a, :schema=>:public},
|
310
310
|
# {:name=>:a_a, :columns=>[:a_id], :key=>[:id], :on_update=>:no_action, :on_delete=>:no_action, :deferrable=>false, :table=>:b, :schema=>:public},
|
@@ -413,12 +413,12 @@ syntax:
|
|
413
413
|
|
414
414
|
DB.create_table(:table){primary_key :id}
|
415
415
|
# Ignore the given value for id, using the identity's sequence value.
|
416
|
-
DB[:table].overriding_user_value.insert(:
|
416
|
+
DB[:table].overriding_user_value.insert(id: 1)
|
417
417
|
|
418
|
-
DB.create_table(:table){primary_key :id, :
|
418
|
+
DB.create_table(:table){primary_key :id, identity: :always}
|
419
419
|
# Force the use of the given value for id, because otherwise the insert will
|
420
420
|
# raise an error, since GENERATED ALWAYS was used when creating the column.
|
421
|
-
DB[:table].overriding_system_value.insert(:
|
421
|
+
DB[:table].overriding_system_value.insert(id: 1)
|
422
422
|
|
423
423
|
=== Distinct On Specific Columns
|
424
424
|
|
@@ -561,7 +561,7 @@ such as the related table and column or constraint.
|
|
561
561
|
|
562
562
|
DB.create_table(:test1){primary_key :id}
|
563
563
|
DB.create_table(:test2){primary_key :id; foreign_key :test1_id, :test1}
|
564
|
-
DB[:test2].insert(:
|
564
|
+
DB[:test2].insert(test1_id: 1) rescue DB.error_info($!)
|
565
565
|
# => {
|
566
566
|
# :schema=>"public",
|
567
567
|
# :table=>"test2",
|
data/doc/querying.rdoc
CHANGED
@@ -715,7 +715,7 @@ aggregation:
|
|
715
715
|
|
716
716
|
Album.select_group(:artist_id).select_append{sum(num_tracks).as(tracks)}
|
717
717
|
# SELECT artist_id, sum(num_tracks) AS tracks FROM albums GROUP BY artist_id
|
718
|
-
|
718
|
+
|
719
719
|
== Having
|
720
720
|
|
721
721
|
The SQL HAVING clause is similar to the WHERE clause, except that
|
@@ -0,0 +1,73 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* A require_valid_schema plugin has been added, for checking that
|
4
|
+
model classes have schema parsed as expected. By default, model
|
5
|
+
classes are not required to have valid schema, because it is
|
6
|
+
allowed to have model classes based on arbitrary datasets (such
|
7
|
+
as those using joins or set-returning functions), and it is not
|
8
|
+
possible to determine the schema for arbitary datasets.
|
9
|
+
|
10
|
+
Sequel swallows non-connection errors when trying to parse schema
|
11
|
+
for a model's dataset, but if schema parsing fails when you would
|
12
|
+
expect it to succeed, it results in a model where typecasting does
|
13
|
+
not work as expected.
|
14
|
+
|
15
|
+
The require_valid_schema plugin will raise an error when setting
|
16
|
+
the dataset for a model if schema parsing fails and the dataset
|
17
|
+
uses a simple table where you would expect schema parsing to
|
18
|
+
succeed. You can also provide an argument of :warn when loading
|
19
|
+
the plugin, to warn instead of raising an error.
|
20
|
+
|
21
|
+
This plugin may not work correctly in all cases for all adapters,
|
22
|
+
especially external adapters. Adapters are not required to support
|
23
|
+
schema parsing. Even if supported, adapters may not support
|
24
|
+
parsing schema for qualified tables, or parsing schema for views.
|
25
|
+
You should consider this plugin as a possible safety net. Users
|
26
|
+
are encouraged to try using it and report any unexpected breakage,
|
27
|
+
as that may help improve schema parsing in adapters that Sequel
|
28
|
+
ships.
|
29
|
+
|
30
|
+
* is_json and is_not_json methods have been added to the pg_json_ops
|
31
|
+
extension, for the IS [NOT] JSON operator supported in PostgreSQL
|
32
|
+
15+.
|
33
|
+
|
34
|
+
* Index creation methods on PostgreSQL 15+ now support a
|
35
|
+
:nulls_distinct option, for NULLS [NOT] DISTINCT. This allows you
|
36
|
+
to create unique indexes where NULL values are not considered
|
37
|
+
distinct.
|
38
|
+
|
39
|
+
* View creation methods on PostgreSQL 15+ now support a
|
40
|
+
:security_invoker option to create a view where access is
|
41
|
+
determined by the permissions of the role that is accessing the
|
42
|
+
view, instead of the role that created the view.
|
43
|
+
|
44
|
+
= Other Improvements
|
45
|
+
|
46
|
+
* The :allow_eager association option is now set to false by default
|
47
|
+
for associations explicitly marked as :instance_specific, if the
|
48
|
+
:eager_loader association is not given.
|
49
|
+
|
50
|
+
* The postgres adapter now supports the sequel-postgres-pr driver.
|
51
|
+
The sequel-postgres-pr driver is a slimmed down fork of the
|
52
|
+
postgres-pr driver designed specifically for use by Sequel.
|
53
|
+
|
54
|
+
* Model code that explicitly does not swallow connection errors
|
55
|
+
will also now not swallow disconnect errors. This can fix issues
|
56
|
+
where model classes are being loaded at runtime, and the query to
|
57
|
+
get the columns/schema for the model uses a connection that has
|
58
|
+
been disconnected.
|
59
|
+
|
60
|
+
* Model classes created from aliased expressions and literal
|
61
|
+
strings no longer use the simple_table optimization, as there
|
62
|
+
are cases where doing so is not safe.
|
63
|
+
|
64
|
+
= Backwards Compatibility
|
65
|
+
|
66
|
+
* The change to not swallow disconnect errors when not swallowing
|
67
|
+
connection errors can result in exceptions being raised which
|
68
|
+
weren't raised previously. In most cases, this will alert you
|
69
|
+
to issues in your application that should be fixed, but it
|
70
|
+
potentially it can result in regressions if you were OK with
|
71
|
+
the errors being swallowed. If this does result in regressions
|
72
|
+
in your application, please file an issue and we can probably
|
73
|
+
add a setting controlling this feature.
|
@@ -0,0 +1,22 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* The date_arithmetic extension now supports arbitrary expressions
|
4
|
+
as interval values on PostgreSQL 9.4+. Previously, only integers
|
5
|
+
were supported for the interval values.
|
6
|
+
|
7
|
+
= Other Improvements
|
8
|
+
|
9
|
+
* Most Kernel#respond_to? calls have been converted to equivalent
|
10
|
+
defined? calls for better performance. defined? is a keyword
|
11
|
+
and is about 50% faster for the same behavior.
|
12
|
+
|
13
|
+
* The is_distinct_from extension now supports the IS DISTINCT FROM
|
14
|
+
syntax natively on SQLite 3.39+, instead of emulating it.
|
15
|
+
|
16
|
+
* HAVING without GROUP BY is now supported on SQLite 3.39+.
|
17
|
+
|
18
|
+
* Coverage testing has been significantly expanded. Previously,
|
19
|
+
the core, model, plugin, and extension code had 100% line/branch
|
20
|
+
coverage. 100% line/branch coverage has been added for the
|
21
|
+
core extensions, bin/sequel, and the postgres adapter with the
|
22
|
+
pg driver.
|
@@ -0,0 +1,43 @@
|
|
1
|
+
= Improvements
|
2
|
+
|
3
|
+
* When typecasting strings to other types, Sequel::Database will now
|
4
|
+
by default not typecast strings that are much longer than expected
|
5
|
+
for the underlying type. Depending on the underlying type, there
|
6
|
+
is a limit of either 100 or 1000 bytes on the input string. This
|
7
|
+
avoids potential performance issues when trying to convert
|
8
|
+
arbitrary sized user input to specific types.
|
9
|
+
|
10
|
+
* The respond_to? to defined? change made in 5.60.0 was reverted in
|
11
|
+
5.60.1 as it broke cases on Ruby < 3 where the object had an unused
|
12
|
+
refinement that added the method.
|
13
|
+
|
14
|
+
* When typecasting strings to integer, strings such as -0xa are now
|
15
|
+
treated as negative hexidecimal strings, similar to how 0xa is
|
16
|
+
treated as a positive hexidecimal string.
|
17
|
+
|
18
|
+
* Database#foreign_key_list now returns results for partitioned
|
19
|
+
tables on PostgreSQL 11+.
|
20
|
+
|
21
|
+
* Timestamps before the date of calendar reform are now handled
|
22
|
+
correctly by the pg_extended_date_support extension when using
|
23
|
+
Ruby 3.2 preview 2+.
|
24
|
+
|
25
|
+
= Backwards Compatibility
|
26
|
+
|
27
|
+
* The change to not typecast strings that are too long can break
|
28
|
+
backwards compatibility for applications that expect typecasting
|
29
|
+
for input beyond Sequel's limits. You can disable the string
|
30
|
+
bytesize checking by setting:
|
31
|
+
|
32
|
+
DB.check_string_typecast_bytesize = false
|
33
|
+
|
34
|
+
or by passing the check_string_typecast_bytesize: false option when
|
35
|
+
creating the Database instance.
|
36
|
+
|
37
|
+
* Code to workaround a bug in JRuby 9.2.0.0 has been removed from the
|
38
|
+
pg_extended_date_support extension. Users of the extension should
|
39
|
+
upgrade to a newer JRuby version.
|
40
|
+
|
41
|
+
* The is_json and is_not_json methods have been removed from the
|
42
|
+
pg_json_ops extension, as the underlying support was removed in
|
43
|
+
PostgreSQL 15 beta 4.
|