Skip to content

Instantly share code, notes, and snippets.

@solnic
Created September 7, 2011 14:53
Show Gist options
  • Select an option

  • Save solnic/1200783 to your computer and use it in GitHub Desktop.

Select an option

Save solnic/1200783 to your computer and use it in GitHub Desktop.
require 'veritas'
require 'veritas-sql-generator'
header_one = [
[ :id, Integer ],
[ :name, String ],
[ :age, Integer ]
]
tuples_one = [
[ 1, 'dkubb', 35 ],
[ 2, 'solnic', 28 ]
]
header_two = [
[ :id, Integer ],
[ :user_id, Integer ],
[ :name, String ],
[ :created_at, DateTime ]
]
tuples_two = [
[ 1, 1, 'veritas', DateTime.parse('2010/01/01') ],
[ 1, 2, 'virtus', DateTime.parse('2011/01/01') ],
]
relation_one = Veritas::Relation::Base.new('one', header_one, tuples_two)
relation_two = Veritas::Relation::Base.new('two', header_two, tuples_two)
relation_two = relation_two.rename(id: :project_id, name: :project_name)
new_relation = relation_one.join(relation_two) { |r| r.id.eq(r.user_id) }
sql_generator = Veritas::SQL::Generator::Relation.visit(new_relation)
puts '-'*40+' SQL '+'-'*40
puts sql_generator.to_sql
puts '-'*40+' SQL '+'-'*40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment