crud.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. module Arel
  2. ###
  3. # FIXME hopefully we can remove this
  4. module Crud
  5. def compile_update values
  6. um = UpdateManager.new @engine
  7. if Nodes::SqlLiteral === values
  8. relation = @ctx.from
  9. else
  10. relation = values.first.first.relation
  11. end
  12. um.table relation
  13. um.set values
  14. um.take @ast.limit.expr if @ast.limit
  15. um.order(*@ast.orders)
  16. um.wheres = @ctx.wheres
  17. um
  18. end
  19. # FIXME: this method should go away
  20. def update values
  21. if $VERBOSE
  22. warn <<-eowarn
  23. update (#{caller.first}) is deprecated and will be removed in ARel 4.0.0. Please
  24. switch to `compile_update`
  25. eowarn
  26. end
  27. um = compile_update values
  28. @engine.connection.update um.to_sql, 'AREL'
  29. end
  30. def compile_insert values
  31. im = create_insert
  32. im.insert values
  33. im
  34. end
  35. def create_insert
  36. InsertManager.new @engine
  37. end
  38. # FIXME: this method should go away
  39. def insert values
  40. if $VERBOSE
  41. warn <<-eowarn
  42. insert (#{caller.first}) is deprecated and will be removed in ARel 4.0.0. Please
  43. switch to `compile_insert`
  44. eowarn
  45. end
  46. @engine.connection.insert compile_insert(values).to_sql
  47. end
  48. def compile_delete
  49. dm = DeleteManager.new @engine
  50. dm.wheres = @ctx.wheres
  51. dm.from @ctx.froms
  52. dm
  53. end
  54. def delete
  55. if $VERBOSE
  56. warn <<-eowarn
  57. delete (#{caller.first}) is deprecated and will be removed in ARel 4.0.0. Please
  58. switch to `compile_delete`
  59. eowarn
  60. end
  61. @engine.connection.delete compile_delete.to_sql, 'AREL'
  62. end
  63. end
  64. end