Пример #1
0
func newTestDB(t *testing.T) *asynql.DB {
	db, err := asynql.Open("sqlite3", ":memory:")
	if err != nil {
		t.Fatal(err)
	}
	db.SetMaxOpenConns(1)
	for _, query := range []string{
		`CREATE TABLE test_table (id INTEGER, name TEXT)`,
		`INSERT INTO test_table (id, name) VALUES (1, "alice")`,
		`INSERT INTO test_table (id, name) VALUES (2, "bob")`,
	} {
		if _, err := db.DB.Exec(query); err != nil {
			t.Fatal(err)
		}
	}
	return db
}
Пример #2
0
func main() {
	db, err := asynql.Open("sqlite3", ":memory:")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()
	db.SetMaxOpenConns(1)
	if err := CreateTable(db); err != nil {
		log.Fatal(err)
	}
	if err := Insert(db); err != nil {
		log.Fatal(err)
	}
	if err := Query(db); err != nil {
		log.Fatal(err)
	}
}