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

Function TestAuthors

examples/authors/sqlite/db_test.go:13–48  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

SQLiteFunction · 0.92
LogMethod · 0.80
NewFunction · 0.70
CloseMethod · 0.65
ListAuthorsMethod · 0.65
CreateAuthorMethod · 0.65
GetAuthorMethod · 0.65

Tested by

no test coverage detected