sqlproxy

package
v0.0.0-...-d4e4f65 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package sqlproxy provides a SQL query interface that wraps SQLite and captures write operations for sync. Apps use standard SQL (Exec/Query/QueryRow); writes are detected and logged for the sync engine to broadcast.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Migration

type Migration struct {
	Version int
	SQL     string
}

Migration defines a schema migration step.

type OnWriteEventFunc

type OnWriteEventFunc func(ctx context.Context, event WriteEvent) error

OnWriteEventFunc is called with structured write events including table name.

type OnWriteFunc

type OnWriteFunc func(entry WriteEntry)

OnWriteFunc is called when a write operation is detected (legacy).

type Proxy

type Proxy struct {
	WriteLog     []WriteEntry     // captured writes (for sync engine to consume)
	OnWrite      OnWriteFunc      // optional legacy callback
	OnWriteEvent OnWriteEventFunc // optional structured callback with table name
	// contains filtered or unexported fields
}

Proxy wraps a SQLite database and intercepts write operations.

func Open

func Open(path string) (*Proxy, error)

Open creates a new Proxy backed by a SQLite database at the given path. Use ":memory:" for an in-memory database.

func (*Proxy) Close

func (p *Proxy) Close() error

Close closes the underlying database.

func (*Proxy) Exec

func (p *Proxy) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)

Exec executes a SQL statement. If the statement is a write (INSERT/UPDATE/DELETE), it is recorded in WriteLog for the sync engine.

func (*Proxy) Migrate

func (p *Proxy) Migrate(ctx context.Context, migrations []Migration) error

Migrate runs migrations in order, skipping already-applied versions.

func (*Proxy) Query

func (p *Proxy) Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)

Query executes a query that returns rows (SELECT).

func (*Proxy) QueryRow

func (p *Proxy) QueryRow(ctx context.Context, query string, args ...any) *sql.Row

QueryRow executes a query that returns at most one row.

type WriteEntry

type WriteEntry struct {
	Op  WriteOp
	SQL string
}

WriteEntry records a detected write operation for sync.

type WriteEvent

type WriteEvent struct {
	Table string  // target table name
	Op    WriteOp // INSERT, UPDATE, DELETE
	SQL   string  // original SQL statement
}

WriteEvent is a structured write event with table name extracted.

type WriteOp

type WriteOp int

WriteOp represents the type of a detected write operation.

const (
	OpInsert WriteOp = iota
	OpUpdate
	OpDelete
)

Jump to

Keyboard shortcuts

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