A dumb little SQL engine.

I wrote a little SQL engine, based on ideas floating around head. Maybe one day I will write a bit more.

Features etc

  • filters (select, where)
  • group by.

The big thing missing is a parser for SQL itself.

Key interface: iterable

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.

Key interface: expr

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

  • constants.
  • variables extracted from the row.
  • expressions defined as other expressions, for example:
    • a+b
    • regexp_extract(foo, 'foobarbaz')

CSV

CSV is an iterable, using a CSF file as the source for the data. Its lame, but works.