mirror of
https://github.com/VinGarcia/ksql.git
synced 2025-05-16 20:43:35 +00:00
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.
36 lines
647 B
Go
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]
|
|
}
|