PureQL.CSharp.Model.Graph.Neo4j.Insertion
0.1.0-preview.0.1.0
See the version list below for details.
dotnet add package PureQL.CSharp.Model.Graph.Neo4j.Insertion --version 0.1.0-preview.0.1.0
NuGet\Install-Package PureQL.CSharp.Model.Graph.Neo4j.Insertion -Version 0.1.0-preview.0.1.0
<PackageReference Include="PureQL.CSharp.Model.Graph.Neo4j.Insertion" Version="0.1.0-preview.0.1.0" />
<PackageVersion Include="PureQL.CSharp.Model.Graph.Neo4j.Insertion" Version="0.1.0-preview.0.1.0" />
<PackageReference Include="PureQL.CSharp.Model.Graph.Neo4j.Insertion" />
paket add PureQL.CSharp.Model.Graph.Neo4j.Insertion --version 0.1.0-preview.0.1.0
#r "nuget: PureQL.CSharp.Model.Graph.Neo4j.Insertion, 0.1.0-preview.0.1.0"
#:package PureQL.CSharp.Model.Graph.Neo4j.Insertion@0.1.0-preview.0.1.0
#addin nuget:?package=PureQL.CSharp.Model.Graph.Neo4j.Insertion&version=0.1.0-preview.0.1.0&prerelease
#tool nuget:?package=PureQL.CSharp.Model.Graph.Neo4j.Insertion&version=0.1.0-preview.0.1.0&prerelease
PureQL.CSharp.Model.Graph.Neo4j.Insertion
Writes a PureQL query to Neo4j as a property graph, in one statement.
Overview
PureQL.CSharp.Model.Graph.Neo4j.Insertion is the insertion package of the PureQL.CSharp.Model.Graph family. It turns the QueryGraph that PureQL.CSharp.Model.Graph builds for a query into a single Cypher statement that creates every node and every relationship of the query at once.
Public API
Namespace PureQL.CSharp.Model.Graph.Neo4j.Insertion:
| Name | Description |
|---|---|
InsertStatement |
sealed record InsertStatement(QueryGraph Graph); Value is the Neo4j.Driver.Query that writes the graph |
InsertedQuery |
sealed record InsertedQuery(IAsyncQueryRunner Runner, StoredQuery Query); ApplyAsync writes the query on a session or transaction you own |
InsertedQueryOf |
sealed record InsertedQueryOf(INeo4jStoredQueries Store, StoredQuery Query); ApplyAsync opens a session on the store and writes the query in a managed write transaction |
Usage
using Neo4j.Driver;
using PureQL.CSharp.Model;
using PureQL.CSharp.Model.Graph.Neo4j.Abstractions;
using PureQL.CSharp.Model.Graph.Neo4j.Insertion;
await using IDriver driver = GraphDatabase.Driver(
"neo4j://localhost:7687",
AuthTokens.Basic("neo4j", "password")
);
INeo4jStoredQueries store = new Neo4jStoredQueries(driver);
PureQLQuery query = /* any PureQL query */;
StoredQuery stored = new StoredQuery(Guid.NewGuid(), query);
// In a transaction of its own:
await new InsertedQueryOf(store, stored).ApplyAsync();
// Or together with other operations, in your transaction:
await using IAsyncSession session = driver.AsyncSession(
builder => builder.WithDatabase(store.Database)
);
await session.ExecuteWriteAsync(
async transaction =>
{
await new InsertedQuery(transaction, new StoredQuery(Guid.NewGuid(), query))
.ApplyAsync();
// ...other operations on the same transaction
}
);
How a query is written
QueryGraphs.Of(query, id) from PureQL.CSharp.Model.Graph gives the nodes and relationships of the query. InsertStatement writes them in one statement:
UNWIND $nodes AS n
CREATE (x:$(n.labels))
SET x = n.props
WITH collect(x) AS xs
UNWIND $rels AS r
WITH xs[r.f] AS a, xs[r.t] AS b, r
CREATE (a)-[e:$(r.type)]->(b)
SET e.position = r.position
$nodesholds each node'slabels(the record label,Node, andQueryon the root) andprops; property values pass through unchanged (strings, longs, booleans and arrays of them). Every node hasqueryId; the root also hasid.$relsholds each relationship's node indexesfandt, itstypeand, on a list item only, itsposition; a single child's relationship has noposition.- Labels and relationship types are dynamic (
$(...)), which needs Neo4j 5.26 or later (neo4j:5-communityandneo4j:2025-communityboth work).
Duplicate ids
Inserting only creates; it never replaces a stored query (the Updating package does). When the uniqueness constraint on Query.id exists (the Creation package creates it as pureql_query_id), inserting an id that is already stored fails with the driver's Neo4j.Driver.ClientException whose Code is Neo.ClientError.Schema.ConstraintValidationFailed, and nothing is written. The exception is not wrapped. Without the constraint, a second copy is written.
Cancellation
Neo4j.Driver 6.x takes no cancellation token for a running statement, so ApplyAsync checks its token before it sends the statement.
Design Principles
- Sealed records with their dependencies in the constructor; no static services
- Composable —
InsertedQueryruns on anyIAsyncQueryRunner, a session or a transaction - AOT-compatible —
IsAotCompatible=true; no reflection
Dependencies
PureQL.CSharp.Model.Graph0.1.0-preview.1.0.0—QueryGraphs,QueryGraphPureQL.CSharp.Model.Graph.Neo4j.Abstractions0.1.0-preview.1.0.0—INeo4jStoredQueries,StoredQueryNeo4j.Driver6.5.1
Target Frameworks
- .NET 11
Installation
dotnet add package PureQL.CSharp.Model.Graph.Neo4j.Insertion
Related packages
PureQL.CSharp.Model.Graph— maps aPureQLQueryto a property graph and back, without a driverPureQL.CSharp.Model.Graph.Neo4j.Abstractions— the stored-queries contract the Neo4j packages sharePureQL.CSharp.Model.Graph.Neo4j.Creation— constraints and indexesPureQL.CSharp.Model.Graph.Neo4j.Querying— reads queries backPureQL.CSharp.Model.Graph.Neo4j.Deletion— deletes queriesPureQL.CSharp.Model.Graph.Neo4j.Updating— replaces a query in one transactionPureQL.CSharp.Model.Graph.Neo4j.Existence— checks the schema and queries existPureQL.CSharp.Model.Graph.Neo4j.Destruction— drops the schema and every stored queryPureQL.CSharp.Model.Graph.Neo4j.Migration— migrates stored graphs between model versionsPureQL.CSharp.Model.Serialization— JSON for the same model
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Neo4j.Driver (>= 6.5.1)
- PureQL.CSharp.Model.Graph (>= 0.1.0-preview.1.0.0)
- PureQL.CSharp.Model.Graph.Neo4j.Abstractions (>= 0.1.0-preview.1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on PureQL.CSharp.Model.Graph.Neo4j.Insertion:
| Package | Downloads |
|---|---|
|
PureQL.CSharp.Model.Graph.Neo4j.Updating
Replaces a stored PureQL query graph in Neo4j in one transaction. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-preview.0.2.0 | 95 | 11/11/2026 |
| 0.1.0-preview.0.1.0 | 88 | 11/9/2026 |