Melkeydev / go-blueprint

Go-blueprint allows users to spin up a quick Go project using a popular framework
MIT License
2.07k stars 141 forks source link

Implement [Database Template] [MySQL] [PostgreSQL] [SQLite] Close Database Connection #204

Closed H0llyW00dzZ closed 1 week ago

H0llyW00dzZ commented 1 month ago

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

Problem/Feature

By implementing this Close Database Connection, it can be useful in scenarios such as graceful shutdown, for example, in Kubernetes (k8s).

Description of Changes:

Note: By using the "log.Printf" method, it is more concise and idiomatic Go.

Checklist

briancbarrow commented 1 month ago

Hey @H0llyW00dzZ, another good idea but we'd need the changes in all the db files, not just MySQL.

H0llyW00dzZ commented 1 month ago

Hey @H0llyW00dzZ, another good idea but we'd need the changes in all the db files, not just MySQL.

@briancbarrow, have to test later one by one for other database

briancbarrow commented 1 month ago

Hey @H0llyW00dzZ, another good idea but we'd need the changes in all the db files, not just MySQL.

@briancbarrow, have to test later one by one for other database

I'm going to move this PR into draft until the other databases have been supported. Ping me again when it is ready.

H0llyW00dzZ commented 1 month ago

Hey @H0llyW00dzZ, another good idea but we'd need the changes in all the db files, not just MySQL.

@briancbarrow, have to test later one by one for other database

I'm going to move this PR into draft until the other databases have been supported. Ping me again when it is ready.

I think any database driver supported database/sql it supported to call this Close()

briancbarrow commented 1 month ago

Hey @H0llyW00dzZ, another good idea but we'd need the changes in all the db files, not just MySQL.

@briancbarrow, have to test later one by one for other database

I'm going to move this PR into draft until the other databases have been supported. Ping me again when it is ready.

I think any database driver supported database/sql it supported to call this Close()

Have you tested this that it works with the other databases?

H0llyW00dzZ commented 1 month ago

Hey @H0llyW00dzZ, another good idea but we'd need the changes in all the db files, not just MySQL.

@briancbarrow, have to test later one by one for other database

I'm going to move this PR into draft until the other databases have been supported. Ping me again when it is ready.

I think any database driver supported database/sql it supported to call this Close()

Have you tested this that it works with the other databases?

currently only Redis and MySQL, was implemented this as well for Redis and MySQL

image

H0llyW00dzZ commented 1 month ago

@briancbarrow Anyway, it's possible to close the connection for any database supported by the standard library's . So, I think I'm going to implement this for MySQL, PostgreSQL, and SQLite.

H0llyW00dzZ commented 1 month ago

@briancbarrow Done, by the way. Only Redis and MongoDB are left, and they must be implemented independently because they are not supported by the standard library's.

H0llyW00dzZ commented 1 month ago

[!NOTE] Also note that this is pretty useful when used for restarting or shutting down, because if the server or service is shut down or restarted without closing the connection, the connection will remain open and could lead to potential deadlocks/hangs for the database (e.g., MySQL, PostgreSQL, SQLite).