upd README.md

This commit is contained in:
Dmitry Fedotov
2025-05-04 21:39:59 +03:00
parent 3c602c7679
commit 2e7ab5e382
3 changed files with 119 additions and 6 deletions

49
test/example.go Normal file
View File

@@ -0,0 +1,49 @@
package main
import (
"context"
"database/sql"
"fmt"
"code.uint32.ru/tiny/repo"
_ "github.com/mattn/go-sqlite3"
)
type My struct {
A string
B int
}
func main() {
db, err := sql.Open("sqlite3", "test.db")
if err != nil {
panic(err)
}
defer db.Close()
ctx := context.Background()
// init repository for our type "My"
r, err := repo.OpenOrCreate[My](ctx, db, "my_test_table")
if err != nil {
panic(err)
}
first := &My{
A: "hello",
B: 42,
}
if err := r.Create(ctx, "first_record", first); err != nil {
panic(err)
}
duplicate, err := r.Read(ctx, "first_record")
if err != nil {
panic(err)
}
// prints Type: *main.My, Value: &{A:hello B:42}
fmt.Printf("Type: %T, Value: %+v\n", duplicate, duplicate)
}

View File

@@ -1,4 +1,4 @@
package repo_test
package main
import (
"context"
@@ -15,11 +15,6 @@ import (
"code.uint32.ru/tiny/repo"
)
type My struct {
A string
B int
}
func TestSqlite3(t *testing.T) {
db, err := sql.Open("sqlite3", "test.db")
if err != nil {