All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
38 lines
922 B
Go
38 lines
922 B
Go
package store
|
|
|
|
import (
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
"gitea.deepak.science/deepak/gogmagog/models"
|
|
"gitea.deepak.science/deepak/gogmagog/util"
|
|
)
|
|
|
|
type postgresStore struct {
|
|
db *sqlx.DB
|
|
}
|
|
|
|
// GetPostgresStore provides a store to back the model based on a postgres connection.
|
|
func GetPostgresStore(db *sqlx.DB) (models.Store, error) {
|
|
|
|
db.MapperFunc(util.ToSnake)
|
|
return &postgresStore{db: db}, nil
|
|
}
|
|
|
|
func (store *postgresStore) SelectActions() ([]*models.Action, error) {
|
|
actions := make([]*models.Action, 0)
|
|
err := store.db.Select(&actions, "SELECT action_id, action_description, created_at, updated_at FROM actions")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return actions, nil
|
|
}
|
|
|
|
func (store *postgresStore) SelectPlans() ([]*models.Plan, error) {
|
|
plans := make([]*models.Plan, 0)
|
|
err := store.db.Select(&plans, "SELECT plan_id, plan_date FROM plans")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return plans, nil
|
|
}
|