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, estimated_chunks, completed_chunks, completed_on, created_at, updated_at, plan_id 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 }