sequel 3.33.0 → 3.34.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. data/CHANGELOG +140 -0
  2. data/Rakefile +7 -0
  3. data/bin/sequel +22 -2
  4. data/doc/dataset_basics.rdoc +1 -1
  5. data/doc/mass_assignment.rdoc +3 -1
  6. data/doc/querying.rdoc +28 -4
  7. data/doc/reflection.rdoc +23 -3
  8. data/doc/release_notes/3.34.0.txt +671 -0
  9. data/doc/schema_modification.rdoc +18 -2
  10. data/doc/virtual_rows.rdoc +49 -0
  11. data/lib/sequel/adapters/do/mysql.rb +0 -5
  12. data/lib/sequel/adapters/ibmdb.rb +9 -4
  13. data/lib/sequel/adapters/jdbc.rb +9 -4
  14. data/lib/sequel/adapters/jdbc/h2.rb +8 -2
  15. data/lib/sequel/adapters/jdbc/mysql.rb +0 -5
  16. data/lib/sequel/adapters/jdbc/postgresql.rb +43 -0
  17. data/lib/sequel/adapters/jdbc/sqlite.rb +19 -0
  18. data/lib/sequel/adapters/mock.rb +24 -3
  19. data/lib/sequel/adapters/mysql.rb +29 -50
  20. data/lib/sequel/adapters/mysql2.rb +13 -28
  21. data/lib/sequel/adapters/oracle.rb +8 -2
  22. data/lib/sequel/adapters/postgres.rb +115 -20
  23. data/lib/sequel/adapters/shared/db2.rb +1 -1
  24. data/lib/sequel/adapters/shared/mssql.rb +14 -3
  25. data/lib/sequel/adapters/shared/mysql.rb +59 -11
  26. data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +6 -0
  27. data/lib/sequel/adapters/shared/oracle.rb +1 -1
  28. data/lib/sequel/adapters/shared/postgres.rb +127 -30
  29. data/lib/sequel/adapters/shared/sqlite.rb +55 -38
  30. data/lib/sequel/adapters/sqlite.rb +9 -3
  31. data/lib/sequel/adapters/swift.rb +2 -2
  32. data/lib/sequel/adapters/swift/mysql.rb +0 -5
  33. data/lib/sequel/adapters/swift/postgres.rb +10 -0
  34. data/lib/sequel/ast_transformer.rb +4 -0
  35. data/lib/sequel/connection_pool.rb +8 -0
  36. data/lib/sequel/connection_pool/sharded_single.rb +5 -0
  37. data/lib/sequel/connection_pool/sharded_threaded.rb +17 -0
  38. data/lib/sequel/connection_pool/single.rb +5 -0
  39. data/lib/sequel/connection_pool/threaded.rb +14 -0
  40. data/lib/sequel/core.rb +24 -3
  41. data/lib/sequel/database/connecting.rb +24 -14
  42. data/lib/sequel/database/dataset_defaults.rb +1 -0
  43. data/lib/sequel/database/misc.rb +16 -25
  44. data/lib/sequel/database/query.rb +20 -2
  45. data/lib/sequel/database/schema_generator.rb +2 -2
  46. data/lib/sequel/database/schema_methods.rb +120 -23
  47. data/lib/sequel/dataset/actions.rb +91 -18
  48. data/lib/sequel/dataset/features.rb +5 -0
  49. data/lib/sequel/dataset/prepared_statements.rb +6 -2
  50. data/lib/sequel/dataset/sql.rb +68 -51
  51. data/lib/sequel/extensions/_pretty_table.rb +79 -0
  52. data/lib/sequel/{core_sql.rb → extensions/core_extensions.rb} +18 -13
  53. data/lib/sequel/extensions/migration.rb +4 -0
  54. data/lib/sequel/extensions/null_dataset.rb +90 -0
  55. data/lib/sequel/extensions/pg_array.rb +460 -0
  56. data/lib/sequel/extensions/pg_array_ops.rb +220 -0
  57. data/lib/sequel/extensions/pg_auto_parameterize.rb +174 -0
  58. data/lib/sequel/extensions/pg_hstore.rb +296 -0
  59. data/lib/sequel/extensions/pg_hstore_ops.rb +259 -0
  60. data/lib/sequel/extensions/pg_statement_cache.rb +316 -0
  61. data/lib/sequel/extensions/pretty_table.rb +5 -71
  62. data/lib/sequel/extensions/query_literals.rb +79 -0
  63. data/lib/sequel/extensions/schema_caching.rb +76 -0
  64. data/lib/sequel/extensions/schema_dumper.rb +227 -31
  65. data/lib/sequel/extensions/select_remove.rb +35 -0
  66. data/lib/sequel/extensions/sql_expr.rb +4 -110
  67. data/lib/sequel/extensions/to_dot.rb +1 -1
  68. data/lib/sequel/model.rb +11 -2
  69. data/lib/sequel/model/associations.rb +35 -7
  70. data/lib/sequel/model/base.rb +159 -36
  71. data/lib/sequel/no_core_ext.rb +2 -0
  72. data/lib/sequel/plugins/caching.rb +25 -18
  73. data/lib/sequel/plugins/composition.rb +1 -1
  74. data/lib/sequel/plugins/hook_class_methods.rb +1 -1
  75. data/lib/sequel/plugins/identity_map.rb +11 -3
  76. data/lib/sequel/plugins/instance_filters.rb +10 -0
  77. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +71 -0
  78. data/lib/sequel/plugins/nested_attributes.rb +4 -3
  79. data/lib/sequel/plugins/prepared_statements.rb +3 -1
  80. data/lib/sequel/plugins/prepared_statements_associations.rb +5 -1
  81. data/lib/sequel/plugins/schema.rb +7 -2
  82. data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
  83. data/lib/sequel/plugins/static_cache.rb +99 -0
  84. data/lib/sequel/plugins/validation_class_methods.rb +1 -1
  85. data/lib/sequel/sql.rb +417 -7
  86. data/lib/sequel/version.rb +1 -1
  87. data/spec/adapters/firebird_spec.rb +1 -1
  88. data/spec/adapters/mssql_spec.rb +12 -15
  89. data/spec/adapters/mysql_spec.rb +81 -23
  90. data/spec/adapters/postgres_spec.rb +444 -77
  91. data/spec/adapters/spec_helper.rb +2 -0
  92. data/spec/adapters/sqlite_spec.rb +8 -8
  93. data/spec/core/connection_pool_spec.rb +85 -0
  94. data/spec/core/database_spec.rb +29 -5
  95. data/spec/core/dataset_spec.rb +171 -3
  96. data/spec/core/expression_filters_spec.rb +364 -0
  97. data/spec/core/mock_adapter_spec.rb +17 -3
  98. data/spec/core/schema_spec.rb +133 -0
  99. data/spec/extensions/association_dependencies_spec.rb +13 -13
  100. data/spec/extensions/caching_spec.rb +26 -3
  101. data/spec/extensions/class_table_inheritance_spec.rb +2 -2
  102. data/spec/{core/core_sql_spec.rb → extensions/core_extensions_spec.rb} +23 -94
  103. data/spec/extensions/force_encoding_spec.rb +4 -2
  104. data/spec/extensions/hook_class_methods_spec.rb +5 -2
  105. data/spec/extensions/identity_map_spec.rb +17 -0
  106. data/spec/extensions/instance_filters_spec.rb +1 -1
  107. data/spec/extensions/lazy_attributes_spec.rb +2 -2
  108. data/spec/extensions/list_spec.rb +4 -4
  109. data/spec/extensions/many_to_one_pk_lookup_spec.rb +140 -0
  110. data/spec/extensions/migration_spec.rb +6 -2
  111. data/spec/extensions/nested_attributes_spec.rb +20 -0
  112. data/spec/extensions/null_dataset_spec.rb +85 -0
  113. data/spec/extensions/optimistic_locking_spec.rb +2 -2
  114. data/spec/extensions/pg_array_ops_spec.rb +105 -0
  115. data/spec/extensions/pg_array_spec.rb +196 -0
  116. data/spec/extensions/pg_auto_parameterize_spec.rb +64 -0
  117. data/spec/extensions/pg_hstore_ops_spec.rb +136 -0
  118. data/spec/extensions/pg_hstore_spec.rb +195 -0
  119. data/spec/extensions/pg_statement_cache_spec.rb +209 -0
  120. data/spec/extensions/prepared_statements_spec.rb +4 -0
  121. data/spec/extensions/pretty_table_spec.rb +6 -0
  122. data/spec/extensions/query_literals_spec.rb +168 -0
  123. data/spec/extensions/schema_caching_spec.rb +41 -0
  124. data/spec/extensions/schema_dumper_spec.rb +231 -11
  125. data/spec/extensions/schema_spec.rb +14 -2
  126. data/spec/extensions/select_remove_spec.rb +38 -0
  127. data/spec/extensions/sharding_spec.rb +6 -6
  128. data/spec/extensions/skip_create_refresh_spec.rb +1 -1
  129. data/spec/extensions/spec_helper.rb +2 -1
  130. data/spec/extensions/sql_expr_spec.rb +28 -19
  131. data/spec/extensions/static_cache_spec.rb +145 -0
  132. data/spec/extensions/touch_spec.rb +1 -1
  133. data/spec/extensions/typecast_on_load_spec.rb +9 -1
  134. data/spec/integration/associations_test.rb +6 -6
  135. data/spec/integration/database_test.rb +1 -1
  136. data/spec/integration/dataset_test.rb +89 -26
  137. data/spec/integration/migrator_test.rb +2 -3
  138. data/spec/integration/model_test.rb +3 -3
  139. data/spec/integration/plugin_test.rb +85 -22
  140. data/spec/integration/prepared_statement_test.rb +28 -8
  141. data/spec/integration/schema_test.rb +78 -7
  142. data/spec/integration/spec_helper.rb +1 -0
  143. data/spec/integration/timezone_test.rb +1 -1
  144. data/spec/integration/transaction_test.rb +4 -6
  145. data/spec/integration/type_test.rb +2 -2
  146. data/spec/model/associations_spec.rb +94 -8
  147. data/spec/model/base_spec.rb +4 -4
  148. data/spec/model/hooks_spec.rb +2 -2
  149. data/spec/model/model_spec.rb +19 -7
  150. data/spec/model/record_spec.rb +135 -58
  151. data/spec/model/spec_helper.rb +1 -0
  152. metadata +35 -7
data/CHANGELOG CHANGED
@@ -1,3 +1,143 @@
1
+ === 3.34.0 (2012-04-02)
2
+
3
+ * Fix connection failures when connecting to PostgreSQL with newer versions of swift (jeremyevans)
4
+
5
+ * Fix using a bound variable for a limit in the ibmdb adapter on ruby 1.9 (jeremyevans)
6
+
7
+ * primary_key :column, :type=>Bignum now works correctly on H2 (jeremyevans)
8
+
9
+ * Add query_literals extension for treating regular strings like literal strings in select, group, and order methods (jeremyevans)
10
+
11
+ * Actually use RETURNING for deletes/updates on PostgreSQL 8.2-9.0 (jeremyevans)
12
+
13
+ * You can now require 'sequel/no_core_ext' to load Sequel without the core extensions (jeremyevans)
14
+
15
+ * The core extensions have now been made a real Sequel extension (still loaded by default) (jeremyevans)
16
+
17
+ * VirtualRow#` has been added for creating literal strings (jeremyevans)
18
+
19
+ * VirtualRow instances now have operator methods defined {+,-,*,/,&,|,~,>,<,>=,<=} (jeremyevans)
20
+
21
+ * Array#all_two_pairs? is now deprecated and will be removed after 3.34.0 is released (jeremyevans)
22
+
23
+ * All of Sequel's core extensions now have equivalent methods defined on the Sequel module (jeremyevans)
24
+
25
+ * Add Sequel.core_extensions? for checking if the core extensions are enabled (jeremyevans)
26
+
27
+ * Increase speed of Model#this by about 85% (jeremyevans)
28
+
29
+ * Increase speed of Model#delete and #destroy by about 75% for models with simple datasets (jeremyevans)
30
+
31
+ * Make nested_attributes plugin work when destroying/removing associated objects when strict_param_setting is true (r-stu31) (#455)
32
+
33
+ * Dataset#disable_insert_returning on PostgreSQL is now deprecated and will be removed after 3.34.0 is released (jeremyevans)
34
+
35
+ * Double speed of Model[pk] for models with simple datasets (most models) (jeremyevans)
36
+
37
+ * Support for ruby <1.8.7 and PostgreSQL <8.2 is now deprecated and will be removed after 3.34.0 is released (jeremyevans)
38
+
39
+ * Add select_remove extension which adds Dataset#select_remove for removing columns/expressions from a dataset selection (jeremyevans)
40
+
41
+ * Add static_cache plugin, for staticly caching all model instances, useful for model tables that don't change (jeremyevans)
42
+
43
+ * Add Model#freeze implementation to get a working frozen model object (jeremyevans)
44
+
45
+ * Add many_to_one_pk_lookup plugin, for using a simple primary key lookup for many_to_one associations (great with caching) (jeremyevans)
46
+
47
+ * Use bigint type instead of integer for Bignum generic type on SQLite, except for auto incrementing primary keys (jeremyevans)
48
+
49
+ * Add Database#dump_foreign_key_migration for just dumping foreign key constraints to the schema dumper extension (jeremyevans)
50
+
51
+ * Dump foreign key constraints by default when using the schema dumper extension (jeremyevans)
52
+
53
+ * Don't raise an error when no indexes exist for a table when calling Database#indexes on the jdbc/sqlite adapter (jeremyevans)
54
+
55
+ * Copy composite foreign key constraints when emulating alter_table on SQLite (jeremyevans)
56
+
57
+ * Add Database#foreign_key_list for getting foreign key metadata for a given table on SQLite, MySQL, and PostgreSQL (jeremyevans)
58
+
59
+ * Add Dataset#to_hash_groups and #select_hash_groups for getting a hash with arrays of matching values (jeremyevans)
60
+
61
+ * Model#set_fields and #update_fields now respect :missing=>:skip and :missing=>:raise options for handling missing values (jeremyevans)
62
+
63
+ * The :on_update and :on_delete entries for foreign key can now take strings, which are used literally (jeremyevans)
64
+
65
+ * Add Database#convert_infinite_timestamps to the postgres adapter, can be set to :nil, :string, or :float (jeremyevans) (#454)
66
+
67
+ * Add Database#create_join_table and #drop_join_table for easily creating many-to-many join tables (jeremyevans)
68
+
69
+ * Fix Dataset#group_rollup/#group_cube on Microsoft SQL Server 2005 (jeremyevans)
70
+
71
+ * Add Dataset#explain on MySQL (jeremyevans)
72
+
73
+ * Change formatting and return value of Dataset#explain on SQLite (jeremyevans)
74
+
75
+ * Recognize unsigned tinyint types in the schema dumper (jeremyevans)
76
+
77
+ * Add null_dataset extension, for creating a dataset that never issues a database query (jeremyevans)
78
+
79
+ * Database#uri and #url now return nil if a connection string was not used when connecting (jeremyevans) (#453)
80
+
81
+ * Add schema_caching extension, to speed up loading a large number of models by loading cached schema information from a file (jeremyevans)
82
+
83
+ * Add Dataset#multi_replace on MySQL, allowing you to REPLACE multiple rows in a single query (danielb2) (#452)
84
+
85
+ * Double speed of Model#new with empty hash, and quadruple speed of Model#set with empty hash (jeremyevans)
86
+
87
+ * Allow SQL::QualifiedIdentifier objects to contain arbitrary Sequel expressions (jeremyevans)
88
+
89
+ * Add pg_hstore_ops extension, for easily calling PostgreSQL hstore functions and operators (jeremyevans)
90
+
91
+ * Add Sequel::SQL::Wrapper class for easier dealing with wrapper objects (jeremyevans)
92
+
93
+ * Add pg_hstore extension, for dealing with the PostgreSQL hstore (key/value table) type (jeremyevans)
94
+
95
+ * Add Database#type_supported? method on PostgreSQL for checking if the given type symbol/string is supported (jeremyevans)
96
+
97
+ * Convert Java::OrgPostgresqlUtil::PGobject instances to ruby strings in jdbc/postgres type conversion (jeremyevans)
98
+
99
+ * Allow PlaceholderLiteralString objects to store placeholder string as an array for improved performance (jeremyevans)
100
+
101
+ * Work around ruby-pg bugs 111 (Time/DateTime fractional seconds) and 112 ("\0" in bytea) in bound variable arguments (jeremyevans) (#450)
102
+
103
+ * Handle fractional seconds correctly for time type on jdbc/postgres (jeremyevans)
104
+
105
+ * Add pg_array_ops extension, for easily calling PostgreSQL array functions and operators (jeremyevans)
106
+
107
+ * Add SQL::Subscript#[] for using nested subscripts (accessing member of multi-dimensional array) (jeremyevans)
108
+
109
+ * Add Model.cache_anonymous_models accessor so you can disable the caching of classes created by Sequel::Model() (jeremyevans)
110
+
111
+ * Convert PostgreSQL JDBC arrays to Ruby arrays in the jdbc/postgres adapter (jeremyevans)
112
+
113
+ * The typecast_on_load extension now works correctly when saving new model objects when insert_select is enabled (jeremyevans)
114
+
115
+ * Add pg_array extension, for dealing with string and numeric PostgreSQL arrays (jeremyevans)
116
+
117
+ * Add Database#reset_conversion_procs to the postgres adapter, for use with extensions with modify default conversion procs (jeremyevans)
118
+
119
+ * Escape table and schema names when getting primary key or sequence information on PostgreSQL (jeremyevans)
120
+
121
+ * Escape identifiers when quoting on MySQL and SQLite (jeremyevans)
122
+
123
+ * Add Database#supports_drop_table_if_exists? for checking if DROP TABLE supports IF EXISTS (jeremyevans)
124
+
125
+ * Add Database#drop_table? for dropping a table if it already exists (jeremyevans)
126
+
127
+ * Log full SQL string by default for prepared statements created automatically by model prepared_statements* plugins (jeremyevans)
128
+
129
+ * Add ability for prepared statements to log full SQL string (jeremyevans)
130
+
131
+ * Add pg_statement_cache extension, for automatically preparing queries when using postgres adapter with pg driver (jeremyevans)
132
+
133
+ * Add pg_auto_parameterize extension, for automatically parameterizing queries when using postgres adapter with pg driver (jeremyevans)
134
+
135
+ * Add ConnectionPool#disconnection_proc= method, to modify disconnection_proc after the pool has been created (jeremyevans)
136
+
137
+ * Add ConnectionPool#after_connect= method, to modify after_connect proc after the pool has been created (jeremyevans)
138
+
139
+ * Add ConnectionPool#all_connections method, which yields all available connections in the pool (jeremyevans)
140
+
1
141
  === 3.33.0 (2012-03-01)
2
142
 
3
143
  * Add ability to force or disable transactions completely in the migrators using the :use_transactions option (jeremyevans)
data/Rakefile CHANGED
@@ -139,12 +139,19 @@ begin
139
139
  spec_with_cov.call("spec", Dir["spec/{core,model}/*_spec.rb"], "Run core and model specs"){|t| t.rcov_opts.concat(%w'--exclude "lib/sequel/adapters/([a-ln-z]|m[a-np-z])"')}
140
140
  spec.call("spec_core", Dir["spec/core/*_spec.rb"], "Run core specs")
141
141
  spec.call("spec_model", Dir["spec/model/*_spec.rb"], "Run model specs")
142
+ spec.call("_spec_model_no_assoc", Dir["spec/model/*_spec.rb"].delete_if{|f| f =~ /association|eager_loading/}, '')
142
143
  spec_with_cov.call("spec_plugin", Dir["spec/extensions/*_spec.rb"], "Run extension/plugin specs")
143
144
  spec_with_cov.call("spec_integration", Dir["spec/integration/*_test.rb"], "Run integration tests")
144
145
 
145
146
  %w'postgres sqlite mysql informix oracle firebird mssql db2'.each do |adapter|
146
147
  spec_with_cov.call("spec_#{adapter}", ["spec/adapters/#{adapter}_spec.rb"] + Dir["spec/integration/*_test.rb"], "Run #{adapter} specs")
147
148
  end
149
+
150
+ desc "Run model specs without the associations code"
151
+ task :spec_model_no_assoc do
152
+ ENV['SEQUEL_NO_ASSOCIATIONS'] = '1'
153
+ Rake::Task['_spec_model_no_assoc'].invoke
154
+ end
148
155
  rescue LoadError
149
156
  task :default do
150
157
  puts "Must install rspec to run the default task (which runs specs)"
data/bin/sequel CHANGED
@@ -7,6 +7,7 @@ require 'sequel'
7
7
  db_opts = {:test=>true}
8
8
  copy_databases = nil
9
9
  dump_migration = nil
10
+ dump_schema = nil
10
11
  echo = nil
11
12
  env = nil
12
13
  logfile = nil
@@ -14,6 +15,7 @@ migrate_dir = nil
14
15
  migrate_ver = nil
15
16
  backtrace = nil
16
17
  load_dirs = []
18
+ exclusive_options = []
17
19
 
18
20
  opts = OptionParser.new do |opts|
19
21
  opts.banner = "Sequel: The Database Toolkit for Ruby"
@@ -39,10 +41,12 @@ opts = OptionParser.new do |opts|
39
41
 
40
42
  opts.on("-d", "--dump-migration", "print database migration to STDOUT") do
41
43
  dump_migration = true
44
+ exclusive_options << :d
42
45
  end
43
46
 
44
47
  opts.on("-D", "--dump-migration-same-db", "print database migration to STDOUT without type translation") do
45
48
  dump_migration = :same_db
49
+ exclusive_options << :D
46
50
  end
47
51
 
48
52
  opts.on("-e", "--env ENV", "use environment config for database") do |v|
@@ -67,6 +71,7 @@ opts = OptionParser.new do |opts|
67
71
 
68
72
  opts.on("-m", "--migrate-directory DIR", "run the migrations in directory") do |v|
69
73
  migrate_dir = v
74
+ exclusive_options << :m
70
75
  end
71
76
 
72
77
  opts.on("-M", "--migrate-version VER", "migrate the database to version given") do |v|
@@ -81,6 +86,11 @@ opts = OptionParser.new do |opts|
81
86
  load_dirs << [v]
82
87
  end
83
88
 
89
+ opts.on("-S", "--dump-schema filename", "dump the schema for all tables to the file") do |v|
90
+ dump_schema = v
91
+ exclusive_options << :S
92
+ end
93
+
84
94
  opts.on("-t", "--trace", "Output the full backtrace if an exception is raised") do
85
95
  backtrace = true
86
96
  end
@@ -100,8 +110,7 @@ error_proc = lambda do |msg|
100
110
  end
101
111
 
102
112
  error_proc["Error: Must specify -m if using -M"] if migrate_ver && !migrate_dir
103
- error_proc["Error: Cannot specify -D or -d with -m"] if dump_migration && migrate_dir
104
- error_proc["Error: Cannot specify -C with -d, -D, or -m"] if copy_databases && (dump_migration || migrate_dir)
113
+ error_proc["Error: Cannot specify #{exclusive_options.map{|v| "-#{v}"}.join(' and ')} together"] if exclusive_options.length > 1
105
114
 
106
115
  if logfile || echo
107
116
  require 'logger'
@@ -139,6 +148,12 @@ begin
139
148
  puts DB.dump_schema_migration(:same_db=>dump_migration==:same_db)
140
149
  exit
141
150
  end
151
+ if dump_schema
152
+ Sequel.extension :schema_caching
153
+ DB.tables.each{|t| DB.schema(Sequel::SQL::Identifier.new(t))}
154
+ DB.dump_schema_cache(dump_schema)
155
+ exit
156
+ end
142
157
  if copy_databases
143
158
  Sequel.extension :migration, :schema_dumper
144
159
 
@@ -151,6 +166,7 @@ begin
151
166
  puts "Databases connections successful"
152
167
  schema_migration = eval(DB.dump_schema_migration(:indexes=>false, :same_db=>same_db))
153
168
  index_migration = eval(DB.dump_indexes_migration(:same_db=>same_db))
169
+ fk_migration = eval(DB.dump_foreign_key_migration(:same_db=>same_db))
154
170
  puts "Migrations dumped successfully"
155
171
 
156
172
  schema_migration.apply(TO_DB, :up)
@@ -182,6 +198,10 @@ begin
182
198
  index_migration.apply(TO_DB, :up)
183
199
  puts "Finished creating indexes"
184
200
 
201
+ puts "Begin adding foreign key constraints"
202
+ fk_migration.apply(TO_DB, :up)
203
+ puts "Finished adding foreign key constraints"
204
+
185
205
  if TO_DB.database_type == :postgres
186
206
  TO_DB.tables.each{|t| TO_DB.reset_primary_key_sequence(t)}
187
207
  puts "Primary key sequences reset successfully"
@@ -93,7 +93,7 @@ other:: clone, distinct, naked, server, with_sql
93
93
 
94
94
  Most other dataset methods commonly used will execute the dataset's SQL on the database:
95
95
 
96
- SELECT (All Records):: all, each, map, to_hash, select_map, select_order_map, select_hash, to_csv
96
+ SELECT (All Records):: all, each, map, to_hash, to_hash_groups, select_map, select_order_map, select_hash, select_hash_groups, to_csv
97
97
  SELECT (First Record):: first, last, get, []
98
98
  SELECT (Aggregates):: count, avg, max, min, sum, range, interval
99
99
  INSERT:: insert, <<, import, multi_insert, insert_multiple
@@ -36,7 +36,7 @@ By default, if an invalid setter method call is attempted, Sequel raises a <tt>S
36
36
  # Instance level
37
37
  post.strict_param_setting = false
38
38
 
39
- These mass assignment methods have been around a long time, but starting in Sequel 3.12.0, the +set_fields+ or +update_fields+ methods were added, and these may be a better mass assignment choice for most users.
39
+ These mass assignment methods have been around a long time, but starting in Sequel 3.12.0, the +set_fields+ and +update_fields+ methods were added, and these may be a better mass assignment choice for most users.
40
40
  These methods take two arguments, the attributes hash as the first argument, and a single array of valid field names as the second argument:
41
41
 
42
42
  post.set_fields(params[:post], [:title, :body])
@@ -50,5 +50,7 @@ They work great for things like HTML forms where the form fields are static.
50
50
  +set_only+ and +update_only+ are designed for cases where you are not sure what fields are going to be present in the input, but still want to make sure only certain setter methods can be called.
51
51
  They work great for flexible APIs.
52
52
 
53
+ Starting in Sequel 3.34.0, +set_fields+ and +update_fields+ take an optional argument hash, and currently handles the :missing option. With <tt>:missing=>:skip</tt>, +set_fields+ and +update_fields+ will just skip missing entries in the hash, allowing them to be used in flexible APIs. With <tt>:missing=>:raise</tt>, +set_fields+ and +update_fields+ will raise an error if one of the entries in the hash is missing, instead of just assigning the value to nil or whatever the hash's default value is. That allows stricter checks, similar to the :strict_param_checking setting for the default mass assignment methods.
54
+
53
55
  In all of the mass assignment cases, methods starting with +set+ will set the attributes without saving the object, while methods starting with +update+ will set the attributes and then save the changes to the object.
54
56
 
data/doc/querying.rdoc CHANGED
@@ -167,17 +167,26 @@ It's also common to want to order such a map, so Sequel provides a
167
167
  Sequel makes it easy to take an SQL query and return it as a ruby hash,
168
168
  using the +to_hash+ method:
169
169
 
170
- artist_names = Artist.to_hash(:name, :id)
170
+ artist_names = Artist.to_hash(:id, :name)
171
171
  # SELECT * FROM artists
172
- => {"YJM"=>1, "AS"=>2}
172
+ => {1=>"YJM", 2=>"AS"}
173
173
 
174
174
  As you can see, the +to_hash+ method uses the first symbol as the key
175
175
  and the second symbol as the value. So if you swap the two arguments the hash
176
176
  will have its keys and values transposed:
177
177
 
178
- artist_names = Artist.to_hash(:id, :name)
178
+ artist_names = Artist.to_hash(:name, :id)
179
179
  # SELECT * FROM artists
180
- => {1=>"YJM", 2=>"AS"}
180
+ => {"YJM"=>1, "AS"=>2}
181
+
182
+ Now what if you have multiple values for the same key? By default, +to_hash+
183
+ will just have the last matching value. If you care about all matching values,
184
+ use +to_hash_groups+, which makes the values of the array an array of matching
185
+ values, in the order they were received:
186
+
187
+ artist_names = Artist.to_hash_groups(:name, :id)
188
+ # SELECT * FROM artists
189
+ => {"YJM"=>[1, 10, ...], "AS"=>[2, 20, ...]}
181
190
 
182
191
  If you only provide one argument to +to_hash+, it uses the entire hash
183
192
  or model object as the value:
@@ -186,6 +195,12 @@ or model object as the value:
186
195
  # SELECT * FROM artists
187
196
  => {"YJM"=>{:id=>1, :name=>"YJM"}, "AS"=>{:id=>2, :name=>"AS"}}
188
197
 
198
+ and +to_hash_groups+ works similarly:
199
+
200
+ artist_names = DB[:artists].to_hash_groups(:name)
201
+ # SELECT * FROM artists
202
+ => {"YJM"=>[{:id=>1, :name=>"YJM"}, {:id=>10, :name=>"YJM"}], ...}
203
+
189
204
  Model datasets have a +to_hash+ method that can be called without any
190
205
  arguments, in which case it will use the primary key as the key and
191
206
  the model object as the value. This can be used to easily create an
@@ -196,6 +211,9 @@ identity map:
196
211
  => {1=>#<Artist @values={:id=>1, :name=>"YGM"}>,
197
212
  2=>#<Artist @values={:id=>2, :name=>"AS"}>}
198
213
 
214
+ There is no equivalent handling to +to_hash_groups+, since there would
215
+ only be one matching record, as the primary key must be unique.
216
+
199
217
  Note that +to_hash+ never modifies the columns selected. However, just
200
218
  like Sequel has a +select_map+ method to modify the columns selected and
201
219
  return an array, Sequel also has a +select_hash+ method to modify the
@@ -205,6 +223,12 @@ columns selected and return a hash:
205
223
  # SELECT name, id FROM artists
206
224
  => {"YJM"=>1, "AS"=>2}
207
225
 
226
+ Likewise, +select_hash_groups+ also exists:
227
+
228
+ artist_names = Artist.select_hash_groups(:name, :id)
229
+ # SELECT name, id FROM artists
230
+ => {"YJM"=>[1, 10, ...], "AS"=>[2, 20, ...]}
231
+
208
232
  == Modifying datasets
209
233
 
210
234
  Note that the retrieval methods discussed above just return
data/doc/reflection.rdoc CHANGED
@@ -4,9 +4,9 @@ Sequel supports reflection information in multiple ways.
4
4
 
5
5
  == Adapter in Use
6
6
 
7
- You can get the adapter in use using Database.adapter_scheme. As this is a class method, you generally need to do DB.class.adapter_scheme:
7
+ You can get the adapter in use using Database#adapter_scheme:
8
8
 
9
- DB.class.adapter_scheme # e.g. :postgres, :jdbc, :odbc
9
+ DB.adapter_scheme # e.g. :postgres, :jdbc, :odbc
10
10
 
11
11
  == Database Connected To
12
12
 
@@ -24,7 +24,7 @@ Database#tables gives an array of table name symbols:
24
24
 
25
25
  Database#views and gives an array of view name symbols:
26
26
 
27
- DB.tables # [:table1, :table2, :table3, ...]
27
+ DB.views # [:view1, :view2, :view3, ...]
28
28
 
29
29
  == Indexes on a table
30
30
 
@@ -34,6 +34,26 @@ Database#indexes takes a table name gives a hash of index information. Keys are
34
34
 
35
35
  Index information generally does not include partial indexes, functional indexes, or indexes on the primary key of the table.
36
36
 
37
+ == Foreign Key Information for a Table
38
+
39
+ Database#foreign_key_list takes a table name and gives an array of hashes of foreign key information:
40
+
41
+ DB.foreign_key_list(:table1) # [{:columns=>[:column1], :table=>:referenced_table, :key=>[:referenced_column1]}]
42
+
43
+ At least the following entries will be present in the hash:
44
+
45
+ :columns :: An array of columns in the given table
46
+ :table :: The table referenced by the columns
47
+ :key :: An array of columns referenced (in the table specified by :table), but can be nil on certain adapters
48
+ if the primary key is referenced.
49
+
50
+ The hash may also contain entries for:
51
+
52
+ :deferrable :: Whether the constraint is deferrable
53
+ :name :: The name of the constraint
54
+ :on_delete :: The action to take ON DELETE
55
+ :on_update :: The action to take ON UPDATE
56
+
37
57
  == Column Information for a Table
38
58
 
39
59
  Database#schema takes a table symbol and returns column information in an array with each element being an array with two elements. The first elements of the subarray is a column symbol, and the second element is a hash of information about that column. The hash should include the following keys:
@@ -0,0 +1,671 @@
1
+ = New PostgreSQL Extensions
2
+
3
+ * A pg_array extension has been added, supporting PostgreSQL's
4
+ numeric and string array types. Both single dimensional and
5
+ multi-dimensional array types are supported. Array values are
6
+ returned as instances of Sequel::Postgres::PGArray, which is a
7
+ delegate class of Array. You can turn an existing array into
8
+ a PGArray using Array#pg_array.
9
+
10
+ If you are using arrays in model objects, you need to load
11
+ support for that:
12
+
13
+ DB.extend Sequel::Postgres::PGArray::DatabaseMethods
14
+
15
+ This makes schema parsing and typecasting of array columns work
16
+ correctly.
17
+
18
+ This extension also allows you to use PGArray objects and arrays
19
+ in bound variables when using the postgres adapter with pg.
20
+
21
+ * A pg_hstore extension has been added, supporting PostgreSQL's hstore
22
+ type, which is a simple hash with string keys and string or NULL
23
+ values. hstore values are retrieved as instances of
24
+ Sequel::Postgres::HStore, which is a delegate class of Hash. You
25
+ can turn an existing hash into an hstore using Hash#hstore.
26
+
27
+ If you are using hstores in model objects, you need to load
28
+ support for that:
29
+
30
+ DB.extend Sequel::Postgres::HStore::DatabaseMethods
31
+
32
+ This makes schema parsing and typecasting of hstore columns work
33
+ correctly.
34
+
35
+ This extension also allows you to use HStore objects and hashes
36
+ in bound variables when using the postgres adapter with pg.
37
+
38
+ * A pg_array_ops extension has been added, making it easier to call
39
+ PostgreSQL array operators and functions using plain ruby code.
40
+ Examples:
41
+
42
+ a = :array_column.pg_array
43
+ a[1] # array_column[1]
44
+ a[1][2] # array_column[1][2]
45
+ a.push(1) # array_column || 1
46
+ a.unshift(1) # 1 || array_column
47
+ a.any # ANY(array_column)
48
+ a.join # array_to_string(array_column, '', NULL)
49
+
50
+ If you are also using the pg_array extension, you can turn
51
+ a PGArray object into a query object, which allows you to run
52
+ operations on array literals:
53
+
54
+ a = [1, 2].pg_array.op
55
+ a.push(3) # ARRAY[1,2] || 3
56
+
57
+ * A pg_hstore_ops extension has been added, making it easier to call
58
+ PostgreSQL hstore operators and functions using plain ruby code.
59
+ Examples:
60
+
61
+ h = :hstore_column.hstore
62
+ h['a'] # hstore_column -> 'a'
63
+ h.has_key?('a') # hstore_column ? 'a'
64
+ h.keys # akeys(hstore_column)
65
+ h.to_array # hstore_to_array(hstore_column)
66
+
67
+ If you are also using the pg_hstore extension, you can turn
68
+ an HStore object into a query object, which allows you to run
69
+ operations on hstore literals:
70
+
71
+ h = {'a' => 'b'}.hstore.op
72
+ h[a] # '"a"=>"b"'::hstore -> 'a'
73
+
74
+ * A pg_auto_parameterize extension has been added for automatically
75
+ using bound variables for all queries. For example, it can take
76
+ code such as:
77
+
78
+ DB[:table].where(:column=>1)
79
+
80
+ and do:
81
+
82
+ SELECT * FROM table WHERE column = $1; -- [1]
83
+
84
+ Note that automatically parameterizing queries is not generally
85
+ faster unless the bound variables are large (i.e. long text/bytea
86
+ values). Also, there are multiple corner cases when automatically
87
+ parameterizing queries, though most can be worked around by
88
+ adding explicit casts.
89
+
90
+ * A pg_statement_cache extension has been added that works with the
91
+ pg_auto_parameterize extension for automatically caching prepared
92
+ statements and reusing them when using the postgres adapter with
93
+ pg. The combination of these two extensions makes it possible to
94
+ take an entire Sequel application and turn most or all of the
95
+ queries into prepared statements.
96
+
97
+ Note that these two extensions do not necessarily improve
98
+ performance. For simple queries, they actually hurt performance.
99
+ They do help for complex queries, but in all cases, it's faster
100
+ to use Sequel's prepared statements API manually.
101
+
102
+ = Other New Extensions
103
+
104
+ * A query_literals extension has been added that makes the select,
105
+ group, and order methods operate similar to the filter methods in
106
+ that if they are given a regular string as their first argument,
107
+ they treat it as a literal string, with additional arguments, if
108
+ any, used as placeholder values. This extension allows you to
109
+ write code such as:
110
+
111
+ DB[:table].select('a, b, ?' 2).group('a, b').order('c')
112
+ # Without query_literals:
113
+ # SELECT 'a, b, ?', 2 FROM table GROUP BY 'a, b' ORDER BY 'c'
114
+ # With query_literals:
115
+ # SELECT a, b, 2 FROM table GROUP BY a, b ORDER BY c
116
+
117
+ Sequel's default handling in this case is to use literal strings,
118
+ which is generally not desired and on some databases not even
119
+ valid syntax. In general, you'll probably want to use this
120
+ extension for all of a database's datasets, which you can do via:
121
+
122
+ Sequel.extension :query_literals
123
+ DB.extend_datasets(Sequel::QueryLiterals)
124
+
125
+ The next major version of Sequel (4.0.0) will probably integrate
126
+ this extension into the core library.
127
+
128
+ * A select_remove extension has been added that adds
129
+ Dataset#select_remove, for removing selected columns/expressions
130
+ from a dataset:
131
+
132
+ ds = DB[:table]
133
+ # Assume table has columns a, b, and c
134
+
135
+ ds.select_remove(:c)
136
+ # SELECT a, b FROM table
137
+
138
+ # Removal by column alias
139
+ ds.select(:a, :b___c, :c___b).select_remove(:c)
140
+ # SELECT a, c AS b FROM table
141
+
142
+ # Removal by expression
143
+ ds.select(:a, :b___c, :c___b).select_remove(:c___b)
144
+ # SELECT a, b AS c FROM table
145
+
146
+ This method makes it easier to select all columns except for the
147
+ columns given. This is common in cases where a table has a few
148
+ large columns that are expensive to retrieve. This method does
149
+ have some corner cases, so read the documentation before using it.
150
+
151
+ * A schema_caching extension has added that makes it possible for
152
+ Database instances to dump the cached schema metadata to a
153
+ marshalled file, and load the cached schema metadata from the file.
154
+ This can be significantly faster than reparsing the schema from the
155
+ database, especially for databases with high latency.
156
+
157
+ bin/sequel -S has been added to dump the schema for the given
158
+ database to a file, and DB.load_schema_cache(filename) can be used
159
+ to populate the schema cache inside your application. This should
160
+ be done after creating the Database object but before loading your
161
+ model files.
162
+
163
+ Note that Sequel does no checking to ensure that the cached schema
164
+ currently reflects the state of the database. That is up to the
165
+ application.
166
+
167
+ * A null_dataset extension has been added, which adds
168
+ Dataset#nullify for creating a dataset that will not issue a
169
+ database query. It implements the null object pattern for
170
+ datasets, and is probably most useful in methods that must return
171
+ a dataset, but can determine that such a dataset will never return
172
+ a row.
173
+
174
+ = New Plugins
175
+
176
+ * A static_cache plugin has been added, allowing you to cache a model
177
+ statically. This plugin is useful for models whose tables do not
178
+ change while the application is running, such as lookup tables.
179
+ When using this plugin, the following methods will no longer require
180
+ queries:
181
+
182
+ * Primary key lookups (e.g. Model[1])
183
+ * Model.all calls
184
+ * Model.each calls
185
+ * Model.map calls without an argument
186
+ * Model.to_hash calls without an argument
187
+
188
+ The statically cached model instances are frozen so they are not
189
+ accidently modified.
190
+
191
+ * A many_to_one_pk_lookup plugin has been added that changes the
192
+ many_to_one association retrieval code to do a simple primary
193
+ key lookup on the associated class in most cases. This results
194
+ in significantly better performance, especially if the
195
+ associated model is using a caching plugin (either caching
196
+ or static_cache).
197
+
198
+ = Core Extension Replacements
199
+
200
+ * Most of Sequel's core extensions now have equivalent methods defined
201
+ on the Sequel module:
202
+
203
+ :column.as(:alias) -> Sequel.as(:column, :alias)
204
+ :column.asc -> Sequel.asc(:column)
205
+ :column.desc -> Sequel.desc(:column)
206
+ :column.cast(Integer) -> Sequel.cast(:column, Integer)
207
+ :column.cast_numeric -> Sequel.cast_numeric(:column)
208
+ :column.cast_string -> Sequel.cast_string(:column)
209
+ :column.extract(:year) -> Sequel.extract(:year, :column)
210
+ :column.identifier -> Sequel.identifier(:column)
211
+ :column.ilike('A%') -> Sequel.ilike(:column, 'A%')
212
+ :column.like('A%') -> Sequel.like(:column, 'A%')
213
+ :column.qualify(:table) -> Sequel.qualify(:table, :column)
214
+ :column.sql_subscript(1) -> Sequel.subscript(:column, 1)
215
+ :function.sql_function(1) -> Sequel.function(:function, 1)
216
+ 'some SQL'.lit -> Sequel.lit('some SQL')
217
+ 'string'.to_sequel_blob -> Sequel.blob('string')
218
+ {:a=>1}.case(0) -> Sequel.case({:a=>1}, 0)
219
+ {:a=>1}.sql_negate -> Sequel.negate(:a=>1)
220
+ {:a=>1}.sql_or -> Sequel.or(:a=>1)
221
+ [[1, 2]].sql_value_list -> Sequel.value_list([[1, 2]])
222
+ [:a, :b].sql_string_join -> Sequel.join([:a, :b])
223
+ ~{:a=>1} -> Sequel.~(:a=>1)
224
+ :a + 1 -> Sequel.+(:a, 1)
225
+ :a - 1 -> Sequel.-(:a, 1)
226
+ :a * 1 -> Sequel.*(:a, 1)
227
+ :a / 1 -> Sequel./(:a, 1)
228
+ :a & 1 -> Sequel.&(:a, 1)
229
+ :a | 1 -> Sequel.|(:a, 1)
230
+
231
+ * You can now wrap any object in a Sequel expression using
232
+ Sequel.expr. This is similar to the sql_expr extension, but
233
+ without defining the sql_expr method on all objects:
234
+
235
+ 1.sql_expr -> Sequel.expr(1)
236
+
237
+ The sql_expr extension now just has Object#sql_expr call
238
+ Sequel.expr.
239
+
240
+ * Virtual Rows now have methods defined that handle the standard
241
+ mathematical operators:
242
+
243
+ select{|o| o.+(1, :a)} # SELECT (1 + a)
244
+
245
+ the standard inequality operators:
246
+
247
+ where{|o| o.>(2, :a)} # WHERE (2 > a)
248
+
249
+ and the standard boolean operators:
250
+
251
+ where{|o| o.&({:a=>1}, o.~(:b=>1))} # WHERE ((a = 1) AND (b != 1))
252
+
253
+ Additionally, there is now direct support for creating literal
254
+ strings in instance_evaled virtual row blocks using `:
255
+
256
+ where{a > `some crazy SQL`} # WHERE (a > some crazy SQL)
257
+
258
+ This doesn't override Kernel.`, since virtual rows use a BasicObject
259
+ subclass. Previously, using ` would result in calling the SQL
260
+ function named ` with the given string, which probably isn't valid
261
+ syntax on most databases.
262
+
263
+ * You can now require 'sequel/no_core_ext' to load Sequel without the
264
+ core extensions. The previous way of setting the
265
+ SEQUEL_NO_CORE_EXTENSIONS constant or environment variable before
266
+ loading Sequel still works.
267
+
268
+ * The core extensions have been moved from Sequel's core library into
269
+ an extension that is loadable with Sequel.extension. This extension
270
+ is still loaded by default for backwards compatibility. However,
271
+ the next major version of Sequel will no longer load this extension
272
+ by default (though it will still be available to load manually).
273
+
274
+ * You can now check if the core extensions have been loaded by using
275
+ Sequel.core_extensions?.
276
+
277
+ = Foreign Keys in the Schema Dumper
278
+
279
+ * Database#foreign_key_list has been added that gives an array of
280
+ foreign key constraints on the table. It is currently implemented
281
+ on MySQL, PostgreSQL, and SQLite, and may be implemented on other
282
+ database types in the future. Each entry in the return array is
283
+ a hash, with at least the following keys present:
284
+
285
+ :columns :: An array of columns in the given table
286
+ :table :: The table referenced by the columns
287
+ :key :: An array of columns referenced (in the table specified by
288
+ :table), but can be nil on certain adapters if the primary
289
+ key is referenced.
290
+
291
+ The hash may also contain entries for:
292
+
293
+ :deferrable :: Whether the constraint is deferrable
294
+ :name :: The name of the constraint
295
+ :on_delete :: The action to take ON DELETE
296
+ :on_update :: The action to take ON UPDATE
297
+
298
+ * The schema_dumper extension now dumps foreign key constraints on
299
+ databases that support Database#foreign_key_list. On such
300
+ databases, dumping a schema migration will dump the tables in
301
+ topological order, such that referenced tables always come before
302
+ referencing tables.
303
+
304
+ In case there is a circular dependency, Sequel breaks the
305
+ dependency and adds separate foreign key constraints at the end
306
+ of the migration. However, when a circular dependency is broken,
307
+ the migration can probably not be migrated down.
308
+
309
+ Foreign key constraints can also be dumped as a separate migration
310
+ using Database#dump_foreign_key_migration, similar to how
311
+ Database#dump_indexes_migration works.
312
+
313
+ * When using bin/sequel -C to copy databases, foreign key constraints
314
+ are now copied if the source database supports
315
+ Database#foreign_key_list.
316
+
317
+ = Other New Features
318
+
319
+ * Dataset#to_hash_groups and #select_hash_groups have been added.
320
+ These methods are similar to #to_hash and #select_hash in that they
321
+ return a hash, but hashes returned by *_hash_groups methods have
322
+ arrays of all matching values, unlike the *_hash methods which
323
+ just use the last matching value. Example:
324
+
325
+ DB[:table].all
326
+ # => [{:a=>1, :b=>2}, {:a=>1, :b=>3}, {:a=>2, :b=>4}]
327
+
328
+ DB[:table].to_hash(:a, :b)
329
+ # => {1=>3, 2=>4}
330
+
331
+ DB[:table].to_hash_groups(:a, :b)
332
+ # => {1=>[2, 3], 2=>[4]}
333
+
334
+ * Model#set_fields and #update_fields now accept :missing=>:skip and
335
+ :missing=>:raise options, allowing them to be used in more cases.
336
+ :missing=>:skip skips missing entries in the hash, instead of
337
+ setting the field to the default hash value. :missing=>:raise
338
+ raises an error for missing fields, similar to
339
+ strict_param_setting = true. It's recommended that these options
340
+ be used in new code in preference to #set_only and #update_only.
341
+
342
+ * Database#drop_table? has been added, for dropping tables if they
343
+ already exist. This uses DROP TABLE IF EXISTS on the databases that
344
+ support it. Database#supports_drop_table_if_exists? has been added
345
+ for checking whether the database supports that syntax.
346
+
347
+ * Database#create_join_table has been added that allows easy
348
+ creation of many_to_many join tables:
349
+
350
+ DB.create_join_table(:album_id=>:albums, :artist_id=>:artists)
351
+
352
+ This uses real foreign keys for both of the columns, uses a
353
+ composite primary key of both of the columns, and adds an
354
+ additional composite index of the columns in reverse order. The
355
+ primary key and additional index should ensure that almost all
356
+ operations on the join table can benefit from an index.
357
+
358
+ In terms of customization, the values in the hash can be hashes
359
+ themselves for column specific options, and an additional options
360
+ hash can also be given to override some of the default settings.
361
+
362
+ Database#drop_join_table also exists and takes the same options
363
+ as create_join_table. It mostly exists to make it easy to
364
+ reverse migrations that use create_join_table.
365
+
366
+ * Model#freeze has been added that freezes a model such that it
367
+ works correctly in a read-only state. Before, it used the standard
368
+ Object#freeze, which broke some things that should work, and
369
+ allowed changes that shouldn't be allowed (like modifying the
370
+ instance's values).
371
+
372
+ * ConnectionPool#all_connections has been added, which yields each
373
+ available connection in the pool to the block. For threaded pools,
374
+ it does not yield connections that are currently being used by
375
+ other threads. When using this method, it is important to only
376
+ operate on the yielded connection objects, and not make any
377
+ modifications to the pool itself. The pool is also locked until
378
+ the method returns.
379
+
380
+ * ConnectionPool#after_connect= has been added, allowing you to
381
+ change a connection pool's after_connect proc after instantiating
382
+ the pool.
383
+
384
+ * ConnectionPool#disconnection_proc= has been added, allowing you to
385
+ change a connection pool's disconnection_proc after instantiating the
386
+ pool.
387
+
388
+ * A Model.cache_anonymous_models accessor has been added, and can be
389
+ set to false to disable the caching of classes created by
390
+ Sequel::Model(). This caching is only useful if you want to reload
391
+ the model's file without getting a superclass mismatch. This
392
+ setting is true by default for backwards compatibility, but may be
393
+ changed to false in a later version, so you should manually set it to
394
+ true if you are using code reloading.
395
+
396
+ * Model.instance_dataset has been added for getting the dataset used
397
+ for model instances (a naked dataset restricted to a single row).
398
+
399
+ * Dataset#with_sql_delete has been added for running the given SQL
400
+ string as a delete and returning the number of rows modified. It's
401
+ designed as a replacement for with_sql(sql).delete, which is slower
402
+ as it requires cloning the dataset.
403
+
404
+ * The :on_update and :on_delete entries for foreign_key now accept
405
+ string arguments which are used literally.
406
+
407
+ * Prepared statement objects now have a log_sql accessor that can be
408
+ turned on to log the entire SQL statement instead of just the
409
+ prepared statement name.
410
+
411
+ * Dataset#multi_replace has been added on MySQL. This is similar to
412
+ multi_insert, but uses REPLACE instead of INSERT.
413
+
414
+ * Dataset#explain has been added to MySQL. You can use an
415
+ :extended=>true option to use EXPLAIN EXTENDED.
416
+
417
+ * A Database#type_supported? method has been added on PostgreSQL to
418
+ check if the database supports the given type:
419
+
420
+ DB.type_supported?(:hstore)
421
+
422
+ * Datatabase#reset_conversion_procs has been added to the postgres
423
+ adapter, for use by extensions that modify the default conversion
424
+ procs and want to have the database use the updated defaults.
425
+
426
+ * A Database#convert_infinite_timestamps accessor has been added to
427
+ the postgres adapter, allowing you to return infinite timestamps as
428
+ nil, a string, or a float.
429
+
430
+ * SQL::PlaceholderLiteralString objects can now use a placeholder
431
+ array, where placeholder values are inserted between array elements.
432
+ This is about 2.5-3x faster than using a string with ? placeholders,
433
+ and allows usage of ? inside the array:
434
+
435
+ Sequel.lit(["(", " ? ", ")"], 1, 2) # (1 ? 2)
436
+
437
+ * SQL::Subscript#[] has been added for accessing members of a
438
+ multi-dimensional array:
439
+
440
+ Sequel.subscript(:column, 1)[2][3] # column[1][2][3]
441
+
442
+ * SQL::Wrapper has been added for wrapping arbitrary objects in a
443
+ Sequel expression object.
444
+
445
+ * SQL::QualifiedIdentifier objects can now contain arbitrary Sequel
446
+ expressions. Before, they could only contain a few expression
447
+ types. This makes it easier to add extensions to support
448
+ PostgreSQL row-valued types.
449
+
450
+ = Performance Improvements
451
+
452
+ * Model.[] when called with a primary key has been made about 110%
453
+ faster for most models by avoiding cloning datasets.
454
+
455
+ * Model.[] when called without arguments or with a single nil argument
456
+ is much faster as it now returns nil immediately instead of issuing
457
+ a database query.
458
+
459
+ * Model#delete and Model#destroy have been made about 75% faster for
460
+ most models by using a static SQL string.
461
+
462
+ * Model.new is now twice as fast when passed an empty hash.
463
+
464
+ * Model#set is now four times as fast when passed an empty hash.
465
+
466
+ * Model#this has been made about 85% faster by reducing the number of
467
+ dataset clones needed from 3 to 1.
468
+
469
+ * Some proc activations have been removed, giving minor speedups when
470
+ running on MRI.
471
+
472
+ = Other Improvements
473
+
474
+ * Database#uri and #url now return the connection string given
475
+ to Sequel.connect. Previously, they tried to reconstruct the
476
+ url using the database's options, but that didn't work well in
477
+ corner cases.
478
+
479
+ * Database#inspect now shows the URL and/or options given when
480
+ connecting to the database. Previously, it showed the URL, or
481
+ all of the databases options if constructing the URL raised an
482
+ error.
483
+
484
+ * Sequel no longer checks for prepared transactions support when
485
+ using transactions unless a prepared transaction is specifically
486
+ requested.
487
+
488
+ * The schema utility dataset cached in the Database object is now
489
+ reset if you use Database#extend_datasets, ensuring that the new
490
+ value will use the given extension.
491
+
492
+ * The prepared_statements* plugins now log the full SQL by default.
493
+ Since the user doesn't choose the name of the prepared statements,
494
+ it was often difficult to determine what SQL was actually run if
495
+ you were only looking at a subsection of the SQL log.
496
+
497
+ * The nested_attributes plugin's delete/remove support now works
498
+ correctly when a false value is given for _delete/_remove and
499
+ strict_param_setting is true.
500
+
501
+ * The hook_class_methods and validation_class_methods plugins
502
+ now work correctly when subclassing if the subclass attempts to
503
+ create instances inside Model.inherited.
504
+
505
+ * The caching plugin has been refactored. Model.cache_get_pk and
506
+ cache_delete_pk have been added for retrieving/deleting from the
507
+ cache by primary key. Model.cache_key is now a public method.
508
+
509
+ * The typecast_on_load plugin now works correctly when saving
510
+ new model objects when insert_select is supported.
511
+
512
+ * In the sql_expr extension, nil.sql_expr is no longer treated as
513
+ a boolean value. It is now treated as a value with generic type.
514
+
515
+ * The postgres adapter no longer issues a query to map type names to
516
+ type oids if no named conversion procs have been registered.
517
+
518
+ * The postgres adapter now works around issues in ruby-pg by
519
+ supporting fractional seconds for Time/DateTime values, and
520
+ supporting SQL::Blob (bytea) values with embedded "\0" characters.
521
+
522
+ * The postgres adapter now supports pre-defining the PG_NAMED_TYPES
523
+ and PG_TYPES constants. This is so extensions can define them,
524
+ so they don't have to load the postgres adapter file first. If
525
+ extensions need to use these constants, they should do:
526
+
527
+ PG_NAMED_TYPES = {} unless defined?(PG_NAMED_TYPES)
528
+ PG_TYPES = {} unless defined?(PG_TYPES)
529
+
530
+ That way they work whether they are loaded before or after the
531
+ postgres adapter.
532
+
533
+ * PostgreSQL 8.2-9.0 now correctly add the RETURNING clause when
534
+ building queries. Sequel 3.31.0 added support for returning values
535
+ from delete/update queries in PostgreSQL 8.2-9.0, but didn't change
536
+ the literalization code to use the RETURNING clause on those
537
+ versions.
538
+
539
+ * The jdbc/postgres adapter now converts Java arrays
540
+ (Java::OrgPostgresqlJdbc4::Jdbc4Array) to ruby arrays.
541
+
542
+ * Tables and schemas with embedded ' characters are now handled
543
+ correctly when parsing primary keys and sequences on PostgreSQL.
544
+
545
+ * Identifiers are now escaped on MySQL and SQLite. Previously they
546
+ were quoted, but internal ` characters were not doubled.
547
+
548
+ * Fractional seconds for the time type are now returned correctly on
549
+ jdbc (assuming they are returned as java.sql.Time values by JDBC).
550
+
551
+ * Multiple changes were made to ensure that Sequel works correctly
552
+ when the core extensions are not loaded.
553
+
554
+ * Composite foreign key constraints are now retained when emulating
555
+ alter_table operations on SQLite. Previously, only single
556
+ foreign key constraints were retained.
557
+
558
+ * An error is no longer raised when no indexes exist when calling
559
+ Database#indexes on jdbc/sqlite.
560
+
561
+ * A possible SystemStackError has been fixed in the SQLite adapter,
562
+ when trying to delete a dataset that uses a having clause and no
563
+ where clause.
564
+
565
+ * ROLLUP/CUBE support now works correctly on Microsoft SQL Server
566
+ 2005.
567
+
568
+ * Unsigned tinyint types are now recognized in the schema dumper.
569
+
570
+ * Using primary_key :column, :type=>Bignum now works correctly on H2.
571
+ Previously, the column created was not autoincrementing.
572
+
573
+ * Using a bound variable for a limit is now supported in the ibmdb
574
+ adapter on ruby 1.9.
575
+
576
+ * Connecting to PostgreSQL via the swift adapter has been fixed when
577
+ using newer versions of swift.
578
+
579
+ * The mock adapter now handles calling the Database#execute methods
580
+ directly (instead of via a dataset).
581
+
582
+ * The mock adapter now has the ability to have per-shared adapter
583
+ specific initialization code executed. This has been used to fix
584
+ some bugs when using the shared postgres adapter.
585
+
586
+ * The pretty_table extension has been split into two extensions, one
587
+ that adds a method to Dataset and one that just adds the
588
+ PrettyTable class. Also, PrettyTable.string has been added to get
589
+ a string copy of the table.
590
+
591
+ * A spec_model_no_assoc task has been added for running model specs
592
+ without the association plugin loaded. This is to check that the
593
+ SEQUEL_NO_ASSOCIATIONS setting works correctly.
594
+
595
+ = Deprecated Features to be Removed in Sequel 3.35.0
596
+
597
+ * Ruby <1.8.7 support is now deprecated.
598
+
599
+ * PostgreSQL <8.2 support is now deprecated.
600
+
601
+ * Dataset#disable_insert_returning on PostgreSQL is now deprecated.
602
+ Starting in 3.35.0, RETURNING will now always be used to get the
603
+ primary key value when inserting.
604
+
605
+ * Array#all_two_pairs? is now deprecated. It was part of the core
606
+ extensions, but the core extensions have been refactored to no
607
+ longer require it. As it doesn't specifically relate to creating
608
+ Sequel expression objects, it is being removed. The private
609
+ Array#sql_expr_if_all_two_pairs method is deprecated as well.
610
+
611
+ = Other Backwards Compatibility Issues
612
+
613
+ * The generic Bignum type now uses bigint on SQLite, similar to
614
+ other databases. The integer type was previously used. The only
615
+ exception is for auto incrementing primary keys, which still use
616
+ integer for Bignum as SQLite doesn't support autoincrementing
617
+ columns other than integer.
618
+
619
+ * On SQLite, Dataset#explain now returns a string, similar to
620
+ PostgreSQL (and now MySQL).
621
+
622
+ * When using the JDBC adapter, Java::OrgPostgresqlUtil::PGobject
623
+ objects are converted to ruby strings if the dataset is set to
624
+ convert types (the default setting). This is to support the
625
+ hstore extension, but it could have unforeseen effects if custom
626
+ types were used.
627
+
628
+ * For PostgreSQL connection objects, #primary_key and #sequence now
629
+ require their arguments are provided as already literalized
630
+ strings. Note that these methods are being removed in the next
631
+ version because they will not be needed after PostgreSQL <8.2
632
+ support is dropped.
633
+
634
+ * Database#uri and #url now return a string or nil, but never raise
635
+ an exception. Previously, they would either return a string
636
+ or raise an exception.
637
+
638
+ * The Model @simple_pk and @simple_table instance variables should
639
+ no longer be modified directly. Instead, the setter methods should
640
+ be used.
641
+
642
+ * Model.primary_key_lookup should no longer be called with a nil
643
+ value.
644
+
645
+ * Logging of prepared statements on some adapters has been changed
646
+ slightly, so log parsers might need to be updated.
647
+
648
+ * Dataset#identifier_append and #table_ref_append no longer treat
649
+ literal strings and blobs specially. Previously, they were treated
650
+ as identifiers.
651
+
652
+ * Dataset#qualified_identifier_sql_append now takes 3 arguments, so
653
+ any extensions that override it should be modified accordingly.
654
+
655
+ * Some internally used constants and private methods have been
656
+ deleted:
657
+
658
+ Database::CASCADE
659
+ Database::NO_ACTION
660
+ Database::SET_DEFAULTS
661
+ Database::SET_NULL
662
+ Database::RESTRICT
663
+ Dataset::COLUMN_ALL
664
+
665
+ or moved:
666
+
667
+ MySQL::Dataset::AFFECTED_ROWS_RE -> MySQL::Database
668
+ MySQL::Dataset#affected_rows -> MySQL::Database
669
+
670
+ * The sql_expr extension no longer creates the
671
+ Sequel::SQL::GenericComplexExpression class.