A session is an independent, server-side context for authentication and session variables. Over a stateful WebSocket connection, the Mojo SDK can open several sessions on a single connection and address each one separately.
Sessions are a stateful feature provided by the WebSocket transport. WebSocket support is rolling out. On the HTTP transport, the engine reports sessions=False and the SDK raises an UnsupportedFeatureError.
Opening a session
new_session() attaches a new session and returns a handle scoped to it. The handle exposes use(), query(), set_string(), unset(), begin_transaction(), and close_session().
var session = client.new_session()
session.use("test", "test")
var resp = session.query("SELECT * FROM person;")
session.close_session()Attaching and detaching
For lower-level control, attach() returns a session id you can pass to other calls, and detach() releases it.
var session_id = client.attach()
var resp = client.query("SELECT * FROM person;", session=Optional(session_id))
client.detach(session_id)sessions() lists the active sessions on the connection.
Most calls on the client, including query, create, and the auth methods, accept an optional session argument so you can target a specific session without a handle.