Changeset 267 in code for trunk/db.go


Ignore:
Timestamp:
Apr 23, 2020, 2:36:20 PM (5 years ago)
Author:
contact
Message:

Add network.channels, remove DB.GetChannel

Store the list of configured channels in the network data structure.
This removes the need for a database lookup and will be useful for
detached channels.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/db.go

    r263 r267  
    4848        Key  string
    4949}
    50 
    51 var ErrNoSuchChannel = fmt.Errorf("soju: no such channel")
    5250
    5351const schema = `
     
    372370}
    373371
    374 func (db *DB) GetChannel(networkID int64, name string) (*Channel, error) {
    375         db.lock.RLock()
    376         defer db.lock.RUnlock()
    377 
    378         ch := &Channel{Name: name}
    379 
    380         var key *string
    381         row := db.db.QueryRow("SELECT id, key FROM Channel WHERE network = ? AND name = ?", networkID, name)
    382         if err := row.Scan(&ch.ID, &key); err == sql.ErrNoRows {
    383                 return nil, ErrNoSuchChannel
    384         } else if err != nil {
    385                 return nil, err
    386         }
    387         ch.Key = fromStringPtr(key)
    388         return ch, nil
    389 }
    390 
    391372func (db *DB) StoreChannel(networkID int64, ch *Channel) error {
    392373        db.lock.Lock()
Note: See TracChangeset for help on using the changeset viewer.