Dzoukr / Dapper.FSharp

Lightweight F# extension for StackOverflow Dapper with support for MSSQL, MySQL, PostgreSQL, and SQLite
MIT License
365 stars 35 forks source link

Question: Logging query parameter values #14

Closed ssiltanen closed 3 years ago

ssiltanen commented 3 years ago

The signature for logging function was before 1.13.0 string Map<string, obj> -> unit and in 1.13.0 it was changed to string obj -> unit.

After the change I have had trouble printing the parameters correctly, especially when obj is Map<string, List<string, obj>> (this happens when using isIn function in where clause). I tried to pattern match the runtime type but had no luck there. Following example is an attempt to log isIn parameters.

match values with
| :? Map<string, System.Collections.Generic.List<string>> as map ->
    map
    |> Seq.map (fun (KeyValue(key,value)) -> sprintf "%s: %s" key (String.concat ", " value))
    |> String.concat Environment.NewLine
 | _ ->
    string values // All other cases so far kinda work straight of obj

// Output: map [(Where_Type1, System.Collections.Generic.List`1[System.String])]

How would you implement the query logging function for parameter values?

Dzoukr commented 3 years ago

Hello, it seems to be a bug introduced in 1.13.0 - the signature for logging function should be string * Map<string, obj> -> unit

I'll try to fix it soon.

Dzoukr commented 3 years ago

Should be fixed now in 1.13.1

ssiltanen commented 3 years ago

Works now thanks!

Dzoukr commented 3 years ago

Cool! Sorry for troubles 😄