You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,8 @@ A MySQL-Driver for Go's [database/sql](http://golang.org/pkg/database/sql) packa
19
19
*[Address](#address)
20
20
*[Parameters](#parameters)
21
21
*[Examples](#examples)
22
-
*[LOAD DATA LOCAL INFILE support](#load-data-local-infile-support)
22
+
*[LOAD DATA LOCAL INFILE support](#load-data-local-infile-support)
23
+
*[time.Time support](#timetime-support)
23
24
*[Testing / Development](#testing--development)
24
25
*[License](#license)
25
26
@@ -105,6 +106,8 @@ Possible Parameters are:
105
106
*`timeout`: **Driver** side connection timeout. The value must be a string of decimal numbers, each with optional fraction and a unit suffix ( *"ms"*, *"s"*, *"m"*, *"h"* ), such as *"30s"*, *"0.5m"* or *"1m30s"*. To set a server side timeout, use the parameter [`wait_timeout`](http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_wait_timeout).
106
107
*`charset`: Sets the charset used for client-server interaction ("SET NAMES `value`"). If multiple charsets are set (separated by a comma), the following charset is used if setting the charset failes. This enables support for `utf8mb4` ([introduced in MySQL 5.5.3](http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html)) with fallback to `utf8` for older servers (`charset=utf8mb4,utf8`).
107
108
*`allowAllFiles`: `allowAllFiles=true` disables the file Whitelist for `LOAD DATA LOCAL INFILE` and allows *all* files. *Might be insecure!*
109
+
*`parseTime`: `parseTime=true` changes the output type of `DATE` and `DATETIME` values to `time.Time` instead of `[]byte` / `string`
110
+
*`loc`: Sets the location for time.Time values (when using `parseTime=true`). The default is `UTC`. *"Local"* sets the system's location. See [time.LoadLocation](http://golang.org/pkg/time/#LoadLocation) for details.
108
111
109
112
All other parameters are interpreted as system variables:
110
113
*`autocommit`: *"SET autocommit=`value`"*
@@ -146,6 +149,13 @@ To use a `io.Reader` a handler function must be registered with `mysql.RegisterR
146
149
147
150
See also the [godoc of Go-MySQL-Driver](http://godoc.org/github.com/go-sql-driver/mysql"golang mysql driver documentation")
148
151
152
+
### `time.Time` support
153
+
The default internal output type of MySQL `DATE` and `DATETIME` values is `[]byte` which allows you to scan the value into a `[]byte`, `string` or `sql.RawBytes` variable in your programm.
154
+
155
+
However, many want to scan MySQL `DATE` and `DATETIME` values into `time.Time` variables, which is the logical opposite in Go to `DATE` and `DATETIME` in MySQL. You can do that by changing the internal output type from `[]byte` to `time.Time` with the DSN parameter `parseTime=true`. You can set the default [`time.Time` location](http://golang.org/pkg/time/#Location) with the `loc` DSN parameter.
156
+
**Caution:** As of Go 1.1, this makes `time.Time` the only variable type you can scan `DATE` and `DATETIME` values into. This breaks for example [`sql.RawBytes` support](https://github.com/go-sql-driver/mysql/wiki/Examples#rawbytes).
157
+
158
+
149
159
150
160
## Testing / Development
151
161
To run the driver tests you may need to adjust the configuration. See [this Wiki-Page](https://github.com/go-sql-driver/mysql/wiki/Testing"Testing") for details.
0 commit comments