powersync

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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.

func NewError

func NewError(err error) *Error

type Progress

type Progress struct {
	Downloaded int
	Total      int
}

Progress represents download progress.

func (*Progress) String

func (p *Progress) String() string

String returns a human-readable progress string like "50/100".

type Ready

type Ready struct{}

Ready means the initial sync is complete and data is fresh.

func NewReady

func NewReady() *Ready

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

func (s *Syncing) WithProgress(downloaded, total int) *Syncing

type TokenRefresher

type TokenRefresher interface {
	GetAccessToken(ctx context.Context) (string, error)
}

TokenRefresher provides access tokens for authentication.

Directories

Path Synopsis
api
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.
db
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL