Dynexpr
Expression builder for dynamo DB.
Install
go get github.com/gauxs/dynexpr && go install github.com/gauxs/dynexpr/...@latest
Note: Dynexpr uses Go Modules to manage dependencies.
What is Dynexpr?
Dynexpr simplifies the creation of DynamoDB expressions by performing code generation on Go structs representing DynamoDB items. It offers convenient methods to generate expressions for DynamoDB, streamlining the process of building complex queries.
Usage
Con
// dynexpr:generate
type Transaction struct {
UserID *string `json:"user_id,omitempty" dynexpr:"partitionKey"`
TransactionID *string `json:"transaction_id,omitempty" dynexpr:"sortKey"`
Amount *int `json:"amount,omitempty"`
}
Configurations
dynexpr:generate
: should be declared over the struct which represents a single item of dynamoDB.
// dynexpr:generate
type DDBItem struct {
...
}
dynexpr:"partitionKey"
: to declare that the attribute is partion key of the dynamoDB item.
type DDBItem struct {
PK *string `json:"pk,omitempty" dynexpr:"partitionKey"`
...
}
dynexpr:"sortKey"
: to declare that the attribute is sort key of the dynamoDB item.
type DDBItem struct {
SK *string `json:"sk,omitempty" dynexpr:"sortKey"`
...
}
Q & A
Is this fit for your usecase?
License
The project is licensed under the MIT License.
Test
go run cmd/main.go -output_filename test/expression/data/person_dynexpr.go test/expression/data