-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using DynamoDB as an option for persistence #101
Conversation
Codecov Report
@@ Coverage Diff @@
## master #101 +/- ##
==========================================
+ Coverage 69.35% 70.47% +1.12%
==========================================
Files 80 86 +6
Lines 3455 3948 +493
==========================================
+ Hits 2396 2782 +386
- Misses 835 894 +59
- Partials 224 272 +48
Continue to review full report at Codecov.
|
fmt.Println(dynamoResult) | ||
for i, resp := range dynamoResult.Responses[dbName] { | ||
dp := dynamoPlayer{} | ||
// TODO unmarshalling a map doesn't work (i.e. the games) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is busted, and it looks like they don't have plans to support in v1. Might as well hop in on v2...
this V2 api is kind of bananas
…ongoToDynamo Conflicts: go.mod go.sum
gonna tackle the interaction service now
and some debug statements:#
jsonutils/gameUnmarshaller.go
Outdated
@@ -31,5 +31,17 @@ func UnmarshalGame(b []byte) (model.Game, error) { | |||
game.Actions[i] = pa | |||
} | |||
|
|||
if game.Hands == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's break this change out to a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want this to be as easy to understand and extend without being a pita but dynamo wasn't written for golang it seems
server/persistence/dynamo/utils.go
Outdated
func getConditionExpression( | ||
pkType condExprType, | ||
pk string, | ||
skType condExprType, | ||
sk string, | ||
) *string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function does some disparate things depending on the inputs; an empty pk
or sk
is not required with notExists
as compared to e.g. equalsID
where you do need to provide those. This makes it a little tough to mentally parse calling sites. I wonder if it'd benefit from taking a struct as a single input arg instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 I don't know if you'll like this idea since it's passing a lot of behavior around and it's kind of a lot of boilerplate -- but I kind of like this pattern as a way to provide composable options to a function
func getConditionExpression(opts ...conditionExpressionOption) *string {
opts := conditionExpressionOptions{}
for _, opt := range opts {
opts = opt(opts)
}
// do whatever with your options
}
type conditionExpressionOptions {
pkType condExprType
pk string
skType condExprType
sk string
}
type conditionExpressionOption func(opts conditionExpressionOptions) conditionExpressionOptions
func pkNotExists(opts conditionExpressionOptions) conditionExpressionOptions {
opts.pkType = notExists
return opts
}
func skHasPrefix(pref string) conditionExpressionOption {
return func(opts conditionExpressionOptions) conditionExpressionOptions {
opts.skType = hasPrefix
opts.sk = pref
return opts
}
}
// etc.
// calling sites
getConditionExpression(pkNotExists)
getConditionExpression(pkEquals(`def`), skHasPrefix(`abc`))
Finally finished my first pass |
Just one outstanding discussion I'd like to finish up before I go for a QA |
@cszczepaniak I think I've found a better way to express condition expressions that meets our needs without adding more complexity. let me know what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will QA a little later, but the code looks great
What broke / What you're adding
We have an in-memory DB, mysql DB, and mongodb DB. Unfornuately, in-memory is ephemeral, mysql is stood up in RDS and we pay for uptime, and I don't like mongodb. So let's add a DB that is pay-as-you-use and can store our games for us in aws.
How you did it
Add another set of services to talk to dynamodb using the AWS go sdk v2 (v1 is deprecated or something).
Also, stand up a local dynamodb instance in docker-compose so that you can test locally.
How to test it and how to try to break it
make dockerbuild
cribbage-server
toimage: cribbage:latest
.localhost:18080
and start playing a game