dynmr
TypeScript icon, indicating that this package has built-in type declarations

2.0.0-alpha.6 • Public • Published

Dynmr is a library to use AWS DynamoDB type-safely.

Getting Started

npm i dynmr

Example

import { createDynmr, type DynmrSchema } from 'dynmr';

const config = {
  user: {
    id: { type: 'S', gsi: { readCapacityUnits: 2, writeCapacityUnits: 2 } },
    name: { type: 'S', optional: true },
    age: { type: 'N', gsi: {} },
    sex: { type: 'S', enum: ['male', 'female'] as const },
  },
} satisfies DynmrSchema;

const client = createDynmr(config, {
  clientConfig: {},
  tableName: 'xxx',
  options: {
    log: {
      query: true,
    },
  },
});

await client.user.$many({
  where: { OR: [{ id: { eq: 'xxx' } }, { name: { contains: 'foo' } }] },
  scanLimit: 10,
  gsi: 'id',
});
const user = await client.user.$one({
  where: { OR: [{ id: { eq: 'xxx' } }, { name: { contains: 'foo' } }] },
});

if (user == null) {
  throw new Error('user not found');
}

const updatedUser = await client.user.update({
  ...user,
  age: user.age + 1,
});

await client.user.$delete(updatedUser.__dynmrId);

Readme

Keywords

none

Package Sidebar

Install

npm i dynmr

Weekly Downloads

300

Version

2.0.0-alpha.6

License

MIT

Unpacked Size

121 kB

Total Files

114

Last publish

Collaborators

  • cubed-ten