sequel 4.49.0 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (484) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +130 -0
  3. data/README.rdoc +195 -136
  4. data/Rakefile +26 -42
  5. data/bin/sequel +6 -9
  6. data/doc/advanced_associations.rdoc +91 -168
  7. data/doc/association_basics.rdoc +197 -274
  8. data/doc/bin_sequel.rdoc +5 -3
  9. data/doc/cheat_sheet.rdoc +66 -43
  10. data/doc/code_order.rdoc +1 -8
  11. data/doc/core_extensions.rdoc +81 -56
  12. data/doc/dataset_basics.rdoc +8 -17
  13. data/doc/dataset_filtering.rdoc +81 -86
  14. data/doc/extensions.rdoc +3 -10
  15. data/doc/mass_assignment.rdoc +73 -30
  16. data/doc/migration.rdoc +19 -36
  17. data/doc/model_dataset_method_design.rdoc +14 -17
  18. data/doc/model_hooks.rdoc +15 -25
  19. data/doc/model_plugins.rdoc +10 -10
  20. data/doc/mssql_stored_procedures.rdoc +3 -3
  21. data/doc/object_model.rdoc +52 -70
  22. data/doc/opening_databases.rdoc +39 -32
  23. data/doc/postgresql.rdoc +48 -38
  24. data/doc/prepared_statements.rdoc +27 -22
  25. data/doc/querying.rdoc +173 -150
  26. data/doc/reflection.rdoc +5 -6
  27. data/doc/release_notes/5.0.0.txt +159 -0
  28. data/doc/release_notes/5.1.0.txt +31 -0
  29. data/doc/release_notes/5.2.0.txt +33 -0
  30. data/doc/release_notes/5.3.0.txt +121 -0
  31. data/doc/schema_modification.rdoc +78 -64
  32. data/doc/security.rdoc +97 -88
  33. data/doc/sharding.rdoc +43 -30
  34. data/doc/sql.rdoc +53 -65
  35. data/doc/testing.rdoc +4 -5
  36. data/doc/thread_safety.rdoc +2 -4
  37. data/doc/transactions.rdoc +18 -17
  38. data/doc/validations.rdoc +48 -45
  39. data/doc/virtual_rows.rdoc +87 -115
  40. data/lib/sequel/adapters/ado/access.rb +7 -13
  41. data/lib/sequel/adapters/ado/mssql.rb +2 -9
  42. data/lib/sequel/adapters/ado.rb +9 -25
  43. data/lib/sequel/adapters/amalgalite.rb +3 -18
  44. data/lib/sequel/adapters/ibmdb.rb +9 -45
  45. data/lib/sequel/adapters/jdbc/db2.rb +8 -37
  46. data/lib/sequel/adapters/jdbc/derby.rb +4 -50
  47. data/lib/sequel/adapters/jdbc/h2.rb +6 -26
  48. data/lib/sequel/adapters/jdbc/hsqldb.rb +2 -27
  49. data/lib/sequel/adapters/jdbc/jtds.rb +2 -9
  50. data/lib/sequel/adapters/jdbc/mssql.rb +1 -11
  51. data/lib/sequel/adapters/jdbc/mysql.rb +11 -15
  52. data/lib/sequel/adapters/jdbc/oracle.rb +4 -26
  53. data/lib/sequel/adapters/jdbc/postgresql.rb +23 -33
  54. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +4 -17
  55. data/lib/sequel/adapters/jdbc/sqlite.rb +1 -7
  56. data/lib/sequel/adapters/jdbc/sqlserver.rb +1 -13
  57. data/lib/sequel/adapters/jdbc/transactions.rb +1 -14
  58. data/lib/sequel/adapters/jdbc.rb +18 -74
  59. data/lib/sequel/adapters/mock.rb +4 -30
  60. data/lib/sequel/adapters/mysql.rb +7 -44
  61. data/lib/sequel/adapters/mysql2.rb +5 -23
  62. data/lib/sequel/adapters/odbc/db2.rb +1 -1
  63. data/lib/sequel/adapters/odbc/mssql.rb +4 -12
  64. data/lib/sequel/adapters/odbc/oracle.rb +1 -1
  65. data/lib/sequel/adapters/odbc.rb +0 -19
  66. data/lib/sequel/adapters/oracle.rb +8 -13
  67. data/lib/sequel/adapters/postgres.rb +28 -150
  68. data/lib/sequel/adapters/postgresql.rb +1 -1
  69. data/lib/sequel/adapters/shared/access.rb +11 -51
  70. data/lib/sequel/adapters/shared/db2.rb +3 -61
  71. data/lib/sequel/adapters/shared/mssql.rb +21 -157
  72. data/lib/sequel/adapters/shared/mysql.rb +61 -227
  73. data/lib/sequel/adapters/shared/oracle.rb +13 -41
  74. data/lib/sequel/adapters/shared/postgres.rb +58 -264
  75. data/lib/sequel/adapters/shared/sqlanywhere.rb +4 -96
  76. data/lib/sequel/adapters/shared/sqlite.rb +22 -101
  77. data/lib/sequel/adapters/sqlanywhere.rb +4 -23
  78. data/lib/sequel/adapters/sqlite.rb +2 -19
  79. data/lib/sequel/adapters/tinytds.rb +5 -15
  80. data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +1 -1
  81. data/lib/sequel/adapters/utils/mysql_mysql2.rb +4 -4
  82. data/lib/sequel/adapters/utils/mysql_prepared_statements.rb +3 -6
  83. data/lib/sequel/adapters/utils/replace.rb +0 -5
  84. data/lib/sequel/adapters/utils/stored_procedures.rb +0 -2
  85. data/lib/sequel/adapters/utils/unmodified_identifiers.rb +2 -0
  86. data/lib/sequel/ast_transformer.rb +3 -94
  87. data/lib/sequel/connection_pool/sharded_single.rb +1 -4
  88. data/lib/sequel/connection_pool/sharded_threaded.rb +97 -95
  89. data/lib/sequel/connection_pool/single.rb +0 -2
  90. data/lib/sequel/connection_pool/threaded.rb +94 -110
  91. data/lib/sequel/connection_pool.rb +38 -28
  92. data/lib/sequel/core.rb +42 -101
  93. data/lib/sequel/database/connecting.rb +23 -60
  94. data/lib/sequel/database/dataset.rb +6 -9
  95. data/lib/sequel/database/dataset_defaults.rb +4 -48
  96. data/lib/sequel/database/features.rb +5 -4
  97. data/lib/sequel/database/logging.rb +2 -9
  98. data/lib/sequel/database/misc.rb +36 -55
  99. data/lib/sequel/database/query.rb +8 -13
  100. data/lib/sequel/database/schema_generator.rb +93 -64
  101. data/lib/sequel/database/schema_methods.rb +61 -79
  102. data/lib/sequel/database/transactions.rb +4 -24
  103. data/lib/sequel/database.rb +12 -2
  104. data/lib/sequel/dataset/actions.rb +57 -107
  105. data/lib/sequel/dataset/dataset_module.rb +4 -16
  106. data/lib/sequel/dataset/features.rb +35 -30
  107. data/lib/sequel/dataset/graph.rb +40 -49
  108. data/lib/sequel/dataset/misc.rb +12 -37
  109. data/lib/sequel/dataset/placeholder_literalizer.rb +4 -4
  110. data/lib/sequel/dataset/prepared_statements.rb +23 -51
  111. data/lib/sequel/dataset/query.rb +91 -161
  112. data/lib/sequel/dataset/sql.rb +33 -225
  113. data/lib/sequel/dataset.rb +18 -10
  114. data/lib/sequel/deprecated.rb +18 -27
  115. data/lib/sequel/exceptions.rb +1 -17
  116. data/lib/sequel/extensions/_model_pg_row.rb +0 -7
  117. data/lib/sequel/extensions/_pretty_table.rb +1 -3
  118. data/lib/sequel/extensions/arbitrary_servers.rb +10 -10
  119. data/lib/sequel/extensions/connection_expiration.rb +1 -1
  120. data/lib/sequel/extensions/connection_validator.rb +1 -1
  121. data/lib/sequel/extensions/constraint_validations.rb +11 -11
  122. data/lib/sequel/extensions/core_extensions.rb +39 -49
  123. data/lib/sequel/extensions/core_refinements.rb +39 -45
  124. data/lib/sequel/extensions/current_datetime_timestamp.rb +0 -4
  125. data/lib/sequel/extensions/date_arithmetic.rb +7 -7
  126. data/lib/sequel/extensions/duplicate_columns_handler.rb +12 -9
  127. data/lib/sequel/extensions/empty_array_consider_nulls.rb +2 -2
  128. data/lib/sequel/extensions/eval_inspect.rb +4 -11
  129. data/lib/sequel/extensions/freeze_datasets.rb +1 -69
  130. data/lib/sequel/extensions/from_block.rb +1 -35
  131. data/lib/sequel/extensions/graph_each.rb +2 -2
  132. data/lib/sequel/extensions/identifier_mangling.rb +9 -19
  133. data/lib/sequel/extensions/implicit_subquery.rb +2 -2
  134. data/lib/sequel/extensions/inflector.rb +4 -4
  135. data/lib/sequel/extensions/migration.rb +27 -43
  136. data/lib/sequel/extensions/no_auto_literal_strings.rb +2 -84
  137. data/lib/sequel/extensions/null_dataset.rb +2 -8
  138. data/lib/sequel/extensions/pagination.rb +1 -17
  139. data/lib/sequel/extensions/pg_array.rb +20 -189
  140. data/lib/sequel/extensions/pg_extended_date_support.rb +230 -0
  141. data/lib/sequel/extensions/pg_hstore.rb +11 -50
  142. data/lib/sequel/extensions/pg_hstore_ops.rb +2 -2
  143. data/lib/sequel/extensions/pg_inet.rb +3 -16
  144. data/lib/sequel/extensions/pg_interval.rb +1 -20
  145. data/lib/sequel/extensions/pg_json.rb +7 -27
  146. data/lib/sequel/extensions/pg_loose_count.rb +1 -1
  147. data/lib/sequel/extensions/pg_range.rb +6 -121
  148. data/lib/sequel/extensions/pg_range_ops.rb +1 -3
  149. data/lib/sequel/extensions/pg_row.rb +5 -77
  150. data/lib/sequel/extensions/pg_row_ops.rb +2 -13
  151. data/lib/sequel/extensions/query.rb +3 -4
  152. data/lib/sequel/extensions/round_timestamps.rb +0 -6
  153. data/lib/sequel/extensions/schema_dumper.rb +13 -13
  154. data/lib/sequel/extensions/select_remove.rb +3 -3
  155. data/lib/sequel/extensions/split_array_nil.rb +2 -2
  156. data/lib/sequel/extensions/sql_comments.rb +2 -2
  157. data/lib/sequel/extensions/string_agg.rb +11 -8
  158. data/lib/sequel/extensions/symbol_aref.rb +6 -20
  159. data/lib/sequel/extensions/synchronize_sql.rb +45 -0
  160. data/lib/sequel/model/associations.rb +129 -131
  161. data/lib/sequel/model/base.rb +133 -731
  162. data/lib/sequel/model/default_inflections.rb +1 -1
  163. data/lib/sequel/model/errors.rb +0 -3
  164. data/lib/sequel/model/exceptions.rb +2 -6
  165. data/lib/sequel/model/inflections.rb +1 -26
  166. data/lib/sequel/model/plugins.rb +1 -0
  167. data/lib/sequel/model.rb +27 -62
  168. data/lib/sequel/plugins/active_model.rb +2 -5
  169. data/lib/sequel/plugins/association_dependencies.rb +15 -15
  170. data/lib/sequel/plugins/association_pks.rb +14 -28
  171. data/lib/sequel/plugins/association_proxies.rb +6 -7
  172. data/lib/sequel/plugins/auto_validations.rb +4 -4
  173. data/lib/sequel/plugins/before_after_save.rb +0 -43
  174. data/lib/sequel/plugins/blacklist_security.rb +9 -8
  175. data/lib/sequel/plugins/boolean_readers.rb +3 -3
  176. data/lib/sequel/plugins/boolean_subsets.rb +2 -2
  177. data/lib/sequel/plugins/caching.rb +5 -5
  178. data/lib/sequel/plugins/class_table_inheritance.rb +71 -102
  179. data/lib/sequel/plugins/column_conflicts.rb +2 -2
  180. data/lib/sequel/plugins/column_select.rb +2 -2
  181. data/lib/sequel/plugins/composition.rb +15 -24
  182. data/lib/sequel/plugins/constraint_validations.rb +4 -3
  183. data/lib/sequel/plugins/csv_serializer.rb +13 -20
  184. data/lib/sequel/plugins/dataset_associations.rb +2 -2
  185. data/lib/sequel/plugins/def_dataset_method.rb +5 -5
  186. data/lib/sequel/plugins/defaults_setter.rb +1 -1
  187. data/lib/sequel/plugins/delay_add_association.rb +1 -1
  188. data/lib/sequel/plugins/finder.rb +16 -10
  189. data/lib/sequel/plugins/force_encoding.rb +1 -7
  190. data/lib/sequel/plugins/hook_class_methods.rb +4 -106
  191. data/lib/sequel/plugins/input_transformer.rb +10 -11
  192. data/lib/sequel/plugins/insert_returning_select.rb +1 -9
  193. data/lib/sequel/plugins/instance_filters.rb +5 -5
  194. data/lib/sequel/plugins/instance_hooks.rb +7 -52
  195. data/lib/sequel/plugins/inverted_subsets.rb +3 -1
  196. data/lib/sequel/plugins/json_serializer.rb +19 -19
  197. data/lib/sequel/plugins/lazy_attributes.rb +1 -10
  198. data/lib/sequel/plugins/list.rb +6 -6
  199. data/lib/sequel/plugins/many_through_many.rb +11 -8
  200. data/lib/sequel/plugins/mssql_optimistic_locking.rb +3 -3
  201. data/lib/sequel/plugins/nested_attributes.rb +18 -31
  202. data/lib/sequel/plugins/optimistic_locking.rb +3 -3
  203. data/lib/sequel/plugins/pg_array_associations.rb +8 -2
  204. data/lib/sequel/plugins/pg_row.rb +2 -11
  205. data/lib/sequel/plugins/prepared_statements.rb +13 -66
  206. data/lib/sequel/plugins/prepared_statements_safe.rb +1 -1
  207. data/lib/sequel/plugins/rcte_tree.rb +7 -7
  208. data/lib/sequel/plugins/serialization.rb +15 -33
  209. data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
  210. data/lib/sequel/plugins/sharding.rb +2 -8
  211. data/lib/sequel/plugins/single_table_inheritance.rb +10 -13
  212. data/lib/sequel/plugins/skip_create_refresh.rb +3 -3
  213. data/lib/sequel/plugins/static_cache.rb +8 -9
  214. data/lib/sequel/plugins/string_stripper.rb +3 -3
  215. data/lib/sequel/plugins/subclasses.rb +1 -1
  216. data/lib/sequel/plugins/subset_conditions.rb +2 -2
  217. data/lib/sequel/plugins/table_select.rb +2 -2
  218. data/lib/sequel/plugins/tactical_eager_loading.rb +4 -4
  219. data/lib/sequel/plugins/timestamps.rb +6 -7
  220. data/lib/sequel/plugins/touch.rb +4 -8
  221. data/lib/sequel/plugins/tree.rb +3 -3
  222. data/lib/sequel/plugins/typecast_on_load.rb +2 -2
  223. data/lib/sequel/plugins/unlimited_update.rb +1 -7
  224. data/lib/sequel/plugins/update_or_create.rb +3 -3
  225. data/lib/sequel/plugins/update_refresh.rb +3 -3
  226. data/lib/sequel/plugins/uuid.rb +7 -11
  227. data/lib/sequel/plugins/validation_class_methods.rb +10 -9
  228. data/lib/sequel/plugins/validation_contexts.rb +4 -4
  229. data/lib/sequel/plugins/validation_helpers.rb +26 -25
  230. data/lib/sequel/plugins/whitelist_security.rb +13 -9
  231. data/lib/sequel/plugins/xml_serializer.rb +24 -25
  232. data/lib/sequel/sql.rb +145 -276
  233. data/lib/sequel/timezones.rb +8 -23
  234. data/lib/sequel/version.rb +2 -2
  235. data/lib/sequel.rb +1 -1
  236. data/spec/adapter_spec.rb +1 -1
  237. data/spec/adapters/db2_spec.rb +2 -103
  238. data/spec/adapters/mssql_spec.rb +89 -68
  239. data/spec/adapters/mysql_spec.rb +111 -478
  240. data/spec/adapters/oracle_spec.rb +1 -9
  241. data/spec/adapters/postgres_spec.rb +459 -664
  242. data/spec/adapters/spec_helper.rb +12 -31
  243. data/spec/adapters/sqlanywhere_spec.rb +2 -77
  244. data/spec/adapters/sqlite_spec.rb +8 -146
  245. data/spec/bin_spec.rb +11 -16
  246. data/spec/core/connection_pool_spec.rb +173 -74
  247. data/spec/core/database_spec.rb +96 -244
  248. data/spec/core/dataset_spec.rb +99 -414
  249. data/spec/core/deprecated_spec.rb +3 -3
  250. data/spec/core/expression_filters_spec.rb +37 -144
  251. data/spec/core/mock_adapter_spec.rb +241 -4
  252. data/spec/core/object_graph_spec.rb +11 -60
  253. data/spec/core/placeholder_literalizer_spec.rb +1 -14
  254. data/spec/core/schema_generator_spec.rb +51 -40
  255. data/spec/core/schema_spec.rb +88 -77
  256. data/spec/core/spec_helper.rb +6 -24
  257. data/spec/core/version_spec.rb +1 -1
  258. data/spec/core_extensions_spec.rb +7 -83
  259. data/spec/core_model_spec.rb +2 -2
  260. data/spec/deprecation_helper.rb +2 -14
  261. data/spec/extensions/accessed_columns_spec.rb +1 -1
  262. data/spec/extensions/active_model_spec.rb +3 -3
  263. data/spec/extensions/after_initialize_spec.rb +1 -1
  264. data/spec/extensions/arbitrary_servers_spec.rb +2 -2
  265. data/spec/extensions/association_dependencies_spec.rb +1 -1
  266. data/spec/extensions/association_pks_spec.rb +30 -92
  267. data/spec/extensions/association_proxies_spec.rb +1 -1
  268. data/spec/extensions/auto_literal_strings_spec.rb +1 -12
  269. data/spec/extensions/auto_validations_spec.rb +1 -1
  270. data/spec/extensions/blacklist_security_spec.rb +1 -1
  271. data/spec/extensions/blank_spec.rb +1 -1
  272. data/spec/extensions/boolean_readers_spec.rb +1 -1
  273. data/spec/extensions/boolean_subsets_spec.rb +1 -1
  274. data/spec/extensions/caching_spec.rb +1 -1
  275. data/spec/extensions/class_table_inheritance_spec.rb +53 -1118
  276. data/spec/extensions/column_conflicts_spec.rb +1 -1
  277. data/spec/extensions/column_select_spec.rb +4 -4
  278. data/spec/extensions/columns_introspection_spec.rb +1 -1
  279. data/spec/extensions/columns_updated_spec.rb +1 -1
  280. data/spec/extensions/composition_spec.rb +8 -30
  281. data/spec/extensions/connection_expiration_spec.rb +3 -3
  282. data/spec/extensions/connection_validator_spec.rb +3 -3
  283. data/spec/extensions/constraint_validations_plugin_spec.rb +1 -1
  284. data/spec/extensions/constraint_validations_spec.rb +1 -1
  285. data/spec/extensions/core_refinements_spec.rb +1 -3
  286. data/spec/extensions/csv_serializer_spec.rb +4 -9
  287. data/spec/extensions/current_datetime_timestamp_spec.rb +1 -1
  288. data/spec/extensions/dataset_associations_spec.rb +2 -1
  289. data/spec/extensions/dataset_source_alias_spec.rb +1 -1
  290. data/spec/extensions/date_arithmetic_spec.rb +3 -3
  291. data/spec/extensions/def_dataset_method_spec.rb +1 -1
  292. data/spec/extensions/defaults_setter_spec.rb +2 -2
  293. data/spec/extensions/delay_add_association_spec.rb +8 -9
  294. data/spec/extensions/dirty_spec.rb +1 -1
  295. data/spec/extensions/duplicate_columns_handler_spec.rb +1 -1
  296. data/spec/extensions/eager_each_spec.rb +2 -2
  297. data/spec/extensions/empty_array_consider_nulls_spec.rb +1 -1
  298. data/spec/extensions/error_splitter_spec.rb +1 -1
  299. data/spec/extensions/error_sql_spec.rb +1 -1
  300. data/spec/extensions/eval_inspect_spec.rb +1 -1
  301. data/spec/extensions/finder_spec.rb +1 -1
  302. data/spec/extensions/force_encoding_spec.rb +2 -5
  303. data/spec/extensions/freeze_datasets_spec.rb +1 -1
  304. data/spec/extensions/graph_each_spec.rb +5 -5
  305. data/spec/extensions/hook_class_methods_spec.rb +1 -194
  306. data/spec/extensions/identifier_mangling_spec.rb +17 -170
  307. data/spec/extensions/implicit_subquery_spec.rb +1 -5
  308. data/spec/extensions/inflector_spec.rb +1 -1
  309. data/spec/extensions/input_transformer_spec.rb +7 -2
  310. data/spec/extensions/insert_returning_select_spec.rb +1 -1
  311. data/spec/extensions/instance_filters_spec.rb +1 -1
  312. data/spec/extensions/instance_hooks_spec.rb +1 -95
  313. data/spec/extensions/inverted_subsets_spec.rb +1 -1
  314. data/spec/extensions/json_serializer_spec.rb +1 -1
  315. data/spec/extensions/lazy_attributes_spec.rb +1 -7
  316. data/spec/extensions/list_spec.rb +5 -6
  317. data/spec/extensions/looser_typecasting_spec.rb +1 -1
  318. data/spec/extensions/many_through_many_spec.rb +25 -33
  319. data/spec/extensions/migration_spec.rb +12 -2
  320. data/spec/extensions/modification_detection_spec.rb +1 -1
  321. data/spec/extensions/mssql_optimistic_locking_spec.rb +1 -1
  322. data/spec/extensions/named_timezones_spec.rb +3 -3
  323. data/spec/extensions/nested_attributes_spec.rb +1 -29
  324. data/spec/extensions/null_dataset_spec.rb +1 -11
  325. data/spec/extensions/optimistic_locking_spec.rb +2 -2
  326. data/spec/extensions/pagination_spec.rb +1 -1
  327. data/spec/extensions/pg_array_associations_spec.rb +22 -26
  328. data/spec/extensions/pg_array_ops_spec.rb +1 -1
  329. data/spec/extensions/pg_array_spec.rb +3 -48
  330. data/spec/extensions/pg_enum_spec.rb +1 -1
  331. data/spec/extensions/pg_extended_date_support_spec.rb +122 -0
  332. data/spec/extensions/pg_hstore_ops_spec.rb +1 -1
  333. data/spec/extensions/pg_hstore_spec.rb +22 -31
  334. data/spec/extensions/pg_inet_ops_spec.rb +1 -1
  335. data/spec/extensions/pg_inet_spec.rb +1 -14
  336. data/spec/extensions/pg_interval_spec.rb +3 -13
  337. data/spec/extensions/pg_json_ops_spec.rb +1 -1
  338. data/spec/extensions/pg_json_spec.rb +1 -13
  339. data/spec/extensions/pg_loose_count_spec.rb +1 -1
  340. data/spec/extensions/pg_range_ops_spec.rb +1 -1
  341. data/spec/extensions/pg_range_spec.rb +3 -88
  342. data/spec/extensions/pg_row_ops_spec.rb +1 -1
  343. data/spec/extensions/pg_row_plugin_spec.rb +1 -1
  344. data/spec/extensions/pg_row_spec.rb +1 -44
  345. data/spec/extensions/pg_static_cache_updater_spec.rb +1 -1
  346. data/spec/extensions/prepared_statements_safe_spec.rb +7 -7
  347. data/spec/extensions/prepared_statements_spec.rb +13 -48
  348. data/spec/extensions/pretty_table_spec.rb +40 -9
  349. data/spec/extensions/query_spec.rb +1 -12
  350. data/spec/extensions/rcte_tree_spec.rb +23 -34
  351. data/spec/extensions/round_timestamps_spec.rb +1 -5
  352. data/spec/extensions/s_spec.rb +1 -1
  353. data/spec/extensions/schema_caching_spec.rb +1 -1
  354. data/spec/extensions/schema_dumper_spec.rb +43 -32
  355. data/spec/extensions/select_remove_spec.rb +1 -1
  356. data/spec/extensions/sequel_4_dataset_methods_spec.rb +1 -1
  357. data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
  358. data/spec/extensions/serialization_spec.rb +5 -17
  359. data/spec/extensions/server_block_spec.rb +1 -1
  360. data/spec/extensions/server_logging_spec.rb +2 -2
  361. data/spec/extensions/sharding_spec.rb +1 -1
  362. data/spec/extensions/shared_caching_spec.rb +1 -28
  363. data/spec/extensions/single_table_inheritance_spec.rb +2 -5
  364. data/spec/extensions/singular_table_names_spec.rb +1 -1
  365. data/spec/extensions/skip_create_refresh_spec.rb +1 -1
  366. data/spec/extensions/spec_helper.rb +5 -27
  367. data/spec/extensions/split_array_nil_spec.rb +1 -1
  368. data/spec/extensions/split_values_spec.rb +1 -1
  369. data/spec/extensions/sql_comments_spec.rb +1 -1
  370. data/spec/extensions/sql_expr_spec.rb +1 -1
  371. data/spec/extensions/static_cache_spec.rb +1 -1
  372. data/spec/extensions/string_agg_spec.rb +2 -2
  373. data/spec/extensions/string_date_time_spec.rb +1 -1
  374. data/spec/extensions/string_stripper_spec.rb +1 -1
  375. data/spec/extensions/subclasses_spec.rb +1 -1
  376. data/spec/extensions/subset_conditions_spec.rb +1 -1
  377. data/spec/extensions/symbol_aref_refinement_spec.rb +1 -1
  378. data/spec/extensions/symbol_as_refinement_spec.rb +1 -1
  379. data/spec/extensions/synchronize_sql_spec.rb +124 -0
  380. data/spec/extensions/table_select_spec.rb +4 -4
  381. data/spec/extensions/tactical_eager_loading_spec.rb +1 -6
  382. data/spec/extensions/thread_local_timezones_spec.rb +1 -1
  383. data/spec/extensions/timestamps_spec.rb +5 -7
  384. data/spec/extensions/to_dot_spec.rb +1 -1
  385. data/spec/extensions/touch_spec.rb +1 -1
  386. data/spec/extensions/tree_spec.rb +1 -1
  387. data/spec/extensions/typecast_on_load_spec.rb +1 -1
  388. data/spec/extensions/unlimited_update_spec.rb +1 -1
  389. data/spec/extensions/update_or_create_spec.rb +12 -16
  390. data/spec/extensions/update_primary_key_spec.rb +4 -3
  391. data/spec/extensions/update_refresh_spec.rb +1 -1
  392. data/spec/extensions/uuid_spec.rb +10 -13
  393. data/spec/extensions/validate_associated_spec.rb +1 -1
  394. data/spec/extensions/validation_class_methods_spec.rb +3 -3
  395. data/spec/extensions/validation_contexts_spec.rb +1 -1
  396. data/spec/extensions/validation_helpers_spec.rb +10 -44
  397. data/spec/extensions/whitelist_security_spec.rb +5 -5
  398. data/spec/extensions/xml_serializer_spec.rb +8 -13
  399. data/spec/guards_helper.rb +2 -1
  400. data/spec/integration/associations_test.rb +1 -23
  401. data/spec/integration/database_test.rb +7 -7
  402. data/spec/integration/dataset_test.rb +12 -47
  403. data/spec/integration/eager_loader_test.rb +1 -1
  404. data/spec/integration/migrator_test.rb +1 -1
  405. data/spec/integration/model_test.rb +4 -82
  406. data/spec/integration/plugin_test.rb +7 -23
  407. data/spec/integration/prepared_statement_test.rb +8 -88
  408. data/spec/integration/schema_test.rb +10 -10
  409. data/spec/integration/spec_helper.rb +17 -21
  410. data/spec/integration/timezone_test.rb +5 -5
  411. data/spec/integration/transaction_test.rb +3 -55
  412. data/spec/integration/type_test.rb +9 -9
  413. data/spec/model/association_reflection_spec.rb +24 -9
  414. data/spec/model/associations_spec.rb +124 -303
  415. data/spec/model/base_spec.rb +43 -137
  416. data/spec/model/class_dataset_methods_spec.rb +2 -20
  417. data/spec/model/dataset_methods_spec.rb +1 -20
  418. data/spec/model/eager_loading_spec.rb +48 -17
  419. data/spec/model/hooks_spec.rb +5 -300
  420. data/spec/model/inflector_spec.rb +1 -1
  421. data/spec/model/model_spec.rb +29 -339
  422. data/spec/model/plugins_spec.rb +2 -16
  423. data/spec/model/record_spec.rb +33 -129
  424. data/spec/model/spec_helper.rb +5 -15
  425. data/spec/model/validations_spec.rb +1 -1
  426. data/spec/sequel_warning.rb +1 -12
  427. metadata +19 -65
  428. data/doc/active_record.rdoc +0 -927
  429. data/lib/sequel/adapters/cubrid.rb +0 -160
  430. data/lib/sequel/adapters/do/mysql.rb +0 -69
  431. data/lib/sequel/adapters/do/postgres.rb +0 -46
  432. data/lib/sequel/adapters/do/sqlite3.rb +0 -41
  433. data/lib/sequel/adapters/do.rb +0 -166
  434. data/lib/sequel/adapters/jdbc/as400.rb +0 -92
  435. data/lib/sequel/adapters/jdbc/cubrid.rb +0 -65
  436. data/lib/sequel/adapters/jdbc/firebirdsql.rb +0 -37
  437. data/lib/sequel/adapters/jdbc/informix-sqli.rb +0 -34
  438. data/lib/sequel/adapters/jdbc/jdbcprogress.rb +0 -34
  439. data/lib/sequel/adapters/odbc/progress.rb +0 -12
  440. data/lib/sequel/adapters/shared/cubrid.rb +0 -245
  441. data/lib/sequel/adapters/shared/firebird.rb +0 -261
  442. data/lib/sequel/adapters/shared/informix.rb +0 -63
  443. data/lib/sequel/adapters/shared/progress.rb +0 -40
  444. data/lib/sequel/adapters/swift/mysql.rb +0 -50
  445. data/lib/sequel/adapters/swift/postgres.rb +0 -49
  446. data/lib/sequel/adapters/swift/sqlite.rb +0 -48
  447. data/lib/sequel/adapters/swift.rb +0 -169
  448. data/lib/sequel/adapters/utils/pg_types.rb +0 -4
  449. data/lib/sequel/dataset/mutation.rb +0 -98
  450. data/lib/sequel/extensions/_deprecated_identifier_mangling.rb +0 -117
  451. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +0 -8
  452. data/lib/sequel/extensions/filter_having.rb +0 -65
  453. data/lib/sequel/extensions/hash_aliases.rb +0 -51
  454. data/lib/sequel/extensions/meta_def.rb +0 -37
  455. data/lib/sequel/extensions/query_literals.rb +0 -86
  456. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +0 -26
  457. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +0 -133
  458. data/lib/sequel/extensions/set_overrides.rb +0 -82
  459. data/lib/sequel/no_core_ext.rb +0 -4
  460. data/lib/sequel/plugins/association_autoreloading.rb +0 -11
  461. data/lib/sequel/plugins/identifier_columns.rb +0 -49
  462. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +0 -11
  463. data/lib/sequel/plugins/pg_typecast_on_load.rb +0 -90
  464. data/lib/sequel/plugins/prepared_statements_associations.rb +0 -137
  465. data/lib/sequel/plugins/prepared_statements_with_pk.rb +0 -71
  466. data/lib/sequel/plugins/schema.rb +0 -84
  467. data/lib/sequel/plugins/scissors.rb +0 -37
  468. data/spec/core/dataset_mutation_spec.rb +0 -253
  469. data/spec/extensions/_deprecated_identifier_mangling_spec.rb +0 -314
  470. data/spec/extensions/before_after_save_spec.rb +0 -40
  471. data/spec/extensions/filter_having_spec.rb +0 -42
  472. data/spec/extensions/from_block_spec.rb +0 -21
  473. data/spec/extensions/hash_aliases_spec.rb +0 -26
  474. data/spec/extensions/identifier_columns_spec.rb +0 -19
  475. data/spec/extensions/meta_def_spec.rb +0 -35
  476. data/spec/extensions/no_auto_literal_strings_spec.rb +0 -69
  477. data/spec/extensions/pg_typecast_on_load_spec.rb +0 -70
  478. data/spec/extensions/prepared_statements_associations_spec.rb +0 -212
  479. data/spec/extensions/prepared_statements_with_pk_spec.rb +0 -40
  480. data/spec/extensions/query_literals_spec.rb +0 -185
  481. data/spec/extensions/schema_spec.rb +0 -123
  482. data/spec/extensions/scissors_spec.rb +0 -27
  483. data/spec/extensions/sequel_3_dataset_methods_spec.rb +0 -118
  484. data/spec/extensions/set_overrides_spec.rb +0 -75
data/lib/sequel/sql.rb CHANGED
@@ -1,42 +1,16 @@
1
1
  # frozen-string-literal: true
2
2
 
3
3
  module Sequel
4
- if RUBY_VERSION < '1.9.0'
5
- # :nocov:
6
- # If on Ruby 1.8, create a <tt>Sequel::BasicObject</tt> class that is similar to the
7
- # the Ruby 1.9 +BasicObject+ class. This is used in a few places where proxy
8
- # objects are needed that respond to any method call.
9
- class BasicObject
10
- # The instance methods to not remove from the class when removing
11
- # other methods.
12
- KEEP_METHODS = %w"__id__ __send__ __metaclass__ instance_eval instance_exec == equal? initialize method_missing"
13
-
14
- # Remove all but the most basic instance methods from the class. A separate
15
- # method so that it can be called again if necessary if you load libraries
16
- # after Sequel that add instance methods to +Object+.
17
- def self.remove_methods!
18
- ((private_instance_methods + instance_methods) - KEEP_METHODS).each{|m| undef_method(m)}
19
- end
20
- remove_methods!
21
- end
22
- # :nocov:
23
- else
24
- # If on 1.9, create a <tt>Sequel::BasicObject</tt> class that is just like the
25
- # default +BasicObject+ class, except that missing constants are resolved in
26
- # +Object+. This allows the virtual row support to work with classes
27
- # without prefixing them with ::, such as:
28
- #
29
- # DB[:bonds].where{maturity_date > Time.now}
30
- class BasicObject < ::BasicObject
31
- # Lookup missing constants in <tt>::Object</tt>
32
- def self.const_missing(name)
33
- ::Object.const_get(name)
34
- end
35
-
36
- # No-op method on ruby 1.9, which has a real +BasicObject+ class.
37
- def self.remove_methods!
38
- Sequel::Deprecation.deprecate("Sequel::BasicObject#remove_methods!", "It has no effect, so stop calling it")
39
- end
4
+ # The <tt>Sequel::BasicObject</tt> class is just like the
5
+ # default +BasicObject+ class, except that missing constants are resolved in
6
+ # +Object+. This allows the virtual row support to work with classes
7
+ # without prefixing them with ::, such as:
8
+ #
9
+ # DB[:bonds].where{maturity_date > Time.now}
10
+ class BasicObject < ::BasicObject
11
+ # Lookup missing constants in <tt>::Object</tt>
12
+ def self.const_missing(name)
13
+ ::Object.const_get(name)
40
14
  end
41
15
  end
42
16
 
@@ -52,15 +26,17 @@ module Sequel
52
26
  # Set the date used for SQLTime instances.
53
27
  attr_writer :date
54
28
 
29
+ # use the date explicitly set, or the current date if there is not a
30
+ # date set.
55
31
  def date
56
32
  @date || now
57
33
  end
58
34
 
59
- # Create a new SQLTime instance given an hour, minute, and second.
35
+ # Create a new SQLTime instance given an hour, minute, second, and usec.
60
36
  def create(hour, minute, second, usec = 0)
61
37
  t = date
62
38
  meth = Sequel.application_timezone == :utc ? :utc : :local
63
- send(meth, t.year, t.month, t.day, hour, minute, second, usec)
39
+ public_send(meth, t.year, t.month, t.day, hour, minute, second, usec)
64
40
  end
65
41
  end
66
42
 
@@ -82,18 +58,11 @@ module Sequel
82
58
  end
83
59
 
84
60
  # The SQL module holds classes whose instances represent SQL fragments.
85
- # It also holds modules that are included in core ruby classes that
86
- # make Sequel a friendly DSL.
61
+ # It also holds modules that are used by these classes.
87
62
  module SQL
88
-
89
- ### Parent Classes ###
90
-
91
- # Classes/Modules aren't in alphabetical order due to the fact that
92
- # some reference constants defined in others at load time.
93
-
94
63
  # Base class for all SQL expression objects.
95
64
  class Expression
96
- @comparison_attrs = []
65
+ @comparison_attrs = [].freeze
97
66
 
98
67
  class << self
99
68
  # All attributes used for equality and hash methods.
@@ -115,7 +84,7 @@ module Sequel
115
84
  subclass.instance_variable_set(:@comparison_attrs, comparison_attrs.dup)
116
85
  end
117
86
 
118
- private
87
+ private
119
88
 
120
89
  # Create a to_s instance method that takes a dataset, and calls
121
90
  # the method provided on the dataset with args as the argument (self by default).
@@ -125,9 +94,17 @@ module Sequel
125
94
  # arbitrary code execution.
126
95
  def to_s_method(meth, args=:self) # :nodoc:
127
96
  class_eval("def to_s_append(ds, sql) ds.#{meth}_append(sql, #{args}) end", __FILE__, __LINE__)
97
+ @comparison_attrs.freeze
128
98
  end
129
99
  end
130
100
 
101
+ # Make clone/dup return self, since Expression objects are supposed to
102
+ # be frozen value objects
103
+ def clone
104
+ self
105
+ end
106
+ alias dup clone
107
+
131
108
  # Alias of <tt>eql?</tt>
132
109
  def ==(other)
133
110
  eql?(other)
@@ -136,35 +113,21 @@ module Sequel
136
113
  # Returns true if the receiver is the same expression as the
137
114
  # the +other+ expression.
138
115
  def eql?(other)
139
- other.is_a?(self.class) && !self.class.comparison_attrs.find{|a| send(a) != other.send(a)}
116
+ other.is_a?(self.class) && !self.class.comparison_attrs.find{|a| public_send(a) != other.public_send(a)}
140
117
  end
141
118
 
142
119
  # Make sure that the hash value is the same if the attributes are the same.
143
120
  def hash
144
- ([self.class] + self.class.comparison_attrs.map{|x| send(x)}).hash
121
+ ([self.class] + self.class.comparison_attrs.map{|x| public_send(x)}).hash
145
122
  end
146
123
 
147
124
  # Show the class name and instance variables for the object.
148
125
  def inspect
149
126
  "#<#{self.class} #{instance_variables.map{|iv| "#{iv}=>#{instance_variable_get(iv).inspect}"}.join(', ')}>"
150
127
  end
151
-
152
- # Returns +self+, because <tt>SQL::Expression</tt> already acts like +LiteralString+.
153
- def lit
154
- Sequel::Deprecation.deprecate("Sequel::SQL::Expression#lit", "This method returns self, so just use the receiver")
155
- self
156
- end
157
-
158
- # Alias of +to_s+
159
- def sql_literal(ds)
160
- Sequel::Deprecation.deprecate("Sequel::SQL::Expression#sql_literal", "Call Sequel::Dataset#literal with the expression instead")
161
- s = String.new
162
- to_s_append(ds, s)
163
- s
164
- end
165
128
  end
166
129
 
167
- # Represents a complex SQL expression, with a given operator and one
130
+ # Represents a SQL expression, with a given operator and one
168
131
  # or more attributes (which may also be ComplexExpressions, forming
169
132
  # a tree). This class is the backbone of Sequel's ruby expression DSL.
170
133
  #
@@ -179,49 +142,49 @@ module Sequel
179
142
  :'NOT LIKE' => :LIKE, :~ => :'!~', :'!~' => :~, :IN => :'NOT IN',
180
143
  :'NOT IN' => :IN, :IS => :'IS NOT', :'IS NOT' => :IS, :'~*' => :'!~*',
181
144
  :'!~*' => :'~*', :NOT => :NOOP, :NOOP => :NOT, :ILIKE => :'NOT ILIKE',
182
- :'NOT ILIKE'=>:ILIKE}
145
+ :'NOT ILIKE'=>:ILIKE}.freeze
183
146
 
184
147
  # Standard mathematical operators used in +NumericMethods+
185
- MATHEMATICAL_OPERATORS = [:+, :-, :/, :*, :**]
148
+ MATHEMATICAL_OPERATORS = [:+, :-, :/, :*, :**].freeze
186
149
 
187
150
  # Bitwise mathematical operators used in +BitwiseMethods+
188
- BITWISE_OPERATORS = [:&, :|, :^, :<<, :>>, :%]
151
+ BITWISE_OPERATORS = [:&, :|, :^, :<<, :>>, :%].freeze
189
152
 
190
153
  # Operators that check for equality
191
- EQUALITY_OPERATORS = [:'=', :'!=']
154
+ EQUALITY_OPERATORS = [:'=', :'!='].freeze
192
155
 
193
156
  # Inequality operators used in +InequalityMethods+
194
- INEQUALITY_OPERATORS = [:<, :>, :<=, :>=]
157
+ INEQUALITY_OPERATORS = [:<, :>, :<=, :>=].freeze
195
158
 
196
159
  # Hash of ruby operator symbols to SQL operators, used in +BooleanMethods+
197
- BOOLEAN_OPERATOR_METHODS = {:& => :AND, :| =>:OR}
160
+ BOOLEAN_OPERATOR_METHODS = {:& => :AND, :| =>:OR}.freeze
198
161
 
199
162
  # Operators that use IN/NOT IN for inclusion/exclusion
200
- IN_OPERATORS = [:IN, :'NOT IN']
163
+ IN_OPERATORS = [:IN, :'NOT IN'].freeze
201
164
 
202
165
  # Operators that use IS, used for special casing to override literal true/false values
203
- IS_OPERATORS = [:IS, :'IS NOT']
166
+ IS_OPERATORS = [:IS, :'IS NOT'].freeze
204
167
 
205
168
  # Operators that do pattern matching via regular expressions
206
- REGEXP_OPERATORS = [:~, :'!~', :'~*', :'!~*']
169
+ REGEXP_OPERATORS = [:~, :'!~', :'~*', :'!~*'].freeze
207
170
 
208
171
  # Operators that do pattern matching via LIKE
209
- LIKE_OPERATORS = [:LIKE, :'NOT LIKE', :ILIKE, :'NOT ILIKE']
172
+ LIKE_OPERATORS = [:LIKE, :'NOT LIKE', :ILIKE, :'NOT ILIKE'].freeze
210
173
 
211
174
  # Operator symbols that take exactly two arguments
212
- TWO_ARITY_OPERATORS = EQUALITY_OPERATORS + INEQUALITY_OPERATORS + IS_OPERATORS + IN_OPERATORS + REGEXP_OPERATORS + LIKE_OPERATORS + [:**]
175
+ TWO_ARITY_OPERATORS = (EQUALITY_OPERATORS + INEQUALITY_OPERATORS + IS_OPERATORS + IN_OPERATORS + REGEXP_OPERATORS + LIKE_OPERATORS + [:**]).freeze
213
176
 
214
177
  # Operator symbols that take one or more arguments
215
- N_ARITY_OPERATORS = [:AND, :OR, :'||'] + MATHEMATICAL_OPERATORS + BITWISE_OPERATORS - [:**]
178
+ N_ARITY_OPERATORS = ([:AND, :OR, :'||'] + MATHEMATICAL_OPERATORS + BITWISE_OPERATORS - [:**]).freeze
216
179
 
217
180
  # Operator symbols that are associative
218
- ASSOCIATIVE_OPERATORS = [:AND, :OR, :'||', :+, :*, :&, :|]
181
+ ASSOCIATIVE_OPERATORS = [:AND, :OR, :'||', :+, :*, :&, :|].freeze
219
182
 
220
183
  # Operator symbols that take only a single argument
221
- ONE_ARITY_OPERATORS = [:NOT, :NOOP, :'B~']
184
+ ONE_ARITY_OPERATORS = [:NOT, :NOOP, :'B~'].freeze
222
185
 
223
186
  # Custom expressions that may have different syntax on different databases
224
- CUSTOM_EXPRESSIONS = [:extract]
187
+ CUSTOM_EXPRESSIONS = [:extract].freeze
225
188
 
226
189
  # The operator symbol for this object
227
190
  attr_reader :op
@@ -272,8 +235,6 @@ module Sequel
272
235
  class GenericExpression < Expression
273
236
  end
274
237
 
275
- ### Modules ###
276
-
277
238
  # Includes an +as+ method that creates an SQL alias.
278
239
  module AliasMethods
279
240
  # Create an SQL alias (+AliasedExpression+) of the receiving column or expression to the given alias.
@@ -302,25 +263,24 @@ module Sequel
302
263
 
303
264
  # Do the bitwise compliment of the self
304
265
  #
305
- # ~:a.sql_number # ~"a"
266
+ # ~(Sequel[:a].sql_number) # ~"a"
306
267
  def ~
307
268
  NumericExpression.new(:'B~', self)
308
269
  end
309
270
  end
310
271
 
311
272
  # This module includes the boolean/logical AND (&), OR (|) and NOT (~) operators
312
- # that are defined on objects that can be used in a boolean context in SQL
313
- # (+Symbol+, +LiteralString+, and <tt>SQL::GenericExpression</tt>).
273
+ # that are defined on objects that can be used in a boolean context in SQL.
314
274
  #
315
- # :a & :b # "a" AND "b"
316
- # :a | :b # "a" OR "b"
317
- # ~:a # NOT "a"
275
+ # Sequel[:a] & Sequel[:b] # "a" AND "b"
276
+ # Sequel[:a] | Sequel[:b] # "a" OR "b"
277
+ # ~Sequel[:a] # NOT "a"
318
278
  #
319
279
  # One exception to this is when a NumericExpression or Integer is the argument
320
280
  # to & or |, in which case a bitwise method will be used:
321
281
  #
322
- # :a & 1 # "a" & 1
323
- # :a | (:b + 1) # "a" | ("b" + 1)
282
+ # Sequel[:a] & 1 # "a" & 1
283
+ # Sequel[:a] | (Sequel[:b] + 1) # "a" | ("b" + 1)
324
284
  module BooleanMethods
325
285
  ComplexExpression::BOOLEAN_OPERATOR_METHODS.each do |m, o|
326
286
  module_eval(<<-END, __FILE__, __LINE__+1)
@@ -337,14 +297,14 @@ module Sequel
337
297
 
338
298
  # Create a new BooleanExpression with NOT, representing the inversion of whatever self represents.
339
299
  #
340
- # ~:a # NOT :a
300
+ # ~Sequel[:a] # NOT :a
341
301
  def ~
342
302
  BooleanExpression.invert(self)
343
303
  end
344
304
  end
345
305
 
346
- # These methods are designed as replacements for the core extensions, so that
347
- # Sequel is still easy to use if the core extensions are not enabled.
306
+ # These methods make it easier to create Sequel expressions without
307
+ # using the core extensions.
348
308
  module Builders
349
309
  # Create an SQL::AliasedExpression for the given expression and alias.
350
310
  #
@@ -362,7 +322,7 @@ module Sequel
362
322
  # are ordered after other values).
363
323
  #
364
324
  # Sequel.asc(:a) # a ASC
365
- # Sequel.asc(:b, :nulls=>:last) # b ASC NULLS LAST
325
+ # Sequel.asc(:b, nulls: :last) # b ASC NULLS LAST
366
326
  def asc(arg, opts=OPTS)
367
327
  SQL::OrderedExpression.new(arg, false, opts)
368
328
  end
@@ -380,8 +340,8 @@ module Sequel
380
340
 
381
341
  # Return an <tt>SQL::CaseExpression</tt> created with the given arguments.
382
342
  #
383
- # Sequel.case([[{:a=>[2,3]}, 1]], 0) # SQL: CASE WHEN a IN (2, 3) THEN 1 ELSE 0 END
384
- # Sequel.case({:a=>1}, 0, :b) # SQL: CASE b WHEN a THEN 1 ELSE 0 END
343
+ # Sequel.case([[{a: [2,3]}, 1]], 0) # SQL: CASE WHEN a IN (2, 3) THEN 1 ELSE 0 END
344
+ # Sequel.case({a: 1}, 0, :b) # SQL: CASE b WHEN a THEN 1 ELSE 0 END
385
345
  def case(*args)
386
346
  SQL::CaseExpression.new(*args)
387
347
  end
@@ -428,8 +388,8 @@ module Sequel
428
388
  # nested structures.
429
389
  #
430
390
  # Sequel.deep_qualify(:table, :column) # "table"."column"
431
- # Sequel.deep_qualify(:table, Sequel.+(:column, 1)) # "table"."column" + 1
432
- # Sequel.deep_qualify(:table, Sequel.like(:a, 'b')) # "table"."a" LIKE 'b' ESCAPE '\'
391
+ # Sequel.deep_qualify(:table, Sequel[:column] + 1) # "table"."column" + 1
392
+ # Sequel.deep_qualify(:table, Sequel[:a].like('b')) # "table"."a" LIKE 'b' ESCAPE '\'
433
393
  def deep_qualify(qualifier, expr)
434
394
  Sequel::Qualifier.new(qualifier).transform(expr)
435
395
  end
@@ -463,7 +423,7 @@ module Sequel
463
423
  # are ordered after other values).
464
424
  #
465
425
  # Sequel.desc(:a) # b DESC
466
- # Sequel.desc(:b, :nulls=>:first) # b DESC NULLS FIRST
426
+ # Sequel.desc(:b, nulls: :first) # b DESC NULLS FIRST
467
427
  def desc(arg, opts=OPTS)
468
428
  SQL::OrderedExpression.new(arg, true, opts)
469
429
  end
@@ -552,7 +512,7 @@ module Sequel
552
512
 
553
513
  # Return the argument wrapped as an <tt>SQL::Identifier</tt>.
554
514
  #
555
- # Sequel.identifier(:a__b) # "a__b"
515
+ # Sequel.identifier(:a) # "a"
556
516
  def identifier(name)
557
517
  SQL::Identifier.new(name)
558
518
  end
@@ -605,10 +565,10 @@ module Sequel
605
565
  # Converts a string into a <tt>Sequel::LiteralString</tt>, in order to override string
606
566
  # literalization, e.g.:
607
567
  #
608
- # DB[:items].where(:abc => 'def').sql #=>
568
+ # DB[:items].where(abc: 'def').sql #=>
609
569
  # "SELECT * FROM items WHERE (abc = 'def')"
610
570
  #
611
- # DB[:items].where(:abc => Sequel.lit('def')).sql #=>
571
+ # DB[:items].where(abc: Sequel.lit('def')).sql #=>
612
572
  # "SELECT * FROM items WHERE (abc = def)"
613
573
  #
614
574
  # You can also provide arguments, to create a <tt>Sequel::SQL::PlaceholderLiteralString</tt>:
@@ -630,7 +590,7 @@ module Sequel
630
590
  # Return a <tt>Sequel::SQL::BooleanExpression</tt> created from the condition
631
591
  # specifier, matching none of the conditions.
632
592
  #
633
- # Sequel.negate(:a=>true) # SQL: a IS NOT TRUE
593
+ # Sequel.negate(a: true) # SQL: a IS NOT TRUE
634
594
  # Sequel.negate([[:a, true]]) # SQL: a IS NOT TRUE
635
595
  # Sequel.negate([[:a, 1], [:b, 2]]) # SQL: ((a != 1) AND (b != 2))
636
596
  def negate(arg)
@@ -644,7 +604,7 @@ module Sequel
644
604
  # Return a <tt>Sequel::SQL::BooleanExpression</tt> created from the condition
645
605
  # specifier, matching any of the conditions.
646
606
  #
647
- # Sequel.or(:a=>true) # SQL: a IS TRUE
607
+ # Sequel.or(a: true) # SQL: a IS TRUE
648
608
  # Sequel.or([[:a, true]]) # SQL: a IS TRUE
649
609
  # Sequel.or([[:a, 1], [:b, 2]]) # SQL: ((a = 1) OR (b = 2))
650
610
  def or(arg)
@@ -733,22 +693,11 @@ module Sequel
733
693
  end
734
694
 
735
695
  # Adds methods that allow you to treat an object as an instance of a specific
736
- # +ComplexExpression+ subclass. This is useful if another library
737
- # overrides the methods defined by Sequel.
738
- #
739
- # For example, if <tt>Symbol#/</tt> is overridden to produce a string (for
740
- # example, to make file system path creation easier), the
741
- # following code will not do what you want:
742
- #
743
- # :price/10 > 100
744
- #
745
- # In that case, you need to do the following:
746
- #
747
- # :price.sql_number/10 > 100
696
+ # +ComplexExpression+ subclass.
748
697
  module ComplexExpressionMethods
749
698
  # Extract a datetime part (e.g. year, month) from self:
750
699
  #
751
- # :date.extract(:year) # extract(year FROM "date")
700
+ # Sequel[:date].extract(:year) # extract(year FROM "date")
752
701
  #
753
702
  # Also has the benefit of returning the result as a
754
703
  # NumericExpression instead of a generic ComplexExpression.
@@ -763,16 +712,16 @@ module Sequel
763
712
 
764
713
  # Return a NumericExpression representation of +self+.
765
714
  #
766
- # ~:a # NOT "a"
767
- # ~:a.sql_number # ~"a"
715
+ # ~Sequel[:a] # NOT "a"
716
+ # ~(Sequel[:a].sql_number) # ~"a"
768
717
  def sql_number
769
718
  NumericExpression.new(:NOOP, self)
770
719
  end
771
720
 
772
721
  # Return a StringExpression representation of +self+.
773
722
  #
774
- # :a + :b # "a" + "b"
775
- # :a.sql_string + :b # "a" || "b"
723
+ # Sequel[:a] + :b # "a" + "b"
724
+ # Sequel[:a].sql_string + :b # "a" || "b"
776
725
  def sql_string
777
726
  StringExpression.new(:NOOP, self)
778
727
  end
@@ -803,7 +752,7 @@ module Sequel
803
752
  # One exception to this is if + is called with a +String+ or +StringExpression+,
804
753
  # in which case the || operator is used instead of the + operator:
805
754
  #
806
- # :a + 'b' # "a" || 'b'
755
+ # Sequel[:a] + 'b' # "a" || 'b'
807
756
  module NumericMethods
808
757
  (ComplexExpression::MATHEMATICAL_OPERATORS - [:+]).each do |o|
809
758
  module_eval("def #{o}(o) NumericExpression.new(#{o.inspect}, self, o) end", __FILE__, __LINE__)
@@ -845,7 +794,7 @@ module Sequel
845
794
  # Sequel[:a] =~ [1, 2] # (a IN [1, 2])
846
795
  # Sequel[:a] =~ nil # (a IS NULL)
847
796
  #
848
- # On Ruby 1.9+, this also adds the !~ method, for easily setting up not equals,
797
+ # This also adds the !~ method, for easily setting up not equals,
849
798
  # exclusion, and inverse pattern matching. This is the same as as inverting the
850
799
  # result of the =~ method
851
800
  #
@@ -859,23 +808,19 @@ module Sequel
859
808
  BooleanExpression.send(:from_value_pair, self, other)
860
809
  end
861
810
 
862
- if RUBY_VERSION >= '1.9'
863
- module_eval(<<-END, __FILE__, __LINE__+1)
864
- def !~(other)
865
- ~(self =~ other)
866
- end
867
- END
811
+ def !~(other)
812
+ ~(self =~ other)
868
813
  end
869
814
  end
870
815
 
871
- # These methods are designed as replacements for the core extension operator
872
- # methods, so that Sequel is still easy to use if the core extensions are not
873
- # enabled.
816
+ # This adds methods to create SQL expressions using operators:
874
817
  #
875
- # The following methods are defined via metaprogramming: +, -, *, /, &, |.
876
- # The +, -, *, and / operators return numeric expressions combining all the
877
- # arguments with the appropriate operator, and the & and | operators return
878
- # boolean expressions combining all of the arguments with either AND or OR.
818
+ # Sequel.+(1, :a) # (1 + a)
819
+ # Sequel.-(1, :a) # (1 - a)
820
+ # Sequel.*(1, :a) # (1 * a)
821
+ # Sequel./(1, :a) # (1 / a)
822
+ # Sequel.&(:b, :a) # (b AND a)
823
+ # Sequel.|(:b, :a) # (b OR a)
879
824
  module OperatorBuilders
880
825
  {'::Sequel::SQL::NumericExpression'=>{'+'=>'+', '-'=>'-', '*'=>'*', '/'=>'/'},
881
826
  '::Sequel::SQL::BooleanExpression'=>{'&'=>'AND', '|'=>'OR'}}.each do |klass, ops|
@@ -942,13 +887,13 @@ module Sequel
942
887
  end
943
888
  end
944
889
 
945
- # Includes a +qualify+ method that created <tt>QualifiedIdentifier</tt>s, used for qualifying column
890
+ # Includes a +qualify+ and <tt>[]</tt> methods that create <tt>QualifiedIdentifier</tt>s, used for qualifying column
946
891
  # names with a table or table names with a schema, and the * method for returning all columns in
947
892
  # the identifier if no arguments are given.
948
893
  module QualifyingMethods
949
894
  # If no arguments are given, return an SQL::ColumnAll:
950
895
  #
951
- # Sequel[:a__b].* # a.b.*
896
+ # Sequel[:a].* # a.*
952
897
  def *(ce=(arg=false;nil))
953
898
  if arg == false
954
899
  Sequel::SQL::ColumnAll.new(self)
@@ -982,7 +927,7 @@ module Sequel
982
927
  # Create a +BooleanExpression+ case insensitive pattern match of the receiver
983
928
  # with the given patterns. See <tt>StringExpression.like</tt>.
984
929
  #
985
- # :a.ilike('A%') # "a" ILIKE 'A%' ESCAPE '\'
930
+ # Sequel[:a].ilike('A%') # "a" ILIKE 'A%' ESCAPE '\'
986
931
  def ilike(*ces)
987
932
  StringExpression.like(self, *(ces << {:case_insensitive=>true}))
988
933
  end
@@ -990,7 +935,7 @@ module Sequel
990
935
  # Create a +BooleanExpression+ case sensitive (if the database supports it) pattern match of the receiver with
991
936
  # the given patterns. See <tt>StringExpression.like</tt>.
992
937
  #
993
- # :a.like('A%') # "a" LIKE 'A%' ESCAPE '\'
938
+ # Sequel[:a].like('A%') # "a" LIKE 'A%' ESCAPE '\'
994
939
  def like(*ces)
995
940
  StringExpression.like(self, *ces)
996
941
  end
@@ -1002,7 +947,7 @@ module Sequel
1002
947
  # Return a +StringExpression+ representing the concatenation of the receiver
1003
948
  # with the given argument.
1004
949
  #
1005
- # :x.sql_string + :y # => "x" || "y"
950
+ # Sequel[:x].sql_string + :y # => "x" || "y"
1006
951
  def +(ce)
1007
952
  StringExpression.new(:'||', self, ce)
1008
953
  end
@@ -1013,36 +958,29 @@ module Sequel
1013
958
  # Return a <tt>Subscript</tt> with the given arguments, representing an
1014
959
  # SQL array access.
1015
960
  #
1016
- # :array.sql_subscript(1) # array[1]
1017
- # :array.sql_subscript(1, 2) # array[1, 2]
1018
- # :array.sql_subscript([1, 2]) # array[1, 2]
1019
- # :array.sql_subscript(:array, 1..2) # array[1:2]
1020
- # :array.sql_subscript(:array, 1...3) # array[1:2]
961
+ # Sequel[:array].sql_subscript(1) # array[1]
962
+ # Sequel[:array].sql_subscript(1, 2) # array[1, 2]
963
+ # Sequel[:array].sql_subscript([1, 2]) # array[1, 2]
964
+ # Sequel[:array].sql_subscript(1..2) # array[1:2]
965
+ # Sequel[:array].sql_subscript(1...3) # array[1:2]
1021
966
  def sql_subscript(*sub)
1022
967
  Subscript.new(self, sub.flatten)
1023
968
  end
1024
969
  end
1025
970
 
1026
- ### Classes ###
1027
-
1028
971
  # Represents an aliasing of an expression to a given alias.
1029
972
  class AliasedExpression < Expression
1030
973
  # The expression to alias
1031
974
  attr_reader :expression
1032
975
 
1033
- # The alias to use for the expression
976
+ # The alias to use for the expression.
1034
977
  attr_reader :alias
1035
978
 
1036
- def aliaz
1037
- Sequel::Deprecation.deprecate("Sequel::SQL::AliasedExpression#aliaz", "Use #alias instead")
1038
- self.alias
1039
- end
1040
-
1041
- # The columns aliases to use, for when the aliased expression is
979
+ # The columns aliases (derived column list) to use, for when the aliased expression is
1042
980
  # a record or set of records (such as a dataset).
1043
981
  attr_reader :columns
1044
982
 
1045
- # Create an object with the given expression and alias.
983
+ # Create an object with the given expression, alias, and optional column aliases.
1046
984
  def initialize(expression, aliaz, columns=nil)
1047
985
  @expression = expression
1048
986
  @alias = aliaz
@@ -1192,11 +1130,11 @@ module Sequel
1192
1130
  # The default value if no conditions match.
1193
1131
  attr_reader :default
1194
1132
 
1195
- # The expression to test the conditions against
1133
+ # An optional expression to test the conditions against
1196
1134
  attr_reader :expression
1197
1135
 
1198
1136
  # Create an object with the given conditions and
1199
- # default value. An expression can be provided to
1137
+ # default value, and optional expression. An expression can be provided to
1200
1138
  # test each condition against, instead of having
1201
1139
  # all conditions represent their own boolean expression.
1202
1140
  def initialize(conditions, default, expression=(no_expression=true; nil))
@@ -1235,7 +1173,7 @@ module Sequel
1235
1173
  # The type to which to cast the expression
1236
1174
  attr_reader :type
1237
1175
 
1238
- # Set the attributes to the given arguments
1176
+ # Set the expression and type for the cast
1239
1177
  def initialize(expr, type)
1240
1178
  @expr = expr
1241
1179
  @type = type
@@ -1268,17 +1206,17 @@ module Sequel
1268
1206
 
1269
1207
  # Return a BooleanExpression with the same op and args.
1270
1208
  def sql_boolean
1271
- BooleanExpression.new(self.op, *self.args)
1209
+ BooleanExpression.new(op, *args)
1272
1210
  end
1273
1211
 
1274
1212
  # Return a NumericExpression with the same op and args.
1275
1213
  def sql_number
1276
- NumericExpression.new(self.op, *self.args)
1214
+ NumericExpression.new(op, *args)
1277
1215
  end
1278
1216
 
1279
1217
  # Return a StringExpression with the same op and args.
1280
1218
  def sql_string
1281
- StringExpression.new(self.op, *self.args)
1219
+ StringExpression.new(op, *args)
1282
1220
  end
1283
1221
  end
1284
1222
 
@@ -1287,7 +1225,7 @@ module Sequel
1287
1225
  # The underlying constant related to this object.
1288
1226
  attr_reader :constant
1289
1227
 
1290
- # Create an constant with the given value
1228
+ # Create a constant with the given value
1291
1229
  def initialize(constant)
1292
1230
  @constant = constant
1293
1231
  freeze
@@ -1296,7 +1234,7 @@ module Sequel
1296
1234
  to_s_method :constant_sql, '@constant'
1297
1235
  end
1298
1236
 
1299
- # Represents boolean constants such as +NULL+, +NOTNULL+, +TRUE+, and +FALSE+.
1237
+ # Represents boolean constants such as +NULL+, +TRUE+, and +FALSE+.
1300
1238
  class BooleanConstant < Constant
1301
1239
  to_s_method :boolean_constant_sql, '@constant'
1302
1240
  end
@@ -1324,7 +1262,7 @@ module Sequel
1324
1262
  class ComplexExpression
1325
1263
  # A hash of the opposite for each constant, used for inverting constants.
1326
1264
  CONSTANT_INVERSIONS = {Constants::TRUE=>Constants::FALSE, Constants::FALSE=>Constants::TRUE,
1327
- Constants::NULL=>Constants::NOTNULL, Constants::NOTNULL=>Constants::NULL}
1265
+ Constants::NULL=>Constants::NOTNULL, Constants::NOTNULL=>Constants::NULL}.freeze
1328
1266
  end
1329
1267
 
1330
1268
  # Represents a delayed evaluation, encapsulating a callable
@@ -1363,11 +1301,6 @@ module Sequel
1363
1301
  # The SQL function to call
1364
1302
  attr_reader :name
1365
1303
 
1366
- def f
1367
- Sequel::Deprecation.deprecate("Sequel::SQL::Function#f", "Use #name instead")
1368
- name
1369
- end
1370
-
1371
1304
  # The array of arguments to pass to the function (may be blank)
1372
1305
  attr_reader :args
1373
1306
 
@@ -1379,7 +1312,8 @@ module Sequel
1379
1312
  _initialize(name, args, OPTS)
1380
1313
  end
1381
1314
 
1382
- def self.new!(name, args, opts)
1315
+ # Set the name, args, and options, for internal use only.
1316
+ def self.new!(name, args, opts) # :nodoc:
1383
1317
  allocate.send(:_initialize, name, args, opts)
1384
1318
  end
1385
1319
 
@@ -1405,7 +1339,7 @@ module Sequel
1405
1339
  # Return a new function with FILTER added to it, for filtered
1406
1340
  # aggregate functions:
1407
1341
  #
1408
- # Sequel.function(:foo, :col).filter(:a=>1) # foo(col) FILTER (WHERE a = 1)
1342
+ # Sequel.function(:foo, :col).filter(a: 1) # foo(col) FILTER (WHERE (a = 1))
1409
1343
  def filter(*args, &block)
1410
1344
  if args.length == 1
1411
1345
  args = args.first
@@ -1434,7 +1368,7 @@ module Sequel
1434
1368
  # Return a new function with an OVER clause (making it a window function).
1435
1369
  # See {SQL::Window} for the list of options +over+ can receive.
1436
1370
  #
1437
- # Sequel.function(:row_number).over(:partition=>:col) # row_number() OVER (PARTITION BY col)
1371
+ # Sequel.function(:row_number).over(partition: :col) # row_number() OVER (PARTITION BY col)
1438
1372
  def over(window=OPTS)
1439
1373
  raise Error, "function already has a window applied to it" if opts[:over]
1440
1374
  window = Window.new(window) unless window.is_a?(Window)
@@ -1452,7 +1386,7 @@ module Sequel
1452
1386
  # Return a new function where the function name will not be quoted even
1453
1387
  # if the database supports quoted functions:
1454
1388
  #
1455
- # Sequel[:foo].function.unquoted # foo()
1389
+ # Sequel[:foo][:bar].function.unquoted # foo.bar()
1456
1390
  def unquoted
1457
1391
  with_opts(:quoted=>false)
1458
1392
  end
@@ -1478,7 +1412,7 @@ module Sequel
1478
1412
 
1479
1413
  private
1480
1414
 
1481
- # Set args and opts
1415
+ # Set name, args, and opts
1482
1416
  def _initialize(name, args, opts)
1483
1417
  @name = name
1484
1418
  @args = args.freeze
@@ -1505,16 +1439,14 @@ module Sequel
1505
1439
  include SubscriptMethods
1506
1440
  end
1507
1441
 
1508
- # Represents an identifier (column or table). Can be used
1509
- # to specify a +Symbol+ with multiple underscores should not be
1510
- # split, or for creating an identifier without using a symbol.
1442
+ # Represents an identifier (column, table, schema, etc.).
1511
1443
  class Identifier < GenericExpression
1512
1444
  include QualifyingMethods
1513
1445
 
1514
- # The table or column to reference
1446
+ # The identifier to reference
1515
1447
  attr_reader :value
1516
1448
 
1517
- # Set the value to the given argument
1449
+ # Set the identifier to the given argument
1518
1450
  def initialize(value)
1519
1451
  @value = value
1520
1452
  freeze
@@ -1744,15 +1676,16 @@ module Sequel
1744
1676
  include InequalityMethods
1745
1677
 
1746
1678
  # Map of [regexp, case_insenstive] to +ComplexExpression+ operator symbol
1747
- LIKE_MAP = {[true, true]=>:'~*', [true, false]=>:~, [false, true]=>:ILIKE, [false, false]=>:LIKE}
1679
+ LIKE_MAP = {[true, true]=>:'~*', [true, false]=>:~, [false, true]=>:ILIKE, [false, false]=>:LIKE}.freeze
1680
+ LIKE_MAP.each_key(&:freeze)
1748
1681
 
1749
1682
  # Creates a SQL pattern match exprssion. left (l) is the SQL string we
1750
1683
  # are matching against, and ces are the patterns we are matching.
1751
1684
  # The match succeeds if any of the patterns match (SQL OR).
1752
1685
  #
1753
1686
  # If a regular expression is used as a pattern, an SQL regular expression will be
1754
- # used, which is currently only supported on MySQL and PostgreSQL. Be aware
1755
- # that MySQL and PostgreSQL regular expression syntax is similar to ruby
1687
+ # used, which is currently only supported on some databases. Be aware
1688
+ # that SQL regular expression syntax is similar to ruby
1756
1689
  # regular expression syntax, but it not exactly the same, especially for
1757
1690
  # advanced regular expression features. Sequel just uses the source of the
1758
1691
  # ruby regular expression verbatim as the SQL regular expression string.
@@ -1765,9 +1698,9 @@ module Sequel
1765
1698
  # if a case insensitive regular expression is used (//i), that particular
1766
1699
  # pattern which will always be case insensitive.
1767
1700
  #
1768
- # StringExpression.like(:a, 'a%') # "a" LIKE 'a%' ESCAPE '\'
1769
- # StringExpression.like(:a, 'a%', :case_insensitive=>true) # "a" ILIKE 'a%' ESCAPE '\'
1770
- # StringExpression.like(:a, 'a%', /^a/i) # "a" LIKE 'a%' ESCAPE '\' OR "a" ~* '^a'
1701
+ # StringExpression.like(:a, 'a%') # ("a" LIKE 'a%' ESCAPE '\')
1702
+ # StringExpression.like(:a, 'a%', case_insensitive: true) # ("a" ILIKE 'a%' ESCAPE '\')
1703
+ # StringExpression.like(:a, 'a%', /^a/i) # (("a" LIKE 'a%' ESCAPE '\') OR ("a" ~* '^a'))
1771
1704
  def self.like(l, *ces)
1772
1705
  l, lre, lci = like_element(l)
1773
1706
  lci = (ces.last.is_a?(Hash) ? ces.pop : {})[:case_insensitive] ? true : lci
@@ -1800,14 +1733,15 @@ module Sequel
1800
1733
  # Represents an SQL array access, with multiple possible arguments.
1801
1734
  class Subscript < GenericExpression
1802
1735
  # The SQL array column
1803
- attr_reader :f
1736
+ attr_reader :expression
1737
+ alias f expression
1804
1738
 
1805
1739
  # The array of subscripts to use (should be an array of numbers)
1806
1740
  attr_reader :sub
1807
1741
 
1808
1742
  # Set the array column and subscripts to the given arguments
1809
- def initialize(f, sub)
1810
- @f = f
1743
+ def initialize(expression, sub)
1744
+ @expression = expression
1811
1745
  @sub = sub
1812
1746
  freeze
1813
1747
  end
@@ -1815,17 +1749,17 @@ module Sequel
1815
1749
  # Create a new +Subscript+ appending the given subscript(s)
1816
1750
  # to the current array of subscripts.
1817
1751
  #
1818
- # :a.sql_subscript(2) # a[2]
1819
- # :a.sql_subscript(2) | 1 # a[2, 1]
1752
+ # Sequel[:a].sql_subscript(2) # a[2]
1753
+ # Sequel[:a].sql_subscript(2) | 1 # a[2, 1]
1820
1754
  def |(sub)
1821
- Subscript.new(@f, @sub + Array(sub))
1755
+ Subscript.new(@expression, @sub + Array(sub))
1822
1756
  end
1823
1757
 
1824
1758
  # Create a new +Subscript+ by accessing a subarray of a multidimensional
1825
1759
  # array.
1826
1760
  #
1827
- # :a.sql_subscript(2) # a[2]
1828
- # :a.sql_subscript(2)[1] # a[2][1]
1761
+ # Sequel[:a].sql_subscript(2) # a[2]
1762
+ # Sequel[:a].sql_subscript(2)[1] # a[2][1]
1829
1763
  def [](sub)
1830
1764
  Subscript.new(self, Array(sub))
1831
1765
  end
@@ -1843,38 +1777,24 @@ module Sequel
1843
1777
  end
1844
1778
  end
1845
1779
 
1846
- # The purpose of the +VirtualRow+ class is to allow the easy creation of SQL identifiers and functions
1847
- # without relying on methods defined on +Symbol+. This is useful if another library defines
1848
- # the methods defined by Sequel, if you are running on ruby 1.9, or if you are not using the
1849
- # core extensions.
1780
+ # The purpose of the +VirtualRow+ class is to allow the easy creation of SQL identifiers and functions,
1781
+ # in a way that leads to more compact code.
1850
1782
  #
1851
1783
  # An instance of this class is yielded to the block supplied to <tt>Dataset#where</tt>, <tt>Dataset#order</tt>, and <tt>Dataset#select</tt>
1852
1784
  # (and the other methods that accept a block and pass it to one of those methods).
1853
1785
  # If the block doesn't take an argument, the block is instance_execed in the context of
1854
1786
  # an instance of this class.
1855
1787
  #
1856
- # +VirtualRow+ uses +method_missing+ to return either an +Identifier+, +QualifiedIdentifier+, or +Function+
1788
+ # +VirtualRow+ uses +method_missing+ to return either an +Identifier+, +Function+
1857
1789
  # depending on how it is called.
1858
1790
  #
1859
- # If a block is _not_ given, creates one of the following objects:
1860
- #
1861
1791
  # +Function+ :: Returned if any arguments are supplied, using the method name
1862
1792
  # as the function name, and the arguments as the function arguments.
1863
- # +QualifiedIdentifier+ :: Returned if the method name contains __, with the
1864
- # table being the part before __, and the column being the part after.
1865
1793
  # +Identifier+ :: Returned otherwise, using the method name.
1866
1794
  #
1867
- # If a block is given, it returns a +Function+. Note that the block is currently not called by the code, though
1868
- # this may change in a future version. If the first argument is:
1869
- #
1870
- # no arguments given :: creates a +Function+ with no arguments.
1871
- # :* :: creates a +Function+ with a literal wildcard argument (*), mostly useful for COUNT.
1872
- # :distinct :: creates a +Function+ that prepends DISTINCT to the rest of the arguments, mostly
1873
- # useful for aggregate functions.
1874
- # :over :: creates a +Function+ with a window. If a second argument is provided, it should be a hash
1875
- # of options which are used to create the +Window+ (with possible keys :window, :partition, :order, and :frame). The
1876
- # arguments to the function itself should be specified as <tt>:*=>true</tt> for a wildcard, or via
1877
- # the <tt>:args</tt> option.
1795
+ # If splitting symbols has been enabled (not the default), then method calls without
1796
+ # arguments will return +QualifiedIdentifier+ instances if the method call includes a
1797
+ # double underscore.
1878
1798
  #
1879
1799
  # Examples:
1880
1800
  #
@@ -1883,22 +1803,14 @@ module Sequel
1883
1803
  # # Argument yielded to block
1884
1804
  # ds.where{|r| r.name < 2} # SELECT * FROM t WHERE (name < 2)
1885
1805
  #
1886
- # # Block without argument (instance_eval)
1806
+ # # Block without argument (instance_exec)
1887
1807
  # ds.where{name < 2} # SELECT * FROM t WHERE (name < 2)
1888
1808
  #
1889
- # # Qualified identifiers
1890
- # ds.where{table__column + 1 < 2} # SELECT * FROM t WHERE ((table.column + 1) < 2)
1891
- #
1892
1809
  # # Functions
1893
1810
  # ds.where{is_active(1, 'arg2')} # SELECT * FROM t WHERE is_active(1, 'arg2')
1894
- # ds.select{version{}} # SELECT version() FROM t
1895
- # ds.select{count(:*){}} # SELECT count(*) FROM t
1896
- # ds.select{count(:distinct, col1){}} # SELECT count(DISTINCT col1) FROM t
1897
- #
1898
- # # Window Functions
1899
- # ds.select{rank(:over){}} # SELECT rank() OVER () FROM t
1900
- # ds.select{count(:over, :*=>true){}} # SELECT count(*) OVER () FROM t
1901
- # ds.select{sum(:over, :args=>col1, :partition=>col2, :order=>col3){}} # SELECT sum(col1) OVER (PARTITION BY col2 ORDER BY col3) FROM t
1811
+ # ds.select{version.function} # SELECT version() FROM t
1812
+ # ds.select{count.function.*} # SELECT count(*) FROM t
1813
+ # ds.select{count(col1).distinct} # SELECT count(DISTINCT col1) FROM t
1902
1814
  #
1903
1815
  # # Math Operators
1904
1816
  # ds.select{|o| o.+(1, :a).as(:b)} # SELECT (1 + a) AS b FROM t
@@ -1907,10 +1819,10 @@ module Sequel
1907
1819
  # ds.select{|o| o./(4, :a).as(:b)} # SELECT (4 / a) AS b FROM t
1908
1820
  #
1909
1821
  # # Boolean Operators
1910
- # ds.where{|o| o.&({:a=>1}, :b)} # SELECT * FROM t WHERE ((a = 1) AND b)
1911
- # ds.where{|o| o.|({:a=>1}, :b)} # SELECT * FROM t WHERE ((a = 1) OR b)
1912
- # ds.where{|o| o.~({:a=>1})} # SELECT * FROM t WHERE (a != 1)
1913
- # ds.where{|o| o.~({:a=>1, :b=>2})} # SELECT * FROM t WHERE ((a != 1) OR (b != 2))
1822
+ # ds.where{|o| o.&({a: 1}, :b)} # SELECT * FROM t WHERE ((a = 1) AND b)
1823
+ # ds.where{|o| o.|({a: 1}, :b)} # SELECT * FROM t WHERE ((a = 1) OR b)
1824
+ # ds.where{|o| o.~(a: 1)} # SELECT * FROM t WHERE (a != 1)
1825
+ # ds.where{|o| o.~(a: 1, b: 2)} # SELECT * FROM t WHERE ((a != 1) OR (b != 2))
1914
1826
  #
1915
1827
  # # Inequality Operators
1916
1828
  # ds.where{|o| o.>(1, :a)} # SELECT * FROM t WHERE (1 > a)
@@ -1918,16 +1830,8 @@ module Sequel
1918
1830
  # ds.where{|o| o.>=(3, :a)} # SELECT * FROM t WHERE (3 >= a)
1919
1831
  # ds.where{|o| o.<=(4, :a)} # SELECT * FROM t WHERE (4 <= a)
1920
1832
  #
1921
- # # Literal Strings
1922
- # ds.where{{a=>`some SQL`}} # SELECT * FROM t WHERE (a = some SQL)
1923
- #
1924
1833
  # For a more detailed explanation, see the {Virtual Rows guide}[rdoc-ref:doc/virtual_rows.rdoc].
1925
1834
  class VirtualRow < BasicObject
1926
- QUESTION_MARK = LiteralString.new('?').freeze
1927
- Sequel::Deprecation.deprecate_constant(self, :QUESTION_MARK)
1928
- DOUBLE_UNDERSCORE = '__'.freeze
1929
- Sequel::Deprecation.deprecate_constant(self, :DOUBLE_UNDERSCORE)
1930
-
1931
1835
  include OperatorBuilders
1932
1836
 
1933
1837
  %w'> < >= <='.each do |op|
@@ -1942,49 +1846,14 @@ module Sequel
1942
1846
  freeze
1943
1847
  end
1944
1848
 
1945
- # Return a literal string created with the given string.
1946
- def `(s)
1947
- Sequel::Deprecation.deprecate("Using Sequel#VirtualRow#` to create a literal SQL fragment", "Use Sequel.lit instead")
1948
- Sequel::LiteralString.new(s)
1949
- end
1950
-
1951
1849
  include(Module.new do
1952
1850
  # Return an +Identifier+, +QualifiedIdentifier+, or +Function+, depending
1953
1851
  # on arguments and whether a block is provided. Does not currently call the block.
1954
1852
  # See the class level documentation.
1955
- def method_missing(m, *args, &block)
1956
- if block
1957
- if args.empty?
1958
- Sequel::Deprecation.deprecate("Passing a block to a virtual row method to create a Sequel::SQL::Function", "Replace the block with a call to .function to create a function, or use the virtual_row_method_block extension")
1959
- Function.new(m)
1960
- else
1961
- case args.shift
1962
- when :*
1963
- Sequel::Deprecation.deprecate("Passing a block to a virtual row method with a :* argument to create a Sequel::SQL::Function", "Remove the :* argument and block and a call to .function.* to create a function(*) call, or use the virtual_row_method_block extension")
1964
- Function.new(m, *args).*
1965
- when :distinct
1966
- Sequel::Deprecation.deprecate("Passing a block to a virtual row method with a :distinct argument to create a Sequel::SQL::Function", "Remove the :distinct argument and block with a call to .function.distinct to create a function(DISTINCT ...) call, or use the virtual_row_method_block extension")
1967
- Function.new(m, *args).distinct
1968
- when :over
1969
- opts = args.shift || OPTS
1970
- f = Function.new(m, *::Kernel.Array(opts[:args]))
1971
- if opts[:*]
1972
- Sequel::Deprecation.deprecate("Passing a block to a virtual row method with a :over argument and :* option to create a Sequel::SQL::WindowFunction", "Remove the :over argument, :* option and block with a call to .function.*.over with the options to create a function(*) OVER (...) call, or use the virtual_row_method_block extension")
1973
- f = f.*
1974
- else
1975
- Sequel::Deprecation.deprecate("Passing a block to a virtual row method with a :over argument to create a Sequel::SQL::WindowFunction", "Remove the :over argument and block with a call to .function.over with the options to create a function(...) OVER (...) call, or use the virtual_row_method_block extension")
1976
- end
1977
- f.over(opts)
1978
- else
1979
- Kernel.raise(Error, 'unsupported VirtualRow method argument used with block')
1980
- end
1981
- end
1982
- elsif args.empty?
1983
- if split = Sequel.split_symbols?
1853
+ def method_missing(m, *args)
1854
+ if args.empty?
1855
+ if Sequel.split_symbols?
1984
1856
  table, column = m.to_s.split('__', 2)
1985
- if column && split == :deprecated
1986
- Sequel::Deprecation.deprecate("Splitting virtual row method names", "Either set Sequel.split_symbols = true, or change #{m.inspect} to #{table}[:#{column}]")
1987
- end
1988
1857
  column ? QualifiedIdentifier.new(table, column) : Identifier.new(m)
1989
1858
  else
1990
1859
  Identifier.new(m)