Comments (6)
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.
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.
Followed up by a spreadsheet representation of how the data would look
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
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.
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.
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.
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.
hi, let me know how to use next() for pagination.
from dynamodb-toolbox.
Related Issues (20)
- Recent versions do not run onDefault if dependsOn contains undefined parameter HOT 2
- Got Error: Please provide a valid entity definition HOT 2
- Created is changing with puts and is always the same as modified HOT 1
- Is `transform` valid for partition key? HOT 2
- Unable to convert date string to JS Date instance
- getting error for formatter.missingAttribute when using computeKey function to build pk and sk HOT 3
- Unable to save null values in V1 HOT 9
- Type inference for query responses with multiple entities HOT 3
- V1 Migration BatchGetCommand type mismatch HOT 5
- Suggestion: date() type HOT 3
- DeleteItemCommand getting empty input for computedKey HOT 4
- Cannot define index with only `partitionKey` in v1.1 HOT 3
- Application built with esbuild possibly broken after `experimentalDecorators` was activated HOT 4
- $add signature for Sets not matching documentation HOT 2
- EQ operator missing from Range Conditions HOT 2
- Unable to match expression attribute path with schema HOT 2
- Suggestion: Allow enums on enum type HOT 2
- Link should apply for put and update by default HOT 1
- Unable to update Map item for optional Map HOT 3
- Extending v1 Entity HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dynamodb-toolbox.