vilterp / treesql

prototype: a relational database which supports live GraphQL-like queries. Written in Go with BoltDB storage.
37 stars 1 forks source link

[wip] new FP-like intermediate representation #10

Open vilterp opened 6 years ago

vilterp commented 6 years ago

Queries are planned into expressions in a small functional programming language,

e.g. the TreeSQL query

MANY blog_posts {
  id,
  comments: MANY comments {
    id,
    blog_post_id
  }
}

becomes

map(
  scan(tables.blog_posts.id),
  (row1) => {
    id: row1.id
    comments: map(
      filter(
        scan(tables.comments.id),
        (row2) => strEq(row2.blog_post_id, row1.id)
      ),
      (row2) => {
        blog_post_id: row2.blog_post_id,
        id: row2.id
      }
    ),
  }
)

…which is then executed to generate the result. Hopefully this will serve as a basis for expanding the set of queries TreeSQL can execute, and be a good place to do index selection, etc.

Still working on the language basics and figuring out how to incrementalize this XD