Skip to content

Commit 2ac4542

Browse files
doublecompilegithub-actions
andauthored
feat: Database Client (#2)
* feat(security): add quoted identifiers and literals * feat: add ServerClient class * feat: add DatabaseClient class --------- Signed-off-by: github-actions <github-actions@github.com> Co-authored-by: github-actions <github-actions@github.com>
1 parent 0846225 commit 2ac4542

31 files changed

Lines changed: 798 additions & 70 deletions

.projen/deps.json

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

.projen/tasks.json

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

.projenrc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const project = new typescript.TypeScriptProject({
2525
bugsUrl: `${projectUrl}/issues`,
2626

2727
deps: ["pg"],
28-
devDeps: ["@jest/globals"],
28+
devDeps: ["@jest/globals", "@types/pg"],
2929

3030
minNodeVersion: "18.0.0",
3131
workflowNodeVersion: "18.18.2",

README.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ import { Login, Role, Catalog } from "@libreworks/db-provision-pgsql";
3434
const username = "example_user";
3535
const password = "🙈";
3636
const owner = new Login(username, password);
37+
3738
const admin = new Role("admin");
38-
const grants = [];
39-
grants.push(admin.assignTo(owner));
4039
const readers = new Role("readers");
40+
41+
const grants = [admin.assignTo(owner)];
4142
const catalog = new Catalog("my_database");
4243
const schema = catalog.createSchema(username, owner);
4344
grants.push(
@@ -65,17 +66,19 @@ console.log(statements.join(";\n") + ";\n");
6566
The above example outputs the following SQL statements:
6667

6768
```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;
69+
CREATE USER "example_user" WITH PASSWORD '🙈';
70+
CREATE ROLE "admin";
71+
CREATE ROLE "readers";
72+
CREATE DATABASE "my_database" ENCODING 'UTF8';
73+
CREATE SCHEMA IF NOT EXISTS "example_user" AUTHORIZATION "example_user";
74+
GRANT "admin" TO "example_user";
75+
GRANT CONNECT, TEMP ON DATABASE "my_database" TO "example_user";
76+
GRANT CONNECT, TEMP ON DATABASE "my_database" TO "readers";
77+
GRANT USAGE ON SCHEMA "example_user" TO "readers";
78+
GRANT SELECT ON ALL TABLES IN SCHEMA "example_user" TO "readers";
79+
GRANT SELECT ON ALL SEQUENCES IN SCHEMA "example_user" TO "readers";
80+
ALTER DEFAULT PRIVILEGES FOR USER "example_user" IN SCHEMA "example_user" GRANT SELECT ON TABLES TO "readers";
81+
ALTER DEFAULT PRIVILEGES FOR USER "example_user" IN SCHEMA "example_user" GRANT SELECT ON SEQUENCES TO "readers";
8182
```
83+
84+
Because all identifiers are quoted, that means the objects will be created using the same character casing as provided. Without double quotes, PostgreSQL creates objects with lowercase identifiers.

docs/assets/navigation.js

Lines changed: 1 addition & 1 deletion
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 & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/classes/Catalog.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)