0.4.0 • Published 1 year ago

ukv v0.4.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

ukv

npm install ukv

Everything is Storage

A Store type has a general api which unifies the api format across many storage types

// Syn
interface Store {
  get(key: string): any;
  set(key: string, value: any): void;
  del(key: string): void;
  // list all keys
  list(): string[];
  // clear all keys
  burn(): void;
  // list all keys and values
  dump(): Record<string, any>;
}

Storage Types

LocalStorage/SessionStorage

import { LS, SS } from 'ukv/browser';

// use the methods directly
LS.get('key');
SS.list();

Cloudflare Workers KV

from Account i.e to use API:

import { CF } from 'ukv/cloudflare';

const cf = CF('ACCOUNT_ID', 'NAMESPACE_ID', 'API_KEY');

// use the methods directly
cf.set('key', 'value');
cf.list();

from Worker i.e to use KV

import { CF } from 'ukv/cloudflare';

const cf = CF(KVNAMESPACE);

// use the methods directly
cf.get('key');
cf.burn();

Turso DB

import { Turso } from 'ukv/turso';

const TABLE_NAME = 'notes';
const client = new Turso(TURSO_URL, TURSO_AUTH, TABLE_NAME);

// use the methods directly
client.set([
  { id: 'key', col1: 'value1', col2: 'value2' },
  { id: 'key2', col1: 'value3', col2: 'value3' }
]);

client.get('key');
client.list();

For safety .burn() will throw. Use .del() one by one instead. .list and .dump are identical here.

0.4.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago