简体   繁体   中英

Suave and DotLiquid

edited for clarity

somehow this works:

path "/" >=> warbler (fun _ -> OK (string DateTime.Now))

but this one does not:

let txnAccA =
    let sqlStr = "select JSON from Store.Txn"
    let result = Db.execute sqlStr Config.oConnStr
    match result with
    | Some a ->
        [for i in a do 
            let msg = JsonConvert.DeserializeObject<TxnAccA>(i)
            yield msg
            ]

    | _ ->
        List.empty<TxnAccA>

let txnAmtA =
    let sqlStr = "select JSON from Store.Amt"
    let result = Db.execute sqlStr Config.oConnStr
    match result with
    | Some a ->
        [for i in a do 
            let msg = JsonConvert.DeserializeObject<TxnAmtA>(i)
            yield msg
            ]

    | _ ->
        List.empty<TxnAmtA>

let result ()= {Acc= txnAccA; Amt= txnAmtA}
path "/txn" >=> warbler (fun _ -> page "txn.html" (result()))

By "works" I mean that the page is not static, it displays latest data from database. Any idea why?

txnAccA and txnAmtA need to be functions (similar to result ). They are defined as values now, so get assigned once and will not query the DB for every request. result will create a new record every time when called, but the values stay always the same.

let txnAccA () = //...

let txnAmtA () = //...

let result () = { Acc = txnAccA(); Amt = txnAmtA() }
path "/txn" >=> warbler (fun _ -> page "txn.html" (result()))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM