Skip to content

Super simple, model-less DynamoDB wrapper

License

Notifications You must be signed in to change notification settings

marvin-j97/tunisia

Repository files navigation

tunisia

Super simple, typesafe DynamoDB query builder.

TS ready ESM ready npm version codecov

Install

pnpm install tunisia
yarn add tunisia
npm install tunisia
import { Client } from "tunisia";

const client = new Client({
  // Client options (region, credentials, etc.)
});

type Person = {
  id: string;
  firstName: string;
  age: number;
};

const personTable = client.defineTable<Person>("tunisia_persons");

Examples

Insert item

const item = {
  id: "ab7bc4d5-45a8-4de2-b1da-0f274a0f6c0a",
  firstName: "Jess",
  age: 32,
};
await personTable.put().one(item);

Get by ID

const item = await personTable.query(({ eq }) => eq("id", "abc")).first();

Update property

await personTable.update().set("name", "Updated").one("id", "abc");

Delete item

await personTable.delete().one("id", "abc");

Iterate through index

const iterator = tunisia
  .query(({ eq }) => eq("id", "abc"))
  .index("secondary-index")
  .iter();

for await (const { items } of iterator) {
  console.log(items);
}

Count

const count = tunisia
  .query(({ eq }) => eq("id", "abc"))
  .index("secondary-index")
  .count();