studio

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package studio is a local, read-only database viewer for SupaCraft projects (Drizzle-Studio style). It serves a small web UI plus a JSON API over the compiled tenant config in {DataDir}/tenants/{id}.json and the SQLite file at {DataDir}/{db_name}.db. The DataSource interface keeps the HTTP layer and frontend independent of where the data comes from (local file or a remote server via ProxySource).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenBrowser

func OpenBrowser(url string) error

OpenBrowser best-effort opens url in the user's default browser. Errors are returned so the caller can fall back to printing the URL.

Types

type Column

type Column struct {
	Name     string `json:"name"`
	Type     string `json:"type"`
	Nullable bool   `json:"nullable"`
	PK       bool   `json:"pk"`
	Readable *bool  `json:"readable,omitempty"`
}

Column describes one column. Type/Nullable/PK come from live DB introspection; Readable is enriched from the tenant config schema when present (so the UI can hint which columns the API would actually expose).

type DataSource

type DataSource interface {
	ListTenants(ctx context.Context) ([]TenantSummary, error)
	GetSchema(ctx context.Context, tenantID string) (TenantSchema, error)
	QueryRows(ctx context.Context, tenantID, table string, opts QueryOptions) (RowsPage, error)
	Close() error
}

DataSource is the backend the HTTP layer talks to: SQLiteSource for local files, ProxySource for a remote server.

type Filter

type Filter struct {
	Column string
	Op     string
	Value  string
}

Filter is a single WHERE clause: Column <Op> Value, with Value always bound as a parameter. Op is one of eq, neq, gt, gte, lt, lte, like.

type ProxySource

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

ProxySource implements DataSource by calling the /admin/studio endpoints on a remote SupaCraft API over HTTPS, instead of reading the database directly. This is for deployments where the DB isn't reachable from the operator's machine. Requests are HMAC-signed with a timestamp and single-use nonce; see internal/studiosign.

func NewProxySource

func NewProxySource(baseURL, secret string) (*ProxySource, error)

NewProxySource targets the API at baseURL (e.g. https://api.example.com), signing each request with secret (the server's STUDIO_SECRET).

func (*ProxySource) Close

func (s *ProxySource) Close() error

func (*ProxySource) GetSchema

func (s *ProxySource) GetSchema(ctx context.Context, tenantID string) (TenantSchema, error)

func (*ProxySource) ListTenants

func (s *ProxySource) ListTenants(ctx context.Context) ([]TenantSummary, error)

func (*ProxySource) QueryRows

func (s *ProxySource) QueryRows(ctx context.Context, tenantID, table string, opts QueryOptions) (RowsPage, error)

type QueryOptions

type QueryOptions struct {
	Limit   int
	Offset  int
	OrderBy string
	Desc    bool
	Filters []Filter
}

QueryOptions controls a row query. Limit is clamped by the source.

type Relation

type Relation struct {
	FromTable  string `json:"from_table"`
	FromColumn string `json:"from_column"`
	ToTable    string `json:"to_table"`
	ToColumn   string `json:"to_column"`
	Type       string `json:"type"`
}

Relation is a foreign-key style relationship taken from the config schema.

type RowsPage

type RowsPage struct {
	Columns []string         `json:"columns"`
	Rows    []map[string]any `json:"rows"`
	Total   int              `json:"total"`
	Limit   int              `json:"limit"`
	Offset  int              `json:"offset"`
}

RowsPage is one page of rows plus the total matching count for pagination.

type SQLiteSource

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

SQLiteSource implements DataSource over local files. It reads tenant config JSON via tenantfile and opens each tenant's SQLite file read-only.

func NewSQLiteSource

func NewSQLiteSource(cfg *config.Config) (*SQLiteSource, error)

NewSQLiteSource builds a source rooted at cfg.DataDir.

func (*SQLiteSource) Close

func (s *SQLiteSource) Close() error

Close closes all cached tenant DB handles.

func (*SQLiteSource) GetSchema

func (s *SQLiteSource) GetSchema(ctx context.Context, tenantID string) (TenantSchema, error)

func (*SQLiteSource) ListTenants

func (s *SQLiteSource) ListTenants(ctx context.Context) ([]TenantSummary, error)

func (*SQLiteSource) QueryRows

func (s *SQLiteSource) QueryRows(ctx context.Context, tenantID, table string, opts QueryOptions) (RowsPage, error)

type Server

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

Server serves the studio JSON API plus the embedded web UI.

func NewServer

func NewServer(src DataSource, secret string) *Server

NewServer wires the routes for the given data source. secret gates access to the data routes via a login-issued session cookie (or a Basic Auth header, kept for curl/scripts) — the same STUDIO_SECRET also signs outbound requests in --proxy mode (proxy_source.go), so changing it affects both paths.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler exposes the mux for http.Server. Auth is enforced per-route (see requireAuth) rather than wrapped here, since the SPA shell, /healthz, and the login/logout endpoints must stay reachable without credentials.

type Table

type Table struct {
	Name    string   `json:"name"`
	Columns []Column `json:"columns"`
}

Table is a single table and its columns.

type TenantSchema

type TenantSchema struct {
	Tables    []Table    `json:"tables"`
	Relations []Relation `json:"relations"`
}

TenantSchema is the full schema for one tenant.

type TenantSummary

type TenantSummary struct {
	ID          string `json:"id"`
	DisplayName string `json:"display_name"`
	DBName      string `json:"db_name"`
	TableCount  int    `json:"table_count"`
}

TenantSummary is the sidebar entry for one tenant.

Jump to

Keyboard shortcuts

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