Created
April 27, 2014 20:16
-
-
Save solnic/11354720 to your computer and use it in GitHub Desktop.
Progress on new axiom SQL generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $LOAD_PATH.unshift './lib' | |
| require 'axiom-sql-generator' | |
| users = Axiom::Relation::Base.new(:users, [[:id, Integer], [:name, String]]) | |
| def compile_sql(relation) | |
| sql_ast = Axiom::SQL::Processor.call(relation) | |
| sql_str = SQL::Generator.generate(sql_ast) | |
| sql_str | |
| end | |
| puts compile_sql(users).inspect | |
| # SELECT "id", "name" FROM "users" | |
| puts compile_sql(users.restrict(name: "Piotr")).inspect | |
| # SELECT "id", "name" FROM "users" WHERE ("name" = 'Piotr') | |
| puts compile_sql(users.insert([[1, 'Piotr']])).inspect | |
| # INSERT INTO "users" VALUES (1, 'Piotr') | |
| puts compile_sql(users.delete(users.restrict(id: 1))).inspect | |
| # DELETE FROM "users" WHERE ("id" = 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment