Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
fordecyt_2019
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rodrigo Tapia-McClung
fordecyt_2019
Commits
0a9d9246
Commit
0a9d9246
authored
Aug 15, 2019
by
Anne Blankert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better cache filenames, layer_columns uses schema
parent
120af7fb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
24 deletions
+43
-24
layer_columns.js
layer_columns.js
+38
-20
mvt.js
mvt.js
+4
-3
tableinfo.html
public/tableinfo.html
+1
-1
No files found.
layer_columns.js
View file @
0a9d9246
...
@@ -12,7 +12,8 @@ const sql = (params) => {
...
@@ -12,7 +12,8 @@ const sql = (params) => {
pg_class.oid = attrelid AND
pg_class.oid = attrelid AND
relnamespace = pg_namespace.oid AND
relnamespace = pg_namespace.oid AND
attnum >= 1 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) {
...
@@ -40,25 +41,42 @@ module.exports = function (app, pool) {
* description: table not found or not accessible
* description: table not found or not accessible
*/
*/
app
.
get
(
'/data/layer_columns/:table'
,
async
(
req
,
res
)
=>
{
app
.
get
(
'/data/layer_columns/:table'
,
async
(
req
,
res
)
=>
{
const
sqlString
=
sql
(
req
.
params
,
req
.
query
);
let
tableName
,
schemaName
;
try
{
const
table
=
req
.
params
.
table
;
const
result
=
await
pool
.
query
(
sqlString
);
if
(
table
)
{
res
.
json
(
result
.
rows
);
const
parts
=
table
.
split
(
'.'
);
}
catch
(
err
)
{
if
(
parts
.
length
===
1
)
{
console
.
log
(
err
);
tableName
=
parts
[
0
];
let
status
=
500
;
schemaName
=
null
;
switch
(
err
.
code
)
{
}
else
{
case
'42P01'
:
schemaName
=
parts
[
0
];
// table does not exist
tableName
=
parts
[
1
];
status
=
422
;
break
;
case
'42703'
:
// column does not exist
status
=
422
;
break
;
default
:
}
}
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
mvt.js
View file @
0a9d9246
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
const
sqlTableName
=
require
(
'./utils/sqltablename.js'
);
const
sqlTableName
=
require
(
'./utils/sqltablename.js'
);
const
DirCache
=
require
(
'./utils/dircache.js'
)
const
DirCache
=
require
(
'./utils/dircache.js'
)
const
cache
=
new
DirCache
(
'./cache
/mvt
'
);
const
cache
=
new
DirCache
(
'./cache'
);
const
sm
=
require
(
'@mapbox/sphericalmercator'
);
const
sm
=
require
(
'@mapbox/sphericalmercator'
);
const
merc
=
new
sm
({
const
merc
=
new
sm
({
...
@@ -10,8 +10,9 @@ const merc = new sm({
...
@@ -10,8 +10,9 @@ const merc = new sm({
})
})
let
cacheMiddleWare
=
async
(
req
,
res
,
next
)
=>
{
let
cacheMiddleWare
=
async
(
req
,
res
,
next
)
=>
{
const
cacheDir
=
`
${
req
.
params
.
datasource
}
/
${
req
.
params
.
z
}
/
${
req
.
params
.
x
}
/
${
req
.
params
.
y
}
`
;
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
:
''
;
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
);
const
mvt
=
await
cache
.
getCachedFile
(
cacheDir
,
key
);
if
(
mvt
)
{
if
(
mvt
)
{
...
...
public/tableinfo.html
View file @
0a9d9246
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
document
.
querySelector
(
'#tablename'
).
innerHTML
=
fullTableName
;
document
.
querySelector
(
'#tablename'
).
innerHTML
=
fullTableName
;
const
parts
=
fullTableName
.
split
(
'.'
);
const
parts
=
fullTableName
.
split
(
'.'
);
const
tableName
=
(
parts
.
length
>
1
)
?
parts
[
1
]
:
parts
[
0
];
const
tableName
=
(
parts
.
length
>
1
)
?
parts
[
1
]
:
parts
[
0
];
fetch
(
`data/layer_columns/
${
t
ableName
}
`
).
then
(
response
=>
{
fetch
(
`data/layer_columns/
${
fullT
ableName
}
`
).
then
(
response
=>
{
const
list
=
document
.
querySelector
(
'#columns'
);
const
list
=
document
.
querySelector
(
'#columns'
);
if
(
response
.
ok
)
{
if
(
response
.
ok
)
{
response
.
json
().
then
(
json
=>
{
response
.
json
().
then
(
json
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment