feat: add go mysql

main
sudo pacman -Syu 2023-03-05 16:44:02 +07:00
parent e68cb49d66
commit 3e672cb1c1
2 changed files with 38 additions and 0 deletions

View File

@ -566,6 +566,25 @@ internal
<span class="pl-k">return</span> <span class="pl-c1">nil</span> <span class="pl-k">return</span> <span class="pl-c1">nil</span>
}</pre> }</pre>
</div> </div>
<h3>
<a
id="user-content-connect-mysql-with-go-sql-drivermysql"
class="anchor"
aria-hidden="true"
href="#connect-mysql-with-go-sql-drivermysql"
><span aria-hidden="true" class="octicon octicon-link"></span></a
>Connect MySQL with
<a href="https://github.com/go-sql-driver/mysql">go-sql-driver/mysql</a>
</h3>
<p>Remember to config:</p>
<ul>
<li><code>SetConnMaxLifetime</code></li>
<li><code>SetMaxOpenConns</code></li>
<li><code>SetMaxIdleConns</code></li>
<li><code>ParseTime</code> to true.</li>
<li><code>Loc</code> to <code>time.UTC</code>.</li>
<li><code>CheckConnLiveness</code> to true.</li>
</ul>
<h3> <h3>
<a <a
id="user-content-if-you-want-test-just-use-stretchrtestify" id="user-content-if-you-want-test-just-use-stretchrtestify"
@ -735,6 +754,13 @@ fieldalignment -fix ./internal/business/<span class="pl-k">*</span>.go</pre>
>Google Go Style</a >Google Go Style</a
> >
</li> </li>
<li>
<a
href="https://github.blog/2020-05-20-three-bugs-in-the-go-mysql-driver/"
rel="nofollow"
>Three bugs in the Go MySQL Driver</a
>
</li>
</ul> </ul>
<div> <div>

View File

@ -279,6 +279,17 @@ func (c *client) HSetWithExpire(ctx context.Context, key string, values []any, e
} }
``` ```
### Connect MySQL with [go-sql-driver/mysql](https://github.com/go-sql-driver/mysql)
Remember to config:
- `SetConnMaxLifetime`
- `SetMaxOpenConns`
- `SetMaxIdleConns`
- `ParseTime` to true.
- `Loc` to `time.UTC`.
- `CheckConnLiveness` to true.
### If you want test, just use [stretchr/testify](https://github.com/stretchr/testify). ### If you want test, just use [stretchr/testify](https://github.com/stretchr/testify).
It is easy to write a suite test, thanks to testify. It is easy to write a suite test, thanks to testify.
@ -358,3 +369,4 @@ fieldalignment -fix ./internal/business/*.go
- [Uber Go Style Guide](https://github.com/uber-go/guide/blob/master/style.md) - [Uber Go Style Guide](https://github.com/uber-go/guide/blob/master/style.md)
- [Functional options for friendly APIs](https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis) - [Functional options for friendly APIs](https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis)
- [Google Go Style](https://google.github.io/styleguide/go/index) - [Google Go Style](https://google.github.io/styleguide/go/index)
- [Three bugs in the Go MySQL Driver](https://github.blog/2020-05-20-three-bugs-in-the-go-mysql-driver/)