Skip to content

Commit b566fb9

Browse files
committed
feat: Initial commit
1 parent 7771863 commit b566fb9

26 files changed

+4167
-2
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# PostgreSQL database URL for development
2+
QUICKPOSTGRES_DEV_POSTGRES_URL=postgresql://postgres:<password>@localhost:5432/postgres

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

.eslintrc.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
env: {
3+
es2021: true,
4+
node: true,
5+
},
6+
extends: [
7+
"eslint:recommended",
8+
"plugin:@typescript-eslint/recommended",
9+
"prettier",
10+
],
11+
parser: "@typescript-eslint/parser",
12+
parserOptions: {
13+
ecmaVersion: 2017,
14+
sourceType: "module",
15+
},
16+
plugins: ["@typescript-eslint", "prefer-arrow"],
17+
rules: {
18+
"no-var": "error",
19+
"sort-imports": "error",
20+
"prefer-arrow-callback": "error",
21+
"no-warning-comments": "warn",
22+
"prefer-arrow/prefer-arrow-functions": "error",
23+
"@typescript-eslint/no-explicit-any": "off",
24+
},
25+
};

.github/workflows/publish-dev.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: NPM Publish (Dev)
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
npm-publish-dev:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout repository
11+
uses: actions/checkout@v2
12+
13+
- name: Install Node 16
14+
uses: actions/setup-node@v2
15+
with:
16+
node-version: 16
17+
cache: npm
18+
registry-url: https://registry.npmjs.org/
19+
20+
- name: Install dependencies
21+
run: npm ci
22+
23+
- name: Run final tests
24+
# npm run test is excluded here intentionally
25+
run: npm run eslint && npm run prettier
26+
27+
- name: Deprecate old versions
28+
run: npm deprecate quickpostgres@"~$(jq --raw-output '.version' package.json)" "no longer supported" || true
29+
env:
30+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
31+
32+
- name: Publish
33+
run: |
34+
npm version --git-tag-version=false $(jq --raw-output '.version' package.json).$(date +%s).$(git rev-parse --short HEAD)
35+
npm publish --tag dev || true
36+
env:
37+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/publish.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: NPM Publish (Release)
2+
on:
3+
release:
4+
types: [pubished]
5+
jobs:
6+
npm-publish:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout repository
10+
uses: actions/checkout@v2
11+
with:
12+
ref: ${{ github.event.release.target_commitish }}
13+
14+
- name: Install Node 16
15+
uses: actions/setup-node@v2
16+
with:
17+
node-version: 16
18+
cache: npm
19+
registry-url: https://registry.npmjs.org/
20+
21+
- name: Install dependencies
22+
run: npm ci
23+
24+
- run: git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
25+
- run: git config --global user.name "github-actions"
26+
27+
- name: Run final tests
28+
# npm run test is excluded here intentionally
29+
run: npm run eslint && npm run prettier
30+
31+
- name: Version package
32+
run: npm version ${{ github.event.release.tag_name }}
33+
34+
- name: Publish to NPM
35+
run: npm publish
36+
env:
37+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
38+
39+
- name: Push version changes to GitHub
40+
run: 'git push -m "chore(Release): bump version to ${{ github.event.release.tag_name }} for release"'
41+
env:
42+
github-token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Test
2+
on: [push, pull_request]
3+
jobs:
4+
lint:
5+
name: ESLint & Prettier
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout repository
9+
uses: actions/checkout@v2
10+
11+
- name: Install Node 16
12+
uses: actions/setup-node@v2
13+
with:
14+
node-version: 16
15+
cache: npm
16+
17+
- name: Install dependencies
18+
run: npm ci
19+
20+
- name: Run ESLint
21+
run: npm run lint
22+
23+
- name: Run Prettier
24+
run: npm run prettier
25+
26+
- name: Run Tests
27+
run: npm run test
28+
env:
29+
QUICKPOSTGRES_DEV_POSTGRES_URL: ${{ secrets.QUICKPOSTGRES_DEV_POSTGRES_URL }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
*.log
3+
*.logs
4+
dist
5+
.env

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

README.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,83 @@
1-
# quickpostgres
2-
An easy, beginner-friendly PostgreSQL database wrapper similar to quick.db.
1+
# [Quickpostgres](https://npmjs.com/package/quickpostgres)
2+
3+
An easy, beginner-friendly [PostgreSQL](https://www.postgresql.org/) database wrapper similar to [quick.db](https://github.com/lorencerri/quick.db).
4+
5+
## Installation
6+
7+
<!-- You can easily install quickpostgres using your preferred package manager.
8+
9+
```bash
10+
npm install quickpostgres
11+
# or
12+
yarn add quickpostgres
13+
# or
14+
pnpm add quickpostgres
15+
``` -->
16+
17+
Not yet published.
18+
19+
## Requirements
20+
21+
- Node.js 14 or above
22+
- A PostgreSQL database
23+
24+
## Usage
25+
26+
Quickpostgres has similar (if not almost identical) syntax to [quick.db](https://github.com/lorencerri/quick.db). You can refer to their [documentation](https://quickdb.js.org/) if you are getting stuck.
27+
28+
> Note: Quickpostgres is built on top of promises, meaning you need to resolve them first using `.then()` or `await` to get their returned data.
29+
30+
```js
31+
// Import quickpostgres
32+
const { Client } = require("quickpostgres");
33+
34+
// Create a new client using the default values on localhost
35+
const dbUrl = "postgresql://postgres:<password>@localhost:5432/postgres";
36+
const db = new Client(dbUrl);
37+
38+
(async () => {
39+
// Connect to your client
40+
await db.connect();
41+
42+
// Setting an object in the database:
43+
await db.set("userInfo", { difficulty: "Easy" });
44+
// => { difficulty: "Easy" }
45+
46+
// Pushing an element to an array (that doesn't exist yet) in an object:
47+
await db.push("userInfo.items", "Sword");
48+
// => { difficulty: "Easy", items: ["Sword"] }
49+
50+
// Adding to a number (that doesn"t exist yet) in an object:
51+
await db.add("userInfo.balance", 500);
52+
// => { difficulty: "Easy", items: ["Sword"], balance: 500 }
53+
54+
// Repeating previous examples:
55+
await db.push("userInfo.items", "Watch");
56+
// => { difficulty: "Easy", items: ["Sword", "Watch"], balance: 500 }
57+
await db.add("userInfo.balance", 500);
58+
// => { difficulty: "Easy", items: ["Sword", "Watch"], balance: 1000 }
59+
60+
// Fetching individual properties
61+
await db.get("userInfo.balance"); // => 1000
62+
await db.get("userInfo.items"); // ["Sword", "Watch"]
63+
64+
// End the database connection
65+
await db.end();
66+
})();
67+
```
68+
69+
## Support
70+
71+
For now, please use [GitHub discussions](https://github.com/GodderE2D/quickpostgres/discussions) if you need any support.
72+
73+
I may consider opening a Discord support server soon, but this is not guranteed.
74+
75+
## Contributing
76+
77+
If you spot a bug or you have a feature request, please open a [GitHub issue](https://github.com/GodderE2D/quickpostgres/issues), or if you'd like to write some code, you can open a [pull request](https://github.com/GodderE2D/quickpostgres/pulls).
78+
79+
If you spot a security vulnerability, please [contact me](mailto:[email protected]).
80+
81+
## License
82+
83+
[Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0)

0 commit comments

Comments
 (0)