@libscout/kv-store v1.1.14
@libscout/kv-store
@libscout/kv-store - implements a hash-like interface for postgres
Table of Contents
Quick start
Install
npm
For module bundlers such as Webpack or Browserify.
npm types @libscout/kv-store
Usage
SQL
First of all, you have to create a table like this:
CREATE TABLE IF NOT EXISTS your_table_name
(
hash_name character varying COLLATE pg_catalog."default" NOT NULL,
key character varying COLLATE pg_catalog."default" NOT NULL,
val jsonb NOT NULL,
CONSTRAINT hash_pkey PRIMARY KEY (hash_name, key)
)
TABLESPACE pg_default;
ES6
import {IHash, PgHash} from "@libscout/kv-store"
enum HashName {
apples = "apples",
oranges = "oranges"
}
enum PgTable {
your_table_name = "your_table_name"
}
const pgUrl = "postgresql://postgres:1234@localhost:5432/test"
const store: IHash<HashName> = PgHash.getStore<HashName, PgTable>(pgUrl, PgTable.your_table_name)
await store.hSet(HashName.name, "key_name", "value")
The "value" can be of any type.
If you need to test your component that use PgHash, you can use MemoryHash to replace it. The MemoryHash class implements the same IHash interface.
import {IHash, MemoryHash} from "@libscout/kv-store"
enum HashName {
apples = "apples",
oranges = "oranges"
}
const store: IHash<HashName> = new MemoryHash()
await store.hSet(HashName.name, "key_name", "value")
© Nikolay Puliak
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago