-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enables building using `modernc.org/sqlite` without using CGO. The default is to build with CGO enabled, as performance is better using CGO.
- Loading branch information
Showing
13 changed files
with
205 additions
and
99 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
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,51 @@ | ||
//go:build !cgo | ||
|
||
package trdsql | ||
|
||
import ( | ||
"database/sql" | ||
|
||
// MySQL driver. | ||
|
||
_ "github.com/go-sql-driver/mysql" | ||
|
||
// PostgreSQL driver. | ||
_ "github.com/lib/pq" | ||
|
||
// SQLite3 driver. | ||
_ "modernc.org/sqlite" | ||
) | ||
|
||
var DefaultDriver = "sqlite" | ||
|
||
// Connect is connects to the database. | ||
// Currently supported drivers are sqlite3, mysql, postgres. | ||
// Set quote character and maxBulk depending on the driver type. | ||
func Connect(driver, dsn string) (*DB, error) { | ||
sqlDB, err := sql.Open(driver, dsn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
db := &DB{ | ||
DB: sqlDB, | ||
driver: driver, | ||
dsn: dsn, | ||
} | ||
debug.Printf("driver: %s, dsn: %s", driver, dsn) | ||
|
||
switch driver { | ||
case "sqlite3", "sqlite3_ext", "sqlite": | ||
db.quote = "`" | ||
db.maxBulk = 500 | ||
case "mysql": | ||
db.quote = "`" | ||
db.maxBulk = 1000 | ||
case "postgres": | ||
db.quote = "\"" | ||
default: | ||
db.quote = "\"" | ||
} | ||
|
||
return db, nil | ||
} |
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,59 @@ | ||
//go:build cgo | ||
|
||
package trdsql | ||
|
||
import ( | ||
"database/sql" | ||
|
||
// MySQL driver. | ||
|
||
_ "github.com/go-sql-driver/mysql" | ||
|
||
// PostgreSQL driver. | ||
_ "github.com/lib/pq" | ||
|
||
// SQLite3 driver. | ||
_ "github.com/mattn/go-sqlite3" | ||
// SQlite3 extension library. | ||
sqlite3_stdlib "github.com/multiprocessio/go-sqlite3-stdlib" | ||
) | ||
|
||
var DefaultDriver = "sqlite3" | ||
|
||
func init() { | ||
// Enable sqlite3 extensions. | ||
// It can be used by setting the driver to "sqlite3_ext". | ||
sqlite3_stdlib.Register("sqlite3_ext") | ||
} | ||
|
||
// Connect is connects to the database. | ||
// Currently supported drivers are sqlite3, mysql, postgres. | ||
// Set quote character and maxBulk depending on the driver type. | ||
func Connect(driver, dsn string) (*DB, error) { | ||
sqlDB, err := sql.Open(driver, dsn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
db := &DB{ | ||
DB: sqlDB, | ||
driver: driver, | ||
dsn: dsn, | ||
} | ||
debug.Printf("driver: %s, dsn: %s", driver, dsn) | ||
|
||
switch driver { | ||
case "sqlite3", "sqlite3_ext", "sqlite": | ||
db.quote = "`" | ||
db.maxBulk = 500 | ||
case "mysql": | ||
db.quote = "`" | ||
db.maxBulk = 1000 | ||
case "postgres": | ||
db.quote = "\"" | ||
default: | ||
db.quote = "\"" | ||
} | ||
|
||
return db, nil | ||
} |
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
Oops, something went wrong.