This repository has been archived on 2021-09-01. You can view files and clone it, but cannot push or open issues or pull requests.
goddit/postgres/store.go

33 lines
629 B
Go
Raw Normal View History

package postgres
import (
"fmt"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
)
func NewStore(dataSourceName string) (*Store, error) {
db, err := sqlx.Open("postgres", dataSourceName)
if err != nil {
return nil, fmt.Errorf("error opening database: %w", err)
}
if err := db.Ping(); err != nil {
return nil, fmt.Errorf("error connecting to database: %w", err)
}
return &Store{
ThreadStore: &ThreadStore{DB: db},
PostStore: &PostStore{DB: db},
CommentStore: &CommentStore{DB: db},
UserStore: &UserStore{DB: db},
}, nil
}
type Store struct {
*ThreadStore
*PostStore
*CommentStore
*UserStore
}