Skip to content

Instantly share code, notes, and snippets.

@anderssonfilip
Last active December 30, 2015 21:39
Show Gist options
  • Select an option

  • Save anderssonfilip/7888997 to your computer and use it in GitHub Desktop.

Select an option

Save anderssonfilip/7888997 to your computer and use it in GitHub Desktop.
Example of using seq{...} to load similar data from tables. To demonstrate difference between synchronous and asynchronous sequences
open Devart.Data
open Devart.Data.Oracle // http://www.devart.com/dotconnect/oracle/download.html
open FSharp.Control // https://github.com/tpetricek/FSharp.AsyncExtensions
open System
open System.Data
let sql = "SELECT * FROM {}"
let tables = [|"t1";"t2";"t3";"t4";"t5";"t6"|]
let cs = "<insert connection string here!>"
let LoadSingleTable (cmd:IDbCommand) table = seq {
cmd.CommandText <- sql.Replace("{}", table)
let reader = cmd.ExecuteReader()
while reader.Read() do
yield reader.GetString(0)
}
let LoadAllTables (db:IDbConnection) =
let cmd = db.CreateCommand()
Seq.map (fun t -> LoadSingleTable cmd t) tables |> Seq.collect (fun r -> r)
[<EntryPoint>]
let Main args =
use db = new OracleConnection(cs)
db.Open()
let items = LoadAllTables db
async{
for item in items do printfn "%s" item
} |> Async.Start
Console.ReadLine() |> ignore
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment