Reference
Below follows a list of the most common extensions for Razor SQL.
Navigation
Navigation happens through the For
, Open
and Vals
methods which can select either
a property, set or relation.
@project BlogView b
@b.For(m => m.Title) # a property
@b.Open(m => m.Posts)
Tables
Table names are written with TblName
and Tbl
with the latter assigning a unique
correlated name.
@project Blog b1
@project Blog b2
@b1.TblName() -- "Blog"
@b1.Tbl() -- "Blog" T0
@b2.Tbl() -- "Blog" T1
Columns
Equally you can output correlated and non-correlated column names with the ColName
and Col
extensions.
@project Blog b1
@project Blog b2
@b1.ColName(m => m.Title) -- "Title"
@b1.Col(m => m.Title) -- T0."Title"
@b2.Col(m => m.Title) -- T1."Title"
Properties
Use the Prop
extension to output the unique name of the property you want to map values into.
@result Blog
... AS @R.Prop(m => m.Title) -- AS "Item.Title"
Or the
Parameters
Parameters are output using the Par
@model Movie
@Model.Title -- @@P0
@Model.Title -- @@P1
@M.Par(m => m.Title) -- @@P2
@M.Par(m => m.Title) -- @@P2
Values
Literals
While Jerrycurl by default only outputs safe literals (e.g. numbers), changing this behavior can pose a security risk in the form of SQL injection attacks, so use with caution.
Literals are output using the Lit
and Lits
methods. They call into
IDialect.Literal
to provide either a) a safe, non-null literal that can be output
to the SQL buffer, or b) null, which indicates that no safe value is available, and hence
a parameter is output instead.
@model Movie
INSERT INTO @M.TblName()
( @M.In().ColNames() )
VALUES ( @M.In().Lits() )
INSERT INTO "Movie"
( "Title", "Year", "StudioId")
VALUES ( @P0, 1996, NULL )
Partials
@model Movie
@M.Subcommand("Create")
@result Movie
@R.Subcommand("Get", this.Model)
Filters
@result Movie
@R.ColNames() -- "Id", "Title", "Year", "StudioId"
@R.In().ColNames() -- "Title", "Year", "StudioId"
@R.Out().ColNames() -- "Id"
@R.Key().ColNames() -- "Id"
@R.Id().ColName() -- "Id"
The Id
filter which returns the identity attribute (or null) is usually used to return
values when doing INSERT
.
INSERT INTO @M.TblName()
( @M.In().ColNames() )
VALUES ( @M.In().Pars() )
@if (this.M.Id() != null)
{
-- parameter binding
SET @M.Id().Par() = SCOPE_IDENTITY()
}
INSERT INTO @M.TblName()
( @M.In().ColNames() )
@if (this.M.Out().Any())
{
-- column binding
OUTPUT @M.Out().Cols("INSERTED").As().Props()
}
VALUES ( @M.In().Pars() )
Operators
JSON
@result MovieDetailsView
@R.JsonPath(m => m.Details.Tagline) -- '$.tagline'