Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ type Project = {
/// List of dependencies
dependencies:(string * string) list }

[<Literal>]
let project = "SQLProvider"
[<Literal>]
let summary = "Type providers for SQL database access."
[<Literal>]
let description = "Type providers for SQL database access."

let projects =
Expand Down Expand Up @@ -148,17 +151,21 @@ let projects =
let authors = [ "Ross McKinlay, Colin Bull, Tuomas Hietanen" ]

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

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

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

// The name of the project on GitHub
[<Literal>]
let gitName = "SQLProvider"

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

let setupMssql url saPassword =

let connBuilder = SqlConnectionStringBuilder()
connBuilder.InitialCatalog <- "master"
connBuilder.UserID <- "sa"
connBuilder.DataSource <- url
connBuilder.Password <- saPassword
connBuilder.TrustServerCertificate <- true
let connBuilder =
SqlConnectionStringBuilder(
InitialCatalog = "master",
UserID = "sa",
DataSource = url,
Password = saPassword,
TrustServerCertificate = true
)

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

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion docs/content/core/async.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type MyWebServer() =
for t2 in context.MyDataBase.MyTable2 do
join t1 in context.MyDataBase.MyTable1 on (t2.ForeignId = t1.Id)
where (t2.Id = id)
select (t1)
select t1
} |> Seq.executeQueryAsync

fetched |> Seq.iter (fun entity ->
Expand Down
12 changes: 4 additions & 8 deletions docs/content/core/composable.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let query1 =
query {
for customers in ctx.Main.Customers do
where (customers.ContactTitle = "USA")
select (customers)}
select customers}

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

let queryable:(IQueryable<CustomersEntity> -> IQueryable<CustomersEntity>) =
match inUse with
|true ->
(fun iq -> iq.Where(fun (c:CustomersEntity) -> c.CompanyName = "The Big Cheese"))
|false ->
myFilter2
if inUse then (fun iq -> iq.Where(fun (c:CustomersEntity) -> c.CompanyName = "The Big Cheese")) else myFilter2
queryable

(**
Expand All @@ -133,7 +129,7 @@ let query1 =
query {
for customers in ctx.Main.Customers do
where (customers.ContactTitle = "USA")
select (customers)}
select customers}


(**
Expand Down Expand Up @@ -185,7 +181,7 @@ let nestedQueryTest =
let qry1 = query {
for emp in ctx.Hr.Employees do
where (emp.FirstName.StartsWith("S"))
select (emp.FirstName)
select emp.FirstName
}
query {
for emp in ctx.Hr.Employees do
Expand Down
9 changes: 6 additions & 3 deletions docs/content/core/crud.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ employees
employee.Create(x.ColumnValues)) // create twins
|> Seq.toList

let twins = ctx.GetUpdates() // Retrieve the FSharp.Data.Sql.Common.SqlEntity objects
/// Retrieve the FSharp.Data.Sql.Common.SqlEntity objects
let twins = ctx.GetUpdates()

ctx.ClearUpdates() // delete the updates
ctx.GetUpdates() // Get the updates
Expand Down Expand Up @@ -283,11 +284,12 @@ To delete many items from a database table, `DELETE FROM [dbo].[EMPLOYEES] WHERE

*)
(*** hide ***)
[<Literal>]
let conditions = true

query {
for c in ctx.Main.Employees do
where (conditions)
where conditions
} |> Seq.``delete all items from single table`` |> Async.AwaitTask |> Async.RunSynchronously

(**
Expand Down Expand Up @@ -319,6 +321,7 @@ In the last case you'll be maintaining code like this:

*)

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

*)

let setIfExists (columnName) =
let setIfExists columnName =
if emp.HasColumn(columnName, StringComparison.InvariantCultureIgnoreCase) then
emp.SetColumn(columnName, "testValue")

3 changes: 2 additions & 1 deletion docs/content/core/general.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let [<Literal>] resolutionPath = __SOURCE_DIRECTORY__ + @"/../../files/sqlite"
let [<Literal>] connectionString = "Data Source=" + __SOURCE_DIRECTORY__ + @"\..\northwindEF.db;Version=3;Read Only=false;FailIfMissing=True;"

(*** hide ***)
(*
(**

# SQL Provider Basics

Expand Down Expand Up @@ -83,6 +83,7 @@ If you want to use non-literal connectionString at runtime (e.g. encrypted produ
passwords), you can pass your runtime connectionString parameter to GetDataContext:
*)

[<Literal>]
let connectionString2 = "(insert runtime connection here)"
let ctx2 = sql.GetDataContext connectionString2

Expand Down
1 change: 1 addition & 0 deletions docs/content/core/msaccess.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ connectionString key/value pair stored in App.config (TODO: confirm file name).
*)

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

(**
Expand Down
12 changes: 9 additions & 3 deletions docs/content/core/mysql.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ connectionString key/value pair stored in App.config (TODO: confirm filename).
*)

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

(**
Expand Down Expand Up @@ -119,11 +120,14 @@ let myEmp =
query {
for jh in ctx.Hr.JobHistory do
where (jh.Years > 10u)
select (jh)
select jh
} |> Seq.head

[<Literal>]
let myUint32 = 10u
[<Literal>]
let myInt64 = 10L
[<Literal>]
let myUInt64 = 10UL

(**
Expand All @@ -134,9 +138,11 @@ If you use a string column to save a Guid to the database, you may want to skip
when serializing them:

*)
let myGuid = System.Guid.NewGuid() //e.g. b8fa7880-ce44-4315-8d60-a160e5734c4b
///e.g. b8fa7880-ce44-4315-8d60-a160e5734c4b
let myGuid = System.Guid.NewGuid()

let myGuidAsString = myGuid.ToString("N") // e.g. "b8fa7880ce4443158d60a160e5734c4b"
/// e.g. "b8fa7880ce4443158d60a160e5734c4b"
let myGuidAsString = myGuid.ToString("N")

(**
The problem with this is that you should never forget to use "N" anywhere.
Expand Down
2 changes: 2 additions & 0 deletions docs/content/core/parameters.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Another usually easier option is to give a runtime connection string as a parame
In your source file:
*)

[<Literal>]
let connexStringName = "MyConnectionString"

(**
Expand Down Expand Up @@ -122,6 +123,7 @@ Number of instances to retrieve using the [individuals](individuals.html) featur
Default is 1000.
*)

[<Literal>]
let indivAmt = 500


Expand Down
18 changes: 9 additions & 9 deletions docs/content/core/querying.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ let example =
query {
for order in ctx.Main.Orders do
where (order.Freight > 0m)
sortBy (order.ShipPostalCode)
sortBy order.ShipPostalCode
skip 3
take 4
select (order)
select order
}

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

let randomBoolean =
let r = System.Random()
let r = Random()
fun () -> r.NextDouble() > 0.5
let c1 = randomBoolean()
let c2 = randomBoolean()
Expand Down Expand Up @@ -634,7 +634,7 @@ let orderIds =
let subItems =
query {
for row in ctx.Main.OrderDetails do
where (orderIds.Contains(row.OrderId))
where (orderIds.Contains row.OrderId)
select (row.OrderId, row.ProductId, row.Quantity)
} |> Seq.toArray

Expand Down Expand Up @@ -670,8 +670,8 @@ for chunk in chunked do
let all =
query {
for row in ctx.Main.OrderDetails do
where (chunk.Contains(row.OrderId))
select (row)
where (chunk.Contains row.OrderId)
select row
} |> Seq.toArray

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

let subItemsAll =
query {
for row in ctx.Main.OrderDetails do
where (nestedOrders.Contains(row.OrderId))
where (nestedOrders.Contains row.OrderId)
select (row.OrderId, row.ProductId, row.Quantity)
} |> Seq.toArray

Expand Down
2 changes: 1 addition & 1 deletion docs/content/core/unittest.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ let someProductionFunction (ctx:sql.dataContext) (orderType:OrderDateFilter) (un
where ((cust.City = "London" || cust.City = "Paris" ) && (
(ignoreOrderDate || order.OrderDate < tomorrow) && (someLegacyCondition < 15)) &&
(ignoreShippedDate || order.ShippedDate < tomorrow) &&
cust.CustomerId <> null && order.Freight > 10m
(not (isNull cust.CustomerId)) && order.Freight > 10m
)
select (cust.PostalCode, order.Freight)
}
Expand Down
8 changes: 4 additions & 4 deletions src/SQLProvider.Common/DataTable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module DataTable =

let groupBy f (dt:DataTable) =
map f dt
|> Seq.groupBy (fst)
|> Seq.groupBy fst
|> Seq.map (fun (k, v) -> k, Seq.map snd v)

let cache (cache:IDictionary<string,'a>) f (dt:DataTable) =
Expand All @@ -35,7 +35,7 @@ module DataTable =
[
for row in dt.Rows do
match f row with
| Some(a) -> yield a
| Some a -> yield a
| None -> ()
]

Expand All @@ -44,7 +44,7 @@ module DataTable =
copy.Rows.Clear()
for row in dt.Rows do
match row |> f with
| Some(a) -> copy.Rows.Add(a.ItemArray) |> ignore
| Some a -> copy.Rows.Add(a.ItemArray) |> ignore
| None -> ()
copy

Expand All @@ -68,7 +68,7 @@ module DataTable =

let computeMaxWidth indx length =
let len =
match widths.TryGetValue(indx) with
match widths.TryGetValue indx with
| true, len -> max len length
| false, _ -> length
widths.[indx] <- len
Expand Down
Loading
Loading