コード例 #1
0
ファイル: pg.go プロジェクト: waterlink/rebecca
// First is for fetching only first specific record from current context matching given where query and arguments
func (d *Driver) First(tablename string, fields []field.Field, ctx context.Context, where string, args ...interface{}) ([]field.Field, error) {
	firstCtx := ctx.SetLimit(1)
	names := fieldNames(fields)

	query := "SELECT %s FROM %s WHERE %s %s"
	query = fmt.Sprintf(query, namesRepr(names), tablename, where, contextFor(firstCtx))
	return d.readRow(ctx.GetTx(), fields, query, args...)
}