server

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package server implements the lsqlited daemon: a TCP server that serves SQLite databases using the lsqlited wire protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Verifier *auth.Verifier
	// contains filtered or unexported fields
}

Account is the runtime form of a UserConfig.

func (*Account) CanAccess

func (a *Account) CanAccess(database string) bool

CanAccess reports whether the account may use the named database.

type AuthConfig

type AuthConfig struct {
	// Users maps account names to their credentials.
	Users map[string]UserConfig `yaml:"users"`
}

AuthConfig configures challenge-response authentication.

func (AuthConfig) Accounts

func (a AuthConfig) Accounts() (map[string]*Account, error)

Accounts derives the runtime account of every configured user, returning nil when authentication is disabled.

type Config

type Config struct {
	Listen ListenConfig `yaml:"listen"`
	// Limits bound the work a single statement may do.
	Limits `yaml:",inline"`
	// MaxConnections bounds the SQLite connections one database may have open at a time, which is how many statements it
	// can run in parallel. Zero leaves it unbounded.
	MaxConnections int `yaml:"max_connections"`
	// Params are SQLite DSN query parameters appended to the "file:" URI of every database, e.g. mode=ro. See the
	// go-sqlite3 documentation for the supported set.
	Params Params `yaml:"params"`
	// Extensions are loadable SQLite extensions registered on every connection to every database.
	Extensions Extensions `yaml:"extensions"`
	// TLS configures transport security. Omitted, the protocol travels in cleartext.
	TLS  TLSConfig  `yaml:"tls"`
	Auth AuthConfig `yaml:"auth"`
	// Databases maps the logical name a client connects to onto the path of the SQLite file serving it. Every database is
	// opened the same way, from the settings above.
	Databases map[string]string `yaml:"databases"`
}

Config is the top-level server configuration, usually loaded from a YAML file. See config.example.yaml for the full set of keys.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig reads and validates a YAML configuration file.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the configuration for obvious mistakes.

type Extension

type Extension struct {
	// Path is the shared library to load, resolved by the platform's dynamic loader, so a bare file name is looked up
	// along the usual search path.
	Path string `yaml:"path"`
	// Entrypoint is the initialization symbol to call. When empty, SQLite picks sqlite3_extension_init, falling back to a
	// name derived from the file name.
	Entrypoint string `yaml:"entrypoint"`
}

Extension identifies an external SQLite extension to load into every connection of a database. In YAML it is written either as a plain path or as a mapping naming the entry point:

extensions:
- /usr/lib/sqlite3/vector0.so
- path: /usr/lib/sqlite3/misc.so
  entrypoint: sqlite3_misc_init

func (Extension) String

func (e Extension) String() string

String renders the extension the way it is written in the configuration.

func (*Extension) UnmarshalYAML

func (e *Extension) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML accepts either a path or a mapping.

type Extensions

type Extensions []Extension

Extensions is an ordered list of SQLite extensions.

type Limits

type Limits struct {
	// QueryTimeout is the upper bound on how long a single statement may run, in seconds. Zero leaves statements
	// unbounded.
	QueryTimeout int64 `yaml:"query_timeout"`
	// TransactionTimeout is how long a transaction may sit without a request, in seconds, before the daemon rolls it back
	// and drops the session. Zero waits forever.
	TransactionTimeout int64 `yaml:"transaction_timeout"`
	// MaxRows is the upper bound on the rows one query result may carry. Zero leaves results unbounded.
	MaxRows int64 `yaml:"max_rows"`
}

Limits bound the work a single statement may do. They are the daemon's own safety net: a client may ask for a tighter bound, but never for a looser one.

type ListenConfig

type ListenConfig struct {
	Host string `yaml:"host"`
	Port int    `yaml:"port"`
}

ListenConfig configures the TCP listener. An empty host binds to all interfaces.

type Option

type Option func(*Server)

Option customizes a Server.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets the logger used by the server.

func WithTLSConfig

func WithTLSConfig(cfg *tls.Config) Option

WithTLSConfig serves TLS using the given configuration, overriding the `tls` section of the configuration file. It is meant for callers that embed the server and manage certificates themselves.

type Params

type Params map[string]string

Params holds extra SQLite DSN query parameters. In YAML it is written either as a mapping or as a URL-style query string:

params:
  mode: ro
  immutable: true

params: mode=ro&immutable=true

func ParseParams

func ParseParams(raw string) (Params, error)

ParseParams parses a query string such as "mode=ro&immutable=true".

func (*Params) UnmarshalYAML

func (p *Params) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML accepts either a mapping or a query string.

type Server

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

Server serves SQLite databases over TCP.

func New

func New(cfg *Config, opts ...Option) *Server

New creates a Server from a configuration.

func (*Server) Addr

func (s *Server) Addr() net.Addr

Addr returns the address the server listens on, or nil before Start.

func (*Server) Close

func (s *Server) Close() error

Close stops accepting connections, terminates active ones, waits for handlers to finish, and closes all open databases.

func (*Server) Start

func (s *Server) Start() error

Start binds the listener and begins accepting connections in the background. Use Close to shut the server down.

func (*Server) TLSEnabled

func (s *Server) TLSEnabled() bool

TLSEnabled reports whether the server encrypts its connections. It is only meaningful once Start has returned.

type TLSConfig

type TLSConfig struct {
	// Cert is a PEM certificate, with any intermediates appended so that clients can build the chain. Key is the matching
	// private key.
	Cert string `yaml:"cert"`
	Key  string `yaml:"key"`
	// ClientCA is a PEM bundle of authorities allowed to sign client certificates. Setting it turns on mutual TLS, which
	// authenticates the connection, not the account; accounts are configured under `auth`.
	ClientCA string `yaml:"client_ca"`
	// MinVersion is the lowest TLS version to negotiate, "1.2" (default) or "1.3".
	MinVersion string `yaml:"min_version"`
}

TLSConfig configures transport security for the listener. Leaving the section out serves the wire protocol over plaintext TCP.

func (TLSConfig) Enabled

func (t TLSConfig) Enabled() bool

Enabled reports whether the listener should speak TLS.

type UserConfig

type UserConfig struct {
	// Verifier is the credential produced by "lsqlited -hash-password", which also decides the PBKDF2 cost.
	Verifier string `yaml:"verifier"`
	// Databases lists the database names the account may use; every name must match an entry under Config.Databases.
	Databases []string `yaml:"databases"`
}

UserConfig holds the credential of a single account and the databases it may access.

Jump to

Keyboard shortcuts

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