BitBadger.Documents.Postgres
4.0.0-rc4
See the version list below for details.
dotnet add package BitBadger.Documents.Postgres --version 4.0.0-rc4
NuGet\Install-Package BitBadger.Documents.Postgres -Version 4.0.0-rc4
<PackageReference Include="BitBadger.Documents.Postgres" Version="4.0.0-rc4" />
<PackageVersion Include="BitBadger.Documents.Postgres" Version="4.0.0-rc4" />
<PackageReference Include="BitBadger.Documents.Postgres" />
paket add BitBadger.Documents.Postgres --version 4.0.0-rc4
#r "nuget: BitBadger.Documents.Postgres, 4.0.0-rc4"
#:package BitBadger.Documents.Postgres@4.0.0-rc4
#addin nuget:?package=BitBadger.Documents.Postgres&version=4.0.0-rc4&prerelease
#tool nuget:?package=BitBadger.Documents.Postgres&version=4.0.0-rc4&prerelease
BitBadger.Documents.Postgres
This package provides a lightweight document library backed by PostgreSQL. It also provides streamlined functions for traditional ADO.NET functionality where relational data is required. Both C# and F# have first-class implementations.
Features
- Select, insert, update, save (upsert), delete, count, and check existence of documents, and create tables and indexes for these documents
- Address documents via ID, via comparison on any field, via equality on any property (using JSON containment, on a likely indexed field), or via condition on any property (using JSON Path queries)
- Access documents as your domain models (<abbr title="Plain Old CLR Objects">POCO</abbr>s)
- Use
Task-based async for all data access functions - Use building blocks for more complex queries
Getting Started
Once the package is installed, the library needs a data source. Construct an NpgsqlDataSource instance, and provide it to the library:
// C#
using BitBadger.Documents.Postgres;
//...
// Do not use "using" here; the library will handle disposing this instance
var data = new NpgsqlDataSourceBuilder("connection-string").Build();
Postgres.Configuration.UseDataSource(data);
// F#
open BitBadger.Documents.Postgres
// ...
// Do not use "use" here; the library will handle disposing this instance
let dataSource = // same as above ....
Configuration.useDataSource dataSource
// ...
By default, the library uses a System.Text.Json-based serializer configured to use the FSharp.SystemTextJson converter. To provide a different serializer (different options, more converters, etc.), construct it to implement IDocumentSerializer and provide it via Configuration.useSerializer. If custom serialization makes the serialized Id field not be Id, that will also need to be configured.
Using
Retrieve all customers:
// C#; parameter is table name
// Find.All type signature is Func<string, Task<List<TDoc>>>
var customers = await Find.All<Customer>("customer");
// F#
// Find.all type signature is string -> Task<'TDoc list>
let! customers = Find.all<Customer> "customer"
Select a customer by ID:
// C#; parameters are table name and ID
// Find.ById type signature is Func<string, TKey, Task<TDoc?>>
var customer = await Find.ById<string, Customer>("customer", "123");
// F#
// Find.byId type signature is string -> 'TKey -> Task<'TDoc option>
let! customer = Find.byId<string, Customer> "customer" "123"
(keys are treated as strings or numbers depending on their defintion; however, they are indexed as strings)
Count customers in Atlanta (using JSON containment):
// C#; parameters are table name and object for containment query
// Count.ByContains type signature is Func<string, TCriteria, int>
var customerCount = await Count.ByContains("customer", new { City = "Atlanta" });
// F#
// Count.byContains type signature is string -> 'TCriteria -> Task<int>
let! customerCount = Count.byContains "customer" {| City = "Atlanta" |}
Delete customers in Chicago: (no offense, Second City; just an example...)
// C#; parameters are table name and JSON Path expression
// Delete.ByJsonPath type signature is Func<string, string, Task>
await Delete.ByJsonPath("customer", "$.City ? (@ == \"Chicago\")");
// F#
// Delete.byJsonPath type signature is string -> string -> Task<unit>
do! Delete.byJsonPath "customer" """$.City ? (@ == "Chicago")"""
More Information
The project site has full details on how to use this library.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net6.0
- BitBadger.Documents.Common (>= 4.0.0-rc4)
- FSharp.Core (>= 8.0.300)
- Npgsql.FSharp (>= 5.7.0)
-
net8.0
- BitBadger.Documents.Common (>= 4.0.0-rc4)
- FSharp.Core (>= 8.0.300)
- Npgsql.FSharp (>= 5.7.0)
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 |
|---|---|---|
| 4.1.0 | 168 | 4/19/2025 |
| 4.0.1 | 170 | 12/30/2024 |
| 4.0.0 | 169 | 12/18/2024 |
| 4.0.0-rc5 | 149 | 9/18/2024 |
| 4.0.0-rc4 | 174 | 9/17/2024 |
| 4.0.0-rc3 | 176 | 8/23/2024 |
| 4.0.0-rc2 | 192 | 8/22/2024 |
| 4.0.0-rc1 | 167 | 8/19/2024 |
| 3.1.0 | 214 | 6/6/2024 |
| 3.0.0 | 192 | 4/21/2024 |
| 3.0.0-rc-2 | 301 | 1/24/2024 |
| 3.0.0-rc-1 | 214 | 12/31/2023 |
From rc3: Add In/InArray field comparisons, revamp internal comparison handling. From rc2: preserve additional ORDER BY qualifiers. From rc1: add case-insensitive ordering. From v3.1: Change ByField to ByFields; support dot-access to nested document fields; add Find*Ordered functions/methods; see project site for breaking changes and compatibility