{"id":13571118,"url":"https://github.com/hashicorp/go-memdb","last_synced_at":"2025-05-12T05:17:36.021Z","repository":{"id":33854699,"uuid":"37560288","full_name":"hashicorp/go-memdb","owner":"hashicorp","description":"Golang in-memory database built on immutable radix trees","archived":false,"fork":false,"pushed_at":"2025-05-09T07:21:52.000Z","size":238,"stargazers_count":3282,"open_issues_count":46,"forks_count":215,"subscribers_count":337,"default_branch":"main","last_synced_at":"2025-05-11T02:55:42.548Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/hashicorp/go-memdb","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hashicorp.png","metadata":{"files":{"readme":"README.md","changelog":"changes.go","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-06-16T22:54:29.000Z","updated_at":"2025-05-01T07:33:53.000Z","dependencies_parsed_at":"2023-02-17T08:30:38.987Z","dependency_job_id":"3c22a562-4cca-4624-ada2-ec32e6aac225","html_url":"https://github.com/hashicorp/go-memdb","commit_stats":{"total_commits":110,"total_committers":35,"mean_commits":3.142857142857143,"dds":0.8454545454545455,"last_synced_commit":"fe53ab56710b3bc437a1a5b7dd0c47fd67dcb468"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fgo-memdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fgo-memdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fgo-memdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fgo-memdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hashicorp","download_url":"https://codeload.github.com/hashicorp/go-memdb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253509775,"owners_count":21919587,"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":[],"created_at":"2024-08-01T14:00:58.789Z","updated_at":"2025-05-11T02:55:48.238Z","avatar_url":"https://github.com/hashicorp.png","language":"Go","funding_links":[],"categories":["Misc","开源类库","Go","Databases","Open source library","Data and Storage"],"sub_categories":["数据库","Database","Databases"],"readme":"# go-memdb [![CircleCI](https://circleci.com/gh/hashicorp/go-memdb/tree/master.svg?style=svg)](https://circleci.com/gh/hashicorp/go-memdb/tree/master)\n\nProvides the `memdb` package that implements a simple in-memory database\nbuilt on immutable radix trees. The database provides Atomicity, Consistency\nand Isolation from ACID. Being that it is in-memory, it does not provide durability.\nThe database is instantiated with a schema that specifies the tables and indices\nthat exist and allows transactions to be executed.\n\nThe database provides the following:\n\n* Multi-Version Concurrency Control (MVCC) - By leveraging immutable radix trees\n  the database is able to support any number of concurrent readers without locking,\n  and allows a writer to make progress.\n\n* Transaction Support - The database allows for rich transactions, in which multiple\n  objects are inserted, updated or deleted. The transactions can span multiple tables,\n  and are applied atomically. The database provides atomicity and isolation in ACID\n  terminology, such that until commit the updates are not visible.\n\n* Rich Indexing - Tables can support any number of indexes, which can be simple like\n  a single field index, or more advanced compound field indexes. Certain types like\n  UUID can be efficiently compressed from strings into byte indexes for reduced\n  storage requirements.\n\n* Watches - Callers can populate a watch set as part of a query, which can be used to\n  detect when a modification has been made to the database which affects the query\n  results. This lets callers easily watch for changes in the database in a very general\n  way.\n\nFor the underlying immutable radix trees, see [go-immutable-radix](https://github.com/hashicorp/go-immutable-radix).\n\nDocumentation\n=============\n\nThe full documentation is available on [Godoc](https://pkg.go.dev/github.com/hashicorp/go-memdb).\n\nExample\n=======\n\nBelow is a [simple example](https://play.golang.org/p/gCGE9FA4og1) of usage\n\n```go\n// Create a sample struct\ntype Person struct {\n\tEmail string\n\tName  string\n\tAge   int\n}\n\n// Create the DB schema\nschema := \u0026memdb.DBSchema{\n\tTables: map[string]*memdb.TableSchema{\n\t\t\"person\": \u0026memdb.TableSchema{\n\t\t\tName: \"person\",\n\t\t\tIndexes: map[string]*memdb.IndexSchema{\n\t\t\t\t\"id\": \u0026memdb.IndexSchema{\n\t\t\t\t\tName:    \"id\",\n\t\t\t\t\tUnique:  true,\n\t\t\t\t\tIndexer: \u0026memdb.StringFieldIndex{Field: \"Email\"},\n\t\t\t\t},\n\t\t\t\t\"age\": \u0026memdb.IndexSchema{\n\t\t\t\t\tName:    \"age\",\n\t\t\t\t\tUnique:  false,\n\t\t\t\t\tIndexer: \u0026memdb.IntFieldIndex{Field: \"Age\"},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t},\n}\n\n// Create a new data base\ndb, err := memdb.NewMemDB(schema)\nif err != nil {\n\tpanic(err)\n}\n\n// Create a write transaction\ntxn := db.Txn(true)\n\n// Insert some people\npeople := []*Person{\n\t\u0026Person{\"joe@aol.com\", \"Joe\", 30},\n\t\u0026Person{\"lucy@aol.com\", \"Lucy\", 35},\n\t\u0026Person{\"tariq@aol.com\", \"Tariq\", 21},\n\t\u0026Person{\"dorothy@aol.com\", \"Dorothy\", 53},\n}\nfor _, p := range people {\n\tif err := txn.Insert(\"person\", p); err != nil {\n\t\tpanic(err)\n\t}\n}\n\n// Commit the transaction\ntxn.Commit()\n\n// Create read-only transaction\ntxn = db.Txn(false)\ndefer txn.Abort()\n\n// Lookup by email\nraw, err := txn.First(\"person\", \"id\", \"joe@aol.com\")\nif err != nil {\n\tpanic(err)\n}\n\n// Say hi!\nfmt.Printf(\"Hello %s!\\n\", raw.(*Person).Name)\n\n// List all the people\nit, err := txn.Get(\"person\", \"id\")\nif err != nil {\n\tpanic(err)\n}\n\nfmt.Println(\"All the people:\")\nfor obj := it.Next(); obj != nil; obj = it.Next() {\n\tp := obj.(*Person)\n\tfmt.Printf(\"  %s\\n\", p.Name)\n}\n\n// Range scan over people with ages between 25 and 35 inclusive\nit, err = txn.LowerBound(\"person\", \"age\", 25)\nif err != nil {\n\tpanic(err)\n}\n\nfmt.Println(\"People aged 25 - 35:\")\nfor obj := it.Next(); obj != nil; obj = it.Next() {\n\tp := obj.(*Person)\n\tif p.Age \u003e 35 {\n\t\tbreak\n\t}\n\tfmt.Printf(\"  %s is aged %d\\n\", p.Name, p.Age)\n}\n// Output:\n// Hello Joe!\n// All the people:\n//   Dorothy\n//   Joe\n//   Lucy\n//   Tariq\n// People aged 25 - 35:\n//   Joe is aged 30\n//   Lucy is aged 35\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashicorp%2Fgo-memdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhashicorp%2Fgo-memdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashicorp%2Fgo-memdb/lists"}