sabisan/internal/store/store.go
V fac53d7b85
All checks were successful
Publish / Test, build, and push image (push) Successful in 3m38s
Refactor app and store layout
2026-05-17 00:03:50 +01:00

82 lines
1.3 KiB
Go

package store
import (
"database/sql"
"os"
"path/filepath"
"time"
_ "github.com/mattn/go-sqlite3"
)
type Store struct {
db *sql.DB
}
type SiteContent struct {
HeroTitle string
HeroSubtitle string
IntroTitle string
IntroText string
AboutName string
AboutRole string
AboutBio string
Email string
Phone string
Location string
HeroImage string
AboutImage string
}
type Project struct {
ID int64
Slug string
Title string
Location string
Year string
Category string
Description string
CoverImage string
Featured bool
CreatedAt time.Time
Images []ProjectImage
}
type ProjectImage struct {
ID int64
ProjectID int64
Path string
Caption string
Position int
}
type ContactRequest struct {
ID int64
Name string
Email string
Message string
CreatedAt time.Time
}
type AdminUser struct {
ID int64
Username string
PasswordHash []byte
}
func Open(path string) (*Store, error) {
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return nil, err
}
db, err := sql.Open("sqlite3", path+"?_foreign_keys=on")
if err != nil {
return nil, err
}
db.SetMaxOpenConns(1)
return &Store{db: db}, db.Ping()
}
func (s *Store) Close() error {
return s.db.Close()
}