QuerySingleAttribute queries the database for a single attribute based on the provided filter.
(_ context.Context, tenantID string, filter *base.AttributeFilter, _ string)
| 170 | |
| 171 | // QuerySingleAttribute queries the database for a single attribute based on the provided filter. |
| 172 | func (r *DataReader) QuerySingleAttribute(_ context.Context, tenantID string, filter *base.AttributeFilter, _ string) (attribute *base.Attribute, err error) { |
| 173 | txn := r.database.DB.Txn(false) |
| 174 | defer txn.Abort() |
| 175 | |
| 176 | // Get the index and arguments based on the filter. |
| 177 | index, args := utils.GetAttributesIndexNameAndArgsByFilters(tenantID, filter) |
| 178 | |
| 179 | // Get the result iterator based on the index and arguments. |
| 180 | var result memdb.ResultIterator |
| 181 | result, err = txn.Get(constants.AttributesTable, index, args...) // Query attributes table |
| 182 | if err != nil { |
| 183 | return nil, errors.New(base.ErrorCode_ERROR_CODE_EXECUTION.String()) |
| 184 | } |
| 185 | |
| 186 | // Filter the result iterator and get the first attribute. |
| 187 | fit := memdb.NewFilterIterator(result, utils.FilterAttributesQuery(tenantID, filter)) |
| 188 | obj := fit.Next() |
| 189 | if obj != nil { |
| 190 | t, ok := obj.(storage.Attribute) |
| 191 | if !ok { |
| 192 | return nil, errors.New(base.ErrorCode_ERROR_CODE_TYPE_CONVERSATION.String()) |
| 193 | } |
| 194 | return t.ToAttribute(), nil |
| 195 | } |
| 196 | |
| 197 | return nil, nil |
| 198 | } |
| 199 | |
| 200 | // QueryAttributes queries the database for attributes based on the provided filter. |
| 201 | func (r *DataReader) QueryAttributes(_ context.Context, tenantID string, filter *base.AttributeFilter, _ string, pagination database.CursorPagination) (iterator *database.AttributeIterator, err error) { |
nothing calls this directly
no test coverage detected