Use go embed to load queries from static files (#607)

This commit is contained in:
Dan Sosedoff
2022-12-06 17:41:46 -06:00
committed by GitHub
parent f4b3091666
commit f48cc5f007
15 changed files with 247 additions and 243 deletions

View File

@@ -0,0 +1,8 @@
SELECT
datname
FROM
pg_database
WHERE
NOT datistemplate
ORDER BY
datname ASC

View File

@@ -0,0 +1,6 @@
SELECT
reltuples
FROM
pg_class
WHERE
oid = ('"' || $1::text || '"."' || $2::text || '"')::regclass

View File

@@ -0,0 +1,10 @@
SELECT
session_user,
current_user,
current_database(),
current_schemas(false),
inet_client_addr(),
inet_client_port(),
inet_server_addr(),
inet_server_port(),
version()

View File

@@ -0,0 +1,13 @@
SELECT
attname AS column_name,
atttypid::regtype AS data_type,
(CASE WHEN attnotnull IS TRUE THEN 'NO' ELSE 'YES' END) AS is_nullable,
NULL AS character_maximum_length,
NULL AS character_set_catalog,
NULL AS column_default
FROM
pg_attribute
WHERE
attrelid = $1::regclass
AND attnum > 0
AND NOT attisdropped

View File

@@ -0,0 +1,25 @@
SELECT
n.nspname AS schema,
c.relname AS name,
CASE c.relkind
WHEN 'r' THEN 'table'
WHEN 'v' THEN 'view'
WHEN 'm' THEN 'materialized_view'
WHEN 'i' THEN 'index'
WHEN 'S' THEN 'sequence'
WHEN 's' THEN 'special'
WHEN 'f' THEN 'foreign_table'
END AS type,
pg_catalog.pg_get_userbyid(c.relowner) AS owner,
pg_catalog.obj_description(c.oid) AS comment
FROM
pg_catalog.pg_class c
LEFT JOIN
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 NOT IN ('information_schema', 'pg_catalog')
AND has_schema_privilege(n.nspname, 'USAGE')
ORDER BY
1, 2

View File

@@ -0,0 +1,6 @@
SELECT
schema_name
FROM
information_schema.schemata
ORDER BY
schema_name ASC

View File

@@ -0,0 +1,14 @@
SELECT
conname AS name,
pg_get_constraintdef(c.oid, true) AS definition
FROM
pg_constraint c
JOIN
pg_namespace n ON n.oid = c.connamespace
JOIN
pg_class cl ON cl.oid = c.conrelid
WHERE
n.nspname = $1
AND relname = $2
ORDER BY
contype DESC

View File

@@ -0,0 +1,9 @@
SELECT
indexname AS index_name,
pg_size_pretty(pg_table_size((schemaname || '.' || indexname)::regclass)) AS index_size,
indexdef AS index_definition
FROM
pg_indexes
WHERE
schemaname = $1
AND tablename = $2

View File

@@ -0,0 +1,5 @@
SELECT
pg_size_pretty(pg_table_size($1)) AS data_size,
pg_size_pretty(pg_indexes_size($1)) AS index_size,
pg_size_pretty(pg_total_relation_size($1)) AS total_size,
(SELECT reltuples FROM pg_class WHERE oid = $1::regclass) AS rows_count

View File

@@ -0,0 +1,5 @@
SELECT
'n/a' AS data_size,
'n/a' AS index_size,
'n/a' AS total_size,
'n/a' AS rows_count

View File

@@ -0,0 +1,13 @@
SELECT
column_name,
data_type,
is_nullable,
character_maximum_length,
character_set_catalog,
column_default,
pg_catalog.col_description(('"' || $1::text || '"."' || $2::text || '"')::regclass::oid, ordinal_position) as comment
FROM
information_schema.columns
WHERE
table_schema = $1
AND table_name = $2