Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/util/db-schema/pg-system.ts
1447 views
1
/*
2
Read access to some PostgreSQL system-level tables for admins.
3
4
Right now:
5
6
- Virtual tables to count the number of entries in any table.
7
These counts are instantly computed but are only approximations. See
8
https://stackoverflow.com/questions/7943233/fast-way-to-discover-the-row-count-of-a-table-in-postgresql/7945274#7945274
9
10
E.g., from browser in dev mode, this counts the number of patches instantly... but only approximately:
11
12
(await cc.client.async_query({query:{pg_class:{reltuples:null,relname:'patches'}}})).query.pg_class
13
14
*/
15
import { Table } from "./types";
16
17
Table({
18
name: "pg_class",
19
fields: {
20
reltuples: {
21
type: "number",
22
},
23
relname: {
24
type: "string",
25
},
26
},
27
rules: {
28
primary_key: "relname",
29
desc: "A useful system table for approximate count of size of table",
30
external: true, // this is a built in external system table
31
user_query: {
32
get: {
33
admin: true,
34
pg_where: [],
35
fields: {
36
reltuples: null,
37
relname: null,
38
},
39
},
40
},
41
},
42
});
43
44