interpreter

package
v0.10.0-beta-1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

package interpreter provides a basic interpreter for Kuneiform procedures. It allows running procedures as standalone programs (instead of generating PL/pgSQL code).

Index

Constants

View Source
const (
	// Can execute actions
	CallPrivilege privilege = "CALL"
	// can execute ad-hoc select queries
	SelectPrivilege privilege = "SELECT"
	// can insert data
	InsertPrivilege privilege = "INSERT"
	// can update data
	UpdatePrivilege privilege = "UPDATE"
	// can delete data
	DeletePrivilege privilege = "DELETE"
	// can create new objects
	CreatePrivilege privilege = "CREATE"
	// can drop objects
	DropPrivilege privilege = "DROP"
	// use can use extensions
	UsePrivilege privilege = "USE"
	// can alter objects
	AlterPrivilege privilege = "ALTER"
	// can manage roles.
	// roles are global, and are not tied to a specific namespace or object.
	RolesPrivilege privilege = "ROLES"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	// Name is the name of the action.
	// It should always be lower case.
	Name string `json:"name"`

	// Parameters are the input parameters of the action.
	Parameters []*NamedType `json:"parameters"`
	// Modifiers modify the access to the action.
	Modifiers []precompiles.Modifier `json:"modifiers"`

	// Body is the logic of the action.
	Body []parse.ActionStmt

	// RawStatement is the unparsed CREATE ACTION statement.
	RawStatement string `json:"raw_statement"`

	// Returns specifies the return types of the action.
	Returns *ActionReturn `json:"return_types"`
}

func (*Action) FromAST

func (a *Action) FromAST(ast *parse.CreateActionStatement) error

FromAST sets the fields of the action from an AST node.

func (*Action) GetName

func (a *Action) GetName() string

type ActionReturn

type ActionReturn struct {
	IsTable bool         `json:"is_table"`
	Fields  []*NamedType `json:"fields"`
}

ActionReturn holds the return type of a procedure. EITHER the Type field is set, OR the Table field is set.

type NamedType

type NamedType struct {
	// Name is the name of the parameter.
	// It should always be lower case.
	// If it is a procedure parameter, it should begin
	// with a $.
	Name string `json:"name"`
	// Type is the type of the parameter.
	Type *types.DataType `json:"type"`
}

NamedType is a parameter in a procedure.

type ThreadSafeInterpreter

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

ThreadSafeInterpreter is a thread-safe interpreter. It is defined as a separate struct because there are time where the interpreter recursively calls itself, and we need to avoid deadlocks.

func NewInterpreter

func NewInterpreter(ctx context.Context, db sql.DB, service *common.Service, accounts common.Accounts, validators common.Validators, nsr engine.NamespaceRegister) (*ThreadSafeInterpreter, error)

NewInterpreter creates a new interpreter. It reads currently stored namespaces and loads them into memory.

func (*ThreadSafeInterpreter) Call

func (t *ThreadSafeInterpreter) Call(ctx *common.EngineContext, db sql.DB, namespace string, action string, args []any, resultFn func(*common.Row) error) (*common.CallResult, error)

func (*ThreadSafeInterpreter) Execute

func (t *ThreadSafeInterpreter) Execute(ctx *common.EngineContext, db sql.DB, statement string, params map[string]any, fn func(*common.Row) error) error

func (*ThreadSafeInterpreter) ExecuteWithoutEngineCtx

func (t *ThreadSafeInterpreter) ExecuteWithoutEngineCtx(ctx context.Context, db sql.DB, statement string, params map[string]any, fn func(*common.Row) error) error

Jump to

Keyboard shortcuts

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