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

Function TestAuthors

examples/authors/mysql/db_test.go:15–53  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestAuthors(t *testing.T) {
16 ctx := context.Background()
17 uri := local.MySQL(t, []string{"schema.sql"})
18 sdb, err := sql.Open("mysql", uri)
19 if err != nil {
20 t.Fatal(err)
21 }
22 defer sdb.Close()
23
24 db := New(sdb)
25
26 // list all authors
27 authors, err := db.ListAuthors(ctx)
28 if err != nil {
29 t.Fatal(err)
30 }
31 t.Log(authors)
32
33 // create an author
34 result, err := db.CreateAuthor(ctx, CreateAuthorParams{
35 Name: "Brian Kernighan",
36 Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true},
37 })
38 if err != nil {
39 t.Fatal(err)
40 }
41 authorID, err := result.LastInsertId()
42 if err != nil {
43 t.Fatal(err)
44 }
45 t.Log(authorID)
46
47 // get the author we just inserted
48 fetchedAuthor, err := db.GetAuthor(ctx, authorID)
49 if err != nil {
50 t.Fatal(err)
51 }
52 t.Log(fetchedAuthor)
53}

Callers

nothing calls this directly

Calls 8

MySQLFunction · 0.92
OpenMethod · 0.80
LogMethod · 0.80
NewFunction · 0.70
CloseMethod · 0.65
ListAuthorsMethod · 0.65
CreateAuthorMethod · 0.65
GetAuthorMethod · 0.65

Tested by

no test coverage detected