Documentation ¶
Index ¶
- type CachedExecutor
- type Config
- type CreateDatasource
- type CreateQuery
- type Datasource
- type DatasourceStore
- type Duration
- type Executor
- type InMemoryCache
- type Query
- type QueryCache
- type QueryStore
- type RedisCache
- type SQLDatasourceStore
- func (s *SQLDatasourceStore) Create(userID string, ca *CreateDatasource) (*Datasource, error)
- func (s *SQLDatasourceStore) Delete(userID, id string) (*Datasource, error)
- func (s *SQLDatasourceStore) Get(userID, id string) (*Datasource, error)
- func (s *SQLDatasourceStore) List(userID string, page, per int) ([]*Datasource, error)
- func (s *SQLDatasourceStore) Update(userID, id string, ua *UpdateDatasource) (*Datasource, error)
- type SQLExecutor
- type SQLQueryStore
- func (s *SQLQueryStore) Create(userID string, ca *CreateQuery) (*Query, error)
- func (s *SQLQueryStore) Delete(userID, id string) (*Query, error)
- func (s *SQLQueryStore) Get(userID, id string) (*Query, error)
- func (s *SQLQueryStore) List(userID string, page, per int) ([]*Query, error)
- func (s *SQLQueryStore) Update(userID, id string, uq *UpdateQuery) (*Query, error)
- type TestExecutor
- type UpdateDatasource
- type UpdateQuery
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CachedExecutor ¶
type CachedExecutor struct { Cache QueryCache Executor Executor Store QueryStore Clock utils.Clock }
CachedExecutor implements Executor that caches query results for the given Lifetime of a Query
func NewCachedExecutor ¶
func NewCachedExecutor(cache QueryCache, store QueryStore, clock utils.Clock, executor Executor) *CachedExecutor
NewCachedExecutor sets up a new CachedExecutor
type Config ¶
type Config struct { QueryStore QueryStore DatasourceStore DatasourceStore Executor Executor Cache QueryCache Clock utils.Clock }
Config contains everything external required to setup querycache
func (*Config) SetupHandlers ¶
SetupHandlers mounts the querycache handlers onto the given mux
type CreateDatasource ¶
type CreateDatasource struct { Name string `json:"name"` Type string `json:"type"` Options string `json:"options"` }
CreateDatasource describes the required paramater to create a new Datasource
type CreateQuery ¶
type CreateQuery struct { Query string `json:"query"` Lifetime Duration `json:"lifetime"` DatasourceID string `json:"datasourceId"` }
CreateQuery describes the required parameter to create a new Query
type Datasource ¶
type Datasource struct { ID string `json:"id" db:"id"` UserID string `json:"userId" db:"user_id"` Name string `json:"name"` Type string `json:"type"` Options string `json:"options"` CreatedAt time.Time `json:"createdAt" db:"created_at"` UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` }
Datasource describes a database that Queries may be related to and executed against
func (*Datasource) NewExecutor ¶
func (a *Datasource) NewExecutor() (Executor, error)
NewExecutor returns a new SQLExecutor configured against this Datasource Will return a TestExecutor if the datasources "Type" is "test"
type DatasourceStore ¶
type DatasourceStore interface { Get(string, string) (*Datasource, error) Create(string, *CreateDatasource) (*Datasource, error) List(string, int, int) ([]*Datasource, error) Delete(string, string) (*Datasource, error) Update(string, string, *UpdateDatasource) (*Datasource, error) }
DatasourceStore describes a generic Store for Datasources
type Duration ¶
Duration is an alias to time.Duration to allow for defining JSON marshalling and unmarshalling
func (Duration) MarshalJSON ¶
MarshalJSON marshals a Duration into JSON
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON unmarshals JSON into a Duration
type InMemoryCache ¶
InMemoryCache is an in-memory implementation of QueryCache
func NewInMemoryCache ¶
func NewInMemoryCache() *InMemoryCache
NewInMemoryCache sets up a new InMemoryCache
type Query ¶
type Query struct { ID string `json:"id"` UserID string `json:"userId" db:"user_id"` Query string `json:"query"` DatasourceID string `json:"datasourceId" db:"datasource_id"` Lifetime Duration `json:"lifetime"` CreatedAt time.Time `json:"createdAt" db:"created_at"` UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` LastRefresh time.Time `json:"lastRefresh" db:"last_refresh"` }
Query describes an SQL query on a given datasource that should be cached for a given Lifetime value
type QueryCache ¶
QueryCache defines the interface for a cache of query results
type QueryStore ¶
type QueryStore interface { Get(string, string) (*Query, error) Create(string, *CreateQuery) (*Query, error) List(string, int, int) ([]*Query, error) Delete(string, string) (*Query, error) Update(string, string, *UpdateQuery) (*Query, error) }
QueryStore describes a generic Store for Queries
type RedisCache ¶
type RedisCache struct {
Client *redis.Client
}
RedisCache is a redis-backed implementation of QueryCache
type SQLDatasourceStore ¶
type SQLDatasourceStore struct {
// contains filtered or unexported fields
}
SQLDatasourceStore describes an SQL implementation of DatasourceStore
func NewSQLDatasourceStore ¶
func NewSQLDatasourceStore(db *hnysqlx.DB, clock utils.Clock, generator utils.IDGenerator) *SQLDatasourceStore
NewSQLDatasourceStore retunes a new SQLDatasourceStore
func (*SQLDatasourceStore) Create ¶
func (s *SQLDatasourceStore) Create(userID string, ca *CreateDatasource) (*Datasource, error)
Create creates and persists a new Datasource to the Store
func (*SQLDatasourceStore) Delete ¶
func (s *SQLDatasourceStore) Delete(userID, id string) (*Datasource, error)
Delete removes the Datasource with given id from the Store
func (*SQLDatasourceStore) Get ¶
func (s *SQLDatasourceStore) Get(userID, id string) (*Datasource, error)
Get returns the Datasource with associated id from the store
func (*SQLDatasourceStore) List ¶
func (s *SQLDatasourceStore) List(userID string, page, per int) ([]*Datasource, error)
List returns the requests Datasources from the Store, ordered by createdAt
func (*SQLDatasourceStore) Update ¶
func (s *SQLDatasourceStore) Update(userID, id string, ua *UpdateDatasource) (*Datasource, error)
Update updates the Datasource with associated id from the store
type SQLExecutor ¶
type SQLExecutor struct {
// contains filtered or unexported fields
}
SQLExecutor implements Executor against an *sql.DB
func NewSQLExecutor ¶
func NewSQLExecutor(driver, conn string) (*SQLExecutor, error)
NewSQLExecutor builds a new SQLExecutor, parameters are passed to sql.Open
type SQLQueryStore ¶
type SQLQueryStore struct {
// contains filtered or unexported fields
}
SQLQueryStore defines an SQL implementation of a QueryStore
func NewSQLQueryStore ¶
func NewSQLQueryStore(db *hnysqlx.DB, clock utils.Clock, generator utils.IDGenerator) *SQLQueryStore
NewSQLQueryStore builds a new SQLQueryStore
func (*SQLQueryStore) Create ¶
func (s *SQLQueryStore) Create(userID string, ca *CreateQuery) (*Query, error)
Create creates and persist to memory a Query from a CreateQuery struct
func (*SQLQueryStore) Delete ¶
func (s *SQLQueryStore) Delete(userID, id string) (*Query, error)
Delete removes the Query with associated id from the store
func (*SQLQueryStore) Get ¶
func (s *SQLQueryStore) Get(userID, id string) (*Query, error)
Get returns the Query with associated id from the store
func (*SQLQueryStore) List ¶
func (s *SQLQueryStore) List(userID string, page, per int) ([]*Query, error)
List returns the requests Queries from the Store, ordered by createdAt
func (*SQLQueryStore) Update ¶
func (s *SQLQueryStore) Update(userID, id string, uq *UpdateQuery) (*Query, error)
Update updates the Query with associated id from the store
type TestExecutor ¶
type TestExecutor struct{}
TestExecutor implements an Executor that echoes the passed query
type UpdateDatasource ¶
type UpdateDatasource struct { Name *string `json:"name"` Type *string `json:"type"` Options *string `json:"options"` }
UpdateDatasource describes the paramater which may be updated on a Datasource
type UpdateQuery ¶
type UpdateQuery struct { Lifetime *Duration `json:"lifetime"` LastRefresh time.Time `json:"lastRefresh"` }
UpdateQuery describes the paramater which may be updated on a Query