• Start

Languages

/

Mojo

/

Concepts

Multiple sessions

Open and manage independent server-side sessions with the Mojo SDK.

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.

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()

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.

Was this page helpful?