Updating movies.go with MovieModel: this struct is the gateway between our app and the database. Adding CRUD methods alongside for the Movie object. Creating models.go: this file holds a Models struct wrapping all of our Models. This way, we are able to use in our application struct in our main.go.

This commit is contained in:
Maxime Delporte
2025-11-06 10:41:12 +01:00
parent 0874a6aac4
commit 1a658d3063
3 changed files with 55 additions and 5 deletions

23
internal/data/models.go Normal file
View File

@@ -0,0 +1,23 @@
package data
import (
"database/sql"
"errors"
)
// ErrRecordNotFound : Define a custom ErrRecordNotFound error. We'll return this from our Get() method when looking up a movie that doesn't exist in our database.
var (
ErrRecordNotFound = errors.New("record not found")
)
// Models : Wraps the MovieModel. We'll add other models to this, like a UserModel and PermissionModel, as our build progresses.
type Models struct {
Movies MovieModel
}
// NewModels : For ease of use, this method returns a Models struct containing the initialized MovieModel.
func NewModels(db *sql.DB) Models {
return Models{
Movies: MovieModel{DB: db},
}
}