sequel 5.28.0 → 5.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (380) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +64 -1922
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/doc/advanced_associations.rdoc +4 -4
  6. data/doc/association_basics.rdoc +3 -3
  7. data/doc/code_order.rdoc +12 -2
  8. data/doc/model_dataset_method_design.rdoc +1 -1
  9. data/doc/postgresql.rdoc +71 -0
  10. data/doc/release_notes/5.29.0.txt +22 -0
  11. data/doc/release_notes/5.30.0.txt +20 -0
  12. data/doc/release_notes/5.31.0.txt +148 -0
  13. data/doc/release_notes/5.32.0.txt +46 -0
  14. data/doc/release_notes/5.33.0.txt +24 -0
  15. data/doc/testing.rdoc +1 -1
  16. data/lib/sequel/adapters/postgres.rb +5 -1
  17. data/lib/sequel/adapters/shared/access.rb +6 -6
  18. data/lib/sequel/adapters/shared/mssql.rb +5 -5
  19. data/lib/sequel/adapters/shared/mysql.rb +10 -10
  20. data/lib/sequel/adapters/shared/oracle.rb +16 -16
  21. data/lib/sequel/adapters/shared/postgres.rb +169 -14
  22. data/lib/sequel/adapters/shared/sqlanywhere.rb +9 -9
  23. data/lib/sequel/adapters/shared/sqlite.rb +32 -5
  24. data/lib/sequel/adapters/tinytds.rb +1 -1
  25. data/lib/sequel/connection_pool/sharded_threaded.rb +2 -2
  26. data/lib/sequel/connection_pool/threaded.rb +1 -1
  27. data/lib/sequel/core.rb +318 -314
  28. data/lib/sequel/database/query.rb +1 -1
  29. data/lib/sequel/database/schema_generator.rb +1 -1
  30. data/lib/sequel/database/transactions.rb +8 -12
  31. data/lib/sequel/dataset/misc.rb +2 -2
  32. data/lib/sequel/extensions/connection_expiration.rb +2 -2
  33. data/lib/sequel/extensions/connection_validator.rb +2 -2
  34. data/lib/sequel/extensions/fiber_concurrency.rb +24 -0
  35. data/lib/sequel/extensions/index_caching.rb +9 -7
  36. data/lib/sequel/extensions/integer64.rb +2 -0
  37. data/lib/sequel/extensions/migration.rb +1 -1
  38. data/lib/sequel/extensions/pg_enum.rb +5 -2
  39. data/lib/sequel/extensions/pg_hstore.rb +6 -0
  40. data/lib/sequel/extensions/pg_inet.rb +13 -5
  41. data/lib/sequel/extensions/pg_interval.rb +2 -0
  42. data/lib/sequel/extensions/pg_range.rb +2 -0
  43. data/lib/sequel/extensions/pg_timestamptz.rb +2 -0
  44. data/lib/sequel/extensions/run_transaction_hooks.rb +72 -0
  45. data/lib/sequel/extensions/schema_dumper.rb +10 -4
  46. data/lib/sequel/extensions/server_block.rb +3 -3
  47. data/lib/sequel/model/associations.rb +18 -5
  48. data/lib/sequel/model/base.rb +60 -53
  49. data/lib/sequel/model/plugins.rb +1 -0
  50. data/lib/sequel/plugins/association_lazy_eager_option.rb +66 -0
  51. data/lib/sequel/plugins/association_multi_add_remove.rb +2 -0
  52. data/lib/sequel/plugins/association_proxies.rb +2 -0
  53. data/lib/sequel/plugins/boolean_subsets.rb +4 -1
  54. data/lib/sequel/plugins/class_table_inheritance.rb +26 -26
  55. data/lib/sequel/plugins/dirty.rb +13 -13
  56. data/lib/sequel/plugins/empty_failure_backtraces.rb +38 -0
  57. data/lib/sequel/plugins/forbid_lazy_load.rb +214 -0
  58. data/lib/sequel/plugins/json_serializer.rb +18 -11
  59. data/lib/sequel/plugins/single_table_inheritance.rb +15 -15
  60. data/lib/sequel/plugins/skip_saving_columns.rb +108 -0
  61. data/lib/sequel/plugins/subclasses.rb +2 -0
  62. data/lib/sequel/plugins/throw_failures.rb +1 -1
  63. data/lib/sequel/timezones.rb +6 -4
  64. data/lib/sequel/version.rb +1 -1
  65. metadata +18 -367
  66. data/Rakefile +0 -151
  67. data/doc/release_notes/4.0.0.txt +0 -262
  68. data/doc/release_notes/4.1.0.txt +0 -85
  69. data/doc/release_notes/4.10.0.txt +0 -226
  70. data/doc/release_notes/4.11.0.txt +0 -147
  71. data/doc/release_notes/4.12.0.txt +0 -105
  72. data/doc/release_notes/4.13.0.txt +0 -169
  73. data/doc/release_notes/4.14.0.txt +0 -68
  74. data/doc/release_notes/4.15.0.txt +0 -56
  75. data/doc/release_notes/4.16.0.txt +0 -36
  76. data/doc/release_notes/4.17.0.txt +0 -38
  77. data/doc/release_notes/4.18.0.txt +0 -36
  78. data/doc/release_notes/4.19.0.txt +0 -45
  79. data/doc/release_notes/4.2.0.txt +0 -129
  80. data/doc/release_notes/4.20.0.txt +0 -79
  81. data/doc/release_notes/4.21.0.txt +0 -94
  82. data/doc/release_notes/4.22.0.txt +0 -72
  83. data/doc/release_notes/4.23.0.txt +0 -65
  84. data/doc/release_notes/4.24.0.txt +0 -99
  85. data/doc/release_notes/4.25.0.txt +0 -181
  86. data/doc/release_notes/4.26.0.txt +0 -44
  87. data/doc/release_notes/4.27.0.txt +0 -78
  88. data/doc/release_notes/4.28.0.txt +0 -57
  89. data/doc/release_notes/4.29.0.txt +0 -41
  90. data/doc/release_notes/4.3.0.txt +0 -40
  91. data/doc/release_notes/4.30.0.txt +0 -37
  92. data/doc/release_notes/4.31.0.txt +0 -57
  93. data/doc/release_notes/4.32.0.txt +0 -132
  94. data/doc/release_notes/4.33.0.txt +0 -88
  95. data/doc/release_notes/4.34.0.txt +0 -86
  96. data/doc/release_notes/4.35.0.txt +0 -130
  97. data/doc/release_notes/4.36.0.txt +0 -116
  98. data/doc/release_notes/4.37.0.txt +0 -50
  99. data/doc/release_notes/4.38.0.txt +0 -67
  100. data/doc/release_notes/4.39.0.txt +0 -127
  101. data/doc/release_notes/4.4.0.txt +0 -92
  102. data/doc/release_notes/4.40.0.txt +0 -179
  103. data/doc/release_notes/4.41.0.txt +0 -77
  104. data/doc/release_notes/4.42.0.txt +0 -221
  105. data/doc/release_notes/4.43.0.txt +0 -87
  106. data/doc/release_notes/4.44.0.txt +0 -125
  107. data/doc/release_notes/4.45.0.txt +0 -370
  108. data/doc/release_notes/4.46.0.txt +0 -404
  109. data/doc/release_notes/4.47.0.txt +0 -56
  110. data/doc/release_notes/4.48.0.txt +0 -293
  111. data/doc/release_notes/4.49.0.txt +0 -222
  112. data/doc/release_notes/4.5.0.txt +0 -34
  113. data/doc/release_notes/4.6.0.txt +0 -30
  114. data/doc/release_notes/4.7.0.txt +0 -103
  115. data/doc/release_notes/4.8.0.txt +0 -175
  116. data/doc/release_notes/4.9.0.txt +0 -190
  117. data/spec/adapter_spec.rb +0 -4
  118. data/spec/adapters/db2_spec.rb +0 -170
  119. data/spec/adapters/mssql_spec.rb +0 -828
  120. data/spec/adapters/mysql_spec.rb +0 -1060
  121. data/spec/adapters/oracle_spec.rb +0 -371
  122. data/spec/adapters/postgres_spec.rb +0 -4476
  123. data/spec/adapters/spec_helper.rb +0 -44
  124. data/spec/adapters/sqlanywhere_spec.rb +0 -97
  125. data/spec/adapters/sqlite_spec.rb +0 -652
  126. data/spec/bin_spec.rb +0 -278
  127. data/spec/core/connection_pool_spec.rb +0 -1250
  128. data/spec/core/database_spec.rb +0 -2915
  129. data/spec/core/dataset_spec.rb +0 -5547
  130. data/spec/core/deprecated_spec.rb +0 -70
  131. data/spec/core/expression_filters_spec.rb +0 -1498
  132. data/spec/core/mock_adapter_spec.rb +0 -722
  133. data/spec/core/object_graph_spec.rb +0 -336
  134. data/spec/core/placeholder_literalizer_spec.rb +0 -166
  135. data/spec/core/schema_generator_spec.rb +0 -214
  136. data/spec/core/schema_spec.rb +0 -1844
  137. data/spec/core/spec_helper.rb +0 -24
  138. data/spec/core/version_spec.rb +0 -14
  139. data/spec/core_extensions_spec.rb +0 -763
  140. data/spec/core_model_spec.rb +0 -2
  141. data/spec/core_spec.rb +0 -1
  142. data/spec/deprecation_helper.rb +0 -30
  143. data/spec/extensions/accessed_columns_spec.rb +0 -51
  144. data/spec/extensions/active_model_spec.rb +0 -99
  145. data/spec/extensions/after_initialize_spec.rb +0 -28
  146. data/spec/extensions/any_not_empty_spec.rb +0 -23
  147. data/spec/extensions/arbitrary_servers_spec.rb +0 -109
  148. data/spec/extensions/association_dependencies_spec.rb +0 -125
  149. data/spec/extensions/association_multi_add_remove_spec.rb +0 -1041
  150. data/spec/extensions/association_pks_spec.rb +0 -423
  151. data/spec/extensions/association_proxies_spec.rb +0 -100
  152. data/spec/extensions/auto_literal_strings_spec.rb +0 -205
  153. data/spec/extensions/auto_validations_spec.rb +0 -229
  154. data/spec/extensions/blacklist_security_spec.rb +0 -95
  155. data/spec/extensions/blank_spec.rb +0 -69
  156. data/spec/extensions/boolean_readers_spec.rb +0 -93
  157. data/spec/extensions/boolean_subsets_spec.rb +0 -47
  158. data/spec/extensions/caching_spec.rb +0 -273
  159. data/spec/extensions/caller_logging_spec.rb +0 -52
  160. data/spec/extensions/class_table_inheritance_spec.rb +0 -750
  161. data/spec/extensions/column_conflicts_spec.rb +0 -75
  162. data/spec/extensions/column_select_spec.rb +0 -129
  163. data/spec/extensions/columns_introspection_spec.rb +0 -90
  164. data/spec/extensions/columns_updated_spec.rb +0 -35
  165. data/spec/extensions/composition_spec.rb +0 -248
  166. data/spec/extensions/connection_expiration_spec.rb +0 -151
  167. data/spec/extensions/connection_validator_spec.rb +0 -144
  168. data/spec/extensions/constant_sql_override_spec.rb +0 -24
  169. data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
  170. data/spec/extensions/constraint_validations_spec.rb +0 -439
  171. data/spec/extensions/core_refinements_spec.rb +0 -528
  172. data/spec/extensions/csv_serializer_spec.rb +0 -183
  173. data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
  174. data/spec/extensions/dataset_associations_spec.rb +0 -365
  175. data/spec/extensions/dataset_source_alias_spec.rb +0 -51
  176. data/spec/extensions/date_arithmetic_spec.rb +0 -181
  177. data/spec/extensions/datetime_parse_to_time_spec.rb +0 -169
  178. data/spec/extensions/def_dataset_method_spec.rb +0 -100
  179. data/spec/extensions/defaults_setter_spec.rb +0 -150
  180. data/spec/extensions/delay_add_association_spec.rb +0 -73
  181. data/spec/extensions/dirty_spec.rb +0 -222
  182. data/spec/extensions/duplicate_columns_handler_spec.rb +0 -104
  183. data/spec/extensions/eager_each_spec.rb +0 -62
  184. data/spec/extensions/eager_graph_eager_spec.rb +0 -100
  185. data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
  186. data/spec/extensions/error_splitter_spec.rb +0 -18
  187. data/spec/extensions/error_sql_spec.rb +0 -20
  188. data/spec/extensions/escaped_like_spec.rb +0 -40
  189. data/spec/extensions/eval_inspect_spec.rb +0 -81
  190. data/spec/extensions/exclude_or_null_spec.rb +0 -15
  191. data/spec/extensions/finder_spec.rb +0 -260
  192. data/spec/extensions/force_encoding_spec.rb +0 -126
  193. data/spec/extensions/freeze_datasets_spec.rb +0 -31
  194. data/spec/extensions/graph_each_spec.rb +0 -113
  195. data/spec/extensions/hook_class_methods_spec.rb +0 -402
  196. data/spec/extensions/identifier_mangling_spec.rb +0 -201
  197. data/spec/extensions/implicit_subquery_spec.rb +0 -58
  198. data/spec/extensions/index_caching_spec.rb +0 -66
  199. data/spec/extensions/inflector_spec.rb +0 -183
  200. data/spec/extensions/input_transformer_spec.rb +0 -69
  201. data/spec/extensions/insert_conflict_spec.rb +0 -103
  202. data/spec/extensions/insert_returning_select_spec.rb +0 -72
  203. data/spec/extensions/instance_filters_spec.rb +0 -79
  204. data/spec/extensions/instance_hooks_spec.rb +0 -246
  205. data/spec/extensions/integer64_spec.rb +0 -22
  206. data/spec/extensions/inverted_subsets_spec.rb +0 -33
  207. data/spec/extensions/json_serializer_spec.rb +0 -336
  208. data/spec/extensions/lazy_attributes_spec.rb +0 -183
  209. data/spec/extensions/list_spec.rb +0 -291
  210. data/spec/extensions/looser_typecasting_spec.rb +0 -43
  211. data/spec/extensions/many_through_many_spec.rb +0 -2177
  212. data/spec/extensions/migration_spec.rb +0 -864
  213. data/spec/extensions/modification_detection_spec.rb +0 -93
  214. data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -92
  215. data/spec/extensions/named_timezones_spec.rb +0 -218
  216. data/spec/extensions/nested_attributes_spec.rb +0 -815
  217. data/spec/extensions/null_dataset_spec.rb +0 -85
  218. data/spec/extensions/optimistic_locking_spec.rb +0 -127
  219. data/spec/extensions/pagination_spec.rb +0 -116
  220. data/spec/extensions/pg_array_associations_spec.rb +0 -802
  221. data/spec/extensions/pg_array_ops_spec.rb +0 -144
  222. data/spec/extensions/pg_array_spec.rb +0 -398
  223. data/spec/extensions/pg_auto_constraint_validations_spec.rb +0 -209
  224. data/spec/extensions/pg_enum_spec.rb +0 -118
  225. data/spec/extensions/pg_extended_date_support_spec.rb +0 -126
  226. data/spec/extensions/pg_hstore_ops_spec.rb +0 -238
  227. data/spec/extensions/pg_hstore_spec.rb +0 -219
  228. data/spec/extensions/pg_inet_ops_spec.rb +0 -102
  229. data/spec/extensions/pg_inet_spec.rb +0 -72
  230. data/spec/extensions/pg_interval_spec.rb +0 -103
  231. data/spec/extensions/pg_json_ops_spec.rb +0 -356
  232. data/spec/extensions/pg_json_spec.rb +0 -451
  233. data/spec/extensions/pg_loose_count_spec.rb +0 -23
  234. data/spec/extensions/pg_range_ops_spec.rb +0 -60
  235. data/spec/extensions/pg_range_spec.rb +0 -600
  236. data/spec/extensions/pg_row_ops_spec.rb +0 -61
  237. data/spec/extensions/pg_row_plugin_spec.rb +0 -60
  238. data/spec/extensions/pg_row_spec.rb +0 -363
  239. data/spec/extensions/pg_static_cache_updater_spec.rb +0 -93
  240. data/spec/extensions/pg_timestamptz_spec.rb +0 -17
  241. data/spec/extensions/prepared_statements_safe_spec.rb +0 -66
  242. data/spec/extensions/prepared_statements_spec.rb +0 -177
  243. data/spec/extensions/pretty_table_spec.rb +0 -123
  244. data/spec/extensions/query_spec.rb +0 -94
  245. data/spec/extensions/rcte_tree_spec.rb +0 -387
  246. data/spec/extensions/round_timestamps_spec.rb +0 -39
  247. data/spec/extensions/s_spec.rb +0 -60
  248. data/spec/extensions/schema_caching_spec.rb +0 -64
  249. data/spec/extensions/schema_dumper_spec.rb +0 -870
  250. data/spec/extensions/select_remove_spec.rb +0 -38
  251. data/spec/extensions/sequel_4_dataset_methods_spec.rb +0 -121
  252. data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
  253. data/spec/extensions/serialization_spec.rb +0 -365
  254. data/spec/extensions/server_block_spec.rb +0 -135
  255. data/spec/extensions/server_logging_spec.rb +0 -45
  256. data/spec/extensions/sharding_spec.rb +0 -197
  257. data/spec/extensions/shared_caching_spec.rb +0 -151
  258. data/spec/extensions/single_table_inheritance_spec.rb +0 -347
  259. data/spec/extensions/singular_table_names_spec.rb +0 -22
  260. data/spec/extensions/skip_create_refresh_spec.rb +0 -18
  261. data/spec/extensions/spec_helper.rb +0 -70
  262. data/spec/extensions/split_array_nil_spec.rb +0 -24
  263. data/spec/extensions/split_values_spec.rb +0 -57
  264. data/spec/extensions/sql_comments_spec.rb +0 -33
  265. data/spec/extensions/sql_expr_spec.rb +0 -59
  266. data/spec/extensions/static_cache_cache_spec.rb +0 -35
  267. data/spec/extensions/static_cache_spec.rb +0 -471
  268. data/spec/extensions/string_agg_spec.rb +0 -90
  269. data/spec/extensions/string_date_time_spec.rb +0 -95
  270. data/spec/extensions/string_stripper_spec.rb +0 -68
  271. data/spec/extensions/subclasses_spec.rb +0 -79
  272. data/spec/extensions/subset_conditions_spec.rb +0 -38
  273. data/spec/extensions/symbol_aref_refinement_spec.rb +0 -28
  274. data/spec/extensions/symbol_as_refinement_spec.rb +0 -21
  275. data/spec/extensions/synchronize_sql_spec.rb +0 -124
  276. data/spec/extensions/table_select_spec.rb +0 -83
  277. data/spec/extensions/tactical_eager_loading_spec.rb +0 -402
  278. data/spec/extensions/thread_local_timezones_spec.rb +0 -67
  279. data/spec/extensions/throw_failures_spec.rb +0 -74
  280. data/spec/extensions/timestamps_spec.rb +0 -209
  281. data/spec/extensions/to_dot_spec.rb +0 -153
  282. data/spec/extensions/touch_spec.rb +0 -226
  283. data/spec/extensions/tree_spec.rb +0 -334
  284. data/spec/extensions/typecast_on_load_spec.rb +0 -86
  285. data/spec/extensions/unlimited_update_spec.rb +0 -21
  286. data/spec/extensions/update_or_create_spec.rb +0 -83
  287. data/spec/extensions/update_primary_key_spec.rb +0 -105
  288. data/spec/extensions/update_refresh_spec.rb +0 -59
  289. data/spec/extensions/uuid_spec.rb +0 -101
  290. data/spec/extensions/validate_associated_spec.rb +0 -52
  291. data/spec/extensions/validation_class_methods_spec.rb +0 -1040
  292. data/spec/extensions/validation_contexts_spec.rb +0 -31
  293. data/spec/extensions/validation_helpers_spec.rb +0 -525
  294. data/spec/extensions/whitelist_security_spec.rb +0 -157
  295. data/spec/extensions/xml_serializer_spec.rb +0 -213
  296. data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
  297. data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
  298. data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  299. data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  300. data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
  301. data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
  302. data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
  303. data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
  304. data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
  305. data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
  306. data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
  307. data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
  308. data/spec/files/double_migration/001_create_sessions.rb +0 -9
  309. data/spec/files/double_migration/002_create_nodes.rb +0 -19
  310. data/spec/files/double_migration/003_3_create_users.rb +0 -4
  311. data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
  312. data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
  313. data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  314. data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
  315. data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
  316. data/spec/files/empty_migration/001_create_sessions.rb +0 -9
  317. data/spec/files/empty_migration/002_create_nodes.rb +0 -0
  318. data/spec/files/empty_migration/003_3_create_users.rb +0 -4
  319. data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
  320. data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
  321. data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
  322. data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  323. data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
  324. data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  325. data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
  326. data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  327. data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
  328. data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
  329. data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  330. data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  331. data/spec/files/reversible_migrations/001_reversible.rb +0 -5
  332. data/spec/files/reversible_migrations/002_reversible.rb +0 -5
  333. data/spec/files/reversible_migrations/003_reversible.rb +0 -5
  334. data/spec/files/reversible_migrations/004_reversible.rb +0 -5
  335. data/spec/files/reversible_migrations/005_reversible.rb +0 -10
  336. data/spec/files/reversible_migrations/006_reversible.rb +0 -10
  337. data/spec/files/reversible_migrations/007_reversible.rb +0 -10
  338. data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
  339. data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
  340. data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
  341. data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
  342. data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
  343. data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
  344. data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
  345. data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
  346. data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
  347. data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
  348. data/spec/guards_helper.rb +0 -59
  349. data/spec/integration/associations_test.rb +0 -2597
  350. data/spec/integration/database_test.rb +0 -113
  351. data/spec/integration/dataset_test.rb +0 -2037
  352. data/spec/integration/eager_loader_test.rb +0 -687
  353. data/spec/integration/migrator_test.rb +0 -262
  354. data/spec/integration/model_test.rb +0 -203
  355. data/spec/integration/plugin_test.rb +0 -2423
  356. data/spec/integration/prepared_statement_test.rb +0 -405
  357. data/spec/integration/schema_test.rb +0 -903
  358. data/spec/integration/spec_helper.rb +0 -71
  359. data/spec/integration/timezone_test.rb +0 -86
  360. data/spec/integration/transaction_test.rb +0 -603
  361. data/spec/integration/type_test.rb +0 -127
  362. data/spec/model/association_reflection_spec.rb +0 -803
  363. data/spec/model/associations_spec.rb +0 -4738
  364. data/spec/model/base_spec.rb +0 -875
  365. data/spec/model/class_dataset_methods_spec.rb +0 -146
  366. data/spec/model/dataset_methods_spec.rb +0 -198
  367. data/spec/model/eager_loading_spec.rb +0 -2377
  368. data/spec/model/hooks_spec.rb +0 -370
  369. data/spec/model/inflector_spec.rb +0 -26
  370. data/spec/model/model_spec.rb +0 -956
  371. data/spec/model/plugins_spec.rb +0 -429
  372. data/spec/model/record_spec.rb +0 -2118
  373. data/spec/model/spec_helper.rb +0 -46
  374. data/spec/model/validations_spec.rb +0 -220
  375. data/spec/model_no_assoc_spec.rb +0 -1
  376. data/spec/model_spec.rb +0 -1
  377. data/spec/plugin_spec.rb +0 -1
  378. data/spec/sequel_coverage.rb +0 -15
  379. data/spec/sequel_warning.rb +0 -4
  380. data/spec/spec_config.rb +0 -12
@@ -14,6 +14,7 @@ module Sequel
14
14
  def schema_parse_table(*)
15
15
  []
16
16
  end
17
+ singleton_class.send(:private, :schema_parse_table)
17
18
  end
18
19
  end
19
20
 
@@ -37,6 +38,10 @@ module Sequel
37
38
  # booleans be stored as integers, but historically Sequel has used 't'/'f'.
38
39
  attr_accessor :integer_booleans
39
40
 
41
+ # Whether to keep CURRENT_TIMESTAMP and similar expressions in UTC. By
42
+ # default, the expressions are converted to localtime.
43
+ attr_accessor :current_timestamp_utc
44
+
40
45
  # A symbol signifying the value of the default transaction mode
41
46
  attr_reader :transaction_mode
42
47
 
@@ -184,7 +189,7 @@ module Sequel
184
189
 
185
190
  # Dataset used for parsing schema
186
191
  def _parse_pragma_ds(table_name, opts)
187
- metadata_dataset.with_sql("PRAGMA table_info(?)", input_identifier_meth(opts[:dataset]).call(table_name))
192
+ metadata_dataset.with_sql("PRAGMA table_#{'x' if sqlite_version > 33100}info(?)", input_identifier_meth(opts[:dataset]).call(table_name))
188
193
  end
189
194
 
190
195
  # Run all alter_table commands in a transaction. This is technically only
@@ -252,7 +257,12 @@ module Sequel
252
257
  when :drop_constraint
253
258
  case op[:type]
254
259
  when :primary_key
255
- duplicate_table(table){|columns| columns.each{|s| s[:primary_key] = s[:auto_increment] = nil}}
260
+ duplicate_table(table) do |columns|
261
+ columns.each do |s|
262
+ s[:unique] = false if s[:primary_key]
263
+ s[:primary_key] = s[:auto_increment] = nil
264
+ end
265
+ end
256
266
  when :foreign_key
257
267
  if op[:columns]
258
268
  duplicate_table(table, :skip_foreign_key_columns=>op[:columns])
@@ -293,9 +303,15 @@ module Sequel
293
303
  false
294
304
  end
295
305
 
296
- # Surround default with parens to appease SQLite
306
+ # Surround default with parens to appease SQLite. Add support for GENERATED ALWAYS AS.
297
307
  def column_definition_default_sql(sql, column)
298
308
  sql << " DEFAULT (#{literal(column[:default])})" if column.include?(:default)
309
+ if (generated = column[:generated_always_as])
310
+ if (generated_type = column[:generated_type]) && (generated_type == :stored || generated_type == :virtual)
311
+ generated_type = generated_type.to_s.upcase
312
+ end
313
+ sql << " GENERATED ALWAYS AS (#{literal(generated)}) #{generated_type}"
314
+ end
299
315
  end
300
316
 
301
317
  # Array of PRAGMA SQL statements based on the Database options that should be applied to
@@ -414,7 +430,7 @@ module Sequel
414
430
  unless unique_columns.empty?
415
431
  unique_columns.map!{|c| quote_identifier(c)}
416
432
  def_columns.each do |c|
417
- c[:unique] = true if unique_columns.include?(quote_identifier(c[:name]))
433
+ c[:unique] = true if unique_columns.include?(quote_identifier(c[:name])) && c[:unique] != false
418
434
  end
419
435
  end
420
436
 
@@ -460,6 +476,15 @@ module Sequel
460
476
  def parse_pragma(table_name, opts)
461
477
  pks = 0
462
478
  sch = _parse_pragma_ds(table_name, opts).map do |row|
479
+ if sqlite_version > 33100
480
+ # table_xinfo PRAGMA used, remove hidden columns
481
+ # that are not generated columns
482
+ if row[:generated] = (row.delete(:hidden) != 0)
483
+ next unless row[:type].end_with?(' GENERATED ALWAYS')
484
+ row[:type] = row[:type].sub(' GENERATED ALWAYS', '')
485
+ end
486
+ end
487
+
463
488
  row.delete(:cid)
464
489
  row[:allow_null] = row.delete(:notnull).to_i == 0
465
490
  row[:default] = row.delete(:dflt_value)
@@ -476,6 +501,8 @@ module Sequel
476
501
  row
477
502
  end
478
503
 
504
+ sch.compact!
505
+
479
506
  if pks > 1
480
507
  # SQLite does not allow use of auto increment for tables
481
508
  # with composite primary keys, so remove auto_increment
@@ -592,7 +619,7 @@ module Sequel
592
619
  # SQLite has CURRENT_TIMESTAMP and related constants in UTC instead
593
620
  # of in localtime, so convert those constants to local time.
594
621
  def constant_sql_append(sql, constant)
595
- if c = CONSTANT_MAP[constant]
622
+ if (c = CONSTANT_MAP[constant]) && !db.current_timestamp_utc
596
623
  sql << c
597
624
  else
598
625
  super
@@ -145,7 +145,7 @@ module Sequel
145
145
 
146
146
  # Return true if the :conn argument is present and not active.
147
147
  def disconnect_error?(e, opts)
148
- super || (opts[:conn] && !opts[:conn].active?) || ((e.is_a?(::TinyTds::Error) && /\A(Attempt to initiate a new Adaptive Server operation with results pending|The request failed to run because the batch is aborted, this can be caused by abort signal sent from client|Adaptive Server connection timed out)/.match(e.message)))
148
+ super || (opts[:conn] && !opts[:conn].active?) || ((e.is_a?(::TinyTds::Error) && /\A(Attempt to initiate a new Adaptive Server operation with results pending|The request failed to run because the batch is aborted, this can be caused by abort signal sent from client|Adaptive Server connection timed out|DBPROCESS is dead or not enabled)/.match(e.message)))
149
149
  end
150
150
 
151
151
  # Dispose of any possible results of execution.
@@ -57,7 +57,7 @@ class Sequel::ShardedThreadedConnectionPool < Sequel::ThreadedConnectionPool
57
57
  # it is yielding all of the connections, which means that until
58
58
  # the method's block returns, the pool is locked.
59
59
  def all_connections
60
- t = Thread.current
60
+ t = Sequel.current
61
61
  sync do
62
62
  @allocated.values.each do |threads|
63
63
  threads.each do |thread, conn|
@@ -121,7 +121,7 @@ class Sequel::ShardedThreadedConnectionPool < Sequel::ThreadedConnectionPool
121
121
  # connection can be acquired, a Sequel::PoolTimeout is raised.
122
122
  def hold(server=:default)
123
123
  server = pick_server(server)
124
- t = Thread.current
124
+ t = Sequel.current
125
125
  if conn = owned_connection(t, server)
126
126
  return yield(conn)
127
127
  end
@@ -83,7 +83,7 @@ class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
83
83
  # is available or the timeout expires. If the timeout expires before a
84
84
  # connection can be acquired, a Sequel::PoolTimeout is raised.
85
85
  def hold(server=nil)
86
- t = Thread.current
86
+ t = Sequel.current
87
87
  if conn = owned_connection(t)
88
88
  return yield(conn)
89
89
  end
@@ -30,7 +30,15 @@ module Sequel
30
30
  @split_symbols = false
31
31
  @single_threaded = false
32
32
 
33
- class << self
33
+ # Mutex used to protect mutable data structures
34
+ @data_mutex = Mutex.new
35
+
36
+ # Frozen hash used as the default options hash for most options.
37
+ OPTS = {}.freeze
38
+
39
+ SPLIT_SYMBOL_CACHE = {}
40
+
41
+ module SequelMethods
34
42
  # Sequel converts two digit years in <tt>Date</tt>s and <tt>DateTime</tt>s by default,
35
43
  # so 01/02/03 is interpreted at January 2nd, 2003, and 12/13/99 is interpreted
36
44
  # as December 13, 1999. You can override this to treat those dates as
@@ -63,361 +71,357 @@ module Sequel
63
71
  # require for backwards compatibility.
64
72
  alias orig_require require
65
73
  private :orig_require
66
- end
67
74
 
68
- # Returns true if the passed object could be a specifier of conditions, false otherwise.
69
- # Currently, Sequel considers hashes and arrays of two element arrays as
70
- # condition specifiers.
71
- #
72
- # Sequel.condition_specifier?({}) # => true
73
- # Sequel.condition_specifier?([[1, 2]]) # => true
74
- # Sequel.condition_specifier?([]) # => false
75
- # Sequel.condition_specifier?([1]) # => false
76
- # Sequel.condition_specifier?(1) # => false
77
- def self.condition_specifier?(obj)
78
- case obj
79
- when Hash
80
- true
81
- when Array
82
- !obj.empty? && !obj.is_a?(SQL::ValueList) && obj.all?{|i| i.is_a?(Array) && (i.length == 2)}
83
- else
84
- false
75
+ # Returns true if the passed object could be a specifier of conditions, false otherwise.
76
+ # Currently, Sequel considers hashes and arrays of two element arrays as
77
+ # condition specifiers.
78
+ #
79
+ # Sequel.condition_specifier?({}) # => true
80
+ # Sequel.condition_specifier?([[1, 2]]) # => true
81
+ # Sequel.condition_specifier?([]) # => false
82
+ # Sequel.condition_specifier?([1]) # => false
83
+ # Sequel.condition_specifier?(1) # => false
84
+ def condition_specifier?(obj)
85
+ case obj
86
+ when Hash
87
+ true
88
+ when Array
89
+ !obj.empty? && !obj.is_a?(SQL::ValueList) && obj.all?{|i| i.is_a?(Array) && (i.length == 2)}
90
+ else
91
+ false
92
+ end
85
93
  end
86
- end
87
94
 
88
- # Frozen hash used as the default options hash for most options.
89
- OPTS = {}.freeze
95
+ # Creates a new database object based on the supplied connection string
96
+ # and optional arguments. The specified scheme determines the database
97
+ # class used, and the rest of the string specifies the connection options.
98
+ # For example:
99
+ #
100
+ # DB = Sequel.connect('sqlite:/') # Memory database
101
+ # DB = Sequel.connect('sqlite://blog.db') # ./blog.db
102
+ # DB = Sequel.connect('sqlite:///blog.db') # /blog.db
103
+ # DB = Sequel.connect('postgres://user:password@host:port/database_name')
104
+ # DB = Sequel.connect('sqlite:///blog.db', max_connections: 10)
105
+ #
106
+ # You can also pass a single options hash:
107
+ #
108
+ # DB = Sequel.connect(adapter: 'sqlite', database: './blog.db')
109
+ #
110
+ # If a block is given, it is passed the opened +Database+ object, which is
111
+ # closed when the block exits. For example:
112
+ #
113
+ # Sequel.connect('sqlite://blog.db'){|db| puts db[:users].count}
114
+ #
115
+ # If a block is not given, a reference to this database will be held in
116
+ # <tt>Sequel::DATABASES</tt> until it is removed manually. This is by
117
+ # design, and used by <tt>Sequel::Model</tt> to pick the default
118
+ # database. It is recommended to pass a block if you do not want the
119
+ # resulting Database object to remain in memory until the process
120
+ # terminates, or use the <tt>keep_reference: false</tt> Database option.
121
+ #
122
+ # For details, see the {"Connecting to a Database" guide}[rdoc-ref:doc/opening_databases.rdoc].
123
+ # To set up a primary/replica or sharded database connection, see the {"Primary/Replica Database Configurations and Sharding" guide}[rdoc-ref:doc/sharding.rdoc].
124
+ def connect(*args, &block)
125
+ Database.connect(*args, &block)
126
+ end
90
127
 
91
- # Creates a new database object based on the supplied connection string
92
- # and optional arguments. The specified scheme determines the database
93
- # class used, and the rest of the string specifies the connection options.
94
- # For example:
95
- #
96
- # DB = Sequel.connect('sqlite:/') # Memory database
97
- # DB = Sequel.connect('sqlite://blog.db') # ./blog.db
98
- # DB = Sequel.connect('sqlite:///blog.db') # /blog.db
99
- # DB = Sequel.connect('postgres://user:password@host:port/database_name')
100
- # DB = Sequel.connect('sqlite:///blog.db', max_connections: 10)
101
- #
102
- # You can also pass a single options hash:
103
- #
104
- # DB = Sequel.connect(adapter: 'sqlite', database: './blog.db')
105
- #
106
- # If a block is given, it is passed the opened +Database+ object, which is
107
- # closed when the block exits. For example:
108
- #
109
- # Sequel.connect('sqlite://blog.db'){|db| puts db[:users].count}
110
- #
111
- # If a block is not given, a reference to this database will be held in
112
- # <tt>Sequel::DATABASES</tt> until it is removed manually. This is by
113
- # design, and used by <tt>Sequel::Model</tt> to pick the default
114
- # database. It is recommended to pass a block if you do not want the
115
- # resulting Database object to remain in memory until the process
116
- # terminates, or use the <tt>keep_reference: false</tt> Database option.
117
- #
118
- # For details, see the {"Connecting to a Database" guide}[rdoc-ref:doc/opening_databases.rdoc].
119
- # To set up a primary/replica or sharded database connection, see the {"Primary/Replica Database Configurations and Sharding" guide}[rdoc-ref:doc/sharding.rdoc].
120
- def self.connect(*args, &block)
121
- Database.connect(*args, &block)
122
- end
128
+ # Assume the core extensions are not loaded by default, if the core_extensions
129
+ # extension is loaded, this will be overridden.
130
+ def core_extensions?
131
+ false
132
+ end
123
133
 
124
- # Assume the core extensions are not loaded by default, if the core_extensions
125
- # extension is loaded, this will be overridden.
126
- def self.core_extensions?
127
- false
128
- end
134
+ # Convert the +exception+ to the given class. The given class should be
135
+ # <tt>Sequel::Error</tt> or a subclass. Returns an instance of +klass+ with
136
+ # the message and backtrace of +exception+.
137
+ def convert_exception_class(exception, klass)
138
+ return exception if exception.is_a?(klass)
139
+ e = klass.new("#{exception.class}: #{exception.message}")
140
+ e.wrapped_exception = exception
141
+ e.set_backtrace(exception.backtrace)
142
+ e
143
+ end
129
144
 
130
- # Convert the +exception+ to the given class. The given class should be
131
- # <tt>Sequel::Error</tt> or a subclass. Returns an instance of +klass+ with
132
- # the message and backtrace of +exception+.
133
- def self.convert_exception_class(exception, klass)
134
- return exception if exception.is_a?(klass)
135
- e = klass.new("#{exception.class}: #{exception.message}")
136
- e.wrapped_exception = exception
137
- e.set_backtrace(exception.backtrace)
138
- e
139
- end
145
+ # The current concurrency primitive, Thread.current by default.
146
+ def current
147
+ Thread.current
148
+ end
140
149
 
141
- # Load all Sequel extensions given. Extensions are just files that exist under
142
- # <tt>sequel/extensions</tt> in the load path, and are just required.
143
- # In some cases, requiring an extension modifies classes directly, and in others,
144
- # it just loads a module that you can extend other classes with. Consult the documentation
145
- # for each extension you plan on using for usage.
146
- #
147
- # Sequel.extension(:blank)
148
- # Sequel.extension(:core_extensions, :named_timezones)
149
- def self.extension(*extensions)
150
- extensions.each{|e| orig_require("sequel/extensions/#{e}")}
151
- end
152
-
153
- # The exception classed raised if there is an error parsing JSON.
154
- # This can be overridden to use an alternative json implementation.
155
- def self.json_parser_error_class
156
- JSON::ParserError
157
- end
150
+ # Load all Sequel extensions given. Extensions are just files that exist under
151
+ # <tt>sequel/extensions</tt> in the load path, and are just required.
152
+ # In some cases, requiring an extension modifies classes directly, and in others,
153
+ # it just loads a module that you can extend other classes with. Consult the documentation
154
+ # for each extension you plan on using for usage.
155
+ #
156
+ # Sequel.extension(:blank)
157
+ # Sequel.extension(:core_extensions, :named_timezones)
158
+ def extension(*extensions)
159
+ extensions.each{|e| orig_require("sequel/extensions/#{e}")}
160
+ end
161
+
162
+ # The exception classed raised if there is an error parsing JSON.
163
+ # This can be overridden to use an alternative json implementation.
164
+ def json_parser_error_class
165
+ JSON::ParserError
166
+ end
158
167
 
159
- # Convert given object to json and return the result.
160
- # This can be overridden to use an alternative json implementation.
161
- def self.object_to_json(obj, *args, &block)
162
- obj.to_json(*args, &block)
163
- end
168
+ # Convert given object to json and return the result.
169
+ # This can be overridden to use an alternative json implementation.
170
+ def object_to_json(obj, *args, &block)
171
+ obj.to_json(*args, &block)
172
+ end
164
173
 
165
- # Parse the string as JSON and return the result.
166
- # This can be overridden to use an alternative json implementation.
167
- def self.parse_json(json)
168
- JSON.parse(json, :create_additions=>false)
169
- end
174
+ # Parse the string as JSON and return the result.
175
+ # This can be overridden to use an alternative json implementation.
176
+ def parse_json(json)
177
+ JSON.parse(json, :create_additions=>false)
178
+ end
170
179
 
171
- # Convert each item in the array to the correct type, handling multi-dimensional
172
- # arrays. For each element in the array or subarrays, call the converter,
173
- # unless the value is nil.
174
- def self.recursive_map(array, converter)
175
- array.map do |i|
176
- if i.is_a?(Array)
177
- recursive_map(i, converter)
178
- elsif !i.nil?
179
- converter.call(i)
180
+ # Convert each item in the array to the correct type, handling multi-dimensional
181
+ # arrays. For each element in the array or subarrays, call the converter,
182
+ # unless the value is nil.
183
+ def recursive_map(array, converter)
184
+ array.map do |i|
185
+ if i.is_a?(Array)
186
+ recursive_map(i, converter)
187
+ elsif !i.nil?
188
+ converter.call(i)
189
+ end
180
190
  end
181
191
  end
182
- end
183
-
184
- # For backwards compatibility only. require_relative should be used instead.
185
- def self.require(files, subdir=nil)
186
- # Use Kernel.require_relative to work around JRuby 9.0 bug
187
- Array(files).each{|f| Kernel.require_relative "#{"#{subdir}/" if subdir}#{f}"}
188
- end
189
192
 
190
- SPLIT_SYMBOL_CACHE = {}
193
+ # For backwards compatibility only. require_relative should be used instead.
194
+ def require(files, subdir=nil)
195
+ # Use Kernel.require_relative to work around JRuby 9.0 bug
196
+ Array(files).each{|f| Kernel.require_relative "#{"#{subdir}/" if subdir}#{f}"}
197
+ end
191
198
 
192
- # Splits the symbol into three parts, if symbol splitting is enabled (not the default).
193
- # Each part will either be a string or nil. If symbol splitting
194
- # is disabled, returns an array with the first and third parts
195
- # being nil, and the second part beind a string version of the symbol.
196
- #
197
- # For columns, these parts are the table, column, and alias.
198
- # For tables, these parts are the schema, table, and alias.
199
- def self.split_symbol(sym)
200
- unless v = Sequel.synchronize{SPLIT_SYMBOL_CACHE[sym]}
201
- if split_symbols?
202
- v = case s = sym.to_s
203
- when /\A((?:(?!__).)+)__((?:(?!___).)+)___(.+)\z/
204
- [$1.freeze, $2.freeze, $3.freeze].freeze
205
- when /\A((?:(?!___).)+)___(.+)\z/
206
- [nil, $1.freeze, $2.freeze].freeze
207
- when /\A((?:(?!__).)+)__(.+)\z/
208
- [$1.freeze, $2.freeze, nil].freeze
199
+ # Splits the symbol into three parts, if symbol splitting is enabled (not the default).
200
+ # Each part will either be a string or nil. If symbol splitting
201
+ # is disabled, returns an array with the first and third parts
202
+ # being nil, and the second part beind a string version of the symbol.
203
+ #
204
+ # For columns, these parts are the table, column, and alias.
205
+ # For tables, these parts are the schema, table, and alias.
206
+ def split_symbol(sym)
207
+ unless v = Sequel.synchronize{SPLIT_SYMBOL_CACHE[sym]}
208
+ if split_symbols?
209
+ v = case s = sym.to_s
210
+ when /\A((?:(?!__).)+)__((?:(?!___).)+)___(.+)\z/
211
+ [$1.freeze, $2.freeze, $3.freeze].freeze
212
+ when /\A((?:(?!___).)+)___(.+)\z/
213
+ [nil, $1.freeze, $2.freeze].freeze
214
+ when /\A((?:(?!__).)+)__(.+)\z/
215
+ [$1.freeze, $2.freeze, nil].freeze
216
+ else
217
+ [nil, s.freeze, nil].freeze
218
+ end
209
219
  else
210
- [nil, s.freeze, nil].freeze
220
+ v = [nil,sym.to_s.freeze,nil].freeze
211
221
  end
212
- else
213
- v = [nil,sym.to_s.freeze,nil].freeze
222
+ Sequel.synchronize{SPLIT_SYMBOL_CACHE[sym] = v}
214
223
  end
215
- Sequel.synchronize{SPLIT_SYMBOL_CACHE[sym] = v}
224
+ v
216
225
  end
217
- v
218
- end
219
-
220
- # Setting this to true enables Sequel's historical behavior of splitting
221
- # symbols on double or triple underscores:
222
- #
223
- # :table__column # table.column
224
- # :column___alias # column AS alias
225
- # :table__column___alias # table.column AS alias
226
- #
227
- # It is only recommended to turn this on for backwards compatibility until
228
- # such symbols have been converted to use newer Sequel APIs such as:
229
- #
230
- # Sequel[:table][:column] # table.column
231
- # Sequel[:column].as(:alias) # column AS alias
232
- # Sequel[:table][:column].as(:alias) # table.column AS alias
233
- #
234
- # Sequel::Database instances do their own caching of literalized
235
- # symbols, and changing this setting does not affect those caches. It is
236
- # recommended that if you want to change this setting, you do so directly
237
- # after requiring Sequel, before creating any Sequel::Database instances.
238
- #
239
- # Disabling symbol splitting will also disable the handling
240
- # of double underscores in virtual row methods, causing such methods to
241
- # yield regular identifers instead of qualified identifiers:
242
- #
243
- # # Sequel.split_symbols = true
244
- # Sequel.expr{table__column} # table.column
245
- # Sequel.expr{table[:column]} # table.column
246
- #
247
- # # Sequel.split_symbols = false
248
- # Sequel.expr{table__column} # table__column
249
- # Sequel.expr{table[:column]} # table.column
250
- def self.split_symbols=(v)
251
- Sequel.synchronize{SPLIT_SYMBOL_CACHE.clear}
252
- @split_symbols = v
253
- end
254
226
 
255
- # Whether Sequel currently splits symbols into qualified/aliased identifiers.
256
- def self.split_symbols?
257
- @split_symbols
258
- end
227
+ # Setting this to true enables Sequel's historical behavior of splitting
228
+ # symbols on double or triple underscores:
229
+ #
230
+ # :table__column # table.column
231
+ # :column___alias # column AS alias
232
+ # :table__column___alias # table.column AS alias
233
+ #
234
+ # It is only recommended to turn this on for backwards compatibility until
235
+ # such symbols have been converted to use newer Sequel APIs such as:
236
+ #
237
+ # Sequel[:table][:column] # table.column
238
+ # Sequel[:column].as(:alias) # column AS alias
239
+ # Sequel[:table][:column].as(:alias) # table.column AS alias
240
+ #
241
+ # Sequel::Database instances do their own caching of literalized
242
+ # symbols, and changing this setting does not affect those caches. It is
243
+ # recommended that if you want to change this setting, you do so directly
244
+ # after requiring Sequel, before creating any Sequel::Database instances.
245
+ #
246
+ # Disabling symbol splitting will also disable the handling
247
+ # of double underscores in virtual row methods, causing such methods to
248
+ # yield regular identifers instead of qualified identifiers:
249
+ #
250
+ # # Sequel.split_symbols = true
251
+ # Sequel.expr{table__column} # table.column
252
+ # Sequel.expr{table[:column]} # table.column
253
+ #
254
+ # # Sequel.split_symbols = false
255
+ # Sequel.expr{table__column} # table__column
256
+ # Sequel.expr{table[:column]} # table.column
257
+ def split_symbols=(v)
258
+ Sequel.synchronize{SPLIT_SYMBOL_CACHE.clear}
259
+ @split_symbols = v
260
+ end
259
261
 
260
- # Converts the given +string+ into a +Date+ object.
261
- #
262
- # Sequel.string_to_date('2010-09-10') # Date.civil(2010, 09, 10)
263
- def self.string_to_date(string)
264
- begin
265
- Date.parse(string, Sequel.convert_two_digit_years)
266
- rescue => e
267
- raise convert_exception_class(e, InvalidValue)
262
+ # Whether Sequel currently splits symbols into qualified/aliased identifiers.
263
+ def split_symbols?
264
+ @split_symbols
268
265
  end
269
- end
270
266
 
271
- # Converts the given +string+ into a +Time+ or +DateTime+ object, depending on the
272
- # value of <tt>Sequel.datetime_class</tt>.
273
- #
274
- # Sequel.string_to_datetime('2010-09-10 10:20:30') # Time.local(2010, 09, 10, 10, 20, 30)
275
- def self.string_to_datetime(string)
276
- begin
277
- if datetime_class == DateTime
278
- DateTime.parse(string, convert_two_digit_years)
279
- else
280
- datetime_class.parse(string)
267
+ # Converts the given +string+ into a +Date+ object.
268
+ #
269
+ # Sequel.string_to_date('2010-09-10') # Date.civil(2010, 09, 10)
270
+ def string_to_date(string)
271
+ begin
272
+ Date.parse(string, Sequel.convert_two_digit_years)
273
+ rescue => e
274
+ raise convert_exception_class(e, InvalidValue)
281
275
  end
282
- rescue => e
283
- raise convert_exception_class(e, InvalidValue)
284
276
  end
285
- end
286
277
 
287
- # Converts the given +string+ into a <tt>Sequel::SQLTime</tt> object.
288
- #
289
- # v = Sequel.string_to_time('10:20:30') # Sequel::SQLTime.parse('10:20:30')
290
- # DB.literal(v) # => '10:20:30'
291
- def self.string_to_time(string)
292
- begin
293
- SQLTime.parse(string)
294
- rescue => e
295
- raise convert_exception_class(e, InvalidValue)
278
+ # Converts the given +string+ into a +Time+ or +DateTime+ object, depending on the
279
+ # value of <tt>Sequel.datetime_class</tt>.
280
+ #
281
+ # Sequel.string_to_datetime('2010-09-10 10:20:30') # Time.local(2010, 09, 10, 10, 20, 30)
282
+ def string_to_datetime(string)
283
+ begin
284
+ if datetime_class == DateTime
285
+ DateTime.parse(string, convert_two_digit_years)
286
+ else
287
+ datetime_class.parse(string)
288
+ end
289
+ rescue => e
290
+ raise convert_exception_class(e, InvalidValue)
291
+ end
296
292
  end
297
- end
298
-
299
- # Mutex used to protect mutable data structures
300
- @data_mutex = Mutex.new
301
-
302
- # Unless in single threaded mode, protects access to any mutable
303
- # global data structure in Sequel.
304
- # Uses a non-reentrant mutex, so calling code should be careful.
305
- # In general, this should only be used around the minimal possible code
306
- # such as Hash#[], Hash#[]=, Hash#delete, Array#<<, and Array#delete.
307
- def self.synchronize(&block)
308
- @single_threaded ? yield : @data_mutex.synchronize(&block)
309
- end
310
293
 
311
- if RUBY_VERSION >= '2.1'
312
- # A timer object that can be passed to Sequel.elapsed_seconds_since
313
- # to return the number of seconds elapsed.
314
- def self.start_timer
315
- Process.clock_gettime(Process::CLOCK_MONOTONIC)
294
+ # Converts the given +string+ into a <tt>Sequel::SQLTime</tt> object.
295
+ #
296
+ # v = Sequel.string_to_time('10:20:30') # Sequel::SQLTime.parse('10:20:30')
297
+ # DB.literal(v) # => '10:20:30'
298
+ def string_to_time(string)
299
+ begin
300
+ SQLTime.parse(string)
301
+ rescue => e
302
+ raise convert_exception_class(e, InvalidValue)
303
+ end
316
304
  end
317
- else
318
- # :nocov:
319
- def self.start_timer # :nodoc:
320
- Time.now
305
+
306
+ # Unless in single threaded mode, protects access to any mutable
307
+ # global data structure in Sequel.
308
+ # Uses a non-reentrant mutex, so calling code should be careful.
309
+ # In general, this should only be used around the minimal possible code
310
+ # such as Hash#[], Hash#[]=, Hash#delete, Array#<<, and Array#delete.
311
+ def synchronize(&block)
312
+ @single_threaded ? yield : @data_mutex.synchronize(&block)
321
313
  end
322
- # :nocov:
323
- end
324
314
 
325
- # The elapsed seconds since the given timer object was created. The
326
- # timer object should have been created via Sequel.start_timer.
327
- def self.elapsed_seconds_since(timer)
328
- start_timer - timer
329
- end
315
+ if RUBY_VERSION >= '2.1'
316
+ # A timer object that can be passed to Sequel.elapsed_seconds_since
317
+ # to return the number of seconds elapsed.
318
+ def start_timer
319
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
320
+ end
321
+ else
322
+ # :nocov:
323
+ def start_timer # :nodoc:
324
+ Time.now
325
+ end
326
+ # :nocov:
327
+ end
330
328
 
331
- # Uses a transaction on all given databases with the given options. This:
332
- #
333
- # Sequel.transaction([DB1, DB2, DB3]){}
334
- #
335
- # is equivalent to:
336
- #
337
- # DB1.transaction do
338
- # DB2.transaction do
339
- # DB3.transaction do
340
- # end
341
- # end
342
- # end
343
- #
344
- # except that if Sequel::Rollback is raised by the block, the transaction is
345
- # rolled back on all databases instead of just the last one.
346
- #
347
- # Note that this method cannot guarantee that all databases will commit or
348
- # rollback. For example, if DB3 commits but attempting to commit on DB2
349
- # fails (maybe because foreign key checks are deferred), there is no way
350
- # to uncommit the changes on DB3. For that kind of support, you need to
351
- # have two-phase commit/prepared transactions (which Sequel supports on
352
- # some databases).
353
- def self.transaction(dbs, opts=OPTS, &block)
354
- unless opts[:rollback]
355
- rescue_rollback = true
356
- opts = Hash[opts].merge!(:rollback=>:reraise)
329
+ # The elapsed seconds since the given timer object was created. The
330
+ # timer object should have been created via Sequel.start_timer.
331
+ def elapsed_seconds_since(timer)
332
+ start_timer - timer
357
333
  end
358
- pr = dbs.reverse.inject(block){|bl, db| proc{db.transaction(opts, &bl)}}
359
- if rescue_rollback
360
- begin
334
+
335
+ # Uses a transaction on all given databases with the given options. This:
336
+ #
337
+ # Sequel.transaction([DB1, DB2, DB3]){}
338
+ #
339
+ # is equivalent to:
340
+ #
341
+ # DB1.transaction do
342
+ # DB2.transaction do
343
+ # DB3.transaction do
344
+ # end
345
+ # end
346
+ # end
347
+ #
348
+ # except that if Sequel::Rollback is raised by the block, the transaction is
349
+ # rolled back on all databases instead of just the last one.
350
+ #
351
+ # Note that this method cannot guarantee that all databases will commit or
352
+ # rollback. For example, if DB3 commits but attempting to commit on DB2
353
+ # fails (maybe because foreign key checks are deferred), there is no way
354
+ # to uncommit the changes on DB3. For that kind of support, you need to
355
+ # have two-phase commit/prepared transactions (which Sequel supports on
356
+ # some databases).
357
+ def transaction(dbs, opts=OPTS, &block)
358
+ unless opts[:rollback]
359
+ rescue_rollback = true
360
+ opts = Hash[opts].merge!(:rollback=>:reraise)
361
+ end
362
+ pr = dbs.reverse.inject(block){|bl, db| proc{db.transaction(opts, &bl)}}
363
+ if rescue_rollback
364
+ begin
365
+ pr.call
366
+ rescue Sequel::Rollback
367
+ nil
368
+ end
369
+ else
361
370
  pr.call
362
- rescue Sequel::Rollback
363
- nil
364
371
  end
365
- else
366
- pr.call
367
372
  end
368
- end
369
373
 
370
- # If the supplied block takes a single argument,
371
- # yield an <tt>SQL::VirtualRow</tt> instance to the block
372
- # argument. Otherwise, evaluate the block in the context of a
373
- # <tt>SQL::VirtualRow</tt> instance.
374
- #
375
- # Sequel.virtual_row{a} # Sequel::SQL::Identifier.new(:a)
376
- # Sequel.virtual_row{|o| o.a} # Sequel::SQL::Function.new(:a)
377
- def self.virtual_row(&block)
378
- vr = VIRTUAL_ROW
379
- case block.arity
380
- when -1, 0
381
- vr.instance_exec(&block)
382
- else
383
- block.call(vr)
384
- end
385
- end
374
+ # If the supplied block takes a single argument,
375
+ # yield an <tt>SQL::VirtualRow</tt> instance to the block
376
+ # argument. Otherwise, evaluate the block in the context of a
377
+ # <tt>SQL::VirtualRow</tt> instance.
378
+ #
379
+ # Sequel.virtual_row{a} # Sequel::SQL::Identifier.new(:a)
380
+ # Sequel.virtual_row{|o| o.a} # Sequel::SQL::Function.new(:a)
381
+ def virtual_row(&block)
382
+ vr = VIRTUAL_ROW
383
+ case block.arity
384
+ when -1, 0
385
+ vr.instance_exec(&block)
386
+ else
387
+ block.call(vr)
388
+ end
389
+ end
386
390
 
387
- ### Private Class Methods ###
391
+ private
388
392
 
389
- # Helper method that the database adapter class methods that are added to Sequel via
390
- # metaprogramming use to parse arguments.
391
- def self.adapter_method(adapter, *args, &block)
392
- options = args.last.is_a?(Hash) ? args.pop : OPTS
393
- opts = {:adapter => adapter.to_sym}
394
- opts[:database] = args.shift if args.first.is_a?(String)
395
- if args.any?
396
- raise ::Sequel::Error, "Wrong format of arguments, either use (), (String), (Hash), or (String, Hash)"
397
- end
393
+ # Helper method that the database adapter class methods that are added to Sequel via
394
+ # metaprogramming use to parse arguments.
395
+ def adapter_method(adapter, *args, &block)
396
+ options = args.last.is_a?(Hash) ? args.pop : OPTS
397
+ opts = {:adapter => adapter.to_sym}
398
+ opts[:database] = args.shift if args.first.is_a?(String)
399
+ if args.any?
400
+ raise ::Sequel::Error, "Wrong format of arguments, either use (), (String), (Hash), or (String, Hash)"
401
+ end
398
402
 
399
- connect(opts.merge(options), &block)
400
- end
403
+ connect(opts.merge(options), &block)
404
+ end
401
405
 
402
- # Method that adds a database adapter class method to Sequel that calls
403
- # Sequel.adapter_method.
404
- def self.def_adapter_method(*adapters) # :nodoc:
405
- adapters.each do |adapter|
406
- define_singleton_method(adapter){|*args, &block| adapter_method(adapter, *args, &block)}
406
+ # Method that adds a database adapter class method to Sequel that calls
407
+ # Sequel.adapter_method.
408
+ def def_adapter_method(*adapters) # :nodoc:
409
+ adapters.each do |adapter|
410
+ define_singleton_method(adapter){|*args, &block| adapter_method(adapter, *args, &block)}
411
+ end
407
412
  end
408
413
  end
409
-
410
- private_class_method :adapter_method, :def_adapter_method
411
-
412
- require_relative "deprecated"
413
- require_relative "sql"
414
- require_relative "connection_pool"
415
- require_relative "exceptions"
416
- require_relative "dataset"
417
- require_relative "database"
418
- require_relative "timezones"
419
- require_relative "ast_transformer"
420
- require_relative "version"
414
+ extend SequelMethods
415
+
416
+ require_relative "deprecated"
417
+ require_relative "sql"
418
+ require_relative "connection_pool"
419
+ require_relative "exceptions"
420
+ require_relative "dataset"
421
+ require_relative "database"
422
+ require_relative "timezones"
423
+ require_relative "ast_transformer"
424
+ require_relative "version"
421
425
 
422
426
  class << self
423
427
  # Allow nicer syntax for creating Sequel expressions: