postgres
This commit is contained in:
@@ -10,9 +10,10 @@ import (
|
||||
"gitea.michaelthomson.dev/mthomson/habits/internal/middleware"
|
||||
"gitea.michaelthomson.dev/mthomson/habits/internal/migrate"
|
||||
todohandler "gitea.michaelthomson.dev/mthomson/habits/internal/todo/handler"
|
||||
todorepository "gitea.michaelthomson.dev/mthomson/habits/internal/todo/repository/sqlite"
|
||||
todorepository "gitea.michaelthomson.dev/mthomson/habits/internal/todo/repository/postgres"
|
||||
todoservice "gitea.michaelthomson.dev/mthomson/habits/internal/todo/service"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
_ "github.com/jackc/pgx/v5/stdlib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -23,18 +24,18 @@ func main() {
|
||||
loggingMiddleware := middleware.LoggingMiddleware(httpLogger)
|
||||
|
||||
// create db pool
|
||||
db, err := sql.Open("sqlite3", "./habits.db")
|
||||
postgresUrl := "postgres://todo:password@localhost:5432/todo"
|
||||
db, err := sql.Open("pgx", postgresUrl)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to open db pool")
|
||||
}
|
||||
|
||||
defer db.Close()
|
||||
|
||||
// run migrations
|
||||
migrate.Migrate(db)
|
||||
|
||||
// create repos
|
||||
todoRepository := todorepository.NewSqliteTodoRepository(db)
|
||||
todoRepository := todorepository.NewPostgresTodoRepository(db)
|
||||
|
||||
// create services
|
||||
todoService := todoservice.NewTodoService(todoRepository)
|
||||
|
||||
Reference in New Issue
Block a user