1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-12 11:15:14 +02:00
ferret/ferret.go
Tim Voronov 8a772851f4
Removed old CLI (#608)
* Removed old CLI

* Added mini-CLI for e2e tests
2021-04-08 18:46:17 -04:00

49 lines
948 B
Go

package ferret
import (
"context"
"github.com/MontFerret/ferret/pkg/compiler"
"github.com/MontFerret/ferret/pkg/drivers"
"github.com/MontFerret/ferret/pkg/runtime"
"github.com/MontFerret/ferret/pkg/runtime/core"
)
type Instance struct {
compiler *compiler.Compiler
drivers *drivers.Container
}
func New() *Instance {
return &Instance{
compiler: compiler.New(),
drivers: drivers.NewContainer(),
}
}
func (i *Instance) Functions() core.Namespace {
return i.compiler
}
func (i *Instance) Drivers() *drivers.Container {
return i.drivers
}
func (i *Instance) Compile(query string) (*runtime.Program, error) {
return i.compiler.Compile(query)
}
func (i *Instance) Exec(ctx context.Context, query string, opts ...runtime.Option) ([]byte, error) {
p, err := i.Compile(query)
if err != nil {
return nil, err
}
for _, drv := range i.drivers.GetAll() {
ctx = drivers.WithContext(ctx, drv)
}
return p.Run(ctx, opts...)
}