Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

revisit the QueryResult interface #134

@travisturner

Description

@travisturner

We may be able to simplify the QueryResult interface.

// QueryResult represents one of the results in the response.
type QueryResult interface {
	Type() uint32
	Bitmap() BitmapResult
	CountItems() []CountResultItem
	Count() int64
	Sum() int64
	Changed() bool
}

Because each function is specific to the type, it's effectively an empty interface. And every implementation is left with unused methods:

func (BitmapResult) Type() uint32                  { return QueryResultTypeBitmap }
func (b BitmapResult) Bitmap() BitmapResult        { return b }
func (BitmapResult) CountItems() []CountResultItem { return nil }
func (BitmapResult) Count() int64                  { return 0 }
func (BitmapResult) Value() int64                  { return 0 }
func (BitmapResult) Changed() bool                 { return false }

I could see it being something like this instead:

type QueryResult interface{}

type BitmapResult struct {
    QueryResult

    Attributes map[string]interface{} `json:"attrs"`
    Bits       []uint64               `json:"bits"`
    Keys       []string               `json:"keys"`
}

In this case the QueryResult inside the BitmapResult is not really necessary because everything implements the empty interface, but if for some reason QueryResult needs to have a function defined, this would ensure BitmapResult implements the interface.

This is not at all a high priority, but may be worth revisiting at some point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions