Skip to main content
The LarkDatabase class is the main entry point for interacting with a Lark database. It manages the connection lifecycle, authentication, and provides access to database references.

Constructor

Creates a new LarkDatabase instance.

LarkDatabaseOptions

You must provide either anonymous: true or a token. If you pass both, the token takes priority.

Properties

AuthInfo

Methods

connect

Opens a connection to the Lark server using the options passed to the constructor. Resolves when the connection is fully established and authenticated.

disconnect

Closes the connection to the server. Resolves when the connection is fully closed.

ref

Returns a DatabaseReference pointing to the specified path in the database. If no path is provided, returns a reference to the root.

signIn

Authenticates the client with the given token. Resolves when authentication succeeds.

signOut

Signs out the current user and reverts to unauthenticated access.

transaction

Executes a batch of operations atomically. All operations succeed or all fail together.

goOffline

Manually disconnects the client and disables automatic reconnection. Pending writes are preserved.

goOnline

Re-enables the connection after a goOffline() call. The client will attempt to reconnect and flush any pending writes.

hasPendingWrites

Returns true if there are writes that have not yet been acknowledged by the server.

getPendingWriteCount

Returns the number of write operations that have not yet been acknowledged by the server.

clearPendingWrites

Discards all pending writes that have not been sent to the server. Use with caution, because discarded writes cannot be recovered.
This permanently drops any unsent writes. Only use this if you intentionally want to discard local changes.

Event Methods

All event methods return an unsubscribe function. Call it to stop listening.

onConnect

Registers a listener that fires when the client establishes a connection.

onDisconnect

Registers a listener that fires when the client loses its connection.

onReconnecting

Registers a listener that fires when the client begins a reconnection attempt.

onError

Registers a listener that fires when a connection-level error occurs.

onAuthStateChanged

Registers a listener that fires when the authentication state changes: on sign-in, sign-out, or token refresh.