intake/core/channel.go
2025-01-31 17:24:30 -08:00

42 lines
911 B
Go

package core
func AddSourceToChannel(db DB, channel string, source string) error {
_, err := db.Exec(`
insert into channels (name, source)
values (?, ?)
`, channel, source)
return err
}
func DeleteSourceFromChannel(db DB, channel string, source string) error {
_, err := db.Exec(`
delete from channels
where name = ? and source = ?
`, channel, source)
return err
}
func GetSourcesInChannel(db DB) (map[string][]string, error) {
rows, err := db.Query(`
select name, source
from channels
order by name, source
`)
if err != nil {
return nil, err
}
defer rows.Close()
channelSources := make(map[string][]string)
for rows.Next() {
var name, source string
if err := rows.Scan(&name, &source); err != nil {
return nil, err
}
channelSources[name] = append(channelSources[name], source)
}
if err := rows.Err(); err != nil {
return nil, err
}
return channelSources, nil
}