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 ¶
- Variables
- func ApplyTop(records []map[string]interface{}, top *ast.TopClause) []map[string]interface{}
- func GetSchemaPath(schemaDir, entity string) string
- func OrderBy(records []map[string]interface{}, orderBy []*ast.OrderByItem) []map[string]interface{}
- func ValidateSchemaDir(schemaDir string) error
- type AggregateFunc
- type Aggregator
- type Engine
- type Executor
- type Job
- type JobManager
- type JobStatus
- type QueryStats
- type Result
- type ResultType
- type SchemaValidator
- type Validator
Constants ¶
This section is empty.
Variables ¶
var Aggregates = map[string]AggregateFunc{
"COUNT": aggCount,
"SUM": aggSum,
"AVG": aggAvg,
"MIN": aggMin,
"MAX": aggMax,
}
Aggregates maps function names to their implementations
Functions ¶
func GetSchemaPath ¶
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 ¶
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 (*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 NewEngineWithSchemaValidator ¶
func NewEngineWithSchemaValidator(store storage.Store, schemaDir string, sv SchemaValidator) *Engine
NewEngineWithSchemaValidator creates an OQL engine with schema validation
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
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) ExecuteSync ¶
ExecuteSync executes a query synchronously
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 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
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 ¶
NewValidator creates a new validator
func (*Validator) EntityExists ¶
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.