# `NebulaGraphEx.Connection`
[🔗](https://github.com/VChain/nebula_graph_ex/blob/v0.1.10/lib/nebula_graph_ex/connection.ex#L1)

`DBConnection` behaviour implementation for NebulaGraph.

Each connection in the pool owns one TCP (or TLS) socket and one
authenticated NebulaGraph session. The session ID is held in the connection
state and is automatically reused for every query checked out from the pool.

You should not use this module directly — `NebulaGraphEx.Graph` is the
public interface. This module is documented for library developers who want
to understand the connection lifecycle or implement custom pool strategies.

## Connection lifecycle

1. `connect/1` — opens the socket, performs the version handshake, and
   authenticates to get a `session_id`.
2. `ping/1` — executes `YIELD 1` to keep the session alive. Called by
   `DBConnection` on idle connections at `:idle_interval`.
3. `handle_execute/4` — encodes and sends the query, decodes the response
   into `%NebulaGraphEx.Result{}`.
4. `disconnect/2` — signs out the session and closes the socket.

## Connection state

The state map held by DBConnection:

* `:socket` — the `:gen_tcp` or `:ssl` socket
* `:session_id` — integer NebulaGraph session ID
* `:opts` — resolved pool options from `NebulaGraphEx.Options`
* `:seq` — monotonically incrementing Thrift sequence number

---

*Consult [api-reference.md](api-reference.md) for complete listing*
