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

Function TestBatchBooks

examples/batch/postgresql/db_test.go:16–153  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestBatchBooks(t *testing.T) {
17 uri := local.PostgreSQL(t, []string{"schema.sql"})
18
19 ctx := context.Background()
20
21 db, err := pgx.Connect(ctx, uri)
22 if err != nil {
23 t.Fatal(err)
24 }
25 defer db.Close(ctx)
26
27 dq := New(db)
28
29 // create an author
30 a, err := dq.CreateAuthor(ctx, "Unknown Master")
31 if err != nil {
32 t.Fatal(err)
33 }
34
35 now := pgtype.Timestamptz{Time: time.Now(), Valid: true}
36
37 // batch insert new books
38 newBooksParams := []CreateBookParams{
39 {
40 AuthorID: a.AuthorID,
41 Isbn: "1",
42 Title: "my book title",
43 BookType: BookTypeFICTION,
44 Year: 2016,
45 Available: now,
46 Tags: []string{},
47 },
48 {
49 AuthorID: a.AuthorID,
50 Isbn: "2",
51 Title: "the second book",
52 BookType: BookTypeFICTION,
53 Year: 2016,
54 Available: now,
55 Tags: []string{"cool", "unique"},
56 },
57 {
58 AuthorID: a.AuthorID,
59 Isbn: "3",
60 Title: "the third book",
61 BookType: BookTypeFICTION,
62 Year: 2001,
63 Available: now,
64 Tags: []string{"cool"},
65 },
66 {
67 AuthorID: a.AuthorID,
68 Isbn: "4",
69 Title: "4th place finisher",
70 BookType: BookTypeNONFICTION,
71 Year: 2011,
72 Available: now,
73 Tags: []string{"other"},

Callers

nothing calls this directly

Calls 14

PostgreSQLFunction · 0.92
NewFunction · 0.70
CloseMethod · 0.65
CreateAuthorMethod · 0.65
QueryRowMethod · 0.65
CreateBookMethod · 0.65
ExecMethod · 0.65
UpdateBookMethod · 0.65
QueryMethod · 0.65
BooksByYearMethod · 0.65
FormatMethod · 0.65
GetAuthorMethod · 0.65

Tested by

no test coverage detected