Skip to content

Instantly share code, notes, and snippets.

@solnic
Created April 2, 2011 19:16
Show Gist options
  • Save solnic/899787 to your computer and use it in GitHub Desktop.
Save solnic/899787 to your computer and use it in GitHub Desktop.
name = Attribute::String.new(:name)
age = Attribute::Integer.new(:age)
header = [ name, age ]
body = [ 'john', 12 ]
base_relation = BaseRelation.new('users', header, body)
relation = SQL::Compiler::Generator::Relation::Unary.new
relation.visit(base_relation.project([ :name, :age ]))
# => SELECT DISTINCT "name", "age" FROM "users"
relation.visit(base_relation.restrict { |r| r[:age].gte(21) & r[:name].include(["john", "jane"]) })
# => SELECT "name", "age" FROM "users" WHERE ("age" >= 21 AND "name" IN ('john', 'jane'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment