6.2 plisqin-lib/unsafe
(require plisqin-lib/unsafe) | package: plisqin |
procedure
aggregate :
(token-constructor [unsafe-content? ...+ -> Scalar?]) A primitive building block with no strict counterpart. Constructs an arbitrary fragment of SQL that represents an aggregate operation. This fragment will recognize grouped joins like the built-in aggregates, such as %%count or %%max. Let’s show the maximum UnitPriceDiscount we’ve ever given for each Product, and add 42 just for fun:
> (define (%%max-plus-42 . tokens) (%%aggregate "max(" tokens ") + 42"))
> (aw:show-table (from p Product (join detailsG SalesOrderDetail (group-by (ProductID detailsG)) (join-on (.= (ProductID detailsG) (ProductID p)))) (select (ProductName p)) (select (%%max-plus-42 (UnitPriceDiscount detailsG))) (limit 3)))
Show TableShow SQL
select p.Name as ProductName
, detailsG.__INJECT1
from Product p
inner join (
select detailsG.ProductID as __INJECT0
, max(detailsG.UnitPriceDiscount) + 42 as __INJECT1
from SalesOrderDetail detailsG
group by detailsG.ProductID
) detailsG
on (detailsG.__INJECT0 = p.ProductID)
limit 3
ProductName
__INJECT1
Sport-100 Helmet, Red
42.15
Sport-100 Helmet, Black
42.15
Mountain Bike Socks, M
42.1
procedure
scalar :
(token-constructor [unsafe-content? ...+ -> Scalar?]) A primitive building block with no strict counterpart. Constructs an arbitrary fragment of SQL that represents a scalar. This fragment will be injected into a grouped join if needed. In the example on %%aggregate, notice that (ProductID detailsG) occurs in a join-on clause of a grouped join. This is why it appears as "__INJECT0" in the generated SQL. This behavior is enabled because (ProductID detailsG) is returning a %%scalar. Although every %%scalar should be a Scalar?, the type Scalar? is irrelevant to this behavior.
procedure
sql :
(token-constructor [unsafe-content? ...+ -> Token?]) A primitive building block with no strict counterpart. Constructs an arbitrary fragment of SQL with no special behavior.Converts a Racket value into a Token?. The token’s nullability is always no. If type is #f, it is inferred as follows:If type is not #f, the return value will be cast to it:
procedure
(?? token-1 [token-N ...+] [/fallback])
token-1 : Token?
token-N : Token?
/fallback : fallback? This procedure is typically used to attach a fallback, but it can also be used as a synonym for %%coalesce if no fallback is given. More precisely, this procedure has 3 cases:
When given two arguments and the last argument is a fallback?, it simply attaches the fallback to the first argument: When given more than two arguments and the last argument is a fallback?, it attaches the fallback to the result of %%coalesce:
(?? token-1 token-N ...+ /fallback) ; is equivalent to (>> (%%coalesce token-1 token-N ...+) #:fallback /fallback) When the last argument is not a fallback?, it is simply a synonym for %%coalesce:
(?? token-1 token-N ...+) ; is equivalent to (%%coalesce token-1 token-N ...+) You may need to check the documentation on %%coalesce to know the return type of cases 2 and 3.
6.2.1 Clauses
procedure
select :
(token-constructor [unsafe-content? ...+ -> Select?])
procedure
where :
(token-constructor [unsafe-content? ...+ -> Where?])
procedure
group-by :
(token-constructor [unsafe-content? ...+ -> GroupBy?])
procedure
having :
(token-constructor [unsafe-content? ...+ -> Having?])
procedure
order-by :
(token-constructor [unsafe-content? ...+ -> OrderBy?])
procedure
join-on :
(token-constructor [unsafe-content? ...+ -> JoinOn?])
6.2.2 Aggregates
procedure
avg :
(token-constructor [unsafe-content? ...+ -> Number?])
procedure
min :
(token-constructor [unsafe-content? ...+ -> Scalar?])
procedure
max :
(token-constructor [unsafe-content? ...+ -> Scalar?])
procedure
sum :
(token-constructor [unsafe-content? ...+ -> Number?])
procedure
count :
(token-constructor [unsafe-content? ...+ -> Number?])
6.2.3 Misc
procedure
exists :
(token-constructor [unsafe-content? ...+ -> Bool?])
procedure
subquery :
(token-constructor [unsafe-content? ...+ -> Subquery?])
procedure
coalesce :
(token-constructor [unsafe-content? unsafe-content? ...+ -> Scalar?])
procedure
round :
(token-constructor [unsafe-content? ...+ -> Number?])
6.2.4 Date Math
procedure
date+ :
(token-constructor [unsafe-content? interval? ...+ -> Datetime?])
procedure
date- :
(token-constructor [unsafe-content? interval? ...+ -> Datetime?])
procedure
years :
(token-constructor [unsafe-content? -> interval?])
procedure
months :
(token-constructor [unsafe-content? -> interval?])
procedure
days :
(token-constructor [unsafe-content? -> interval?])
procedure
hours :
(token-constructor [unsafe-content? -> interval?])
procedure
minutes :
(token-constructor [unsafe-content? -> interval?])
procedure
seconds :
(token-constructor [unsafe-content? -> interval?])
6.2.5 Operators
(require plisqin-lib/unsafe/operators) | package: plisqin |
procedure
and :
(token-constructor [unsafe-content? ...+ -> Bool?])
procedure
or :
(token-constructor [unsafe-content? ...+ -> Bool?])
procedure
not :
(token-constructor [unsafe-content? ...+ -> Bool?])
procedure
= :
(token-constructor [unsafe-content? ...+ -> Bool?])
procedure
<> :
(token-constructor [unsafe-content? ...+ -> Bool?])
procedure
< :
(token-constructor [unsafe-content? ...+ -> Bool?])
procedure
<= :
(token-constructor [unsafe-content? ...+ -> Bool?])
procedure
> :
(token-constructor [unsafe-content? ...+ -> Bool?])
procedure
>= :
(token-constructor [unsafe-content? ...+ -> Bool?])
procedure
like :
(token-constructor [unsafe-content? ...+ -> Bool?])
procedure
not-like :
(token-constructor [unsafe-content? ...+ -> Bool?])
procedure
is :
(token-constructor [unsafe-content? unsafe-content? -> Bool?])
procedure
is-not :
(token-constructor [unsafe-content? unsafe-content? -> Bool?])
procedure
+ :
(token-constructor [unsafe-content? ...+ -> Scalar?])
procedure
- :
(token-constructor [unsafe-content? ...+ -> Scalar?])
procedure
* :
(token-constructor [unsafe-content? ...+ -> Scalar?])
procedure
/ :
(token-constructor [unsafe-content? ...+ -> Scalar?])