DuckDB.FSharp 0.1.6

dotnet add package DuckDB.FSharp --version 0.1.6
                    
NuGet\Install-Package DuckDB.FSharp -Version 0.1.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DuckDB.FSharp" Version="0.1.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DuckDB.FSharp" Version="0.1.6" />
                    
Directory.Packages.props
<PackageReference Include="DuckDB.FSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DuckDB.FSharp --version 0.1.6
                    
#r "nuget: DuckDB.FSharp, 0.1.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DuckDB.FSharp@0.1.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DuckDB.FSharp&version=0.1.6
                    
Install as a Cake Addin
#tool nuget:?package=DuckDB.FSharp&version=0.1.6
                    
Install as a Cake Tool

DuckDB.FSharp

Thin F#-friendly layer for DuckDB, inspired by Npgsql.FSharp.

Provides a functional, type-safe, and ergonomic API for working with DuckDB databases in F#, including connection management, parameterized queries, and flexible reader mappings.

Installation

dotnet add package DuckDB.FSharp

Quick Start

DuckDB connection strings are simple paths to a database file or :memory: for an in-memory database.

open DuckDB.FSharp

let connectionString = ":memory:"  // or "mydb.db" for a file-based database

connectionString
|> Sql.connect
|> Sql.query "SELECT 1 AS value"
|> Sql.execute (fun read -> read.int "value")

Usage Examples

Reading results as a list of records

type User = {
    Id: int
    Username: string
    Email: string option
}

let getUsers (connectionString: string) : List<User> =
    connectionString
    |> Sql.connect
    |> Sql.query "SELECT user_id, username, email FROM users"
    |> Sql.execute (fun read ->
        {
            Id = read.int "user_id"
            Username = read.text "username"
            Email = read.textOrNone "email"
        })

Asynchronous execution

let getUsersAsync (connectionString: string) : Async<List<User>> =
    connectionString
    |> Sql.connect
    |> Sql.query "SELECT user_id, username, email FROM users"
    |> Sql.executeAsync (fun read ->
        {
            Id = read.int "user_id"
            Username = read.text "username"
            Email = read.textOrNone "email"
        })

Parameterized queries

let getActiveUsers (connectionString: string) (isActive: bool) =
    connectionString
    |> Sql.connect
    |> Sql.query "SELECT * FROM users WHERE is_active = @isActive"
    |> Sql.parameters [ "@isActive", Sql.bool isActive ]
    |> Sql.execute (fun read ->
        {
            Id = read.int "user_id"
            Username = read.text "username"
            Email = read.textOrNone "email"
        })

Reading a single row (scalar values)

let getUserCount (connectionString: string) : int64 =
    connectionString
    |> Sql.connect
    |> Sql.query "SELECT COUNT(*) AS count FROM users"
    |> Sql.executeRow (fun read -> read.int64 "count")

Transactions (multiple statements)

connectionString
|> Sql.connect
|> Sql.executeTransaction [
    "INSERT INTO users (username, email) VALUES (@name1, @email1), (@name2, @email2)", [
        [ "@name1", Sql.text "alice" ; "@email1", Sql.text "alice@example.com" ]
        [ "@name2", Sql.text "bob"   ; "@email2", Sql.textOrNone None ]
    ]
    "UPDATE settings SET version = @version", [
        [ "@version", Sql.int 2 ]
    ]
]

Features

  • Pure functional pipeline style (inspired by Npgsql.FSharp)
  • Parameterized queries with type-safe parameter helpers
  • Support for nullable columns via textOrNone, intOrNone, etc.
  • Synchronous and asynchronous execution
  • Transaction support
  • Comprehensive unit tests covering connections, queries, parameters, readers, and edge cases

Status

.NET

Contributing

Contributions are welcome! Feel free to open issues or PRs on GitHub.

License

MIT License (see LICENSE file)

Support & Freelance

If DuckDB.FSharp is useful in your projects:

I'm also available for freelance F# work, especially data/analytics projects with DuckDB. Feel free to reach out on X: @typesmar

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.6 70 2/3/2026