In Development Package, API may change between versions.

import "github.com/egdaemon/eg/runtime/x/wasi/egdb"

Package egdb provides access to the analytics database of the workload.

func Cache

func Cache(ctx context.Context, _ eg.Op) error

Cache persists a copy of the analytics database of this workload into the cache directory, making it available to Latest in later runs of the workload, including runs that do not go through the control plane. it is intended to be the last operation of the workload: it is only reached when everything before it succeeded.

func Check

func Check(ctx context.Context, _ eg.Op) error

Check logs whether the analytics database is available where it is run, i.e.) whether Cache can work there, and whether a copy of it is already cached. a debugging aid, it never fails: what it found is in the log.

func Latest

func Latest(ctx context.Context, options ...LatestOption) (_ string, err error)

Latest provides the path of a local copy of the analytics database of the last successful run of the workload. the copy is stored in the cache directory, when it already exists it is returned as is, otherwise it is downloaded from the control plane. see Cache for keeping the copy current.

returns an error matching os.ErrNotExist when the workload has no successful runs.

func Open

func Open(ctx context.Context) *sql.DB

Open a connection pool to the workload database served by the runner. connections are made when they are first used, use OpenVerify to know the database is reachable. callers must Close the result.

func OpenMigrate

func OpenMigrate(ctx context.Context) (*sql.DB, error)

OpenMigrate is Open after migrating the database to the schema this version of eg writes, so a guest does not depend on the runner having created the same schema, e.g.) a runner older than the guest. migrations already applied are skipped. disabled by setting EG_COMPUTE_GUEST_MIGRATIONS_ENABLED to false, which makes it Open. the connection is verified before returning; callers must Close the result.

func OpenVerify

func OpenVerify(ctx context.Context) (*sql.DB, error)

OpenVerify a connection pool to the workload database served by the runner. the connection is verified before returning; callers must Close the result.

type File

File is a read only connection pool to a database file, see OpenFile.

type File struct {
    *sql.DB
    // contains filtered or unexported fields
}

func OpenFile

func OpenFile(ctx context.Context, path string) (*File, error)

OpenFile opens the database file at path, e.g.) the file provided by Latest, read only. the file is served by the runner separately from the analytics database, which is not touched. the connection is verified before returning; callers must Close the result.

func (*File) Close

func (t *File) Close() error

Close the connection pool and release the file, once every handle of the file has been closed it is no longer served.

type LatestOption

LatestOption configures Latest.

type LatestOption func(*latest)

func WithClient

func WithClient(c *http.Client) LatestOption

WithClient overrides the http client used to talk to the control plane.

func WithEndpoint

func WithEndpoint(endpoint string) LatestOption

WithEndpoint overrides the base url of the control plane api.

func WithWorkload

func WithWorkload(entry string) LatestOption

WithWorkload selects the workload (module name, see eg.DefaultWorkload) to find the last successful run of. defaults to the workload currently running.

⬤