clarkie / dynogels

DynamoDB data mapper for node.js. Originally forked from https://github.com/ryanfitz/vogels

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

createtable necessary if the table already exists?

wuichen opened this issue · comments

do i have to call createtable everytime when i want to do create an item in an existing table? If not, how to do so? The only operation i need is CRUD on existing tables. im working on lambda functions.

Hi @wuichen, you don't need to call createTables on every call. If you can "guarantee" that the table is there and accessible by the Lambda function then you can just interact with it using query, scan, etc as needed.

@clarkie are there any examples showing how to do simple create without createTable?

Something like this?


const schema = {
  id: joi.string(),
  name: joi.string(),
};

const userTable = dynogels.define('user', {
  hashKey: 'id',
  timestamps: true,
  schema,
});

function create(user) {
  const id = uuid.v4();

  return userTable
    .createAsync(Object.assign({ id }, user))
    .then(console.log);
}