Giter VIP home page Giter VIP logo

Comments (6)

michael-wolfenden avatar michael-wolfenden commented on September 26, 2024 7

If anyone wants an example of using this library, I have re-implemented Forrest Brazeal's Single Table Northwind example here ->

https://github.com/michael-wolfenden/dynamodb-toolbox-northwind

from dynamodb-toolbox.

Ankcorn avatar Ankcorn commented on September 26, 2024 3

I was thinking that too! I'm still quite uncomfortable with single table design so it is taking a little trial and error.

This library does so much lovely magic that makes working with DynamoDB so much more pleasant than I am used too.

I'm building a homebrew deployment pipeline tool and need a database to store the stuff I drew a little diagram of how the data model will fit together visually to help by brain start to think through how I can smoosh the entities into 1 table.

image

Followed up by a spreadsheet representation of how the data would look

image

I also have some entities (all very much a work in progress any feedback on them would be appreciated)

import { Table, Entity } from "dynamodb-toolbox";
import DynamoDB from "aws-sdk/clients/dynamodb";
const DocumentClient = new DynamoDB.DocumentClient({ region: 'us-east-1' });

export const Data = new Table({
    name: 'datastore-dev',
    partitionKey: 'pk',
    sortKey: 'sk',
    DocumentClient  
});

export const User = new Entity({
    name: 'User',
    attributes: {
        id: {  partitionKey: true },
        sk: { hidden: true, sortKey: true, default: () => 'user' },
        grt: { alias: 'githubRefreshToken' },
        ce: { alias: 'contactEmail' },
    },
    table: Data
});

export const Pipeline = new Entity({
    name: 'Pipeline',
    attributes: {
        pk: { hidden: true, partitionKey: true },
        userId: ['pk', 1],
        sk: { hidden: true, sortKey: true },
        config: { type: 'string' },
        mb: { alias: 'mainBranch' },
        type: ['sk', 0],
        id: ['sk', 1]
    },
    table: Data
});

export const Build = new Entity({
    name: 'Build',
    attributes: {
        pk: { hidden: true, partitionKey: true },
        sk: { hidden: true, sortKey: true },
        status: { type: 'string' },
        et: { alias: 'executionTime' },
        type: ['sk', 0],
        id: ['sk', 1],
        pipelineId: ['pk', 1]
    },
    table: Data
});

here are some simple queries puts and gets.

import { User, Build, Pipeline } from "./index"

describe('Data', () => {
    it('does the stuff', async () => {
        await User.put({
            id: '12345',
            githubRefreshToken: '1234',
            contactEmail: '[email protected]'
        });

        const user = await User.get({ id: '12345'});
        
        console.log(user)

//  console.log
//      {
//        Item: {
//          contactEmail: '[email protected]',
//          modified: '2020-06-23T21:56:21.940Z',
//          githubRefreshToken: '1234',
//          id: '12345',
//          entity: 'User',
//          created: '2020-06-23T21:56:21.940Z'
//        }
//      }

        await Pipeline.put({
            userId: '12345',
            type: 'pipeline',
            id: 'a1a1',
            mainBranch: 'main',
            config: 'I get paid to write yml, for fun I write matlab'
        });

        await Pipeline.put({
            userId: '12345',
            type: 'pipeline',
            id: 'b2b2',
            mainBranch: 'main',
            config: '🤘 do emoji\'s work in dynamodb'
        });

        const pipelines = await Pipeline.query('12345', { beginsWith: 'build'})
        console.log(pipelines);

// console.log
//     {
//       Items: [
//         {
//           modified: '2020-06-23T21:56:22.794Z',
//           mainBranch: 'main',
//           config: 'I get paid to write yml, for fun I write matlab',
//           userId: '12345',
//           id: 'a1a1',
//           entity: 'Pipeline',
//           created: '2020-06-23T21:56:22.794Z',
//           type: 'pipeline'
 //        },
//         {
//           modified: '2020-06-23T21:56:23.096Z',
//           mainBranch: 'main',
//           config: "🤘 do emoji's work in dynamodb",
//           userId: '12345',
//           id: 'b2b2',
//           entity: 'Pipeline',
//           created: '2020-06-23T21:56:23.096Z',
//           type: 'pipeline'
//         }
//       ],
//       Count: 2,
//       ScannedCount: 2
//     }


        await Build.put({
            pipelineId: 'b2b2',
            id: 'cccc',
            type: 'build',
            status: 'success',
            executionTime: 93
        })

        const build = await Build.get({
            pipelineId: 'b2b2',
            id: 'cccc',
            type: 'build'
        })

        console.log(build);

//  console.log
//     {
//       Item: {
//         executionTime: '93',
//         modified: '2020-06-23T21:54:03.102Z',
//         status: 'success',
//         pipelineId: 'b2b2',
//         id: 'cccc',
//         entity: 'Build',
//         created: '2020-06-23T21:54:03.102Z',
//         type: 'build'
//       }
//     }
//     })    
// })

Finally here is what it all looks like in dynamodb afterwards

image

With a little bit of refinement, I hope this could be a good start for an example app 🐶 (emojis do work in dynamodb)

from dynamodb-toolbox.

jeremydaly avatar jeremydaly commented on September 26, 2024

Hey everyone. Thanks for the question and feedback. I'm trying to get the library stable first, but an example app would be super helpful. @Ankcorn looks like he has a great start. I'm sure there are several simple examples that could be put together as well. I've got it on my list.

from dynamodb-toolbox.

joedevgee avatar joedevgee commented on September 26, 2024

I like that you are always trying to keep things simple. Do you think lambda-api and this library is a good fit together? If so, would like to see how you would recommend using them together

from dynamodb-toolbox.

jeremydaly avatar jeremydaly commented on September 26, 2024

I like that you are always trying to keep things simple. Do you think lambda-api and this library is a good fit together? If so, would like to see how you would recommend using them together

Lambda API needs some more work (like v2 payload support for HTTP APIs), but libraries do work well together.

I always create a Data Access Layer (DAL) for my projects, which abstracts the data model into simple calls like getUser, getOrders, getOrderById, setUser, etc. I built this library to help me build my DALs faster.

from dynamodb-toolbox.

Easy-Cloud-in avatar Easy-Cloud-in commented on September 26, 2024

hi, let me know how to use next() for pagination.

from dynamodb-toolbox.

Related Issues (20)

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.