Documentation
¶
Overview ¶
Package powersync provides background sync using PowerSync.
It takes a sqlite.DB, loads the PowerSync extension, and keeps the database in sync with the server via HTTP streaming.
You don't query through powersync - just use sqlite directly.
Subpackages:
- api: HTTP client for PowerSync service
- extension: SQLite extension interface and wire types
- db: Local database operations (CRUD queue, batch completion)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connecting ¶
type Connecting struct{}
Connecting means the syncer is establishing its first connection.
func NewConnecting ¶
func NewConnecting() *Connecting
type Disconnected ¶
type Disconnected struct{}
Disconnected means the syncer is not running.
func NewDisconnected ¶
func NewDisconnected() *Disconnected
type Error ¶
type Error struct {
Err error
}
Error means a fatal error occurred and syncing stopped.
type Reconnecting ¶
type Reconnecting struct {
Degraded bool
}
Reconnecting means the syncer lost its connection and is retrying. Degraded is true after repeated consecutive failures.
func NewReconnecting ¶
func NewReconnecting(degraded bool) *Reconnecting
type State ¶
type State interface {
// contains filtered or unexported methods
}
State represents the current syncer state. Use a type switch to handle each phase:
switch s := syncer.State().(type) {
case *powersync.Disconnected:
case *powersync.Connecting:
case *powersync.Syncing:
case *powersync.Ready:
case *powersync.Reconnecting:
case *powersync.Error:
}
type Syncer ¶
type Syncer interface {
Start(ctx context.Context, db sqlite.DB, accountID string, onFirstSync func()) error
Stop()
State() State
IsReady() bool
}
Syncer manages PowerSync synchronization.
func NewSyncer ¶
func NewSyncer(endpoint string, tokenRefresher TokenRefresher, scope log.Scope, opts ...SyncerOption) Syncer
NewSyncer creates a new Syncer. Call Start() when you have a database ready.
type SyncerOption ¶
type SyncerOption func(*syncer)
SyncerOption configures a Syncer.
func WithClientFactory ¶
func WithClientFactory(factory func(endpoint string) api.Client) SyncerOption
WithClientFactory sets a custom client factory (for testing).
type Syncing ¶
type Syncing struct {
Progress *Progress // nil until progress is known
}
Syncing means the syncer is actively downloading data.
func NewSyncing ¶
func NewSyncing() *Syncing
func (*Syncing) WithProgress ¶
type TokenRefresher ¶
type TokenRefresher interface {
GetAccessToken(ctx context.Context) (string, error)
// ForceRefreshAccessToken refreshes the token unconditionally, bypassing
// local expiration checks. Used when the server rejects a token the
// client still considers valid (e.g. clock skew).
ForceRefreshAccessToken(ctx context.Context) (string, error)
}
TokenRefresher provides access tokens for authentication.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package api provides HTTP client access to the PowerSync service.
|
Package api provides HTTP client access to the PowerSync service. |
|
apitest
Package apitest provides test doubles for the powersync/api package.
|
Package apitest provides test doubles for the powersync/api package. |
|
Package db provides PowerSync local database operations.
|
Package db provides PowerSync local database operations. |
|
dbtest
Package dbtest provides test utilities for the powersync/db package.
|
Package dbtest provides test utilities for the powersync/db package. |
|
Package extension provides the interface to the PowerSync SQLite extension.
|
Package extension provides the interface to the PowerSync SQLite extension. |
|
generate
command
Package main generates the PowerSync schema from the PowerSync service.
|
Package main generates the PowerSync schema from the PowerSync service. |
|
Package powersynctest provides test utilities for the powersync package.
|
Package powersynctest provides test utilities for the powersync package. |