Example #1
0
// GetRaw runs the provided postgres query and args against this sqlquery's db.
func (q SqlQuery) GetRaw(ctx context.Context, query string, args []interface{}, dest interface{}) error {
	db := sqlx.NewDb(q.DB, "postgres")
	log.WithField(ctx, "sql", query).Info("query sql")
	log.WithField(ctx, "args", args).Debug("query args")

	return db.Get(dest, query, args...)
}
Example #2
0
func (q SqlQuery) Select(ctx context.Context, sql sq.SelectBuilder, dest interface{}) error {
	db := sqlx.NewDb(q.DB, "postgres")
	sql = sql.PlaceholderFormat(sq.Dollar)
	query, args, err := sql.ToSql()

	if err != nil {
		return err
	}

	log.WithField(ctx, "sql", query).Info("Executing query")

	return db.Select(dest, query, args...)
}
Example #3
0
// run is the workhorse of the stream pump system.  It facilitates the triggering
// of open streams by closing a new channel every time the input pump sends.
func run() {
	for {
		select {
		case at, more := <-pump:
			log.WithField(ctx, "time", at).Debug("sse pump")

			prev := nextTick
			nextTick = make(chan struct{})
			// trigger all listeners by closing the nextTick channel
			close(prev)

			if !more {
				return
			}
		case <-ctx.Done():
			pump = nil
			return
		}
	}
}