ksql/dialect.go
Vinícius Garcia de8f4e56d7 Fix Insert function to work with postgres
This commit adds the concept of dialects so we can support
different ways of escaping names, creating placeholders, etc.

Currently we are only using it on the Insert route and we only
support postgres and sqlite3, in the future we should add
more tests so we can start supporting more drivers.
2020-12-29 23:36:10 -03:00

36 lines
647 B
Go

package kissorm
import "strconv"
type dialect interface {
Escape(str string) string
Placeholder(idx int) string
}
type postgresDialect struct{}
func (postgresDialect) Escape(str string) string {
return `"` + str + `"`
}
func (postgresDialect) Placeholder(idx int) string {
return "$" + strconv.Itoa(idx+1)
}
type sqlite3Dialect struct{}
func (sqlite3Dialect) Escape(str string) string {
return "`" + str + "`"
}
func (sqlite3Dialect) Placeholder(idx int) string {
return "?"
}
func getDriverDialect(driver string) dialect {
return map[string]dialect{
"postgres": &postgresDialect{},
"sqlite3": &sqlite3Dialect{},
}[driver]
}