@stash-it/postgresql-adapter v0.1.0
@stash-it/postgresql-adapter
@stash-it/postgresql-adapter
is a simple redis adapter that can be used with @stash-it/stash-it
.
It uses pg
package under the hood.
Installation
npm
npm install @stash-it/postgresql-adapter
deno
deno add @stash-it/postgresql-adapter
yarn
yarn dlx jsr add @stash-it/postgresql-adapter
pnpm
pnpm dlx jsr add @stash-it/postgresql-adapter
bun
bunx jsr add @stash-it/postgresql-adapter
Usage
// Import stash-it main class.
import { StashIt } from "@stash-it/stash-it";
import { PostgreSqlAdapter } from "@stash-it/postgresql-adapter";
// Create an instance of the adapter. Use whatever configuration your PostgreSQL instance runs on.
const adapter = new PostgreSqlAdapter({
connection: {
host: "localhost",
user: "user",
password: "password",
database: "dbname",
port: 5432, // optional property, if not set, this value is used
},
// The whole "table" configuration is optional
// So are the properties of this object.
// If not provided, those values are used and expected.
table: {
tableName: "items",
keyColumnName: "key",
valueColumnName: "value",
extraColumnName: "extra",
},
});
// And use it with stash-it.
const stash = new StashIt(adapter);
Table schema
If you don't have a table ready, you can use this query to create one. This is the expected schema.
CREATE TABLE "items" (
"key" TEXT PRIMARY KEY,
"value" JSONB NOT NULL,
"extra" JSONB NOT NULL
)
Development/testing
Running tests locally
Make sure to have .env
file with those variables (and your values):
POSTGRES_CONTAINER_NAME='postgresql_container'
POSTGRES_DATABASE="dbname"
POSTGRES_PASSWORD="password"
POSTGRES_USER="user"
POSTGRES_PORT="5432"
And then execute pnpm test
.
The tests you will run do all sorts of checks to verify if the adapter is capable of conducting CRUD operations.
If you want, you can target different DBs in different environments and run the tests against them. The test suite will clean up after self (or at least attempt), as it is designed to add numerous data, check if it is readable, and eventually it's removed.
License
MIT
Contribution
Feel free to open an issue or a pull request.
7 months ago