From c0e97287356157dfdeaba0914863761b72fb59fb Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 27 Oct 2014 22:03:54 +0000 Subject: Added listkeycolumns function to db library --- db.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/db.lua b/db.lua index 18af1f3..0e8848f 100644 --- a/db.lua +++ b/db.lua @@ -148,6 +148,21 @@ export.listcolumns = function(dbobject, table) return result end +export.listkeycolumns = function(dbobject, table) + local result = {} + if dbobject.engine == mymodule.engine.postgresql then + local col = dbobject.getselectresponse("SELECT pg_attribute.attname AS field FROM pg_index, pg_class, pg_attribute WHERE pg_class.oid = '"..dbobject.escape(table).."'::regclass AND indrelid = pg_class.oid AND pg_attribute.attrelid = pg_class.oid AND pg_attribute.attnum = any(pg_index.indkey) AND indisprimary") + if nil == next(col) then + result = export.listcolumns(dbobject, table) + else + for i,c in ipairs(col) do + result[#result+1] = c.field + end + end + end + return result +end + export.listdatabases = function(dbobject) local result = {} if dbobject.engine == mymodule.engine.postgresql then -- cgit v1.2.3