Skip to content

Instantly share code, notes, and snippets.

@JustinJohnWilliams
Created August 26, 2016 15:48
Show Gist options
  • Save JustinJohnWilliams/3736675f537c37487dcc84c544bd07aa to your computer and use it in GitHub Desktop.
Save JustinJohnWilliams/3736675f537c37487dcc84c544bd07aa to your computer and use it in GitHub Desktop.
module database
open FSharp.Data.Sql
open FSharp.Data.Sql.Common
let [<Literal>] connectionString = "Data Source=.;Initial Catalog=CreditFulfillment;Integrated Security=SSPI;"
type sql = SqlDataProvider<DatabaseProviderTypes.MSSQLSERVER,
connectionString,
CaseSensitivityChange = CaseSensitivityChange.ORIGINAL>
let ctx = sql.GetDataContext()
let getActiveAccountsFor email =
query {
for customer in ctx.Dbo.Customers do
join account in ctx.Dbo.Accounts on (customer.Id = account.CustomerId)
where (customer.EmailAddress = email && account.IsActive = true)
select account
} |> Seq.toArray
let deactivateAccount accountId =
query {
for account in ctx.Dbo.Accounts do
where (account.AccountId = accountId)
select account
} |> Seq.iter(fun account ->
account.IsActive <- false
)
ctx.SubmitUpdates()
let deActivateCustomer email =
getActiveAccountsFor email |> Seq.iter (fun account -> deactivateAccount account.AccountId)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment