Skip to content

Commit f99e93e

Browse files
committed
chore(docs): changes before initial release
1 parent f00a137 commit f99e93e

24 files changed

Lines changed: 4129 additions & 11 deletions

README.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,81 @@
1-
# replace this
1+
# @libreworks/db-provision-pgsql
2+
3+
[![MIT](https://img.shields.io/github/license/libreworks/db-provision-pgsql)](https://github.com/libreworks/db-provision-pgsql/blob/main/LICENSE)
4+
[![npm](https://img.shields.io/npm/v/@libreworks/db-provision-pgsql)](https://www.npmjs.com/package/@libreworks/db-provision-pgsql)
5+
[![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/libreworks/db-provision-pgsql/release/main?label=release)](https://github.com/libreworks/db-provision-pgsql/actions/workflows/release.yml)
6+
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/libreworks/db-provision-pgsql?sort=semver)](https://github.com/libreworks/db-provision-pgsql/releases)
7+
[![codecov](https://codecov.io/gh/libreworks/db-provision-pgsql/branch/main/graph/badge.svg?token=OHTRGNTSPO)](https://codecov.io/gh/libreworks/db-provision-pgsql)
8+
9+
Provision databases and schemas in PostgreSQL along with roles, logins, and grants.
10+
11+
## Installation
12+
13+
```shell
14+
npm install @libreworks/db-provision-pgsql
15+
```
16+
17+
This library conforms to ECMAScript Modules (ESM). You can import this module using ESM or TypeScript syntax.
18+
19+
```TypeScript
20+
import { Catalog } from "@libreworks/db-provision-pgsql";
21+
```
22+
23+
If you're using CommonJS, you must use [dynamic imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) instead.
24+
25+
## Usage
26+
27+
You can use this library to perform initialization of a PostgreSQL database server (version 11 and later). For example, creating databases, schemas, roles, users, and grants.
28+
29+
Here is an example to provision several database objects.
30+
31+
```typescript
32+
import { Login, Role, Catalog } from "@libreworks/db-provision-pgsql";
33+
34+
const username = "example_user";
35+
const password = "🙈";
36+
const owner = new Login(username, password);
37+
const admin = new Role("admin");
38+
const grants = [];
39+
grants.push(admin.assignTo(owner));
40+
const readers = new Role("readers");
41+
const catalog = new Catalog("my_database");
42+
const schema = catalog.createSchema(username, owner);
43+
grants.push(
44+
catalog.grant(owner, "CONNECT", "TEMP"),
45+
catalog.grant(readers, "CONNECT", "TEMP"),
46+
schema.grant(readers, "USAGE"),
47+
schema.allTables().grant(readers, "SELECT"),
48+
schema.allSequences().grant(readers, "SELECT"),
49+
schema.setDefaultTablePrivileges(readers, "SELECT").forCreator(owner),
50+
schema.setDefaultSequencePrivileges(readers, "SELECT").forCreator(owner)
51+
);
52+
53+
// Display the SQL
54+
const statements = [
55+
owner,
56+
admin,
57+
readers,
58+
catalog,
59+
schema,
60+
...grants,
61+
].map((v) => v.toSql());
62+
console.log(statements.join(";\n") + ";\n");
63+
```
64+
65+
The above example outputs the following SQL statements:
66+
67+
```sql
68+
CREATE USER example_user WITH PASSWORD '🙈';
69+
CREATE ROLE admin;
70+
CREATE ROLE readers;
71+
CREATE DATABASE my_database ENCODING 'UTF8';
72+
CREATE SCHEMA IF NOT EXISTS example_user AUTHORIZATION example_user;
73+
GRANT admin TO example_user;
74+
GRANT CONNECT, TEMP ON DATABASE my_database TO example_user;
75+
GRANT CONNECT, TEMP ON DATABASE my_database TO readers;
76+
GRANT USAGE ON SCHEMA example_user TO readers;
77+
GRANT SELECT ON ALL TABLES IN SCHEMA example_user TO readers;
78+
GRANT SELECT ON ALL SEQUENCES IN SCHEMA example_user TO readers;
79+
ALTER DEFAULT PRIVILEGES FOR USER example_user IN SCHEMA example_user GRANT SELECT ON TABLES TO readers;
80+
ALTER DEFAULT PRIVILEGES FOR USER example_user IN SCHEMA example_user GRANT SELECT ON SEQUENCES TO readers;
81+
```

docs/.nojekyll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.

docs/assets/highlight.css

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
:root {
2+
--light-hl-0: #795E26;
3+
--dark-hl-0: #DCDCAA;
4+
--light-hl-1: #000000;
5+
--dark-hl-1: #D4D4D4;
6+
--light-hl-2: #A31515;
7+
--dark-hl-2: #CE9178;
8+
--light-hl-3: #AF00DB;
9+
--dark-hl-3: #C586C0;
10+
--light-hl-4: #001080;
11+
--dark-hl-4: #9CDCFE;
12+
--light-hl-5: #0000FF;
13+
--dark-hl-5: #569CD6;
14+
--light-hl-6: #0070C1;
15+
--dark-hl-6: #4FC1FF;
16+
--light-hl-7: #008000;
17+
--dark-hl-7: #6A9955;
18+
--light-hl-8: #EE0000;
19+
--dark-hl-8: #D7BA7D;
20+
--light-code-background: #FFFFFF;
21+
--dark-code-background: #1E1E1E;
22+
}
23+
24+
@media (prefers-color-scheme: light) { :root {
25+
--hl-0: var(--light-hl-0);
26+
--hl-1: var(--light-hl-1);
27+
--hl-2: var(--light-hl-2);
28+
--hl-3: var(--light-hl-3);
29+
--hl-4: var(--light-hl-4);
30+
--hl-5: var(--light-hl-5);
31+
--hl-6: var(--light-hl-6);
32+
--hl-7: var(--light-hl-7);
33+
--hl-8: var(--light-hl-8);
34+
--code-background: var(--light-code-background);
35+
} }
36+
37+
@media (prefers-color-scheme: dark) { :root {
38+
--hl-0: var(--dark-hl-0);
39+
--hl-1: var(--dark-hl-1);
40+
--hl-2: var(--dark-hl-2);
41+
--hl-3: var(--dark-hl-3);
42+
--hl-4: var(--dark-hl-4);
43+
--hl-5: var(--dark-hl-5);
44+
--hl-6: var(--dark-hl-6);
45+
--hl-7: var(--dark-hl-7);
46+
--hl-8: var(--dark-hl-8);
47+
--code-background: var(--dark-code-background);
48+
} }
49+
50+
:root[data-theme='light'] {
51+
--hl-0: var(--light-hl-0);
52+
--hl-1: var(--light-hl-1);
53+
--hl-2: var(--light-hl-2);
54+
--hl-3: var(--light-hl-3);
55+
--hl-4: var(--light-hl-4);
56+
--hl-5: var(--light-hl-5);
57+
--hl-6: var(--light-hl-6);
58+
--hl-7: var(--light-hl-7);
59+
--hl-8: var(--light-hl-8);
60+
--code-background: var(--light-code-background);
61+
}
62+
63+
:root[data-theme='dark'] {
64+
--hl-0: var(--dark-hl-0);
65+
--hl-1: var(--dark-hl-1);
66+
--hl-2: var(--dark-hl-2);
67+
--hl-3: var(--dark-hl-3);
68+
--hl-4: var(--dark-hl-4);
69+
--hl-5: var(--dark-hl-5);
70+
--hl-6: var(--dark-hl-6);
71+
--hl-7: var(--dark-hl-7);
72+
--hl-8: var(--dark-hl-8);
73+
--code-background: var(--dark-code-background);
74+
}
75+
76+
.hl-0 { color: var(--hl-0); }
77+
.hl-1 { color: var(--hl-1); }
78+
.hl-2 { color: var(--hl-2); }
79+
.hl-3 { color: var(--hl-3); }
80+
.hl-4 { color: var(--hl-4); }
81+
.hl-5 { color: var(--hl-5); }
82+
.hl-6 { color: var(--hl-6); }
83+
.hl-7 { color: var(--hl-7); }
84+
.hl-8 { color: var(--hl-8); }
85+
pre, code { background: var(--code-background); }

docs/assets/main.js

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/navigation.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/search.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)