-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa5e345
commit 0dfbfb6
Showing
16 changed files
with
214 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,14 @@ | ||
package golang | ||
|
||
type SQLDriver string | ||
import "github.com/sqlc-dev/sqlc-gen-go/internal/opts" | ||
|
||
const ( | ||
SQLPackagePGXV4 string = "pgx/v4" | ||
SQLPackagePGXV5 string = "pgx/v5" | ||
SQLPackageStandard string = "database/sql" | ||
) | ||
|
||
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" | ||
) | ||
|
||
func parseDriver(sqlPackage string) SQLDriver { | ||
func parseDriver(sqlPackage string) opts.SQLDriver { | ||
switch sqlPackage { | ||
case SQLPackagePGXV4: | ||
return SQLDriverPGXV4 | ||
case SQLPackagePGXV5: | ||
return SQLDriverPGXV5 | ||
default: | ||
return SQLDriverLibPQ | ||
} | ||
} | ||
|
||
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 | ||
case opts.SQLPackagePGXV4: | ||
return opts.SQLDriverPGXV4 | ||
case opts.SQLPackagePGXV5: | ||
return opts.SQLDriverPGXV5 | ||
default: | ||
return SQLPackageStandard | ||
return opts.SQLDriverLibPQ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.