PostgreSQL storage implementation for the Pure relational schema ecosystem — creates schemas, manages tables, and reads/writes rows via IDbConnection.
Pure.RelationalSchema.Storage.PostgreSQL bridges the abstract relational model defined in Pure.RelationalSchema with a live PostgreSQL database. It provides:
- DDL execution —
PostgreSqlCreatedSchemalazily generates and executesCREATE SCHEMA,CREATE TABLE,CREATE INDEX, andALTER TABLE … ADD CONSTRAINTstatements derived from anISchema. - Row access —
PostgreSqlStoredTableDataSetexposes table rows as bothIQueryable<IRow>andIAsyncEnumerable<IRow>viaSELECT *queries. - Row insertion —
PostgreSqlStoredSchemaDataSetWithInsertedRows/PostgreSqlStoredTableDataSetWithInsertedDataexecuteINSERT INTOstatements and surface the inserted rows alongside existing ones.
Schema and table identifiers are derived from hash codes (via Pure.RelationalSchema.HashCodes) to avoid name-length and special-character constraints in PostgreSQL.
| Type | Kind | Description |
|---|---|---|
IPostgreSqlStoredSchemaDataSet | interface | Extends IStoredSchemaDataSet with an IDbConnection Connection property |
PostgreSqlStoredSchemaDataSet | record | Maps each ITable in an ISchema to a PostgreSqlStoredTableDataSet; implements IPostgreSqlStoredSchemaDataSet |
PostgreSqlStoredSchemaDataSetWithInsertedRows | record | Wraps an IPostgreSqlStoredSchemaDataSet and inserts grouped IRow data into the corresponding table datasets |
PostgreSqlCreatedSchema | record | ISchema decorator that executes DDL lazily on first property access |
PostgreSqlStoredTableDataSet | record | IStoredTableDataSet backed by a PostgreSQL table; supports sync and async enumeration |
PostgreSqlStoredTableDataSetWithInsertedData | record | Wraps a table dataset and inserts rows on first enumeration |
PostgreSqlColumnTypeName | class | Maps Pure schema column types to PostgreSQL type name strings |
Pure.RelationalSchema.Storage— storage abstractions (IStoredSchemaDataSet,IStoredTableDataSet,IRow) that this package implementsPure.RelationalSchema— core relational model abstractions:ISchema,ITable,IForeignKey, and related typesPure.RelationalSchema.HashCodes— hash code derivation for schema/table/column identifiers used as PostgreSQL object namesPure.RelationalSchema.Storage.HashCodes— hash codes for storage-layer typesPure.Primitives.Abstractions— base interfaces for primitive types (IString,IBool,INumber, etc.)Pure.Primitives— concrete primitive type implementationsPure.Primitives.String.Operations— string composition utilities (JoinedString,ConcatenatedString,WrappedString, etc.) used to build SQL statementsPure.Primitives.Choices— discriminated union / choice typesPure.Primitives.Switches— switch / pattern matching utilitiesPure.Collections.Generic— generic collection implementations (e.g.Dictionary<TKey1, TKey2, TValue>with dual-key lookup)
- .NET 8
- .NET 9
- .NET 10
dotnet add package Pure.RelationalSchema.Storage.PostgreSQL
usingSystem.Data;usingNpgsql;usingPure.RelationalSchema.Storage.PostgreSQL;// schema is your ISchema; connection is an open IDbConnectionIDbConnectionconnection=newNpgsqlConnection(connectionString);connection.Open();// Execute DDL lazily on first accessISchemacreatedSchema=newPostgreSqlCreatedSchema(schema,connection);// Build a dataset backed by the created schemaIPostgreSqlStoredSchemaDataSetdataset=newPostgreSqlStoredSchemaDataSet(createdSchema,connection);// Read rows asynchronously from a tableIStoredTableDataSettableDataset=dataset[myTable];awaitforeach(IRowrowintableDataset){objectvalue=row.Cells[myColumn].Value;}// Insert rows grouped by tableIEnumerable<IGrouping<ITable,IRow>>rowGroups=rows.GroupBy(r =>r.Table);IPostgreSqlStoredSchemaDataSetwithInserted=newPostgreSqlStoredSchemaDataSetWithInsertedRows(dataset,rowGroups);