CountContext count all matching resources in the db
(ctx context.Context, s *schema.Schema, filter transaction.Filter)
| 1077 | |
| 1078 | //CountContext count all matching resources in the db |
| 1079 | func (tx *Transaction) CountContext(ctx context.Context, s *schema.Schema, filter transaction.Filter) (res uint64, err error) { |
| 1080 | defer tx.measureTime(time.Now(), s.ID, "count") |
| 1081 | |
| 1082 | q := sq.Select("Count(id) as count").From(quote(s.GetDbTableName())) |
| 1083 | //Filter get already tested |
| 1084 | q, _ = AddFilterToQuery(s, q, filter, false) |
| 1085 | sql, args, err := q.ToSql() |
| 1086 | if err != nil { |
| 1087 | return |
| 1088 | } |
| 1089 | result := map[string]interface{}{} |
| 1090 | err = tx.transaction.QueryRowxContext(ctx, sql, args...).MapScan(result) |
| 1091 | if err != nil { |
| 1092 | return |
| 1093 | } |
| 1094 | count, _ := result["count"] |
| 1095 | decoder := &integerHandler{} |
| 1096 | decoded, decodeErr := decoder.decode(nil, count) |
| 1097 | if decodeErr != nil { |
| 1098 | err = fmt.Errorf("SQL List decoding error: %s", decodeErr) |
| 1099 | return |
| 1100 | } |
| 1101 | res = uint64(decoded.(int)) |
| 1102 | return |
| 1103 | } |
| 1104 | |
| 1105 | func (tx *Transaction) Fetch(s *schema.Schema, filter transaction.Filter, options *transaction.ViewOptions) (*schema.Resource, error) { |
| 1106 | return tx.FetchContext(context.Background(), s, filter, options) |
no test coverage detected