Class: MiniSql::Postgres::PreparedBinds
Instance Method Summary
collapse
#array_wrap, #bind, #bind_array
Instance Method Details
#bind_hash(sql, hash) ⇒ Object
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
|
# File 'lib/mini_sql/postgres/prepared_binds.rb', line 9
def bind_hash(sql, hash)
sql = sql.dup
binds = []
bind_names = []
i = 0
hash.each do |k, v|
bind_outputs =
array_wrap(v).map { |vv|
binds << vv
bind_names << [BindName.new(k)]
bind_output(i += 1)
}.join(', ')
sql.gsub!(":#{k}") do
if $` && $`[-1] != ":"
bind_outputs
else
":#{k}"
end
end
end
[sql, binds, bind_names]
end
|
#bind_output(i) ⇒ Object
36
37
38
|
# File 'lib/mini_sql/postgres/prepared_binds.rb', line 36
def bind_output(i)
"$#{i}"
end
|