-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repository): add mysql repository (gorm)
- Loading branch information
Showing
13 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
DATABASE_DSN="mysql://root:imdeo@localhost:23306/imdeo" | ||
DATABASE_DSN="mysql://root:imdeo@tcp(127.0.0.1:3306)/todolist?charset=utf8mb4&parseTime=True&loc=Local" | ||
PORT=5000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: '3.7' | ||
services: | ||
database: | ||
image: mysql:8.0 | ||
ports: | ||
- "23306:3306" | ||
env_file: | ||
- ./mysql/.env | ||
api: | ||
image: ghcr.io/mcauto/todolist-api:latest | ||
build: | ||
context: .. | ||
dockerfile: ./deploy/todolist-api/Dockerfile | ||
env_file: | ||
- ./todolist-api/.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
MYSQL_USER=deokim | ||
MYSQL_PASSWORD=imdeo | ||
MYSQL_ROOT_PASSWORD=imdeo | ||
MYSQL_DATABASE=todolist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[client] | ||
default-character-set=utf8mb4 | ||
|
||
[mysql] | ||
default-character-set=utf8mb4 | ||
|
||
[mysqld] | ||
default-authentication-plugin=mysql_native_password | ||
init-connect='SET collation_connection = utf8mb4_unicode_ci' | ||
init-connect='SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci' | ||
character-set-server = utf8mb4 | ||
collation-server = utf8mb4_unicode_ci | ||
!includedir /etc/mysql/conf.d/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DATABASE_DSN="mysql://root:imdeo@tcp(127.0.0.1:3306)/todolist?charset=utf8mb4&parseTime=True&loc=Local" | ||
PORT=5000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package config | ||
|
||
// DatabaseCmd represents the database command | ||
func (s Settings) DatabaseDSN() string { | ||
return s.Database.DSN | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# repository | ||
|
||
외부 저장소 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package _mysql | ||
|
||
import ( | ||
"log" | ||
"todolist-api/modules/config" | ||
|
||
"gorm.io/driver/mysql" | ||
"gorm.io/gorm" | ||
) | ||
|
||
// Repository is an interface for the repository | ||
type Repository interface{} | ||
|
||
// RepositoryImpl is an implementation of Repository | ||
type RepositoryImpl struct { | ||
*gorm.DB | ||
} | ||
|
||
// NewRepository returns a new instance of Repository | ||
func NewRepository(settings *config.Settings) Repository { | ||
db, err := gorm.Open(mysql.Open(settings.DatabaseDSN()), &gorm.Config{}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
return &RepositoryImpl{db} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package repository | ||
|
||
import ( | ||
"todolist-api/modules/repository/_mysql" | ||
|
||
"go.uber.org/fx" | ||
) | ||
|
||
// Modules is a list of all modules | ||
var Modules = fx.Options(fx.Provide(_mysql.NewRepository)) |