sequel 5.80.0 → 5.92.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.
- checksums.yaml +4 -4
- data/bin/sequel +9 -4
- data/lib/sequel/adapters/ado.rb +1 -1
- data/lib/sequel/adapters/ibmdb.rb +1 -0
- data/lib/sequel/adapters/jdbc/db2.rb +2 -2
- data/lib/sequel/adapters/jdbc/derby.rb +3 -3
- data/lib/sequel/adapters/jdbc/h2.rb +2 -2
- data/lib/sequel/adapters/jdbc/hsqldb.rb +2 -2
- data/lib/sequel/adapters/jdbc/jtds.rb +2 -2
- data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +5 -5
- data/lib/sequel/adapters/jdbc/postgresql.rb +5 -5
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +6 -6
- data/lib/sequel/adapters/jdbc/sqlite.rb +2 -2
- data/lib/sequel/adapters/jdbc/sqlserver.rb +2 -2
- data/lib/sequel/adapters/jdbc.rb +8 -8
- data/lib/sequel/adapters/mysql2.rb +8 -1
- data/lib/sequel/adapters/shared/access.rb +1 -0
- data/lib/sequel/adapters/shared/db2.rb +1 -1
- data/lib/sequel/adapters/shared/mssql.rb +18 -5
- data/lib/sequel/adapters/shared/mysql.rb +8 -4
- data/lib/sequel/adapters/shared/oracle.rb +1 -0
- data/lib/sequel/adapters/shared/postgres.rb +106 -13
- data/lib/sequel/adapters/shared/sqlite.rb +4 -2
- data/lib/sequel/adapters/sqlite.rb +4 -0
- data/lib/sequel/adapters/trilogy.rb +1 -2
- data/lib/sequel/connection_pool/sharded_threaded.rb +26 -10
- data/lib/sequel/connection_pool/threaded.rb +26 -10
- data/lib/sequel/connection_pool.rb +2 -2
- data/lib/sequel/core.rb +15 -0
- data/lib/sequel/database/connecting.rb +20 -26
- data/lib/sequel/database/dataset_defaults.rb +3 -3
- data/lib/sequel/database/misc.rb +46 -10
- data/lib/sequel/database/query.rb +11 -11
- data/lib/sequel/database/schema_generator.rb +8 -0
- data/lib/sequel/database/schema_methods.rb +17 -1
- data/lib/sequel/dataset/actions.rb +9 -1
- data/lib/sequel/dataset/deprecated_singleton_class_methods.rb +1 -1
- data/lib/sequel/dataset/prepared_statements.rb +2 -1
- data/lib/sequel/dataset/query.rb +9 -5
- data/lib/sequel/dataset/sql.rb +25 -5
- data/lib/sequel/extensions/caller_logging.rb +2 -0
- data/lib/sequel/extensions/connection_validator.rb +15 -10
- data/lib/sequel/extensions/dataset_run.rb +41 -0
- data/lib/sequel/extensions/migration.rb +23 -3
- data/lib/sequel/extensions/null_dataset.rb +2 -2
- data/lib/sequel/extensions/pg_auto_parameterize.rb +1 -1
- data/lib/sequel/extensions/pg_auto_parameterize_in_array.rb +93 -10
- data/lib/sequel/extensions/pg_enum.rb +3 -3
- data/lib/sequel/extensions/pg_json_ops.rb +642 -9
- data/lib/sequel/extensions/pg_row.rb +3 -1
- data/lib/sequel/extensions/pg_schema_caching.rb +90 -0
- data/lib/sequel/extensions/provenance.rb +2 -0
- data/lib/sequel/extensions/query_blocker.rb +172 -0
- data/lib/sequel/extensions/schema_caching.rb +24 -9
- data/lib/sequel/extensions/schema_dumper.rb +16 -4
- data/lib/sequel/extensions/sqlite_json_ops.rb +1 -1
- data/lib/sequel/extensions/stdio_logger.rb +48 -0
- data/lib/sequel/extensions/string_agg.rb +17 -4
- data/lib/sequel/extensions/temporarily_release_connection.rb +178 -0
- data/lib/sequel/extensions/virtual_row_method_block.rb +1 -0
- data/lib/sequel/model/associations.rb +28 -3
- data/lib/sequel/model/base.rb +67 -18
- data/lib/sequel/plugins/association_pks.rb +1 -1
- data/lib/sequel/plugins/column_encryption.rb +1 -1
- data/lib/sequel/plugins/composition.rb +1 -1
- data/lib/sequel/plugins/defaults_setter.rb +16 -4
- data/lib/sequel/plugins/enum.rb +1 -1
- data/lib/sequel/plugins/forbid_lazy_load.rb +14 -1
- data/lib/sequel/plugins/input_transformer.rb +1 -1
- data/lib/sequel/plugins/inspect_pk.rb +44 -0
- data/lib/sequel/plugins/instance_filters.rb +4 -1
- data/lib/sequel/plugins/inverted_subsets.rb +1 -0
- data/lib/sequel/plugins/lazy_attributes.rb +1 -1
- data/lib/sequel/plugins/nested_attributes.rb +10 -5
- data/lib/sequel/plugins/optimistic_locking.rb +2 -0
- data/lib/sequel/plugins/paged_operations.rb +5 -2
- data/lib/sequel/plugins/pg_auto_constraint_validations.rb +6 -1
- data/lib/sequel/plugins/pg_auto_validate_enums.rb +88 -0
- data/lib/sequel/plugins/pg_eager_any_typed_array.rb +95 -0
- data/lib/sequel/plugins/rcte_tree.rb +1 -1
- data/lib/sequel/plugins/serialization.rb +11 -5
- data/lib/sequel/plugins/sql_comments.rb +7 -2
- data/lib/sequel/plugins/static_cache_cache.rb +50 -13
- data/lib/sequel/plugins/subset_conditions.rb +85 -5
- data/lib/sequel/plugins/subset_static_cache.rb +263 -0
- data/lib/sequel/plugins/tactical_eager_loading.rb +6 -2
- data/lib/sequel/plugins/validate_associated.rb +1 -1
- data/lib/sequel/sql.rb +16 -6
- data/lib/sequel/version.rb +1 -1
- metadata +12 -234
- data/CHANGELOG +0 -1355
- data/README.rdoc +0 -936
- data/doc/advanced_associations.rdoc +0 -884
- data/doc/association_basics.rdoc +0 -1859
- data/doc/bin_sequel.rdoc +0 -146
- data/doc/cheat_sheet.rdoc +0 -255
- data/doc/code_order.rdoc +0 -102
- data/doc/core_extensions.rdoc +0 -405
- data/doc/dataset_basics.rdoc +0 -96
- data/doc/dataset_filtering.rdoc +0 -222
- data/doc/extensions.rdoc +0 -77
- data/doc/fork_safety.rdoc +0 -84
- data/doc/mass_assignment.rdoc +0 -98
- data/doc/migration.rdoc +0 -660
- data/doc/model_dataset_method_design.rdoc +0 -129
- data/doc/model_hooks.rdoc +0 -254
- data/doc/model_plugins.rdoc +0 -270
- data/doc/mssql_stored_procedures.rdoc +0 -43
- data/doc/object_model.rdoc +0 -563
- data/doc/opening_databases.rdoc +0 -436
- data/doc/postgresql.rdoc +0 -611
- data/doc/prepared_statements.rdoc +0 -144
- data/doc/querying.rdoc +0 -1070
- data/doc/reflection.rdoc +0 -120
- data/doc/release_notes/5.0.0.txt +0 -159
- data/doc/release_notes/5.1.0.txt +0 -31
- data/doc/release_notes/5.10.0.txt +0 -84
- data/doc/release_notes/5.11.0.txt +0 -83
- data/doc/release_notes/5.12.0.txt +0 -141
- data/doc/release_notes/5.13.0.txt +0 -27
- data/doc/release_notes/5.14.0.txt +0 -63
- data/doc/release_notes/5.15.0.txt +0 -39
- data/doc/release_notes/5.16.0.txt +0 -110
- data/doc/release_notes/5.17.0.txt +0 -31
- data/doc/release_notes/5.18.0.txt +0 -69
- data/doc/release_notes/5.19.0.txt +0 -28
- data/doc/release_notes/5.2.0.txt +0 -33
- data/doc/release_notes/5.20.0.txt +0 -89
- data/doc/release_notes/5.21.0.txt +0 -87
- data/doc/release_notes/5.22.0.txt +0 -48
- data/doc/release_notes/5.23.0.txt +0 -56
- data/doc/release_notes/5.24.0.txt +0 -56
- data/doc/release_notes/5.25.0.txt +0 -32
- data/doc/release_notes/5.26.0.txt +0 -35
- data/doc/release_notes/5.27.0.txt +0 -21
- data/doc/release_notes/5.28.0.txt +0 -16
- data/doc/release_notes/5.29.0.txt +0 -22
- data/doc/release_notes/5.3.0.txt +0 -121
- data/doc/release_notes/5.30.0.txt +0 -20
- data/doc/release_notes/5.31.0.txt +0 -148
- data/doc/release_notes/5.32.0.txt +0 -46
- data/doc/release_notes/5.33.0.txt +0 -24
- data/doc/release_notes/5.34.0.txt +0 -40
- data/doc/release_notes/5.35.0.txt +0 -56
- data/doc/release_notes/5.36.0.txt +0 -60
- data/doc/release_notes/5.37.0.txt +0 -30
- data/doc/release_notes/5.38.0.txt +0 -28
- data/doc/release_notes/5.39.0.txt +0 -19
- data/doc/release_notes/5.4.0.txt +0 -80
- data/doc/release_notes/5.40.0.txt +0 -40
- data/doc/release_notes/5.41.0.txt +0 -25
- data/doc/release_notes/5.42.0.txt +0 -136
- data/doc/release_notes/5.43.0.txt +0 -98
- data/doc/release_notes/5.44.0.txt +0 -32
- data/doc/release_notes/5.45.0.txt +0 -34
- data/doc/release_notes/5.46.0.txt +0 -87
- data/doc/release_notes/5.47.0.txt +0 -59
- data/doc/release_notes/5.48.0.txt +0 -14
- data/doc/release_notes/5.49.0.txt +0 -59
- data/doc/release_notes/5.5.0.txt +0 -61
- data/doc/release_notes/5.50.0.txt +0 -78
- data/doc/release_notes/5.51.0.txt +0 -47
- data/doc/release_notes/5.52.0.txt +0 -87
- data/doc/release_notes/5.53.0.txt +0 -23
- data/doc/release_notes/5.54.0.txt +0 -27
- data/doc/release_notes/5.55.0.txt +0 -21
- data/doc/release_notes/5.56.0.txt +0 -51
- data/doc/release_notes/5.57.0.txt +0 -23
- data/doc/release_notes/5.58.0.txt +0 -31
- data/doc/release_notes/5.59.0.txt +0 -73
- data/doc/release_notes/5.6.0.txt +0 -31
- data/doc/release_notes/5.60.0.txt +0 -22
- data/doc/release_notes/5.61.0.txt +0 -43
- data/doc/release_notes/5.62.0.txt +0 -132
- data/doc/release_notes/5.63.0.txt +0 -33
- data/doc/release_notes/5.64.0.txt +0 -50
- data/doc/release_notes/5.65.0.txt +0 -21
- data/doc/release_notes/5.66.0.txt +0 -24
- data/doc/release_notes/5.67.0.txt +0 -32
- data/doc/release_notes/5.68.0.txt +0 -61
- data/doc/release_notes/5.69.0.txt +0 -26
- data/doc/release_notes/5.7.0.txt +0 -108
- data/doc/release_notes/5.70.0.txt +0 -35
- data/doc/release_notes/5.71.0.txt +0 -21
- data/doc/release_notes/5.72.0.txt +0 -33
- data/doc/release_notes/5.73.0.txt +0 -66
- data/doc/release_notes/5.74.0.txt +0 -45
- data/doc/release_notes/5.75.0.txt +0 -35
- data/doc/release_notes/5.76.0.txt +0 -86
- data/doc/release_notes/5.77.0.txt +0 -63
- data/doc/release_notes/5.78.0.txt +0 -67
- data/doc/release_notes/5.79.0.txt +0 -28
- data/doc/release_notes/5.8.0.txt +0 -170
- data/doc/release_notes/5.80.0.txt +0 -40
- data/doc/release_notes/5.9.0.txt +0 -99
- data/doc/schema_modification.rdoc +0 -679
- data/doc/security.rdoc +0 -443
- data/doc/sharding.rdoc +0 -286
- data/doc/sql.rdoc +0 -648
- data/doc/testing.rdoc +0 -190
- data/doc/thread_safety.rdoc +0 -15
- data/doc/transactions.rdoc +0 -250
- data/doc/validations.rdoc +0 -558
- data/doc/virtual_rows.rdoc +0 -265
@@ -1,144 +0,0 @@
|
|
1
|
-
= Prepared Statements and Bound Variables
|
2
|
-
|
3
|
-
Sequel has support for prepared statements and bound variables. No matter which
|
4
|
-
database you are using, the Sequel prepared statement/bound variable API remains
|
5
|
-
the same. There is native support for prepared statements/bound variables on
|
6
|
-
the following adapters:
|
7
|
-
|
8
|
-
* ibmdb (prepared statements only)
|
9
|
-
* jdbc
|
10
|
-
* mysql (server prepared statements using literalized connection variables)
|
11
|
-
* mysql2 (full support on 0.4+, otherwise server prepared statements using literalized connection variables)
|
12
|
-
* oracle (requires type specifiers for nil/NULL values)
|
13
|
-
* postgres (when using the pg driver)
|
14
|
-
* sqlite
|
15
|
-
* tinytds
|
16
|
-
|
17
|
-
Support on other adapters is emulated.
|
18
|
-
|
19
|
-
You can use the prepared_statements model plugin to automatically use prepared
|
20
|
-
statements for some common model actions such as saving or deleting a model
|
21
|
-
instance, or looking up a model based on a primary key.
|
22
|
-
|
23
|
-
== Placeholders
|
24
|
-
|
25
|
-
Generally, when using prepared statements (and certainly when using bound
|
26
|
-
variables), you need to put placeholders in your SQL to indicate where you
|
27
|
-
want your bound arguments to appear. Database support and syntax vary
|
28
|
-
significantly for placeholders (e.g. :name, $1, ?). Sequel abstracts all of
|
29
|
-
that and allows you to specify placeholders by using the :$name format for
|
30
|
-
placeholders, e.g.:
|
31
|
-
|
32
|
-
ds = DB[:items].where(name: :$n)
|
33
|
-
|
34
|
-
You can use these placeholders in most places where you can use the value
|
35
|
-
directly. For example, if you want to use placeholders while also using
|
36
|
-
raw SQL, you can do:
|
37
|
-
|
38
|
-
ds = DB["SELECT * FROM items WHERE name = ?", :$n]
|
39
|
-
|
40
|
-
== Bound Variables
|
41
|
-
|
42
|
-
Using bound variables for this query is simple:
|
43
|
-
|
44
|
-
ds.call(:select, n: 'Jim')
|
45
|
-
|
46
|
-
This will do the equivalent of selecting records that have the name 'Jim'. It
|
47
|
-
returns all records, and can take a block that is passed to <tt>Dataset#all</tt>.
|
48
|
-
|
49
|
-
Deleting or returning the first record works similarly:
|
50
|
-
|
51
|
-
ds.call(:first, n: 'Jim') # First record with name 'Jim'
|
52
|
-
ds.call(:delete, n: 'Jim') # Delete records with name 'Jim'
|
53
|
-
|
54
|
-
For inserting/updating records, you should also specify a value hash, which
|
55
|
-
may itself contain placeholders:
|
56
|
-
|
57
|
-
# Insert record with 'Jim', note that the previous filter is ignored
|
58
|
-
ds.call(:insert, {n: 'Jim'}, name: :$n)
|
59
|
-
# Change name to 'Bob' for all records with name of 'Jim'
|
60
|
-
ds.call(:update, {n: 'Jim', new_n: 'Bob'}, name: :$new_n)
|
61
|
-
|
62
|
-
== Prepared Statements
|
63
|
-
|
64
|
-
Prepared statement support is similar to bound variable support, but you
|
65
|
-
use <tt>Dataset#prepare</tt> with a name, and <tt>Dataset#call</tt> or <tt>Database#call</tt> later with the values:
|
66
|
-
|
67
|
-
ds = DB[:items].where(name: :$n)
|
68
|
-
ps = ds.prepare(:select, :select_by_name)
|
69
|
-
|
70
|
-
ps.call(n: 'Jim')
|
71
|
-
DB.call(:select_by_name, n: 'Jim') # same
|
72
|
-
|
73
|
-
The <tt>Dataset#prepare</tt> method returns a prepared statement, and also stores a
|
74
|
-
copy of the prepared statement in the database for later use. For insert
|
75
|
-
and update queries, the hash to insert/update is passed to +prepare+:
|
76
|
-
|
77
|
-
ps1 = DB[:items].prepare(:insert, :insert_with_name, name: :$n)
|
78
|
-
|
79
|
-
ps1.call(n: 'Jim')
|
80
|
-
DB.call(:insert_with_name, n: 'Jim') # same
|
81
|
-
|
82
|
-
ds = DB[:items].where(name: :$n)
|
83
|
-
ps2 = ds.prepare(:update, :update_name, name: :$new_n)
|
84
|
-
|
85
|
-
ps2.call(n: 'Jim', new_n: 'Bob')
|
86
|
-
DB.call(:update_name, n: 'Jim', new_n: 'Bob') # same
|
87
|
-
|
88
|
-
== Implementation Issues
|
89
|
-
|
90
|
-
Currently, creating a prepared statement uses Object#extend, which can hurt
|
91
|
-
performance. For high performance applications, it's recommended to create
|
92
|
-
all of your prepared statements upon application initialization, and not
|
93
|
-
to create prepared statements dynamically at runtime.
|
94
|
-
|
95
|
-
== Database support
|
96
|
-
|
97
|
-
=== PostgreSQL
|
98
|
-
|
99
|
-
If you are using the postgres-pr driver, PostgreSQL uses the
|
100
|
-
default emulated support. If you are using ruby-pg, there is native support
|
101
|
-
for both prepared statements and bound variables. Prepared statements are
|
102
|
-
always server side.
|
103
|
-
|
104
|
-
=== SQLite
|
105
|
-
|
106
|
-
SQLite supports both prepared statements and bound variables.
|
107
|
-
|
108
|
-
=== MySQL/Mysql2
|
109
|
-
|
110
|
-
The MySQL and Mysql2 <0.4 ruby drivers do not support bound variables, so the bound
|
111
|
-
variable methods are emulated. It uses server side prepared statements.
|
112
|
-
|
113
|
-
Mysql2 0.4+ supports both prepared statements and bound variables.
|
114
|
-
|
115
|
-
=== JDBC
|
116
|
-
|
117
|
-
JDBC supports both prepared statements and bound variables. Whether these
|
118
|
-
are server side or client side depends on the JDBC driver. For PostgreSQL
|
119
|
-
over JDBC, you can add the prepareThreshold=N parameter to the connection
|
120
|
-
string, which will use a server side prepared statement after N calls to
|
121
|
-
the prepared statement.
|
122
|
-
|
123
|
-
=== TinyTDS
|
124
|
-
|
125
|
-
Uses the sp_executesql stored procedure with bound variables, since
|
126
|
-
Microsoft SQL Server doesn't support true prepared statements.
|
127
|
-
|
128
|
-
=== IBM_DB
|
129
|
-
|
130
|
-
DB2 supports both prepared statements and bound variables.
|
131
|
-
|
132
|
-
=== Oracle
|
133
|
-
|
134
|
-
Oracle supports both prepared statements and bound variables. Prepared
|
135
|
-
statements (OCI8::Cursor objects) are cached per connection. If you
|
136
|
-
ever plan to use a nil/NULL value as a bound variable/prepared statement
|
137
|
-
value, you must specify the type in the placeholder using a __* suffix.
|
138
|
-
You can use any of the schema types that Sequel supports, such as
|
139
|
-
:$name__string or :$num__integer. Using blobs as bound variables is
|
140
|
-
not currently supported.
|
141
|
-
|
142
|
-
=== All Others
|
143
|
-
|
144
|
-
Support is emulated.
|