mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 07:02:12 +08:00

* Remove dbProviderFunc function. This removes one extra indirection that made the code bit more difficult to navigate. * Remove indirection function types implementing single-method interfaces. This streamlines the code and makes it bit easier to navigate. * Update pkg/storage/unified/sql/sqltemplate/dialect_mysql.go Co-authored-by: Mustafa Sencer Özcan <32759850+mustafasencer@users.noreply.github.com> --------- Co-authored-by: Mustafa Sencer Özcan <32759850+mustafasencer@users.noreply.github.com>
43 lines
940 B
Go
43 lines
940 B
Go
package sqltemplate
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// PostgreSQL is an implementation of Dialect for the PostgreSQL DMBS.
|
|
var PostgreSQL = postgresql{}
|
|
|
|
var (
|
|
ErrPostgreSQLUnsupportedIdent = errors.New("identifiers in PostgreSQL cannot contain the character with code zero")
|
|
)
|
|
|
|
type postgresql struct{}
|
|
|
|
func (p postgresql) DialectName() string {
|
|
return "postgres"
|
|
}
|
|
|
|
func (p postgresql) ArgPlaceholder(argNum int) string {
|
|
return fmt.Sprintf("$%d", argNum)
|
|
}
|
|
|
|
func (p postgresql) SelectFor(s ...string) (string, error) {
|
|
return rowLockingClauseAll.SelectFor(s...)
|
|
}
|
|
|
|
func (p postgresql) Ident(s string) (string, error) {
|
|
// See:
|
|
// https://www.postgresql.org/docs/current/sql-syntax-lexical.html
|
|
if strings.IndexByte(s, 0) != -1 {
|
|
return "", ErrPostgreSQLUnsupportedIdent
|
|
}
|
|
|
|
return standardIdent(s)
|
|
}
|
|
|
|
func (postgresql) CurrentEpoch() string {
|
|
return "(EXTRACT(EPOCH FROM statement_timestamp()) * 1000000)::BIGINT"
|
|
}
|