Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ func testDatabases(t *testing.T) {
assertMatches(t, []string{"booktown", "postgres"}, res)
}

func testSchemas(t *testing.T) {
res, err := testClient.Schemas()
assert.NoError(t, err)
assert.Equal(t, []string{"public"}, res)
}

func testObjects(t *testing.T) {
res, err := testClient.Objects()
objects := ObjectsFromResult(res)
Expand Down Expand Up @@ -617,6 +623,7 @@ func TestAll(t *testing.T) {
testInfo(t)
testActivity(t)
testDatabases(t)
testSchemas(t)
testObjects(t)
testTable(t)
testTableRows(t)
Expand Down
4 changes: 2 additions & 2 deletions pkg/statements/sql/objects.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ WITH all_objects AS (
pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE
c.relkind IN ('r','v','m','S','s','')
AND n.nspname !~ '^pg_toast'
AND n.nspname !~ '^pg_(toast|temp)'
AND n.nspname NOT IN ('information_schema', 'pg_catalog')
AND has_schema_privilege(n.nspname, 'USAGE')

Expand All @@ -38,7 +38,7 @@ WITH all_objects AS (
JOIN
pg_catalog.pg_proc p ON p.pronamespace = n.oid
WHERE
n.nspname !~ '^pg_toast'
n.nspname !~ '^pg_(toast|temp)'
AND n.nspname NOT IN ('information_schema', 'pg_catalog')
)
SELECT * FROM all_objects
Expand Down
3 changes: 3 additions & 0 deletions pkg/statements/sql/schemas.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ SELECT
schema_name
FROM
information_schema.schemata
WHERE
schema_name NOT IN ('information_schema', 'pg_catalog')
AND schema_name !~ '^pg_(toast|temp)'
ORDER BY
schema_name ASC
78 changes: 50 additions & 28 deletions static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function apiCall(method, path, params, cb) {

function getInfo(cb) { apiCall("get", "/info", {}, cb); }
function getConnection(cb) { apiCall("get", "/connection", {}, cb); }
function getSchemas(cb) { apiCall("get", "/schemas", {}, cb); }
function getObjects(cb) { apiCall("get", "/objects", {}, cb); }
function getTables(cb) { apiCall("get", "/tables", {}, cb); }
function getTableRows(table, opts, cb) { apiCall("get", "/tables/" + table + "/rows", opts, cb); }
Expand Down Expand Up @@ -161,44 +162,65 @@ function buildSchemaSection(name, objects) {
function loadSchemas() {
$("#objects").html("");

getObjects(function(data) {
if (Object.keys(data).length == 0) {
data["public"] = {
table: [],
view: [],
materialized_view: [],
function: [],
sequence: []
};
var emptyObjectList = function() {
return {
table: [],
view: [],
materialized_view: [],
function: [],
sequence: []
}
}

for (schema in data) {
$(buildSchemaSection(schema, data[schema])).appendTo("#objects");
getSchemas(function(schemasData) {
if (schemasData.error) {
alert("Error while fetching schemas: " + schemasData.error);
return;
}

if (Object.keys(data).length == 1) {
$(".schema").addClass("expanded");
}
getObjects(function(data) {
if (data.error) {
alert("Error while fetching database objects: " + data.error);
return;
}

if (Object.keys(data).length == 0) {
data["public"] = emptyObjectList();
}

// Clear out all autocomplete objects
autocompleteObjects = [];
for (schema in data) {
for (kind in data[schema]) {
if (!(kind == "table" || kind == "view" || kind == "materialized_view" || kind == "function")) {
continue
for (schemaName of schemasData) {
// Allow users to see empty schemas if we dont have any objects in them
if (!data[schemaName]) {
data[schemaName] = emptyObjectList();
}

for (item in data[schema][kind]) {
autocompleteObjects.push({
caption: data[schema][kind][item].name,
value: data[schema][kind][item].name,
meta: kind
});
$(buildSchemaSection(schemaName, data[schemaName])).appendTo("#objects");
}

if (Object.keys(data).length == 1) {
$(".schema").addClass("expanded");
}

// Clear out all autocomplete objects
autocompleteObjects = [];
for (schema in data) {
for (kind in data[schema]) {
if (!(kind == "table" || kind == "view" || kind == "materialized_view" || kind == "function")) {
continue
}

for (item in data[schema][kind]) {
autocompleteObjects.push({
caption: data[schema][kind][item].name,
value: data[schema][kind][item].name,
meta: kind
});
}
}
}
}

bindContextMenus();
bindContextMenus();
});
});
}

Expand Down