Skip to content

Latest commit

 

History

History
48 lines (35 loc) · 779 Bytes

File metadata and controls

48 lines (35 loc) · 779 Bytes

Getting started

Install

go get github.com/fgrzl/lexkey

Encode a key

key := lexkey.Encode("user", int64(123), true)
fmt.Println(key.ToHexString())

Compare keys

k1 := lexkey.Encode("apple")
k2 := lexkey.Encode("banana")
ordered := bytes.Compare(k1, k2) < 0 // true

Primary keys for KV

pk := lexkey.NewPrimaryKey(
    lexkey.Encode("tenant", tenantID), // partition
    lexkey.Encode("user", userID),     // row
)

Prefix range scan

prefix := lexkey.Encode("orders", shopID)
from := lexkey.EncodeFirst(prefix)
to := lexkey.EncodeLast(prefix)
// use from/to with kv.Query range operators

JSON

data, _ := json.Marshal(key) // hex string form

See SPEC.md for encoding details.