@@ -76,54 +76,54 @@ module SqlGen =
7676 /// reordering. Returns None where the engine has no equivalent.
7777 let private fnName ( vendor : Vendor ) ( fn : SqlFn ) =
7878 match fn, vendor with
79- | Upper, _ -> Some " UPPER"
80- | Lower, _ -> Some " LOWER"
81- | Trim, _ -> Some " TRIM"
82- | Replace, _ -> Some " REPLACE"
83- | Abs, _ -> Some " ABS"
84-
85- | Length, Sqlite -> Some " LENGTH"
86- | Length, Postgres -> Some " CHAR_LENGTH"
87- | Length, MySql -> Some " CHAR_LENGTH"
88- | Length, Generic -> Some " LENGTH"
89-
90- | Substring, MySql -> Some " MID"
91- | Substring, Sqlite -> Some " SUBSTR"
92- | Substring, _ -> Some " SUBSTRING"
93-
94- | IndexOf, Postgres -> Some " STRPOS"
95- | IndexOf, MySql -> Some " LOCATE"
96- | IndexOf, Sqlite -> Some " INSTR"
97- | IndexOf, Generic -> Some " INSTR"
79+ | Upper, _ -> ValueSome " UPPER"
80+ | Lower, _ -> ValueSome " LOWER"
81+ | Trim, _ -> ValueSome " TRIM"
82+ | Replace, _ -> ValueSome " REPLACE"
83+ | Abs, _ -> ValueSome " ABS"
84+
85+ | Length, Sqlite -> ValueSome " LENGTH"
86+ | Length, Postgres -> ValueSome " CHAR_LENGTH"
87+ | Length, MySql -> ValueSome " CHAR_LENGTH"
88+ | Length, Generic -> ValueSome " LENGTH"
89+
90+ | Substring, MySql -> ValueSome " MID"
91+ | Substring, Sqlite -> ValueSome " SUBSTR"
92+ | Substring, _ -> ValueSome " SUBSTRING"
93+
94+ | IndexOf, Postgres -> ValueSome " STRPOS"
95+ | IndexOf, MySql -> ValueSome " LOCATE"
96+ | IndexOf, Sqlite -> ValueSome " INSTR"
97+ | IndexOf, Generic -> ValueSome " INSTR"
9898
9999 // Every engine's plain-rounding function has the same name.
100- | Round, _ -> Some " ROUND"
100+ | Round, _ -> ValueSome " ROUND"
101101
102102 // The rest are not plain function calls on every engine, so they are
103103 // handled separately below and never reach this table.
104- | ( Year | Month | Day | Hour | Minute | Second | DateOnly), _ -> None
105- | ( Ceiling | Floor | RoundTo _ | Truncate | Greatest | Least), _ -> None
106- | ( CastText | CastInt | DateDiffDays | DateDiffSecs), _ -> None
104+ | ( Year | Month | Day | Hour | Minute | Second | DateOnly), _ -> ValueNone
105+ | ( Ceiling | Floor | RoundTo _ | Truncate | Greatest | Least), _ -> ValueNone
106+ | ( CastText | CastInt | DateDiffDays | DateDiffSecs), _ -> ValueNone
107107
108108 /// SQLite has no YEAR(); it has STRFTIME with a format string. PostgreSQL
109109 /// wants EXTRACT(field FROM x). MySQL has the plain function.
110110 let private datePartName ( fn : SqlFn ) =
111111 match fn with
112- | Year -> Some ( " YEAR" , " %Y" )
113- | Month -> Some ( " MONTH" , " %m" )
114- | Day -> Some ( " DAY" , " %d " )
115- | Hour -> Some ( " HOUR" , " %H" )
116- | Minute -> Some ( " MINUTE" , " %M " )
117- | Second -> Some ( " SECOND" , " %S" )
118- | _ -> None
112+ | Year -> ValueSome ( " YEAR" , " %Y" )
113+ | Month -> ValueSome ( " MONTH" , " %m" )
114+ | Day -> ValueSome ( " DAY" , " %d " )
115+ | Hour -> ValueSome ( " HOUR" , " %H" )
116+ | Minute -> ValueSome ( " MINUTE" , " %M " )
117+ | Second -> ValueSome ( " SECOND" , " %S" )
118+ | _ -> ValueNone
119119
120120 let rec private renderExpr ( b : Builder ) ( e : SqlExpr ) =
121121 let append ( s : string ) = write b s
122122
123123 match e with
124124 | ColumnRef( table, column) ->
125125 if b.Qualify then
126- append ( table + " . " + column)
126+ append ( $ " {table}.{ column} " )
127127 else
128128 append column
129129
@@ -385,7 +385,7 @@ module SqlGen =
385385 match b.Vendor with
386386 | Sqlite
387387 | Generic -> append ( sqliteName + " (" )
388- | _ -> append ( name + " (" )
388+ | Postgres | MySql -> append ( name + " (" )
389389
390390 renderExpr b first
391391 append " , "
@@ -491,29 +491,29 @@ module SqlGen =
491491 let append ( s : string ) = write b s
492492
493493 match datePartName fn with
494- | Some ( name, strftime) ->
494+ | ValueSome ( name, strftime) ->
495495 let arg = oneArg fn args
496496
497497 ( match b.Vendor with
498498 | Sqlite ->
499499 // STRFTIME returns text, so cast back to a number to keep
500500 // comparisons behaving like the other engines.
501- append ( " CAST(STRFTIME('" + strftime + " ', " )
501+ append ( $ " CAST(STRFTIME('{ strftime} ', " )
502502 renderExpr b arg
503503 append " ) AS INTEGER)"
504504 | Postgres ->
505- append ( " EXTRACT(" + name + " FROM " )
505+ append ( $ " EXTRACT({ name} FROM " )
506506 renderExpr b arg
507507 append " )"
508508 | MySql
509509 | Generic ->
510510 append ( name + " (" )
511511 renderExpr b arg
512512 append " )" )
513- | None ->
513+ | ValueNone ->
514514 match fnName b.Vendor fn with
515- | None -> failwith ( " SqlGen: no SQL mapping for " + string fn)
516- | Some name ->
515+ | ValueNone -> failwith ( " SqlGen: no SQL mapping for " + string fn)
516+ | ValueSome name ->
517517 // PostgreSQL's STRPOS takes (haystack, needle) like .NET's
518518 // IndexOf; MySQL's LOCATE takes (needle, haystack).
519519 let args =
@@ -585,15 +585,15 @@ module SqlGen =
585585
586586 append " DATETIME("
587587 renderExpr b inner
588- append ( " , '" + signed + " " + unitName + " s')" )
588+ append ( $ " , '{ signed} { unitName} s')" )
589589
590590 and private renderSource ( b : Builder ) ( s : Source ) =
591591 let append ( t : string ) = write b t
592592
593593 if s.Alias = s.Table then
594594 append s.Table
595595 else
596- append ( s.Table + " AS " + s.Alias)
596+ append ( $ " { s.Table} AS { s.Alias} " )
597597
598598 /// Renders a query into an existing builder, so a subquery shares the outer
599599 /// statement's parameter list and stays numbered in the order the SQL
@@ -766,7 +766,7 @@ module SqlGen =
766766 // Columns are bare here, not qualified: an INSERT names exactly one
767767 // table and every engine rejects `INSERT INTO t (t.c) ..`.
768768 let b = newBuilder vendor false
769- write b ( " INSERT INTO " + i.Table + " (" )
769+ write b ( $ " INSERT INTO { i.Table} (" )
770770
771771 i.Assignments
772772 |> Array.iteri ( fun n a ->
@@ -802,7 +802,7 @@ module SqlGen =
802802 failwith " SqlGen: the insert has no rows"
803803
804804 let b = newBuilder vendor false
805- write b ( " INSERT INTO " + i.Table + " (" )
805+ write b ( $ " INSERT INTO { i.Table} (" )
806806
807807 i.Columns
808808 |> Array.iteri ( fun n c ->
@@ -840,7 +840,7 @@ module SqlGen =
840840 match vendor with
841841 | Postgres ->
842842 let sql , ps = renderInsert vendor i
843- Some( sql + " RETURNING " + keyColumn, ps)
843+ Some( $ " { sql} RETURNING { keyColumn} " , ps)
844844 | _ -> None
845845
846846 /// The query that reports the key the last insert on this connection
@@ -861,7 +861,7 @@ module SqlGen =
861861 failwith " SqlGen: the update has no WHERE and would rewrite every row -- say Update.all if that is meant"
862862
863863 let b = newBuilder vendor false
864- write b ( " UPDATE " + u.Table + " SET " )
864+ write b ( $ " UPDATE { u.Table} SET " )
865865 renderAssignments b u.Assignments
866866
867867 match u.Where with
0 commit comments