Code Monkey home page Code Monkey logo

Comments (1)

brianleroux avatar brianleroux commented on June 5, 2024

So we created @begin/data to make it easier to get started with DynamoDB doing simple persistence tasks. This is a perfect use case!

@begin/data

There is only one database table for all the data defined in an .arc app that uses @begin/data. It is defined as follows:

@app 
myapp

@tables
data
  scopeID *String
  dataID **String
  ttl TTL

The .arc above defines a single DynamoDB table with a partition key of scopeID and a sort key of dataID. This table can optionally have items that expire by setting the ttl attribute on rows

From here on reading and writing is done completely in code. @begin/data methods always have a table attribute but under the hood this is a virtual table of data! I would model the system with separate tables. A good convention is to use plural form of the noun the table represents. I'm not entirely sure what Image represents so I'm just going to focus on the user/org/post nouns.

let data = require('@begin/data')

// create a new org
await data.set({
  table: 'orgs', 
  key: 'engineering'
})

// adds a brand new user (and will automatically create key)
let user = await data.set({
  table: 'users',
  org: 'engineering',
  name: 'brian'
})

let post = await data.set({
  table: `users-${user.key}`,
  title: 'my post',
  body: 'some wisdom here'
})

Let me know if this makes sense so far!

from begin-data.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.