@opengis/fastify-table 1.0.93 → 1.0.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Changelog.md +8 -0
- package/index.js +1 -1
- package/package.json +1 -1
- package/pg/funcs/getMeta.js +27 -27
package/Changelog.md
CHANGED
package/index.js
CHANGED
|
@@ -43,7 +43,7 @@ async function plugin(fastify, opt) {
|
|
|
43
43
|
fastify.decorate('getFolder', (req, type = 'server') => {
|
|
44
44
|
if (!['server', 'local'].includes(type)) throw new Error('params type is invalid');
|
|
45
45
|
const types = { local: req.root || config.root, server: req.mapServerRoot || config.mapServerRoot };
|
|
46
|
-
const filepath = path.posix.join(types[type] ||
|
|
46
|
+
const filepath = path.posix.join(types[type] || `/data/local/${req.pg?.options?.database || ''}`, req.folder || config.folder || '');
|
|
47
47
|
return filepath;
|
|
48
48
|
});
|
|
49
49
|
|
package/package.json
CHANGED
package/pg/funcs/getMeta.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
// import pgClient from '../pgClients.js';
|
|
2
|
-
import getPG from './getPG.js';
|
|
3
|
-
|
|
4
|
-
const data = {};
|
|
5
|
-
|
|
6
|
-
// decorator
|
|
7
|
-
export default async function getMeta(opt) {
|
|
8
|
-
const pg = opt.pg || getPG({ name: 'client' });
|
|
9
|
-
const table = opt.table || opt;
|
|
10
|
-
|
|
11
|
-
if (data[table]) return data[table];
|
|
12
|
-
|
|
13
|
-
if (!pg.tlist?.includes(table)) {
|
|
14
|
-
return { error: `${table} - not found`, status: 400 };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const { fields } = await pg.query(`select * from ${table} where $1=$1 limit 0`, [1]);
|
|
18
|
-
const { pks1 } = await pg.one(`SELECT json_object_agg(c.conrelid::regclass, a.attname) as pks1 FROM pg_constraint c
|
|
19
|
-
left join pg_attribute a on c.conrelid=a.attrelid and a.attnum = c.conkey[1] WHERE c.contype='p'::"char"`, { cache: 0 });
|
|
20
|
-
const pk = pks1[table];
|
|
21
|
-
|
|
22
|
-
const geomAttr = fields.find((el) => pg.pgType[el.dataTypeID] === 'geometry')?.name; // change geometry text to geometry code
|
|
23
|
-
|
|
24
|
-
const res = { pk, columns: fields, geom: geomAttr };
|
|
25
|
-
data[table] = res;
|
|
26
|
-
return res;
|
|
27
|
-
}
|
|
1
|
+
// import pgClient from '../pgClients.js';
|
|
2
|
+
import getPG from './getPG.js';
|
|
3
|
+
|
|
4
|
+
const data = {};
|
|
5
|
+
|
|
6
|
+
// decorator
|
|
7
|
+
export default async function getMeta(opt) {
|
|
8
|
+
const pg = opt.pg || getPG({ name: 'client' });
|
|
9
|
+
const table = opt.table || opt;
|
|
10
|
+
|
|
11
|
+
if (data[table]) return data[table];
|
|
12
|
+
|
|
13
|
+
if (!pg.tlist?.includes(table)) {
|
|
14
|
+
return { error: `${table} - not found`, status: 400 };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { fields } = await pg.query(`select * from ${table} where $1=$1 limit 0`, [1]);
|
|
18
|
+
const { pks1 } = await pg.one(`SELECT json_object_agg(c.conrelid::regclass, a.attname) as pks1 FROM pg_constraint c
|
|
19
|
+
left join pg_attribute a on c.conrelid=a.attrelid and a.attnum = c.conkey[1] WHERE c.contype='p'::"char"`, { cache: 0 });
|
|
20
|
+
const pk = table.startsWith('public.') ? pks1[table.replace('public.', '')] : pks1[table];
|
|
21
|
+
|
|
22
|
+
const geomAttr = fields.find((el) => pg.pgType[el.dataTypeID] === 'geometry')?.name; // change geometry text to geometry code
|
|
23
|
+
|
|
24
|
+
const res = { pk, columns: fields, geom: geomAttr };
|
|
25
|
+
data[table] = res;
|
|
26
|
+
return res;
|
|
27
|
+
}
|