func RebindInsert(db *sqlx.DB, q string) string { q = db.Rebind(q) q = strings.TrimRight(q, " \t\n;") if db.DriverName() == "postgres" { q = q + " RETURNING id" } return q }
// Truncate truncates teh DB func Truncate(db *sqlx.DB) { var sql string switch db.DriverName() { case "postgres": sql = pgTruncateTables case "sqlite3": sql = sqliteTruncateTables default: panic("Unknown driver") } if _, err := db.Exec(sql); err != nil { panic(err) } }
// Truncate truncates the DB func Truncate(db *sqlx.DB) { var sql []string switch db.DriverName() { case "mysql": sql = strings.Split(mysqlTruncateTables, "\n") case "postgres": sql = []string{pgTruncateTables} case "sqlite3": sql = []string{sqliteTruncateTables} default: panic("Unknown driver") } for _, expr := range sql { if len(strings.TrimSpace(expr)) == 0 { continue } if _, err := db.Exec(expr); err != nil { panic(err) } } }
func Migrate(db *sqlx.DB, dir migrate.MigrationDirection) error { _, err := migrate.Exec(db.DB, db.DriverName(), Migrations, dir) return err }