sequel 4.49.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (477) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +70 -0
  3. data/README.rdoc +195 -136
  4. data/Rakefile +26 -42
  5. data/bin/sequel +3 -5
  6. data/doc/advanced_associations.rdoc +86 -163
  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/schema_modification.rdoc +63 -60
  29. data/doc/security.rdoc +97 -88
  30. data/doc/sharding.rdoc +43 -30
  31. data/doc/sql.rdoc +53 -65
  32. data/doc/testing.rdoc +3 -5
  33. data/doc/thread_safety.rdoc +2 -4
  34. data/doc/transactions.rdoc +18 -17
  35. data/doc/validations.rdoc +48 -45
  36. data/doc/virtual_rows.rdoc +87 -115
  37. data/lib/sequel.rb +1 -1
  38. data/lib/sequel/adapters/ado.rb +9 -25
  39. data/lib/sequel/adapters/ado/access.rb +7 -13
  40. data/lib/sequel/adapters/ado/mssql.rb +2 -9
  41. data/lib/sequel/adapters/amalgalite.rb +3 -18
  42. data/lib/sequel/adapters/ibmdb.rb +9 -45
  43. data/lib/sequel/adapters/jdbc.rb +13 -73
  44. data/lib/sequel/adapters/jdbc/db2.rb +8 -37
  45. data/lib/sequel/adapters/jdbc/derby.rb +4 -50
  46. data/lib/sequel/adapters/jdbc/h2.rb +4 -25
  47. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -26
  48. data/lib/sequel/adapters/jdbc/jtds.rb +2 -9
  49. data/lib/sequel/adapters/jdbc/mssql.rb +1 -11
  50. data/lib/sequel/adapters/jdbc/mysql.rb +1 -15
  51. data/lib/sequel/adapters/jdbc/oracle.rb +4 -26
  52. data/lib/sequel/adapters/jdbc/postgresql.rb +2 -31
  53. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +4 -17
  54. data/lib/sequel/adapters/jdbc/sqlite.rb +1 -7
  55. data/lib/sequel/adapters/jdbc/sqlserver.rb +1 -13
  56. data/lib/sequel/adapters/jdbc/transactions.rb +1 -14
  57. data/lib/sequel/adapters/mock.rb +4 -30
  58. data/lib/sequel/adapters/mysql.rb +7 -44
  59. data/lib/sequel/adapters/mysql2.rb +5 -23
  60. data/lib/sequel/adapters/odbc.rb +0 -19
  61. data/lib/sequel/adapters/odbc/db2.rb +1 -1
  62. data/lib/sequel/adapters/odbc/mssql.rb +4 -12
  63. data/lib/sequel/adapters/odbc/oracle.rb +1 -1
  64. data/lib/sequel/adapters/oracle.rb +7 -13
  65. data/lib/sequel/adapters/postgres.rb +13 -57
  66. data/lib/sequel/adapters/postgresql.rb +1 -1
  67. data/lib/sequel/adapters/shared/access.rb +11 -51
  68. data/lib/sequel/adapters/shared/db2.rb +3 -61
  69. data/lib/sequel/adapters/shared/mssql.rb +21 -157
  70. data/lib/sequel/adapters/shared/mysql.rb +23 -224
  71. data/lib/sequel/adapters/shared/oracle.rb +13 -41
  72. data/lib/sequel/adapters/shared/postgres.rb +44 -259
  73. data/lib/sequel/adapters/shared/sqlanywhere.rb +4 -96
  74. data/lib/sequel/adapters/shared/sqlite.rb +12 -101
  75. data/lib/sequel/adapters/sqlanywhere.rb +4 -23
  76. data/lib/sequel/adapters/sqlite.rb +2 -19
  77. data/lib/sequel/adapters/tinytds.rb +5 -15
  78. data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +1 -1
  79. data/lib/sequel/adapters/utils/mysql_mysql2.rb +2 -4
  80. data/lib/sequel/adapters/utils/mysql_prepared_statements.rb +3 -6
  81. data/lib/sequel/adapters/utils/replace.rb +0 -5
  82. data/lib/sequel/adapters/utils/stored_procedures.rb +0 -2
  83. data/lib/sequel/adapters/utils/unmodified_identifiers.rb +2 -0
  84. data/lib/sequel/ast_transformer.rb +3 -94
  85. data/lib/sequel/connection_pool.rb +26 -28
  86. data/lib/sequel/connection_pool/sharded_single.rb +1 -4
  87. data/lib/sequel/connection_pool/sharded_threaded.rb +97 -95
  88. data/lib/sequel/connection_pool/single.rb +0 -2
  89. data/lib/sequel/connection_pool/threaded.rb +94 -110
  90. data/lib/sequel/core.rb +42 -101
  91. data/lib/sequel/database.rb +12 -2
  92. data/lib/sequel/database/connecting.rb +23 -60
  93. data/lib/sequel/database/dataset.rb +6 -9
  94. data/lib/sequel/database/dataset_defaults.rb +4 -48
  95. data/lib/sequel/database/features.rb +5 -4
  96. data/lib/sequel/database/logging.rb +2 -9
  97. data/lib/sequel/database/misc.rb +23 -55
  98. data/lib/sequel/database/query.rb +8 -13
  99. data/lib/sequel/database/schema_generator.rb +89 -64
  100. data/lib/sequel/database/schema_methods.rb +61 -79
  101. data/lib/sequel/database/transactions.rb +4 -24
  102. data/lib/sequel/dataset.rb +18 -10
  103. data/lib/sequel/dataset/actions.rb +53 -107
  104. data/lib/sequel/dataset/dataset_module.rb +3 -15
  105. data/lib/sequel/dataset/features.rb +30 -30
  106. data/lib/sequel/dataset/graph.rb +40 -49
  107. data/lib/sequel/dataset/misc.rb +12 -37
  108. data/lib/sequel/dataset/placeholder_literalizer.rb +4 -4
  109. data/lib/sequel/dataset/prepared_statements.rb +23 -51
  110. data/lib/sequel/dataset/query.rb +71 -155
  111. data/lib/sequel/dataset/sql.rb +30 -225
  112. data/lib/sequel/deprecated.rb +18 -27
  113. data/lib/sequel/exceptions.rb +1 -17
  114. data/lib/sequel/extensions/_model_pg_row.rb +0 -7
  115. data/lib/sequel/extensions/_pretty_table.rb +1 -3
  116. data/lib/sequel/extensions/arbitrary_servers.rb +10 -10
  117. data/lib/sequel/extensions/connection_expiration.rb +1 -1
  118. data/lib/sequel/extensions/connection_validator.rb +1 -1
  119. data/lib/sequel/extensions/constraint_validations.rb +11 -11
  120. data/lib/sequel/extensions/core_extensions.rb +39 -49
  121. data/lib/sequel/extensions/core_refinements.rb +39 -45
  122. data/lib/sequel/extensions/current_datetime_timestamp.rb +0 -4
  123. data/lib/sequel/extensions/date_arithmetic.rb +7 -7
  124. data/lib/sequel/extensions/duplicate_columns_handler.rb +12 -9
  125. data/lib/sequel/extensions/empty_array_consider_nulls.rb +2 -2
  126. data/lib/sequel/extensions/eval_inspect.rb +4 -11
  127. data/lib/sequel/extensions/freeze_datasets.rb +1 -69
  128. data/lib/sequel/extensions/from_block.rb +1 -35
  129. data/lib/sequel/extensions/graph_each.rb +2 -2
  130. data/lib/sequel/extensions/identifier_mangling.rb +9 -19
  131. data/lib/sequel/extensions/implicit_subquery.rb +2 -2
  132. data/lib/sequel/extensions/inflector.rb +4 -4
  133. data/lib/sequel/extensions/migration.rb +23 -40
  134. data/lib/sequel/extensions/no_auto_literal_strings.rb +2 -84
  135. data/lib/sequel/extensions/null_dataset.rb +2 -8
  136. data/lib/sequel/extensions/pagination.rb +1 -17
  137. data/lib/sequel/extensions/pg_array.rb +20 -189
  138. data/lib/sequel/extensions/pg_hstore.rb +11 -50
  139. data/lib/sequel/extensions/pg_hstore_ops.rb +2 -2
  140. data/lib/sequel/extensions/pg_inet.rb +2 -15
  141. data/lib/sequel/extensions/pg_interval.rb +1 -20
  142. data/lib/sequel/extensions/pg_json.rb +7 -27
  143. data/lib/sequel/extensions/pg_loose_count.rb +1 -1
  144. data/lib/sequel/extensions/pg_range.rb +6 -121
  145. data/lib/sequel/extensions/pg_range_ops.rb +1 -3
  146. data/lib/sequel/extensions/pg_row.rb +5 -77
  147. data/lib/sequel/extensions/pg_row_ops.rb +2 -13
  148. data/lib/sequel/extensions/query.rb +3 -4
  149. data/lib/sequel/extensions/round_timestamps.rb +0 -6
  150. data/lib/sequel/extensions/schema_dumper.rb +13 -13
  151. data/lib/sequel/extensions/select_remove.rb +3 -3
  152. data/lib/sequel/extensions/split_array_nil.rb +2 -2
  153. data/lib/sequel/extensions/sql_comments.rb +2 -2
  154. data/lib/sequel/extensions/string_agg.rb +11 -8
  155. data/lib/sequel/extensions/symbol_aref.rb +6 -20
  156. data/lib/sequel/model.rb +27 -62
  157. data/lib/sequel/model/associations.rb +128 -131
  158. data/lib/sequel/model/base.rb +171 -711
  159. data/lib/sequel/model/default_inflections.rb +1 -1
  160. data/lib/sequel/model/errors.rb +0 -3
  161. data/lib/sequel/model/exceptions.rb +2 -6
  162. data/lib/sequel/model/inflections.rb +1 -26
  163. data/lib/sequel/model/plugins.rb +1 -0
  164. data/lib/sequel/plugins/active_model.rb +2 -5
  165. data/lib/sequel/plugins/association_dependencies.rb +15 -15
  166. data/lib/sequel/plugins/association_pks.rb +14 -28
  167. data/lib/sequel/plugins/association_proxies.rb +6 -7
  168. data/lib/sequel/plugins/auto_validations.rb +4 -4
  169. data/lib/sequel/plugins/before_after_save.rb +0 -43
  170. data/lib/sequel/plugins/blacklist_security.rb +9 -8
  171. data/lib/sequel/plugins/boolean_readers.rb +3 -3
  172. data/lib/sequel/plugins/boolean_subsets.rb +2 -2
  173. data/lib/sequel/plugins/caching.rb +5 -5
  174. data/lib/sequel/plugins/class_table_inheritance.rb +71 -102
  175. data/lib/sequel/plugins/column_conflicts.rb +2 -2
  176. data/lib/sequel/plugins/column_select.rb +2 -2
  177. data/lib/sequel/plugins/composition.rb +15 -24
  178. data/lib/sequel/plugins/constraint_validations.rb +4 -3
  179. data/lib/sequel/plugins/csv_serializer.rb +13 -20
  180. data/lib/sequel/plugins/dataset_associations.rb +2 -2
  181. data/lib/sequel/plugins/def_dataset_method.rb +5 -5
  182. data/lib/sequel/plugins/defaults_setter.rb +1 -1
  183. data/lib/sequel/plugins/delay_add_association.rb +1 -1
  184. data/lib/sequel/plugins/finder.rb +16 -10
  185. data/lib/sequel/plugins/force_encoding.rb +1 -7
  186. data/lib/sequel/plugins/hook_class_methods.rb +4 -106
  187. data/lib/sequel/plugins/input_transformer.rb +10 -11
  188. data/lib/sequel/plugins/insert_returning_select.rb +1 -9
  189. data/lib/sequel/plugins/instance_filters.rb +5 -5
  190. data/lib/sequel/plugins/instance_hooks.rb +7 -52
  191. data/lib/sequel/plugins/inverted_subsets.rb +3 -1
  192. data/lib/sequel/plugins/json_serializer.rb +19 -19
  193. data/lib/sequel/plugins/lazy_attributes.rb +1 -10
  194. data/lib/sequel/plugins/list.rb +6 -6
  195. data/lib/sequel/plugins/many_through_many.rb +11 -8
  196. data/lib/sequel/plugins/mssql_optimistic_locking.rb +3 -3
  197. data/lib/sequel/plugins/nested_attributes.rb +18 -31
  198. data/lib/sequel/plugins/optimistic_locking.rb +3 -3
  199. data/lib/sequel/plugins/pg_array_associations.rb +8 -2
  200. data/lib/sequel/plugins/pg_row.rb +2 -11
  201. data/lib/sequel/plugins/prepared_statements.rb +13 -66
  202. data/lib/sequel/plugins/prepared_statements_safe.rb +1 -1
  203. data/lib/sequel/plugins/rcte_tree.rb +7 -7
  204. data/lib/sequel/plugins/serialization.rb +15 -33
  205. data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
  206. data/lib/sequel/plugins/sharding.rb +2 -8
  207. data/lib/sequel/plugins/single_table_inheritance.rb +10 -13
  208. data/lib/sequel/plugins/skip_create_refresh.rb +3 -3
  209. data/lib/sequel/plugins/static_cache.rb +8 -9
  210. data/lib/sequel/plugins/string_stripper.rb +3 -3
  211. data/lib/sequel/plugins/subclasses.rb +1 -1
  212. data/lib/sequel/plugins/subset_conditions.rb +2 -2
  213. data/lib/sequel/plugins/table_select.rb +2 -2
  214. data/lib/sequel/plugins/tactical_eager_loading.rb +4 -4
  215. data/lib/sequel/plugins/timestamps.rb +6 -7
  216. data/lib/sequel/plugins/touch.rb +4 -8
  217. data/lib/sequel/plugins/tree.rb +3 -3
  218. data/lib/sequel/plugins/typecast_on_load.rb +2 -2
  219. data/lib/sequel/plugins/unlimited_update.rb +1 -7
  220. data/lib/sequel/plugins/update_or_create.rb +3 -3
  221. data/lib/sequel/plugins/update_refresh.rb +3 -3
  222. data/lib/sequel/plugins/uuid.rb +7 -11
  223. data/lib/sequel/plugins/validation_class_methods.rb +10 -9
  224. data/lib/sequel/plugins/validation_contexts.rb +4 -4
  225. data/lib/sequel/plugins/validation_helpers.rb +26 -25
  226. data/lib/sequel/plugins/whitelist_security.rb +13 -9
  227. data/lib/sequel/plugins/xml_serializer.rb +24 -25
  228. data/lib/sequel/sql.rb +145 -276
  229. data/lib/sequel/timezones.rb +8 -22
  230. data/lib/sequel/version.rb +2 -2
  231. data/spec/adapter_spec.rb +1 -1
  232. data/spec/adapters/db2_spec.rb +2 -103
  233. data/spec/adapters/mssql_spec.rb +89 -68
  234. data/spec/adapters/mysql_spec.rb +101 -480
  235. data/spec/adapters/oracle_spec.rb +1 -9
  236. data/spec/adapters/postgres_spec.rb +312 -565
  237. data/spec/adapters/spec_helper.rb +12 -31
  238. data/spec/adapters/sqlanywhere_spec.rb +2 -77
  239. data/spec/adapters/sqlite_spec.rb +8 -146
  240. data/spec/bin_spec.rb +11 -16
  241. data/spec/core/connection_pool_spec.rb +173 -74
  242. data/spec/core/database_spec.rb +64 -244
  243. data/spec/core/dataset_spec.rb +81 -415
  244. data/spec/core/deprecated_spec.rb +3 -3
  245. data/spec/core/expression_filters_spec.rb +37 -144
  246. data/spec/core/mock_adapter_spec.rb +176 -4
  247. data/spec/core/object_graph_spec.rb +11 -60
  248. data/spec/core/placeholder_literalizer_spec.rb +1 -14
  249. data/spec/core/schema_generator_spec.rb +51 -40
  250. data/spec/core/schema_spec.rb +74 -77
  251. data/spec/core/spec_helper.rb +6 -24
  252. data/spec/core/version_spec.rb +1 -1
  253. data/spec/core_extensions_spec.rb +7 -83
  254. data/spec/core_model_spec.rb +2 -2
  255. data/spec/deprecation_helper.rb +2 -14
  256. data/spec/extensions/accessed_columns_spec.rb +1 -1
  257. data/spec/extensions/active_model_spec.rb +3 -3
  258. data/spec/extensions/after_initialize_spec.rb +1 -1
  259. data/spec/extensions/arbitrary_servers_spec.rb +2 -2
  260. data/spec/extensions/association_dependencies_spec.rb +1 -1
  261. data/spec/extensions/association_pks_spec.rb +4 -59
  262. data/spec/extensions/association_proxies_spec.rb +1 -1
  263. data/spec/extensions/auto_literal_strings_spec.rb +1 -12
  264. data/spec/extensions/auto_validations_spec.rb +1 -1
  265. data/spec/extensions/blacklist_security_spec.rb +1 -1
  266. data/spec/extensions/blank_spec.rb +1 -1
  267. data/spec/extensions/boolean_readers_spec.rb +1 -1
  268. data/spec/extensions/boolean_subsets_spec.rb +1 -1
  269. data/spec/extensions/caching_spec.rb +1 -1
  270. data/spec/extensions/class_table_inheritance_spec.rb +35 -1086
  271. data/spec/extensions/column_conflicts_spec.rb +1 -1
  272. data/spec/extensions/column_select_spec.rb +4 -4
  273. data/spec/extensions/columns_introspection_spec.rb +1 -1
  274. data/spec/extensions/columns_updated_spec.rb +1 -1
  275. data/spec/extensions/composition_spec.rb +1 -7
  276. data/spec/extensions/connection_expiration_spec.rb +3 -3
  277. data/spec/extensions/connection_validator_spec.rb +3 -3
  278. data/spec/extensions/constraint_validations_plugin_spec.rb +1 -1
  279. data/spec/extensions/constraint_validations_spec.rb +1 -1
  280. data/spec/extensions/core_refinements_spec.rb +1 -3
  281. data/spec/extensions/csv_serializer_spec.rb +4 -9
  282. data/spec/extensions/current_datetime_timestamp_spec.rb +1 -1
  283. data/spec/extensions/dataset_associations_spec.rb +2 -1
  284. data/spec/extensions/dataset_source_alias_spec.rb +1 -1
  285. data/spec/extensions/date_arithmetic_spec.rb +3 -3
  286. data/spec/extensions/def_dataset_method_spec.rb +1 -1
  287. data/spec/extensions/defaults_setter_spec.rb +2 -2
  288. data/spec/extensions/delay_add_association_spec.rb +8 -9
  289. data/spec/extensions/dirty_spec.rb +1 -1
  290. data/spec/extensions/duplicate_columns_handler_spec.rb +1 -1
  291. data/spec/extensions/eager_each_spec.rb +2 -2
  292. data/spec/extensions/empty_array_consider_nulls_spec.rb +1 -1
  293. data/spec/extensions/error_splitter_spec.rb +1 -1
  294. data/spec/extensions/error_sql_spec.rb +1 -1
  295. data/spec/extensions/eval_inspect_spec.rb +1 -1
  296. data/spec/extensions/finder_spec.rb +1 -1
  297. data/spec/extensions/force_encoding_spec.rb +2 -5
  298. data/spec/extensions/freeze_datasets_spec.rb +1 -1
  299. data/spec/extensions/graph_each_spec.rb +5 -5
  300. data/spec/extensions/hook_class_methods_spec.rb +1 -194
  301. data/spec/extensions/identifier_mangling_spec.rb +17 -170
  302. data/spec/extensions/implicit_subquery_spec.rb +1 -5
  303. data/spec/extensions/inflector_spec.rb +1 -1
  304. data/spec/extensions/input_transformer_spec.rb +7 -2
  305. data/spec/extensions/insert_returning_select_spec.rb +1 -1
  306. data/spec/extensions/instance_filters_spec.rb +1 -1
  307. data/spec/extensions/instance_hooks_spec.rb +1 -95
  308. data/spec/extensions/inverted_subsets_spec.rb +1 -1
  309. data/spec/extensions/json_serializer_spec.rb +1 -1
  310. data/spec/extensions/lazy_attributes_spec.rb +1 -7
  311. data/spec/extensions/list_spec.rb +1 -1
  312. data/spec/extensions/looser_typecasting_spec.rb +1 -1
  313. data/spec/extensions/many_through_many_spec.rb +1 -1
  314. data/spec/extensions/migration_spec.rb +2 -2
  315. data/spec/extensions/modification_detection_spec.rb +1 -1
  316. data/spec/extensions/mssql_optimistic_locking_spec.rb +1 -1
  317. data/spec/extensions/named_timezones_spec.rb +3 -3
  318. data/spec/extensions/nested_attributes_spec.rb +1 -29
  319. data/spec/extensions/null_dataset_spec.rb +1 -11
  320. data/spec/extensions/optimistic_locking_spec.rb +1 -1
  321. data/spec/extensions/pagination_spec.rb +1 -1
  322. data/spec/extensions/pg_array_associations_spec.rb +4 -1
  323. data/spec/extensions/pg_array_ops_spec.rb +1 -1
  324. data/spec/extensions/pg_array_spec.rb +3 -48
  325. data/spec/extensions/pg_enum_spec.rb +1 -1
  326. data/spec/extensions/pg_hstore_ops_spec.rb +1 -1
  327. data/spec/extensions/pg_hstore_spec.rb +23 -32
  328. data/spec/extensions/pg_inet_ops_spec.rb +1 -1
  329. data/spec/extensions/pg_inet_spec.rb +1 -14
  330. data/spec/extensions/pg_interval_spec.rb +3 -13
  331. data/spec/extensions/pg_json_ops_spec.rb +1 -1
  332. data/spec/extensions/pg_json_spec.rb +1 -13
  333. data/spec/extensions/pg_loose_count_spec.rb +1 -1
  334. data/spec/extensions/pg_range_ops_spec.rb +1 -1
  335. data/spec/extensions/pg_range_spec.rb +3 -88
  336. data/spec/extensions/pg_row_ops_spec.rb +1 -1
  337. data/spec/extensions/pg_row_plugin_spec.rb +1 -1
  338. data/spec/extensions/pg_row_spec.rb +1 -44
  339. data/spec/extensions/pg_static_cache_updater_spec.rb +1 -1
  340. data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
  341. data/spec/extensions/prepared_statements_spec.rb +13 -48
  342. data/spec/extensions/pretty_table_spec.rb +1 -1
  343. data/spec/extensions/query_spec.rb +1 -12
  344. data/spec/extensions/rcte_tree_spec.rb +1 -1
  345. data/spec/extensions/round_timestamps_spec.rb +1 -5
  346. data/spec/extensions/s_spec.rb +1 -1
  347. data/spec/extensions/schema_caching_spec.rb +1 -1
  348. data/spec/extensions/schema_dumper_spec.rb +1 -1
  349. data/spec/extensions/select_remove_spec.rb +1 -1
  350. data/spec/extensions/sequel_4_dataset_methods_spec.rb +1 -1
  351. data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
  352. data/spec/extensions/serialization_spec.rb +2 -14
  353. data/spec/extensions/server_block_spec.rb +1 -1
  354. data/spec/extensions/server_logging_spec.rb +2 -2
  355. data/spec/extensions/sharding_spec.rb +1 -1
  356. data/spec/extensions/shared_caching_spec.rb +1 -28
  357. data/spec/extensions/single_table_inheritance_spec.rb +2 -5
  358. data/spec/extensions/singular_table_names_spec.rb +1 -1
  359. data/spec/extensions/skip_create_refresh_spec.rb +1 -1
  360. data/spec/extensions/spec_helper.rb +5 -27
  361. data/spec/extensions/split_array_nil_spec.rb +1 -1
  362. data/spec/extensions/split_values_spec.rb +1 -1
  363. data/spec/extensions/sql_comments_spec.rb +1 -1
  364. data/spec/extensions/sql_expr_spec.rb +1 -1
  365. data/spec/extensions/static_cache_spec.rb +1 -1
  366. data/spec/extensions/string_agg_spec.rb +2 -2
  367. data/spec/extensions/string_date_time_spec.rb +1 -1
  368. data/spec/extensions/string_stripper_spec.rb +1 -1
  369. data/spec/extensions/subclasses_spec.rb +1 -1
  370. data/spec/extensions/subset_conditions_spec.rb +1 -1
  371. data/spec/extensions/symbol_aref_refinement_spec.rb +1 -1
  372. data/spec/extensions/symbol_as_refinement_spec.rb +1 -1
  373. data/spec/extensions/table_select_spec.rb +4 -4
  374. data/spec/extensions/tactical_eager_loading_spec.rb +1 -6
  375. data/spec/extensions/thread_local_timezones_spec.rb +1 -1
  376. data/spec/extensions/timestamps_spec.rb +3 -3
  377. data/spec/extensions/to_dot_spec.rb +1 -1
  378. data/spec/extensions/touch_spec.rb +1 -1
  379. data/spec/extensions/tree_spec.rb +1 -1
  380. data/spec/extensions/typecast_on_load_spec.rb +1 -1
  381. data/spec/extensions/unlimited_update_spec.rb +1 -1
  382. data/spec/extensions/update_or_create_spec.rb +1 -1
  383. data/spec/extensions/update_primary_key_spec.rb +4 -3
  384. data/spec/extensions/update_refresh_spec.rb +1 -1
  385. data/spec/extensions/uuid_spec.rb +10 -12
  386. data/spec/extensions/validate_associated_spec.rb +1 -1
  387. data/spec/extensions/validation_class_methods_spec.rb +3 -3
  388. data/spec/extensions/validation_contexts_spec.rb +1 -1
  389. data/spec/extensions/validation_helpers_spec.rb +10 -44
  390. data/spec/extensions/whitelist_security_spec.rb +5 -5
  391. data/spec/extensions/xml_serializer_spec.rb +3 -3
  392. data/spec/guards_helper.rb +2 -1
  393. data/spec/integration/associations_test.rb +1 -23
  394. data/spec/integration/database_test.rb +7 -7
  395. data/spec/integration/dataset_test.rb +5 -47
  396. data/spec/integration/eager_loader_test.rb +1 -1
  397. data/spec/integration/migrator_test.rb +1 -1
  398. data/spec/integration/model_test.rb +4 -82
  399. data/spec/integration/plugin_test.rb +6 -22
  400. data/spec/integration/prepared_statement_test.rb +8 -88
  401. data/spec/integration/schema_test.rb +6 -6
  402. data/spec/integration/spec_helper.rb +13 -21
  403. data/spec/integration/timezone_test.rb +5 -5
  404. data/spec/integration/transaction_test.rb +3 -55
  405. data/spec/integration/type_test.rb +9 -9
  406. data/spec/model/association_reflection_spec.rb +24 -9
  407. data/spec/model/associations_spec.rb +124 -303
  408. data/spec/model/base_spec.rb +18 -137
  409. data/spec/model/class_dataset_methods_spec.rb +2 -20
  410. data/spec/model/dataset_methods_spec.rb +1 -20
  411. data/spec/model/eager_loading_spec.rb +17 -11
  412. data/spec/model/hooks_spec.rb +5 -300
  413. data/spec/model/inflector_spec.rb +1 -1
  414. data/spec/model/model_spec.rb +15 -320
  415. data/spec/model/plugins_spec.rb +2 -16
  416. data/spec/model/record_spec.rb +29 -121
  417. data/spec/model/spec_helper.rb +5 -15
  418. data/spec/model/validations_spec.rb +1 -1
  419. data/spec/sequel_warning.rb +1 -12
  420. metadata +8 -64
  421. data/doc/active_record.rdoc +0 -927
  422. data/lib/sequel/adapters/cubrid.rb +0 -160
  423. data/lib/sequel/adapters/do.rb +0 -166
  424. data/lib/sequel/adapters/do/mysql.rb +0 -69
  425. data/lib/sequel/adapters/do/postgres.rb +0 -46
  426. data/lib/sequel/adapters/do/sqlite3.rb +0 -41
  427. data/lib/sequel/adapters/jdbc/as400.rb +0 -92
  428. data/lib/sequel/adapters/jdbc/cubrid.rb +0 -65
  429. data/lib/sequel/adapters/jdbc/firebirdsql.rb +0 -37
  430. data/lib/sequel/adapters/jdbc/informix-sqli.rb +0 -34
  431. data/lib/sequel/adapters/jdbc/jdbcprogress.rb +0 -34
  432. data/lib/sequel/adapters/odbc/progress.rb +0 -12
  433. data/lib/sequel/adapters/shared/cubrid.rb +0 -245
  434. data/lib/sequel/adapters/shared/firebird.rb +0 -261
  435. data/lib/sequel/adapters/shared/informix.rb +0 -63
  436. data/lib/sequel/adapters/shared/progress.rb +0 -40
  437. data/lib/sequel/adapters/swift.rb +0 -169
  438. data/lib/sequel/adapters/swift/mysql.rb +0 -50
  439. data/lib/sequel/adapters/swift/postgres.rb +0 -49
  440. data/lib/sequel/adapters/swift/sqlite.rb +0 -48
  441. data/lib/sequel/adapters/utils/pg_types.rb +0 -4
  442. data/lib/sequel/dataset/mutation.rb +0 -98
  443. data/lib/sequel/extensions/_deprecated_identifier_mangling.rb +0 -117
  444. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +0 -8
  445. data/lib/sequel/extensions/filter_having.rb +0 -65
  446. data/lib/sequel/extensions/hash_aliases.rb +0 -51
  447. data/lib/sequel/extensions/meta_def.rb +0 -37
  448. data/lib/sequel/extensions/query_literals.rb +0 -86
  449. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +0 -26
  450. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +0 -133
  451. data/lib/sequel/extensions/set_overrides.rb +0 -82
  452. data/lib/sequel/no_core_ext.rb +0 -4
  453. data/lib/sequel/plugins/association_autoreloading.rb +0 -11
  454. data/lib/sequel/plugins/identifier_columns.rb +0 -49
  455. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +0 -11
  456. data/lib/sequel/plugins/pg_typecast_on_load.rb +0 -90
  457. data/lib/sequel/plugins/prepared_statements_associations.rb +0 -137
  458. data/lib/sequel/plugins/prepared_statements_with_pk.rb +0 -71
  459. data/lib/sequel/plugins/schema.rb +0 -84
  460. data/lib/sequel/plugins/scissors.rb +0 -37
  461. data/spec/core/dataset_mutation_spec.rb +0 -253
  462. data/spec/extensions/_deprecated_identifier_mangling_spec.rb +0 -314
  463. data/spec/extensions/before_after_save_spec.rb +0 -40
  464. data/spec/extensions/filter_having_spec.rb +0 -42
  465. data/spec/extensions/from_block_spec.rb +0 -21
  466. data/spec/extensions/hash_aliases_spec.rb +0 -26
  467. data/spec/extensions/identifier_columns_spec.rb +0 -19
  468. data/spec/extensions/meta_def_spec.rb +0 -35
  469. data/spec/extensions/no_auto_literal_strings_spec.rb +0 -69
  470. data/spec/extensions/pg_typecast_on_load_spec.rb +0 -70
  471. data/spec/extensions/prepared_statements_associations_spec.rb +0 -212
  472. data/spec/extensions/prepared_statements_with_pk_spec.rb +0 -40
  473. data/spec/extensions/query_literals_spec.rb +0 -185
  474. data/spec/extensions/schema_spec.rb +0 -123
  475. data/spec/extensions/scissors_spec.rb +0 -27
  476. data/spec/extensions/sequel_3_dataset_methods_spec.rb +0 -118
  477. data/spec/extensions/set_overrides_spec.rb +0 -75
@@ -1,11 +0,0 @@
1
- # frozen-string-literal: true
2
-
3
- Sequel::Deprecation.deprecate("The many_to_one_pk_lookup plugin", "This plugin was integrated into the default model behavior in Sequel 4.0, and no longer has an effect")
4
-
5
- module Sequel
6
- module Plugins
7
- # Empty plugin module for backwards compatibility
8
- module ManyToOnePkLookup
9
- end
10
- end
11
- end
@@ -1,90 +0,0 @@
1
- # frozen-string-literal: true
2
-
3
- Sequel::Deprecation.deprecate("The pg_typecast_on_load plugin", "This plugin is only useful on the deprecated do and switch adapters")
4
-
5
- module Sequel
6
- module Plugins
7
- # The PgTypecastOnLoad plugin exists because when you connect to PostgreSQL
8
- # using the do and swift adapters, Sequel doesn't have complete
9
- # control over typecasting, and may return columns as strings instead of how
10
- # the native postgres adapter would typecast them. This is mostly needed for
11
- # the additional support that the pg_* extensions add for advanced PostgreSQL
12
- # types such as arrays. This plugin is not needed if using the postgres or
13
- # jdbc/postgresql adapters.
14
- #
15
- # This plugin makes model loading to do the same conversion that the
16
- # native postgres adapter would do for all columns given. You can either
17
- # specify the columns to typecast on load in the plugin call itself, or
18
- # afterwards using add_pg_typecast_on_load_columns:
19
- #
20
- # # aliases => text[] column
21
- # # config => hstore column
22
- #
23
- # Album.plugin :pg_typecast_on_load, :aliases, :config
24
- # # or:
25
- # Album.plugin :pg_typecast_on_load
26
- # Album.add_pg_typecast_on_load_columns :aliases, :config
27
- #
28
- # This plugin only handles values that the adapter returns as strings. If
29
- # the adapter returns a value other than a string, this plugin will have no
30
- # effect. You may be able to use the regular typecast_on_load plugin to
31
- # handle those cases.
32
- module PgTypecastOnLoad
33
- # Call add_pg_typecast_on_load_columns on the passed column arguments.
34
- def self.configure(model, *columns)
35
- model.instance_eval do
36
- @pg_typecast_on_load_columns ||= []
37
- add_pg_typecast_on_load_columns(*columns)
38
- end
39
- end
40
-
41
- module ClassMethods
42
- # The columns to typecast on load for this model.
43
- attr_reader :pg_typecast_on_load_columns
44
-
45
- # Add additional columns to typecast on load for this model.
46
- def add_pg_typecast_on_load_columns(*columns)
47
- @pg_typecast_on_load_columns.concat(columns)
48
- end
49
-
50
- def call(values)
51
- super(load_typecast_pg(values))
52
- end
53
-
54
- # Freeze the typecast on load columns when freezing the model class.
55
- def freeze
56
- @pg_typecast_on_load_columns.freeze
57
-
58
- super
59
- end
60
-
61
- # Lookup the conversion proc for the column's oid in the Database
62
- # object, and use it to convert the value.
63
- def load_typecast_pg(values)
64
- pg_typecast_on_load_columns.each do |c|
65
- if (v = values[c]).is_a?(String) && (oid = db_schema[c][:oid]) && (pr = db.conversion_procs[oid])
66
- values[c] = pr.call(v)
67
- end
68
- end
69
- values
70
- end
71
-
72
- Plugins.inherited_instance_variables(self, :@pg_typecast_on_load_columns=>:dup)
73
- end
74
-
75
- module InstanceMethods
76
- private
77
-
78
- # Typecast specific columns using the conversion procs when manually refreshing.
79
- def _refresh_set_values(values)
80
- super(model.load_typecast_pg(values))
81
- end
82
-
83
- # Typecast specific columns using the conversion procs when refreshing after save.
84
- def _save_set_values(values)
85
- super(model.load_typecast_pg(values))
86
- end
87
- end
88
- end
89
- end
90
- end
@@ -1,137 +0,0 @@
1
- # frozen-string-literal: true
2
-
3
- Sequel::Deprecation.deprecate("The prepared_statements_associations plugin", "Stop using the plugin, it is probably unneeded and making the application slower")
4
-
5
- module Sequel
6
- module Plugins
7
- # The prepared_statements_associations plugin modifies the regular association
8
- # load method to use a cached prepared statement to load the associations.
9
- # It will not work on all associations, but it should skip the use of prepared
10
- # statements for associations where it will not work, assuming you load the
11
- # plugin before defining the associations.
12
- #
13
- # Note that in most cases, this plugin will probably make things slower,
14
- # so you should only use it if you really want to use prepared statements
15
- # to load associations.
16
- #
17
- # Usage:
18
- #
19
- # # Make all model subclasses more safe when using prepared statements (called before loading subclasses)
20
- # Sequel::Model.plugin :prepared_statements_associations
21
- #
22
- # # Make the Album class more safe when using prepared statements
23
- # Album.plugin :prepared_statements_associations
24
- module PreparedStatementsAssociations
25
- # Synchronize access to the integer sequence so that no two calls get the same integer.
26
- MUTEX = Mutex.new
27
-
28
- i = 0
29
- # This plugin names prepared statements uniquely using an integer sequence, this
30
- # lambda returns the next integer to use.
31
- NEXT = lambda{MUTEX.synchronize{i += 1}}
32
-
33
- module InstanceMethods
34
- private
35
-
36
- # Mark that associated objects should use the same server.
37
- def _associated_objects_use_same_server?
38
- return super if defined?(super)
39
- false
40
- end
41
-
42
- # Return a bound variable hash that maps the keys in +ks+ (qualified by the +table+)
43
- # to the values of the results of sending the methods in +vs+.
44
- def association_bound_variable_hash(table, ks, vs)
45
- Hash[*ks.zip(vs).map{|k, v| [:"#{table}.#{k}", get_column_value(v)]}.flatten]
46
- end
47
-
48
- # Given an association reflection, return a bound variable hash for the given
49
- # association for this instance's values.
50
- def association_bound_variables(opts)
51
- return if opts[:instance_specific]
52
-
53
- case opts[:type]
54
- when :many_to_one
55
- association_bound_variable_hash(opts.associated_class.table_name, opts.primary_keys, opts[:keys])
56
- when :one_to_many, :one_to_one
57
- association_bound_variable_hash(opts.associated_class.table_name, opts[:keys], opts[:primary_keys])
58
- when :many_to_many, :one_through_one
59
- association_bound_variable_hash(opts.join_table_alias, opts[:left_keys], opts[:left_primary_keys])
60
- when :many_through_many, :one_through_many
61
- association_bound_variable_hash(opts.final_reverse_edge[:alias], Array(opts[:left_key]), opts[:left_primary_keys])
62
- end
63
- end
64
-
65
- # Given an association reflection, return and cache a prepared statement for this association such
66
- # that, given appropriate bound variables, the prepared statement will work correctly for any
67
- # instance. Return false if such a prepared statement cannot be created.
68
- def association_prepared_statement(opts, assoc_bv)
69
- return unless model.cache_associations
70
- ps = opts.send(:cached_fetch, :prepared_statement) do
71
- unless opts[:instance_specific]
72
- ds, bv = _associated_dataset(opts, {}).unbind
73
-
74
- f = ds.opts[:from]
75
- if f && f.length == 1
76
- s = ds.opts[:select]
77
- if ds.opts[:join]
78
- if opts.eager_loading_use_associated_key? && s && s.length == 1 && s.first.is_a?(SQL::ColumnAll)
79
- table = s.first.table
80
- ds = ds.select(*opts.associated_class.columns.map{|c| Sequel.identifier(c).qualify(table)})
81
- end
82
- elsif !s || s.empty?
83
- ds = ds.select(*opts.associated_class.columns.map{|c| Sequel.identifier(c)})
84
- end
85
- end
86
-
87
- if bv.length != assoc_bv.length
88
- h = {}
89
- bv.each do |k,v|
90
- h[k] = v unless assoc_bv.has_key?(k)
91
- end
92
- ds = ds.bind(h)
93
- end
94
- ds.clone(:log_sql=>true).prepare(opts.returns_array? ? :select : :first, :"smpsap_#{NEXT.call}")
95
- end
96
- end
97
-
98
- if ps && @server && _associated_objects_use_same_server?
99
- ps = ps.server(@server)
100
- end
101
-
102
- ps
103
- end
104
-
105
- # Use a prepared statement if possible to load the associated object,
106
- # unless a dynamic callback is given.
107
- def _load_associated_object(opts, dynamic_opts)
108
- if !dynamic_opts[:callback] && (bv = association_bound_variables(opts)) && (ps = association_prepared_statement(opts, bv))
109
- ps.call(bv)
110
- else
111
- super
112
- end
113
- end
114
-
115
- # Use a prepared statement if possible to load the associated object,
116
- # unless the associated model uses caching.
117
- def _load_associated_object_via_primary_key(opts)
118
- if !opts.associated_class.respond_to?(:cache_get_pk) && (bv = association_bound_variables(opts)) && (ps = association_prepared_statement(opts, bv))
119
- ps.call(bv)
120
- else
121
- super
122
- end
123
- end
124
-
125
- # Use a prepared statement if possible to load the associated objects,
126
- # unless a dynamic callback is given.
127
- def _load_associated_object_array(opts, dynamic_opts)
128
- if !dynamic_opts[:callback] && (bv = association_bound_variables(opts)) && (ps = association_prepared_statement(opts, bv))
129
- ps.call(bv)
130
- else
131
- super
132
- end
133
- end
134
- end
135
- end
136
- end
137
- end
@@ -1,71 +0,0 @@
1
- # frozen-string-literal: true
2
-
3
- Sequel::Deprecation.deprecate("The prepared_statements_with_pk plugin", "Stop using the plugin, it is probably unneeded and making the application slower")
4
-
5
- module Sequel
6
- module Plugins
7
- # The prepared_statements_with_pk plugin allows Dataset#with_pk for model datasets
8
- # to use prepared statements by extract the values of previously bound variables
9
- # using <tt>Dataset#unbind</tt>, and attempting to use a prepared statement if the
10
- # variables can be unbound correctly. See +Unbinder+ for details about what types of
11
- # dataset filters can be unbound correctly.
12
- #
13
- # This plugin depends on the +prepared_statements+ plugin and should be considered unsafe.
14
- # Unbinding dataset values cannot be done correctly in all cases, and use of this plugin
15
- # in cases where not there are variables that are not unbound can lead to an denial of
16
- # service attack by allocating an arbitrary number of prepared statements. You have been
17
- # warned.
18
- #
19
- # Note that in most cases, this plugin will probably make things slower,
20
- # so you should only use it if you really want to use prepared statements
21
- # for Dataset#with_pk.
22
- #
23
- # Usage:
24
- #
25
- # # Make all model subclasses use prepared statements for Dataset#with_pk (called before loading subclasses)
26
- # Sequel::Model.plugin :prepared_statements_with_pk
27
- #
28
- # # Make the Album class use prepared statements for Dataset#with_pk
29
- # Album.plugin :prepared_statements_with_pk
30
- module PreparedStatementsWithPk
31
- # Depend on the prepared_statements plugin
32
- def self.apply(model)
33
- model.plugin(:prepared_statements)
34
- end
35
-
36
- module ClassMethods
37
- private
38
-
39
- # Return a prepared statement that can be used to lookup a row given a dataset for the row matching
40
- # the primary key.
41
- def prepared_lookup_dataset(ds)
42
- cached_prepared_statement(:lookup_sql, ds.sql){prepare_statement(ds.where(prepared_statement_key_array(primary_key).map{|k, v| [SQL::QualifiedIdentifier.new(ds.model.table_name, k), v]}), :first)}
43
- end
44
- end
45
-
46
- module DatasetMethods
47
- # Use a prepared statement to find a row with the matching primary key
48
- # inside this dataset.
49
- def with_pk(pk)
50
- begin
51
- ds, bv = unbind
52
- rescue UnbindDuplicate
53
- super
54
- else
55
- begin
56
- bv = bv.merge!(model.primary_key_hash(pk)){|k, v1, v2| ((v1 == v2) ? v1 : raise(UnbindDuplicate))}
57
- rescue UnbindDuplicate
58
- super
59
- else
60
- ps = model.send(:prepared_lookup_dataset, ds)
61
- if server = @opts[:server]
62
- ps = ps.server(server)
63
- end
64
- ps.call(bv)
65
- end
66
- end
67
- end
68
- end
69
- end
70
- end
71
- end
@@ -1,84 +0,0 @@
1
- # frozen-string-literal: true
2
-
3
- Sequel::Deprecation.deprecate("The schema plugin", "Switch to defining your schema using Database schema methods before creating your model classes")
4
-
5
- module Sequel
6
- module Plugins
7
- # Sequel's built in schema plugin allows you to define your schema
8
- # directly in the model using Model.set_schema (which takes a block
9
- # similar to Database#create_table), and use Model.create_table to
10
- # create a table using the schema information.
11
- #
12
- # This plugin is mostly suited to test code. If there is any
13
- # chance that your application's schema could change, you should
14
- # be using the migration extension instead.
15
- #
16
- # Usage:
17
- #
18
- # # Add the schema methods to all model subclasses (called before loading subclasses)
19
- # Sequel::Model.plugin :schema
20
- #
21
- # # Add the schema methods to the Album class
22
- # Album.plugin :schema
23
- module Schema
24
- module ClassMethods
25
- # Creates table, using the column information from set_schema.
26
- def create_table(*args, &block)
27
- set_schema(*args, &block) if block
28
- db.create_table(table_name, :generator=>@schema)
29
- @db_schema = get_db_schema(true)
30
- columns
31
- end
32
-
33
- # Drops the table if it exists and then runs create_table. Should probably
34
- # not be used except in testing.
35
- def create_table!(*args, &block)
36
- drop_table?
37
- create_table(*args, &block)
38
- end
39
-
40
- # Creates the table unless the table already exists
41
- def create_table?(*args, &block)
42
- create_table(*args, &block) unless table_exists?
43
- end
44
-
45
- # Drops table. If the table doesn't exist, this will probably raise an error.
46
- def drop_table
47
- db.drop_table(table_name)
48
- end
49
-
50
- # Drops table if it already exists, do nothing if it doesn't exist.
51
- def drop_table?
52
- db.drop_table?(table_name)
53
- end
54
-
55
- # Returns table schema created with set_schema for direct descendant of Model.
56
- # Does not retreive schema information from the database, see db_schema if you
57
- # want that.
58
- def schema
59
- @schema || (superclass.schema unless superclass == Model)
60
- end
61
-
62
- # Defines a table schema (see Schema::CreateTableGenerator for more information).
63
- #
64
- # This is only needed if you want to use the create_table/create_table! methods.
65
- # Will also set the dataset if you provide a name, as well as setting
66
- # the primary key if you defined one in the passed block.
67
- #
68
- # In general, it is a better idea to use migrations for production code, as
69
- # migrations allow changes to existing schema. set_schema is mostly useful for
70
- # test code or simple examples.
71
- def set_schema(name = nil, &block)
72
- set_dataset(db[name]) if name
73
- @schema = db.create_table_generator(&block)
74
- set_primary_key(@schema.primary_key_name) if @schema.primary_key_name
75
- end
76
-
77
- # Returns true if table exists, false otherwise.
78
- def table_exists?
79
- db.table_exists?(table_name)
80
- end
81
- end
82
- end
83
- end
84
- end
@@ -1,37 +0,0 @@
1
- # frozen-string-literal: true
2
-
3
- Sequel::Deprecation.deprecate("The scissors plugin", "Running with scissors is dangerous")
4
-
5
- module Sequel
6
- module Plugins
7
- # The scissors plugin adds class methods for update, delete, and destroy.
8
- # It is so named because this is considered dangerous, since it is easy
9
- # to write:
10
- #
11
- # Album.delete
12
- #
13
- # and delete all rows in the table, when you meant to write:
14
- #
15
- # album.delete
16
- #
17
- # and only delete a single row.
18
- #
19
- # This plugin is mostly useful for backwards compatibility, and not
20
- # recommended for use in production. However, it can cut down on
21
- # verbosity in non-transactional test code, so it may be appropriate
22
- # to use when testing.
23
- #
24
- # Usage:
25
- #
26
- # # Make all model subclass run with scissors
27
- # Sequel::Model.plugin :scissors
28
- #
29
- # # Make the Album class run with scissors
30
- # Album.plugin :scissors
31
- module Scissors
32
- module ClassMethods
33
- Plugins.def_dataset_methods(self, [:update, :delete, :destroy])
34
- end
35
- end
36
- end
37
- end
@@ -1,253 +0,0 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
2
-
3
- # SEQUEL5: Remove
4
- unless Sequel.mock.dataset.frozen?
5
-
6
- describe "Dataset" do
7
- before do
8
- @d = Sequel.mock.dataset.from(:x)
9
- end
10
-
11
- deprecated "should support self-changing select!" do
12
- @d.select!(:y)
13
- @d.sql.must_equal "SELECT y FROM x"
14
- end
15
-
16
- deprecated "should support self-changing from!" do
17
- @d.from!(:y)
18
- @d.sql.must_equal "SELECT * FROM y"
19
- end
20
-
21
- deprecated "should support self-changing order!" do
22
- @d.order!(:y)
23
- @d.sql.must_equal "SELECT * FROM x ORDER BY y"
24
- end
25
-
26
- deprecated "should support self-changing filter!" do
27
- @d.filter!(:y => 1)
28
- @d.sql.must_equal "SELECT * FROM x WHERE (y = 1)"
29
- end
30
-
31
- deprecated "should support self-changing filter! with block" do
32
- @d.filter!{y < 2}
33
- @d.sql.must_equal "SELECT * FROM x WHERE (y < 2)"
34
- end
35
-
36
- deprecated "should raise for ! methods that don't return a dataset" do
37
- proc {@d.opts!}.must_raise(NoMethodError)
38
- end
39
-
40
- deprecated "should raise for missing methods" do
41
- proc {@d.xuyz}.must_raise(NoMethodError)
42
- proc {@d.xyz!}.must_raise(NoMethodError)
43
- proc {@d.xyz?}.must_raise(NoMethodError)
44
- end
45
-
46
- deprecated "should support chaining of bang methods" do
47
- @d.order!(:y).filter!(:y => 1).sql.must_equal "SELECT * FROM x WHERE (y = 1) ORDER BY y"
48
- end
49
- end
50
-
51
- describe "Frozen Datasets" do
52
- before do
53
- @ds = Sequel.mock[:test].freeze
54
- end
55
-
56
- deprecated "should have dups not be frozen" do
57
- @ds.dup.wont_be :frozen?
58
- end
59
-
60
- deprecated "should raise an error when calling mutation methods" do
61
- proc{@ds.select!(:a)}.must_raise RuntimeError
62
- proc{@ds.row_proc = proc{}}.must_raise RuntimeError
63
- proc{@ds.extension! :query}.must_raise RuntimeError
64
- proc{@ds.naked!}.must_raise RuntimeError
65
- proc{@ds.from_self!}.must_raise RuntimeError
66
- end
67
- end
68
-
69
- describe "Dataset mutation methods" do
70
- def m(&block)
71
- ds = Sequel.mock[:t]
72
- def ds.supports_cte?(*) true end
73
- ds.instance_exec(&block)
74
- ds.sql
75
- end
76
-
77
- deprecated "should modify the dataset in place" do
78
- dsc = Sequel.mock[:u]
79
- dsc.send(:columns=, [:v])
80
-
81
- m{and!(:a=>1).or!(:b=>2)}.must_equal "SELECT * FROM t WHERE ((a = 1) OR (b = 2))"
82
- m{select!(:f).graph!(dsc, :b=>:c).set_graph_aliases!(:e=>[:m, :n]).add_graph_aliases!(:d=>[:g, :c])}.must_equal "SELECT m.n AS e, g.c AS d FROM t LEFT OUTER JOIN u ON (u.b = t.c)"
83
- m{cross_join!(:a)}.must_equal "SELECT * FROM t CROSS JOIN a"
84
- m{distinct!}.must_equal "SELECT DISTINCT * FROM t"
85
- m{except!(dsc)}.must_equal "SELECT * FROM (SELECT * FROM t EXCEPT SELECT * FROM u) AS t1"
86
- m{exclude!(:a=>1)}.must_equal "SELECT * FROM t WHERE (a != 1)"
87
- m{exclude_having!(:a=>1)}.must_equal "SELECT * FROM t HAVING (a != 1)"
88
- m{exclude_where!(:a=>1)}.must_equal "SELECT * FROM t WHERE (a != 1)"
89
- m{filter!(:a=>1)}.must_equal "SELECT * FROM t WHERE (a = 1)"
90
- m{for_update!}.must_equal "SELECT * FROM t FOR UPDATE"
91
- m{from!(:p)}.must_equal "SELECT * FROM p"
92
- m{full_join!(:a, [:b])}.must_equal "SELECT * FROM t FULL JOIN a USING (b)"
93
- m{full_outer_join!(:a, [:b])}.must_equal "SELECT * FROM t FULL OUTER JOIN a USING (b)"
94
- m{grep!(:a, 'b')}.must_equal "SELECT * FROM t WHERE ((a LIKE 'b' ESCAPE '\\'))"
95
- m{group!(:a)}.must_equal "SELECT * FROM t GROUP BY a"
96
- m{group_and_count!(:a)}.must_equal "SELECT a, count(*) AS count FROM t GROUP BY a"
97
- m{group_by!(:a)}.must_equal "SELECT * FROM t GROUP BY a"
98
- m{having!(:a)}.must_equal "SELECT * FROM t HAVING a"
99
- m{inner_join!(:a, [:b])}.must_equal "SELECT * FROM t INNER JOIN a USING (b)"
100
- m{intersect!(dsc)}.must_equal "SELECT * FROM (SELECT * FROM t INTERSECT SELECT * FROM u) AS t1"
101
- m{where!(:a).invert!}.must_equal "SELECT * FROM t WHERE NOT a"
102
- m{join!(:a, [:b])}.must_equal "SELECT * FROM t INNER JOIN a USING (b)"
103
- m{join_table!(:inner, :a, [:b])}.must_equal "SELECT * FROM t INNER JOIN a USING (b)"
104
- m{left_join!(:a, [:b])}.must_equal "SELECT * FROM t LEFT JOIN a USING (b)"
105
- m{left_outer_join!(:a, [:b])}.must_equal "SELECT * FROM t LEFT OUTER JOIN a USING (b)"
106
- m{limit!(1)}.must_equal "SELECT * FROM t LIMIT 1"
107
- m{lock_style!(:update)}.must_equal "SELECT * FROM t FOR UPDATE"
108
- m{natural_full_join!(:a)}.must_equal "SELECT * FROM t NATURAL FULL JOIN a"
109
- m{natural_join!(:a)}.must_equal "SELECT * FROM t NATURAL JOIN a"
110
- m{natural_left_join!(:a)}.must_equal "SELECT * FROM t NATURAL LEFT JOIN a"
111
- m{natural_right_join!(:a)}.must_equal "SELECT * FROM t NATURAL RIGHT JOIN a"
112
- m{offset!(1)}.must_equal "SELECT * FROM t OFFSET 1"
113
- m{order!(:a).reverse_order!}.must_equal "SELECT * FROM t ORDER BY a DESC"
114
- m{order_by!(:a).order_more!(:b).order_append!(:c).order_prepend!(:d).reverse!}.must_equal "SELECT * FROM t ORDER BY d DESC, a DESC, b DESC, c DESC"
115
- m{qualify!}.must_equal "SELECT t.* FROM t"
116
- m{right_join!(:a, [:b])}.must_equal "SELECT * FROM t RIGHT JOIN a USING (b)"
117
- m{right_outer_join!(:a, [:b])}.must_equal "SELECT * FROM t RIGHT OUTER JOIN a USING (b)"
118
- m{select!(:a)}.must_equal "SELECT a FROM t"
119
- m{select_all!(:t).select_more!(:b).select_append!(:c)}.must_equal "SELECT t.*, b, c FROM t"
120
- m{select_group!(:a)}.must_equal "SELECT a FROM t GROUP BY a"
121
- m{where!(:a).unfiltered!}.must_equal "SELECT * FROM t"
122
- m{group!(:a).ungrouped!}.must_equal "SELECT * FROM t"
123
- m{limit!(1).unlimited!}.must_equal "SELECT * FROM t"
124
- m{order!(:a).unordered!}.must_equal "SELECT * FROM t"
125
- m{union!(dsc)}.must_equal "SELECT * FROM (SELECT * FROM t UNION SELECT * FROM u) AS t1"
126
- m{with!(:a, dsc)}.must_equal "WITH a AS (SELECT * FROM u) SELECT * FROM t"
127
- m{with_recursive!(:a, dsc, dsc)}.must_equal "WITH a AS (SELECT * FROM u UNION ALL SELECT * FROM u) SELECT * FROM t"
128
- m{with_sql!('SELECT foo')}.must_equal "SELECT foo"
129
-
130
- dsc.server!(:a)
131
- dsc.opts[:server].must_equal :a
132
- dsc.graph!(dsc, {:b=>:c}, :table_alias=>:foo).ungraphed!.opts[:graph].must_be_nil
133
- end
134
-
135
- deprecated "should clear the cache" do
136
- ds = Sequel.mock[:a]
137
- ds.columns
138
- ds.send(:cache_set, :columns, [:a])
139
- ds.select!(:foo, :bar).send(:cache_get, :columns).must_be_nil
140
- end
141
- end
142
-
143
- describe "Dataset#clone" do
144
- before do
145
- @dataset = Sequel.mock.dataset.from(:items)
146
- end
147
-
148
- deprecated "should copy the dataset opts" do
149
- clone = @dataset.clone
150
- clone.opts.must_equal @dataset.opts
151
- @dataset.filter!(:a => 'b')
152
- clone.opts[:filter].must_be_nil
153
- end
154
- end
155
-
156
- describe "Dataset extensions" do
157
- before(:all) do
158
- class << Sequel
159
- alias _extension extension
160
- remove_method :extension
161
- def extension(*)
162
- end
163
- end
164
- end
165
- after(:all) do
166
- class << Sequel
167
- remove_method :extension
168
- alias extension _extension
169
- remove_method :_extension
170
- end
171
- end
172
- before do
173
- @ds = Sequel.mock.dataset
174
- end
175
-
176
- deprecated "should have #extension! modify the receiver" do
177
- Sequel::Dataset.register_extension(:foo, Module.new{def a; 1; end})
178
- @ds.extension!(:foo)
179
- @ds.a.must_equal 1
180
- end
181
-
182
- deprecated "should have #extension! return the receiver" do
183
- Sequel::Dataset.register_extension(:foo, Module.new{def a; 1; end})
184
- @ds.extension!(:foo).must_be_same_as(@ds)
185
- end
186
- end
187
-
188
- describe "Dataset#naked!" do
189
- deprecated "should remove any existing row_proc" do
190
- d = Sequel.mock.dataset.with_row_proc(Proc.new{|r| r})
191
- d.naked!.row_proc.must_be_nil
192
- d.row_proc.must_be_nil
193
- end
194
- end
195
-
196
- describe "Dataset#row_proc=" do
197
- deprecated "should set the row_proc" do
198
- d = Sequel.mock.dataset.with_row_proc(Proc.new{|r| r})
199
- d.row_proc.wont_be_nil
200
- d.row_proc = nil
201
- d.row_proc.must_be_nil
202
- end
203
- end
204
-
205
- describe "Dataset#quote_identifiers=" do
206
- deprecated "should change quote identifiers setting" do
207
- d = Sequel.mock.dataset.with_quote_identifiers(true)
208
- d.literal(:a).must_equal '"a"'
209
- d.quote_identifiers = false
210
- d.literal(:a).must_equal 'a'
211
- end
212
- end
213
-
214
- describe "Dataset#from_self!" do
215
- deprecated "should work" do
216
- Sequel.mock.dataset.from(:test).select(:name).limit(1).from_self!.sql.must_equal 'SELECT * FROM (SELECT name FROM test LIMIT 1) AS t1'
217
- end
218
- end
219
-
220
- describe "Sequel Mock Adapter" do
221
- deprecated "should be able to set the rows returned by each on a per dataset basis using _fetch" do
222
- rs = []
223
- db = Sequel.mock(:fetch=>{:a=>1})
224
- ds = db[:t]
225
- ds.each{|r| rs << r}
226
- rs.must_equal [{:a=>1}]
227
- ds._fetch = {:b=>2}
228
- ds.each{|r| rs << r}
229
- rs.must_equal [{:a=>1}, {:b=>2}]
230
- end
231
-
232
- deprecated "should be able to set the number of rows modified by update and delete on a per dataset basis" do
233
- db = Sequel.mock(:numrows=>2)
234
- ds = db[:t]
235
- ds.update(:a=>1).must_equal 2
236
- ds.delete.must_equal 2
237
- ds.numrows = 3
238
- ds.update(:a=>1).must_equal 3
239
- ds.delete.must_equal 3
240
- end
241
-
242
- deprecated "should be able to set the autogenerated primary key returned by insert on a per dataset basis" do
243
- db = Sequel.mock(:autoid=>1)
244
- ds = db[:t]
245
- ds.insert(:a=>1).must_equal 1
246
- ds.autoid = 5
247
- ds.insert(:a=>1).must_equal 5
248
- ds.insert(:a=>1).must_equal 6
249
- db[:t].insert(:a=>1).must_equal 2
250
- end
251
- end
252
-
253
- end