clarkie / dynogels

DynamoDB data mapper for node.js. Originally forked from https://github.com/ryanfitz/vogels
Other
490 stars 110 forks source link

createtable necessary if the table already exists? #139

Closed wuichen closed 6 years ago

wuichen commented 6 years ago

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.

clarkie commented 6 years ago

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.

wuichen commented 6 years ago

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

clarkie commented 6 years ago

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);
}