-
-
Save radeksimko/44d205695c70428a7029b7326d917365 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
entry: &main.entry{Address:"aws", Version:"1.0.0"} | |
entry: &main.entry{Address:"aws", Version:"1.0.0"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"github.com/hashicorp/go-memdb" | |
) | |
func main() { | |
type entry struct { | |
Address string | |
Version string | |
} | |
db, err := memdb.NewMemDB(&memdb.DBSchema{ | |
Tables: map[string]*memdb.TableSchema{ | |
"providers": { | |
Name: "providers", | |
Indexes: map[string]*memdb.IndexSchema{ | |
"id": { | |
Name: "id", | |
Unique: true, | |
Indexer: &memdb.CompoundIndex{ | |
Indexes: []memdb.Indexer{ | |
&memdb.StringFieldIndex{Field: "Address"}, | |
&memdb.StringFieldIndex{Field: "Version"}, | |
}, | |
AllowMissing: true, | |
}, | |
}, | |
"provider": { | |
Name: "provider", | |
Indexer: &memdb.CompoundMultiIndex{ | |
Indexes: []memdb.Indexer{ | |
&memdb.StringFieldIndex{Field: "Address"}, | |
&memdb.StringFieldIndex{Field: "Version"}, | |
}, | |
AllowMissing: true, | |
}, | |
}, | |
}, | |
}, | |
}, | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
wTxn := db.Txn(true) | |
defer wTxn.Abort() | |
err = wTxn.Insert("providers", &entry{ | |
Address: "aws", | |
Version: "1.0.0", | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
wTxn.Commit() | |
txn := db.Txn(false) | |
it, err := txn.Get("providers", "provider") | |
if err != nil { | |
log.Fatal(err) | |
} | |
for obj := it.Next(); obj != nil; obj = it.Next() { | |
fmt.Printf("entry: %#v\n", obj) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment