@fedify/postgres
Version:
PostgreSQL drivers for Fedify
59 lines (58 loc) • 1.74 kB
text/typescript
import { KvKey, KvStore, KvStoreSetOptions } from "@fedify/fedify";
import { Sql } from "postgres";
//#region src/kv.d.ts
/**
* Options for the PostgreSQL key–value store.
*/
interface PostgresKvStoreOptions {
/**
* The table name to use for the key–value store.
* `"fedify_kv_v2"` by default.
* @default `"fedify_kv_v2"`
*/
tableName?: string;
/**
* Whether the table has been initialized. `false` by default.
* @default `false`
*/
initialized?: boolean;
}
/**
* A key–value store that uses PostgreSQL as the underlying storage.
*
* @example
* ```ts
* import { createFederation } from "@fedify/fedify";
* import { PostgresKvStore } from "@fedify/postgres";
* import postgres from "postgres";
*
* const federation = createFederation({
* // ...
* kv: new PostgresKvStore(postgres("postgres://user:pass@localhost/db")),
* });
* ```
*/
declare class PostgresKvStore implements KvStore {
#private;
/**
* Creates a new PostgreSQL key–value store.
* @param sql The PostgreSQL client to use.
* @param options The options for the key–value store.
*/
constructor(sql: Sql<{}>, options?: PostgresKvStoreOptions);
get<T = unknown>(key: KvKey): Promise<T | undefined>;
set(key: KvKey, value: unknown, options?: KvStoreSetOptions | undefined): Promise<void>;
delete(key: KvKey): Promise<void>;
/**
* Creates the table used by the key–value store if it does not already exist.
* Does nothing if the table already exists.
*/
initialize(): Promise<void>;
/**
* Drops the table used by the key–value store. Does nothing if the table
* does not exist.
*/
drop(): Promise<void>;
}
//#endregion
export { PostgresKvStore, PostgresKvStoreOptions };