sequel 5.8.0 → 5.38.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (510) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +409 -1795
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +4 -4
  5. data/bin/sequel +4 -0
  6. data/doc/advanced_associations.rdoc +136 -18
  7. data/doc/association_basics.rdoc +10 -5
  8. data/doc/cheat_sheet.rdoc +1 -0
  9. data/doc/code_order.rdoc +12 -2
  10. data/doc/dataset_filtering.rdoc +17 -2
  11. data/doc/mass_assignment.rdoc +3 -3
  12. data/doc/model_dataset_method_design.rdoc +1 -1
  13. data/doc/model_plugins.rdoc +1 -1
  14. data/doc/opening_databases.rdoc +30 -8
  15. data/doc/postgresql.rdoc +107 -2
  16. data/doc/release_notes/5.10.0.txt +84 -0
  17. data/doc/release_notes/5.11.0.txt +83 -0
  18. data/doc/release_notes/5.12.0.txt +141 -0
  19. data/doc/release_notes/5.13.0.txt +27 -0
  20. data/doc/release_notes/5.14.0.txt +63 -0
  21. data/doc/release_notes/5.15.0.txt +39 -0
  22. data/doc/release_notes/5.16.0.txt +110 -0
  23. data/doc/release_notes/5.17.0.txt +31 -0
  24. data/doc/release_notes/5.18.0.txt +69 -0
  25. data/doc/release_notes/5.19.0.txt +28 -0
  26. data/doc/release_notes/5.20.0.txt +89 -0
  27. data/doc/release_notes/5.21.0.txt +87 -0
  28. data/doc/release_notes/5.22.0.txt +48 -0
  29. data/doc/release_notes/5.23.0.txt +56 -0
  30. data/doc/release_notes/5.24.0.txt +56 -0
  31. data/doc/release_notes/5.25.0.txt +32 -0
  32. data/doc/release_notes/5.26.0.txt +35 -0
  33. data/doc/release_notes/5.27.0.txt +21 -0
  34. data/doc/release_notes/5.28.0.txt +16 -0
  35. data/doc/release_notes/5.29.0.txt +22 -0
  36. data/doc/release_notes/5.30.0.txt +20 -0
  37. data/doc/release_notes/5.31.0.txt +148 -0
  38. data/doc/release_notes/5.32.0.txt +46 -0
  39. data/doc/release_notes/5.33.0.txt +24 -0
  40. data/doc/release_notes/5.34.0.txt +40 -0
  41. data/doc/release_notes/5.35.0.txt +56 -0
  42. data/doc/release_notes/5.36.0.txt +60 -0
  43. data/doc/release_notes/5.37.0.txt +30 -0
  44. data/doc/release_notes/5.38.0.txt +28 -0
  45. data/doc/release_notes/5.9.0.txt +99 -0
  46. data/doc/security.rdoc +10 -0
  47. data/doc/sharding.rdoc +42 -28
  48. data/doc/sql.rdoc +12 -0
  49. data/doc/testing.rdoc +24 -17
  50. data/doc/transactions.rdoc +78 -0
  51. data/doc/validations.rdoc +2 -2
  52. data/lib/sequel/adapters/ado.rb +26 -18
  53. data/lib/sequel/adapters/ado/access.rb +2 -2
  54. data/lib/sequel/adapters/ado/mssql.rb +5 -8
  55. data/lib/sequel/adapters/amalgalite.rb +1 -1
  56. data/lib/sequel/adapters/jdbc.rb +71 -27
  57. data/lib/sequel/adapters/jdbc/mysql.rb +6 -6
  58. data/lib/sequel/adapters/jdbc/oracle.rb +7 -6
  59. data/lib/sequel/adapters/jdbc/postgresql.rb +17 -28
  60. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +5 -6
  61. data/lib/sequel/adapters/jdbc/sqlite.rb +33 -2
  62. data/lib/sequel/adapters/jdbc/sqlserver.rb +4 -3
  63. data/lib/sequel/adapters/jdbc/transactions.rb +14 -28
  64. data/lib/sequel/adapters/mysql.rb +14 -15
  65. data/lib/sequel/adapters/mysql2.rb +5 -3
  66. data/lib/sequel/adapters/odbc.rb +4 -6
  67. data/lib/sequel/adapters/oracle.rb +7 -7
  68. data/lib/sequel/adapters/postgres.rb +52 -16
  69. data/lib/sequel/adapters/shared/access.rb +16 -12
  70. data/lib/sequel/adapters/shared/db2.rb +5 -0
  71. data/lib/sequel/adapters/shared/mssql.rb +41 -18
  72. data/lib/sequel/adapters/shared/mysql.rb +66 -19
  73. data/lib/sequel/adapters/shared/oracle.rb +29 -23
  74. data/lib/sequel/adapters/shared/postgres.rb +341 -95
  75. data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
  76. data/lib/sequel/adapters/shared/sqlite.rb +174 -21
  77. data/lib/sequel/adapters/sqlanywhere.rb +33 -17
  78. data/lib/sequel/adapters/sqlite.rb +78 -68
  79. data/lib/sequel/adapters/tinytds.rb +14 -6
  80. data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +2 -5
  81. data/lib/sequel/adapters/utils/mysql_mysql2.rb +5 -1
  82. data/lib/sequel/connection_pool.rb +2 -6
  83. data/lib/sequel/connection_pool/sharded_single.rb +7 -4
  84. data/lib/sequel/connection_pool/sharded_threaded.rb +32 -21
  85. data/lib/sequel/connection_pool/single.rb +1 -1
  86. data/lib/sequel/connection_pool/threaded.rb +26 -11
  87. data/lib/sequel/core.rb +327 -319
  88. data/lib/sequel/database/connecting.rb +7 -8
  89. data/lib/sequel/database/logging.rb +7 -1
  90. data/lib/sequel/database/misc.rb +68 -34
  91. data/lib/sequel/database/query.rb +6 -4
  92. data/lib/sequel/database/schema_generator.rb +31 -11
  93. data/lib/sequel/database/schema_methods.rb +32 -22
  94. data/lib/sequel/database/transactions.rb +129 -25
  95. data/lib/sequel/dataset.rb +4 -2
  96. data/lib/sequel/dataset/actions.rb +34 -23
  97. data/lib/sequel/dataset/features.rb +34 -0
  98. data/lib/sequel/dataset/graph.rb +27 -11
  99. data/lib/sequel/dataset/misc.rb +17 -3
  100. data/lib/sequel/dataset/placeholder_literalizer.rb +50 -21
  101. data/lib/sequel/dataset/prepared_statements.rb +96 -26
  102. data/lib/sequel/dataset/query.rb +43 -8
  103. data/lib/sequel/dataset/sql.rb +189 -41
  104. data/lib/sequel/deprecated.rb +3 -1
  105. data/lib/sequel/exceptions.rb +2 -0
  106. data/lib/sequel/extensions/_pretty_table.rb +1 -2
  107. data/lib/sequel/extensions/any_not_empty.rb +45 -0
  108. data/lib/sequel/extensions/caller_logging.rb +79 -0
  109. data/lib/sequel/extensions/columns_introspection.rb +1 -2
  110. data/lib/sequel/extensions/connection_expiration.rb +6 -6
  111. data/lib/sequel/extensions/connection_validator.rb +7 -6
  112. data/lib/sequel/extensions/constant_sql_override.rb +65 -0
  113. data/lib/sequel/extensions/constraint_validations.rb +53 -28
  114. data/lib/sequel/extensions/core_refinements.rb +2 -0
  115. data/lib/sequel/extensions/duplicate_columns_handler.rb +2 -0
  116. data/lib/sequel/extensions/escaped_like.rb +100 -0
  117. data/lib/sequel/extensions/eval_inspect.rb +3 -1
  118. data/lib/sequel/extensions/exclude_or_null.rb +68 -0
  119. data/lib/sequel/extensions/fiber_concurrency.rb +24 -0
  120. data/lib/sequel/extensions/index_caching.rb +9 -7
  121. data/lib/sequel/extensions/integer64.rb +3 -1
  122. data/lib/sequel/extensions/looser_typecasting.rb +3 -3
  123. data/lib/sequel/extensions/migration.rb +13 -6
  124. data/lib/sequel/extensions/named_timezones.rb +84 -23
  125. data/lib/sequel/extensions/pg_array.rb +87 -79
  126. data/lib/sequel/extensions/pg_array_ops.rb +14 -6
  127. data/lib/sequel/extensions/pg_enum.rb +34 -18
  128. data/lib/sequel/extensions/pg_extended_date_support.rb +34 -14
  129. data/lib/sequel/extensions/pg_hstore.rb +6 -0
  130. data/lib/sequel/extensions/pg_hstore_ops.rb +2 -0
  131. data/lib/sequel/extensions/pg_inet.rb +15 -5
  132. data/lib/sequel/extensions/pg_interval.rb +2 -0
  133. data/lib/sequel/extensions/pg_json.rb +387 -123
  134. data/lib/sequel/extensions/pg_json_ops.rb +168 -0
  135. data/lib/sequel/extensions/pg_range.rb +20 -10
  136. data/lib/sequel/extensions/pg_range_ops.rb +2 -0
  137. data/lib/sequel/extensions/pg_row.rb +3 -2
  138. data/lib/sequel/extensions/pg_row_ops.rb +24 -0
  139. data/lib/sequel/extensions/pg_static_cache_updater.rb +2 -2
  140. data/lib/sequel/extensions/pg_timestamptz.rb +2 -0
  141. data/lib/sequel/extensions/query.rb +1 -0
  142. data/lib/sequel/extensions/run_transaction_hooks.rb +72 -0
  143. data/lib/sequel/extensions/s.rb +2 -0
  144. data/lib/sequel/extensions/schema_dumper.rb +13 -7
  145. data/lib/sequel/extensions/sequel_4_dataset_methods.rb +4 -2
  146. data/lib/sequel/extensions/server_block.rb +18 -7
  147. data/lib/sequel/extensions/sql_comments.rb +2 -2
  148. data/lib/sequel/extensions/symbol_aref_refinement.rb +2 -0
  149. data/lib/sequel/extensions/symbol_as_refinement.rb +2 -0
  150. data/lib/sequel/extensions/to_dot.rb +9 -3
  151. data/lib/sequel/model.rb +3 -1
  152. data/lib/sequel/model/associations.rb +403 -69
  153. data/lib/sequel/model/base.rb +170 -90
  154. data/lib/sequel/model/plugins.rb +105 -0
  155. data/lib/sequel/plugins/after_initialize.rb +1 -1
  156. data/lib/sequel/plugins/association_dependencies.rb +3 -3
  157. data/lib/sequel/plugins/association_lazy_eager_option.rb +66 -0
  158. data/lib/sequel/plugins/association_multi_add_remove.rb +85 -0
  159. data/lib/sequel/plugins/association_pks.rb +74 -22
  160. data/lib/sequel/plugins/association_proxies.rb +6 -2
  161. data/lib/sequel/plugins/auto_validations.rb +36 -17
  162. data/lib/sequel/plugins/blacklist_security.rb +1 -2
  163. data/lib/sequel/plugins/boolean_subsets.rb +4 -1
  164. data/lib/sequel/plugins/caching.rb +3 -0
  165. data/lib/sequel/plugins/class_table_inheritance.rb +62 -34
  166. data/lib/sequel/plugins/composition.rb +13 -9
  167. data/lib/sequel/plugins/csv_serializer.rb +28 -9
  168. data/lib/sequel/plugins/defaults_setter.rb +2 -2
  169. data/lib/sequel/plugins/dirty.rb +60 -22
  170. data/lib/sequel/plugins/eager_graph_eager.rb +139 -0
  171. data/lib/sequel/plugins/empty_failure_backtraces.rb +38 -0
  172. data/lib/sequel/plugins/finder.rb +2 -2
  173. data/lib/sequel/plugins/forbid_lazy_load.rb +216 -0
  174. data/lib/sequel/plugins/hook_class_methods.rb +17 -5
  175. data/lib/sequel/plugins/insert_conflict.rb +72 -0
  176. data/lib/sequel/plugins/instance_specific_default.rb +113 -0
  177. data/lib/sequel/plugins/inverted_subsets.rb +2 -2
  178. data/lib/sequel/plugins/json_serializer.rb +21 -14
  179. data/lib/sequel/plugins/lazy_attributes.rb +1 -1
  180. data/lib/sequel/plugins/list.rb +22 -10
  181. data/lib/sequel/plugins/many_through_many.rb +1 -1
  182. data/lib/sequel/plugins/nested_attributes.rb +27 -5
  183. data/lib/sequel/plugins/pg_array_associations.rb +12 -9
  184. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +149 -61
  185. data/lib/sequel/plugins/prepared_statements.rb +6 -12
  186. data/lib/sequel/plugins/prepared_statements_safe.rb +1 -3
  187. data/lib/sequel/plugins/rcte_tree.rb +20 -22
  188. data/lib/sequel/plugins/sharding.rb +13 -7
  189. data/lib/sequel/plugins/single_table_inheritance.rb +20 -15
  190. data/lib/sequel/plugins/skip_saving_columns.rb +108 -0
  191. data/lib/sequel/plugins/static_cache.rb +36 -17
  192. data/lib/sequel/plugins/static_cache_cache.rb +53 -0
  193. data/lib/sequel/plugins/string_stripper.rb +1 -1
  194. data/lib/sequel/plugins/subclasses.rb +2 -0
  195. data/lib/sequel/plugins/subset_conditions.rb +2 -2
  196. data/lib/sequel/plugins/tactical_eager_loading.rb +73 -2
  197. data/lib/sequel/plugins/throw_failures.rb +110 -0
  198. data/lib/sequel/plugins/tree.rb +49 -31
  199. data/lib/sequel/plugins/typecast_on_load.rb +3 -2
  200. data/lib/sequel/plugins/validation_class_methods.rb +11 -5
  201. data/lib/sequel/plugins/validation_helpers.rb +2 -2
  202. data/lib/sequel/sql.rb +120 -30
  203. data/lib/sequel/timezones.rb +55 -14
  204. data/lib/sequel/version.rb +6 -1
  205. metadata +101 -361
  206. data/Rakefile +0 -151
  207. data/doc/release_notes/4.0.0.txt +0 -262
  208. data/doc/release_notes/4.1.0.txt +0 -85
  209. data/doc/release_notes/4.10.0.txt +0 -226
  210. data/doc/release_notes/4.11.0.txt +0 -147
  211. data/doc/release_notes/4.12.0.txt +0 -105
  212. data/doc/release_notes/4.13.0.txt +0 -169
  213. data/doc/release_notes/4.14.0.txt +0 -68
  214. data/doc/release_notes/4.15.0.txt +0 -56
  215. data/doc/release_notes/4.16.0.txt +0 -36
  216. data/doc/release_notes/4.17.0.txt +0 -38
  217. data/doc/release_notes/4.18.0.txt +0 -36
  218. data/doc/release_notes/4.19.0.txt +0 -45
  219. data/doc/release_notes/4.2.0.txt +0 -129
  220. data/doc/release_notes/4.20.0.txt +0 -79
  221. data/doc/release_notes/4.21.0.txt +0 -94
  222. data/doc/release_notes/4.22.0.txt +0 -72
  223. data/doc/release_notes/4.23.0.txt +0 -65
  224. data/doc/release_notes/4.24.0.txt +0 -99
  225. data/doc/release_notes/4.25.0.txt +0 -181
  226. data/doc/release_notes/4.26.0.txt +0 -44
  227. data/doc/release_notes/4.27.0.txt +0 -78
  228. data/doc/release_notes/4.28.0.txt +0 -57
  229. data/doc/release_notes/4.29.0.txt +0 -41
  230. data/doc/release_notes/4.3.0.txt +0 -40
  231. data/doc/release_notes/4.30.0.txt +0 -37
  232. data/doc/release_notes/4.31.0.txt +0 -57
  233. data/doc/release_notes/4.32.0.txt +0 -132
  234. data/doc/release_notes/4.33.0.txt +0 -88
  235. data/doc/release_notes/4.34.0.txt +0 -86
  236. data/doc/release_notes/4.35.0.txt +0 -130
  237. data/doc/release_notes/4.36.0.txt +0 -116
  238. data/doc/release_notes/4.37.0.txt +0 -50
  239. data/doc/release_notes/4.38.0.txt +0 -67
  240. data/doc/release_notes/4.39.0.txt +0 -127
  241. data/doc/release_notes/4.4.0.txt +0 -92
  242. data/doc/release_notes/4.40.0.txt +0 -179
  243. data/doc/release_notes/4.41.0.txt +0 -77
  244. data/doc/release_notes/4.42.0.txt +0 -221
  245. data/doc/release_notes/4.43.0.txt +0 -87
  246. data/doc/release_notes/4.44.0.txt +0 -125
  247. data/doc/release_notes/4.45.0.txt +0 -370
  248. data/doc/release_notes/4.46.0.txt +0 -404
  249. data/doc/release_notes/4.47.0.txt +0 -56
  250. data/doc/release_notes/4.48.0.txt +0 -293
  251. data/doc/release_notes/4.49.0.txt +0 -222
  252. data/doc/release_notes/4.5.0.txt +0 -34
  253. data/doc/release_notes/4.6.0.txt +0 -30
  254. data/doc/release_notes/4.7.0.txt +0 -103
  255. data/doc/release_notes/4.8.0.txt +0 -175
  256. data/doc/release_notes/4.9.0.txt +0 -190
  257. data/spec/adapter_spec.rb +0 -4
  258. data/spec/adapters/db2_spec.rb +0 -170
  259. data/spec/adapters/mssql_spec.rb +0 -804
  260. data/spec/adapters/mysql_spec.rb +0 -1041
  261. data/spec/adapters/oracle_spec.rb +0 -327
  262. data/spec/adapters/postgres_spec.rb +0 -4000
  263. data/spec/adapters/spec_helper.rb +0 -43
  264. data/spec/adapters/sqlanywhere_spec.rb +0 -97
  265. data/spec/adapters/sqlite_spec.rb +0 -600
  266. data/spec/bin_spec.rb +0 -269
  267. data/spec/core/connection_pool_spec.rb +0 -1228
  268. data/spec/core/database_spec.rb +0 -2673
  269. data/spec/core/dataset_spec.rb +0 -5419
  270. data/spec/core/deprecated_spec.rb +0 -70
  271. data/spec/core/expression_filters_spec.rb +0 -1344
  272. data/spec/core/mock_adapter_spec.rb +0 -722
  273. data/spec/core/object_graph_spec.rb +0 -306
  274. data/spec/core/placeholder_literalizer_spec.rb +0 -166
  275. data/spec/core/schema_generator_spec.rb +0 -214
  276. data/spec/core/schema_spec.rb +0 -1820
  277. data/spec/core/spec_helper.rb +0 -23
  278. data/spec/core/version_spec.rb +0 -7
  279. data/spec/core_extensions_spec.rb +0 -762
  280. data/spec/core_model_spec.rb +0 -2
  281. data/spec/core_spec.rb +0 -1
  282. data/spec/deprecation_helper.rb +0 -30
  283. data/spec/extensions/accessed_columns_spec.rb +0 -51
  284. data/spec/extensions/active_model_spec.rb +0 -99
  285. data/spec/extensions/after_initialize_spec.rb +0 -24
  286. data/spec/extensions/arbitrary_servers_spec.rb +0 -109
  287. data/spec/extensions/association_dependencies_spec.rb +0 -125
  288. data/spec/extensions/association_pks_spec.rb +0 -423
  289. data/spec/extensions/association_proxies_spec.rb +0 -100
  290. data/spec/extensions/auto_literal_strings_spec.rb +0 -205
  291. data/spec/extensions/auto_validations_spec.rb +0 -202
  292. data/spec/extensions/blacklist_security_spec.rb +0 -95
  293. data/spec/extensions/blank_spec.rb +0 -69
  294. data/spec/extensions/boolean_readers_spec.rb +0 -93
  295. data/spec/extensions/boolean_subsets_spec.rb +0 -47
  296. data/spec/extensions/caching_spec.rb +0 -273
  297. data/spec/extensions/class_table_inheritance_spec.rb +0 -568
  298. data/spec/extensions/column_conflicts_spec.rb +0 -75
  299. data/spec/extensions/column_select_spec.rb +0 -129
  300. data/spec/extensions/columns_introspection_spec.rb +0 -90
  301. data/spec/extensions/columns_updated_spec.rb +0 -35
  302. data/spec/extensions/composition_spec.rb +0 -248
  303. data/spec/extensions/connection_expiration_spec.rb +0 -133
  304. data/spec/extensions/connection_validator_spec.rb +0 -127
  305. data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
  306. data/spec/extensions/constraint_validations_spec.rb +0 -395
  307. data/spec/extensions/core_refinements_spec.rb +0 -528
  308. data/spec/extensions/csv_serializer_spec.rb +0 -183
  309. data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
  310. data/spec/extensions/dataset_associations_spec.rb +0 -365
  311. data/spec/extensions/dataset_source_alias_spec.rb +0 -51
  312. data/spec/extensions/date_arithmetic_spec.rb +0 -181
  313. data/spec/extensions/datetime_parse_to_time_spec.rb +0 -169
  314. data/spec/extensions/def_dataset_method_spec.rb +0 -100
  315. data/spec/extensions/defaults_setter_spec.rb +0 -141
  316. data/spec/extensions/delay_add_association_spec.rb +0 -73
  317. data/spec/extensions/dirty_spec.rb +0 -189
  318. data/spec/extensions/duplicate_columns_handler_spec.rb +0 -104
  319. data/spec/extensions/eager_each_spec.rb +0 -62
  320. data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
  321. data/spec/extensions/error_splitter_spec.rb +0 -18
  322. data/spec/extensions/error_sql_spec.rb +0 -20
  323. data/spec/extensions/eval_inspect_spec.rb +0 -74
  324. data/spec/extensions/finder_spec.rb +0 -260
  325. data/spec/extensions/force_encoding_spec.rb +0 -126
  326. data/spec/extensions/freeze_datasets_spec.rb +0 -31
  327. data/spec/extensions/graph_each_spec.rb +0 -113
  328. data/spec/extensions/hook_class_methods_spec.rb +0 -380
  329. data/spec/extensions/identifier_mangling_spec.rb +0 -201
  330. data/spec/extensions/implicit_subquery_spec.rb +0 -58
  331. data/spec/extensions/index_caching_spec.rb +0 -66
  332. data/spec/extensions/inflector_spec.rb +0 -183
  333. data/spec/extensions/input_transformer_spec.rb +0 -69
  334. data/spec/extensions/insert_returning_select_spec.rb +0 -72
  335. data/spec/extensions/instance_filters_spec.rb +0 -79
  336. data/spec/extensions/instance_hooks_spec.rb +0 -246
  337. data/spec/extensions/integer64_spec.rb +0 -22
  338. data/spec/extensions/inverted_subsets_spec.rb +0 -33
  339. data/spec/extensions/json_serializer_spec.rb +0 -336
  340. data/spec/extensions/lazy_attributes_spec.rb +0 -183
  341. data/spec/extensions/list_spec.rb +0 -275
  342. data/spec/extensions/looser_typecasting_spec.rb +0 -43
  343. data/spec/extensions/many_through_many_spec.rb +0 -2177
  344. data/spec/extensions/migration_spec.rb +0 -840
  345. data/spec/extensions/modification_detection_spec.rb +0 -93
  346. data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -92
  347. data/spec/extensions/named_timezones_spec.rb +0 -109
  348. data/spec/extensions/nested_attributes_spec.rb +0 -703
  349. data/spec/extensions/null_dataset_spec.rb +0 -85
  350. data/spec/extensions/optimistic_locking_spec.rb +0 -127
  351. data/spec/extensions/pagination_spec.rb +0 -116
  352. data/spec/extensions/pg_array_associations_spec.rb +0 -802
  353. data/spec/extensions/pg_array_ops_spec.rb +0 -144
  354. data/spec/extensions/pg_array_spec.rb +0 -398
  355. data/spec/extensions/pg_auto_constraint_validations_spec.rb +0 -165
  356. data/spec/extensions/pg_enum_spec.rb +0 -113
  357. data/spec/extensions/pg_extended_date_support_spec.rb +0 -126
  358. data/spec/extensions/pg_hstore_ops_spec.rb +0 -238
  359. data/spec/extensions/pg_hstore_spec.rb +0 -219
  360. data/spec/extensions/pg_inet_ops_spec.rb +0 -102
  361. data/spec/extensions/pg_inet_spec.rb +0 -72
  362. data/spec/extensions/pg_interval_spec.rb +0 -103
  363. data/spec/extensions/pg_json_ops_spec.rb +0 -289
  364. data/spec/extensions/pg_json_spec.rb +0 -262
  365. data/spec/extensions/pg_loose_count_spec.rb +0 -23
  366. data/spec/extensions/pg_range_ops_spec.rb +0 -60
  367. data/spec/extensions/pg_range_spec.rb +0 -487
  368. data/spec/extensions/pg_row_ops_spec.rb +0 -61
  369. data/spec/extensions/pg_row_plugin_spec.rb +0 -60
  370. data/spec/extensions/pg_row_spec.rb +0 -363
  371. data/spec/extensions/pg_static_cache_updater_spec.rb +0 -93
  372. data/spec/extensions/pg_timestamptz_spec.rb +0 -17
  373. data/spec/extensions/prepared_statements_safe_spec.rb +0 -66
  374. data/spec/extensions/prepared_statements_spec.rb +0 -182
  375. data/spec/extensions/pretty_table_spec.rb +0 -123
  376. data/spec/extensions/query_spec.rb +0 -94
  377. data/spec/extensions/rcte_tree_spec.rb +0 -381
  378. data/spec/extensions/round_timestamps_spec.rb +0 -39
  379. data/spec/extensions/s_spec.rb +0 -60
  380. data/spec/extensions/schema_caching_spec.rb +0 -64
  381. data/spec/extensions/schema_dumper_spec.rb +0 -868
  382. data/spec/extensions/select_remove_spec.rb +0 -38
  383. data/spec/extensions/sequel_4_dataset_methods_spec.rb +0 -121
  384. data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
  385. data/spec/extensions/serialization_spec.rb +0 -365
  386. data/spec/extensions/server_block_spec.rb +0 -97
  387. data/spec/extensions/server_logging_spec.rb +0 -45
  388. data/spec/extensions/sharding_spec.rb +0 -189
  389. data/spec/extensions/shared_caching_spec.rb +0 -151
  390. data/spec/extensions/single_table_inheritance_spec.rb +0 -347
  391. data/spec/extensions/singular_table_names_spec.rb +0 -22
  392. data/spec/extensions/skip_create_refresh_spec.rb +0 -18
  393. data/spec/extensions/spec_helper.rb +0 -61
  394. data/spec/extensions/split_array_nil_spec.rb +0 -24
  395. data/spec/extensions/split_values_spec.rb +0 -57
  396. data/spec/extensions/sql_comments_spec.rb +0 -33
  397. data/spec/extensions/sql_expr_spec.rb +0 -59
  398. data/spec/extensions/static_cache_spec.rb +0 -410
  399. data/spec/extensions/string_agg_spec.rb +0 -90
  400. data/spec/extensions/string_date_time_spec.rb +0 -95
  401. data/spec/extensions/string_stripper_spec.rb +0 -68
  402. data/spec/extensions/subclasses_spec.rb +0 -79
  403. data/spec/extensions/subset_conditions_spec.rb +0 -38
  404. data/spec/extensions/symbol_aref_refinement_spec.rb +0 -28
  405. data/spec/extensions/symbol_as_refinement_spec.rb +0 -21
  406. data/spec/extensions/synchronize_sql_spec.rb +0 -124
  407. data/spec/extensions/table_select_spec.rb +0 -83
  408. data/spec/extensions/tactical_eager_loading_spec.rb +0 -141
  409. data/spec/extensions/thread_local_timezones_spec.rb +0 -67
  410. data/spec/extensions/timestamps_spec.rb +0 -209
  411. data/spec/extensions/to_dot_spec.rb +0 -153
  412. data/spec/extensions/touch_spec.rb +0 -226
  413. data/spec/extensions/tree_spec.rb +0 -284
  414. data/spec/extensions/typecast_on_load_spec.rb +0 -86
  415. data/spec/extensions/unlimited_update_spec.rb +0 -21
  416. data/spec/extensions/update_or_create_spec.rb +0 -83
  417. data/spec/extensions/update_primary_key_spec.rb +0 -105
  418. data/spec/extensions/update_refresh_spec.rb +0 -59
  419. data/spec/extensions/uuid_spec.rb +0 -101
  420. data/spec/extensions/validate_associated_spec.rb +0 -52
  421. data/spec/extensions/validation_class_methods_spec.rb +0 -1040
  422. data/spec/extensions/validation_contexts_spec.rb +0 -31
  423. data/spec/extensions/validation_helpers_spec.rb +0 -525
  424. data/spec/extensions/whitelist_security_spec.rb +0 -157
  425. data/spec/extensions/xml_serializer_spec.rb +0 -213
  426. data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
  427. data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
  428. data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  429. data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  430. data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
  431. data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
  432. data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
  433. data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
  434. data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
  435. data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
  436. data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
  437. data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
  438. data/spec/files/double_migration/001_create_sessions.rb +0 -9
  439. data/spec/files/double_migration/002_create_nodes.rb +0 -19
  440. data/spec/files/double_migration/003_3_create_users.rb +0 -4
  441. data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
  442. data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
  443. data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  444. data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
  445. data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
  446. data/spec/files/empty_migration/001_create_sessions.rb +0 -9
  447. data/spec/files/empty_migration/002_create_nodes.rb +0 -0
  448. data/spec/files/empty_migration/003_3_create_users.rb +0 -4
  449. data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
  450. data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
  451. data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
  452. data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  453. data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
  454. data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  455. data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
  456. data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  457. data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
  458. data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
  459. data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  460. data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  461. data/spec/files/reversible_migrations/001_reversible.rb +0 -5
  462. data/spec/files/reversible_migrations/002_reversible.rb +0 -5
  463. data/spec/files/reversible_migrations/003_reversible.rb +0 -5
  464. data/spec/files/reversible_migrations/004_reversible.rb +0 -5
  465. data/spec/files/reversible_migrations/005_reversible.rb +0 -10
  466. data/spec/files/reversible_migrations/006_reversible.rb +0 -10
  467. data/spec/files/reversible_migrations/007_reversible.rb +0 -10
  468. data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
  469. data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
  470. data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
  471. data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
  472. data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
  473. data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
  474. data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
  475. data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
  476. data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
  477. data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
  478. data/spec/guards_helper.rb +0 -58
  479. data/spec/integration/associations_test.rb +0 -2513
  480. data/spec/integration/database_test.rb +0 -113
  481. data/spec/integration/dataset_test.rb +0 -1880
  482. data/spec/integration/eager_loader_test.rb +0 -687
  483. data/spec/integration/migrator_test.rb +0 -262
  484. data/spec/integration/model_test.rb +0 -203
  485. data/spec/integration/plugin_test.rb +0 -2302
  486. data/spec/integration/prepared_statement_test.rb +0 -398
  487. data/spec/integration/schema_test.rb +0 -869
  488. data/spec/integration/spec_helper.rb +0 -64
  489. data/spec/integration/timezone_test.rb +0 -86
  490. data/spec/integration/transaction_test.rb +0 -354
  491. data/spec/integration/type_test.rb +0 -127
  492. data/spec/model/association_reflection_spec.rb +0 -803
  493. data/spec/model/associations_spec.rb +0 -4538
  494. data/spec/model/base_spec.rb +0 -817
  495. data/spec/model/class_dataset_methods_spec.rb +0 -146
  496. data/spec/model/dataset_methods_spec.rb +0 -198
  497. data/spec/model/eager_loading_spec.rb +0 -2262
  498. data/spec/model/hooks_spec.rb +0 -370
  499. data/spec/model/inflector_spec.rb +0 -26
  500. data/spec/model/model_spec.rb +0 -953
  501. data/spec/model/plugins_spec.rb +0 -318
  502. data/spec/model/record_spec.rb +0 -2107
  503. data/spec/model/spec_helper.rb +0 -45
  504. data/spec/model/validations_spec.rb +0 -193
  505. data/spec/model_no_assoc_spec.rb +0 -1
  506. data/spec/model_spec.rb +0 -1
  507. data/spec/plugin_spec.rb +0 -1
  508. data/spec/sequel_coverage.rb +0 -15
  509. data/spec/sequel_warning.rb +0 -4
  510. data/spec/spec_config.rb +0 -12
@@ -1,5 +1,5 @@
1
1
  Copyright (c) 2007-2008 Sharon Rosner
2
- Copyright (c) 2008-2018 Jeremy Evans
2
+ Copyright (c) 2008-2020 Jeremy Evans
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to
@@ -9,7 +9,7 @@ toolkit for Ruby.
9
9
  records to Ruby objects and handling associated records.
10
10
  * Sequel supports advanced database features such as prepared
11
11
  statements, bound variables, savepoints, two-phase commit,
12
- transaction isolation, master/slave configurations, and
12
+ transaction isolation, primary/replica configurations, and
13
13
  database sharding.
14
14
  * Sequel currently has adapters for ADO, Amalgalite,
15
15
  IBM_DB, JDBC, MySQL, Mysql2, ODBC, Oracle,
@@ -172,7 +172,7 @@ Datasets are the primary way records are retrieved and manipulated. They are ge
172
172
  posts = DB.from(:posts)
173
173
  posts = DB[:posts] # same
174
174
 
175
- Datasets will only fetch records when you tell them to. They can be manipulated to filter records, change ordering, join tables, etc.. Datasets are always frozen, and they safe to use by multiple threads concurrently.
175
+ Datasets will only fetch records when you tell them to. They can be manipulated to filter records, change ordering, join tables, etc. Datasets are always frozen, and they are safe to use by multiple threads concurrently.
176
176
 
177
177
  === Retrieving Records
178
178
 
@@ -578,7 +578,7 @@ A single model instance can also be fetched by specifying a condition:
578
578
  post = Post.first(title: 'hello world')
579
579
  post = Post.first{num_comments < 10}
580
580
 
581
- The dataset for a model class returns rows a model instances instead of plain hashes:
581
+ The dataset for a model class returns rows of model instances instead of plain hashes:
582
582
 
583
583
  DB[:posts].first.class # => Hash
584
584
  Post.first.class # => Post
@@ -894,7 +894,7 @@ in the most current release.
894
894
 
895
895
  Sequel fully supports the currently supported versions of Ruby (MRI) and JRuby. It may
896
896
  support unsupported versions of Ruby or JRuby, but such support may be dropped in any
897
- minor version of keeping it becomes a support issue. The minimum Ruby version
897
+ minor version if keeping it becomes a support issue. The minimum Ruby version
898
898
  required to run the current version of Sequel is 1.9.2.
899
899
 
900
900
  == Maintainer
data/bin/sequel CHANGED
@@ -195,6 +195,10 @@ begin
195
195
  same_db = DB.database_type==TO_DB.database_type
196
196
  index_opts = {:same_db=>same_db}
197
197
  index_opts[:index_names] = :namespace if !DB.global_index_namespace? && TO_DB.global_index_namespace?
198
+ if DB.database_type == :sqlite && !same_db
199
+ # SQLite integer types allows 64-bit integers
200
+ TO_DB.extension :integer64
201
+ end
198
202
 
199
203
  puts "Databases connections successful"
200
204
  schema_migration = eval(DB.dump_schema_migration(:indexes=>false, :same_db=>same_db))
@@ -1,29 +1,149 @@
1
1
  = Advanced Associations
2
2
 
3
- Sequel::Model's association support is very powerful and flexible, but using that power and flexibility
4
- often results in complexity.
3
+ Sequel::Model's association support is powerful and flexible, but it can be difficult for
4
+ new users to understand what the support enables. This guide shows off some of the more
5
+ advanced Sequel::Model association features.
5
6
 
6
7
  You should probably review the {Model Associations Basics and Options guide}[rdoc-ref:doc/association_basics.rdoc]
7
8
  before reviewing this guide.
8
9
 
9
- == Background: Sequel::Model association options
10
+ == Sequel::Model Eager Loading
11
+
12
+ Sequel::Model offers two different ways to perform eager loading, +eager+ and
13
+ +eager_graph+. +eager+ uses an SQL query per association, +eager_graph+ uses a single
14
+ SQL query containing JOINs.
15
+
16
+ Assuming the following associations:
17
+
18
+ Artist.one_to_many :albums
19
+ Album.one_to_many :tracks
20
+ Tracks.many_to_one :lyric
21
+
22
+ Let's say you wanted to load all artists and eagerly load the related albums, tracks, and lyrics.
23
+
24
+ Artist.eager(albums: {tracks: :lyric})
25
+ # 4 Queries:
26
+ # SELECT * FROM artists;
27
+ # SELECT * FROM albums WHERE (artist_id IN (...));
28
+ # SELECT * FROM tracks WHERE (album_id IN (...));
29
+ # SELECT * FROM lyrics WHERE (id IN (...));
30
+
31
+ Artist.eager_graph(albums: {tracks: :lyric})
32
+ # 1 Query:
33
+ # SELECT artists.id, artists.name, ...
34
+ # albums.id AS albums_id, albums.name AS albums_name, ...
35
+ # tracks.id AS tracks_id, tracks.name AS tracks_name, ...
36
+ # lyric.id AS lyric_id, ...
37
+ # FROM artists
38
+ # LEFT OUTER JOIN albums ON (albums.artist_id = artists.id)
39
+ # LEFT OUTER JOIN tracks ON (tracks.album_id = albums.id)
40
+ # LEFT OUTER JOIN lyrics AS lyric ON (lyric.id = tracks.lyric_id);
41
+
42
+ In general, the recommendation is to use +eager+ unless you have a reason to use +eager_graph+.
43
+ +eager_graph+ is needed when you want to reference columns in an associated table. For example,
44
+ if you want to order the loading of returned artists based on the names of the albums, you cannot
45
+ do:
46
+
47
+ Artist.eager(albums: {tracks: :lyric}).order{albums[:name]}
48
+
49
+ because the initial query Sequel will use would be:
50
+
51
+ # SELECT * FROM artists ORDER BY albums.name;
52
+
53
+ and +albums+ is not a valid qualifier in such a query. In this situation, you must use +eager_graph+:
54
+
55
+ Artist.eager_graph(albums: {tracks: :lyric}).order{albums[:name]}
56
+
57
+ Whether +eager+ or +eager_graph+ performs better is association and database dependent. If
58
+ you are concerned about performance, you should try benchmarking both cases with appropriate
59
+ data to see which performs better.
60
+
61
+ === Mixing eager and eager_graph
62
+
63
+ Sequel offers the ability to mix +eager+ and +eager_graph+ when loading results. This can
64
+ be done at the main level by calling both +eager+ and +eager_graph+ on the same dataset:
65
+
66
+ Album.eager(:artist).eager_graph(:tracks)
67
+ # 2 Queries:
68
+ # SELECT albums.id, albums.name, ...
69
+ # artist.id AS artist_id, artist.name AS artist_name, ...
70
+ # FROM albums
71
+ # LEFT OUTER JOIN artists AS artist ON (artist.id = albums.artist_id);
72
+ # SELECT * FROM artists WHERE (id IN (...));
73
+
74
+ You can also use +eager+ to load initial associations, and +eager_graph+ to load
75
+ remaining associations, by using +eager_graph+ in an eager load callback:
76
+
77
+ Artist.eager(albums: {tracks: proc{|ds| ds.eager_graph(:lyric)}})
78
+ # 3 Queries:
79
+ # SELECT * FROM artists;
80
+ # SELECT * FROM albums WHERE (artist_id IN (...));
81
+ # SELECT tracks.id, tracks.name, ...
82
+ # lyric.id AS lyric_id, ...
83
+ # FROM tracks
84
+ # LEFT OUTER JOIN lyrics AS lyric ON (lyric.id = tracks.lyric_id)
85
+ # WHERE (tracks.album_id IN (...));
86
+
87
+ Using the +eager_graph_eager+ plugin, you can use +eager_graph+ to load the
88
+ initial associations, and +eager+ to load the remaining associations. When
89
+ you call +eager_graph_eager+, you must specify the dependency chain at
90
+ which to start the eager loading via +eager+:
91
+
92
+ Artist.plugin :eager_graph_eager
93
+ Artist.eager_graph(albums: :tracks).eager_graph_eager([:albums, :tracks], :lyric)
94
+ # 2 Queries:
95
+ # SELECT artists.id, artists.name, ...
96
+ # albums.id AS albums_id, albums.name AS albums_name, ...
97
+ # tracks.id AS tracks_id, tracks.name AS tracks_name, ...
98
+ # FROM artists
99
+ # LEFT OUTER JOIN albums ON (albums.artist_id = artists.id)
100
+ # LEFT OUTER JOIN tracks ON (tracks.album_id= albums.id);
101
+ # SELECT * FROM lyrics WHERE (id IN (...));
102
+
103
+ These two approaches can also be nested, with +eager+ -> +eager_graph+ -> +eager+:
104
+
105
+ Album.plugin :eager_graph_eager
106
+ Artist.eager(albums: proc{|ds| ds.eager_graph(:tracks).eager_graph_eager([:tracks], :lyric)})
107
+ # 3 Queries:
108
+ # SELECT * FROM artists;
109
+ # SELECT albums.id, albums.name, ...
110
+ # tracks.id AS tracks_id, tracks.name AS tracks_name, ...
111
+ # FROM albums
112
+ # LEFT OUTER JOIN tracks ON (tracks.album_id = albums.id)
113
+ # WHERE (albums.artist_id IN (...));
114
+ # SELECT * FROM lyrics WHERE (id IN (...));
115
+
116
+ Or with 2 separate +eager_graph+ queries:
117
+
118
+ Artist.eager_graph(:albums).eager_graph_eager([:albums], :tracks=>proc{|ds| ds.eager_graph(:lyric)})
119
+ # 2 Queries:
120
+ # SELECT artists.id, artists.name, ...
121
+ # albums.id AS albums_id, albums.name AS albums_name, ...
122
+ # FROM artists
123
+ # LEFT OUTER JOIN albums ON (albums.artist_id = artists.id);
124
+ # SELECT tracks.id, tracks.name, ...
125
+ # lyric.id AS lyric_id, ...
126
+ # FROM tracks
127
+ # LEFT OUTER JOIN lyrics AS lyric ON (lyric.id = tracks.lyric_id)
128
+ # WHERE (tracks.album_id IN (...));
129
+
130
+ == Sequel::Model Association Loading Options
10
131
 
11
132
  There are a bunch of advanced association options that are available to
12
133
  handle more complex cases. First we'll go over some of the simpler ones:
13
134
 
14
135
  All associations take a block that can be used to further filter/modify the
15
- default dataset. There's also an :eager_block option if you want to use
16
- a different block when eager loading via <tt>Dataset#eager</tt>. Association blocks are
17
- useful for things like:
136
+ default dataset:
18
137
 
19
138
  Artist.one_to_many :gold_albums, class: :Album do |ds|
20
139
  ds.where{copies_sold > 500000}
21
140
  end
22
141
 
23
- There are a whole bunch of options for changing how the association is eagerly
24
- loaded via <tt>Dataset#eager_graph</tt>: <tt>:graph_block</tt>, <tt>:graph_conditions</tt>,
25
- <tt>:graph_only_conditions</tt>, <tt>:graph_join_type</tt> (and <tt>:graph_join_table_*</tt> ones for
26
- JOINing to the join table in a many_to_many association).
142
+ There's also an :eager_block option if you want to use a different block when
143
+ eager loading via <tt>Dataset#eager</tt>.
144
+
145
+ There are many options for changing how the association is eagerly
146
+ loaded via <tt>Dataset#eager_graph</tt>:
27
147
 
28
148
  :graph_join_type :: The type of join to do (<tt>:inner</tt>, <tt>:left</tt>, <tt>:right</tt>)
29
149
  :graph_conditions :: Additional conditions to put on join (needs to be a
@@ -62,10 +182,6 @@ These can be used like this:
62
182
  # Handles the case where both key columns have the name artist_name, and you want to use
63
183
  # a JOIN USING
64
184
  Artist.one_to_many :albums, key: :artist_name, graph_only_conditions: [:artist_name]
65
-
66
- Remember, using +eager_graph+ is generally only necessary when you need to
67
- filter/order based on columns in an associated table, it is recommended to
68
- use +eager+ for eager loading if possible.
69
185
 
70
186
  One advantage of using +eager_graph+ is that you can easily filter/order
71
187
  on columns in an associated table on a per-query basis, using regular
@@ -83,6 +199,8 @@ For lazy loading (e.g. Model[1].association), the <tt>:dataset</tt> option can b
83
199
  to specify an arbitrary dataset (one that uses different keys, multiple keys,
84
200
  joins to other tables, etc.).
85
201
 
202
+ == Custom Eager Loaders
203
+
86
204
  For eager loading via +eager+, the <tt>:eager_loader</tt> option can be used to specify
87
205
  how to eagerly load a complex association. This is an extremely powerful
88
206
  option. Though it can often be verbose (compared to other things in Sequel),
@@ -613,7 +731,7 @@ associations:
613
731
  one_to_one :tracks, key: [:disc_number, :number, :album_id], primary_key: [:disc_number, :number, :album_id]
614
732
  end
615
733
 
616
- === Tree - All Ancestors and Descendents
734
+ === Tree - All Ancestors and Descendants
617
735
 
618
736
  Let's say you want to store a tree relationship in your database, it's pretty
619
737
  simple:
@@ -631,7 +749,7 @@ node.children. You can even eager load the relationship up to a certain depth:
631
749
  # Load parents and grandparents for a group of nodes
632
750
  Node.where{id < 10}.eager(parent: :parent).all
633
751
 
634
- What if you want to get all ancestors up to the root node, or all descendents,
752
+ What if you want to get all ancestors up to the root node, or all descendants,
635
753
  without knowing the depth of the tree?
636
754
 
637
755
  class Node < Sequel::Model
@@ -652,7 +770,7 @@ without knowing the depth of the tree?
652
770
  id_map = {}
653
771
  # Create an map of parent_ids to nodes that have that parent id
654
772
  non_root_nodes.each{|n| (id_map[n.parent_id] ||= []) << n}
655
- # Doesn't cause an infinte loop, because when only the root node
773
+ # Doesn't cause an infinite loop, because when only the root node
656
774
  # is left, this is not called.
657
775
  Node.where(id: id_map.keys).eager(:ancestors).all do |node|
658
776
  # Populate the parent association for each node
@@ -761,4 +879,4 @@ associated tickets.
761
879
  end
762
880
 
763
881
  Note that it is often better to use a sum cache instead of this approach. You can implement
764
- a sum cache using +after_create+, +after_update+, and +after_delete+ hooks, or preferrably using a database trigger.
882
+ a sum cache using +after_create+, +after_update+, and +after_delete+ hooks, or preferably using a database trigger.
@@ -113,7 +113,7 @@ many rows in the current table, by using a join table to associate the two table
113
113
  The one_through_one association can be thought of as a subset of the many_to_many
114
114
  association, but where there can only be 0 or 1 records in the associated table.
115
115
  This is useful if there is a unique constraint on the foreign key in the join table
116
- that refrences the current table. It's also useful if you want to impose an order
116
+ that references the current table. It's also useful if you want to impose an order
117
117
  on the association and just want the first record returned. The one_through_one
118
118
  association is so named because it sets up a one-to-one association through a
119
119
  single join table.
@@ -781,7 +781,7 @@ Sequel is designed to be very flexible. If the default behavior of the
781
781
  association modification methods isn't what you desire, you can override
782
782
  the methods in your classes. However, you should be aware that for each
783
783
  of the association modification methods described, there is a private
784
- method that is preceeded by an underscore that does the actual
784
+ method that is preceded by an underscore that does the actual
785
785
  modification. The public method without the underscore handles caching
786
786
  and callbacks, and shouldn't be overridden by the user.
787
787
 
@@ -1069,7 +1069,7 @@ option of the first association, it doesn't attempt to merge them.
1069
1069
  In addition to the options hash, the :clone option will copy a block argument
1070
1070
  from the existing situation. If you want a cloned association to not have the
1071
1071
  same block as the association you are cloning from, specify the block: nil option
1072
- in additon to the :clone option.
1072
+ in addition to the :clone option.
1073
1073
 
1074
1074
  ==== :dataset
1075
1075
 
@@ -1676,11 +1676,16 @@ instances.
1676
1676
  ==== :instance_specific
1677
1677
 
1678
1678
  This allows you to override the setting of whether the dataset contains instance
1679
- specific code. For example, if you are passing a block to the association,
1679
+ specific code. If you are passing a block to the association,
1680
1680
  Sequel sets this to true by default, which disables some optimizations that
1681
1681
  would be invalid if the association is instance specific. If you know that the
1682
1682
  block does not contain instance specific code, you can set this to false to
1683
- reenable the optimizations.
1683
+ reenable the optimizations. Instance specific code is mostly commonly calling
1684
+ model instance methods inside an association block, but also
1685
+ includes cases where the association block can return different values based
1686
+ on the runtime environment, such as calls to <tt>Time.now</tt> in the block.
1687
+ Associations that use the :dataset option are always considered instance specific,
1688
+ even if explicitly specified otherwise.
1684
1689
 
1685
1690
  ==== :cartesian_product_number
1686
1691
 
@@ -55,6 +55,7 @@ Without a filename argument, the sqlite adapter will setup a new sqlite database
55
55
 
56
56
  dataset.exclude(:active).delete
57
57
  dataset.where{price < 100}.update(:active => true)
58
+ dataset.where(:active).update(:price => Sequel[:price] * 0.90)
58
59
 
59
60
  == Datasets are Enumerable
60
61
 
@@ -7,7 +7,7 @@ this guide will be specific about which are strictly necessary.
7
7
 
8
8
  == Require Sequel
9
9
 
10
- This is sort of a no brainer, but you need to require the library
10
+ This is sort of a no-brainer, but you need to require the library
11
11
  first. This is a strict requirement, none of the other code can
12
12
  be executed unless the library has been required first. Example:
13
13
 
@@ -70,7 +70,7 @@ copied into the subclass when model subclasses are created. Example:
70
70
  == Load Model Classes
71
71
 
72
72
  After you have established a database connection, and configured your
73
- global model configration and global plugins, you can load your model
73
+ global model configuration and global plugins, you can load your model
74
74
  classes. It's recommended to have a separate file for each model class,
75
75
  unless the model classes are very simple. Example:
76
76
 
@@ -91,6 +91,16 @@ unsafe runtime modification of the configuration:
91
91
  model_classes.each(&:freeze)
92
92
  DB.freeze
93
93
 
94
+ The `subclasses` plugin can be used to keep track of all model classes
95
+ that have been setup in your application. Finalizing their associations
96
+ and freezing them can easily be achieved through the plugin:
97
+
98
+ # Register the plugin before setting up the models
99
+ Sequel::Model.plugin :subclasses
100
+ # ... setup models
101
+ # Now finalize associations & freeze models by calling the plugin:
102
+ Sequel::Model.freeze_descendents
103
+
94
104
  == Disconnect If Using Forking Webserver with Code Preloading
95
105
 
96
106
  If you are using a forking webserver such as unicorn or passenger, with
@@ -36,8 +36,8 @@ Ranges (both inclusive and exclusive) can also be used:
36
36
 
37
37
  If you need to select multiple items from a dataset, you can supply an array:
38
38
 
39
- items.where(id: [1, 38, 47, 99]).sql
40
- # "SELECT * FROM items WHERE (id IN (1, 38, 47, 99))"
39
+ items.where(id: [1, 38, 47, 99]).sql
40
+ # "SELECT * FROM items WHERE (id IN (1, 38, 47, 99))"
41
41
 
42
42
  == Filtering using expressions
43
43
 
@@ -106,6 +106,21 @@ You can also use placeholders with :placeholder and a hash of placeholder values
106
106
  items.where(Sequel.lit('category = :category', category: "ruby")).sql
107
107
  # "SELECT * FROM items WHERE category = 'ruby'"
108
108
 
109
+ In order to combine AND and OR together, you have a few options:
110
+
111
+ items.where(category: nil).or(category: "ruby")
112
+ # SELECT * FROM items WHERE (category IS NULL) OR (category = 'ruby')
113
+
114
+ This won't work if you add other conditions:
115
+
116
+ items.where(name: "Programming in Ruby").where(category: nil).or(category: 'ruby')
117
+ # SELECT * FROM items WHERE ((name = 'Programming in Ruby') AND (category IS NULL)) OR (category = 'ruby')
118
+
119
+ The OR applies globally and not locally. To fix this, use & and |:
120
+
121
+ items.where(Sequel[name: "Programming in Ruby"] & (Sequel[category: nil] | Sequel[category: "ruby"]))
122
+ # SELECT * FROM items WHERE ((name = 'Programming in Ruby') AND ((category IS NULL) OR (category = 'ruby')))
123
+
109
124
  === Specifying SQL functions
110
125
 
111
126
  Sequel also allows you to specify functions by using the Sequel.function method:
@@ -15,13 +15,13 @@ and you call a mass assignment method with a hash:
15
15
 
16
16
  the mass assignment method will go through each key in the hash, append <tt>=</tt> to it to determine the
17
17
  setter method, and if the setter method is defined and access to it is not restricted, Sequel will call the
18
- setter method with the hash value. So if we assume that the posts table has subject and text columns, what
18
+ setter method with the hash value. So if we assume that the posts table has title and body columns, what
19
19
  the above mass assignment call actually does is:
20
-
20
+
21
21
  post.title=('T')
22
22
  post.body=('B')
23
23
 
24
- By default, there are two types of setter methods that are restricted.
24
+ By default, there are two types of setter methods that are restricted.
25
25
  The first is methods like <tt>typecast_on_assignment=</tt> and <tt>==</tt>, which don't affect columns.
26
26
  These methods cannot be enabled for mass assignment.
27
27
  The second is primary key setters.
@@ -4,7 +4,7 @@ How you design your model dataset methods can significantly affect the flexibili
4
4
 
5
5
  == Flexibility: Use Single Method Per Task
6
6
 
7
- In general, it is recommended that you have a single method per task for maximum flexibilty. For example, let's say you need to retrieve all albums released in a given year, ordered by number of units sold descending, and only care about the id, name and number of units sold. One way to do this is in your application code (outside the model), you can
7
+ In general, it is recommended that you have a single method per task for maximum flexibility. For example, let's say you need to retrieve all albums released in a given year, ordered by number of units sold descending, and only care about the id, name and number of units sold. One way to do this is in your application code (outside the model), you can
8
8
  call the dataset methods directly:
9
9
 
10
10
  Album.
@@ -212,7 +212,7 @@ In general you should only require plugin arguments if you absolutely must have
212
212
 
213
213
  == Handling Subclasses
214
214
 
215
- Sequel::Model uses a copy-on-subclassing approach to model state. So instead of model subclasses asking their parent class for a value if they don't have it defined, the value is automatically copied from the parent class to the subclass when the subclass is created. While you can do this by overriding the inherited class method, there is a available shortcut that handles most cases:
215
+ Sequel::Model uses a copy-on-subclassing approach to model state. So instead of having a model subclass ask its superclass for a value if the subclass don't have the value defined, the value should be copied from the parent class to the subclass when the subclass is created. While this can be implemented by overriding the +inherited+ class method, there is an available shortcut that handles most cases:
216
216
 
217
217
  module Sequel::Plugins::Foo
218
218
  module ClassMethods
@@ -75,15 +75,24 @@ These options are shared by all adapters unless otherwise noted.
75
75
 
76
76
  :adapter :: The adapter to use
77
77
  :database :: The name of the database to which to connect
78
+ :extensions :: Extensions to load into this Database instance. Can be a symbol, array of symbols,
79
+ or string with extensions separated by columns. These extensions are loaded after
80
+ connections are made by the :preconnect option.
78
81
  :cache_schema :: Whether schema should be cached for this database (true by default)
79
82
  :default_string_column_size :: The default size for string columns (255 by default)
80
83
  :host :: The hostname of the database server to which to connect
81
84
  :keep_reference :: Whether to keep a reference to the database in Sequel::DATABASES (true by default)
85
+ :logger :: A specific SQL logger to log to
82
86
  :loggers :: An array of SQL loggers to log to
83
87
  :log_connection_info :: Whether to include connection information in log messages (false by default)
84
88
  :log_warn_duration :: The amount of seconds after which the queries are logged at :warn level
85
89
  :password :: The password for the user account
86
- :servers :: A hash with symbol keys and hash or proc values, used with master/slave/partitioned database configurations
90
+ :preconnect :: Whether to automatically make the maximum number of connections when setting up the pool.
91
+ Can be set to "concurrently" to connect in parallel.
92
+ :preconnect_extensions :: Similar to the :extensions option, but loads the extensions before the
93
+ connections are made by the :preconnect option.
94
+ :quote_identifiers :: Whether to quote identifiers.
95
+ :servers :: A hash with symbol keys and hash or proc values, used with primary/replica and sharded database configurations
87
96
  :sql_log_level :: The level at which to issue queries to the loggers (:info by default)
88
97
  :test :: Whether to test that a valid database connection can be made (true by default)
89
98
  :user :: The user account name to use logging in
@@ -95,8 +104,6 @@ The following options can be specified and are passed to the database's internal
95
104
  useful for customizations that you want to apply to all connections (nil by default).
96
105
  :max_connections :: The maximum size of the connection pool (4 connections by default on most databases)
97
106
  :pool_timeout :: The number of seconds to wait if a connection cannot be acquired before raising an error (5 seconds by default)
98
- :preconnect :: Whether to automatically make the maximum number of connections when setting up the pool.
99
- Can be set to "concurrently" to connect in parallel.
100
107
  :single_threaded :: Whether to use a single-threaded (non-thread safe) connection pool
101
108
 
102
109
  == Adapter specific connection options
@@ -180,9 +187,8 @@ For Derby, H2, HSQLDB, JTDS, MySQL, Postgres, SQLite3
180
187
  the adapters can use the `jdbc-*` gem, for the others you need to have the `.jar` in your CLASSPATH
181
188
  or load the Java class manually before calling Sequel.connect.
182
189
 
183
-
184
190
  Note that when using a JDBC adapter, the best way to use Sequel
185
- is via Sequel.connect, NOT Sequel.jdbc. Use the JDBC connection
191
+ is via Sequel.connect using a connection string, NOT Sequel.jdbc. Use the JDBC connection
186
192
  string when connecting, which will be in a different format than
187
193
  the native connection string. The connection string should start
188
194
  with 'jdbc:'. For PostgreSQL, use 'jdbc:postgresql:', and for
@@ -194,11 +200,15 @@ Sequel does no preprocessing of JDBC connection strings, it passes them directly
194
200
  So if you have problems getting a connection string to work, look up the
195
201
  documentation for the JDBC driver.
196
202
 
203
+ The jdbc adapter does not handle common options such as +:host+,
204
+ +:user+, and +:port+. If you must use a hash of options when connecting,
205
+ provide the full JDBC connection string as the :uri option.
206
+
197
207
  Example connection strings:
198
208
 
199
209
  jdbc:sqlite::memory:
200
210
  jdbc:postgresql://localhost/database?user=username
201
- jdbc:mysql://localhost/test?user=root&password=root
211
+ jdbc:mysql://localhost/test?user=root&password=root&serverTimezone=UTC
202
212
  jdbc:h2:mem:
203
213
  jdbc:hsqldb:mem:mymemdb
204
214
  jdbc:derby:memory:myDb;create=true
@@ -230,10 +240,14 @@ The following additional options are supported:
230
240
  There are a few issues with specific jdbc driver gems:
231
241
 
232
242
  jdbc-h2 :: jdbc-h2 versions greater than 1.3.175 have issues with ORDER BY not working correctly in some cases.
243
+ jdbc-mysql :: Depending on the configuration of the MySQL server, jdbc-mysql versions greater 8 may complain
244
+ about the server time zone being unrecognized. You can either use an older jdbc-mysql version,
245
+ or you can specify the +serverTimezone+ option in the connection string, as shown in the example
246
+ jdbc:mysql connection string above.
233
247
 
234
248
  === mysql
235
249
 
236
- Requires: mysqlplus (or mysql if mysqlplus is not available)
250
+ Requires: mysql
237
251
 
238
252
  The MySQL adapter does not support the pure-ruby mysql.rb driver, it requires the C-extension driver.
239
253
 
@@ -254,7 +268,8 @@ The following additional options are supported:
254
268
  or an array of symbols or strings (e.g. <tt>:sql_mode=>[:no_zero_date, :pipes_as_concat]</tt>).
255
269
  :timeout :: Sets the wait_timeout for the connection, defaults to 1 month.
256
270
  :read_timeout :: Set the timeout in seconds for reading back results to a query.
257
- :connect_timeout :: Set the timeout in seconds before a connection attempt is abandoned.
271
+ :connect_timeout :: Set the timeout in seconds before a connection attempt is abandoned
272
+ (may not be supported when using MariaDB 10.2+ client libraries).
258
273
 
259
274
  The :sslkey, :sslcert, :sslca, :sslcapath, and :sslca options (in that order) are passed to Mysql#ssl_set method
260
275
  if either the :sslca or :sslkey option is given.
@@ -309,6 +324,10 @@ The following additional options are supported:
309
324
  conversion is done, so an error is raised if you attempt to retrieve an infinite
310
325
  timestamp/date. You can set this to :nil to convert to nil, :string to leave
311
326
  as a string, or :float to convert to an infinite float.
327
+ :conn_str :: Use connection string (in form of `host=x port=y ...`). Ignores all other options, only supported with pg
328
+ library. See https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING and
329
+ https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS for format and list of supported
330
+ options.
312
331
  :connect_timeout :: Set the number of seconds to wait for a connection (default 20, only respected
313
332
  if using the pg library).
314
333
  :driver_options :: A hash of options to pass to the underlying driver (only respected if using the pg library)
@@ -386,6 +405,9 @@ options that you may want to set are :login_timeout, :timeout, :tds_version, :az
386
405
 
387
406
  Other Sequel specific options:
388
407
 
408
+ :ansi :: Set to true to enable the ANSI compatibility settings when connecting
409
+ (ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ANSI_NULL_DFLT_ON, QUOTED_IDENTIFIER,
410
+ CONCAT_NULL_YIELDS_NULL).
389
411
  :server_version :: Override the server version to use (9000000 = SQL Server 2005).
390
412
  This also works on any other adapter that connects to Microsoft
391
413
  SQL Server.