db

package
v1.15.0 Latest Latest
Warning

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

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

Documentation

Overview

Package db provides PowerSync local database operations.

Index

Constants

This section is empty.

Variables

View Source
var ErrDatabaseCorrupt = fmt.Errorf("database corrupt")

ErrDatabaseCorrupt indicates the database is in an inconsistent state from a crash during migration or write. The database should be deleted and re-synced from the server.

Functions

func CompleteBatch

func CompleteBatch(ctx context.Context, db sqlite.DB, lastEntryID int64, checkpoint string) error

CompleteBatch finalizes a CRUD upload by atomically: 1. Deleting uploaded entries from ps_crud 2. Setting target_op to the write checkpoint

This must be called after uploading entries and fetching a write checkpoint from the server. The checkpoint signals to sync that uploads are complete.

func GetClientID

func GetClientID(ctx context.Context, db sqlite.DB) (string, error)

GetClientID returns the PowerSync client ID for this database. This ID is used when fetching write checkpoints from the server.

Types

type CrudEntry

type CrudEntry struct {
	// ID is the auto-incrementing client-side id.
	ID int64
	// TxID is the transaction id. All operations in the same transaction share this.
	TxID *int64
	// Op is the operation type: PUT, PATCH, or DELETE.
	Op Op
	// Table is the table name.
	Table sqlite.Table
	// RowID is the ID of the affected row.
	RowID string
	// Data contains the row data (for PUT/PATCH operations).
	Data map[string]any
	// Old contains previous values (for tables with trackPreviousValues enabled).
	Old map[string]any
	// Metadata contains client-side metadata (if trackMetadata was enabled).
	Metadata *string
}

CrudEntry represents a single entry in the ps_crud upload queue.

type CrudQueue

type CrudQueue struct {
	// contains filtered or unexported fields
}

CrudQueue provides access to the PowerSync CRUD upload queue.

func NewCrudQueue

func NewCrudQueue(db sqlite.DB) *CrudQueue

NewCrudQueue creates a new CRUD queue accessor.

func (*CrudQueue) CheckHealth

func (q *CrudQueue) CheckHealth(ctx context.Context) error

CheckHealth verifies the database is in a consistent state. Returns ErrDatabaseCorrupt if corruption is detected from a crash.

func (*CrudQueue) GetAllEntries

func (q *CrudQueue) GetAllEntries(ctx context.Context) ([]*CrudEntry, error)

GetAllEntries returns all pending CRUD entries in order.

func (*CrudQueue) GetNextEntry

func (q *CrudQueue) GetNextEntry(ctx context.Context) (*CrudEntry, error)

GetNextEntry returns the next CRUD entry to process, or nil if the queue is empty.

func (*CrudQueue) GetNextTransaction

func (q *CrudQueue) GetNextTransaction(ctx context.Context) ([]CrudEntry, error)

GetNextTransaction returns all CRUD entries for the next transaction. If entries exist without a transaction ID, returns just the first entry.

func (*CrudQueue) HasPendingUploads

func (q *CrudQueue) HasPendingUploads(ctx context.Context) (bool, error)

HasPendingUploads returns true if there are entries waiting to be uploaded.

type Op

type Op string

Op represents a CRUD operation type.

const (
	OpPut    Op = "PUT"    // Insert or replace
	OpPatch  Op = "PATCH"  // Update
	OpDelete Op = "DELETE" // Delete
)

CRUD operation types.

Directories

Path Synopsis
Package dbtest provides test utilities for the powersync/db package.
Package dbtest provides test utilities for the powersync/db package.

Jump to

Keyboard shortcuts

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