Skip to content

Commit 3889dc2

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents ad1b9b0 + cd327b5 commit 3889dc2

File tree

5 files changed

+73
-4
lines changed

5 files changed

+73
-4
lines changed

src/code-listings/lesson-35/BankAccountDb/Script.PostDeployment.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,22 @@ IF NOT EXISTS (SELECT * FROM dbo.Operation)
1414
BEGIN
1515
INSERT INTO dbo.Operation VALUES (1, 'Withdraw')
1616
INSERT INTO dbo.Operation VALUES (2, 'Deposit')
17+
END
18+
19+
IF NOT EXISTS (SELECT * FROM dbo.Account)
20+
BEGIN
21+
INSERT INTO [dbo].[Account] ([Owner], [AccountId]) VALUES (N'isaac', N'c425e943-b3ca-40b5-8977-f3ddbcda80fc')
22+
END
23+
24+
IF NOT EXISTS (SELECT * FROM dbo.AccountTransaction)
25+
BEGIN
26+
SET IDENTITY_INSERT [dbo].[AccountTransaction] ON
27+
INSERT INTO [dbo].[AccountTransaction] ([AccountTransactionId], [AccountId], [Timestamp], [OperationId], [Amount]) VALUES (1, N'c425e943-b3ca-40b5-8977-f3ddbcda80fc', N'2017-05-11 22:51:47', 2, CAST(10 AS Decimal(18, 0)))
28+
INSERT INTO [dbo].[AccountTransaction] ([AccountTransactionId], [AccountId], [Timestamp], [OperationId], [Amount]) VALUES (2, N'c425e943-b3ca-40b5-8977-f3ddbcda80fc', N'2017-05-11 22:51:48', 2, CAST(10 AS Decimal(18, 0)))
29+
INSERT INTO [dbo].[AccountTransaction] ([AccountTransactionId], [AccountId], [Timestamp], [OperationId], [Amount]) VALUES (3, N'c425e943-b3ca-40b5-8977-f3ddbcda80fc', N'2017-05-11 22:51:48', 2, CAST(10 AS Decimal(18, 0)))
30+
INSERT INTO [dbo].[AccountTransaction] ([AccountTransactionId], [AccountId], [Timestamp], [OperationId], [Amount]) VALUES (4, N'c425e943-b3ca-40b5-8977-f3ddbcda80fc', N'2017-05-11 22:51:48', 2, CAST(10 AS Decimal(18, 0)))
31+
INSERT INTO [dbo].[AccountTransaction] ([AccountTransactionId], [AccountId], [Timestamp], [OperationId], [Amount]) VALUES (5, N'c425e943-b3ca-40b5-8977-f3ddbcda80fc', N'2017-05-11 22:51:51', 2, CAST(50 AS Decimal(18, 0)))
32+
INSERT INTO [dbo].[AccountTransaction] ([AccountTransactionId], [AccountId], [Timestamp], [OperationId], [Amount]) VALUES (6, N'c425e943-b3ca-40b5-8977-f3ddbcda80fc', N'2017-05-11 22:51:54', 1, CAST(100 AS Decimal(18, 0)))
33+
INSERT INTO [dbo].[AccountTransaction] ([AccountTransactionId], [AccountId], [Timestamp], [OperationId], [Amount]) VALUES (7, N'c425e943-b3ca-40b5-8977-f3ddbcda80fc', N'2017-05-11 22:52:00', 2, CAST(50 AS Decimal(18, 0)))
34+
SET IDENTITY_INSERT [dbo].[AccountTransaction] OFF
1735
END
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
#load "Domain.fs"
22
#load "Operations.fs"
3+
#r @"..\packages\FSharp.Data.SqlClient.1.8.2\lib\net40\FSharp.Data.SqlClient.dll"
4+
#load "SqlRepository.fs"
35

46
open Capstone6.Operations
57
open Capstone6.Domain
68
open System
9+
open FSharp.Data
10+
11+
// Copied from SqlRepository.fs, this allows you to test out the queries and commands in isolation.
12+
let [<Literal>] Conn = @"Data Source=(localdb)\MSSQLLocalDB;Database=BankAccountDb;Integrated Security=True;Connect Timeout=60"
13+
type AccountsDb = SqlProgrammabilityProvider<Conn>
14+
type GetAccountId = SqlCommandProvider<"SELECT TOP 1 AccountId FROM dbo.Account WHERE Owner = @owner", Conn, SingleRow = true>
15+
type FindTransactions = SqlCommandProvider<"SELECT Timestamp, OperationId, Amount FROM dbo.AccountTransaction WHERE AccountId = @accountId", Conn>
16+
type FindTransactionsByOwner = SqlCommandProvider<"SELECT a.AccountId, at.Timestamp, at.OperationId, at.Amount FROM dbo.Account a LEFT JOIN dbo.AccountTransaction at on a.AccountId = at.AccountId WHERE Owner = @owner", Conn>
17+
type DbOperations = SqlEnumProvider<"SELECT Description, OperationId FROM dbo.Operation", Conn>
18+
19+
// Get an accountId and then associated transactions. Note that I'm using .Value to "unwrap" the
20+
// optional accountId. This is unsafe and should NEVER be done in "real" code; use either pattern
21+
// matching or Option.map. I'm using it here as (a) this is a demo script, and (b) the database
22+
// is primed with an account that I know about.
23+
let accountId = GetAccountId.Create(Conn).Execute("isaac")
24+
let transactions = FindTransactions.Create(Conn).Execute(accountId.Value) |> Seq.toArray

src/code-listings/lesson-35/sample-solution/BankAccountDb/Script.PostDeployment.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,22 @@ IF NOT EXISTS (SELECT * FROM dbo.Operation)
1414
BEGIN
1515
INSERT INTO dbo.Operation VALUES (1, 'Withdraw')
1616
INSERT INTO dbo.Operation VALUES (2, 'Deposit')
17+
END
18+
19+
IF NOT EXISTS (SELECT * FROM dbo.Account)
20+
BEGIN
21+
INSERT INTO [dbo].[Account] ([Owner], [AccountId]) VALUES (N'isaac', N'c425e943-b3ca-40b5-8977-f3ddbcda80fc')
22+
END
23+
24+
IF NOT EXISTS (SELECT * FROM dbo.AccountTransaction)
25+
BEGIN
26+
SET IDENTITY_INSERT [dbo].[AccountTransaction] ON
27+
INSERT INTO [dbo].[AccountTransaction] ([AccountTransactionId], [AccountId], [Timestamp], [OperationId], [Amount]) VALUES (1, N'c425e943-b3ca-40b5-8977-f3ddbcda80fc', N'2017-05-11 22:51:47', 2, CAST(10 AS Decimal(18, 0)))
28+
INSERT INTO [dbo].[AccountTransaction] ([AccountTransactionId], [AccountId], [Timestamp], [OperationId], [Amount]) VALUES (2, N'c425e943-b3ca-40b5-8977-f3ddbcda80fc', N'2017-05-11 22:51:48', 2, CAST(10 AS Decimal(18, 0)))
29+
INSERT INTO [dbo].[AccountTransaction] ([AccountTransactionId], [AccountId], [Timestamp], [OperationId], [Amount]) VALUES (3, N'c425e943-b3ca-40b5-8977-f3ddbcda80fc', N'2017-05-11 22:51:48', 2, CAST(10 AS Decimal(18, 0)))
30+
INSERT INTO [dbo].[AccountTransaction] ([AccountTransactionId], [AccountId], [Timestamp], [OperationId], [Amount]) VALUES (4, N'c425e943-b3ca-40b5-8977-f3ddbcda80fc', N'2017-05-11 22:51:48', 2, CAST(10 AS Decimal(18, 0)))
31+
INSERT INTO [dbo].[AccountTransaction] ([AccountTransactionId], [AccountId], [Timestamp], [OperationId], [Amount]) VALUES (5, N'c425e943-b3ca-40b5-8977-f3ddbcda80fc', N'2017-05-11 22:51:51', 2, CAST(50 AS Decimal(18, 0)))
32+
INSERT INTO [dbo].[AccountTransaction] ([AccountTransactionId], [AccountId], [Timestamp], [OperationId], [Amount]) VALUES (6, N'c425e943-b3ca-40b5-8977-f3ddbcda80fc', N'2017-05-11 22:51:54', 1, CAST(100 AS Decimal(18, 0)))
33+
INSERT INTO [dbo].[AccountTransaction] ([AccountTransactionId], [AccountId], [Timestamp], [OperationId], [Amount]) VALUES (7, N'c425e943-b3ca-40b5-8977-f3ddbcda80fc', N'2017-05-11 22:52:00', 2, CAST(50 AS Decimal(18, 0)))
34+
SET IDENTITY_INSERT [dbo].[AccountTransaction] OFF
1735
END
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
#load "Domain.fs"
22
#load "Operations.fs"
3+
#r @"..\packages\FSharp.Data.SqlClient.1.8.2\lib\net40\FSharp.Data.SqlClient.dll"
4+
#load "SqlRepository.fs"
35

46
open Capstone6.Operations
57
open Capstone6.Domain
68
open System
9+
open FSharp.Data
10+
11+
// Copied from SqlRepository.fs, this allows you to test out the queries and commands in isolation.
12+
let [<Literal>] Conn = @"Data Source=(localdb)\MSSQLLocalDB;Database=BankAccountDb;Integrated Security=True;Connect Timeout=60"
13+
type AccountsDb = SqlProgrammabilityProvider<Conn>
14+
type GetAccountId = SqlCommandProvider<"SELECT TOP 1 AccountId FROM dbo.Account WHERE Owner = @owner", Conn, SingleRow = true>
15+
type FindTransactions = SqlCommandProvider<"SELECT Timestamp, OperationId, Amount FROM dbo.AccountTransaction WHERE AccountId = @accountId", Conn>
16+
type FindTransactionsByOwner = SqlCommandProvider<"SELECT a.AccountId, at.Timestamp, at.OperationId, at.Amount FROM dbo.Account a LEFT JOIN dbo.AccountTransaction at on a.AccountId = at.AccountId WHERE Owner = @owner", Conn>
17+
type DbOperations = SqlEnumProvider<"SELECT Description, OperationId FROM dbo.Operation", Conn>
18+
19+
// Get an accountId and then associated transactions. Note that I'm using .Value to "unwrap" the
20+
// optional accountId. This is unsafe and should NEVER be done in "real" code; use either pattern
21+
// matching or Option.map. I'm using it here as (a) this is a demo script, and (b) the database
22+
// is primed with an account that I know about.
23+
let accountId = GetAccountId.Create(Conn).Execute("isaac")
24+
let transactions = FindTransactions.Create(Conn).Execute(accountId.Value) |> Seq.toArray

src/code-listings/lesson-36.fsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@ let asyncLength =
3737

3838
asyncLength |> Async.RunSynchronously
3939

40-
// Listing 36.4
41-
let getTextAsync = async { return "HELLO" }
42-
Async.StartWithContinuations(getTextAsync, (fun text -> printfn "%s WORLD" text), ignore, ignore)
43-
4440
// Listing 36.5
41+
let getTextAsync = async { return "HELLO" }
4542
let printHelloWorld =
4643
async {
4744
let! text = getTextAsync

0 commit comments

Comments
 (0)