Functions I keep around when using Npgsql.FSharp

I have previously written about SqlFun and how I really like the library and its quasi-static type checking. However, at work I’m currently working with Npgsql.FSharp from the great Zaid Ajaj. I also like this library a lot, although, I don’t really appreciate some aspects of it.

You can see that someone also missed this functionality on issue #67. I volunteered to introduce it on the library too. In order to “fix” this issue, you can introduce the following code on your project:

namespace Npgsql.FShap

open Npgsql.FSharp

/// This module is an extension of the Npgsql.FSharp.Sql module
/// it contains useful functions not present on the library
module Sql =
    /// Executes a query and returns an optional with the results
    /// If no value is returned, returns None
    /// If values are found, returns Some
    let tryExecuteAsync read props =
        task {
            match! Sql.executeAsync read props with
            | [] -> return None
            | data -> return Some data

    /// Executes a query and returns an optional with the first result
    /// If no value is returned, returns None
    /// If values are found, returns the first one
    let tryExecuteRowAsync read props =
        task {
            match! tryExecuteAsync read props with
            | None -> return None
            | Some [] -> return None
            | Some(data :: _) -> return Some data

Articles from blogs I follow around the net

Trimming a Fake Object

A refactoring example. When I introduce the Fake Object testing pattern to people, a common concern is the maintenance burden of it. The point of the pattern is that you write some 'working' code only for test purposes. …

via ploeh blog November 20, 2023

Building a digital vigil for those we've lost

This post is hard to write in a lot of ways. It's more personal than most I've written. This is presumptively a tech blog, and this piece is about so much more than technology. But it's important. Making things, software or otherwise, is ultimatel…

via blog November 19, 2023

#122 Experimenting and Learning

Update on what happened across the GNOME project in the week from November 10 to November 17. GNOME Circle Apps and Libraries Workbench A sandbox to learn and prototype with GNOME technologies. Sonny says Workbench is a code playground and Library to learn, e…

via This Week in GNOME November 17, 2023

Generated by openring