Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAuto ¶
NewAuto creates a database based on environment variables:
- DB_URL + DB_TOKEN: Remote libSQL replica (syncs with Turso/libSQL server)
- DB_PATH: Local file-based SQLite database
- Neither: In-memory database (for development/testing)
When using remote mode, DB_PATH can optionally specify the local replica path. If not set, it defaults to "/data/replica.db".
Fatal if the configured mode fails. Memory mode cannot fail.
func NewMemory ¶
NewMemory creates a new in-memory database. Useful for testing and development. Data is lost when the connection is closed.
func NewRemote ¶
func NewRemote(localPath, primaryURL, authToken string, opts ...RemoteOption) (*database.Database, error)
NewRemote creates a new embedded replica database that syncs with a remote libSQL server. It maintains a local copy for fast reads while syncing writes to the primary.
The localPath is where the local replica is stored. The primaryURL is the remote libSQL server URL (e.g., "libsql://db-name.turso.io"). The authToken is the authentication token for the remote server.
Returns an error if the connection cannot be established after retries.
Example:
db, err := engines.NewRemote(
"./data/replica.db",
os.Getenv("DB_URL"),
os.Getenv("DB_TOKEN"),
engines.WithSyncInterval(time.Minute),
)
Types ¶
type RemoteOption ¶
type RemoteOption func(*remoteConfig)
RemoteOption configures a remote database
func WithSyncInterval ¶
func WithSyncInterval(d time.Duration) RemoteOption
WithSyncInterval sets the automatic sync interval. If not set, sync must be called manually.