1.1.14 • Published 2 years ago

@libscout/kv-store v1.1.14

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

@libscout/kv-store

@libscout/kv-store - implements a hash-like interface for postgres

npm version

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")

Modules

© Nikolay Puliak

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.61

2 years ago

1.0.60

2 years ago

1.0.57

2 years ago

1.0.56

2 years ago

1.0.55

2 years ago

1.0.54

2 years ago

1.0.53

2 years ago

1.0.52

2 years ago

1.0.51

2 years ago

1.0.50

2 years ago

1.0.45

2 years ago

1.0.44

2 years ago

1.0.41

2 years ago

1.0.40

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.36

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.8

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago