Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package opts
|
|
|
|
import "fmt"
|
|
|
|
type SQLDriver string
|
|
|
|
const (
|
|
SQLPackagePGXV4 string = "pgx/v4"
|
|
SQLPackagePGXV5 string = "pgx/v5"
|
|
SQLPackageStandard string = "database/sql"
|
|
)
|
|
|
|
var validPackages = map[string]struct{}{
|
|
string(SQLPackagePGXV4): {},
|
|
string(SQLPackagePGXV5): {},
|
|
string(SQLPackageStandard): {},
|
|
}
|
|
|
|
func validatePackage(sqlPackage string) error {
|
|
if _, found := validPackages[sqlPackage]; !found {
|
|
return fmt.Errorf("unknown SQL package: %s", sqlPackage)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
const (
|
|
SQLDriverPGXV4 SQLDriver = "github.com/jackc/pgx/v4"
|
|
SQLDriverPGXV5 = "github.com/jackc/pgx/v5"
|
|
SQLDriverLibPQ = "github.com/lib/pq"
|
|
SQLDriverGoSQLDriverMySQL = "github.com/go-sql-driver/mysql"
|
|
)
|
|
|
|
var validDrivers = map[string]struct{}{
|
|
string(SQLDriverPGXV4): {},
|
|
string(SQLDriverPGXV5): {},
|
|
string(SQLDriverLibPQ): {},
|
|
string(SQLDriverGoSQLDriverMySQL): {},
|
|
}
|
|
|
|
func validateDriver(sqlDriver string) error {
|
|
if _, found := validDrivers[sqlDriver]; !found {
|
|
return fmt.Errorf("unknown SQL driver: %s", sqlDriver)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (d SQLDriver) IsPGX() bool {
|
|
return d == SQLDriverPGXV4 || d == SQLDriverPGXV5
|
|
}
|
|
|
|
func (d SQLDriver) IsGoSQLDriverMySQL() bool {
|
|
return d == SQLDriverGoSQLDriverMySQL
|
|
}
|
|
|
|
func (d SQLDriver) Package() string {
|
|
switch d {
|
|
case SQLDriverPGXV4:
|
|
return SQLPackagePGXV4
|
|
case SQLDriverPGXV5:
|
|
return SQLPackagePGXV5
|
|
default:
|
|
return SQLPackageStandard
|
|
}
|
|
}
|