File tree 3 files changed +44
-0
lines changed
3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ Jeffrey Charles <jeffreycharles at gmail.com>
54
54
Jerome Meyer <jxmeyer at gmail.com>
55
55
Jiajia Zhong <zhong2plus at gmail.com>
56
56
Jian Zhen <zhenjl at gmail.com>
57
+ Jille Timmermans <jille at quis.cx>
57
58
Joshua Prunier <joshua.prunier at gmail.com>
58
59
Julien Lefevre <julien.lefevr at gmail.com>
59
60
Julien Schmidt <go-sql-driver at julienschmidt.com>
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments