-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose a MySQLConn interface for use with database/sql.Conn.Raw()
Based on the design of @methane We can later add a LoadLocalInfile() method instead of the Register...() functions. for issue #1416
- Loading branch information
Showing
3 changed files
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package mysql | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// MySQLConn exposes the usable methods on driverConn given to database/sql.Conn.Raw. | ||
type MySQLConn interface { | ||
// Prevent other modules from implementing this interface so we can keep adding methods. | ||
isMySQLConn() | ||
|
||
// Location gets the Config.Loc of this connection. (This may differ from `time_zone` connection variable.) | ||
Location() *time.Location | ||
} | ||
|
||
func (mc *mysqlConn) isMySQLConn() { | ||
} | ||
|
||
func (mc *mysqlConn) Location() *time.Location { | ||
return mc.cfg.Loc | ||
} |
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,22 @@ | ||
package mysql | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
"time" | ||
) | ||
|
||
var _ MySQLConn = &mysqlConn{} | ||
|
||
func ExampleMySQLConn() { | ||
db, _ := sql.Open("mysql", "root:pw@unix(/tmp/mysql.sock)/myDatabase?parseTime=true&loc=Europe%2FAmsterdam") | ||
conn, _ := db.Conn(context.Background()) | ||
var location *time.Location | ||
conn.Raw(func(dc any) error { | ||
mc := dc.(MySQLConn) | ||
location = mc.Location() | ||
return nil | ||
}) | ||
fmt.Println(location) | ||
} |