Skip to content

Commit 3a5e111

Browse files
committed
fsharp-refactor fixes
1 parent 0a210c0 commit 3a5e111

6 files changed

Lines changed: 26 additions & 17 deletions

File tree

‎src/SQLProvider.Fable.Core/Query.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ module Expr =
347347
/// backslash as an escape *inside string literals* too, so `ESCAPE '\'`
348348
/// would escape its own closing quote there. `!` is ordinary in all three
349349
/// engines' string literals.
350+
[<Literal>]
350351
let likeEscapeChar = '!'
351352

352353
let escapeLikeValue (value: string) =

‎src/SQLProvider.Fable.Core/SqlGen.fs‎

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module SqlGen =
8383
| Abs, _ -> ValueSome "ABS"
8484

8585
| Length, Sqlite -> ValueSome "LENGTH"
86-
| Length, Postgres -> ValueSome "CHAR_LENGTH"
86+
| Length, Postgres
8787
| Length, MySql -> ValueSome "CHAR_LENGTH"
8888
| Length, Generic -> ValueSome "LENGTH"
8989

@@ -93,7 +93,7 @@ module SqlGen =
9393

9494
| IndexOf, Postgres -> ValueSome "STRPOS"
9595
| IndexOf, MySql -> ValueSome "LOCATE"
96-
| IndexOf, Sqlite -> ValueSome "INSTR"
96+
| IndexOf, Sqlite
9797
| IndexOf, Generic -> ValueSome "INSTR"
9898

9999
// Every engine's plain-rounding function has the same name.
@@ -117,6 +117,22 @@ module SqlGen =
117117
| Second -> ValueSome("SECOND", "%S")
118118
| _ -> ValueNone
119119

120+
/// The one argument of a single-argument function.
121+
let private oneArg (fn: SqlFn) (args: SqlExpr list) : SqlExpr =
122+
match args with
123+
| [ single ] -> single
124+
| _ -> failwith ("SqlGen: " + string fn + " takes exactly one argument")
125+
126+
let private twoArgs (fn: SqlFn) (args: SqlExpr list) : SqlExpr * SqlExpr =
127+
match args with
128+
| [ first; second ] -> first, second
129+
| _ -> failwith ("SqlGen: " + string fn + " takes exactly two arguments")
130+
131+
/// `.Date`. SQLite and MySQL have DATE(); PostgreSQL's DATE() is not the
132+
/// same thing, so it uses the truncation SQLProvider uses too.
133+
134+
/// The two arguments of a two-argument function.
135+
120136
let rec private renderExpr (b: Builder) (e: SqlExpr) =
121137
let append (s: string) = write b s
122138

@@ -269,20 +285,6 @@ module SqlGen =
269285
// tree loses its bindings (the G25 family) -- and small single-scrutinee
270286
// matches are what it compiles correctly.
271287

272-
/// The one argument of a single-argument function.
273-
and private oneArg (fn: SqlFn) (args: SqlExpr list) : SqlExpr =
274-
match args with
275-
| [ single ] -> single
276-
| _ -> failwith ("SqlGen: " + string fn + " takes exactly one argument")
277-
278-
/// The two arguments of a two-argument function.
279-
and private twoArgs (fn: SqlFn) (args: SqlExpr list) : SqlExpr * SqlExpr =
280-
match args with
281-
| [ first; second ] -> first, second
282-
| _ -> failwith ("SqlGen: " + string fn + " takes exactly two arguments")
283-
284-
/// `.Date`. SQLite and MySQL have DATE(); PostgreSQL's DATE() is not the
285-
/// same thing, so it uses the truncation SQLProvider uses too.
286288
and private renderDateOnly (b: Builder) (arg: SqlExpr) =
287289
let append (s: string) = write b s
288290

‎src/SQLProvider.Fable.Design/SchemaReader.fs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module SchemaReader =
1616

1717
// --- SQLite ------------------------------------------------------------
1818

19+
[<Literal>]
1920
let private sqliteTables =
2021
"SELECT name, type FROM sqlite_master
2122
WHERE type IN ('table', 'view') AND name NOT LIKE 'sqlite_%'
@@ -119,6 +120,7 @@ module SchemaReader =
119120

120121
/// One row per column, ordered within its constraint, so a composite key
121122
/// reassembles by grouping on constraint_name.
123+
[<Literal>]
122124
let private infoSchemaForeignKeys =
123125
"SELECT k.constraint_name, k.column_name, k.referenced_table_name, k.referenced_column_name
124126
FROM information_schema.key_column_usage k
@@ -133,6 +135,7 @@ module SchemaReader =
133135
/// joining it against a composite key cross-multiplies the pairs.
134136
/// `position_in_unique_constraint` is what lines each column up with the
135137
/// one it references.
138+
[<Literal>]
136139
let private postgresForeignKeys =
137140
"SELECT kcu.constraint_name,
138141
kcu.column_name,
@@ -168,7 +171,7 @@ module SchemaReader =
168171
|> ResultSet.map (fun r ->
169172
{ Name = text r "column_name"
170173
Kind = kindOfDbType (text r "data_type")
171-
IsNullable = (text r "is_nullable").ToUpperInvariant() = "YES"
174+
IsNullable = System.String.Equals((text r "is_nullable"), "YES", System.StringComparison.OrdinalIgnoreCase)
172175
// COUNT-style flags come back as an integer on
173176
// PostgreSQL and can arrive as a decimal on MySQL.
174177
IsPrimaryKey =

‎tests/SQLProvider.Fable.SmokeTests/GeneratedSchema.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ module Orders =
7676
let Freight = Col.decimal table "Freight"
7777

7878
/// One row, as a record.
79+
[<Struct>]
7980
type Row =
8081
{ OrderId: int64
8182
CustomerId: int64

‎tests/SQLProvider.Fable.SmokeTests/Smoke.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Fixture =
4444

4545
module Fixture =
4646

47+
[<Literal>]
4748
let private invoiceAsText =
4849
"CREATE TABLE Invoice (Id TEXT NOT NULL, Total TEXT NOT NULL, Issued TEXT NOT NULL, Rebate TEXT NULL)"
4950

‎tests/SQLProvider.Fable.Tests.Readme/ReadmeSamples.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ module Order =
4646
let OrderId = Col.int64 table "OrderId"
4747
let CustomerId = Col.int64 table "CustomerId"
4848

49+
[<Struct>]
4950
type Row = { OrderId: int64 }
5051

5152
let qualified = [| "Orders_OrderId", OrderId.E |]

0 commit comments

Comments
 (0)