I wrote a little SQL engine, based on ideas floating around head. Maybe one day I will write a bit more.
select
, where
)group by
.The big thing missing is a parser for SQL itself.
type iterable interface {
next(context.Context) (*row, error)
}
This is used by each operation (select
, group by
, order by
etc) to provide a new row of results to the calling operation. For example, where
would call next
on its source until it gets a row matching the where clause, then it would return that row to the caller.
A errStop
is called on there being no more rows to return.
type expr interface {
value(r *row) (interface{}, typ, error)
}
This is used to evaluate different expressions in the context of a single row. Example expressios:
select a+b
- here a+b
is the expression.where a<3
- here a<3
is the expression.Expressions are currently
a+b
regexp_extract(foo, 'foobarbaz')
CSV is an iterable, using a CSF file as the source for the data. Its lame, but works.