29 lines
794 B
Go
29 lines
794 B
Go
package db
|
|
|
|
import "testing"
|
|
|
|
func TestRebind(t *testing.T) {
|
|
sqlite := &DB{Dialect: SQLite}
|
|
pg := &DB{Dialect: Postgres}
|
|
|
|
q := "SELECT * FROM posts WHERE kind = ? AND status = ? LIMIT ? OFFSET ?"
|
|
|
|
if got := sqlite.Rebind(q); got != q {
|
|
t.Errorf("sqlite must keep ? placeholders, got %q", got)
|
|
}
|
|
|
|
want := "SELECT * FROM posts WHERE kind = $1 AND status = $2 LIMIT $3 OFFSET $4"
|
|
if got := pg.Rebind(q); got != want {
|
|
t.Errorf("postgres rebind:\n got %q\nwant %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestAutoInc(t *testing.T) {
|
|
if got := (&DB{Dialect: SQLite}).AutoInc(); got != "INTEGER PRIMARY KEY AUTOINCREMENT" {
|
|
t.Errorf("sqlite autoincrement = %q", got)
|
|
}
|
|
if got := (&DB{Dialect: Postgres}).AutoInc(); got != "BIGSERIAL PRIMARY KEY" {
|
|
t.Errorf("postgres autoincrement = %q", got)
|
|
}
|
|
}
|