Commit e799d61a authored by Anne Blankert's avatar Anne Blankert

add type of table (table,ftable,view,mview)

parent 3b5cf385
......@@ -10,7 +10,8 @@ const sql = () => {
COALESCE(postgis_typmod_dims(a.atttypmod), sn.ndims, 2) AS coord_dimension,
COALESCE(NULLIF(postgis_typmod_srid(a.atttypmod), 0), sr.srid, 0) AS srid,
replace(replace(COALESCE(NULLIF(upper(postgis_typmod_type(a.atttypmod)), 'GEOMETRY'::text), st.type, 'GEOMETRY'::text), 'ZM'::text, ''::text), 'Z'::text, ''::text)::character varying(30) AS type,
((c.reltuples/case when c.relpages=0 then 1 else c.relpages end) * (pg_relation_size(c.oid) / (current_setting('block_size')::integer)))::bigint as estimated_rows
((c.reltuples/case when c.relpages=0 then 1 else c.relpages end) * (pg_relation_size(c.oid) / (current_setting('block_size')::integer)))::bigint as estimated_rows,
case when relkind='r' then 'table' when relkind='v' then 'view' when relkind='m' then 'mview' when relkind='f' then 'ftable' else 'other(' || relkind || ')' end table_type
FROM pg_class c
JOIN pg_attribute a ON a.attrelid = c.oid AND NOT a.attisdropped
JOIN pg_namespace n ON c.relnamespace = n.oid
......@@ -53,6 +54,39 @@ const sql = () => {
* responses:
* 200:
* description: list of layers
* content:
* application/json
* schema:
* type: array
* items:
* type: object
* properties:
* f_table_catalog:
* description: name of database (group of tables)
* type: string
* f_table_schema:
* description: schema name (sub-group of tables)
* type: string
* f_table_name:
* description: name of table or view
* type: string
* f_geometry_column:
* description: name of geometry column for geometries
* type: string
* coord_dimension:
* description: number of dimensions, usually 2 or 3
* type: integer
* srid:
* description: EPSG id of spatial reference system (4326=WGS 84/GPS coordinates, 3857=webmercator coordinates)
* type: integer
* estimated_rows:
* description: estimated number of rows in table, 0 (unknown) for views or foreign tables
* type: integer
* table_type:
* description: type of table, 1 of 'table', 'view', 'mview' (material view), 'ftable' (foreign table), 'other'
* type: string
* 500:
* description: unexpected error
*/
app.get('/data/list_layers', async (req, res)=>{
try {
......@@ -61,7 +95,7 @@ const sql = () => {
const layers = result.rows
res.json(layers)
} catch(err) {
res.json({error: err})
res.status(500).json({error: err.message})
}
})
}
\ No newline at end of file
......@@ -27,6 +27,9 @@
case 'dim':
fieldname = 'coord_dimension';
break;
case 'type':
fieldname = 'table_type';
break;
case 'count':
fieldname = 'estimated_rows'
break;
......@@ -52,6 +55,7 @@
break;
case 'f_geometry_column':
case 'type':
case 'table_type':
case 'coord_dimension':
layerInfo.sort((item1, item2) => ('' + item1[field] + '.' + item1.f_table_schema + '.' + item1.f_table_name).localeCompare(item2[field] + '.' + item2.f_table_schema + '.' + item2.f_table_name));
break;
......@@ -64,7 +68,7 @@
if (!ascending) {
layerInfo.reverse();
}
table.innerHTML = '<tr><th>schema</th><th>name</th><th>geom_column</th><th>srid</th><th>geom_type</th><th>dim</th><th>count</th></tr>' +
table.innerHTML = '<tr><th>schema</th><th>name</th><th>geom_column</th><th>srid</th><th>geom_type</th><th>dim</th><th>type</th><th>count</th></tr>' +
layerInfo.map(item=>`<tr>
<td>${item.f_table_schema}</td>
<td><a href="tableinfo.html?table=${item.f_table_schema}.${item.f_table_name}&geom_column=${item.f_geometry_column}&srid=${item.srid}&geomtype=${item.type}&dimensions=${item.coord_dimension}&estimated_rows=${item.estimated_rows}">${item.f_table_name}</a></td>
......@@ -72,6 +76,7 @@
<td>${item.srid}</td>
<td>${item.type}</td>
<td>${item.coord_dimension}D</td>
<td>${item.table_type}</td>
<td>${item.estimated_rows}</td></tr>`).join('\n');
const tableHeaders = document.querySelectorAll('tr > th');
for (let i = 0; i < tableHeaders.length; i++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment