Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 91a33fb

Browse files
committed
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
1 parent 564dee9 commit 91a33fb

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

‎AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Jeffrey Charles <jeffreycharles at gmail.com>
5454
Jerome Meyer <jxmeyer at gmail.com>
5555
Jiajia Zhong <zhong2plus at gmail.com>
5656
Jian Zhen <zhenjl at gmail.com>
57+
Jille Timmermans <jille at quis.cx>
5758
Joshua Prunier <joshua.prunier at gmail.com>
5859
Julien Lefevre <julien.lefevr at gmail.com>
5960
Julien Schmidt <go-sql-driver at julienschmidt.com>

‎interface.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package mysql
2+
3+
import (
4+
"time"
5+
)
6+
7+
// MySQLConn exposes the usable methods on driverConn given to database/sql.Conn.Raw.
8+
type MySQLConn interface {
9+
// Prevent other modules from implementing this interface so we can keep adding methods.
10+
isMySQLConn()
11+
12+
// Location gets the Config.Loc of this connection. (This may differ from `time_zone` connection variable.)
13+
Location() *time.Location
14+
}
15+
16+
func (mc *mysqlConn) isMySQLConn() {
17+
}
18+
19+
func (mc *mysqlConn) Location() *time.Location {
20+
return mc.cfg.Loc
21+
}

‎interface_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package mysql
2+
3+
import (
4+
"context"
5+
"database/sql"
6+
"fmt"
7+
"time"
8+
)
9+
10+
var _ MySQLConn = &mysqlConn{}
11+
12+
func ExampleMySQLConn() {
13+
db, _ := sql.Open("mysql", "root:pw@unix(/tmp/mysql.sock)/myDatabase?parseTime=true&loc=Europe%2FAmsterdam")
14+
conn, _ := db.Conn(context.Background())
15+
var location *time.Location
16+
conn.Raw(func(dc any) error {
17+
mc := dc.(MySQLConn)
18+
location = mc.Location()
19+
return nil
20+
})
21+
fmt.Println(location)
22+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /