Connecting
TheLarkDatabase class is your entry point. Pass your project, database, and auth details to the constructor and start using it immediately. The connection happens automatically.
Creating an instance
The constructor takes a path string in the formatprojectId/databaseId, and an options object:
Options
All connection configuration is passed as the second argument to the constructor:You must provide either
anonymous: true or a token. If you pass both, the token takes priority.Self-hosting Lark? Set
domain to your own host instead of the default larkdb.net. See Open source.Waiting for the connection
If you need to confirm the connection is established before proceeding, you can optionally callawait db.connect():
await db.connect() when you need to gate logic on a confirmed connection (e.g., showing a “connected” indicator, or failing fast if the server is unreachable).
Transport selection
The SDK uses WebSocket by default. To opt in to WebTransport, settransport to 'auto' or 'webtransport':
Connection states
A connection moves through these states in order:Properties
Once connected, several properties are available on thedb instance:
Lifecycle events
Use callback methods to react to connection state changes:Disconnecting
There are two ways to take a connection offline, and they behave differently:disconnect()
Fully tears down the connection. Clears all cached data, removes all subscriptions, and resets the client. Use this when you’re done with the database entirely.
goOffline()
Pauses the connection but preserves your local cache and subscription registrations. When you call goOnline() later, subscriptions are re-established and you pick up where you left off.

