-
Notifications
You must be signed in to change notification settings - Fork 5
Configuration
Jacek edited this page Nov 2, 2019
·
2 revisions
The first step is to define parameterless function creating a database connection:
let createConnection () = new SqlConnection(connectionString)
let generatorConfig = createDefaultConfig createConnectionConnections are used in two contexts - when query code is generated, and when query functions are executed.
In the first case the connection creation function is wired-up by defining some functions:
let sql commandText = sql generatorConfig commandTextand, if explicit timeouts must be specified:
let sqlWithTimeout timeout commandText =
sql (generatorConfig |> addCommandTimeout timeout) commandTextthat generate code executing inline sql, and:
let proc name =
proc generatorConfig nameand
let procWithTimeout timeout name =
proc (generatorConfig |> addCommandTimeout timeout) namegenerating code for stored procedure execution.
The query execution configuration code depends on query mode (i.e. whether they are synchornous or asynchronous).
For synchronous execution the run function should be defined:
let run f = DbAction.run createConnection fand, additionally, when composite queries are used:
let buildQuery ctx = FinalQueryPart(ctx, generatorConfig, cleanUpTemplate)or with timeout:
let buildQueryWithTimeout timeout ctx =
FinalQueryPart(
ctx,
(generatorConfig |> addCommandTimeout timeout),
cleanUpTemplate)For asynchronous execution these function should be defined as follows:
let run f = AsyncDb.run createConnection fand
let buildQuery ctx = async {
return FinalQueryPart(ctx, generatorConfig, cleanUpTemplate)
}or
let buildQueryWithTimeout timeout ctx = async {
return FinalQueryPart(
ctx,
(generatorConfig |> addCommandTimeout timeout),
cleanUpTemplate)
}