-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.fs
63 lines (47 loc) · 1.7 KB
/
Program.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
open System
open FSharp.Data.Sql
FSharp.Data.Sql.Common.QueryEvents.SqlQueryEvent |> Event.add (printfn "Executing SQL: %O")
[<Literal>]
let ConnString = "Server=localhost;Database=test;User=njeiseck;Password=password"
[<Literal>]
let DbVendor = Common.DatabaseProviderTypes.MYSQL
[<Literal>]
let ContextSchemaPath = __SOURCE_DIRECTORY__ + @"/test.schema"
type Sql = SqlDataProvider<DatabaseVendor = DbVendor,
ConnectionString = ConnString,
ContextSchemaPath = ContextSchemaPath,
Owner = "Test",
UseOptionTypes = true
>
let ctx = Sql.GetDataContext()
let query1 = ctx.Test.People
|> Seq.map (fun e -> e.ColumnValues |> Seq.toList)
|> Seq.toList
let query2 =
query {
for t in ctx.Test.People do
where (t.FirstName.Value.Contains "F") // Name is Nullable
select (t.FirstName, t.LastName, t.Info, t.Id)
} |> Seq.toList
[<EntryPoint>]
let main argv =
// Query some data
printfn "Q1: %A" query1
printfn "Q2: %A" query2
// Add
let rows =
seq {
for i in 1 .. 10 do
let row = ctx.Test.People.Create()
row.FirstName <- Some "First Name";
row.LastName <- Some "Last Name"
yield row
} |> Seq.toList
ctx.SubmitUpdates()
// print generated ids
for row in rows do
printfn "New Id %A" row.Id
// Rather crude way to store the schema data so no actual DB is needed in CI
//printfn "Context Schema: %s" ContextSchemaPath
//ctx.SaveContextSchema() |> ignore
0 // exit code