expr

package
v0.0.0-...-75e7317 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveReturnType

func ResolveReturnType(resultType any) expr.Option

Types

type Config

type Config struct {
	DB func() DBLike
}

type DB

type DB struct {
	// contains filtered or unexported fields
}

func NewDB

func NewDB(db func() DBLike) *DB

func (*DB) Exec

func (d *DB) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)

func (*DB) Query

func (d *DB) Query(ctx context.Context, query string, args ...any) ([]*entity.Entity, error)

type DBLike

type DBLike interface {
	Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
	Query(ctx context.Context, query string, args ...any) ([]*entity.Entity, error)
}

type Env

type Env[ArgType any] struct {
	Context   context.Context              `expr:"$context"`
	Args      ArgType                      `expr:"$args"`
	DB        *DB                          `expr:"$db"`
	Undefined *Undefined                   `expr:"$undefined"`
	Sprintf   func(string, ...any) string  `expr:"$sprintf"`
	Hash      func(string) (string, error) `expr:"$hash"`
}

func NewEnv

func NewEnv[ArgType any](
	ctx context.Context,
	args ArgType,
	configs ...Config,
) *Env[ArgType]

type Program

type Program[ArgsType any, ResultType any] struct {
	*vm.Program
}

func Compile

func Compile[ArgsType any, ResultType any](
	program string,
	sampleArgs ...ArgsType,
) (*Program[ArgsType, ResultType], error)

func (*Program[ArgsType, ResultType]) Run

func (p *Program[ArgsType, ResultType]) Run(
	ctx context.Context,
	args ArgsType,
	configs ...Config,
) (*Result[ResultType], error)

type Result

type Result[T any] struct {
	// contains filtered or unexported fields
}

func (*Result[T]) IsUndefined

func (r *Result[T]) IsUndefined() bool

func (*Result[T]) Raw

func (r *Result[T]) Raw() any

func (*Result[T]) Value

func (r *Result[T]) Value() (T, error)

type Undefined

type Undefined struct{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL