PgDoc 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package PgDoc --version 1.0.4
                    
NuGet\Install-Package PgDoc -Version 1.0.4
                    
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="PgDoc" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PgDoc" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="PgDoc" />
                    
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 PgDoc --version 1.0.4
                    
#r "nuget: PgDoc, 1.0.4"
                    
#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 PgDoc@1.0.4
                    
#: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=PgDoc&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=PgDoc&version=1.0.4
                    
Install as a Cake Tool

PgDoc

PgDoc is a library for using PostgreSQL as a JSON document store.

Setup

Run the SQL script in src/PgDoc/SQL/pgdoc.sql to create the required table and functions in the database.

Document structure

Documents are stored in a single table with three columns:

  • body: The JSON document itself. It can be any valid JSON object, including nested objects and nested arrays. This is a jsonb column, and it is possible to query and index any nested field. This field is NULL if the document has been deleted.
  • id: The unique identifier of the document, of type uuid.
  • version: The version of the document. Any update must reference the current version of the document for the update to succeed. This ensures documents can be read by the application, and later updated in a safe fashion.

In C#, documents are represented by the Document class:

public class Document
{
    /// <summary>
    /// Gets the unique identifier of the document.
    /// </summary>
    public Guid Id { get; }

    /// <summary>
    /// Gets the JSON body of the document as a string, or null if the document does not exist.
    /// </summary>
    public string? Body { get; }

    /// <summary>
    /// Gets the current version of the document.
    /// </summary>
    public ByteString Version { get; }
}

Deleting and creating documents

Retrieving a documents that doesn't exist will return a document with the Body property set to null. This can be either because the document has never been created, or because it has been deleted.

In addition, the Version property of a document that has never been created is always set to ByteString.Empty.

PgDoc has no concept of inserting or deleting. They are both treated as an update.

Creating a new document is equivalent to updating a document from a null body to a non-null body. Deleting a document is equivalent to updating a document from a non-null body to a null body.

Usage

Initialize the document store

NpgsqlConnection databaseConnection = new NpgsqlConnection(connectionString);
IDocumentStore documentStore = new DocumentStore(databaseConnection);
await documentStore.Initialize();

Create a new document

Guid documentId = Guid.NewGuid();

Document newDocument = new Document(
    id: documentId,
    body: "{'key':'inital_value'}",
    version: ByteString.Empty);

await documentStore.UpdateDocuments(newDocument);

Retrieve a document

Document document = await documentStore.GetDocument(documentId);

Update a document

Document updatedDocument = new Document(
    id: document.Id,
    body: "{'key':'updated_value'}",
    version: document.Version);

await documentStore.UpdateDocuments(updatedDocument);

Delete a document

Document document = await documentStore.GetDocument(documentId);

Document deletedDocument = new Document(
    id: document.Id,
    body: null,
    version: document.Version);

await documentStore.UpdateDocuments(deletedDocument);

License

Copyright 2016 Flavien Charlon

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on PgDoc:

Package Downloads
PgDoc.Serialization

PgDoc.Serialization is a library for serializing .NET objects to JSON and store them into a PostgreSQL document store.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.0 687 6/7/2022
3.0.0 591 6/5/2022
2.1.1 842 6/4/2022
2.1.0 873 6/1/2022
2.0.1 618 5/27/2022
2.0.0 619 5/27/2022
2.0.0-alpha.2 247 5/27/2022
2.0.0-alpha.1 505 10/9/2021
1.2.2 747 10/7/2021
1.1.2 2,332 5/21/2019
1.1.1 1,009 5/19/2019
1.0.6 1,108 5/12/2019
1.0.5 1,418 1/31/2019
1.0.4 1,596 1/5/2019
1.0.3 1,252 12/28/2018
1.0.2 1,216 12/26/2018
1.0.1 2,684 12/8/2018
Loading failed