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

Function TestAuthors

examples/authors/postgresql/db_test.go:15–49  ·  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.PostgreSQL(t, []string{"schema.sql"})
18 db, err := pgx.Connect(ctx, uri)
19 if err != nil {
20 t.Fatal(err)
21 }
22 defer db.Close(ctx)
23
24 q := New(db)
25
26 // list all authors
27 authors, err := q.ListAuthors(ctx)
28 if err != nil {
29 t.Fatal(err)
30 }
31 t.Log(authors)
32
33 // create an author
34 insertedAuthor, err := q.CreateAuthor(ctx, CreateAuthorParams{
35 Name: "Brian Kernighan",
36 Bio: pgtype.Text{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 t.Log(insertedAuthor)
42
43 // get the author we just inserted
44 fetchedAuthor, err := q.GetAuthor(ctx, insertedAuthor.ID)
45 if err != nil {
46 t.Fatal(err)
47 }
48 t.Log(fetchedAuthor)
49}

Callers

nothing calls this directly

Calls 7

PostgreSQLFunction · 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