sequel 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +76 -0
- data/Rakefile +2 -2
- data/bin/sequel +9 -4
- data/doc/opening_databases.rdoc +279 -0
- data/doc/release_notes/3.2.0.txt +268 -0
- data/doc/virtual_rows.rdoc +42 -51
- data/lib/sequel/adapters/ado.rb +2 -5
- data/lib/sequel/adapters/db2.rb +5 -0
- data/lib/sequel/adapters/do.rb +3 -0
- data/lib/sequel/adapters/firebird.rb +6 -4
- data/lib/sequel/adapters/informix.rb +5 -3
- data/lib/sequel/adapters/jdbc.rb +10 -8
- data/lib/sequel/adapters/jdbc/h2.rb +17 -4
- data/lib/sequel/adapters/mysql.rb +6 -19
- data/lib/sequel/adapters/odbc.rb +14 -18
- data/lib/sequel/adapters/openbase.rb +8 -0
- data/lib/sequel/adapters/shared/mssql.rb +14 -8
- data/lib/sequel/adapters/shared/mysql.rb +53 -28
- data/lib/sequel/adapters/shared/oracle.rb +21 -12
- data/lib/sequel/adapters/shared/postgres.rb +46 -26
- data/lib/sequel/adapters/shared/progress.rb +10 -5
- data/lib/sequel/adapters/shared/sqlite.rb +28 -12
- data/lib/sequel/adapters/sqlite.rb +4 -3
- data/lib/sequel/adapters/utils/stored_procedures.rb +18 -9
- data/lib/sequel/connection_pool.rb +4 -3
- data/lib/sequel/database.rb +110 -10
- data/lib/sequel/database/schema_sql.rb +12 -3
- data/lib/sequel/dataset.rb +40 -3
- data/lib/sequel/dataset/convenience.rb +0 -11
- data/lib/sequel/dataset/graph.rb +25 -11
- data/lib/sequel/dataset/sql.rb +176 -68
- data/lib/sequel/extensions/migration.rb +37 -21
- data/lib/sequel/extensions/schema_dumper.rb +8 -61
- data/lib/sequel/model.rb +3 -3
- data/lib/sequel/model/associations.rb +9 -1
- data/lib/sequel/model/base.rb +8 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
- data/lib/sequel/sql.rb +125 -18
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/ado_spec.rb +1 -0
- data/spec/adapters/firebird_spec.rb +1 -0
- data/spec/adapters/informix_spec.rb +1 -0
- data/spec/adapters/mysql_spec.rb +23 -8
- data/spec/adapters/oracle_spec.rb +1 -0
- data/spec/adapters/postgres_spec.rb +52 -4
- data/spec/adapters/spec_helper.rb +2 -2
- data/spec/adapters/sqlite_spec.rb +2 -1
- data/spec/core/connection_pool_spec.rb +16 -0
- data/spec/core/database_spec.rb +174 -0
- data/spec/core/dataset_spec.rb +121 -26
- data/spec/core/expression_filters_spec.rb +156 -0
- data/spec/core/object_graph_spec.rb +20 -1
- data/spec/core/schema_spec.rb +5 -5
- data/spec/extensions/migration_spec.rb +140 -74
- data/spec/extensions/schema_dumper_spec.rb +3 -69
- data/spec/extensions/single_table_inheritance_spec.rb +6 -0
- data/spec/integration/dataset_test.rb +84 -2
- data/spec/integration/schema_test.rb +24 -5
- data/spec/integration/spec_helper.rb +8 -6
- data/spec/model/eager_loading_spec.rb +9 -0
- data/spec/model/record_spec.rb +35 -8
- metadata +8 -7
- data/lib/sequel/adapters/utils/date_format.rb +0 -21
- data/lib/sequel/adapters/utils/savepoint_transactions.rb +0 -80
- data/lib/sequel/adapters/utils/unsupported.rb +0 -50
data/CHANGELOG
CHANGED
@@ -1,3 +1,79 @@
|
|
1
|
+
=== 3.2.0 (2009-07-02)
|
2
|
+
|
3
|
+
* In the STI plugin, don't overwrite the STI field if it is already set (jeremyevans)
|
4
|
+
|
5
|
+
* Add support for Common Table Expressions, which use the SQL WITH clause (jeremyevans)
|
6
|
+
|
7
|
+
* Add SQL::WindowFunction, expand virtual row blocks to support them and other constructions (jeremyevans)
|
8
|
+
|
9
|
+
* Add Model#autoincrementing_primary_key, for when the autoincrementing key isn't the same as the primary key (jeremyevans)
|
10
|
+
|
11
|
+
* Add Dataset#ungraphed, to remove the splitting of results into subhashes or associated records (jeremyevans)
|
12
|
+
|
13
|
+
* Support :opclass option for PostgreSQL indexes (tmi, jeremyevans)
|
14
|
+
|
15
|
+
* Make parsing of server's version more reliable for PostgreSQL (jeremyevans)
|
16
|
+
|
17
|
+
* Add Dataset#qualify, which is qualify_to with a first_source default (jeremyevans)
|
18
|
+
|
19
|
+
* Add :ruby_default to parsed schema information, which contains a ruby object representing the database default (jeremyevans)
|
20
|
+
|
21
|
+
* Fix changing a column's name, type, or null status on MySQL when column has a string default (jeremyevans)
|
22
|
+
|
23
|
+
* Remove Dataset#to_table_reference protected method, no longer used (jeremyevans)
|
24
|
+
|
25
|
+
* Fix thread-safety issue in stored procedure code (jeremyevans)
|
26
|
+
|
27
|
+
* Remove SavepointTransactions module, integrate into Database code (jeremyevans)
|
28
|
+
|
29
|
+
* Add supports_distinct_on? method (jeremyevans)
|
30
|
+
|
31
|
+
* Remove SQLStandardDateFormat, replace with requires_sql_standard_datetimes? method (jeremyevans)
|
32
|
+
|
33
|
+
* Remove UnsupportedIsTrue module, replace with supports_is_true? method (jeremyevans)
|
34
|
+
|
35
|
+
* Remove UnsupportedIntersectExcept(All)? modules, replace with methods (jeremyevans)
|
36
|
+
|
37
|
+
* Make Database#indexes work on PostgreSQL versions prior to 8.3 (tested on 7.4) (jeremyevans)
|
38
|
+
|
39
|
+
* Fix bin/sequel using a YAML file on 1.9 (jeremyevans)
|
40
|
+
|
41
|
+
* Allow connection pool options to be specified in connection string (jeremyevans)
|
42
|
+
|
43
|
+
* Handle :user and :password options in the JDBC adapter (jeremyevans)
|
44
|
+
|
45
|
+
* Fix warnings when using the ODBC adapter (jeremyevans)
|
46
|
+
|
47
|
+
* Add opening_databases.rdoc file for describing how to connect to a database (mwlang, jeremyevans)
|
48
|
+
|
49
|
+
* Significantly increase JDBC select performance (jeremyevans)
|
50
|
+
|
51
|
+
* Slightly increase SQLite select performance using the native adapter (jeremyevans)
|
52
|
+
|
53
|
+
* Majorly increase MySQL select performance using the native adapter (jeremyevans)
|
54
|
+
|
55
|
+
* Pass through unsigned/elements/size and other options when altering columns on MySQL (tmm1)
|
56
|
+
|
57
|
+
* Allow on_duplicate_key_update to affect Dataset#insert on MySQL (tmm1)
|
58
|
+
|
59
|
+
* Support using a given table and column to store schema versions, using new Migrator.run method (bougyman, jeremyevans)
|
60
|
+
|
61
|
+
* Fix foreign key table constraints on MySQL (jeremyevans)
|
62
|
+
|
63
|
+
* Remove Dataset#table_exists?, use Database#table_exists? instead (jeremyevans)
|
64
|
+
|
65
|
+
* Fix graphing of datasets with dataset sources (jeremyevans) (#271)
|
66
|
+
|
67
|
+
* Raise a Sequel::Error if Sequel.connect is called with something other than a Hash or String (jeremyevans) (#272)
|
68
|
+
|
69
|
+
* Add -N option to bin/sequel to not test the database connection (jeremyevans)
|
70
|
+
|
71
|
+
* Make Model.grep call Dataset#grep instead of Enumerable#grep (jeremyevans)
|
72
|
+
|
73
|
+
* Support the use of Regexp as first argument to StringExpression.like (jeremyevans)
|
74
|
+
|
75
|
+
* Fix Database#indexes on PostgreSQL when the schema used is a symbol (jeremyevans)
|
76
|
+
|
1
77
|
=== 3.1.0 (2009-06-04)
|
2
78
|
|
3
79
|
* Require the classes match to consider an association a reciprocal (jeremyevans) (#270)
|
data/Rakefile
CHANGED
@@ -164,14 +164,14 @@ begin
|
|
164
164
|
|
165
165
|
desc "Run integration tests"
|
166
166
|
Spec::Rake::SpecTask.new("integration") do |t|
|
167
|
-
t.spec_files =
|
167
|
+
t.spec_files = Dir["spec/integration/*_test.rb"]
|
168
168
|
t.spec_opts = spec_opts.call
|
169
169
|
end
|
170
170
|
|
171
171
|
%w'postgres sqlite mysql informix oracle ado'.each do |adapter|
|
172
172
|
desc "Run #{adapter} specs without coverage"
|
173
173
|
Spec::Rake::SpecTask.new("spec_#{adapter}") do |t|
|
174
|
-
t.spec_files = ["spec/adapters/#{adapter}_spec.rb"]
|
174
|
+
t.spec_files = ["spec/adapters/#{adapter}_spec.rb"] + Dir["spec/integration/*_test.rb"]
|
175
175
|
t.spec_opts = spec_opts.call
|
176
176
|
end
|
177
177
|
end
|
data/bin/sequel
CHANGED
@@ -13,6 +13,7 @@ logfile = nil
|
|
13
13
|
migrate_dir = nil
|
14
14
|
migrate_ver = nil
|
15
15
|
backtrace = nil
|
16
|
+
test_connection = true
|
16
17
|
load_dirs = []
|
17
18
|
|
18
19
|
opts = OptionParser.new do |opts|
|
@@ -69,6 +70,10 @@ opts = OptionParser.new do |opts|
|
|
69
70
|
migrate_ver = Integer(v)
|
70
71
|
end
|
71
72
|
|
73
|
+
opts.on("-N", "--no-test-connection", "do not test the connection") do
|
74
|
+
test_connection = false
|
75
|
+
end
|
76
|
+
|
72
77
|
opts.on("-t", "--trace", "Output the full backtrace if an exception is raised") do
|
73
78
|
backtrace = true
|
74
79
|
end
|
@@ -100,21 +105,22 @@ if logfile || echo
|
|
100
105
|
end
|
101
106
|
|
102
107
|
connect_proc = lambda do |database|
|
103
|
-
if File.exist?(database)
|
108
|
+
db = if File.exist?(database)
|
104
109
|
require 'yaml'
|
105
110
|
env ||= "development"
|
106
111
|
db_config = YAML.load_file(database)
|
107
112
|
db_config = db_config[env] || db_config[env.to_sym] || db_config
|
108
|
-
db_config.each{|
|
113
|
+
db_config.keys.each{|k| db_config[k.to_sym] = db_config.delete(k)}
|
109
114
|
Sequel.connect(db_config.merge!(db_opts))
|
110
115
|
else
|
111
116
|
Sequel.connect(database, db_opts)
|
112
117
|
end
|
118
|
+
db.test_connection if test_connection
|
119
|
+
db
|
113
120
|
end
|
114
121
|
|
115
122
|
begin
|
116
123
|
DB = connect_proc[db]
|
117
|
-
DB.test_connection
|
118
124
|
if migrate_dir
|
119
125
|
Sequel.extension :migration
|
120
126
|
Sequel::Migrator.apply(DB, migrate_dir, migrate_ver)
|
@@ -132,7 +138,6 @@ begin
|
|
132
138
|
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?
|
133
139
|
start_time = Time.now
|
134
140
|
TO_DB = connect_proc[db2]
|
135
|
-
TO_DB.test_connection
|
136
141
|
same_db = DB.database_type==TO_DB.database_type
|
137
142
|
|
138
143
|
puts "Databases connections successful"
|
@@ -0,0 +1,279 @@
|
|
1
|
+
= Connecting to a database
|
2
|
+
|
3
|
+
All Sequel activity begins with connecting to a database, which creates a
|
4
|
+
Sequel::Database object. The Database object is used to create datasets and execute
|
5
|
+
queries. Sequel provides a powerful and flexible mechanism for connecting to
|
6
|
+
databases. There are two main ways to establish database connections:
|
7
|
+
|
8
|
+
1. Using the Sequel.connect method
|
9
|
+
2. Using the specialized adapter method (Sequel.sqlite, Sequel.postgres, etc.)
|
10
|
+
|
11
|
+
The connection options needed depend on the adapter being used, though most adapters
|
12
|
+
share the same basic connection options.
|
13
|
+
|
14
|
+
If you are only connecting to a single database, it is recommended that you store the
|
15
|
+
database object in a constant named DB. This should never be required, but it is the
|
16
|
+
convention that most Sequel code uses.
|
17
|
+
|
18
|
+
== Using the Sequel.connect method
|
19
|
+
|
20
|
+
The connect method usually takes a well-formed URI, which is parsed into connection options needed to open
|
21
|
+
the database connection. The scheme/protocol part of the URI is used to determine the adapter to use:
|
22
|
+
|
23
|
+
DB = Sequel.connect('postgres://user:password@localhost/blog') # Uses the postgres adapter
|
24
|
+
|
25
|
+
You can use URI query parameters to specify options:
|
26
|
+
|
27
|
+
DB = Sequel.connect('postgres://localhost/blog?user=user&password=password')
|
28
|
+
|
29
|
+
You can also pass an additional option hash with the connection string:
|
30
|
+
|
31
|
+
DB = Sequel.connect('postgres://localhost/blog' :user=>'user', :password=>'password')
|
32
|
+
|
33
|
+
You can also just use an options hash without a connection string. If you do this, you must
|
34
|
+
provide the adapter to use:
|
35
|
+
|
36
|
+
DB = Sequel.connect(:adapter=>'postgres', :host=>'localhost', :database=>'blog', :user=>'user', :password=>'password')
|
37
|
+
|
38
|
+
All of the above statements are equivalent.
|
39
|
+
|
40
|
+
== Using the specialized adapter method
|
41
|
+
|
42
|
+
The specialized adapter method is similar to Sequel.connect with an options hash, except that it
|
43
|
+
automatically populates the :adapter option and assumes the first argument is the :database option,
|
44
|
+
unless the first argument is a hash. So the following statements are equivalent to the previous statements.
|
45
|
+
|
46
|
+
DB = Sequel.postgres('blog', :host=>'localhost', :user=>'user', :password=>'password')
|
47
|
+
DB = Sequel.postgres(:host=>'localhost', :user=>'user', :password=>'password', :database=>'blog')
|
48
|
+
|
49
|
+
== Passing a block to either method
|
50
|
+
|
51
|
+
Both the Sequel.connect method and the specialized adapter methods take a block. If you
|
52
|
+
provide a block to the method, Sequel will open the connection and pass it as an argument
|
53
|
+
to the block. When the block is exited, Sequel will disconnect the database connection.
|
54
|
+
For example:
|
55
|
+
|
56
|
+
Sequel.connect('sqlite://blog.db'){|db| puts db[:users].count}
|
57
|
+
|
58
|
+
== General connection options
|
59
|
+
|
60
|
+
These options are shared by all adapters unless otherwise noted.
|
61
|
+
|
62
|
+
* :adapter - The adapter to use
|
63
|
+
* :database - The name of the database to which to connect
|
64
|
+
* :default_schema - The database schema to use by default.
|
65
|
+
* :host - The hostname of the database server to which to connect
|
66
|
+
* :logger - An array of SQL loggers to log to
|
67
|
+
* :loggers - An array of SQL loggers to log to
|
68
|
+
* :password - The password for the user account
|
69
|
+
* :servers - A hash with symbol keys and hash or proc values, used with master/slave/partitioned database configurations
|
70
|
+
* :single_threaded - Whether to use the single-threaded (non-thread safe) connection pool
|
71
|
+
* :user - The user account name to use logging in
|
72
|
+
|
73
|
+
The following options can be specified and are passed to the the database's internal connection pool.
|
74
|
+
|
75
|
+
* :max_connections - The maximum size of the connection pool (default: 4 connections on most databases)
|
76
|
+
* :pool_sleep_time - The number of seconds to sleep before trying to acquire a connection again (default: 0.001 seconds)
|
77
|
+
* :pool_timeout - The number of seconds to wait if a connection cannot be acquired before raising an error (default: 5 seconds)
|
78
|
+
|
79
|
+
== Adapter specific connection options
|
80
|
+
|
81
|
+
The following sections explain the options and behavior specific to each adapter.
|
82
|
+
If the library the adapter requires is different from the name of the adapter
|
83
|
+
scheme, it is listed specifically, otherwise you can assume that is requires the
|
84
|
+
library with the same name.
|
85
|
+
|
86
|
+
=== ado
|
87
|
+
|
88
|
+
Requires: win32ole
|
89
|
+
|
90
|
+
The ADO adapter provides connectivity to ADO databases in Windows. It relies
|
91
|
+
on WIN32OLE library, so it isn't usable on other operating systems (except
|
92
|
+
possibly through WINE, but that's fairly unlikely).
|
93
|
+
|
94
|
+
The following options are supported:
|
95
|
+
* :driver - The driver to use. The default if not specified is 'SQL Server'.
|
96
|
+
* :command_timeout - Sets the time in seconds to wait while attempting
|
97
|
+
to execute a command before cancelling the attempt and generating
|
98
|
+
an error. Specifically, it sets the ADO CommandTimeout property.
|
99
|
+
If this property is not set, the default of 30 seconds is used.
|
100
|
+
* :provider - Sets the Provider of this ADO connection (for example, "SQLOLEDB")
|
101
|
+
|
102
|
+
=== amalgalite
|
103
|
+
|
104
|
+
Amalgalite is an ruby extension that provides self contained access to SQLite,
|
105
|
+
so you don't need to install SQLite separately. As amalgalite is a file backed
|
106
|
+
database, the :host, :user, and :password options are not used.
|
107
|
+
|
108
|
+
* :database - The name of the database file
|
109
|
+
* :timeout - The busy timeout period given in milliseconds
|
110
|
+
|
111
|
+
Without a database argument, assumes a memory database, so you can do:
|
112
|
+
|
113
|
+
Sequel.amalgalite
|
114
|
+
|
115
|
+
Handles paths in the connection string similar to the SQLite adapter, so see
|
116
|
+
the sqlite section below for details.
|
117
|
+
|
118
|
+
=== db2
|
119
|
+
|
120
|
+
Requires: db2/db2cli
|
121
|
+
|
122
|
+
I'm not even sure exactly how this works, or if it works at all (I've never heard from
|
123
|
+
anyone who attempted to use it). It uses the SQL_HANDLE_DBC constant to
|
124
|
+
get a handle, and respects the :database, :user, and :password options. It doesn't
|
125
|
+
appear to respect the :host or :port options.
|
126
|
+
|
127
|
+
=== dbi
|
128
|
+
|
129
|
+
Allows access to a multitude of databases via ruby-dbi. Additional options:
|
130
|
+
|
131
|
+
* :db_type - Specifying 'mssql' allows Microsoft SQL Server specific syntax to
|
132
|
+
be used. Otherwise has no effect.
|
133
|
+
|
134
|
+
DBI connection strings are a preprocessed a bit, and are specified with a dbi-
|
135
|
+
in front of the protocol. Examples:
|
136
|
+
|
137
|
+
dbi-ado://...
|
138
|
+
dbi-db2://...
|
139
|
+
dbi-frontbase://...
|
140
|
+
dbi-interbase://...
|
141
|
+
dbi-msql://...
|
142
|
+
dbi-mysql://...
|
143
|
+
dbi-odbc://...
|
144
|
+
dbi-oracle://...
|
145
|
+
dbi-pg://...
|
146
|
+
dbi-proxy://...
|
147
|
+
dbi-sqlite://...
|
148
|
+
dbi-sqlrelay://...
|
149
|
+
|
150
|
+
While the DBI adapter does work, it is recommended that you use another adapter
|
151
|
+
if your database supports it.
|
152
|
+
|
153
|
+
=== do
|
154
|
+
|
155
|
+
Requires: data_objects
|
156
|
+
|
157
|
+
The DataObjects adapter supports PostgreSQL, MySQL, and SQLite. One possible
|
158
|
+
advantage of using DataObjects is that it does the typecasting in C, which may
|
159
|
+
be faster than the other adapters.
|
160
|
+
|
161
|
+
Similar to the JDBC adapter, the DO adapter only cares about connection strings,
|
162
|
+
which can either be the String argument given to Sequel.connect directly or contained
|
163
|
+
in a :uri or :url option. The DO adapter passes through the connection string
|
164
|
+
directly to DataObjects, it does no processing of it.
|
165
|
+
|
166
|
+
Connection string examples:
|
167
|
+
|
168
|
+
do:sqlite3::memory:
|
169
|
+
do:postgres://user:password@host/database
|
170
|
+
do:mysql://user:password@host/database
|
171
|
+
|
172
|
+
=== firebird
|
173
|
+
|
174
|
+
Requires: fb (using code at http://github.com/wishdev/fb)
|
175
|
+
|
176
|
+
Does not support the :port option.
|
177
|
+
|
178
|
+
=== informix
|
179
|
+
|
180
|
+
Does not support the :host or :port options.
|
181
|
+
|
182
|
+
=== jdbc
|
183
|
+
|
184
|
+
Requires: java
|
185
|
+
|
186
|
+
Houses Sequel's JDBC support when running on JRuby.
|
187
|
+
Support for individual database types is done using sub adapters.
|
188
|
+
There are currently subadapters for PostgreSQL, MySQL, SQLite, H2,
|
189
|
+
Oracle, and MSSQL. All except Oracle and MSSQL can load the
|
190
|
+
JDBC gem, for those you need to have the .jar in your CLASSPATH
|
191
|
+
or load the Java class manually.
|
192
|
+
|
193
|
+
You just use the JDBC connection string directly, which can be specified
|
194
|
+
via the string given to Sequel.connect or via the :uri, :url, or :database options.
|
195
|
+
Sequel does no preprocessing of the string, it passes it directly to JDBC.
|
196
|
+
So if you have problems getting a connection string to work, look up the JDBC
|
197
|
+
documentation.
|
198
|
+
|
199
|
+
Example connections strings:
|
200
|
+
|
201
|
+
jdbc:sqlite::memory:
|
202
|
+
jdbc:postgresql://localhost/database?user=username
|
203
|
+
jdbc:mysql://localhost/test?user=root&password=root
|
204
|
+
jdbc:h2:mem:
|
205
|
+
|
206
|
+
=== mysql
|
207
|
+
|
208
|
+
The MySQL adapter does not support the pure-ruby MySQL adapter that ships with
|
209
|
+
ActiveRecord, it requires the native adapter.
|
210
|
+
|
211
|
+
The following additional options are supported:
|
212
|
+
|
213
|
+
* :auto_is_null - If set to true, makes "WHERE primary_key IS NULL" select the last inserted id.
|
214
|
+
* :charset - Same as :encoding, :encoding takes precedence.
|
215
|
+
* :compress - Whether to compress data sent/received via the socket connection.
|
216
|
+
* :encoding - Specify the encoding/character set to use for the connection.
|
217
|
+
* :socket - Can be used to specify a Unix socket file to connect to instead of a TCP host and port.
|
218
|
+
* :timeout - Sets the wait_timeout for the connection, defaults to 1 month.
|
219
|
+
|
220
|
+
=== odbc
|
221
|
+
|
222
|
+
The ODBC adapter allows you to connect to any database with the appropriate ODBC drivers installed.
|
223
|
+
The :database option given ODBC database should be the DSN (Descriptive Service Name) from the ODBC configuration.
|
224
|
+
|
225
|
+
Sequel.odbc('mydb', :user => "user", :password => "password")
|
226
|
+
|
227
|
+
The :host and :port options are not respected. The following additional options are supported:
|
228
|
+
|
229
|
+
* :db_type - Can be specified as 'mssql' or 'progress' to use SQL syntax specific to those databases.
|
230
|
+
* :driver - The name of the ODBC driver to utilize.
|
231
|
+
|
232
|
+
=== openbase
|
233
|
+
|
234
|
+
The :port option is ignored.
|
235
|
+
|
236
|
+
=== oracle
|
237
|
+
|
238
|
+
Requires: oci8
|
239
|
+
|
240
|
+
The following additional options are supported:
|
241
|
+
|
242
|
+
* :privilege - The Oracle privilege level.
|
243
|
+
|
244
|
+
=== postgres
|
245
|
+
|
246
|
+
Requires: pg (or postgres if pg is not available)
|
247
|
+
|
248
|
+
The Sequel postgres adapter works with the pg, postgres, and postgres-pr ruby libraries.
|
249
|
+
The pg library is the best supported, as it supports real bound variables and prepared statements.
|
250
|
+
|
251
|
+
The following additional options are supported:
|
252
|
+
|
253
|
+
* :charset - Same as :encoding, :encoding takes precedence
|
254
|
+
* :encoding - Set the client_encoding to the given string
|
255
|
+
|
256
|
+
=== sqlite
|
257
|
+
|
258
|
+
As SQLite is a file-based database, the :host and :port options are ignored, and
|
259
|
+
the :database option should be a path to the file.
|
260
|
+
|
261
|
+
Examples:
|
262
|
+
|
263
|
+
# In Memory databases:
|
264
|
+
Sequel.sqlite
|
265
|
+
Sequel.connect('sqlite:/')
|
266
|
+
Sequel.sqlite(':memory:')
|
267
|
+
|
268
|
+
# Relative Path
|
269
|
+
Sequel.sqlite('blog.db')
|
270
|
+
Sequel.sqlite('./blog.db')
|
271
|
+
Sequel.connect('sqlite://blog.db')
|
272
|
+
|
273
|
+
# Absolute Path
|
274
|
+
Sequel.sqlite('/var/sqlite/blog.db')
|
275
|
+
Sequel.connect('sqlite:///var/sqlite/blog.db')
|
276
|
+
|
277
|
+
The following additional options are supported:
|
278
|
+
|
279
|
+
* :timeout - the busy timeout to use in milliseconds (default: 5000).
|
@@ -0,0 +1,268 @@
|
|
1
|
+
New Features
|
2
|
+
------------
|
3
|
+
|
4
|
+
* Common table expressions (CTEs) are now supported. CTEs use the
|
5
|
+
SQL WITH clause, and specify inline views that queries can use.
|
6
|
+
They also support a recursive mode, where the CTE can recursively
|
7
|
+
query its own output, allowing you do do things like load all
|
8
|
+
branches for a given node in a plain tree structure.
|
9
|
+
|
10
|
+
The standard with takes an alias and a dataset:
|
11
|
+
|
12
|
+
DB[:vw].with(:vw, DB[:table].filter{col < 1})
|
13
|
+
# WITH vw AS (SELECT * FROM table WHERE col < 1)
|
14
|
+
# SELECT * FROM vw
|
15
|
+
|
16
|
+
The recursive with takes an alias, a nonrecursive dataset, and a
|
17
|
+
recursive dataset:
|
18
|
+
|
19
|
+
DB[:vw].with_recursive(:vw,
|
20
|
+
DB[:tree].filter(:id=>1),
|
21
|
+
DB[:tree].join(:vw, :id=>:parent_id).
|
22
|
+
select(:vw__id, :vw__parent_id))
|
23
|
+
# WITH RECURSIVE vw AS (SELECT * FROM tree
|
24
|
+
# WHERE (id = 1)
|
25
|
+
# UNION ALL
|
26
|
+
# SELECT vw.id, vw.parent_id
|
27
|
+
# FROM tree
|
28
|
+
# INNER JOIN vw ON (vw.id = tree.parent_id))
|
29
|
+
# SELECT * FROM vw
|
30
|
+
|
31
|
+
CTEs are supported by Microsoft SQL Server 2005+, DB2 7+,
|
32
|
+
Firebird 2.1+, Oracle 9+, and PostgreSQL 8.4+.
|
33
|
+
|
34
|
+
* SQL window functions are now supported, and a DSL has been added to
|
35
|
+
ease their creation. Window functions act similarly to aggregate
|
36
|
+
functions but operate on sliding ranges of rows.
|
37
|
+
|
38
|
+
In virtual row blocks (blocks passed to filter, select, order, etc.)
|
39
|
+
you can now provide a block to method calls to change the default
|
40
|
+
behavior to create functions that weren't possible previously. The
|
41
|
+
blocks aren't called, but their presence serves as a flag.
|
42
|
+
|
43
|
+
What function is created depends on the arguments to the method:
|
44
|
+
|
45
|
+
* If there are no arguments, an SQL::Function is created with the
|
46
|
+
name of method used, and no arguments. Previously, it was not
|
47
|
+
possible to create functions without arguments using the virtual
|
48
|
+
row block DSL. Example:
|
49
|
+
|
50
|
+
DB.dataset.select{version{}} # SELECT version()
|
51
|
+
|
52
|
+
* If the first argument is :*, an SQL::Function is created with a
|
53
|
+
single wildcard argument (*). This is mostly useful for count:
|
54
|
+
|
55
|
+
DB[:t].select{count(:*){}} # SELECT count(*) FROM t
|
56
|
+
|
57
|
+
* If the first argument is :distinct, an SQL::Function is created
|
58
|
+
with the keyword DISTINCT prefacing all remaining arguments. This
|
59
|
+
is useful for aggregate functions such as count:
|
60
|
+
|
61
|
+
DB[:t].select{count(:distinct, col1){}}
|
62
|
+
# SELECT count(DISTINCT col1) FROM t
|
63
|
+
|
64
|
+
* If the first argument is :over, the second argument, if provided,
|
65
|
+
should be a hash of options to pass to SQL::Window. The options
|
66
|
+
hash can also contain :*=>true to use a wildcard argument as the
|
67
|
+
function argument, or :args=>... to specify an array of arguments
|
68
|
+
to use as the function arguments.
|
69
|
+
|
70
|
+
DB[:t].select{rank(:over){}} # SELECT rank() OVER ()
|
71
|
+
DB[:t].select{count(:over, :*=>true){}} # SELECT count(*) OVER ()
|
72
|
+
DB[:t].select{sum(:over, :args=>col1,
|
73
|
+
:partition=>col2, :order=>col3){}}
|
74
|
+
# SELECT sum(col1) OVER (PARTITION BY col2 ORDER BY col3)
|
75
|
+
|
76
|
+
PostgreSQL also supports named windows. Named windows can be
|
77
|
+
specified by Dataset#window, and window functions can reference
|
78
|
+
them using the :window option.
|
79
|
+
|
80
|
+
* Schema information for columns now includes a :ruby_default entry
|
81
|
+
which contains a ruby object that represents the default given by
|
82
|
+
the database (which is stored in :default). Not all :default
|
83
|
+
entries can be parsed into a :ruby_default, but if the
|
84
|
+
schema_dumper extension previously supported it, it should work.
|
85
|
+
|
86
|
+
* Methods to create compound datasets (union, intersect, except), now
|
87
|
+
take an options hash instead of a true/false flag. The previous
|
88
|
+
API is still supported, but switching to specifying the ALL setting
|
89
|
+
using :all=>true is recommended.
|
90
|
+
|
91
|
+
Additionally, you can now set :from_self=>false to not wrap the
|
92
|
+
returned dataset in a "SELECT * FROM (...)".
|
93
|
+
|
94
|
+
* Dataset#ungraphed was added that removes the graphing information
|
95
|
+
from the dataset. This allows you to use Dataset#graph for the
|
96
|
+
automatic aliasing, or #eager_graph for the automatic aliasing and
|
97
|
+
joining, and then remove the graphing information so that the
|
98
|
+
resulting objects will not be split into subhashes or associations.
|
99
|
+
|
100
|
+
* There were some introspection methods added to Dataset to describe
|
101
|
+
which capabilities that dataset does or does not support:
|
102
|
+
|
103
|
+
supports_cte?
|
104
|
+
supports_distinct_on?
|
105
|
+
supports_intersect_except?
|
106
|
+
supports_intersect_except_all?
|
107
|
+
supports_window_functions?
|
108
|
+
|
109
|
+
In addition to being available for the user to use, these are also
|
110
|
+
used internally, so attempting to use a CTE on a dataset that
|
111
|
+
doesn't support it will raise an Error.
|
112
|
+
|
113
|
+
* Dataset#qualify was added, which is like qualify_to with a default
|
114
|
+
of first_source.
|
115
|
+
|
116
|
+
Additionally, qualify now affects PlaceholderLiteralStrings. It
|
117
|
+
doesn't scan the string (as Sequel never attempts to parse SQL),
|
118
|
+
but if you provide the column as a symbol placeholder argument, it
|
119
|
+
will qualify it.
|
120
|
+
|
121
|
+
* You can now specify the table and column Sequel::Migrator will use
|
122
|
+
to record the current schema version. The new Migrator.run method
|
123
|
+
must be used to use these new options.
|
124
|
+
|
125
|
+
* The JDBC adapter now accepts :user and :password options, instead
|
126
|
+
of requiring them to be specified in the connection string and
|
127
|
+
handled by the JDBC driver. This should allow connections to
|
128
|
+
Oracle using the Thin JDBC driver.
|
129
|
+
|
130
|
+
* You can now specify the max_connections, pool_timeout, and
|
131
|
+
single_threaded settings directly in the connection string:
|
132
|
+
|
133
|
+
postgres:///database?single_threaded=t
|
134
|
+
postgres:///database?max_connections=10&pool_timeout=20
|
135
|
+
|
136
|
+
* Dataset#on_duplicate_key_update now affects Dataset#insert when
|
137
|
+
using MySQL.
|
138
|
+
|
139
|
+
* You can now specify the :opclass option when creating PostgreSQL
|
140
|
+
indexes. Currently, this only supports a single operator class
|
141
|
+
for all columns. If you need different operator classes per
|
142
|
+
column, please post on sequel-talk.
|
143
|
+
|
144
|
+
* Model#autoincrementing_primary_key was added and can be used if
|
145
|
+
the autoincrementing key isn't the same as the primary key. The
|
146
|
+
only likely use for this is on MySQL MyISAM tables with composite
|
147
|
+
primary keys where only one of the composite parts is
|
148
|
+
autoincrementing.
|
149
|
+
|
150
|
+
* You can now use database column values as search patterns and
|
151
|
+
specify the text to search as a String or Regexp:
|
152
|
+
|
153
|
+
String.send(:include, Sequel::SQL::StringMethods)
|
154
|
+
Regexp.send(:include, Sequel::SQL::StringMethods)
|
155
|
+
|
156
|
+
'a'.like(:x) # ('a' LIKE x)
|
157
|
+
/a/.like(:x) # ('a' ~ x)
|
158
|
+
/a/i.like(:x) # ('a' ~* x)
|
159
|
+
/a/.like(:x, 'b') # (('a' ~ x) OR ('a' ~ 'b'))
|
160
|
+
|
161
|
+
* The Dataset#dataset_alias private method was added. It can be
|
162
|
+
overridden if you have tables named t0, t1, etc and want to make
|
163
|
+
sure the default dataset aliases that Sequel uses do not clash
|
164
|
+
with existing table names.
|
165
|
+
|
166
|
+
* Sequel now raises an Error if you call Sequel.connect with
|
167
|
+
something that is not a Hash or String.
|
168
|
+
|
169
|
+
* bin/sequel now accepts a -N option to not test the database
|
170
|
+
connection.
|
171
|
+
|
172
|
+
* An opening_databases.rdoc file was added to the documentation
|
173
|
+
directory, which should be a good introduction for new users about
|
174
|
+
how to set up your Database connection.
|
175
|
+
|
176
|
+
Other Improvements
|
177
|
+
------------------
|
178
|
+
|
179
|
+
* MySQL native adapter SELECT is much faster than before, up to 75%
|
180
|
+
faster.
|
181
|
+
|
182
|
+
* JDBC SELECT is about 10% faster than before. It's still much
|
183
|
+
slower than the native adapters, due to conversion issues.
|
184
|
+
|
185
|
+
* bin/sequel now works with a YAML file on ruby 1.9.
|
186
|
+
|
187
|
+
* MySQL foreign key table constraints have been fixed.
|
188
|
+
|
189
|
+
* Database#indexes now works on PostgreSQL if the schema used is a
|
190
|
+
Symbol. It also works on PostgreSQL versions all the way back to
|
191
|
+
7.4.
|
192
|
+
|
193
|
+
* Graphing of datasets with dataset sources has been fixed.
|
194
|
+
|
195
|
+
* Changing a columns name, type, or NULL status on MySQL now
|
196
|
+
supports a much wider selection of column defaults.
|
197
|
+
|
198
|
+
* The stored procedure code is now thread-safe. Sequel is
|
199
|
+
thread-safe in general, but due to a bug the previous stored
|
200
|
+
procedure code was not thread-safe.
|
201
|
+
|
202
|
+
* The ODBC adapter now drops statements automatically instead of
|
203
|
+
requiring the user to do so manually, making it more similar
|
204
|
+
to other adapters.
|
205
|
+
|
206
|
+
* The single_table_inheritance plugin no longer overwrites the STI
|
207
|
+
field if the field already has a value. This allows you to use
|
208
|
+
create in the generic class to insert a value that will be
|
209
|
+
returned as a subclass:
|
210
|
+
|
211
|
+
Person.create(:kind => "Manager")
|
212
|
+
|
213
|
+
* When altering colums on MySQL, :unsigned, :elements, :size and other
|
214
|
+
options given are no longer ignored.
|
215
|
+
|
216
|
+
* The PostgreSQL shared adapter's explain and analyze methods have
|
217
|
+
been fixed, they had been broken in 3.0.
|
218
|
+
|
219
|
+
* Parsing of the server's version is more robust on PostgreSQL.
|
220
|
+
It should now work correctly for 8.4 and 8.4rc1 type versions.
|
221
|
+
|
222
|
+
Backwards Compatibility
|
223
|
+
-----------------------
|
224
|
+
|
225
|
+
* Dataset#table_exists? has been removed, since it never worked
|
226
|
+
perfectly. Use Database#table_exists? instead.
|
227
|
+
|
228
|
+
* Model.grep now calls Dataset#grep instead of Enumerable#grep.
|
229
|
+
If you are using Model.grep, you need to modify your application.
|
230
|
+
|
231
|
+
* The MSSQL shared adapter previously used the :with option for
|
232
|
+
storing the NOLOCK setting of the query. That option has been
|
233
|
+
renamed to :table_options, since :with is now used for CTEs.
|
234
|
+
This should not have an effect unless you where using the option
|
235
|
+
manually.
|
236
|
+
|
237
|
+
* Previously, providing a block to a method calls in virtual row
|
238
|
+
blocks did not change behavior, where now it causes a different
|
239
|
+
code path to be used. In both cases, the block is not evaluated,
|
240
|
+
but that may change in a future version.
|
241
|
+
|
242
|
+
* Dataset#to_table_reference protected method was removed, as it was
|
243
|
+
no longer used.
|
244
|
+
|
245
|
+
* The pool_timeout setting is now converted to an Integer, so if you
|
246
|
+
used to pass in a Float, it no longer works the same way.
|
247
|
+
|
248
|
+
* Most files in adapters/utils have been removed, in favor of
|
249
|
+
integrating the code directly into Database and Dataset. If you
|
250
|
+
were previously checking for the UnsupportedIntersectExcept or
|
251
|
+
related modules, use the Dataset introspection methods instead
|
252
|
+
(e.g. supports_intersect_except?).
|
253
|
+
|
254
|
+
* If you were using the ODBC adapter and manually dropping returned
|
255
|
+
statements, you should note that now statements are dropped
|
256
|
+
automatically, and the execute method doesn't return a statement
|
257
|
+
object.
|
258
|
+
|
259
|
+
* The MySQL adapter on_duplicate_key_update_sql is now a private
|
260
|
+
method.
|
261
|
+
|
262
|
+
* If you were modifying the :from dataset option directly, note that
|
263
|
+
Sequel now expects this option to be preprocessed. See the new
|
264
|
+
implementation of Dataset#from for an idea of the changes
|
265
|
+
required.
|
266
|
+
|
267
|
+
* Dataset#simple_select_all? now returns false instead of true for a
|
268
|
+
dataset that selects from another dataset.
|