sequel 3.21.0 → 3.31.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.
- data/CHANGELOG +485 -3
- data/README.rdoc +20 -6
- data/Rakefile +37 -19
- data/bin/sequel +1 -5
- data/doc/association_basics.rdoc +249 -43
- data/doc/dataset_basics.rdoc +4 -4
- data/doc/dataset_filtering.rdoc +8 -0
- data/doc/mass_assignment.rdoc +54 -0
- data/doc/migration.rdoc +15 -538
- data/doc/model_hooks.rdoc +72 -27
- data/doc/opening_databases.rdoc +89 -50
- data/doc/prepared_statements.rdoc +40 -13
- data/doc/reflection.rdoc +8 -2
- data/doc/release_notes/3.22.0.txt +39 -0
- data/doc/release_notes/3.23.0.txt +172 -0
- data/doc/release_notes/3.24.0.txt +420 -0
- data/doc/release_notes/3.25.0.txt +88 -0
- data/doc/release_notes/3.26.0.txt +88 -0
- data/doc/release_notes/3.27.0.txt +82 -0
- data/doc/release_notes/3.28.0.txt +304 -0
- data/doc/release_notes/3.29.0.txt +459 -0
- data/doc/release_notes/3.30.0.txt +135 -0
- data/doc/release_notes/3.31.0.txt +146 -0
- data/doc/schema_modification.rdoc +547 -0
- data/doc/sharding.rdoc +7 -1
- data/doc/testing.rdoc +129 -0
- data/doc/transactions.rdoc +137 -0
- data/doc/virtual_rows.rdoc +2 -2
- data/lib/sequel/adapters/ado/mssql.rb +18 -6
- data/lib/sequel/adapters/ado.rb +40 -18
- data/lib/sequel/adapters/amalgalite.rb +17 -9
- data/lib/sequel/adapters/db2.rb +175 -86
- data/lib/sequel/adapters/dbi.rb +15 -15
- data/lib/sequel/adapters/do/mysql.rb +5 -7
- data/lib/sequel/adapters/do/postgres.rb +0 -5
- data/lib/sequel/adapters/do/sqlite.rb +0 -5
- data/lib/sequel/adapters/do.rb +17 -36
- data/lib/sequel/adapters/firebird.rb +27 -208
- data/lib/sequel/adapters/ibmdb.rb +448 -0
- data/lib/sequel/adapters/informix.rb +6 -23
- data/lib/sequel/adapters/jdbc/as400.rb +16 -34
- data/lib/sequel/adapters/jdbc/db2.rb +45 -0
- data/lib/sequel/adapters/jdbc/derby.rb +247 -0
- data/lib/sequel/adapters/jdbc/firebird.rb +29 -0
- data/lib/sequel/adapters/jdbc/h2.rb +56 -29
- data/lib/sequel/adapters/jdbc/hsqldb.rb +170 -0
- data/lib/sequel/adapters/jdbc/informix.rb +26 -0
- data/lib/sequel/adapters/jdbc/jtds.rb +34 -0
- data/lib/sequel/adapters/jdbc/mssql.rb +3 -33
- data/lib/sequel/adapters/jdbc/mysql.rb +11 -11
- data/lib/sequel/adapters/jdbc/oracle.rb +81 -25
- data/lib/sequel/adapters/jdbc/postgresql.rb +9 -13
- data/lib/sequel/adapters/jdbc/sqlite.rb +2 -6
- data/lib/sequel/adapters/jdbc/sqlserver.rb +71 -0
- data/lib/sequel/adapters/jdbc/transactions.rb +83 -0
- data/lib/sequel/adapters/jdbc.rb +231 -78
- data/lib/sequel/adapters/mock.rb +335 -0
- data/lib/sequel/adapters/mysql.rb +82 -184
- data/lib/sequel/adapters/mysql2.rb +26 -25
- data/lib/sequel/adapters/odbc/db2.rb +17 -0
- data/lib/sequel/adapters/odbc/mssql.rb +1 -6
- data/lib/sequel/adapters/odbc.rb +28 -9
- data/lib/sequel/adapters/openbase.rb +3 -5
- data/lib/sequel/adapters/oracle.rb +351 -53
- data/lib/sequel/adapters/postgres.rb +194 -33
- data/lib/sequel/adapters/shared/access.rb +32 -9
- data/lib/sequel/adapters/shared/db2.rb +321 -0
- data/lib/sequel/adapters/shared/firebird.rb +221 -0
- data/lib/sequel/adapters/shared/informix.rb +53 -0
- data/lib/sequel/adapters/shared/mssql.rb +231 -106
- data/lib/sequel/adapters/shared/mysql.rb +181 -63
- data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +149 -0
- data/lib/sequel/adapters/shared/oracle.rb +231 -41
- data/lib/sequel/adapters/shared/postgres.rb +214 -82
- data/lib/sequel/adapters/shared/progress.rb +4 -7
- data/lib/sequel/adapters/shared/sqlite.rb +201 -57
- data/lib/sequel/adapters/sqlite.rb +29 -21
- data/lib/sequel/adapters/swift/mysql.rb +12 -7
- data/lib/sequel/adapters/swift/postgres.rb +0 -5
- data/lib/sequel/adapters/swift/sqlite.rb +8 -6
- data/lib/sequel/adapters/swift.rb +5 -5
- data/lib/sequel/adapters/tinytds.rb +160 -19
- data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +66 -0
- data/lib/sequel/adapters/utils/stored_procedures.rb +1 -11
- data/lib/sequel/ast_transformer.rb +190 -0
- data/lib/sequel/connection_pool/threaded.rb +3 -2
- data/lib/sequel/connection_pool.rb +1 -1
- data/lib/sequel/core.rb +46 -5
- data/lib/sequel/database/connecting.rb +5 -6
- data/lib/sequel/database/dataset.rb +4 -4
- data/lib/sequel/database/dataset_defaults.rb +59 -1
- data/lib/sequel/database/logging.rb +1 -1
- data/lib/sequel/database/misc.rb +104 -19
- data/lib/sequel/database/query.rb +153 -58
- data/lib/sequel/database/schema_generator.rb +17 -7
- data/lib/sequel/database/schema_methods.rb +59 -29
- data/lib/sequel/dataset/actions.rb +231 -76
- data/lib/sequel/dataset/features.rb +91 -8
- data/lib/sequel/dataset/graph.rb +38 -11
- data/lib/sequel/dataset/misc.rb +50 -23
- data/lib/sequel/dataset/mutation.rb +5 -6
- data/lib/sequel/dataset/prepared_statements.rb +48 -27
- data/lib/sequel/dataset/query.rb +236 -43
- data/lib/sequel/dataset/sql.rb +665 -253
- data/lib/sequel/dataset.rb +8 -0
- data/lib/sequel/exceptions.rb +4 -0
- data/lib/sequel/extensions/columns_introspection.rb +61 -0
- data/lib/sequel/extensions/migration.rb +6 -4
- data/lib/sequel/extensions/named_timezones.rb +5 -0
- data/lib/sequel/extensions/thread_local_timezones.rb +1 -1
- data/lib/sequel/extensions/to_dot.rb +95 -83
- data/lib/sequel/model/associations.rb +1020 -337
- data/lib/sequel/model/base.rb +414 -132
- data/lib/sequel/model/errors.rb +1 -1
- data/lib/sequel/model/exceptions.rb +5 -1
- data/lib/sequel/model.rb +15 -8
- data/lib/sequel/plugins/association_pks.rb +22 -4
- data/lib/sequel/plugins/class_table_inheritance.rb +4 -4
- data/lib/sequel/plugins/dataset_associations.rb +100 -0
- data/lib/sequel/plugins/defaults_setter.rb +58 -0
- data/lib/sequel/plugins/force_encoding.rb +6 -6
- data/lib/sequel/plugins/identity_map.rb +114 -7
- data/lib/sequel/plugins/many_through_many.rb +65 -7
- data/lib/sequel/plugins/prepared_statements.rb +151 -0
- data/lib/sequel/plugins/prepared_statements_associations.rb +84 -0
- data/lib/sequel/plugins/prepared_statements_safe.rb +82 -0
- data/lib/sequel/plugins/prepared_statements_with_pk.rb +59 -0
- data/lib/sequel/plugins/rcte_tree.rb +29 -15
- data/lib/sequel/plugins/serialization.rb +88 -44
- data/lib/sequel/plugins/serialization_modification_detection.rb +51 -0
- data/lib/sequel/plugins/sharding.rb +21 -54
- data/lib/sequel/plugins/single_table_inheritance.rb +3 -1
- data/lib/sequel/plugins/typecast_on_load.rb +9 -12
- data/lib/sequel/plugins/update_primary_key.rb +2 -2
- data/lib/sequel/plugins/xml_serializer.rb +3 -3
- data/lib/sequel/sql.rb +109 -52
- data/lib/sequel/timezones.rb +57 -38
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +146 -0
- data/spec/adapters/mssql_spec.rb +111 -29
- data/spec/adapters/mysql_spec.rb +135 -123
- data/spec/adapters/oracle_spec.rb +49 -77
- data/spec/adapters/postgres_spec.rb +267 -78
- data/spec/adapters/spec_helper.rb +6 -5
- data/spec/adapters/sqlite_spec.rb +35 -21
- data/spec/core/connection_pool_spec.rb +71 -92
- data/spec/core/core_sql_spec.rb +21 -30
- data/spec/core/database_spec.rb +788 -512
- data/spec/core/dataset_spec.rb +1073 -1053
- data/spec/core/expression_filters_spec.rb +159 -42
- data/spec/core/mock_adapter_spec.rb +419 -0
- data/spec/core/object_graph_spec.rb +86 -114
- data/spec/core/schema_generator_spec.rb +3 -3
- data/spec/core/schema_spec.rb +298 -38
- data/spec/core/spec_helper.rb +6 -48
- data/spec/extensions/association_autoreloading_spec.rb +1 -10
- data/spec/extensions/association_dependencies_spec.rb +2 -12
- data/spec/extensions/association_pks_spec.rb +66 -32
- data/spec/extensions/caching_spec.rb +23 -50
- data/spec/extensions/class_table_inheritance_spec.rb +31 -83
- data/spec/extensions/columns_introspection_spec.rb +91 -0
- data/spec/extensions/composition_spec.rb +18 -13
- data/spec/extensions/dataset_associations_spec.rb +199 -0
- data/spec/extensions/defaults_setter_spec.rb +64 -0
- data/spec/extensions/hook_class_methods_spec.rb +65 -91
- data/spec/extensions/identity_map_spec.rb +114 -22
- data/spec/extensions/instance_filters_spec.rb +11 -21
- data/spec/extensions/instance_hooks_spec.rb +53 -0
- data/spec/extensions/json_serializer_spec.rb +4 -5
- data/spec/extensions/lazy_attributes_spec.rb +16 -20
- data/spec/extensions/list_spec.rb +17 -39
- data/spec/extensions/many_through_many_spec.rb +283 -250
- data/spec/extensions/migration_spec.rb +35 -32
- data/spec/extensions/named_timezones_spec.rb +23 -3
- data/spec/extensions/nested_attributes_spec.rb +97 -88
- data/spec/extensions/optimistic_locking_spec.rb +9 -20
- data/spec/extensions/prepared_statements_associations_spec.rb +111 -0
- data/spec/extensions/prepared_statements_safe_spec.rb +61 -0
- data/spec/extensions/prepared_statements_spec.rb +53 -0
- data/spec/extensions/prepared_statements_with_pk_spec.rb +31 -0
- data/spec/extensions/pretty_table_spec.rb +1 -6
- data/spec/extensions/rcte_tree_spec.rb +41 -43
- data/spec/extensions/schema_dumper_spec.rb +5 -8
- data/spec/extensions/schema_spec.rb +13 -21
- data/spec/extensions/serialization_modification_detection_spec.rb +37 -0
- data/spec/extensions/serialization_spec.rb +72 -43
- data/spec/extensions/sharding_spec.rb +66 -140
- data/spec/extensions/single_table_inheritance_spec.rb +18 -29
- data/spec/extensions/spec_helper.rb +13 -61
- data/spec/extensions/sql_expr_spec.rb +20 -60
- data/spec/extensions/tactical_eager_loading_spec.rb +9 -19
- data/spec/extensions/thread_local_timezones_spec.rb +22 -2
- data/spec/extensions/timestamps_spec.rb +6 -6
- data/spec/extensions/to_dot_spec.rb +4 -7
- data/spec/extensions/touch_spec.rb +13 -14
- data/spec/extensions/tree_spec.rb +11 -26
- data/spec/extensions/typecast_on_load_spec.rb +1 -6
- data/spec/extensions/update_primary_key_spec.rb +30 -24
- data/spec/extensions/validation_class_methods_spec.rb +30 -51
- data/spec/extensions/validation_helpers_spec.rb +16 -35
- data/spec/extensions/xml_serializer_spec.rb +16 -4
- data/spec/integration/associations_test.rb +537 -21
- data/spec/integration/database_test.rb +4 -2
- data/spec/integration/dataset_test.rb +461 -65
- data/spec/integration/eager_loader_test.rb +19 -21
- data/spec/integration/model_test.rb +80 -1
- data/spec/integration/plugin_test.rb +304 -116
- data/spec/integration/prepared_statement_test.rb +212 -122
- data/spec/integration/schema_test.rb +161 -30
- data/spec/integration/spec_helper.rb +39 -30
- data/spec/integration/timezone_test.rb +38 -12
- data/spec/integration/transaction_test.rb +172 -5
- data/spec/integration/type_test.rb +17 -3
- data/spec/model/association_reflection_spec.rb +201 -7
- data/spec/model/associations_spec.rb +865 -662
- data/spec/model/base_spec.rb +275 -95
- data/spec/model/dataset_methods_spec.rb +7 -27
- data/spec/model/eager_loading_spec.rb +677 -676
- data/spec/model/hooks_spec.rb +309 -67
- data/spec/model/model_spec.rb +222 -168
- data/spec/model/plugins_spec.rb +24 -13
- data/spec/model/record_spec.rb +381 -218
- data/spec/model/spec_helper.rb +13 -71
- data/spec/model/validations_spec.rb +11 -0
- metadata +115 -73
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
= New Features
|
|
2
|
+
|
|
3
|
+
* The serialization plugin can now support custom serialization
|
|
4
|
+
formats, by supplying a serializer/deserializer pair of
|
|
5
|
+
callable objects. You can also register custom deserializers
|
|
6
|
+
via Sequel::Plugins::Serialization.register_format, so that
|
|
7
|
+
they can be referenced by name. Example:
|
|
8
|
+
|
|
9
|
+
Sequel::Plugins::Serialization.register_format(:reverse,
|
|
10
|
+
lambda{|v| v.reverse},
|
|
11
|
+
lambda{|v| v.reverse})
|
|
12
|
+
class User < Sequel::Model
|
|
13
|
+
serialize_attributes :reverse, :password
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
* Dataset#import and #multi_insert now support a
|
|
17
|
+
:return=>:primary_key option. When this option is used, the
|
|
18
|
+
methods return an array of primary key values, one for each
|
|
19
|
+
inserted row. Usage of this option on MySQL requires that a
|
|
20
|
+
separate query be issued per row (instead of the single
|
|
21
|
+
query for all rows that MySQL would usually use).
|
|
22
|
+
|
|
23
|
+
* PostgreSQL can now use Dataset#returning in conjunction with
|
|
24
|
+
import/multi_insert to set a custom column to return.
|
|
25
|
+
|
|
26
|
+
* Microsoft SQL Server can now use Dataset#output in conjection with
|
|
27
|
+
import/multi_insert to set a custom column to return.
|
|
28
|
+
|
|
29
|
+
* Dataset#import and #multi_insert now respect a :server option to
|
|
30
|
+
set the server/shard on which to execute the queries.
|
|
31
|
+
Additionally, options given to this method are also passed to
|
|
32
|
+
Dataset#transaction.
|
|
33
|
+
|
|
34
|
+
* Dataset#insert_multiple now returns an array of inserted primary
|
|
35
|
+
keys.
|
|
36
|
+
|
|
37
|
+
* Model.def_column_alias has been added to make it easy to create
|
|
38
|
+
alias methods for columns. This is useful if you have a legacy
|
|
39
|
+
database and want to create friendly method names for the
|
|
40
|
+
underlying columns. Note that this alias only affects the setter
|
|
41
|
+
and getter methods. This does not affect the dataset level, so you
|
|
42
|
+
still need to use the actual column names in dataset filters.
|
|
43
|
+
|
|
44
|
+
* many_to_one associations can now have the same name as the related
|
|
45
|
+
foreign key column, using the :key_column option. Use of this
|
|
46
|
+
feature is not recommended, as it is much better to either rename
|
|
47
|
+
the column or rename the association. Here's an example of usage:
|
|
48
|
+
|
|
49
|
+
# Example schema:
|
|
50
|
+
# albums artists
|
|
51
|
+
# :id /--> :id
|
|
52
|
+
# :artist --/ :name
|
|
53
|
+
# :name
|
|
54
|
+
class Album < Sequel::Model
|
|
55
|
+
def_column_alias(:artist_id, :artist)
|
|
56
|
+
many_to_one :artist, :key_column=>:artist
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
* The mock adapter can now mock out database types, by providing a
|
|
60
|
+
shared adapter name as the host (e.g. mock://postgres). This
|
|
61
|
+
emulation is not perfect, but in most cases it allows you to see
|
|
62
|
+
what SQL Sequel would generate on a given database without needing
|
|
63
|
+
to install the required database driver.
|
|
64
|
+
|
|
65
|
+
* Sequel now supports creating full text indexes on Microsoft SQL
|
|
66
|
+
Server. Before using it, you must have previously setup a default
|
|
67
|
+
full text search catalog, and you need to provide a :key_index
|
|
68
|
+
option with an index name symbol.
|
|
69
|
+
|
|
70
|
+
* Dataset#group_rollup and #group_cube methods have been added for
|
|
71
|
+
GROUP BY ROLLUP and GROUP BY CUBE support. These features are in
|
|
72
|
+
a recent SQL standard, and they are supported to various degrees on
|
|
73
|
+
Microsoft SQL Server, DB2, Oracle, MySQL, and Derby.
|
|
74
|
+
|
|
75
|
+
* Dataset#full_text_search on Microsoft SQL Server now supports
|
|
76
|
+
multiple search terms.
|
|
77
|
+
|
|
78
|
+
* The jdbc adapter now supports a :login_timeout option, giving the
|
|
79
|
+
timeout in seconds.
|
|
80
|
+
|
|
81
|
+
= Other Improvements
|
|
82
|
+
|
|
83
|
+
* Dataset#exists can now be used with prepared statement
|
|
84
|
+
placeholders.
|
|
85
|
+
|
|
86
|
+
* Dataset#full_text_search can now be used with prepared statement
|
|
87
|
+
placeholders on PostgreSQL, MySQL, and Microsoft SQL Server.
|
|
88
|
+
|
|
89
|
+
* If tables from two separate schema are detected when parsing the
|
|
90
|
+
schema for a table on PostgreSQL, an error is now raised.
|
|
91
|
+
Previously, no error was raised, which led to weird errors later,
|
|
92
|
+
such as duplicate columns in a model's primary_key.
|
|
93
|
+
|
|
94
|
+
* RETURNING is now supported with UPDATE/DELETE on PostgreSQL 8.2+.
|
|
95
|
+
Previously, Sequel only supported it on 9.1+, but PostgreSQL
|
|
96
|
+
introduced support for it in 8.2.
|
|
97
|
+
|
|
98
|
+
* The shared postgres adapter now correctly handles the return value
|
|
99
|
+
for Dataset#insert if you provide a separate column array and value
|
|
100
|
+
array on PostgreSQL < 8.2.
|
|
101
|
+
|
|
102
|
+
* Handle case in the PostgreSQL adapter where the server version
|
|
103
|
+
cannot be determined via a query.
|
|
104
|
+
|
|
105
|
+
* H2 clob types are now treated as string instead of as blob.
|
|
106
|
+
Treating clob as blob breaks on H2, as it doesn't automatically
|
|
107
|
+
hex-unescape the input for clobs as it does for blobs.
|
|
108
|
+
|
|
109
|
+
* Dataset#empty? now works correctly when the dataset has an offset
|
|
110
|
+
and offset support is being emulated.
|
|
111
|
+
|
|
112
|
+
* The mock adapter no longer defaults to downcasing identifiers on
|
|
113
|
+
output.
|
|
114
|
+
|
|
115
|
+
= Backwards Compatibility
|
|
116
|
+
|
|
117
|
+
* Dataset#exists now returns a PlaceholderLiteralString instead of a
|
|
118
|
+
LiteralString, which could potentially break some code. If you
|
|
119
|
+
would like a String returned, you can pass the returned object to
|
|
120
|
+
Dataset#literal:
|
|
121
|
+
|
|
122
|
+
dataset.literal(dataset.exists)
|
|
123
|
+
|
|
124
|
+
* Dataset#from no longer handles :a__b__c___d as "a.b.c AS d". This
|
|
125
|
+
was not the intended behavior, and nowhere else in Sequel is a
|
|
126
|
+
symbol treated that way. Now, Dataset#from is consistent with the
|
|
127
|
+
rest of Sequel, using "a.b__c AS d". This should only affect
|
|
128
|
+
people in very rare cases, as most databases don't use three level
|
|
129
|
+
qualified tables. One exception is Microsoft SQL Server, which can
|
|
130
|
+
use three level qualified tables for cross-database access.
|
|
131
|
+
|
|
132
|
+
* Previously, Dataset#insert_multiple returned an array of hashes, now
|
|
133
|
+
it returns an array of primary key values.
|
|
134
|
+
|
|
135
|
+
* Dataset#EXRACT_CLOSE in the shared sqlite adapter has been renamed to
|
|
136
|
+
Dataset#EXTRACT_CLOSE.
|
|
137
|
+
|
|
138
|
+
* Dataset::StoredProcedureMethods::SQL_QUERY_TYPE and
|
|
139
|
+
Dataset::ArgumentMapper::SQL_QUERY_TYPE constants have been removed,
|
|
140
|
+
as have related sql_query_type private methods.
|
|
141
|
+
|
|
142
|
+
* The serialization plugin was significantly refactored.
|
|
143
|
+
Model.serialization_map now contains a callable object instead of a
|
|
144
|
+
Symbol, and Model.serialization_format has been removed.
|
|
145
|
+
Model.define_serialized_attribute_accessors private method now takes
|
|
146
|
+
two callable objects before the columns, instead of a single symbol.
|
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
= Schema modification methods
|
|
2
|
+
|
|
3
|
+
Here's a brief description of the most common schema modification methods:
|
|
4
|
+
|
|
5
|
+
== +create_table+
|
|
6
|
+
|
|
7
|
+
+create_table+ is the most common schema modification method, and it's used for adding new tables
|
|
8
|
+
to the schema. You provide it with the name of the table as a symbol, as well a block:
|
|
9
|
+
|
|
10
|
+
create_table(:artists) do
|
|
11
|
+
primary_key :id
|
|
12
|
+
String :name
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
Not that if you want a primary key for the table, you need to specify it, Sequel does not create one
|
|
16
|
+
by default.
|
|
17
|
+
|
|
18
|
+
=== Column types
|
|
19
|
+
|
|
20
|
+
Most method calls inside the create_table block will create columns, since +method_missing+ calls +column+.
|
|
21
|
+
Columns are generally created by specifying the column type as the method
|
|
22
|
+
name, followed by the column name symbol to use, and after that any options that should be used.
|
|
23
|
+
If the method is a ruby class name that Sequel recognizes, Sequel will transform it into the appropriate
|
|
24
|
+
type for the given database. So while you specified +String+, Sequel will actually use +varchar+ or
|
|
25
|
+
+text+ depending on the underlying database. Here's a list of all of ruby classes that Sequel will
|
|
26
|
+
convert to database types:
|
|
27
|
+
|
|
28
|
+
create_table(:columns_types) do # common database type used
|
|
29
|
+
Integer :a0 # integer
|
|
30
|
+
String :a1 # varchar(255)
|
|
31
|
+
String :a2, :size=>50 # varchar(50)
|
|
32
|
+
String :a3, :fixed=>true # char(255)
|
|
33
|
+
String :a4, :fixed=>true, :size=>50 # char(50)
|
|
34
|
+
String :a5, :text=>true # text
|
|
35
|
+
File :b, # blob
|
|
36
|
+
Fixnum :c # integer
|
|
37
|
+
Bignum :d # bigint
|
|
38
|
+
Float :e # double precision
|
|
39
|
+
BigDecimal :f # numeric
|
|
40
|
+
BigDecimal :f2, :size=>10 # numeric(10)
|
|
41
|
+
BigDecimal :f3, :size=>[10, 2] # numeric(10, 2)
|
|
42
|
+
Date :g # date
|
|
43
|
+
DateTime :h # timestamp
|
|
44
|
+
Time :i # timestamp
|
|
45
|
+
Time :i2, :only_time=>true # time
|
|
46
|
+
Numeric :j # numeric
|
|
47
|
+
TrueClass :k # boolean
|
|
48
|
+
FalseClass :l # boolean
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
Note that in addition to the ruby class name, Sequel also pays attention to the column options when
|
|
52
|
+
determining which database type to use. Also note that for boolean columns, you can use either
|
|
53
|
+
TrueClass or FalseClass, they are treated the same way (ruby doesn't have a Boolean class).
|
|
54
|
+
|
|
55
|
+
Also note that this conversion is only done if you use a supported ruby class name. In all other
|
|
56
|
+
cases, Sequel uses the type specified verbatim:
|
|
57
|
+
|
|
58
|
+
create_table(:columns_types) do # database type used
|
|
59
|
+
string :a1 # string
|
|
60
|
+
datetime :a2 # datetime
|
|
61
|
+
blob :a3 # blob
|
|
62
|
+
inet :a4 # inet
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
In addition to specifying the types as methods, you can use the +column+ method and specify the types
|
|
66
|
+
as the second argument, either as ruby classes, symbols, or strings:
|
|
67
|
+
|
|
68
|
+
create_table(:columns_types) do # database type used
|
|
69
|
+
column :a1, :string # string
|
|
70
|
+
column :a2, String # varchar(255)
|
|
71
|
+
column :a3, 'string' # string
|
|
72
|
+
column :a4, :datetime # datetime
|
|
73
|
+
column :a5, DateTime # timestamp
|
|
74
|
+
column :a6, 'timestamp(6)' # timestamp(6)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
=== Column options
|
|
78
|
+
|
|
79
|
+
When using the type name as method, the third argument is an options hash, and when using the +column+
|
|
80
|
+
method, the fourth argument is the options hash. The following options are supported:
|
|
81
|
+
|
|
82
|
+
:default :: The default value for the column.
|
|
83
|
+
:index :: Create an index on this column.
|
|
84
|
+
:null :: Mark the column as allowing NULL values (if true),
|
|
85
|
+
or not allowing NULL values (if false). If unspecified, will default
|
|
86
|
+
to whatever the database default is.
|
|
87
|
+
:size :: The size of the column, generally used with string
|
|
88
|
+
columns to specify the maximum number of characters the column will hold.
|
|
89
|
+
An array of two integers can be provided to set the size and the
|
|
90
|
+
precision, respectively, of decimal columns.
|
|
91
|
+
:unique :: Mark the column as unique, generally has the same effect as
|
|
92
|
+
creating a unique index on the column.
|
|
93
|
+
:unsigned :: Make the column type unsigned, only useful for integer
|
|
94
|
+
columns.
|
|
95
|
+
|
|
96
|
+
=== Other methods
|
|
97
|
+
|
|
98
|
+
In addition to the +column+ method and other methods that create columns, there are a other methods that can be used:
|
|
99
|
+
|
|
100
|
+
==== +primary_key+
|
|
101
|
+
|
|
102
|
+
You've seen this one used already. It's used to create an autoincrementing integer primary key column.
|
|
103
|
+
|
|
104
|
+
create_table(:a0){primary_key :id}
|
|
105
|
+
|
|
106
|
+
If you want to create a primary key column that doesn't use an autoincrementing integer, you should
|
|
107
|
+
not use this method. Instead, you should use the :primary_key option to the +column+ method or type
|
|
108
|
+
method:
|
|
109
|
+
|
|
110
|
+
create_table(:a1){Integer :id, :primary_key=>true} # Non autoincrementing integer primary key
|
|
111
|
+
create_table(:a2){String :name, :primary_key=>true} # varchar(255) primary key
|
|
112
|
+
|
|
113
|
+
If you want to create a composite primary key, you should call the +primary_key+ method with an
|
|
114
|
+
array of column symbols:
|
|
115
|
+
|
|
116
|
+
create_table(:items) do
|
|
117
|
+
Integer :group_id
|
|
118
|
+
Integer :position
|
|
119
|
+
primary_key [:group_id, :position]
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
If provided with an array, +primary_key+ does not create a column, it just sets up the primary key constraint.
|
|
123
|
+
|
|
124
|
+
==== +foreign_key+
|
|
125
|
+
|
|
126
|
+
+foreign_key+ is used to create a foreign key column that references a column in another table (or the same table).
|
|
127
|
+
It takes the column name as the first argument, the table it references as the second argument, and an options hash
|
|
128
|
+
as it's third argument. A simple example is:
|
|
129
|
+
|
|
130
|
+
create_table(:albums) do
|
|
131
|
+
primary_key :id
|
|
132
|
+
foreign_key :artist_id, :artists
|
|
133
|
+
String :name
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
+foreign_key+ accepts some specific options:
|
|
137
|
+
|
|
138
|
+
:deferrable :: Makes the foreign key constraint checks deferrable, so they aren't checked
|
|
139
|
+
until the end of the transaction.
|
|
140
|
+
:key :: For foreign key columns, the column in the associated table
|
|
141
|
+
that this column references. Unnecessary if this column
|
|
142
|
+
references the primary key of the associated table, at least
|
|
143
|
+
on most databases.
|
|
144
|
+
:on_delete :: Specify the behavior of this foreign key column when the row with the primary key
|
|
145
|
+
it references is deleted , can be :restrict, :cascade, :set_null, or :set_default.
|
|
146
|
+
:on_update :: Specify the behavior of this foreign key column when the row with the primary key
|
|
147
|
+
it references modifies the value of the primary key, can be
|
|
148
|
+
:restrict, :cascade, :set_null, or :set_default.
|
|
149
|
+
|
|
150
|
+
Like +primary_key+, if you provide +foreign_key+ with an array of symbols, it will not create a
|
|
151
|
+
column, but create a foreign key constraint:
|
|
152
|
+
|
|
153
|
+
create_table(:artists) do
|
|
154
|
+
String :name
|
|
155
|
+
String :location
|
|
156
|
+
primary_key [:name, :location]
|
|
157
|
+
end
|
|
158
|
+
create_table(:albums) do
|
|
159
|
+
String :artist_name
|
|
160
|
+
String :artist_location
|
|
161
|
+
String :name
|
|
162
|
+
foreign_key [:artist_name, :artist_location], :artists
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
==== +index+
|
|
166
|
+
|
|
167
|
+
+index+ creates indexes on the table. For single columns, calling index is the same as using the
|
|
168
|
+
<tt>:index</tt> option when creating the column:
|
|
169
|
+
|
|
170
|
+
create_table(:a){Integer :id, :index=>true}
|
|
171
|
+
# Same as:
|
|
172
|
+
create_table(:a) do
|
|
173
|
+
Integer :id
|
|
174
|
+
index :id
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
Similar to the +primary_key+ and +foreign_key+ methods, calling +index+ with an array of symbols
|
|
178
|
+
will create a multiple column index:
|
|
179
|
+
|
|
180
|
+
create_table(:albums) do
|
|
181
|
+
primary_key :id
|
|
182
|
+
foreign_key :artist_id, :artists
|
|
183
|
+
Integer :position
|
|
184
|
+
index [:artist_id, :position]
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
The +index+ method also accepts some options:
|
|
188
|
+
|
|
189
|
+
:name :: The name of the index (generated based on the table and column names if not provided).
|
|
190
|
+
:type :: The type of index to use (only supported by some databases)
|
|
191
|
+
:unique :: Make the index unique, so duplicate values are not allowed.
|
|
192
|
+
:where :: Create a partial index (only supported by some databases)
|
|
193
|
+
|
|
194
|
+
==== +unique+
|
|
195
|
+
|
|
196
|
+
The +unique+ method creates a unique constraint on the table. A unique constraint generally
|
|
197
|
+
operates identically to a unique index, so the following three +create_table+ blocks are
|
|
198
|
+
pretty much identical:
|
|
199
|
+
|
|
200
|
+
create_table(:a){Integer :a, :unique=>true}
|
|
201
|
+
|
|
202
|
+
create_table(:a) do
|
|
203
|
+
Integer :a
|
|
204
|
+
index :a, :unique=>true
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
create_table(:a) do
|
|
208
|
+
Integer :a
|
|
209
|
+
unique :a
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
Just like +index+, +unique+ can set up a multiple column unique constraint, where the
|
|
213
|
+
combination of the columns must be unique:
|
|
214
|
+
|
|
215
|
+
create_table(:a) do
|
|
216
|
+
Integer :a
|
|
217
|
+
Integer :b
|
|
218
|
+
unique [:a, :b]
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
==== +full_text_index+ and +spatial_index+
|
|
222
|
+
|
|
223
|
+
Both of these create specialized index types supported by some databases. They
|
|
224
|
+
both take the same options as +index+.
|
|
225
|
+
|
|
226
|
+
==== +constraint+
|
|
227
|
+
|
|
228
|
+
+constraint+ creates a named table constraint:
|
|
229
|
+
|
|
230
|
+
create_table(:artists) do
|
|
231
|
+
primary_key :id
|
|
232
|
+
String :name
|
|
233
|
+
constraint(:name_min_length){char_length(name) > 2}
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
Instead of using a block, you can use arguments that will be handled similarly
|
|
237
|
+
to <tt>Dataset#filter</tt>:
|
|
238
|
+
|
|
239
|
+
create_table(:artists) do
|
|
240
|
+
primary_key :id
|
|
241
|
+
String :name
|
|
242
|
+
constraint(:name_length_range, :char_length.sql_function(:name)=>3..50)
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
==== +check+
|
|
246
|
+
|
|
247
|
+
+check+ operates just like +constraint+, except that it doesn't take a name
|
|
248
|
+
and it creates an unnamed constraint
|
|
249
|
+
|
|
250
|
+
create_table(:artists) do
|
|
251
|
+
primary_key :id
|
|
252
|
+
String :name
|
|
253
|
+
check{char_length(name) > 2}
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
== +alter_table+
|
|
257
|
+
|
|
258
|
+
+alter_table+ is used to alter existing tables, changing their columns, indexes,
|
|
259
|
+
or constraints. It it used just like +create_table+, accepting a block which
|
|
260
|
+
is instance_evaled, and providing its own methods:
|
|
261
|
+
|
|
262
|
+
=== +add_column+
|
|
263
|
+
|
|
264
|
+
One of the most common methods, +add_column+ is used to add a column to the table.
|
|
265
|
+
Its API is similar to that of +create_table+'s +column+ method, where the first
|
|
266
|
+
argument is the column name, the second is the type, and the third is an options
|
|
267
|
+
hash:
|
|
268
|
+
|
|
269
|
+
alter_table(:albums) do
|
|
270
|
+
add_column :copies_sold, Integer, :default=>0
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
When adding a column, it's a good idea to provide a default value, unless you
|
|
274
|
+
want the value for all rows to be set to NULL.
|
|
275
|
+
|
|
276
|
+
=== +drop_column+
|
|
277
|
+
|
|
278
|
+
As you may expect, +drop_column+ takes a column name and drops the column. It's
|
|
279
|
+
often used in the +down+ block of a migration to drop a column added in an +up+ block:
|
|
280
|
+
|
|
281
|
+
alter_table(:albums) do
|
|
282
|
+
drop_column :copies_sold
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
=== +rename_column+
|
|
286
|
+
|
|
287
|
+
+rename_column+ is used to rename a column. It takes the old column name as the first
|
|
288
|
+
argument, and the new column name as the second argument:
|
|
289
|
+
|
|
290
|
+
alter_table(:albums) do
|
|
291
|
+
rename_column :copies_sold, :total_sales
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
=== +add_primary_key+
|
|
295
|
+
|
|
296
|
+
If you forgot to include a primary key on the table, and want to add one later, you
|
|
297
|
+
can use +add_primary_key+. A common use of this is to make many_to_many association
|
|
298
|
+
join tables into real models:
|
|
299
|
+
|
|
300
|
+
alter_table(:albums_artists) do
|
|
301
|
+
add_primary_key :id
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
Just like +create_table+'s +primary_key+ method, if you provide an array of symbols,
|
|
305
|
+
Sequel will not add a column, but will add a composite primary key constraint:
|
|
306
|
+
|
|
307
|
+
alter_table(:albums_artists) do
|
|
308
|
+
add_primary_key [:album_id, :artist_id]
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
If you just want to take an existing single column and make it a primary key, call
|
|
312
|
+
+add_primary_key+ with an array with a single symbol:
|
|
313
|
+
|
|
314
|
+
alter_table(:artists) do
|
|
315
|
+
add_primary_key [:id]
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
=== +add_foreign_key+
|
|
319
|
+
|
|
320
|
+
+add_foreign_key+ can be used to add a new foreign key column or constraint to a table.
|
|
321
|
+
Like +add_primary_key+, if you provide it with a symbol as the first argument, it
|
|
322
|
+
creates a new column:
|
|
323
|
+
|
|
324
|
+
alter_table(:albums) do
|
|
325
|
+
add_foreign_key :artist_id, :artists
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
If you want to add a new foreign key constraint to an existing column, you provide an
|
|
329
|
+
array with a single element:
|
|
330
|
+
|
|
331
|
+
alter_table(:albums) do
|
|
332
|
+
add_foreign_key [:artist_id], :artists
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
To set up a multiple column foreign key constraint, use an array with multiple column
|
|
336
|
+
symbols:
|
|
337
|
+
|
|
338
|
+
alter_table(:albums) do
|
|
339
|
+
add_foreign_key [:artist_name, :artist_location], :artists
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
=== +add_index+
|
|
343
|
+
|
|
344
|
+
+add_index+ works just like +create_table+'s +index+ method, creating a new index on
|
|
345
|
+
the table:
|
|
346
|
+
|
|
347
|
+
alter_table(:albums) do
|
|
348
|
+
add_index :artist_id
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
It accepts the same options as +create_table+'s +index+ method, and you can set up
|
|
352
|
+
a multiple column index using an array:
|
|
353
|
+
|
|
354
|
+
alter_table(:albums_artists) do
|
|
355
|
+
add_index [:album_id, :artist_id], :unique=>true
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
=== +drop_index+
|
|
359
|
+
|
|
360
|
+
As you may expect, +drop_index+ drops an existing index:
|
|
361
|
+
|
|
362
|
+
alter_table(:albums) do
|
|
363
|
+
drop_index :artist_id
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
Just like +drop_column+, it is often used in the +down+ block of a migration.
|
|
367
|
+
|
|
368
|
+
To drop an index with a specific name, use the <tt>:name</tt> option:
|
|
369
|
+
|
|
370
|
+
alter_table(:albums) do
|
|
371
|
+
drop_index :artist_id, :name=>:artists_id_index
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
=== +add_full_text_index+, +add_spatial_index+
|
|
375
|
+
|
|
376
|
+
Corresponding to +create_table+'s +full_text_index+ and +spatial_index+ methods,
|
|
377
|
+
these two methods create new indexes on the table.
|
|
378
|
+
|
|
379
|
+
=== +add_constraint+
|
|
380
|
+
|
|
381
|
+
This adds a named constraint to the table, similar to +create_table+'s +constraint+
|
|
382
|
+
method:
|
|
383
|
+
|
|
384
|
+
alter_table(:albums) do
|
|
385
|
+
add_constraint(:name_min_length){char_length(name) > 2}
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
There is no method to add an unnamed constraint, but you can pass nil as the first
|
|
389
|
+
argument of +add_constraint+ to do so. However, it's not recommend to do that
|
|
390
|
+
as it is difficult to drop such a constraint.
|
|
391
|
+
|
|
392
|
+
=== +add_unique_constraint+
|
|
393
|
+
|
|
394
|
+
This adds a unique constraint to the table, similar to +create_table+'s +unique+
|
|
395
|
+
method. This usually has the same effect as adding a unique index.
|
|
396
|
+
|
|
397
|
+
alter_table(:albums) do
|
|
398
|
+
add_unique_constraint [:artist_id, :name]
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
=== +drop_constraint+
|
|
402
|
+
|
|
403
|
+
This method drops an existing named constraint:
|
|
404
|
+
|
|
405
|
+
alter_table(:albums) do
|
|
406
|
+
drop_constraint(:name_min_length)
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
There is no database independent method to drop an unnamed constraint. Generally, the
|
|
410
|
+
database will give it a name automatically, and you will have to figure out what it is.
|
|
411
|
+
For that reason, you should not add unnamed constraints that you ever might need to remove.
|
|
412
|
+
|
|
413
|
+
On MySQL, you must specify the type of constraint via a <tt>:type</tt> option:
|
|
414
|
+
|
|
415
|
+
alter_table(:albums) do
|
|
416
|
+
drop_constraint(:albums_pk, :type=>:primary_key)
|
|
417
|
+
drop_constraint(:albums_fk, :type=>:foreign_key)
|
|
418
|
+
drop_constraint(:albums_uk, :type=>:unique)
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
=== +set_column_default+
|
|
422
|
+
|
|
423
|
+
This modifies the default value of a column:
|
|
424
|
+
|
|
425
|
+
alter_table(:albums) do
|
|
426
|
+
set_column_default :copies_sold, 0
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
=== +set_column_type+
|
|
430
|
+
|
|
431
|
+
This modifies a column's type. Most databases will attempt to convert existing values in
|
|
432
|
+
the columns to the new type:
|
|
433
|
+
|
|
434
|
+
alter_table(:albums) do
|
|
435
|
+
set_column_type :copies_sold, Bignum
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
You can specify the type as a string or symbol, in which case it is used verbatim, or as a supported
|
|
439
|
+
ruby class, in which case it gets converted to an appropriate database type.
|
|
440
|
+
|
|
441
|
+
=== +set_column_allow_null+
|
|
442
|
+
|
|
443
|
+
This changes the NULL or NOT NULL setting of a column:
|
|
444
|
+
|
|
445
|
+
alter_table(:albums) do
|
|
446
|
+
set_column_allow_null :artist_id, true # NULL
|
|
447
|
+
set_column_allow_null :copies_sold, false # NOT NULL
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
== Other +Database+ schema modification methods
|
|
451
|
+
|
|
452
|
+
<tt>Sequel::Database</tt> has many schema modification instance methods,
|
|
453
|
+
most of which are shortcuts to the same methods in +alter_table+. The
|
|
454
|
+
following +Database+ instance methods just call +alter_table+ with a
|
|
455
|
+
block that calls the method with the same name inside the +alter_table+
|
|
456
|
+
block with all arguments after the first argument (which is used as
|
|
457
|
+
the table name):
|
|
458
|
+
|
|
459
|
+
* +add_column+
|
|
460
|
+
* +drop_column+
|
|
461
|
+
* +rename_column+
|
|
462
|
+
* +add_index+
|
|
463
|
+
* +drop_index+
|
|
464
|
+
* +set_column_default+
|
|
465
|
+
* +set_column_type+
|
|
466
|
+
|
|
467
|
+
For example, the following two method calls do the same thing:
|
|
468
|
+
|
|
469
|
+
alter_table(:artists){add_column :copies_sold, Integer}
|
|
470
|
+
add_column :artists, :copies_sold, Integer
|
|
471
|
+
|
|
472
|
+
There are some other schema modification methods that have no +alter_table+
|
|
473
|
+
counterpart:
|
|
474
|
+
|
|
475
|
+
=== +drop_table+
|
|
476
|
+
|
|
477
|
+
+drop_table+ takes multiple arguments and treats all arguments as a
|
|
478
|
+
table name to drop:
|
|
479
|
+
|
|
480
|
+
drop_table(:albums_artists, :albums, :artists)
|
|
481
|
+
|
|
482
|
+
Note that when dropping tables, you may need to drop them in a specific order
|
|
483
|
+
if you are using foreign keys and the database is enforcing referential
|
|
484
|
+
integrity. In general, you need to drop the tables containing the foreign
|
|
485
|
+
keys before the tables containing the primary keys they reference.
|
|
486
|
+
|
|
487
|
+
=== +rename_table+
|
|
488
|
+
|
|
489
|
+
You can rename an existing table using +rename_table+. Like +rename_column+,
|
|
490
|
+
the first argument is the current name, and the second is the new name:
|
|
491
|
+
|
|
492
|
+
rename_table(:artist, :artists)
|
|
493
|
+
|
|
494
|
+
=== <tt>create_table!</tt>
|
|
495
|
+
|
|
496
|
+
<tt>create_table!</tt> with the bang drops the table if it exists
|
|
497
|
+
before attempting to create it, so:
|
|
498
|
+
|
|
499
|
+
create_table!(:artists)
|
|
500
|
+
primary_key :id
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
is the same as:
|
|
504
|
+
|
|
505
|
+
drop_table(:artists) if table_exists?(:artists)
|
|
506
|
+
create_table(:artists)
|
|
507
|
+
primary_key :id
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
It should not be used inside migrations, as if the table does not exist, it may
|
|
511
|
+
mess up the migration.
|
|
512
|
+
|
|
513
|
+
=== <tt>create_table?</tt>
|
|
514
|
+
|
|
515
|
+
<tt>create_table?</tt> with a question mark only creates the table if it does
|
|
516
|
+
not already exist, so:
|
|
517
|
+
|
|
518
|
+
create_table!(:artists)
|
|
519
|
+
primary_key :id
|
|
520
|
+
end
|
|
521
|
+
|
|
522
|
+
is the same as:
|
|
523
|
+
|
|
524
|
+
create_table(:artists)
|
|
525
|
+
primary_key :id
|
|
526
|
+
end unless table_exists?(:artists)
|
|
527
|
+
|
|
528
|
+
Like <tt>create_table!</tt>, it should not be used inside migrations.
|
|
529
|
+
|
|
530
|
+
=== +create_view+ and +create_or_replace_view+
|
|
531
|
+
|
|
532
|
+
These can be used to create views. The difference between them is that
|
|
533
|
+
+create_or_replace_view+ will unconditionally replace an existing view of
|
|
534
|
+
the same name, while +create_view+ will probably raise an error. Both methods
|
|
535
|
+
take the name as the first argument, and either an string or a dataset as the
|
|
536
|
+
second argument:
|
|
537
|
+
|
|
538
|
+
create_view(:gold_albums, DB[:albums].filter{copies_sold > 500000})
|
|
539
|
+
create_or_replace_view(:gold_albums, "SELECT * FROM albums WHERE copies_sold > 500000")
|
|
540
|
+
|
|
541
|
+
=== +drop_view+
|
|
542
|
+
|
|
543
|
+
+drop_view+ drops existing views. Just like +drop_table+, it can accept multiple
|
|
544
|
+
arguments:
|
|
545
|
+
|
|
546
|
+
drop_view(:gold_albums, :platinum_albums)
|
|
547
|
+
|
data/doc/sharding.rdoc
CHANGED
|
@@ -10,7 +10,13 @@ that ship with Sequel.
|
|
|
10
10
|
|
|
11
11
|
Both features use the :servers Database option. The :servers option should
|
|
12
12
|
be a hash with symbol keys and values that are either hashes or procs that
|
|
13
|
-
return hashes.
|
|
13
|
+
return hashes. These hashes are merged into the Database object's default
|
|
14
|
+
options hash to get the connection options for the shard, so you don't need
|
|
15
|
+
to override all options, just the ones that need to be modified. For example,
|
|
16
|
+
if you are using the same user, password, and database name and just the
|
|
17
|
+
host is changing, you only need a :host entry in each shard's hash.
|
|
18
|
+
|
|
19
|
+
Note that all servers should have the same schema for all
|
|
14
20
|
tables you are accessing, unless you really know what you are doing.
|
|
15
21
|
|
|
16
22
|
== Master and Slave Database Configurations
|