@graffy/pg 0.15.18 → 0.15.19
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/Readme.md +26 -4
- package/package.json +2 -2
package/Readme.md
CHANGED
|
@@ -2,19 +2,41 @@
|
|
|
2
2
|
|
|
3
3
|
The standard Postgres module for Graffy. Each instance this module mounts a Postgres table as a Graffy subtree.
|
|
4
4
|
|
|
5
|
+
Requires the [pg](https://github.com/brianc/node-postgres) library to be installed as a peer dependency.
|
|
6
|
+
|
|
5
7
|
## Usage
|
|
6
8
|
|
|
7
9
|
```js
|
|
8
10
|
import pg from '@graffy/pg';
|
|
11
|
+
import Graffy from '@graffy/core';
|
|
12
|
+
import link from '@graffy/link';
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
const store = new Graffy();
|
|
15
|
+
store.use(path, pg(options));
|
|
11
16
|
```
|
|
12
17
|
|
|
13
|
-
|
|
18
|
+
### Options
|
|
19
|
+
|
|
20
|
+
- `table`, the name of the table. If not provided, the last segment of the `path` is used. This table must exist.
|
|
21
|
+
- `idCol`: the name of the column to use as ID. Defaults to `id`. This column must exist and be the primary key or have a unique constraint.
|
|
22
|
+
- `verCol`: the name of the column to store the Graffy version number. This column must exist, and must have a `DEFAULT` SQL expression defined - this expression is evaluated to calculate the version number. Graffy versions must monotonically increase, so this expression is typically based on `CURRENT_TIMESTAMP`.
|
|
23
|
+
- `connection`: a [pg](https://github.com/brianc/node-postgres) Client or Pool object (recommended), or the arguments for constructing a new Pool object. Optional.
|
|
24
|
+
|
|
25
|
+
### Database connection
|
|
26
|
+
|
|
27
|
+
Graffy Postgres can be configured to use a specific pg.Client object on a per-request basis, by including a `pgClient` property on the read or write options. This is useful for implementing transactions, partitioning, row-level security, etc.
|
|
28
|
+
|
|
29
|
+
If no `pgClient` is provided for a particular operation, Graffy Postgres falls back to the "global" pg.Client or pg.Pool object defined in the `connection` parameter in the initialization options. If no `connection` parameter was passed, a new pg.Pool will be created using PSQL environment variables.
|
|
30
|
+
|
|
31
|
+
## Data model
|
|
32
|
+
|
|
33
|
+
Graffy Postgres interprets each property as the name of a column, except for `$count`, `$sum` etc. as described in the aggregation section below.
|
|
34
|
+
|
|
35
|
+
It also interprets the `$key` as specifying filtering, sorting, pagination and aggregation parameters.
|
|
14
36
|
|
|
15
|
-
###
|
|
37
|
+
### Filters
|
|
16
38
|
|
|
17
|
-
Query filters are
|
|
39
|
+
Query filters are JSON-based, somewhat like MongoDB.
|
|
18
40
|
|
|
19
41
|
1. Filters expressions follow a **property**, **operator**, **value** order. Values are scalar values (strings or numbers).
|
|
20
42
|
2. Property names are always object keys. They may be strings with dots `.`.
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graffy/pg",
|
|
3
3
|
"description": "The standard Postgres module for Graffy. Each instance this module mounts a Postgres table as a Graffy subtree.",
|
|
4
4
|
"author": "aravind (https://github.com/aravindet)",
|
|
5
|
-
"version": "0.15.
|
|
5
|
+
"version": "0.15.19",
|
|
6
6
|
"main": "./index.cjs",
|
|
7
7
|
"exports": {
|
|
8
8
|
"import": "./index.mjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"license": "Apache-2.0",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@graffy/common": "0.15.
|
|
19
|
+
"@graffy/common": "0.15.19",
|
|
20
20
|
"sql-template-tag": "^4.1.0",
|
|
21
21
|
"debug": "^4.3.3"
|
|
22
22
|
},
|