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
[<RequireQualifiedAccess>]
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

Variations of the Range kata

In the languages I usually employ. The Range kata is succinct, bordering on the spartan in both description and requirements. To be honest, it's hardly the most inspiring kata available, and yet it may help showcase a few in…

via ploeh blog January 1, 2024

Some notes on NixOS

Hello! Over the holidays I decided it might be fun to run NixOS on one of my servers, as part of my continuing experiments with Nix. My motivation for this was that previously I was using Ansible to provision the server, but then I’d ad hoc installed a bunch…

via Julia Evans January 1, 2024

I found some of my first code! Annotating and reflecting on robotics code from 2009.

In high school, one of my teachers shattered my plans for my life, in the most beautiful way. Most of my life, I'd intended to become a math professional of some sort: a math teacher, when that was all I saw math for; an actuary, when I started to lear…

via ntietz.com blog January 1, 2024

Generated by openring