colincasey-sequel 2.10.0 → 2.10.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -1
- data/doc/advanced_associations.rdoc +614 -0
- data/doc/cheat_sheet.rdoc +223 -0
- data/doc/dataset_filtering.rdoc +158 -0
- data/doc/prepared_statements.rdoc +104 -0
- data/doc/release_notes/1.0.txt +38 -0
- data/doc/release_notes/1.1.txt +143 -0
- data/doc/release_notes/1.3.txt +101 -0
- data/doc/release_notes/1.4.0.txt +53 -0
- data/doc/release_notes/1.5.0.txt +155 -0
- data/doc/release_notes/2.0.0.txt +298 -0
- data/doc/release_notes/2.1.0.txt +271 -0
- data/doc/release_notes/2.10.0.txt +328 -0
- data/doc/release_notes/2.2.0.txt +253 -0
- data/doc/release_notes/2.3.0.txt +88 -0
- data/doc/release_notes/2.4.0.txt +106 -0
- data/doc/release_notes/2.5.0.txt +137 -0
- data/doc/release_notes/2.6.0.txt +157 -0
- data/doc/release_notes/2.7.0.txt +166 -0
- data/doc/release_notes/2.8.0.txt +171 -0
- data/doc/release_notes/2.9.0.txt +97 -0
- data/doc/schema.rdoc +29 -0
- data/doc/sharding.rdoc +113 -0
- data/lib/sequel.rb +1 -0
- data/lib/sequel_core/adapters/ado.rb +89 -0
- data/lib/sequel_core/adapters/db2.rb +143 -0
- data/lib/sequel_core/adapters/dbi.rb +112 -0
- data/lib/sequel_core/adapters/do/mysql.rb +38 -0
- data/lib/sequel_core/adapters/do/postgres.rb +92 -0
- data/lib/sequel_core/adapters/do/sqlite.rb +31 -0
- data/lib/sequel_core/adapters/do.rb +205 -0
- data/lib/sequel_core/adapters/firebird.rb +298 -0
- data/lib/sequel_core/adapters/informix.rb +85 -0
- data/lib/sequel_core/adapters/jdbc/h2.rb +69 -0
- data/lib/sequel_core/adapters/jdbc/mysql.rb +66 -0
- data/lib/sequel_core/adapters/jdbc/oracle.rb +23 -0
- data/lib/sequel_core/adapters/jdbc/postgresql.rb +113 -0
- data/lib/sequel_core/adapters/jdbc/sqlite.rb +43 -0
- data/lib/sequel_core/adapters/jdbc.rb +491 -0
- data/lib/sequel_core/adapters/mysql.rb +369 -0
- data/lib/sequel_core/adapters/odbc.rb +174 -0
- data/lib/sequel_core/adapters/openbase.rb +68 -0
- data/lib/sequel_core/adapters/oracle.rb +107 -0
- data/lib/sequel_core/adapters/postgres.rb +456 -0
- data/lib/sequel_core/adapters/shared/ms_access.rb +110 -0
- data/lib/sequel_core/adapters/shared/mssql.rb +102 -0
- data/lib/sequel_core/adapters/shared/mysql.rb +325 -0
- data/lib/sequel_core/adapters/shared/oracle.rb +61 -0
- data/lib/sequel_core/adapters/shared/postgres.rb +715 -0
- data/lib/sequel_core/adapters/shared/progress.rb +31 -0
- data/lib/sequel_core/adapters/shared/sqlite.rb +265 -0
- data/lib/sequel_core/adapters/sqlite.rb +248 -0
- data/lib/sequel_core/connection_pool.rb +258 -0
- data/lib/sequel_core/core_ext.rb +217 -0
- data/lib/sequel_core/core_sql.rb +202 -0
- data/lib/sequel_core/database/schema.rb +164 -0
- data/lib/sequel_core/database.rb +691 -0
- data/lib/sequel_core/dataset/callback.rb +13 -0
- data/lib/sequel_core/dataset/convenience.rb +237 -0
- data/lib/sequel_core/dataset/pagination.rb +96 -0
- data/lib/sequel_core/dataset/prepared_statements.rb +220 -0
- data/lib/sequel_core/dataset/query.rb +41 -0
- data/lib/sequel_core/dataset/schema.rb +15 -0
- data/lib/sequel_core/dataset/sql.rb +1010 -0
- data/lib/sequel_core/dataset/stored_procedures.rb +75 -0
- data/lib/sequel_core/dataset/unsupported.rb +43 -0
- data/lib/sequel_core/dataset.rb +511 -0
- data/lib/sequel_core/deprecated.rb +26 -0
- data/lib/sequel_core/exceptions.rb +44 -0
- data/lib/sequel_core/migration.rb +212 -0
- data/lib/sequel_core/object_graph.rb +230 -0
- data/lib/sequel_core/pretty_table.rb +71 -0
- data/lib/sequel_core/schema/generator.rb +320 -0
- data/lib/sequel_core/schema/sql.rb +325 -0
- data/lib/sequel_core/schema.rb +2 -0
- data/lib/sequel_core/sql.rb +887 -0
- data/lib/sequel_core/version.rb +11 -0
- data/lib/sequel_core.rb +172 -0
- data/lib/sequel_model/association_reflection.rb +267 -0
- data/lib/sequel_model/associations.rb +499 -0
- data/lib/sequel_model/base.rb +523 -0
- data/lib/sequel_model/caching.rb +82 -0
- data/lib/sequel_model/dataset_methods.rb +26 -0
- data/lib/sequel_model/eager_loading.rb +370 -0
- data/lib/sequel_model/exceptions.rb +7 -0
- data/lib/sequel_model/hooks.rb +101 -0
- data/lib/sequel_model/inflector.rb +281 -0
- data/lib/sequel_model/plugins.rb +62 -0
- data/lib/sequel_model/record.rb +568 -0
- data/lib/sequel_model/schema.rb +49 -0
- data/lib/sequel_model/validations.rb +429 -0
- data/lib/sequel_model.rb +91 -0
- data/spec/adapters/ado_spec.rb +46 -0
- data/spec/adapters/firebird_spec.rb +376 -0
- data/spec/adapters/informix_spec.rb +96 -0
- data/spec/adapters/mysql_spec.rb +881 -0
- data/spec/adapters/oracle_spec.rb +244 -0
- data/spec/adapters/postgres_spec.rb +687 -0
- data/spec/adapters/spec_helper.rb +10 -0
- data/spec/adapters/sqlite_spec.rb +555 -0
- data/spec/integration/dataset_test.rb +134 -0
- data/spec/integration/eager_loader_test.rb +696 -0
- data/spec/integration/prepared_statement_test.rb +130 -0
- data/spec/integration/schema_test.rb +180 -0
- data/spec/integration/spec_helper.rb +58 -0
- data/spec/integration/type_test.rb +96 -0
- data/spec/rcov.opts +6 -0
- data/spec/sequel_core/connection_pool_spec.rb +526 -0
- data/spec/sequel_core/core_ext_spec.rb +156 -0
- data/spec/sequel_core/core_sql_spec.rb +522 -0
- data/spec/sequel_core/database_spec.rb +1188 -0
- data/spec/sequel_core/dataset_spec.rb +3481 -0
- data/spec/sequel_core/expression_filters_spec.rb +363 -0
- data/spec/sequel_core/migration_spec.rb +261 -0
- data/spec/sequel_core/object_graph_spec.rb +272 -0
- data/spec/sequel_core/pretty_table_spec.rb +58 -0
- data/spec/sequel_core/schema_generator_spec.rb +167 -0
- data/spec/sequel_core/schema_spec.rb +780 -0
- data/spec/sequel_core/spec_helper.rb +55 -0
- data/spec/sequel_core/version_spec.rb +7 -0
- data/spec/sequel_model/association_reflection_spec.rb +93 -0
- data/spec/sequel_model/associations_spec.rb +1767 -0
- data/spec/sequel_model/base_spec.rb +419 -0
- data/spec/sequel_model/caching_spec.rb +215 -0
- data/spec/sequel_model/dataset_methods_spec.rb +78 -0
- data/spec/sequel_model/eager_loading_spec.rb +1165 -0
- data/spec/sequel_model/hooks_spec.rb +485 -0
- data/spec/sequel_model/inflector_spec.rb +119 -0
- data/spec/sequel_model/model_spec.rb +588 -0
- data/spec/sequel_model/plugins_spec.rb +80 -0
- data/spec/sequel_model/record_spec.rb +1184 -0
- data/spec/sequel_model/schema_spec.rb +90 -0
- data/spec/sequel_model/spec_helper.rb +78 -0
- data/spec/sequel_model/validations_spec.rb +1067 -0
- data/spec/spec.opts +0 -0
- data/spec/spec_config.rb.example +10 -0
- metadata +177 -3
@@ -0,0 +1,164 @@
|
|
1
|
+
module Sequel
|
2
|
+
class Database
|
3
|
+
# Adds a column to the specified table. This method expects a column name,
|
4
|
+
# a datatype and optionally a hash with additional constraints and options:
|
5
|
+
#
|
6
|
+
# DB.add_column :items, :name, :text, :unique => true, :null => false
|
7
|
+
# DB.add_column :items, :category, :text, :default => 'ruby'
|
8
|
+
#
|
9
|
+
# See alter_table.
|
10
|
+
def add_column(table, *args)
|
11
|
+
alter_table(table) {add_column(*args)}
|
12
|
+
end
|
13
|
+
|
14
|
+
# Adds an index to a table for the given columns:
|
15
|
+
#
|
16
|
+
# DB.add_index :posts, :title
|
17
|
+
# DB.add_index :posts, [:author, :title], :unique => true
|
18
|
+
#
|
19
|
+
# See alter_table.
|
20
|
+
def add_index(table, *args)
|
21
|
+
alter_table(table) {add_index(*args)}
|
22
|
+
end
|
23
|
+
|
24
|
+
# Alters the given table with the specified block. Here are the currently
|
25
|
+
# available operations:
|
26
|
+
#
|
27
|
+
# DB.alter_table :items do
|
28
|
+
# add_column :category, :text, :default => 'ruby'
|
29
|
+
# drop_column :category
|
30
|
+
# rename_column :cntr, :counter
|
31
|
+
# set_column_type :value, :float
|
32
|
+
# set_column_default :value, :float
|
33
|
+
# add_index [:group, :category]
|
34
|
+
# drop_index [:group, :category]
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# Note that #add_column accepts all the options available for column
|
38
|
+
# definitions using create_table, and #add_index accepts all the options
|
39
|
+
# available for index definition.
|
40
|
+
#
|
41
|
+
# See Schema::AlterTableGenerator.
|
42
|
+
def alter_table(name, generator=nil, &block)
|
43
|
+
remove_cached_schema(name)
|
44
|
+
generator ||= Schema::AlterTableGenerator.new(self, &block)
|
45
|
+
alter_table_sql_list(name, generator.operations).flatten.each {|sql| execute_ddl(sql)}
|
46
|
+
end
|
47
|
+
|
48
|
+
# Creates a table with the columns given in the provided block:
|
49
|
+
#
|
50
|
+
# DB.create_table :posts do
|
51
|
+
# primary_key :id, :serial
|
52
|
+
# column :title, :text
|
53
|
+
# column :content, :text
|
54
|
+
# index :title
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
# See Schema::Generator.
|
58
|
+
def create_table(name, options={}, &block)
|
59
|
+
options = {:generator=>options} if options.is_a?(Schema::Generator)
|
60
|
+
create_table_sql_list(name, *((options[:generator] || Schema::Generator.new(self, &block)).create_info << options)).flatten.each {|sql| execute_ddl(sql)}
|
61
|
+
end
|
62
|
+
|
63
|
+
# Forcibly creates a table. If the table already exists it is dropped.
|
64
|
+
def create_table!(name, options={}, &block)
|
65
|
+
drop_table(name) rescue nil
|
66
|
+
create_table(name, options, &block)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Creates a view, replacing it if it already exists:
|
70
|
+
#
|
71
|
+
# DB.create_or_replace_view(:cheap_items, "SELECT * FROM items WHERE price < 100")
|
72
|
+
# DB.create_or_replace_view(:ruby_items, DB[:items].filter(:category => 'ruby'))
|
73
|
+
def create_or_replace_view(name, source)
|
74
|
+
remove_cached_schema(name)
|
75
|
+
source = source.sql if source.is_a?(Dataset)
|
76
|
+
execute_ddl("CREATE OR REPLACE VIEW #{quote_identifier(name)} AS #{source}")
|
77
|
+
end
|
78
|
+
|
79
|
+
# Creates a view based on a dataset or an SQL string:
|
80
|
+
#
|
81
|
+
# DB.create_view(:cheap_items, "SELECT * FROM items WHERE price < 100")
|
82
|
+
# DB.create_view(:ruby_items, DB[:items].filter(:category => 'ruby'))
|
83
|
+
def create_view(name, source)
|
84
|
+
source = source.sql if source.is_a?(Dataset)
|
85
|
+
execute_ddl("CREATE VIEW #{quote_identifier(name)} AS #{source}")
|
86
|
+
end
|
87
|
+
|
88
|
+
# Removes a column from the specified table:
|
89
|
+
#
|
90
|
+
# DB.drop_column :items, :category
|
91
|
+
#
|
92
|
+
# See alter_table.
|
93
|
+
def drop_column(table, *args)
|
94
|
+
alter_table(table) {drop_column(*args)}
|
95
|
+
end
|
96
|
+
|
97
|
+
# Removes an index for the given table and column/s:
|
98
|
+
#
|
99
|
+
# DB.drop_index :posts, :title
|
100
|
+
# DB.drop_index :posts, [:author, :title]
|
101
|
+
#
|
102
|
+
# See alter_table.
|
103
|
+
def drop_index(table, columns)
|
104
|
+
alter_table(table) {drop_index(columns)}
|
105
|
+
end
|
106
|
+
|
107
|
+
# Drops one or more tables corresponding to the given table names:
|
108
|
+
#
|
109
|
+
# DB.drop_table(:posts, :comments)
|
110
|
+
def drop_table(*names)
|
111
|
+
names.each do |n|
|
112
|
+
remove_cached_schema(n)
|
113
|
+
execute_ddl(drop_table_sql(n))
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# Drops a view:
|
118
|
+
#
|
119
|
+
# DB.drop_view(:cheap_items)
|
120
|
+
def drop_view(*names)
|
121
|
+
names.each do |n|
|
122
|
+
remove_cached_schema(n)
|
123
|
+
execute_ddl("DROP VIEW #{quote_identifier(n)}")
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Renames a table:
|
128
|
+
#
|
129
|
+
# DB.tables #=> [:items]
|
130
|
+
# DB.rename_table :items, :old_items
|
131
|
+
# DB.tables #=> [:old_items]
|
132
|
+
def rename_table(*args)
|
133
|
+
execute_ddl(rename_table_sql(*args))
|
134
|
+
end
|
135
|
+
|
136
|
+
# Renames a column in the specified table. This method expects the current
|
137
|
+
# column name and the new column name:
|
138
|
+
#
|
139
|
+
# DB.rename_column :items, :cntr, :counter
|
140
|
+
#
|
141
|
+
# See alter_table.
|
142
|
+
def rename_column(table, *args)
|
143
|
+
alter_table(table) {rename_column(*args)}
|
144
|
+
end
|
145
|
+
|
146
|
+
# Sets the default value for the given column in the given table:
|
147
|
+
#
|
148
|
+
# DB.set_column_default :items, :category, 'perl!'
|
149
|
+
#
|
150
|
+
# See alter_table.
|
151
|
+
def set_column_default(table, *args)
|
152
|
+
alter_table(table) {set_column_default(*args)}
|
153
|
+
end
|
154
|
+
|
155
|
+
# Set the data type for the given column in the given table:
|
156
|
+
#
|
157
|
+
# DB.set_column_type :items, :price, :float
|
158
|
+
#
|
159
|
+
# See alter_table.
|
160
|
+
def set_column_type(table, *args)
|
161
|
+
alter_table(table) {set_column_type(*args)}
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|