Skip to content

Commit

Permalink
refactor: massively simplify example
Browse files Browse the repository at this point in the history
  • Loading branch information
tauraamui committed Jul 6, 2023
1 parent 3fbf5f2 commit 9859815
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 162 deletions.
9 changes: 0 additions & 9 deletions example/example_data.go

This file was deleted.

38 changes: 38 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"fmt"

"github.com/tauraamui/kvs"
"github.com/tauraamui/kvs/storage"
)

type Balloon struct {
ID uint32 `mdb:"ignore"`
Color string
Size int
}

func (b Balloon) TableName() string { return "balloons" }
func (b *Balloon) SetID(id uint32) { b.ID = id }
func (b *Balloon) Ref() any { return b }

func main() {
db, err := kvs.NewMemKVDB()
if err != nil {
panic(err)
}
defer db.Close()

store := storage.New(db)
defer store.Close()

store.Save(kvs.RootOwner{}, &Balloon{Color: "RED", Size: 695})
store.Save(kvs.RootOwner{}, &Balloon{Color: "WHITE", Size: 366})

bs, err := storage.LoadAllByOwner(store, Balloon{}, kvs.RootOwner{})
for rowID, balloon := range bs {
fmt.Printf("ROWID: %d, %+v\n", rowID, balloon)
}

}
115 changes: 0 additions & 115 deletions example/repo.go

This file was deleted.

38 changes: 0 additions & 38 deletions example/repo_test.go

This file was deleted.

0 comments on commit 9859815

Please sign in to comment.