mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* datastore no longer implements logstore the underlying implementation of our sql store implements both the datastore and the logstore interface, however going forward we are likely to encounter datastore implementers that would mock out the logstore interface and not use its methods - signalling a poor interface. this remedies that, now they are 2 completely separate things, which our sqlstore happens to implement both of. related to some recent changes around wrapping, this keeps the imposed metrics and validation wrapping of a servers logstore and datastore, just moving it into New instead of in the opts - this is so that a user can have the underlying datastore in order to set the logstore to it, since wrapping it in a validator/metrics would render it no longer a logstore implementer (i.e. validate datastore doesn't implement the logstore interface), we need to do this after setting the logstore to the datastore if one wasn't provided explicitly. * splits logstore and datastore metrics & validation logic * `make test` should be `make full-test` always. got rid of that so that nobody else has to wait for CI to blow up on them after the tests pass locally ever again. * fix new tests
68 lines
3.0 KiB
Go
68 lines
3.0 KiB
Go
package models
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
type Datastore interface {
|
|
// GetAppByID gets an App by ID.
|
|
// Returns ErrDatastoreEmptyAppID for empty appID.
|
|
// Returns ErrAppsNotFound if no app is found.
|
|
GetAppByID(ctx context.Context, appID string) (*App, error)
|
|
|
|
// GetAppID gets an app ID by app name, ensures if app exists.
|
|
// Returns ErrDatastoreEmptyAppName for empty appName.
|
|
// Returns ErrAppsNotFound if no app is found.
|
|
GetAppID(ctx context.Context, appName string) (string, error)
|
|
|
|
// GetApps gets a slice of Apps, optionally filtered by name.
|
|
// Missing filter or empty name will match all Apps.
|
|
GetApps(ctx context.Context, filter *AppFilter) ([]*App, error)
|
|
|
|
// InsertApp inserts an App. Returns ErrDatastoreEmptyApp when app is nil, and
|
|
// ErrDatastoreEmptyAppName when app.Name is empty.
|
|
// Returns ErrAppsAlreadyExists if an App by the same name already exists.
|
|
InsertApp(ctx context.Context, app *App) (*App, error)
|
|
|
|
// UpdateApp updates an App's Config. Returns ErrDatastoreEmptyApp when app is nil, and
|
|
// ErrDatastoreEmptyAppName when app.Name is empty.
|
|
// Returns ErrAppsNotFound if an App is not found.
|
|
UpdateApp(ctx context.Context, app *App) (*App, error)
|
|
|
|
// RemoveApp removes the App named appName. Returns ErrDatastoreEmptyAppName if appName is empty.
|
|
// Returns ErrAppsNotFound if an App is not found.
|
|
RemoveApp(ctx context.Context, appID string) error
|
|
|
|
// GetRoute looks up a matching Route for appName and the literal request route routePath.
|
|
// Returns ErrDatastoreEmptyAppName when appName is empty, and ErrDatastoreEmptyRoutePath when
|
|
// routePath is empty.
|
|
// Returns ErrRoutesNotFound when no matching route is found.
|
|
GetRoute(ctx context.Context, appID, routePath string) (*Route, error)
|
|
|
|
// GetRoutesByApp gets a slice of routes for a appName, optionally filtering on filter (filter.AppName is ignored).
|
|
// Returns ErrDatastoreEmptyAppName if appName is empty.
|
|
GetRoutesByApp(ctx context.Context, appID string, filter *RouteFilter) ([]*Route, error)
|
|
|
|
// InsertRoute inserts a route. Returns ErrDatastoreEmptyRoute when route is nil, and ErrDatastoreEmptyAppName
|
|
// or ErrDatastoreEmptyRoutePath for empty AppName or Path.
|
|
// Returns ErrRoutesAlreadyExists if the exact route.Path already exists
|
|
InsertRoute(ctx context.Context, route *Route) (*Route, error)
|
|
|
|
// UpdateRoute updates route's Config and Header fields. Returns ErrDatastoreEmptyRoute when route is nil, and
|
|
// ErrDatastoreEmptyAppName or ErrDatastoreEmptyRoutePath for empty AppName or Path.
|
|
UpdateRoute(ctx context.Context, route *Route) (*Route, error)
|
|
|
|
// RemoveRoute removes a route. Returns ErrDatastoreEmptyAppID when appName is empty, and
|
|
// ErrDatastoreEmptyRoutePath when routePath is empty. Returns ErrRoutesNotFound when no route exists.
|
|
RemoveRoute(ctx context.Context, appID, routePath string) error
|
|
|
|
// GetDatabase returns the underlying sqlx database implementation
|
|
GetDatabase() *sqlx.DB
|
|
|
|
// implements io.Closer to shutdown
|
|
io.Closer
|
|
}
|