theHarmonicAlgorithm-3.1.0: Real-time harmonic progression generation for TidalCycles live performance
Safe HaskellNone
LanguageGHC2021

Harmonic.Database

Description

The single place the codebase talks to Neo4j. Queries go over the modern HTTP endpoint (POST /db/neo4j/query/v2, Neo4j 5.23+/2025.x), which replaced both the Bolt binary protocol dependency and the deprecated tx/commit HTTP API. HTTP keep-alive pooling in the shared Manager plays the role a long-lived Bolt pipe used to: one DbConn serves a whole generation run, including the full K-attempt loop under attempt N K.

Why not Bolt: the last maintained Haskell Bolt driver speaks protocol 3.0 only, which Neo4j 5 removed — it pinned this project to the EOL Neo4j 4.4. The HTTP endpoint is perf-neutral here (measured ~7.5ms vs ~10ms per generation step on the hottest node, including JSON parsing).

Rows come back as Map Text Aeson.Value — the same field-keyed shape the old driver produced — so query-site parsing stays a lookup plus a pattern match.

Synopsis

Connection

data DbConn Source #

An open connection to Neo4j: a keep-alive HTTP manager plus the pre-built request template (endpoint URL and auth header).

connectNeo4j :: IO DbConn Source #

Connect to the local Neo4j from Harmonic.Config (override with the HA_NEO4J_URL environment variable, e.g. http://localhost:7477 to point a REPL at a scratch container). Probes the server with RETURN 1 so an unreachable database surfaces the error here, at connect time — matching what every online generation path expects.

connectNeo4jAt :: String -> IO DbConn Source #

connectNeo4j against an explicit base URL (no trailing slash).

Running actions

type DbActionT = ReaderT DbConn IO Source #

Database actions, threaded over a DbConn. Run with runDb. ReaderT keeps call sites shaped exactly like the old Bolt action monad: query functions compose in the same do-blocks and liftIO works as before.

runDb :: DbConn -> DbActionT a -> IO a Source #

Run a database action against a connection.

Queries

runQuery :: Text -> DbActionT [Map Text Value] Source #

Run a Cypher query with no parameters.

runQueryP :: Text -> Map Text Value -> DbActionT [Map Text Value] Source #

Run a Cypher query with parameters. Each result row is keyed by the RETURN field names. Server-side errors (Cypher failures, auth) are thrown as IOErrors carrying the Neo4j error message.