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 about the Where operator AND and OR #75

Closed newbienewbie closed 1 year ago

newbienewbie commented 1 year ago

Hi, Dzoukr. Thanks for your awesome library.

I need compose multiple WHERE conditions:

    let x = select {
        for e: Customer in customerTable do
        where (e.firstname = "S")        //  1st where condition
    }

    let meetSomeCondition = true   // some condition 

    let y = 
        if not meetSomeCondition then x 
        else {
            x with 
                Where = x.Where + Column("Age", Gt 3)        //  2nd where condition
            }

    y |> conn.SelectAsync<Customer>

However, I'm confused about the operator AND & OR defined for the Where Type:

type Where =
    | Empty
    | Column of string * ColumnComparison
    | Binary of Where * BinaryOperation * Where
    | Unary of UnaryOperation * Where
    | Expr of string
    static member (+) (a, b) = Binary(a, And, b)
    static member (*) (a, b) = Binary(a, Or, b)
    static member (!!) a = Unary (Not, a)

Is there any reason why (+) is chosen for AND & (*) is chosen for OR ?

Dzoukr commented 1 year ago

Hello @newbienewbie, there is already discussion around this here https://github.com/Dzoukr/Dapper.FSharp/issues/37

I think, in a long term, I should mark these operators as obsolete and use traditional LINQ && and ||

newbienewbie commented 1 year ago

I'm sorry I should search the issues before asking :(

Dzoukr commented 1 year ago

No problem at all. :) Thanks for using this library 👍