The function sql-operation
takes an operator and its arguments, and returns an SQL statement. It is shorthand for (apply (sql-operator op) args)
.
The following code, uses sql-operation
to produce an SQL expression.
(sql-operation 'select
(sql-expression :table 'foo :attribute 'bar)
(sql-expression :attribute 'baz)
:from (list
(sql-expression :table 'foo)
(sql-expression :table 'quux))
:where
(sql-operation 'or
(sql-operation '>
(sql-expression :attribute 'baz)
3)
(sql-operation 'like
(sql-expression :table 'foo :attribute 'bar)
"SU%")))
The following SQL expression is produced.
#<SQL-QUERY: "(SELECT FOO.BAR,BAZ FROM FOO,QUUX
WHERE ((BAZ > 3) OR (FOO.BAR LIKE 'SU%')))">