Skip to content

Commit

Permalink
datatable output
Browse files Browse the repository at this point in the history
  • Loading branch information
pimbrouwers committed Mar 20, 2024
1 parent 43b76ed commit a75073f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/Donald/Db.fs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ module Db =
tran.TryRollback()
reraise ()

/// Execute paramterized query and return DataTable
let dataTable (dbUnit : DbUnit) : DataTable =
read (fun rd ->
let dt = new DataTable()
dt.Load(rd)
dt) dbUnit

module Async =
let private tryDoAsync (dbUnit : DbUnit) (fn : DbCommand -> Task<'a>) : Task<'a> =
task {
Expand Down Expand Up @@ -165,4 +172,11 @@ module Db =
return result }
with _ ->
tran.TryRollback()
reraise()
reraise()

/// Asynchronously Execute paramterized query and return DataTable
let dataTable (dbUnit : DbUnit) =
read (fun rd ->
let dt = new DataTable()
dt.Load(rd)
dt) dbUnit
2 changes: 1 addition & 1 deletion src/Donald/Donald.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<AssemblyName>Donald</AssemblyName>
<Version>10.0.2</Version>
<Version>10.1.0</Version>

<!-- General info -->
<Description>Functional F# interface for ADO.NET.</Description>
Expand Down
17 changes: 17 additions & 0 deletions test/Donald.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -768,3 +768,20 @@ type ExecutionTests() =
|> ignore

action |> should throw typeof<Tasks.TaskCanceledException>

[<Fact>]
member _.``SELECT dataTable should produce DataTable matching first result set`` () =
let sql = "
SELECT 'Donald Chamberlin' AS name, 'Computer Scientist' AS profession
UNION
SELECT 'LeBron James' As name, 'Professional Athlete' AS profession"

let dataTable =
conn
|> Db.newCommand sql
|> Db.dataTable

dataTable.Rows[0]["name"] |> should equal "Donald Chamberlin"
dataTable.Rows[0]["profession"] |> should equal "Computer Scientist"
dataTable.Rows[1]["name"] |> should equal "LeBron James"
dataTable.Rows[1]["profession"] |> should equal "Professional Athlete"

0 comments on commit a75073f

Please sign in to comment.