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 ¶
- func OpenBrowser(url string) error
- type Column
- type DataSource
- type Filter
- type ProxySource
- func (s *ProxySource) Close() error
- func (s *ProxySource) GetSchema(ctx context.Context, tenantID string) (TenantSchema, error)
- func (s *ProxySource) ListTenants(ctx context.Context) ([]TenantSummary, error)
- func (s *ProxySource) QueryRows(ctx context.Context, tenantID, table string, opts QueryOptions) (RowsPage, error)
- type QueryOptions
- type Relation
- type RowsPage
- type SQLiteSource
- func (s *SQLiteSource) Close() error
- func (s *SQLiteSource) GetSchema(ctx context.Context, tenantID string) (TenantSchema, error)
- func (s *SQLiteSource) ListTenants(ctx context.Context) ([]TenantSummary, error)
- func (s *SQLiteSource) QueryRows(ctx context.Context, tenantID, table string, opts QueryOptions) (RowsPage, error)
- type Server
- type Table
- type TenantSchema
- type TenantSummary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OpenBrowser ¶
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 ¶
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 ¶
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.
type TenantSchema ¶
TenantSchema is the full schema for one tenant.