basic logger middleware and formatting

This commit is contained in:
2025-02-09 00:43:50 -05:00
parent c10cc07324
commit 8f8e83a0d7
4 changed files with 21 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ import (
"embed"
"fmt"
"log"
"log/slog"
_ "github.com/mattn/go-sqlite3"
)
@@ -18,6 +19,7 @@ type Migration struct {
}
func Migrate(db *sql.DB) {
slog.Info("Running migrations...")
migrationTableSql := `
CREATE TABLE IF NOT EXISTS migrations(
version INTEGER PRIMARY KEY,
@@ -35,12 +37,11 @@ func Migrate(db *sql.DB) {
}
for _, file := range files {
fmt.Printf("Checking file: %s\n", file.Name())
var migration Migration
row := db.QueryRow("SELECT * FROM migrations WHERE name = ?;", file.Name())
err = row.Scan(&migration.Version, &migration.Name)
if err == sql.ErrNoRows {
fmt.Printf("Running migration: %s\n", file.Name())
slog.Info(fmt.Sprintf("Running migration: %s", file.Name()))
migrationSql, err := migrations.ReadFile(fmt.Sprintf("migrations/%s", file.Name()))
if err != nil {
log.Fatal(err)
@@ -57,4 +58,5 @@ func Migrate(db *sql.DB) {
}
}
}
slog.Info("Migrations completed")
}

View File

@@ -16,7 +16,6 @@ func NewInMemoryTodoRepository() InMemoryTodoRepository {
}
}
func (r *InMemoryTodoRepository) GetById(id int64) (repository.TodoRow, error) {
todo, found := r.Db[id]

View File

@@ -9,7 +9,7 @@ var (
)
type TodoRow struct {
Id int64
Id int64
Name string
Done bool
}