{"id":20853760,"url":"https://github.com/wolfeidau/dynastorev2","last_synced_at":"2025-05-12T05:31:39.869Z","repository":{"id":37953623,"uuid":"477258357","full_name":"wolfeidau/dynastorev2","owner":"wolfeidau","description":"This package provides a CRUD store for AWS DynamoDB","archived":false,"fork":false,"pushed_at":"2025-02-15T23:31:37.000Z","size":98,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-01T01:21:51.270Z","etag":null,"topics":["aws","dynamodb","go"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wolfeidau.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-03T06:33:30.000Z","updated_at":"2025-02-15T04:52:05.000Z","dependencies_parsed_at":"2024-06-19T20:04:32.374Z","dependency_job_id":"e57ad967-2c3d-4386-9e76-4dc0cc93f33d","html_url":"https://github.com/wolfeidau/dynastorev2","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfeidau%2Fdynastorev2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfeidau%2Fdynastorev2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfeidau%2Fdynastorev2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfeidau%2Fdynastorev2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wolfeidau","download_url":"https://codeload.github.com/wolfeidau/dynastorev2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253682248,"owners_count":21946902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","dynamodb","go"],"created_at":"2024-11-18T03:23:04.969Z","updated_at":"2025-05-12T05:31:39.209Z","avatar_url":"https://github.com/wolfeidau.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dynastorev2\n\nThis package provides a CRUD (create, read, update and delete) store for [Amazon DynamoDB](https://aws.amazon.com/dynamodb/) using the [AWS Go SDK v2](https://github.com/aws/aws-sdk-go-v2/).\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/wolfeidau/dynastorev2)](https://goreportcard.com/report/github.com/wolfeidau/dynastorev2)\n[![Documentation](https://godoc.org/github.com/wolfeidau/dynastorev2?status.svg)](https://godoc.org/github.com/wolfeidau/dynastorev2)\n\n# Overview\n\nThis is a rewrite of the original [dynastore](https://github.com/wolfeidau/dynastore) with the main differences being:\n\n1. It uses the Generics feature added in Go 1.18\n2. It is built on AWS Go SDK v2.\n3. The API has been simplified.\n4. I am still learning how to use Generics in Go...\n\n# Example\n\n```go\n\tctx := context.Background()\n\n\tcfg, err := config.LoadDefaultConfig(ctx)\n\tif err != nil {\n\t\t// handle error\n\t}\n\n\tclient = dynamodb.NewFromConfig(cfg)\n\tcustomerStore := dynastorev2.New[string, string, []byte](client, \"tickets-table\")\n\n\tfields := map[string]any{\n\t\t\"created\": time.Now().UTC().Round(time.Millisecond),\n\t}\n\n\tres, err := customerStore.Create(ctx,\n\t\t\"customer\",                                 // partition key\n\t\t\"01FCFSDXQ8EYFCNMEA7C2WJG74\",               // sort key\n\t\t[]byte(`{\"name\": \"Stax\"}`),                 // value, in this case JSON encoded value\n\t\tcustomerStore.WriteWithExtraFields(fields), // extra fields which could be indexed in the future\n\t)\n\tif err != nil {\n\t\t// handle error\n\t}\n\n\t// print out the version from the mutation result, this is used for optimistic locking\n\tfmt.Println(\"version\", res.Version)\n```\n\nCreates a record which looks like this in Amazon DynamoDB.\n\n| id (Partition Key) | name (Sort Key) | version | payload | expires | created |\n| --------------- | --------------- | --------------- | --------------- | --------------- | --------------- |\n| customer | 01FCFSDXQ8EYFCNMEA7C2WJG74 | 1 | `{\"name\": \"Stax\"}` | null | `2022-04-10T06:27:16.994Z` |\n\n**Note:** This library doesn't aim to provide a high level abstraction for Amazon DynamoDB, you will need to learn how it works to understand some of the limitations to use it successfully.\n\n# Implementation Tips\n\nBefore you get started i recommend you review some of the [code examples](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/service_code_examples.html) provided in the Amazon DynamoDB documentation.\n\n1. Don't use Amazon DynamoDB if you have anything beyond a simple K/V compatible model until you understand your [access patterns](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-modeling-nosql-B.html).\n2. Use a [single-table design](https://aws.amazon.com/blogs/compute/creating-a-single-table-design-with-amazon-dynamodb/) to model your data.\n3. Use [Universally Unique Lexicographically Sortable Identifier](https://github.com/ulid/spec) (ULID) for sort keys, this will help ensure a rational order of data in the table. Sort key by default is sorted in descending order, oldest first, newest last, exploiting this behaviour may mitigate some of the limitations with Amazon DynamoDB.\n4. If your using `WriteWithTTL` you need to deal with the fact that Amazon DynamoDB doesn't delete expired data straight away, records can hang around for up to [48 hours according to the documentation](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/howitworks-ttl.html).\n\n# Status\n\n* [x] Added CRUD with conditional checks and tests\n* [x] List with pagination\n* [x] [Optimistic Locking](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBMapper.OptimisticLocking.html) for Updates\n* [ ] Locking\n* [ ] Leasing\n\n# References\n\nPrior work in this space:\n\n* https://github.com/wolfeidau/dynastore\n* https://github.com/wolfeidau/dynalock\n* https://github.com/awslabs/dynamodb-lock-client\n* https://github.com/intercom/lease\n\nUpdates to the original API are based on a great blog post by @davecheney https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis\n\n# License\n\nThis code was authored by [Mark Wolfe](https://github.com/wolfeidau) and licensed under the [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwolfeidau%2Fdynastorev2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwolfeidau%2Fdynastorev2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwolfeidau%2Fdynastorev2/lists"}