-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathdb_test.go
More file actions
53 lines (43 loc) · 1 KB
/
db_test.go
File metadata and controls
53 lines (43 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package authors
import (
"context"
"testing"
"github.com/sqlc-dev/sqlc/internal/sqltest/local"
_ "github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/query"
)
func ptr(s string) *string {
return &s
}
func TestAuthors(t *testing.T) {
ctx := context.Background()
db := local.YDB(t, []string{"schema.sql"})
defer db.Close(ctx)
q := New(db.Query())
// list all authors
authors, err := q.ListAuthors(ctx)
if err != nil {
t.Fatal(err)
}
t.Log(authors)
// create an author
insertedAuthor, err := q.CreateOrUpdateAuthor(ctx, CreateOrUpdateAuthorParams{
Name: "Brian Kernighan",
Bio: ptr("Co-author of The C Programming Language and The Go Programming Language"),
}, query.WithIdempotent())
if err != nil {
t.Fatal(err)
}
t.Log(insertedAuthor)
// get the author we just inserted
fetchedAuthor, err := q.GetAuthor(ctx, insertedAuthor.ID)
if err != nil {
t.Fatal(err)
}
t.Log(fetchedAuthor)
// drop table
err = q.DropTable(ctx)
if err != nil {
t.Fatal(err)
}
}