2017-02-13 13:58:58 -05:00
|
|
|
# frozen_string_literal: true
|
2018-02-24 01:45:50 -05:00
|
|
|
|
2018-02-24 02:41:47 -05:00
|
|
|
module Arel # :nodoc: all
|
2010-08-16 17:56:56 -04:00
|
|
|
###
|
|
|
|
# FIXME hopefully we can remove this
|
|
|
|
module Crud
|
2018-02-24 01:45:50 -05:00
|
|
|
def compile_update(values, pk)
|
2014-11-29 19:22:17 -05:00
|
|
|
um = UpdateManager.new
|
2010-08-18 12:52:16 -04:00
|
|
|
|
2010-08-23 16:28:08 -04:00
|
|
|
if Nodes::SqlLiteral === values
|
2010-12-24 17:48:33 -05:00
|
|
|
relation = @ctx.from
|
2010-08-18 12:52:16 -04:00
|
|
|
else
|
2010-09-14 16:39:33 -04:00
|
|
|
relation = values.first.first.relation
|
2010-08-18 12:52:16 -04:00
|
|
|
end
|
2013-11-16 17:20:07 -05:00
|
|
|
um.key = pk
|
2010-09-14 16:39:33 -04:00
|
|
|
um.table relation
|
2010-08-16 17:56:56 -04:00
|
|
|
um.set values
|
2011-01-03 18:44:16 -05:00
|
|
|
um.take @ast.limit.expr if @ast.limit
|
2010-11-05 17:09:09 -04:00
|
|
|
um.order(*@ast.orders)
|
2010-09-21 12:20:14 -04:00
|
|
|
um.wheres = @ctx.wheres
|
2010-12-02 17:31:37 -05:00
|
|
|
um
|
|
|
|
end
|
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
def compile_insert(values)
|
2011-03-22 00:23:48 -04:00
|
|
|
im = create_insert
|
2010-08-16 17:56:56 -04:00
|
|
|
im.insert values
|
2010-12-02 17:01:08 -05:00
|
|
|
im
|
|
|
|
end
|
|
|
|
|
2011-03-22 00:23:48 -04:00
|
|
|
def create_insert
|
2014-11-29 19:22:17 -05:00
|
|
|
InsertManager.new
|
2011-03-22 00:23:48 -04:00
|
|
|
end
|
|
|
|
|
2010-12-02 18:45:00 -05:00
|
|
|
def compile_delete
|
2014-11-29 19:22:17 -05:00
|
|
|
dm = DeleteManager.new
|
2012-02-29 10:47:28 -05:00
|
|
|
dm.take @ast.limit.expr if @ast.limit
|
2010-08-18 14:32:44 -04:00
|
|
|
dm.wheres = @ctx.wheres
|
2010-09-20 17:27:34 -04:00
|
|
|
dm.from @ctx.froms
|
2010-12-02 18:45:00 -05:00
|
|
|
dm
|
|
|
|
end
|
2010-08-16 17:56:56 -04:00
|
|
|
end
|
|
|
|
end
|