code: func (ss *SQLSubStore) CreateSub(sub *spb.SubState) error {
  	ss.Lock()
  	defer ss.Unlock()
  	// Check limits only if needed
  	if ss.limits.MaxSubscriptions > 0 {
  		r := ss.sqlStore.preparedStmts[sqlCheckMaxSubs].QueryRow(ss.channelID)
  		count := 0
  		if err := r.Scan(&count); err != nil {
  			return sqlStmtError(sqlCheckMaxSubs, err)
  		}
  		if count >= ss.limits.MaxSubscriptions {
  			return ErrTooManySubs
  		}
  	}
  	sub.ID = atomic.AddUint64(ss.maxSubID, 1)
  	subBytes, _ := sub.Marshal()
  	if _, err := ss.sqlStore.preparedStmts[sqlCreateSub].Exec(ss.channelID, sub.ID, subBytes); err != nil {
  		sub.ID = 0
  		return sqlStmtError(sqlCreateSub, err)
  	}
  	if ss.hasMarkedAsDel {
  		if _, err := ss.sqlStore.preparedStmts[sqlDeleteSubMarkedAsDeleted].Exec(ss.channelID); err != nil {
  			return sqlStmtError(sqlDeleteSubMarkedAsDeleted, err)
  		}
  		ss.hasMarkedAsDel = false
  	}
  	return nil
  }
docs: ////////////////////////////////////////////////////////////////////////////
  // SQLSubStore methods
  ////////////////////////////////////////////////////////////////////////////
  // CreateSub implements the SubStore interface