func benchmarkTransactedDatN(b *testing.B, rows int, argc int) { benchReset() builder, err := benchInsertBuilder(rows, argc) if err != nil { b.Fatal(err) } sql, args := builder.ToSQL() tx, err := testDB.Begin() if err != nil { b.Fatal(err) } defer tx.Commit() b.ResetTimer() for i := 0; i < b.N; i++ { sql2, args2, err := dat.Interpolate(sql, args) if err != nil { b.Fatal(err) } _, err = tx.Exec(sql2, args2...) if err != nil { //fmt.Println(builder) b.Fatal(err) } } }
func benchmarkInsertDatN(b *testing.B, rows int, argc int) { benchReset() builder, err := benchInsertBuilder(rows, argc) if err != nil { b.Fatal(err) } sql, args := builder.ToSQL() b.ResetTimer() for i := 0; i < b.N; i++ { sql2, args2, err := dat.Interpolate(sql, args) if err != nil { b.Fatal(err) } _, err = testDB.Exec(sql2, args2...) if err != nil { b.Error(err) } } }
func benchmarkVaryingLengthDatN(b *testing.B, maxBytes int, maxText int) { benchReset() builder, err := benchInsertVaryingLengthBuilder(maxBytes, maxText) if err != nil { b.Fatal(err) } sql, args := builder.ToSQL() b.ResetTimer() for i := 0; i < b.N; i++ { sql2, args2, err := dat.Interpolate(sql, args) if err != nil { b.Fatal(err) } _, err = testDB.Exec(sql2, args2...) if err != nil { b.Error(err.Error()) } } }
func pgTasks(p *Project) { Env = ` DAT_DRIVER=postgres DAT_DSN="dbname=dbr_test user=dbr password=!test host=localhost sslmode=disable" ` p.Task("file", nil, func(c *Context) { filename := c.Args.Leftover()[0] if !util.FileExists(filename) { util.Error("ERR", "file not found %s", filename) return } b, err := ioutil.ReadFile(filename) if err != nil { panic(err) } parts := strings.Split(string(b), "---\n") if len(parts) != 2 { panic("sql file must have frontmatter") } var args []interface{} err = json.Unmarshal([]byte(parts[0]), &args) if err != nil { panic(err) } sql := parts[1] sql, args, _ = dat.Interpolate(sql, args) querySQL(sql, args) }).Desc("Executes a SQL file with placeholders") p.Task("query", nil, func(c *Context) { if len(c.Args.Leftover()) != 1 { fmt.Println(`usage: godo query -- "SELECT * ..." `) return } sql := c.Args.Leftover()[0] querySQL(sql, nil) }).Desc("Executes a query against the database") }