headspacemeditation / beyonce Goto Github PK
View Code? Open in Web Editor NEWType-safe DynamoDB query builder for TypeScript. Designed with single-table architecture in mind.
License: Apache License 2.0
Type-safe DynamoDB query builder for TypeScript. Designed with single-table architecture in mind.
License: Apache License 2.0
I am using dataloader and I want to keep the type checking which Dataloader does support, that's why I find it it useful to export the keys types.
Also the returned value of the batchGet function is like so:
batchGet<T extends PartitionAndSortKey<TaggedModel>>(params: {
keys: T[];
consistentRead?: boolean;
}): Promise<GroupedModels<ExtractKeyType<T>>>;
Dataloader expects an array of Promises which makes it incompatible:
DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>
Yesterday I realised that there is no update Item, and trying to implement it myself was not straight forward, especially the conditional updates and the nested fields when you have lists and maps inside your model. On the same note as the Put ReturnValue, having the option to get the updated fields is also good.
I know you are pretty responsive and quick to add these, I realise that this feature may be the trickiest until now, Let me know if you wanna discuss it here, may be I'll make a PR.
For now I just exported the DocumentClient and made a plain update myself just to not get stuck.
The QueryExpressionBuilder doesn't support BETWEEN clause for sortKey.
Is there a way to do batch write with updates, puts and deletes ?
I think I red on the doc that conditional updates are not yet possible to ?!
Right now I am using the dynamodb client to make something like this work :
client.transactWrite({
TransactItems : [
{
"Put": {
"TableName": `${process.env.DATA_TABLE}`,
"Item": {
"pk": {"S": `${BeginsWith.User}-${userId}`},
"sk": {"S": `${BeginsWith.Friend}-${firendId}`},
"followedUser": {"S": userId},
"followingUser": {"S": firendId},
"timestamp": {"S": +new Date},
},
"ConditionExpression": "attribute_not_exists(sk)",
"ReturnValuesOnConditionCheckFailure": "ALL_OLD",
}
},
{
"Update": {
"TableName": `${process.env.DATA_TABLE}`,
"Key": {"pk": {"S": `${BeginsWith.User}-${firendId}`}, "sk": {"S": `${BeginsWith.User}-${firendId}`}},
"UpdateExpression": "SET followers = followers + :i",
"ExpressionAttributeValues": {":i": {"N": "1"}},
"ReturnValuesOnConditionCheckFailure": "ALL_OLD",
}
},
{
"Update": {
"TableName": `${process.env.DATA_TABLE}`,
"Key": {"pk": {"S": `${BeginsWith.User}-${userId}`}, "sk": {"S": `${BeginsWith.User}-${userId}`}},
"UpdateExpression": "SET following = following + :i",
"ExpressionAttributeValues": {":i": {"N": "1"}},
"ReturnValuesOnConditionCheckFailure": "ALL_OLD",
}
},
]
})
Thank you so much again for this library, Beyonce rocks !
I made my own contraption to do the same thing same table, but multiple types, I am using graphql, so the typescript classes are part of the entire app.
Is there a technical limitation why you went with the yaml model generation ? instead of typescript decorators ?
Again thank you so much for this
I was going to rework this project to use CircleCI instead of CodeShip, but the test suite is falling locally, as well as in CI.
The jest-dynamodb package is failing with this issue: shelfio/jest-dynamodb#212. But it's fairly out-of-date, so I couldn't easily try the workaround described in that issue.
I also tried migrating to https://github.com/freshollie/jest-dynalite, but was running into issues with that, as well:
FAIL src/test/dynamo/Beyonce.test.ts
● Beyonce › should put and delete in the same transaction
Failed: [UnknownOperationException: null]
111 | })
112 |
> 113 | it("should put and delete in the same transaction", async () => {
| ^
114 | await testPutAndDeleteItemInTransaction()
115 | })
116 |
at Env.it (node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:95:24)
at Suite.<anonymous> (src/test/dynamo/Beyonce.test.ts:113:3)
at Object.<anonymous> (src/test/dynamo/Beyonce.test.ts:18:1)
Hey Joshua,
I am opening new issues for tracking and to avoid that the other threads gets too long.
This query return undefined when there are no records for Book model.
import { BookModel } from "generated/models"
// Get all Books for an Author
const results = await beyonce
.query(BookModel.partitionKey({ authorId: "1" }))
.exec() // returns { Book: Book[] }
It would be best to return an empty array, since this is a Query(N) and not a Get(1).
I made a query using a partionkey, the constructed json query outputted by the beautiful Beyoncé is like this:
[AWS dynamodb 200 0.007s 0 retries] query({ TableName: 'test-dev',
KeyConditionExpression: '#pk = :pk',
ExpressionAttributeNames: { '#pk': 'pk' },
ExpressionAttributeValues: { ':pk': { S: 'USR-test' } } })
Why not just put ExpressionAttributeValues: { ':pk': 'USR-test' }
without the type ?
The current implementation of library does not support any delimiter other than "-".
It would be nice to make it dynamic and configurable in the yaml to support already created tables.
for eg. # (pound sign)
I think it would be very useful to add an argument to get the return value on inserted records with the default behaviour no return.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.