Documentation
¶
Overview ¶
Package tiles defines tinySQL's stable, typed API for immutable tile artifacts. It is intended for serving applications such as tinyTiles, not for arbitrary SQL access to an artifact's implementation tables.
Tile coordinates are always TMS coordinates. Callers that receive XYZ requests must convert the row before constructing a Key.
Index ¶
Constants ¶
const APIVersion = 1
APIVersion changes only for a deliberately incompatible change to this package's public contract. Additive fields and methods are introduced under the same major API version.
Variables ¶
ErrArtifactReaderUnavailable is returned on targets that do not support the native paged-artifact reader. Browser/WASM applications use tinyTiles' offline cache protocol rather than opening server artifact files directly.
ErrSQLiteImportUnavailable is returned by ImportMBTiles in builds that omit tinySQL's optional sqliteimport build tag. Opening and serving an already published artifact does not link SQLite on supported native targets.
Functions ¶
This section is empty.
Types ¶
type ArtifactInfo ¶
type ArtifactInfo struct {
APIVersion int `json:"api_version"`
FormatVersion int `json:"format_version"`
TinySQLVersion string `json:"tinysql_version"`
Schema Schema `json:"schema"`
CoordinateSystem CoordinateSystem `json:"coordinate_system"`
CreatedAt time.Time `json:"created_at"`
Source string `json:"source"`
SourceBytes int64 `json:"source_bytes"`
Resources ResourceEstimate `json:"resources"`
Provenance map[string]any `json:"provenance,omitempty"`
Tables []Table `json:"tables"`
PhysicalIndexes map[string]string `json:"physical_indexes,omitempty"`
Checksums map[string]string `json:"checksums"`
TileDigestSHA256 string `json:"tile_digest_sha256"`
MetadataDigestSHA256 string `json:"metadata_digest_sha256"`
}
ArtifactInfo is the stable, semantic view of manifest.json. It deliberately does not expose tinySQL's private pager or raw index configuration map. Call Clone before retaining and modifying an Info value obtained elsewhere.
func ValidateArtifact ¶
func ValidateArtifact(ctx context.Context, artifactPath string) (ArtifactInfo, error)
ValidateArtifact runs the complete checksum, schema, unique-key, index and logical digest audit. It is safe to call before changing a publication pointer or deploying an artifact to a reader fleet.
func (ArtifactInfo) Clone ¶
func (info ArtifactInfo) Clone() ArtifactInfo
Clone returns a deep copy of all maps and slices in info. It is useful when passing metadata to code outside the trust boundary of an application.
type CoordinateSystem ¶
type CoordinateSystem string
CoordinateSystem identifies the row convention used by tile keys.
const ( // CoordinateTMS is the coordinate system used by MBTiles and every tiles // API lookup. y=0 is the southernmost row at a zoom level. CoordinateTMS CoordinateSystem = "TMS" )
type ImportOptions ¶
type ImportOptions struct {
Schema Schema
BatchSize int
MaxMemoryBytes int64
MinFreeBytes int64
Provenance map[string]any
Progress func(Progress)
ProgressEvery time.Duration
ReplaceExisting bool
}
ImportOptions controls a bounded, atomically published MBTiles import. Provenance must be JSON-compatible; it is copied and checksummed into the published manifest without interpretation by tinySQL.
type ImportResult ¶
type ImportResult struct {
ArtifactPath string `json:"artifact_path"`
Info ArtifactInfo `json:"info"`
Estimate ResourceEstimate `json:"estimate"`
}
ImportResult is returned only after full validation and atomic publication.
func ImportMBTiles ¶
func ImportMBTiles(ctx context.Context, sourcePath, artifactPath string, opts *ImportOptions) (*ImportResult, error)
ImportMBTiles streams a flat or normalized MBTiles SQLite source into a validated, immutable tile artifact. It never exposes the source database or tinySQL's internal pager to the caller.
type Index ¶
type Index struct {
Name string `json:"name"`
Columns []string `json:"columns"`
Unique bool `json:"unique"`
}
Index describes one persisted artifact index.
type MetadataScanner ¶
type MetadataScanner interface {
Reader
// ScanMetadata visits all metadata name/value pairs without materializing
// table rows. Returning an error from fn stops the scan and returns that
// same error to the caller.
ScanMetadata(ctx context.Context, fn func(name, value string) error) error
}
MetadataScanner is implemented by readers that can stream the complete (normally small) MBTiles metadata table. It is deliberately separate from Reader so existing Reader implementations remain source-compatible. The callback receives values in stable name order and must not retain mutable implementation state.
OpenArtifact always returns a MetadataScanner. Applications that need a copied metadata map can build one at open time, keeping the tile request hot path free of metadata-table scans.
func OpenArtifact ¶
func OpenArtifact(ctx context.Context, artifactPath string, opts OpenOptions) (MetadataScanner, error)
OpenArtifact validates artifactPath before returning a read-only Reader. The result has no database/sql dependency in its serving API.
type OpenOptions ¶
type OpenOptions struct {
MaxMemoryBytes int64
}
OpenOptions controls one artifact reader. A non-positive MaxMemoryBytes delegates to tinySQL's documented default reader budget.
type Progress ¶
type Progress struct {
Phase string
RowsRead int64
RowsWritten int64
BytesRead int64
BytesWritten int64
TotalRows int64
BatchSize int
Estimate *ResourceEstimate
}
Progress is reported after resource preflight and bounded import batches. It never retains a source tile or source row.
type Range ¶
type Range struct {
Z int `json:"z"`
XMin int `json:"x_min"`
XMax int `json:"x_max"`
YMin int `json:"y_min"`
YMax int `json:"y_max"`
}
Range is an inclusive TMS rectangle at one zoom level. Scan visits matching tiles in stable z/x/y order without materializing the rectangle.
type Reader ¶
type Reader interface {
io.Closer
// Info returns an independent copy of immutable artifact information.
Info() ArtifactInfo
// Metadata finds a standard MBTiles metadata value by name.
Metadata(ctx context.Context, name string) (value string, found bool, err error)
// Lookup reads one exact TMS tile.
Lookup(ctx context.Context, key Key) (tile Tile, found bool, err error)
// LookupFunc avoids the result wrapper on an exact tile read. fn receives a
// caller-owned tile payload and may retain it.
LookupFunc(ctx context.Context, key Key, fn func(Tile) error) (found bool, err error)
// Scan streams an inclusive TMS rectangle in stable z/x/y order. Returning
// an error from fn stops the scan and returns that same error to the caller.
Scan(ctx context.Context, tileRange Range, fn func(Tile) error) error
}
Reader is the serving-path contract. Implementations are read-only and validate the COMPLETE marker, checksums and logical index integrity before OpenArtifact returns. One Reader is intended for one concurrent user; use a pool of independent readers for parallel HTTP requests.
type ResourceEstimate ¶
type ResourceEstimate struct {
SourceBytes int64 `json:"source_bytes"`
TileCount int64 `json:"tile_count"`
MapRows int64 `json:"map_rows,omitempty"`
ImageRows int64 `json:"image_rows,omitempty"`
MetadataRows int64 `json:"metadata_rows"`
EstimatedMemory int64 `json:"estimated_memory"`
EstimatedDisk int64 `json:"estimated_disk"`
AvailableDisk int64 `json:"available_disk"`
BatchSize int `json:"batch_size"`
}
ResourceEstimate is the preflight resource plan computed before destination files are created.