{"id":13412354,"url":"https://github.com/zegl/goriak","last_synced_at":"2025-03-21T06:32:17.752Z","repository":{"id":45480472,"uuid":"70079787","full_name":"zegl/goriak","owner":"zegl","description":"goriak - Go language driver for Riak KV","archived":false,"fork":false,"pushed_at":"2021-09-15T17:43:18.000Z","size":271,"stargazers_count":30,"open_issues_count":4,"forks_count":7,"subscribers_count":4,"default_branch":"v3","last_synced_at":"2025-03-12T17:41:12.239Z","etag":null,"topics":["database-adapter","database-connector","go","query-builder","riak","riak-kv"],"latest_commit_sha":null,"homepage":"https://godoc.org/gopkg.in/zegl/goriak.v3","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/zegl.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}},"created_at":"2016-10-05T16:48:17.000Z","updated_at":"2024-06-20T01:46:56.000Z","dependencies_parsed_at":"2022-07-18T23:18:26.997Z","dependency_job_id":null,"html_url":"https://github.com/zegl/goriak","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zegl%2Fgoriak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zegl%2Fgoriak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zegl%2Fgoriak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zegl%2Fgoriak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zegl","download_url":"https://codeload.github.com/zegl/goriak/tar.gz/refs/heads/v3","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244117670,"owners_count":20400743,"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":["database-adapter","database-connector","go","query-builder","riak","riak-kv"],"created_at":"2024-07-30T20:01:23.782Z","updated_at":"2025-03-21T06:32:17.432Z","avatar_url":"https://github.com/zegl.png","language":"Go","funding_links":[],"categories":["Database Drivers","数据库驱动程序","\u003cspan id=\"数据库驱动-database-drivers\"\u003e数据库驱动 Database Drivers\u003c/span\u003e","数据库驱动","数据库驱动`连接和操作数据库工具`","Data Integration Frameworks","NoSQL Databases","Generators"],"sub_categories":["NoSQL数据库驱动程序","Advanced Console UIs","NoSQL Database Drivers","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","SQL 查询语句构建库"],"readme":"# goriak [![Build Status](https://circleci.com/gh/zegl/goriak.svg?style=shield)](https://circleci.com/gh/zegl/goriak) [![codecov](https://codecov.io/gh/zegl/goriak/branch/v3/graph/badge.svg)](https://codecov.io/gh/zegl/goriak/branch/v3) [![Go Report Card](https://goreportcard.com/badge/gopkg.in/zegl/goriak.v3)](https://goreportcard.com/report/gopkg.in/zegl/goriak.v3)\n\nCurrent version: `v3.2.1`.  \nRiak KV version: 2.0 or higher, the latest version of Riak KV is always recommended. \n\n![](https://i.imgur.com/0RmZ9E5.png)\n\n# What is goriak?\n\ngoriak is a wrapper around [riak-go-client](https://github.com/basho/riak-go-client) (version `1.9.0` or newer is required) to make it easier and more friendly for developers to use Riak KV.\n\n* [Documentation](https://godoc.org/gopkg.in/zegl/goriak.v3)\n\n# Installation\n\nAs a Go module (requires Go 1.11 or later):\n\n```bash\ngo get github.com/zegl/goriak/v3@v3.2.3\n```\n\nAs a Go package:\n\n```bash\ngo get -u gopkg.in/zegl/goriak.v3\n```\n\n# Maps (Riak Data Types)\n\nThe main feature of goriak is that goriak automatically can marshal/unmarshal your Go types into [Riak data types](http://docs.basho.com/riak/kv/2.1.4/developing/data-types/).\n\n## Set (Riak Data Types)\n\nIn the example below `Name` will be saved as a register, and `Aliases` will be a set.\n\n```go\ntype User struct {\n    Name    string\n    Aliases []string\n}\n\nuser := User {\n    Name:   \"Foo\",\n    Alises: []string{\"Foo\", \"Bar\"},\n}\n\ngoriak.Bucket(\"bucket-name\", \"bucket-type\").Set(user).Key(\"key\").Run(c)\n```\n\n### Tags\n\nStruct tags can be used to change the name of the item, or to ignore it.\n\n```go\ntype User struct {\n    Name    string   `goriak:\"-\"`       // Ignore field\n    Aliases []string `goriak:\"aliases\"` // Save as \"aliases\" in Riak KV\n}\n```\n\n\n## Get (Riak Data Types)\n\nThe map can later be retreived as a whole:\n\n```go\nvar res User\ngoriak.Bucket(\"bucket-name\", \"bucket-type\").Get(\"key\", \u0026res).Run(c)\n```\n\n## Supported Go types\n\n\n|  Go Type    | Riak Type |\n|-------------|-----------|\n| `struct`    | map       |\n| `string`    | register  |\n| `[n]byte`   | register  |\n| `[]byte`    | register  |\n| `[]slice`   | set       |\n| `[]slice`   | set       |\n| `[][]byte`  | set       |\n| `map`       | map       |\n| `time.Time` | register  |\n| int [1]     | register  |\n\n1: All signed and unsigned integer types are supported.\n\n### Golang map types\n\nSupported key types: all integer types, `string`.  \nSupported value types: `string`, `[]byte`.\n\n## Helper types\n\nSome actions are more complicated then necessary with the use of the default Go types and `MapOperations`.\n\nThis is why goriak contains the types `Counter`, `Set`, `Flag` and `Register`. All of these types will help you performing actions such as incrementing a value, or adding/removing items.\n\n### Counters\n\nRiak Counters is supported with the special `goriak.Counter` type.\n\nExample:\n\n```go\ntype Article struct {\n    Title string\n    Views *goriak.Counter\n}\n\n// Get our object\nvar article Article\ngoriak.Bucket(\"articles\", \"map\").Get(\"1-hello-world\", \u0026article).Run(con)\n\n// Increase views by 1\nerr := article.Views.Increase(1).Exec(con)\n\n// check err\n```\n\n`Counter.Exec(con)` will make a lightweight request to Riak, and the counter is the only object that will be updated.\n\nYou can also save the changes to your counter with `SetMap()`, this is useful if you want to change multiple counters at the same time.\n\nCheck [godoc](https://godoc.org/github.com/zegl/goriak) for more information.\n\n### Sets\n\nYou can chose to use `goriak.Set` to help you with Set related actions, such as adding and removing items. `goriak.Set` also has support for sending incremental actions to Riak so that you don't have to build that functionality yourself.\n\nExample:\n\n```go\ntype Article struct {\n    Title string\n    Tags *goriak.Set\n}\n\n// Get our object\nvar article Article\ngoriak.Bucket(\"articles\", \"map\").Get(\"1-hello-world\", \u0026article).Run(con)\n\n// Add the tag \"animals\"\nerr := article.Tags.AddString(\"animals\").Exec(con)\n\n// check err\n```\n\nCheck [godoc](https://godoc.org/github.com/zegl/goriak#Set) for more information.\n\n# Values\n\nValues can be automatically JSON Marshalled/Unmarshalled by using `SetJSON()` and `GetJSON()`.\nThere is also `SetRaw()` and `GetRaw()` that works directly on `[]byte`s.\n\n## JSON\n\n```go\n// Set object\ngoriak.Bucket(\"bucket-name\", \"bucket-type\").SetJSON(obj).Key(\"key\").Run(con)\n\n// Get object\ngoriak.Bucket(\"bucket-name\", \"bucket-type\").GetJSON(\"key\", \u0026obj).Run(con)\n```\n\n## MapOperation\n\nThere is a time in everyones life where you need to perform raw MapOperations on your Riak Data Values.\n\nSome operations, such as `RemoveFromSet` requires a Context to perform the operation.\nA Context can be retreived from `Get` by setting a special context type.\n\n\n```go\ntype ourType struct {\n    Aliases []string\n\n    // The context from Riak will be added if the tag goriakcontext is provided\n    Context []byte `goriak:\"goriakcontext\"`\n}\n\n// ... GetMap()\n\n// Works with MapOperation from github.com/basho/riak-go-client\noperation := goriak.NewMapOperation()\noperation.AddToSet(\"Aliases\", []byte(\"Baz\"))\n\ngoriak.MapOperation(\"bucket-name\", \"bucket-type\", \"key\", operation, val.Context)\n```\n\n\n# Secondary Indexes\n\nYou can set secondary indexes automatically with `SetJSON()` by using struct tags.\n\nStrings and all signed integer types are supported. Both as-is and in slices.\n\n```go\ntype User struct {\n    Name    string `goriakindex:\"nameindex_bin\"`\n    Aliases []string\n}\n```\n\nIndexes can also be used in slices. If you are using a slice every value in the slice will be added to the index.\n\n```go\ntype User struct {\n    Aliases []string `goriakindex:\"aliasesindex_bin\"`\n}\n```\n\n\nWhen saved the next time the index will be updated.\n\n## KeysInIndex\n\nKeys in a particular index can be retreived with `KeysInIndex`.\n\n```go\ncallback := func(item goriak.SecondaryIndexQueryResult) {\n    // use item\n}\n\ngoriak.Bucket(\"bucket-name\", \"bucket-type\").\n    KeysInIndex(\"nameindex_bin\", \"Value\", callback).\n    Run(con)\n```\n\n## AddToIndex\n\nAn alternative way of setting Secondary Indexes is by using `AddToIndex()`.\n\n```go\ngoriak.Bucket(\"bucket-name\", \"bucket-type\").\n    SetRaw(data).\n    AddToIndex(\"indexname_bin\", \"value\").\n    Run(con)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzegl%2Fgoriak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzegl%2Fgoriak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzegl%2Fgoriak/lists"}