Files
plainleaf/lib/data/dynamodb_kv_primitives.ts
T
MaksandGitHub 8a3782e946 improve dependency management (#770)
* use import_map.json instead of per-file import

* remove test_deps.ts in favor of import_map

* remove common/deps.ts in favor of import_map

* use import_map instead of server/deps.ts

* make all plug-api files usable without an import_map

* make all lib files usable without an import_map

* remove web/deps.ts in favor of import_map

* fix plug build

* remove plug-api/deps.ts in favor of lib/deps.ts

* fix server deps bundled in client deps
2024-03-16 15:29:24 +01:00

71 lines
1.8 KiB
TypeScript

import { KV, KvKey } from "../../plug-api/types.ts";
import { KvPrimitives, KvQueryOptions } from "./kv_primitives.ts";
import { createClient, DynamoDBClient } from "../deps_server.ts";
export type AwsOptions = {
accessKey: string;
secretKey: string;
region: string;
};
const keySeparator = "\0";
const batchReadSize = 100;
/**
* Start of an implementation, to be continued at some point
*/
export class DynamoDBKvPrimitives implements KvPrimitives {
client: DynamoDBClient;
partitionKey: string;
tableName: string;
constructor(tableName: string, partitionKey: string, options: AwsOptions) {
this.tableName = tableName;
this.partitionKey = partitionKey;
this.client = createClient({
credentials: {
accessKeyId: options.accessKey,
secretAccessKey: options.secretKey,
},
region: options.region,
});
}
batchGet(keys: KvKey[]): Promise<any[]> {
const allResults: any[] = [];
const promises: Promise<any>[] = [];
for (let i = 0; i < keys.length; i += batchReadSize) {
const batch = keys.slice(i, i + batchReadSize);
promises.push(
this.client.batchGetItem(
{
RequestItems: {
[this.tableName]: {
Keys: batch.map((key) => ({
pk: this.partitionKey,
sk: key.join(keySeparator),
})),
},
},
},
),
);
}
throw new Error("Method not implemented.");
}
batchSet(entries: KV[]): Promise<void> {
throw new Error("Method not implemented.");
}
batchDelete(keys: KvKey[]): Promise<void> {
throw new Error("Method not implemented.");
}
query(options: KvQueryOptions): AsyncIterableIterator<KV> {
throw new Error("Method not implemented.");
}
close(): void {
throw new Error("Method not implemented.");
}
}