blob: 2bb4bbbd904cd8e7ce96f85f22838afe9d7b33e1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
module Arel
# this file is currently just a hack to adapt between activerecord::base which holds the connection specification
# and active relation. ultimately, this file should be in effect what the connection specification is in active record;
# that is: a spec of the database (url, password, etc.), a quoting adapter layer, and a connection pool.
class Engine
def initialize(ar = nil)
@ar = ar
end
def connection
@ar.connection
end
def method_missing(method, *args, &block)
@ar.connection.send(method, *args, &block)
end
module CRUD
def create(relation)
connection.insert(relation.to_sql)
end
def read(relation)
results = connection.execute(relation.to_sql)
rows = []
results.each do |row|
rows << attributes.zip(row).to_hash
end
rows
end
def update(relation)
connection.update(relation.to_sql)
end
def delete(relation)
connection.delete(relation.to_sql)
end
end
include CRUD
end
end
|