Documentation
¶
Overview ¶
Package db provides PowerSync local database operations.
Index ¶
- Variables
- func CompleteBatch(ctx context.Context, db sqlite.DB, lastEntryID int64, checkpoint string) error
- func GetClientID(ctx context.Context, db sqlite.DB) (string, error)
- type CrudEntry
- type CrudQueue
- func (q *CrudQueue) CheckHealth(ctx context.Context) error
- func (q *CrudQueue) GetAllEntries(ctx context.Context) ([]*CrudEntry, error)
- func (q *CrudQueue) GetNextEntry(ctx context.Context) (*CrudEntry, error)
- func (q *CrudQueue) GetNextTransaction(ctx context.Context) ([]CrudEntry, error)
- func (q *CrudQueue) HasPendingUploads(ctx context.Context) (bool, error)
- type Op
Constants ¶
This section is empty.
Variables ¶
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 ¶
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.
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 ¶
NewCrudQueue creates a new CRUD queue accessor.
func (*CrudQueue) CheckHealth ¶
CheckHealth verifies the database is in a consistent state. Returns ErrDatabaseCorrupt if corruption is detected from a crash.
func (*CrudQueue) GetAllEntries ¶
GetAllEntries returns all pending CRUD entries in order.
func (*CrudQueue) GetNextEntry ¶
GetNextEntry returns the next CRUD entry to process, or nil if the queue is empty.
func (*CrudQueue) GetNextTransaction ¶
GetNextTransaction returns all CRUD entries for the next transaction. If entries exist without a transaction ID, returns just the first entry.