Commit 0a9d9246 authored by Anne Blankert's avatar Anne Blankert

better cache filenames, layer_columns uses schema

parent 120af7fb
......@@ -12,7 +12,8 @@ const sql = (params) => {
pg_class.oid = attrelid AND
relnamespace = pg_namespace.oid AND
attnum >= 1 AND
relname = '${params.table}'
relname = '${params.table}'
${params.schema?` AND nspname= '${params.schema}'`:''}
`
}
......@@ -40,25 +41,42 @@ module.exports = function (app, pool) {
* description: table not found or not accessible
*/
app.get('/data/layer_columns/:table', async (req, res)=> {
const sqlString = sql(req.params, req.query);
try {
const result = await pool.query(sqlString);
res.json(result.rows);
} catch (err) {
console.log(err);
let status = 500;
switch (err.code) {
case '42P01':
// table does not exist
status = 422;
break;
case '42703':
// column does not exist
status = 422;
break;
default:
let tableName, schemaName;
const table = req.params.table;
if (table) {
const parts = table.split('.');
if (parts.length === 1) {
tableName = parts[0];
schemaName = null;
} else {
schemaName = parts[0];
tableName = parts[1];
}
res.status(status).json({error:err.message})
req.params.table = tableName;
req.params.schema = schemaName;
const sqlString = sql(req.params, req.query);
try {
const result = await pool.query(sqlString);
res.json(result.rows);
} catch (err) {
console.log(err);
let status = 500;
switch (err.code) {
case '42P01':
// table does not exist
status = 422;
break;
case '42703':
// column does not exist
status = 422;
break;
default:
}
res.status(status).json({error:err.message})
}
} else {
res.status(422).json({error:"missing parameter 'table'"})
}
})
});
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
const sqlTableName = require('./utils/sqltablename.js');
const DirCache = require('./utils/dircache.js')
const cache = new DirCache('./cache/mvt');
const cache = new DirCache('./cache');
const sm = require('@mapbox/sphericalmercator');
const merc = new sm({
......@@ -10,8 +10,9 @@ const merc = new sm({
})
let cacheMiddleWare = async(req, res, next) => {
const cacheDir = `${req.params.datasource}/${req.params.z}/${req.params.x}/${req.params.y}`;
const key = (req.query.geom_column?req.query.geom_column:'geom') + req.query.columns?','+req.query.columns:'';
const cacheDir = `${req.params.datasource}/mvt/${req.params.z}/${req.params.x}/${req.params.y}`;
const key = ((req.query.geom_column?req.query.geom_column:'geom') + (req.query.columns?','+req.query.columns:''))
.replace(/[\W]+/g, '_');
const mvt = await cache.getCachedFile(cacheDir, key);
if (mvt) {
......
......@@ -24,7 +24,7 @@
document.querySelector('#tablename').innerHTML = fullTableName;
const parts = fullTableName.split('.');
const tableName = (parts.length > 1) ? parts[1] : parts[0];
fetch(`data/layer_columns/${tableName}`).then(response=>{
fetch(`data/layer_columns/${fullTableName}`).then(response=>{
const list = document.querySelector('#columns');
if (response.ok) {
response.json().then(json=> {
......
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