MCPcopy
hub / github.com/sqlc-dev/sqlc / TestBooks

Function TestBooks

examples/booktest/sqlite/db_test.go:19–163  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestBooks(t *testing.T) {
20 db, cleanup := sqltest.SQLite(t, []string{"schema.sql"})
21 defer db.Close()
22 defer cleanup()
23
24 ctx := context.Background()
25 dq := New(db)
26
27 // create an author
28 a, err := dq.CreateAuthor(ctx, "Unknown Master")
29 if err != nil {
30 t.Fatal(err)
31 }
32
33 // create transaction
34 tx, err := db.Begin()
35 if err != nil {
36 t.Fatal(err)
37 }
38
39 tq := dq.WithTx(tx)
40
41 // save first book
42 now := time.Now()
43 _, err = tq.CreateBook(ctx, CreateBookParams{
44 AuthorID: a.AuthorID,
45 Isbn: "1",
46 Title: "my book title",
47 BookType: BooksBookTypeFICTION,
48 Yr: 2016,
49 Available: now,
50 Tag: "",
51 })
52 if err != nil {
53 t.Fatal(err)
54 }
55
56 // save second book
57 b1, err := tq.CreateBook(ctx, CreateBookParams{
58 AuthorID: a.AuthorID,
59 Isbn: "2",
60 Title: "the second book",
61 BookType: BooksBookTypeFICTION,
62 Yr: 2016,
63 Available: now,
64 Tag: "unique",
65 })
66 if err != nil {
67 t.Fatal(err)
68 }
69
70 // update the title and tags
71 err = tq.UpdateBook(ctx, UpdateBookParams{
72 BookID: b1.BookID,
73 Title: "changed second title",
74 Tag: "disastor",
75 })
76 if err != nil {

Callers

nothing calls this directly

Calls 14

SQLiteFunction · 0.92
NewFunction · 0.70
CloseMethod · 0.65
CreateAuthorMethod · 0.65
CreateBookMethod · 0.65
UpdateBookMethod · 0.65
FormatMethod · 0.65
GetAuthorMethod · 0.65
DeleteBookMethod · 0.65
WithTxMethod · 0.45
UpdateBookISBNMethod · 0.45
BooksByTitleYearMethod · 0.45

Tested by

no test coverage detected