DuckDB.FSharp
0.1.6
dotnet add package DuckDB.FSharp --version 0.1.6
NuGet\Install-Package DuckDB.FSharp -Version 0.1.6
<PackageReference Include="DuckDB.FSharp" Version="0.1.6" />
<PackageVersion Include="DuckDB.FSharp" Version="0.1.6" />
<PackageReference Include="DuckDB.FSharp" />
paket add DuckDB.FSharp --version 0.1.6
#r "nuget: DuckDB.FSharp, 0.1.6"
#:package DuckDB.FSharp@0.1.6
#addin nuget:?package=DuckDB.FSharp&version=0.1.6
#tool nuget:?package=DuckDB.FSharp&version=0.1.6
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
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:
- ⭐ Star the repo to show support
- Consider sponsoring on GitHub ❤️
I'm also available for freelance F# work, especially data/analytics projects with DuckDB. Feel free to reach out on X: @typesmar
| Product | Versions 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. |
-
net10.0
- DuckDB.Net.Data.Full (>= 1.4.1)
- FSharp.Core (>= 10.0.102)
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 |