File tree 2 files changed +39
-0
lines changed
2 files changed +39
-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
+ "context"
5
+ "database/sql"
6
+ "fmt"
7
+ "time"
8
+ )
9
+
10
+ // MySQLConn exposes the usable methods on driverConn given to database/sql.Conn.Raw.
11
+ type MySQLConn interface {
12
+ // Prevent other modules from implementing this interface so we can keep adding methods.
13
+ isMySQLConn ()
14
+
15
+ // Location gets the Config.Loc of this connection. (This may differ from `time_zone` connection variable.)
16
+ Location () * time.Location
17
+ }
18
+
19
+ func (mc * mysqlConn ) isMySQLConn () {
20
+ }
21
+
22
+ func (mc * mysqlConn ) Location () * time.Location {
23
+ return mc .cfg .Loc
24
+ }
25
+
26
+ var _ MySQLConn = & mysqlConn {}
27
+
28
+ func ExampleMySQLConn () {
29
+ db , _ := sql .Open ("mysql" , "root:pw@unix(/tmp/mysql.sock)/myDatabase?parseTime=true&loc=Europe%2FAmsterdam" )
30
+ conn , _ := db .Conn (context .Background ())
31
+ var location * time.Location
32
+ conn .Raw (func (dc any ) error {
33
+ mc := dc .(MySQLConn )
34
+ location = mc .Location ()
35
+ return nil
36
+ })
37
+ fmt .Println (location )
38
+ }
You can’t perform that action at this time.
0 commit comments