Skip to content

Commit

Permalink
fix(db): Changes query for postgres compatibility on table_exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Etiene committed Nov 14, 2015
1 parent 403bac8 commit 85cc1f5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/sailor/db/luasql_common.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--------------------------------------------------------------------------------
-- luasql_common.lua, v0.5: DB module for connecting and querying through LuaSQL
-- luasql_common.lua, v0.5.1: DB module for connecting and querying through LuaSQL
-- This file is a part of Sailor project
-- Copyright (c) 2014 Etiene Dalcol <dalcol@etiene.net>
-- License: MIT
Expand Down Expand Up @@ -197,7 +197,7 @@ function db.table_exists(table_name)
table_name = db.escape(table_name)
local query
if conf.driver == 'postgres' then
query = "SELECT to_regclass('public."..table_name.."');"
query = "SELECT relname FROM pg_class WHERE relname = '"..table_name.."';"
elseif conf.driver == 'sqlite3' then
query = "SELECT name FROM sqlite_master WHERE type='table' AND name='"..table_name.."';"
else
Expand Down
10 changes: 6 additions & 4 deletions src/sailor/db/resty_mysql.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--------------------------------------------------------------------------------
-- resty_mysql.lua, v0.3: DB module for connecting and querying through MySQL on openresty servers
-- resty_mysql.lua, v0.3.1: DB module for connecting and querying through MySQL on openresty servers
-- This file is a part of Sailor project
-- Copyright (c) 2014 Etiene Dalcol <dalcol@etiene.net>
-- License: MIT
Expand Down Expand Up @@ -172,10 +172,12 @@ function db.get_columns(table_name)

local query = "SELECT column_name, column_key FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '"..table_name.."';"
local res = db.query(query)
for k,v in pairs(res.column_key) do
if v == 'PRI' then key = k end
local helper = require "tests.helper"
for _,v in ipairs(res) do
if v.column_key == 'PRI' then key = v.column_name end
columns[#columns+1] = v.column_name
end
columns = res.column_name


return columns, key
end
Expand Down
1 change: 0 additions & 1 deletion test/dev-app/tests/functional/autogen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe("Testing #Autogen", function()
local path = 'models/category.lua'
os.remove(path)
local res = test.request('autogen',{post={table_name ='category'}})
print(res.body)
assert.truthy(res.body:match('Model generated with success'))
assert.truthy(lfs.attributes(path))
end)
Expand Down

0 comments on commit 85cc1f5

Please sign in to comment.