{"id":13412091,"url":"https://github.com/twharmon/dynago","last_synced_at":"2026-01-12T01:04:21.103Z","repository":{"id":42177154,"uuid":"471051727","full_name":"twharmon/dynago","owner":"twharmon","description":"Simplify working with AWS DynamoDB.","archived":false,"fork":false,"pushed_at":"2023-07-22T05:33:39.000Z","size":130,"stargazers_count":12,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-07-31T20:49:48.083Z","etag":null,"topics":["aws","dynamodb","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twharmon.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-03-17T16:09:23.000Z","updated_at":"2024-03-26T11:56:26.000Z","dependencies_parsed_at":"2024-06-20T22:08:00.125Z","dependency_job_id":null,"html_url":"https://github.com/twharmon/dynago","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twharmon%2Fdynago","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twharmon%2Fdynago/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twharmon%2Fdynago/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twharmon%2Fdynago/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twharmon","download_url":"https://codeload.github.com/twharmon/dynago/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243618767,"owners_count":20320288,"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","golang"],"created_at":"2024-07-30T20:01:20.903Z","updated_at":"2025-03-14T17:31:33.165Z","avatar_url":"https://github.com/twharmon.png","language":"Go","funding_links":[],"categories":["数据库","Database","Generators"],"sub_categories":["数据库工具","Database Tools"],"readme":"# Dynago\n\n![](https://github.com/twharmon/dynago/workflows/Test/badge.svg) [![](https://goreportcard.com/badge/github.com/twharmon/dynago)](https://goreportcard.com/report/github.com/twharmon/dynago) [![codecov](https://codecov.io/gh/twharmon/dynago/branch/main/graph/badge.svg?token=K0P59TPRAL)](https://codecov.io/gh/twharmon/dynago)\n\nThe aim of this package is to make it easier to work with AWS DynamoDB.\n\n## Documentation\nFor full documentation see [pkg.go.dev](https://pkg.go.dev/github.com/twharmon/dynago).\n\n## Usage\n\n### Basic\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/aws/aws-sdk-go/aws/session\"\n\t\"github.com/aws/aws-sdk-go/service/dynamodb\"\n\t\"github.com/twharmon/dynago\"\n)\n\ntype Schema struct {}\n\nfunc (s *Schema) PrimaryKeys() []string {\n\treturn []string{\"PK\", \"SK\"}\n}\n\ntype Post struct {\n\t// Embed a struct that implements the dynago.Keyer interface.\n\t*Schema\n\n\t// Set attribute name with `attr` tag if it needs to be different\n\t// than field name. Use `fmt:\"Post#{}\"` to indicate how the value\n\t// will be stored in DynamoDB.\n\tID string `attr:\"PK\" fmt:\"Post#{}\"`\n\n\tCreated  time.Time `attr:\"SK\" fmt:\"Created#{}\"`\n\tAuthorID string\n\tTitle    string\n\tBody     string\n}\n\nfunc main() {\n\t// Get client.\n\tddb := dynago.New(getDynamoDB(), \u0026dynago.Config{\n\t\tDefaultTableName: \"tmp\",\n\t})\n\n\t// Put item in DynamoDB.\n\tp := Post{\n\t\tID:      \"hello-world\",\n\t\tTitle:   \"Hi\",\n\t\tBody:    \"Hello world!\",\n\t\tCreated: time.Now(),\n\t}\n\tif err := ddb.PutItem(\u0026p).Exec(); err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Get same item from DynamoDB. Fields used in the primary key\n\t// must be set.\n\tp2 := Post{\n\t\tID:      p.ID,\n\t\tCreated: p.Created,\n\t}\n\tif err := ddb.GetItem(\u0026p2).Exec(); err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(p2)\n}\n\nfunc getDynamoDB() *dynamodb.DynamoDB {\n\tos.Setenv(\"AWS_SDK_LOAD_CONFIG\", \"true\")\n\tsess, err := session.NewSession()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn dynamodb.New(sess)\n}\n```\n\n### Additional Attributes\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"reflect\"\n\t\"time\"\n\n\t\"github.com/aws/aws-sdk-go/aws/session\"\n\t\"github.com/aws/aws-sdk-go/service/dynamodb\"\n\t\"github.com/twharmon/dynago\"\n)\n\ntype Schema struct {}\n\nfunc (s *Schema) PrimaryKeys() []string {\n\treturn []string{\"PK\", \"SK\"}\n}\n\ntype Post struct {\n\t// Embed a struct that implements the dynago.Keyer interface.\n\t*Schema\n\n\tID       string `attr:\"PK\" fmt:\"Post#{}\"`\n\tAuthorID string\n\tTitle    string\n\tBody     string\n\tCreated  time.Time `attr:\"SK\" fmt:\"Created#{}\"`\n}\n\ntype Author struct {\n\tID   string `attr:\"PK\" fmt:\"Author#{}\"`\n\n\t// Copy same value to attribute AltName by using `copy:\"AltName\"` in tag.\n\tName string `copy:\"AltName\"`\n}\n\nfunc main() {\n\t// Get client.\n\tddb := dynago.New(getDynamoDB(), \u0026dynago.Config{\n\t\tDefaultTableName: \"tmp\",\n\t\tAdditionalAttrs:  additionalAttrs,\n\t})\n\n\t// ...\n}\n\nfunc additionalAttrs(item map[string]*dynamodb.AttributeValue, v reflect.Value) {\n\tty := v.Type().Name()\n\n\t// Add a \"Type\" attribute to every item\n\titem[\"Type\"] = \u0026dynamodb.AttributeValue{S: \u0026ty}\n\n\t// Add additional attributes for specific types\n\tswitch val := v.Interface().(type) {\n\tcase Author:\n\t\t// Add a fat partition or sparse global secondary index to\n\t\t// make querying for all authors possible\n\t\tauthor := fmt.Sprintf(\"Author#%s\", val.ID)\n\t\titem[\"GSIPK\"] = \u0026dynamodb.AttributeValue{S: \u0026ty}\n\t\titem[\"GSISK\"] = \u0026dynamodb.AttributeValue{S: \u0026author}\n\t}\n}\n```\n\n### Compound Field Attributes\n```go\ntype Event struct {\n\tOrg string `attr:\"PK\" fmt:\"Org#{}\"`\n\n\t// In this `fmt` tag, {} is equivalent to {Country}. You can\n\t// reference a different field name by putting it's name in\n\t// curly brackets.\n\tCountry string `attr:\"SK\" fmt:\"Country#{}#City#{City}\"`\n\n\t// Since the City is specified in the \"SK\" attribute, we can\n\t// skip putting it in another attribute if we want.\n\tCity    string `attr:\"-\"`\n\tCreated time.Time\n}\n```\n\n## Contribute\nMake a pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwharmon%2Fdynago","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwharmon%2Fdynago","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwharmon%2Fdynago/lists"}