Skip to content

Executing queries

Jacek Hełka edited this page Mar 20, 2024 · 4 revisions

Query functions, defined with DbFun, return DbCall<'Result>, that is function taking IConnector parameter (object carrying database connection and optionally transaction) and returning data wrapped in Async.

Such function can be executed by passing it to the run function defined in the Configuration section:

    let blog = getBlog id |> DB.run

To execute more queries on one open connection the dbsession computation expression can be used:

    dbsession {
        let! postId = insertPost p
        do! insertTags postId p.tags 
    } 
    |> DB.run

Queries can also be executed transactionally:

    dbsession {
        let! postId = insertPost p
        do! insertTags postId p.tags 
    } 
    |> DbCall.InTransaction 
    |> DB.run

With a certain isolationlevel:

    dbsession {
        let! postId = insertPost p
        do! insertTags postId p.tags 
    } 
    |> DbCall.InTransactionWith IsolationLevel.RepeatableRead 
    |> DB.run
Clone this wiki locally