oql

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package oql provides SQL-compatible query language for olu.

OQL supports a subset of T-SQL syntax for querying and mutating data:

  • SELECT with aggregates (COUNT, SUM, AVG, MIN, MAX)
  • GROUP BY, HAVING, ORDER BY, TOP
  • INSERT with VALUES
  • UPDATE with WHERE (required)
  • DELETE with WHERE (required)

JOINs are not supported as relationships are handled by the graph layer.

Index

Constants

This section is empty.

Variables

View Source
var Aggregates = map[string]AggregateFunc{
	"COUNT": aggCount,
	"SUM":   aggSum,
	"AVG":   aggAvg,
	"MIN":   aggMin,
	"MAX":   aggMax,
}

Aggregates maps function names to their implementations

Functions

func ApplyTop

func ApplyTop(records []map[string]interface{}, top *ast.TopClause) []map[string]interface{}

ApplyTop limits results to TOP n

func GetSchemaPath

func GetSchemaPath(schemaDir, entity string) string

GetSchemaPath returns the full path to an entity's schema

func OrderBy

func OrderBy(records []map[string]interface{}, orderBy []*ast.OrderByItem) []map[string]interface{}

OrderBy sorts records by the specified order items

func ValidateSchemaDir

func ValidateSchemaDir(schemaDir string) error

ValidateSchemaDir checks if the schema directory exists

Types

type AggregateFunc

type AggregateFunc func(values []interface{}) interface{}

AggregateFunc is a function that computes an aggregate over values

type Aggregator

type Aggregator struct{}

Aggregator handles GROUP BY and aggregate function execution

func NewAggregator

func NewAggregator() *Aggregator

NewAggregator creates a new aggregator

func (*Aggregator) Aggregate

func (a *Aggregator) Aggregate(
	records []map[string]interface{},
	columns []ast.SelectColumn,
	groupBy []ast.Expression,
	having ast.Expression,
) []map[string]interface{}

Aggregate groups records and applies aggregate functions

type Engine

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

Engine is the main OQL query engine

func NewEngine

func NewEngine(store storage.Store, schemaDir string) *Engine

NewEngine creates a new OQL engine

func NewEngineWithSchemaValidator

func NewEngineWithSchemaValidator(store storage.Store, schemaDir string, sv SchemaValidator) *Engine

NewEngineWithSchemaValidator creates an OQL engine with schema validation

func (*Engine) Execute

func (e *Engine) Execute(ctx context.Context, sql string) (*Result, error)

Execute parses, validates, and executes an OQL query

func (*Engine) RefreshSchema

func (e *Engine) RefreshSchema()

RefreshSchema reloads the entity list from disk

type Executor

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

Executor executes OQL queries against storage

func NewExecutor

func NewExecutor(store storage.Store, sv SchemaValidator) *Executor

NewExecutor creates a new executor

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, stmt ast.Statement) (*Result, error)

Execute executes a validated AST statement

type Job

type Job struct {
	ID        string
	Query     string
	Status    JobStatus
	Result    *Result
	Error     string
	CreatedAt time.Time
	UpdatedAt time.Time
}

Job represents an async OQL query job

type JobManager

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

JobManager manages async OQL query jobs

func NewJobManager

func NewJobManager(engine *Engine, ttl time.Duration) *JobManager

NewJobManager creates a new job manager

func (*JobManager) Close

func (jm *JobManager) Close()

Close stops the job manager

func (*JobManager) ExecuteSync

func (jm *JobManager) ExecuteSync(ctx context.Context, query string) (*Result, error)

ExecuteSync executes a query synchronously

func (*JobManager) GetJob

func (jm *JobManager) GetJob(id string) *Job

GetJob returns a job by ID

func (*JobManager) GetJobResult

func (jm *JobManager) GetJobResult(id string) (*Result, error)

GetJobResult returns the result of a completed job

func (*JobManager) Submit

func (jm *JobManager) Submit(query string) string

Submit submits a query for async execution

type JobStatus

type JobStatus string

JobStatus represents the status of a job

const (
	JobPending   JobStatus = "pending"
	JobRunning   JobStatus = "running"
	JobCompleted JobStatus = "completed"
	JobFailed    JobStatus = "failed"
)

type QueryStats

type QueryStats struct {
	RowsScanned   int           `json:"rows_scanned"`
	RowsReturned  int           `json:"rows_returned"`
	RowsAffected  int           `json:"rows_affected,omitempty"`
	ExecutionTime time.Duration `json:"execution_time_ms"`
}

QueryStats contains execution statistics

type Result

type Result struct {
	Type  ResultType               `json:"type"`
	Rows  []map[string]interface{} `json:"data,omitempty"`
	Stats QueryStats               `json:"stats"`
}

Result represents the result of an OQL query execution

func NewMutationResult

func NewMutationResult(resultType ResultType, affected int, duration time.Duration) *Result

NewMutationResult creates a result for INSERT/UPDATE/DELETE queries

func NewSelectResult

func NewSelectResult(rows []map[string]interface{}, scanned int, duration time.Duration) *Result

NewSelectResult creates a result for SELECT queries

type ResultType

type ResultType int

ResultType indicates the type of SQL statement executed

const (
	ResultSelect ResultType = iota
	ResultInsert
	ResultUpdate
	ResultDelete
)

func (ResultType) String

func (rt ResultType) String() string

type SchemaValidator

type SchemaValidator interface {
	Validate(entity string, data map[string]interface{}) (bool, []string)
}

SchemaValidator validates entity data against schemas

type Validator

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

Validator validates OQL queries against schema

func NewValidator

func NewValidator(schemaDir string) *Validator

NewValidator creates a new validator

func (*Validator) EntityExists

func (v *Validator) EntityExists(name string) bool

EntityExists checks if an entity exists. If the entity is not in the cache, it automatically refreshes from disk before returning false. This ensures newly created entity types are recognised without requiring manual refresh.

func (*Validator) RefreshEntities

func (v *Validator) RefreshEntities()

RefreshEntities reloads the entity list from the schema directory. This is called automatically when EntityExists encounters an unknown entity, so manual calls are typically unnecessary.

func (*Validator) Validate

func (v *Validator) Validate(stmt ast.Statement) error

Validate validates an AST statement

Jump to

Keyboard shortcuts

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