Follow these rules when writing application code that uses Arcadic. See the guides for workflows and Compatibility for dependencies and server requirements.
Bind values and validate identifiers
Keep statement text fixed. Bind Cypher values with $name and SQL values
with :name. When a database language requires an identifier in statement
text, validate it with Arcadic.Identifier.validate/1 and the application's
allowlist before using it. Use the library's helpers for import, export,
backup, and DDL.
# Correct
Arcadic.query(conn, "MATCH (u:User {name: $name}) RETURN u", %{"name" => name})
# Incorrect
Arcadic.query(conn, "MATCH (u:User {name: '#{name}'}) RETURN u")Choose the entry point by effect
Use Arcadic.query/4 to read and Arcadic.command/4 to write. Use
Arcadic.explain/4 to inspect a plan without executing it. Treat
Arcadic.profile/4 as execution. Treat Arcadic.command_async/4 success as
submission only.
# Correct
Arcadic.explain(conn, "CREATE (u:User {name: $name}) RETURN u", %{"name" => name})
# Incorrect: profiling executes the write
Arcadic.profile(conn, "CREATE (u:User {name: $name}) RETURN u", %{"name" => name})Keep transaction work on the session handle
Use the connection passed into the Arcadic.transaction/3 callback. Use
Arcadic.rollback/2 to abort intentionally. Retry only replayable callbacks
and reconcile uncertain writes before resubmitting them. Use the migrator's
recovery workflow for interrupted DDL.
# Correct
Arcadic.transaction(conn, fn tx -> Arcadic.command!(tx, statement, params) end)
# Incorrect: uses the outer connection
Arcadic.transaction(conn, fn _tx -> Arcadic.command!(conn, statement, params) end)Keep diagnostics value-free
Handle Arcadic.Error and Arcadic.TransportError using their structured
fields. Keep statements, parameters, credentials, rows, database names,
and quarantined error.detail out of logs and telemetry. Configure
authorization in the calling application.
# Correct
%{reason: error.reason, http_status: error.http_status}
# Incorrect
%{detail: error.detail, params: params}Follow the transport's streaming contract
Keep ordering and paging clauses out of HTTP streams. Consume a transaction cursor inside its callback. Choose the transport and timeout bounds from Connections and transports.
# Correct: Arcadic adds paging
Arcadic.query_stream(conn, "SELECT FROM User", %{}, language: "sql")
# Incorrect: contains its own paging clause
Arcadic.query_stream(conn, "SELECT FROM User LIMIT 100", %{}, language: "sql")Reconcile change feed gaps
Handle :reconnected and :overflow deliveries by reconciling with the
database. Reestablish a feed that stops on an authorization failure. See
Change delivery.
# Correct
case event.change_type do
type when type in [:reconnected, :overflow] -> reconcile_from_database()
_ -> apply_change(event)
end
# Incorrect: assumes gaps resolve through replay
if event.change_type == :update, do: apply_change(event)