1.0.2 • Published 3 years ago

sekitsu v1.0.2

Weekly downloads
8
License
ISC
Repository
-
Last release
3 years ago

Sekitsu

Backend ops.

Prerequisites

  • Node v8.10+

Classes

DynamoDB

Use basic CRUD operations to interact with DynamoDB.

Set-up

Specify the apiVersion and region before making calls.

DynamoDB(apiVersion, region);

apiVersion: latest, 2015-03-31 (default), 2012-08-10, 2011-12-05

region: us-east-1 (default)

const sekitsu = require('sekitsu');

// Defaults to apiVersion = 2015-03-31 and region = us-east-1
const db = new sekitsu.DynamoDB();

Methods

METHODCRUD
createcreate
getread
scanread
updateupdate
removedelete

Examples

  • create

Creates a single item with specified fields. Fields must match the schema of the table (i.e. if id is a number, you cannot pass a string to id). Automatically adds a 'created' timestamp to the item. Specify 'false' in params.createdAt to prevent adding the timestamp.

Required keys: TableName, Item

const params = {
  TableName: 'my-table',
  Item: {
    id: 1,
    event: 'convert',
  },
};

try {
  // creates an item in the table 'my-table' with id = 1, event = 'convert', and
  // created = new Date().toISOString();
  await db.create(params);
} catch (error) {
  console.error(error);
}
  • get

Gets all items that match the filter. Works with GSIs. Returns an object with keys Items, Count, and ScannedCount.Items contains an array of objects that match the expression.Count and ScannedCount is the length of the Items array.

Required keys: TableName, KeyConditionExpression, ExpressionAttributeValues

const params = {
  TableName: 'my-other-table',
  KeyConditionExpression: 'id = :id',
  ExpressionAttributeValues: {
    ':id': 1,
  },
};
let records;

try {
  record = await db.get(params);
} catch (error) {
  console.error(error);
}
  • scan

Scans the entire table before filtering and returning all matching items.

Required keys: TableName

const params = {
  TableName: 'my-perfect-table',
};
let records;

try {
  // Returns all items in the table in the key Items.
  records = await db.scan(params);
} catch (error) {
  console.error(error);
}
  • update

Updates a single item in the database with the specified expression. Returns an object with the updated

Required keys: TableName, Key, UpdateExpression, ExpressionAttributeValues

const params = {
  TableName: 'my-special-table',
  Key: { id: 1 },
  UpdateExpression: 'set event = :event, name = :name',
  ExpressionAttributeValues: {
    ':event': 'convert',
    ':name': 'Billy',
  },
};

try {
  // Updates an item with id = 1 to have fields event = 'convert' and name = 'Billy'
  await db.update(params);
} catch (error) {
  console.error(error);
}
  • remove

Removes a single item from the database with the specified expression.

Required keys: TableName, Key

const params = {
  TableName: 'my-best-table',
  Key: {
    id: 1,
    name: 'Bob',
  },
};

try {
  // Deletes an item with the primary key id = 1 and sort key name = 'Bob'
  await db.remove(params);
} catch (error) {
  console.error(error);
}
1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago