Skip to content

Commit

Permalink
Implement getDCs
Browse files Browse the repository at this point in the history
  • Loading branch information
zxia-wish committed Jun 24, 2021
1 parent 3669176 commit d09a955
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,25 @@ func (p *PostgresStore) DeleteTopic(string) error {
}

func (p *PostgresStore) GetDCs() ([]DC, error) {
// TODO: implement this function
return nil, nil
rows, err := p.db.Query("SELECT dc_id, dc from event_dc")
if err != nil {
return nil, err
}
defer rows.Close()
var dcs []DC

var dc_id, dc string
for rows.Next() {
err = rows.Scan(&dc_id, &dc)
if err != nil {
return nil, err
}
dcs = append(dcs, DC{
ID: dc_id,
Name: dc,
})
}
return dcs, nil
}

func (p *PostgresStore) AddDC(dc DC) error {
Expand All @@ -102,7 +119,7 @@ func (p *PostgresStore) AddDC(dc DC) error {
}
_, err = stmt.Exec(dc.ID, dc.Name)
if err != nil {
return errors.Wrap(err, "Failed executing insert DC statement")
return err
}

return nil
Expand Down

0 comments on commit d09a955

Please sign in to comment.