Pretty rough presentation, each example is a lets, with a pair of sql quasiquotes: one with antiquotes, and one with the resultant sql without antiquotes.
The source this file is generated from is here: QuasiQuoteTests.lhs
let tablename = "my_table" varname = "my_field" typename = "text" in Stmt [sqlStmt| create table $(tablename) ( $(varname) $(typename) ); |] [sqlStmt| create table my_table ( my_field text ); |] |
let fnname = "my_function" tablename = "my_table" typename = "int" in Stmt [sqlStmt| create function $(fnname)() returns $(typename) as $a$ select * from $(tablename); $a$ language sql stable; |] [sqlStmt| create function my_function() returns int as $a$ select * from my_table; $a$ language sql stable; |] |
let fnname = "my_function" in Stmt [sqlStmt| drop function $(fnname)();|] [sqlStmt| drop function my_function();|] |
let expr = StringLit ea "testing" in PgSqlStmt [pgsqlStmt| return $(expr); |] [pgsqlStmt| return 'testing'; |] |
let expr = (FunCall ea (Name ea [Nmc "+"]) [NumberLit ea "3", NumberLit ea "4"]) in PgSqlStmt [pgsqlStmt| return $(expr); |] [pgsqlStmt| return 3 + 4; |] |
let errMsg = "this splice is slighty dodgy" in PgSqlStmt [pgsqlStmt| if true then raise exception '$(errMsg)'; end if;|] [pgsqlStmt| if true then raise exception 'this splice is slighty dodgy'; end if;|] |
let triggername = "my_trigger" tablename = "my_table" opname = "my_function" in Stmt [sqlStmt| create trigger $(triggername) after insert or update or delete on $(tablename) for each statement execute procedure $(opname)(); |] [sqlStmt| create trigger my_trigger after insert or update or delete on my_table for each statement execute procedure my_function(); |] |
let tablename = "lotsastuff" in Expr [sqlExpr|(select count(*) from $(tablename))|] [sqlExpr|(select count(*) from lotsastuff)|] |
let trigname = "tbl_trig1" tablename = "tbl" tevent = TUpdate fn = "checkit" in Stmt [sqlStmt| create trigger $(trigname) after $(tevent) on $(tablename) for each row execute procedure $(fn)(); |] [sqlStmt| create trigger tbl_trig1 after update on tbl for each row execute procedure checkit(); |] |
let x = "fnname" in Expr [sqlExpr| $(x)('a') |] [sqlExpr| fnname('a') |] |
let x = "splicedstring" in Expr [sqlExpr| $s(x) |] (StringLit ea "splicedstring") |
let x = "splicedIdentifier" in Expr [sqlExpr| $i(x) |] (Identifier ea $ Nmc "splicedIdentifier") |
let errMsg = "this splice isn't too dodgy" in PgSqlStmt [pgsqlStmt| raise exception $s(errMsg); |] [pgsqlStmt| raise exception 'this splice isn''t too dodgy'; |] |