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

Is there a query that implements something like `QueryFirst`, `QueryFirstOrDefault`? #103

Closed vitash closed 3 months ago

vitash commented 3 months ago

The following code queries the first data by id:

let findById id = task {
    let! data =
        select {
            for u in Tbl do
            where (u.id = id)
            take 1
        } |> conn.SelectAsync<'a>
    return data |> Seq.tryHead
}

It would be simpler to have something like QueryFirstOrDefault and want the return value to be of option type.

Dzoukr commented 3 months ago

I think it's rather about personal taste so I'll keep that for custom project-specific wrappers.

vitash commented 3 months ago

Got it. Thanks.