From 74623c967af5035f046b0d978bb870ab5a02ba09 Mon Sep 17 00:00:00 2001 From: Can Celasun Date: Fri, 6 Feb 2015 16:05:37 +0200 Subject: [PATCH] Implement Vertica support --- README.md | 2 +- lib/run-query.js | 23 ++++++++++++++++++++++- routes/schema-info.js | 24 ++++++++++++++++++------ views/connection.ejs | 3 ++- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 853a3e5c1..c2d1490e8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # SqlPad -A Node.js web app for writing and running SQL queries and visualizing the results. Supports Postgres, MySQL, and SQL Server. +A Node.js web app for writing and running SQL queries and visualizing the results. Supports Postgres, MySQL, SQL Server and Vertica. ![SqlPad Query Editor](screenshots/query-editor.png) diff --git a/lib/run-query.js b/lib/run-query.js index ae1f9dedb..33466452f 100644 --- a/lib/run-query.js +++ b/lib/run-query.js @@ -84,4 +84,25 @@ clients.sqlserver = function (query, connection, callback) { }); } }); -}; \ No newline at end of file +}; + +clients.vertica = function (query, connection, callback) { + + var connectionUrl = "postgres://" + connection.username + + ":" + connection.password + + "@" + connection.host + + "/" + connection.database; + + var client = new pg.Client(connectionUrl); + client.connect(function (err) { + if (err) { + callback(err); + client.end(); + } else { + client.query(query, function(err, result) { + callback(err, result); + client.end(); + }); + } + }); +} diff --git a/routes/schema-info.js b/routes/schema-info.js index e985e592f..30606e294 100644 --- a/routes/schema-info.js +++ b/routes/schema-info.js @@ -12,11 +12,23 @@ module.exports = function (app) { connection.username = decipher(connection.username); connection.password = decipher(connection.password); - var tableAndColumnSql = "SELECT t.table_type, t.table_schema, t.table_name, c.column_name, c.data_type, c.is_nullable " - + " FROM INFORMATION_SCHEMA.tables t " - + " JOIN INFORMATION_SCHEMA.columns c ON t.table_schema = c.table_schema AND t.table_name = c.table_name " - + " WHERE t.table_schema NOT IN ('information_schema', 'pg_catalog') " - + " ORDER BY t.table_type, t.table_schema, t.table_name, c.ordinal_position "; + if (connection.driver !== "vertica") { + + var tableAndColumnSql = "SELECT t.table_type, t.table_schema, t.table_name, c.column_name, c.data_type, c.is_nullable " + + " FROM INFORMATION_SCHEMA.tables t " + + " JOIN INFORMATION_SCHEMA.columns c ON t.table_schema = c.table_schema AND t.table_name = c.table_name " + + " WHERE t.table_schema NOT IN ('information_schema', 'pg_catalog') " + + " ORDER BY t.table_type, t.table_schema, t.table_name, c.ordinal_position"; + } else { + var tableAndColumnSql = "SELECT (CASE vat.table_type WHEN 'TABLE' THEN 'BASE TABLE' ELSE 'TABLE' END) AS table_type, " + + " vt.table_schema, vt.table_name, vc.column_name, vc.data_type, " + + " (CASE vc.is_nullable WHEN 't' THEN 'YES' ELSE 'NO' END) as is_nullable " + + " FROM V_CATALOG.TABLES vt " + + " JOIN V_CATALOG.ALL_TABLES vat ON vt.table_id = vat.table_id " + + " JOIN V_CATALOG.COLUMNS vc ON vt.table_schema = vc.table_schema AND vt.table_name = vc.table_name " + + " WHERE vt.table_schema NOT IN ('V_CATALOG') AND vat.table_type = 'TABLE' " + + " ORDER BY vat.table_type, vt.table_schema, vt.table_name, vc.ordinal_position"; + } var tree = {}; @@ -62,4 +74,4 @@ module.exports = function (app) { }); }); -}; \ No newline at end of file +}; diff --git a/views/connection.ejs b/views/connection.ejs index 970d10966..959f6d185 100644 --- a/views/connection.ejs +++ b/views/connection.ejs @@ -22,6 +22,7 @@ + @@ -74,4 +75,4 @@ -<% include footer %> \ No newline at end of file +<% include footer %>