intake/core/channel.go

42 lines
911 B
Go
Raw Normal View History

2025-02-01 01:23:41 +00:00
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
}