Documentation
¶
Overview ¶
Package sqlite provides the local SQLite database for the CLI. This is the primary data layer - PowerSync keeps it in sync with the server, but you query it directly like any SQLite database.
Package sqlite provides the local SQLite database for the CLI.
This is the primary data layer. PowerSync keeps it in sync with the server, but you query it directly like any SQLite database.
Code Generation ¶
The schema types are generated from the PowerSync service. To regenerate:
doppler run -- go generate ./internal/sqlite
This fetches the current schema and sync rules from the PowerSync API and generates Go types for each synced table.
Index ¶
- func SetExtensionPath(path string)
- func WrapSQLiteError(err error, op string) error
- type Conversations
- type DB
- type DatadogAccountStatuses
- type LogEventPolicies
- type LogEvents
- type Messages
- type SQLiteError
- type ServiceStatuses
- type Services
- type Storage
- type StorageService
- type Table
- type Tx
- func (t *Tx) Commit() error
- func (t *Tx) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (t *Tx) Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (t *Tx) QueryRow(ctx context.Context, query string, args ...any) *sql.Row
- func (t *Tx) Rollback() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetExtensionPath ¶
func SetExtensionPath(path string)
SetExtensionPath configures the PowerSync extension to be loaded on every new database connection. This must be called before Open() to have effect. Typically called once at startup by the powersync package.
func WrapSQLiteError ¶
WrapSQLiteError wraps an error with SQLite-specific details if available. If the error is not a sqlite3.Error, it returns a generic wrapped error.
Types ¶
type Conversations ¶
type Conversations interface {
Count(ctx context.Context) (int64, error)
Create(ctx context.Context, accountID, workspaceID string) (string, error)
UpdateTitle(ctx context.Context, id, title string) error
List(ctx context.Context, accountID string) ([]gen.Conversation, error)
Get(ctx context.Context, id string) (gen.Conversation, error)
}
Conversations provides type-safe access to conversations.
type DB ¶
type DB interface {
// Domain entities
Conversations() Conversations
LogEventPolicies() LogEventPolicies
LogEvents() LogEvents
Messages() Messages
Services() Services
// Aggregated statuses
DatadogAccountStatuses() DatadogAccountStatuses
ServiceStatuses() ServiceStatuses
// Sync
PendingUploadCounts(ctx context.Context) (map[Table]int64, error)
// Low-level
Query(ctx context.Context, sql string, args ...any) (*sql.Rows, error)
QueryRow(ctx context.Context, sql string, args ...any) *sql.Row
Exec(ctx context.Context, sql string, args ...any) (sql.Result, error)
WithTx(ctx context.Context, fn func(tx *Tx) error) error
Raw() *sql.DB // Write pool — for PowerSync controller and direct writes
ReadRaw() *sql.DB // Read pool — for query tool and direct reads
Close() error
}
DB is the interface for application code. It provides type-safe access to domain data and raw query execution.
func Open ¶
Open opens a SQLite database at the given path with separate read and write connection pools. The write pool enables WAL mode for concurrent read access during writes. The read pool enforces query_only = ON via the driver hook.
The database file and parent directories are created if they don't exist.
type DatadogAccountStatuses ¶
type DatadogAccountStatuses interface {
GetSummary(ctx context.Context) (domain.AccountSummary, error)
}
DatadogAccountStatuses provides access to Datadog account status data.
type LogEventPolicies ¶
type LogEventPolicies interface {
Count(ctx context.Context) (int64, error)
ListCategoryStatuses(ctx context.Context) ([]domain.PolicyCategoryStatus, error)
}
LogEventPolicies provides type-safe access to log event policies.
type Messages ¶
type Messages interface {
Count(ctx context.Context) (int64, error)
Get(ctx context.Context, id domain.MessageID) (*domain.Message, error)
CreateUserMessage(ctx context.Context, accountID domain.AccountID, conversationID domain.ConversationID, text string) (domain.MessageID, error)
CreateToolResultMessage(ctx context.Context, accountID domain.AccountID, conversationID domain.ConversationID, results []domain.ToolResult) (domain.MessageID, error)
CreateAssistantMessage(ctx context.Context, accountID domain.AccountID, conversationID domain.ConversationID, model string) (domain.MessageID, error)
UpdateContent(ctx context.Context, id domain.MessageID, content string) error
UpdateMeta(ctx context.Context, id domain.MessageID, model, stopReason string) error
Delete(ctx context.Context, id domain.MessageID) error
List(ctx context.Context, conversationID domain.ConversationID) ([]domain.Message, error)
}
Messages provides type-safe access to messages.
type SQLiteError ¶
type SQLiteError struct {
Code int // Primary error code
ExtendedCode int // Extended error code with more detail
Message string // Error message from sqlite3_errmsg()
Op string // Operation that failed (e.g., "insert message")
}
SQLiteError wraps a sqlite3.Error with additional context. It provides structured access to error codes for debugging.
func (*SQLiteError) Error ¶
func (e *SQLiteError) Error() string
func (*SQLiteError) Unwrap ¶
func (e *SQLiteError) Unwrap() error
Unwrap returns nil since this is the root error.
type ServiceStatuses ¶
type ServiceStatuses interface {
ListServiceStatuses(ctx context.Context) ([]domain.ServiceStatus, error)
}
ServiceStatuses provides access to per-service status data.
type Storage ¶
type Storage interface {
DatabasePath(accountID string) (string, error)
ClearDatabase(accountID string) error
Clear() error
}
Storage provides database file operations.
type StorageService ¶
type StorageService struct {
// contains filtered or unexported fields
}
StorageService implements Storage.
func NewStorageService ¶
func NewStorageService(cfg *config.Config) *StorageService
NewStorageService creates a new storage service.
func (*StorageService) Clear ¶
func (s *StorageService) Clear() error
Clear removes all SQLite database files.
func (*StorageService) ClearDatabase ¶
func (s *StorageService) ClearDatabase(accountID string) error
ClearDatabase removes the SQLite database file for a specific account.
func (*StorageService) DatabasePath ¶
func (s *StorageService) DatabasePath(accountID string) (string, error)
DatabasePath returns the path to the SQLite database for a specific account.
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx wraps a SQL transaction with convenience methods.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package main generates SQLite schema types from PowerSync.
|
Package main generates SQLite schema types from PowerSync. |
|
Package sqlitetest provides test doubles for the sqlite package.
|
Package sqlitetest provides test doubles for the sqlite package. |