Pure.RelationalSchema.Storage.PostgreSQL.Insertion
0.1.0-preview.0.1.1
dotnet add package Pure.RelationalSchema.Storage.PostgreSQL.Insertion --version 0.1.0-preview.0.1.1
NuGet\Install-Package Pure.RelationalSchema.Storage.PostgreSQL.Insertion -Version 0.1.0-preview.0.1.1
<PackageReference Include="Pure.RelationalSchema.Storage.PostgreSQL.Insertion" Version="0.1.0-preview.0.1.1" />
<PackageVersion Include="Pure.RelationalSchema.Storage.PostgreSQL.Insertion" Version="0.1.0-preview.0.1.1" />
<PackageReference Include="Pure.RelationalSchema.Storage.PostgreSQL.Insertion" />
paket add Pure.RelationalSchema.Storage.PostgreSQL.Insertion --version 0.1.0-preview.0.1.1
#r "nuget: Pure.RelationalSchema.Storage.PostgreSQL.Insertion, 0.1.0-preview.0.1.1"
#:package Pure.RelationalSchema.Storage.PostgreSQL.Insertion@0.1.0-preview.0.1.1
#addin nuget:?package=Pure.RelationalSchema.Storage.PostgreSQL.Insertion&version=0.1.0-preview.0.1.1&prerelease
#tool nuget:?package=Pure.RelationalSchema.Storage.PostgreSQL.Insertion&version=0.1.0-preview.0.1.1&prerelease
Pure.RelationalSchema.Storage.PostgreSQL.Insertion
PostgreSQL row insertion for the Pure relational schema ecosystem — de-duplicating INSERT decorators over Pure.RelationalSchema.Storage.PostgreSQL.Querying datasets.
Overview
Pure.RelationalSchema.Storage.PostgreSQL.Insertion writes rows into a live PostgreSQL database through the storage abstractions defined in Pure.RelationalSchema.Storage. PostgreSqlStoredSchemaDataSetWithInsertedRows wraps any IPostgreSqlStoredSchemaDataSet (the usual implementation is PostgreSqlStoredSchemaDataSet from Pure.RelationalSchema.Storage.PostgreSQL.Querying) and a set of rows grouped by table. The INSERT INTO statement is executed lazily, the first time a table dataset of the result is accessed. Before inserting, it:
- skips rows that are duplicates within the supplied batch, and
- skips rows that already exist in the table (compared by
RowHash).
It then exposes the wrapped dataset, so the inserted rows can be read back through the same IStoredTableDataSet. Wrapping the result again with the same rows inserts nothing new.
The result exposes only the tables present in the supplied groupings, not every table of the wrapped dataset.
This package covers writes only. Creating the tables and reading rows are handled by the related packages listed below. The tables must already exist with the hash-based names produced by Pure.RelationalSchema.Storage.PostgreSQL.Creation. Schema, table and column identifiers are the first 63 hexadecimal characters of the hashes from Pure.RelationalSchema.HashCodes, not the model names. The caller owns the IDbConnection: it must be opened before use, and this package never disposes it.
Public API
| Type | Kind | Description |
|---|---|---|
PostgreSqlStoredSchemaDataSetWithInsertedRows |
record | Wraps an IPostgreSqlStoredSchemaDataSet and inserts grouped IRow data into the corresponding table datasets, skipping duplicate and already-stored rows; implements IPostgreSqlStoredSchemaDataSet |
The constructor takes any IPostgreSqlStoredSchemaDataSet. The table-level decorator, InsertStatement and the hashing helpers are internal. IPostgreSqlStoredSchemaDataSet comes from Pure.RelationalSchema.Storage.PostgreSQL.Abstractions; this package does not depend on Querying or Creation.
Dependencies
Pure.RelationalSchema.Storage.PostgreSQL.Abstractions— providesIPostgreSqlStoredSchemaDataSet; the wrapped dataset is re-read to skip rows that already existPure.RelationalSchema.Storage— storage abstractions (IStoredSchemaDataSet,IStoredTableDataSet,IRow) that this package implementsPure.RelationalSchema.Storage.HashCodes—RowHash, used to detect duplicate and existing rowsPure.RelationalSchema.HashCodes— hash codes used to derive PostgreSQL object namesPure.Primitives.Abstractions— base interfaces for primitive types (IString,IBool, etc.)Pure.Primitives— concrete primitive type implementationsPure.Primitives.String.Operations— string composition utilities used to build SQL statementsPure.Collections.Generic— generic collection implementations (e.g.OrderedDictionaryandDictionary<TKey1, TKey2, TValue>with dual-key lookup)
Target Frameworks
- .NET 8
- .NET 9
- .NET 10
Installation
dotnet add package Pure.RelationalSchema.Storage.PostgreSQL.Insertion
This package does not create tables or read rows itself. The example below also uses Pure.RelationalSchema.Storage.PostgreSQL.Creation to create the tables and Pure.RelationalSchema.Storage.PostgreSQL.Querying for the wrapped dataset; neither is a dependency of this package.
Usage
using System.Data;
using Npgsql;
using Pure.Collections.Generic;
using Pure.RelationalSchema.Abstractions.Column;
using Pure.RelationalSchema.Abstractions.Schema;
using Pure.RelationalSchema.Abstractions.Table;
using Pure.RelationalSchema.ColumnType;
using Pure.RelationalSchema.HashCodes;
using Pure.RelationalSchema.Storage;
using Pure.RelationalSchema.Storage.Abstractions;
using Pure.RelationalSchema.Storage.PostgreSQL.Abstractions;
using Pure.RelationalSchema.Storage.PostgreSQL.Creation;
using Pure.RelationalSchema.Storage.PostgreSQL.Insertion;
using Pure.RelationalSchema.Storage.PostgreSQL.Querying;
using Column = Pure.RelationalSchema.Column.Column;
using Schema = Pure.RelationalSchema.Schema.Schema;
using String = Pure.Primitives.String.String;
using Table = Pure.RelationalSchema.Table.Table;
IDbConnection connection = new NpgsqlConnection(connectionString);
connection.Open();
IColumn idColumn = new Column(new String("Id"), new IntColumnType());
IColumn nameColumn = new Column(new String("Name"), new StringColumnType());
ITable usersTable = new Table(new String("Users"), [idColumn, nameColumn], []);
ISchema schema = new Schema(new String("Shop"), [usersTable], []);
ISchema createdSchema = new PostgreSqlCreatedSchema(schema, connection);
_ = createdSchema.Tables.ToArray();
IPostgreSqlStoredSchemaDataSet dataSet =
new PostgreSqlStoredSchemaDataSet(createdSchema, connection);
IRow alice = new Row(
new Dictionary<IColumn, IColumn, ICell>(
[idColumn, nameColumn],
column => column,
column =>
column == idColumn
? new Cell(new String("1"))
: new Cell(new String("Alice")),
column => new ColumnHash(column)
)
);
// Rows are supplied grouped by table. LINQ's GroupBy cannot be used here: it hashes
// the key, and ITable implementations do not support GetHashCode.
IEnumerable<IGrouping<ITable, IRow>> rows = [new TableRows(usersTable, [alice])];
IPostgreSqlStoredSchemaDataSet withInserted =
new PostgreSqlStoredSchemaDataSetWithInsertedRows(dataSet, rows);
foreach (IRow row in withInserted[usersTable])
{
Console.WriteLine(row.Cells[nameColumn].Value.TextValue);
}
internal sealed class TableRows : IGrouping<ITable, IRow>
{
private readonly IEnumerable<IRow> _rows;
public TableRows(ITable key, IEnumerable<IRow> rows)
{
Key = key;
_rows = rows;
}
public ITable Key { get; }
public IEnumerator<IRow> GetEnumerator()
{
return _rows.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
GroupBy cannot be used to group the rows: it hashes the key, and ITable implementations do not support GetHashCode, so supply your own IGrouping<ITable, IRow> as above. Every cell value is an IString.
How values are written
Every cell value is written into the INSERT statement as an escaped string literal (E'...', with backslashes and single quotes doubled), so a value cannot end the literal or change the statement. PostgreSQL then converts the literal to the column's type, so a value that does not convert (for example abc for an integer column) makes the insert fail.
Related packages
Pure.RelationalSchema.Storage.PostgreSQL.Creation— creates the schema and tables this package writes toPure.RelationalSchema.Storage.PostgreSQL.Querying— reads rows from those tables;PostgreSqlStoredSchemaDataSetis the usual dataset to wrapPure.RelationalSchema.Storage.PostgreSQL.Abstractions— providesIPostgreSqlStoredSchemaDataSet
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 is compatible. 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 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
- Pure.Collections.Generic (>= 0.1.0-preview.3.0.0)
- Pure.Primitives (>= 3.6.5)
- Pure.Primitives.Abstractions (>= 4.3.0)
- Pure.Primitives.String.Operations (>= 1.5.1)
- Pure.RelationalSchema.HashCodes (>= 3.3.0)
- Pure.RelationalSchema.Storage (>= 0.1.0-preview.8.0.0)
- Pure.RelationalSchema.Storage.HashCodes (>= 0.1.0-preview.2.2.0)
- Pure.RelationalSchema.Storage.PostgreSQL.Abstractions (>= 0.1.0-preview.0.1.0)
-
net8.0
- Pure.Collections.Generic (>= 0.1.0-preview.3.0.0)
- Pure.Primitives (>= 3.6.5)
- Pure.Primitives.Abstractions (>= 4.3.0)
- Pure.Primitives.String.Operations (>= 1.5.1)
- Pure.RelationalSchema.HashCodes (>= 3.3.0)
- Pure.RelationalSchema.Storage (>= 0.1.0-preview.8.0.0)
- Pure.RelationalSchema.Storage.HashCodes (>= 0.1.0-preview.2.2.0)
- Pure.RelationalSchema.Storage.PostgreSQL.Abstractions (>= 0.1.0-preview.0.1.0)
-
net9.0
- Pure.Collections.Generic (>= 0.1.0-preview.3.0.0)
- Pure.Primitives (>= 3.6.5)
- Pure.Primitives.Abstractions (>= 4.3.0)
- Pure.Primitives.String.Operations (>= 1.5.1)
- Pure.RelationalSchema.HashCodes (>= 3.3.0)
- Pure.RelationalSchema.Storage (>= 0.1.0-preview.8.0.0)
- Pure.RelationalSchema.Storage.HashCodes (>= 0.1.0-preview.2.2.0)
- Pure.RelationalSchema.Storage.PostgreSQL.Abstractions (>= 0.1.0-preview.0.1.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Pure.RelationalSchema.Storage.PostgreSQL.Insertion:
| Package | Downloads |
|---|---|
|
Pure.RelationalSchema.Storage.PostgreSQL
Meta-package that references the Abstractions, Creation, Querying and Insertion packages of the Pure relational schema PostgreSQL storage. It contains no code. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-preview.0.1.1 | 36 | 10/16/2026 |
| 0.1.0-preview.0.1.0 | 68 | 10/15/2026 |