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 ¶
ErrArtifactImportUnavailable is returned on targets that cannot create a native paged artifact.
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(context.Context, string) (ArtifactInfo, error)
ValidateArtifact is unavailable on browser and bare-metal targets.
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(context.Context, string, string, *ImportOptions) (*ImportResult, error)
ImportMBTiles requires tinySQL's optional sqliteimport build tag.
func ImportTiles ¶ added in v0.29.0
func ImportTiles(context.Context, Source, string, *ImportOptions) (*ImportResult, error)
ImportTiles requires a native artifact builder.
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.
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.
func OpenArtifact ¶
OpenArtifact is unavailable on browser and bare-metal targets.
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.
type Source ¶ added in v0.29.0
type Source interface {
Info(context.Context) (SourceInfo, error)
ScanTiles(context.Context, func(Tile) error) error
}
Source is a repeatable, bounded producer of TMS tiles. ScanTiles may emit tiles in any order, but every key must be unique. Tile data is only retained for the duration of visit; ImportTiles copies it into its bounded batch.
type SourceInfo ¶ added in v0.29.0
type SourceInfo struct {
Name string
SourceBytes int64
TileCount int64
TileBytes int64
MaxTileBytes int64
Metadata map[string]string
}
SourceInfo describes a repeatable tile stream before an artifact import starts. Counts are used for bounded resource planning and verified while the stream is consumed. Metadata is copied by ImportTiles.