Skip to content

Commit

Permalink
misc postgres cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Feb 20, 2015
1 parent f2a3a63 commit a0ce300
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
5 changes: 3 additions & 2 deletions lapis/db/postgres.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ init_db = function()
end
local escape_identifier
escape_identifier = function(ident)
if type(ident) == "table" and ident[1] == "raw" then
if is_raw(ident) then
return ident[2]
end
ident = tostring(ident)
Expand All @@ -132,9 +132,10 @@ escape_literal = function(val)
if val == NULL then
return "NULL"
end
if val[1] == "raw" and val[2] then
if is_raw(val) then
return val[2]
end
error("unknown table passed to `escape_literal`")
end
return error("don't know how to escape value: " .. tostring(val))
end
Expand Down
8 changes: 3 additions & 5 deletions lapis/db/postgres.moon
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ init_db = ->
set_backend default_backend

escape_identifier = (ident) ->
if type(ident) == "table" and ident[1] == "raw"
return ident[2]

return ident[2] if is_raw ident
ident = tostring ident
'"' .. (ident\gsub '"', '""') .. '"'

Expand All @@ -104,8 +102,8 @@ escape_literal = (val) ->
return val and "TRUE" or "FALSE"
when "table"
return "NULL" if val == NULL
if val[1] == "raw" and val[2]
return val[2]
return val[2] if is_raw val
error "unknown table passed to `escape_literal`"
error "don't know how to escape value: #{val}"
Expand Down
3 changes: 1 addition & 2 deletions spec/helpers.moon
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ s\set "assertion.one_of.negative",
assert\register "assertion",
"one_of", one_of, "assertion.one_of.positive", "assertion.one_of.negative"

with_query_fn = (q, run) ->
db = require "lapis.db.postgres"
with_query_fn = (q, run, db=require "lapis.db.postgres") ->
old_query = db.set_backend "raw", q
if not run
-> db.set_backend "raw", old_query
Expand Down
3 changes: 1 addition & 2 deletions spec/postgres_spec.moon
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

import with_query_fn from require "spec.helpers"
require "spec.helpers" -- for one_of

db = require "lapis.db.postgres"
schema = require "lapis.db.postgres.schema"
Expand Down

0 comments on commit a0ce300

Please sign in to comment.