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

andWhereIf, orWhereIf #95

Closed jindraivanek closed 10 months ago

jindraivanek commented 10 months ago

Adding new custom operations: andWhereIf, orWhereIf.

They get bool condition as first parameter and acts as andWhere, orWhere if condition holds and do nothing otherwise.

It allows to optionally extend WHERE condition based on parameters outside of query.

let pos = Some 10
let posOr = Some 2
select {
    for p in personTable do
    where (p.Position > 5)
    andWhereIf pos.IsSome (p.Position < pos.Value)
    orWhereIf posOr.IsSome (p.Position < posOr.Value)
} |> conn.SelectAsync<Person>