Skip to content

Commit da3add1

Browse files
authored
Merge pull request #876 from Thorium/pr/note-fixes
Code cleanup
2 parents 6f53869 + 4269f28 commit da3add1

60 files changed

Lines changed: 2526 additions & 2377 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎build.fsx‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,11 @@ type Project = {
103103
/// List of dependencies
104104
dependencies:(string * string) list }
105105

106+
[<Literal>]
106107
let project = "SQLProvider"
108+
[<Literal>]
107109
let summary = "Type providers for SQL database access."
110+
[<Literal>]
108111
let description = "Type providers for SQL database access."
109112

110113
let projects =
@@ -148,17 +151,21 @@ let projects =
148151
let authors = [ "Ross McKinlay, Colin Bull, Tuomas Hietanen" ]
149152

150153
// Tags for your project (for NuGet package)
154+
[<Literal>]
151155
let tags = "F#, fsharp, typeprovider, sql, sqlserver, mysql, sql-server, sqlite, postgresql, oracle, mariadb, firebirdsql, database, dotnet"
152156

153157
// Pattern specifying assemblies to be tested using NUnit
158+
[<Literal>]
154159
let testAssemblies = "tests/**/bin/Release/*Tests*.dll"
155160

156161
// Git configuration (used for publishing documentation in gh-pages branch)
157162
// The profile where the project is posted
163+
[<Literal>]
158164
let gitOwner = "fsprojects"
159165
let gitHome = "https://github.com/" + gitOwner
160166

161167
// The name of the project on GitHub
168+
[<Literal>]
162169
let gitName = "SQLProvider"
163170

164171
// The url for the raw files hosted
@@ -175,7 +182,7 @@ let release = ReleaseNotes.load "docs/RELEASE_NOTES.md"
175182
Target.create "AssemblyInfo" (fun _ ->
176183
projects
177184
|> Seq.iter (fun project ->
178-
let fileName = "src/" + project.name + "/AssemblyInfo.fs"
185+
let fileName = $"src/{project.name}/AssemblyInfo.fs"
179186
Fake.DotNet.AssemblyInfoFile.createFSharp fileName
180187
[ Fake.DotNet.AssemblyInfo.Title project.name
181188
Fake.DotNet.AssemblyInfo.Product "SQLProvider"
@@ -277,12 +284,14 @@ Target.create "SetupPostgreSQL" (fun _ ->
277284

278285
let setupMssql url saPassword =
279286

280-
let connBuilder = SqlConnectionStringBuilder()
281-
connBuilder.InitialCatalog <- "master"
282-
connBuilder.UserID <- "sa"
283-
connBuilder.DataSource <- url
284-
connBuilder.Password <- saPassword
285-
connBuilder.TrustServerCertificate <- true
287+
let connBuilder =
288+
SqlConnectionStringBuilder(
289+
InitialCatalog = "master",
290+
UserID = "sa",
291+
DataSource = url,
292+
Password = saPassword,
293+
TrustServerCertificate = true
294+
)
286295

287296
let maxAttempts = if Fake.Core.BuildServer.buildServer = AppVeyor then 60 else 30
288297
let runCmd query =
@@ -310,7 +319,7 @@ let setupMssql url saPassword =
310319
match cache, lines with
311320
| [], [] -> ()
312321
| cmds, [] -> yield cmds
313-
| cmds, l :: ls when l.Trim().ToUpper() = "GO" -> yield cmds; yield! cmdGen [] ls
322+
| cmds, l :: ls when String.Equals(l.Trim(), "GO", StringComparison.OrdinalIgnoreCase) -> yield cmds; yield! cmdGen [] ls
314323
| cmds, l :: ls -> yield! cmdGen (l :: cmds) ls
315324
}
316325

@@ -320,7 +329,7 @@ let setupMssql url saPassword =
320329

321330
let testDbName = "sqlprovider"
322331
printfn "Creating test database %s on connection %s" testDbName connBuilder.ConnectionString
323-
runCmd (sprintf "CREATE DATABASE %s" testDbName)
332+
runCmd $"CREATE DATABASE %s{testDbName}"
324333
connBuilder.InitialCatalog <- testDbName
325334

326335
(!! "src/DatabaseScripts/MSSQLServer/*.sql")
@@ -440,15 +449,15 @@ Target.create "WatchLocalDocs" (fun _ ->
440449
Target.create "ReleaseDocs" (fun _ ->
441450
let tempDocsDir = "temp/gh-pages"
442451
Fake.IO.Shell.cleanDir tempDocsDir
443-
Repository.cloneSingleBranch "" (gitHome + "/" + gitName + ".git") "gh-pages" tempDocsDir
452+
Repository.cloneSingleBranch "" ($"{gitHome}/{gitName}.git") "gh-pages" tempDocsDir
444453

445454
//Fake.IO.Shell.deleteDir tempDocsDir
446455
Fake.IO.Shell.copyRecursive "docs/output" tempDocsDir true |> Fake.Core.Trace.tracefn "%A"
447456
if not (System.IO.Directory.Exists tempDocsDir) then
448457
printfn "GH Pages not found, couldn't release."
449458
else
450459
Git.Staging.stageAll tempDocsDir
451-
Git.Commit.exec tempDocsDir (sprintf "Update generated documentation for version %s" release.NugetVersion)
460+
Git.Commit.exec tempDocsDir $"Update generated documentation for version %s{release.NugetVersion}"
452461
Branches.push tempDocsDir
453462
)
454463

‎docs/content/core/async.fsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type MyWebServer() =
7070
for t2 in context.MyDataBase.MyTable2 do
7171
join t1 in context.MyDataBase.MyTable1 on (t2.ForeignId = t1.Id)
7272
where (t2.Id = id)
73-
select (t1)
73+
select t1
7474
} |> Seq.executeQueryAsync
7575

7676
fetched |> Seq.iter (fun entity ->

‎docs/content/core/composable.fsx‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ let query1 =
4444
query {
4545
for customers in ctx.Main.Customers do
4646
where (customers.ContactTitle = "USA")
47-
select (customers)}
47+
select customers}
4848

4949
(**
5050
The variable that is returned from the query is sometimes called a computation. If you write to evaluate
@@ -116,11 +116,7 @@ let companyNameFilter inUse =
116116
let myFilter2 : IQueryable<CustomersEntity> -> IQueryable<CustomersEntity> = fun x -> x.Where(fun i -> i.CustomerId = "ALFKI")
117117

118118
let queryable:(IQueryable<CustomersEntity> -> IQueryable<CustomersEntity>) =
119-
match inUse with
120-
|true ->
121-
(fun iq -> iq.Where(fun (c:CustomersEntity) -> c.CompanyName = "The Big Cheese"))
122-
|false ->
123-
myFilter2
119+
if inUse then (fun iq -> iq.Where(fun (c:CustomersEntity) -> c.CompanyName = "The Big Cheese")) else myFilter2
124120
queryable
125121

126122
(**
@@ -133,7 +129,7 @@ let query1 =
133129
query {
134130
for customers in ctx.Main.Customers do
135131
where (customers.ContactTitle = "USA")
136-
select (customers)}
132+
select customers}
137133

138134

139135
(**
@@ -185,7 +181,7 @@ let nestedQueryTest =
185181
let qry1 = query {
186182
for emp in ctx.Hr.Employees do
187183
where (emp.FirstName.StartsWith("S"))
188-
select (emp.FirstName)
184+
select emp.FirstName
189185
}
190186
query {
191187
for emp in ctx.Hr.Employees do

‎docs/content/core/crud.fsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ employees
172172
employee.Create(x.ColumnValues)) // create twins
173173
|> Seq.toList
174174

175-
let twins = ctx.GetUpdates() // Retrieve the FSharp.Data.Sql.Common.SqlEntity objects
175+
/// Retrieve the FSharp.Data.Sql.Common.SqlEntity objects
176+
let twins = ctx.GetUpdates()
176177

177178
ctx.ClearUpdates() // delete the updates
178179
ctx.GetUpdates() // Get the updates
@@ -283,11 +284,12 @@ To delete many items from a database table, `DELETE FROM [dbo].[EMPLOYEES] WHERE
283284
284285
*)
285286
(*** hide ***)
287+
[<Literal>]
286288
let conditions = true
287289

288290
query {
289291
for c in ctx.Main.Employees do
290-
where (conditions)
292+
where conditions
291293
} |> Seq.``delete all items from single table`` |> Async.AwaitTask |> Async.RunSynchronously
292294

293295
(**
@@ -319,6 +321,7 @@ In the last case you'll be maintaining code like this:
319321
320322
*)
321323

324+
[<Literal>]
322325
let employeeId = 123
323326
// Got some untyped array of data from the client
324327
let createSomeItem (data: seq<string*obj>) =
@@ -373,7 +376,7 @@ SetColumn takes an object, giving you more control over the type serialization.
373376
374377
*)
375378

376-
let setIfExists (columnName) =
379+
let setIfExists columnName =
377380
if emp.HasColumn(columnName, StringComparison.InvariantCultureIgnoreCase) then
378381
emp.SetColumn(columnName, "testValue")
379382

‎docs/content/core/general.fsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let [<Literal>] resolutionPath = __SOURCE_DIRECTORY__ + @"/../../files/sqlite"
77
let [<Literal>] connectionString = "Data Source=" + __SOURCE_DIRECTORY__ + @"\..\northwindEF.db;Version=3;Read Only=false;FailIfMissing=True;"
88

99
(*** hide ***)
10-
(*
10+
(**
1111
1212
# SQL Provider Basics
1313
@@ -83,6 +83,7 @@ If you want to use non-literal connectionString at runtime (e.g. encrypted produ
8383
passwords), you can pass your runtime connectionString parameter to GetDataContext:
8484
*)
8585

86+
[<Literal>]
8687
let connectionString2 = "(insert runtime connection here)"
8788
let ctx2 = sql.GetDataContext connectionString2
8889

‎docs/content/core/msaccess.fsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ connectionString key/value pair stored in App.config (TODO: confirm file name).
5454
*)
5555

5656
// found in App.config (TODO:confirm)
57+
[<Literal>]
5758
let connexStringName = "DefaultConnectionString"
5859

5960
(**

‎docs/content/core/mysql.fsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ connectionString key/value pair stored in App.config (TODO: confirm filename).
4646
*)
4747

4848
// found in App.config (TODO: confirm)
49+
[<Literal>]
4950
let connexStringName = "DefaultConnectionString"
5051

5152
(**
@@ -119,11 +120,14 @@ let myEmp =
119120
query {
120121
for jh in ctx.Hr.JobHistory do
121122
where (jh.Years > 10u)
122-
select (jh)
123+
select jh
123124
} |> Seq.head
124125

126+
[<Literal>]
125127
let myUint32 = 10u
128+
[<Literal>]
126129
let myInt64 = 10L
130+
[<Literal>]
127131
let myUInt64 = 10UL
128132

129133
(**
@@ -134,9 +138,11 @@ If you use a string column to save a Guid to the database, you may want to skip
134138
when serializing them:
135139
136140
*)
137-
let myGuid = System.Guid.NewGuid() //e.g. b8fa7880-ce44-4315-8d60-a160e5734c4b
141+
///e.g. b8fa7880-ce44-4315-8d60-a160e5734c4b
142+
let myGuid = System.Guid.NewGuid()
138143

139-
let myGuidAsString = myGuid.ToString("N") // e.g. "b8fa7880ce4443158d60a160e5734c4b"
144+
/// e.g. "b8fa7880ce4443158d60a160e5734c4b"
145+
let myGuidAsString = myGuid.ToString("N")
140146

141147
(**
142148
The problem with this is that you should never forget to use "N" anywhere.

‎docs/content/core/parameters.fsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Another usually easier option is to give a runtime connection string as a parame
6767
In your source file:
6868
*)
6969

70+
[<Literal>]
7071
let connexStringName = "MyConnectionString"
7172

7273
(**
@@ -122,6 +123,7 @@ Number of instances to retrieve using the [individuals](individuals.html) featur
122123
Default is 1000.
123124
*)
124125

126+
[<Literal>]
125127
let indivAmt = 500
126128

127129

‎docs/content/core/querying.fsx‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ let example =
5151
query {
5252
for order in ctx.Main.Orders do
5353
where (order.Freight > 0m)
54-
sortBy (order.ShipPostalCode)
54+
sortBy order.ShipPostalCode
5555
skip 3
5656
take 4
57-
select (order)
57+
select order
5858
}
5959

6060
let test = example |> Seq.toArray |> Array.map(fun i -> i.ColumnValues |> Map.ofSeq)
@@ -77,7 +77,7 @@ let exampleAsync =
7777
query {
7878
for order in ctx.Main.Orders do
7979
where (order.Freight > 0m)
80-
select (order)
80+
select order
8181
} |> Seq.executeQueryAsync
8282
return res
8383
}
@@ -375,7 +375,7 @@ this is still ok and will give you a very simple select-clause:
375375
*)
376376

377377
let randomBoolean =
378-
let r = System.Random()
378+
let r = Random()
379379
fun () -> r.NextDouble() > 0.5
380380
let c1 = randomBoolean()
381381
let c2 = randomBoolean()
@@ -634,7 +634,7 @@ let orderIds =
634634
let subItems =
635635
query {
636636
for row in ctx.Main.OrderDetails do
637-
where (orderIds.Contains(row.OrderId))
637+
where (orderIds.Contains row.OrderId)
638638
select (row.OrderId, row.ProductId, row.Quantity)
639639
} |> Seq.toArray
640640

@@ -670,8 +670,8 @@ for chunk in chunked do
670670
let all =
671671
query {
672672
for row in ctx.Main.OrderDetails do
673-
where (chunk.Contains(row.OrderId))
674-
select (row)
673+
where (chunk.Contains row.OrderId)
674+
select row
675675
} |> Seq.toArray
676676

677677
all |> Array.iter(fun row -> row.Discount <- 0.1)
@@ -690,13 +690,13 @@ let nestedOrders =
690690
query {
691691
for order in ctx.Main.Orders do
692692
// where(...)
693-
select (order.OrderId)
693+
select order.OrderId
694694
}
695695

696696
let subItemsAll =
697697
query {
698698
for row in ctx.Main.OrderDetails do
699-
where (nestedOrders.Contains(row.OrderId))
699+
where (nestedOrders.Contains row.OrderId)
700700
select (row.OrderId, row.ProductId, row.Quantity)
701701
} |> Seq.toArray
702702

‎docs/content/core/unittest.fsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ let someProductionFunction (ctx:sql.dataContext) (orderType:OrderDateFilter) (un
9393
where ((cust.City = "London" || cust.City = "Paris" ) && (
9494
(ignoreOrderDate || order.OrderDate < tomorrow) && (someLegacyCondition < 15)) &&
9595
(ignoreShippedDate || order.ShippedDate < tomorrow) &&
96-
cust.CustomerId <> null && order.Freight > 10m
96+
(not (isNull cust.CustomerId)) && order.Freight > 10m
9797
)
9898
select (cust.PostalCode, order.Freight)
9999
}

0 commit comments

Comments
 (0)