PureQL.CSharp.Model.Graph.Neo4j.Insertion 0.1.0-preview.0.2.0

This is a prerelease version of PureQL.CSharp.Model.Graph.Neo4j.Insertion.
dotnet add package PureQL.CSharp.Model.Graph.Neo4j.Insertion --version 0.1.0-preview.0.2.0
                    
NuGet\Install-Package PureQL.CSharp.Model.Graph.Neo4j.Insertion -Version 0.1.0-preview.0.2.0
                    
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="PureQL.CSharp.Model.Graph.Neo4j.Insertion" Version="0.1.0-preview.0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PureQL.CSharp.Model.Graph.Neo4j.Insertion" Version="0.1.0-preview.0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="PureQL.CSharp.Model.Graph.Neo4j.Insertion" />
                    
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 PureQL.CSharp.Model.Graph.Neo4j.Insertion --version 0.1.0-preview.0.2.0
                    
#r "nuget: PureQL.CSharp.Model.Graph.Neo4j.Insertion, 0.1.0-preview.0.2.0"
                    
#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 PureQL.CSharp.Model.Graph.Neo4j.Insertion@0.1.0-preview.0.2.0
                    
#: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=PureQL.CSharp.Model.Graph.Neo4j.Insertion&version=0.1.0-preview.0.2.0&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=PureQL.CSharp.Model.Graph.Neo4j.Insertion&version=0.1.0-preview.0.2.0&prerelease
                    
Install as a Cake Tool

PureQL.CSharp.Model.Graph.Neo4j.Insertion

Writes a PureQL query to Neo4j as a property graph, in one statement.

.NET build & test Build and Deploy NuGet License: MIT

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
  • $nodes holds each node's labels (the record label, Node, and Query on the root) and props; property values pass through unchanged (strings, longs, booleans and arrays of them). Every node has queryId; the root also has id.
  • $rels holds each relationship's node indexes f and t, its type and, on a list item only, its position; a single child's relationship has no position.
  • Labels and relationship types are dynamic ($(...)), which needs Neo4j 5.26 or later (neo4j:5-community and neo4j:2025-community both 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 — InsertedQuery runs on any IAsyncQueryRunner, a session or a transaction
  • AOT-compatible — IsAotCompatible=true; no reflection

Dependencies

Target Frameworks

  • .NET 11

Installation

dotnet add package PureQL.CSharp.Model.Graph.Neo4j.Insertion
Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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 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