File tree 1 file changed +38
-0
lines changed
1 file changed +38
-0
lines changed 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