...

Source file src/github.com/ory/x/dbal/canonicalize.go

Documentation: github.com/ory/x/dbal

     1  package dbal
     2  
     3  import "github.com/ory/x/cmdx"
     4  
     5  const (
     6  	// DriverMySQL is the mysql driver name.
     7  	DriverMySQL = "mysql"
     8  
     9  	// DriverPostgreSQL is the postgres driver name.
    10  	DriverPostgreSQL = "postgres"
    11  
    12  	// DriverCockroachDB is the cockroach driver name.
    13  	DriverCockroachDB = "cockroach"
    14  
    15  	// UnknownDriver is the driver name if the driver is unknown.
    16  	UnknownDriver = "unknown"
    17  )
    18  
    19  // Canonicalize returns constants DriverMySQL, DriverPostgreSQL, DriverCockroachDB, UnknownDriver, depending on `database`.
    20  func Canonicalize(database string) string {
    21  	switch database {
    22  	case "mysql":
    23  		return DriverMySQL
    24  	case "pgx", "pq", "postgres":
    25  		return DriverPostgreSQL
    26  	case "cockroach":
    27  		return DriverCockroachDB
    28  	default:
    29  		return UnknownDriver
    30  	}
    31  }
    32  
    33  // MustCanonicalize returns constants DriverMySQL, DriverPostgreSQL, DriverCockroachDB or fatals.
    34  func MustCanonicalize(database string) string {
    35  	d := Canonicalize(database)
    36  	if d == UnknownDriver {
    37  		cmdx.Fatalf("Unknown database driver: %s", database)
    38  	}
    39  	return d
    40  }
    41  

View as plain text