Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GoとテストとインプロセスDB

MakKi
December 02, 2023

 GoとテストとインプロセスDB

Go Conference mini 2023 WINTER IN KYOTO

MakKi

December 02, 2023
Tweet

More Decks by MakKi

Other Decks in Programming

Transcript

  1. テストで使いやすくするラッパー github.com/makiuchi-d/testdb つくりました db := testdb.New("my_test_db") db.Exec(`CREATE TABLE people (

    id integer NOT NULL AUTO_INCREMENT, name varchar(128) NOT NULL, PRIMARY KEY (id) )`) sqlInsert := `INSERT INTO people (id, name) VALUES (?, ?)` db.Exec(sqlInsert, 1, "Alice") db.Exec(sqlInsert, 2, "Bob") db.Exec(sqlInsert, 3, "Carol") rows, _ := db.Query(`SELECT id, name FROM people`) defer rows.Close() for rows.Next() { var id int var name string rows.Scan(&id, &name) fmt.Println(id, name) }