Skip to content
daz10000Public

About

FSharp Server - lightweight web server

Resources

Stars

19 stars

Watchers

9 watching

Forks

Repository files navigation

fss

CI NuGet fss_duckdb

Typed SQL for F# with no mapping code. Write SQL, get F# records back; hand it F# records and it inserts them. fss works with DuckDB, PostgreSQL and SQLite.

open Fss.Data.DuckDB

type Sale = { region : string ; product : string ; revenue : decimal }

use db = new DynamicSqlConnection("Data Source=:memory:")

// Query a Parquet file (or CSV, JSON, or a table) straight into records
let top =
    db.Query<Sale>("""
        select region, product, sum(qty * price) as revenue
        from 'sales/*.parquet'
        where region = $region
        group by all order by revenue desc limit 10""", [ "region", box "west" ])
    |> List.ofSeq

Packages

Package Database Driver Status
fss_duckdb DuckDB (in-process analytics) DuckDB.NET Primary.
fss_postgres PostgreSQL Npgsql Maintained
fss_sqlite SQLite Microsoft.Data.Sqlite Maintained
fss_mysql MySQL MySql.Data Retired (no new releases)
fss — — Legacy HTTP server and Jinja-style templates

The database packages are independent of each other and of fss. Reference only the one you need:

dotnet add package fss_duckdb

All packages target .NET 10.

What it does

  • Query to records: db.Query<'T>(sql) maps columns to record fields by name (case-insensitive). option fields take NULLs. It also maps to tuples (columns by position) and to single values (Query<int64> "select count(*) ...").
  • Insert records: db.InsertOne(record) and db.InsertMany(records) build the INSERT from the table's metadata and return the generated primary keys.
  • Parameters: pass [ "name", box value ] to Query, ExecuteScalar and ExecuteNonQuery. Never splice user input into SQL.
  • Transactions: use t = db.StartTrans() exposes the same API. Call t.Commit() to commit; disposing without committing rolls back.
  • Type conversion: handles the usual driver mismatches, such as SQLite's int64 → int/bool, DuckDB's HUGEINT → int64, DATE → DateOnly, text → F# enum, and uuid → Guid.
  • Pooling: each DynamicSqlConnection owns a small pool of connections and is safe to share between threads.

Documentation

Samples

Runnable projects live in samples/. The DuckDB samples are a good place to start:

dotnet run --project samples/DuckDbQuickStart
dotnet run --project samples/DuckDbAnalytics

Building from source

You need the .NET 10 SDK.

dotnet build fss.slnx
dotnet test  fss.slnx                      # DuckDB + SQLite tests always run
FSS_TEST_POSTGRES="Host=localhost;Username=postgres;Password=...;Database=fsstest" dotnet test fss.slnx

Postgres and MySQL tests are skipped unless FSS_TEST_POSTGRES / FSS_TEST_MYSQL are set. Contributors and maintainers should read MAINTAINERS.md.

License

Apache 2.0. See LICENSE.

About

FSharp Server - lightweight web server

Resources

Stars

19 stars

Watchers

9 watching

Forks

Releases

Packages

Used by

Contributors

Languages