(key string, min rangeCap, max rangeCap, attribute string)
| 125 | } |
| 126 | |
| 127 | func (c Client) zGeneralCount(key string, min rangeCap, max rangeCap, attribute string) (count int64, err error) { |
| 128 | builder := newExpresionBuilder() |
| 129 | builder.addConditionEquality(c.pk, StringValue{key}) |
| 130 | |
| 131 | betweenRange := min.present() && max.present() |
| 132 | |
| 133 | if betweenRange { |
| 134 | builder.condition(fmt.Sprintf("#%v BETWEEN :min AND :max", attribute), attribute) |
| 135 | } |
| 136 | |
| 137 | if min.present() { |
| 138 | builder.values["min"] = min.ToAV() |
| 139 | |
| 140 | if !betweenRange { |
| 141 | builder.condition(fmt.Sprintf("#%v >= :min", attribute), attribute) |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | if max.present() { |
| 146 | builder.values["max"] = max.ToAV() |
| 147 | |
| 148 | if !betweenRange { |
| 149 | builder.condition(fmt.Sprintf("#%v <= :max", attribute), attribute) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | hasMoreResults := true |
| 154 | |
| 155 | var lastEvaluatedKey map[string]dynamodb.AttributeValue |
| 156 | |
| 157 | var queryIndex *string |
| 158 | |
| 159 | if attribute == c.skN { |
| 160 | queryIndex = aws.String(c.index) |
| 161 | } |
| 162 | |
| 163 | for hasMoreResults { |
| 164 | resp, err := c.ddbClient.QueryRequest(&dynamodb.QueryInput{ |
| 165 | ConsistentRead: aws.Bool(c.consistentReads), |
| 166 | ExclusiveStartKey: lastEvaluatedKey, |
| 167 | ExpressionAttributeNames: builder.expressionAttributeNames(), |
| 168 | ExpressionAttributeValues: builder.expressionAttributeValues(), |
| 169 | IndexName: queryIndex, |
| 170 | KeyConditionExpression: builder.conditionExpression(), |
| 171 | Select: dynamodb.SelectCount, |
| 172 | TableName: aws.String(c.table), |
| 173 | }).Send(context.TODO()) |
| 174 | |
| 175 | if err != nil { |
| 176 | return count, err |
| 177 | } |
| 178 | |
| 179 | count += aws.Int64Value(resp.Count) |
| 180 | |
| 181 | if len(resp.LastEvaluatedKey) > 0 { |
| 182 | lastEvaluatedKey = resp.LastEvaluatedKey |
| 183 | } else { |
| 184 | hasMoreResults = false |
no test coverage detected