Documentation
¶
Overview ¶
Package datasource is Orbit's neutral, backend-agnostic contract for Data Studio (ADR-001). The Data Studio panel speaks only these types and never imports nucleus/pkg/model or pkg/db; a single adapter per backend translates — internal/datasource/nucleus today, a Quark adapter later.
These interfaces and types are Orbit public API and are frozen at Orbit v1.0 (quantum/QADR-0005). Design decisions (ADR-001):
- D1 — IDs are string at the boundary (Quark PKs may be uuid/string/ composite); a backend adapter narrows internally.
- D2 — the panel speaks Record (maps), not entities; the reflection lives in the adapter, which enables non-struct backends.
- D3 — catalogue (ModelSource) and access (RecordStore) are separate; Store resolves a store per (model, dbAlias) request.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CountResult ¶
CountResult is a (possibly estimated) row count. Present is false when the backing table does not exist.
type DataSource ¶
type DataSource interface {
ModelSource
Store(modelName, dbAlias string) (RecordStore, error)
}
DataSource is what NewPanel takes. Store resolves the RecordStore for a model and database alias (empty alias = the model's default), mirroring the panel's old getCRUD(meta, alias).
type FieldInfo ¶
type FieldInfo struct {
Name string `json:"name"`
Column string `json:"column"`
Label string `json:"label"`
GoType string `json:"go_type"`
HTMLType string `json:"html_type"`
IsPK bool `json:"is_pk"`
IsRequired bool `json:"is_required"`
IsReadOnly bool `json:"is_read_only"`
IsList bool `json:"is_list"`
IsSearch bool `json:"is_search"`
IsFilter bool `json:"is_filter"`
IsExcluded bool `json:"is_excluded"`
IsForeignKey bool `json:"is_foreign_key"`
IsTenantField bool `json:"is_tenant_field"`
ForeignModel string `json:"foreign_model,omitempty"`
Choices []Choice `json:"choices,omitempty"`
}
FieldInfo describes one field of a model, backend-neutral. It carries exactly what Data Studio needs to render columns, forms, filters, and exports; the HTTP layer maps it to the SPA-facing schema JSON.
type ForeignKey ¶
type ForeignKey struct {
FieldName string `json:"field_name"`
Column string `json:"column"`
ForeignModel string `json:"foreign_model"`
ForeignTable string `json:"foreign_table"`
ForeignColumn string `json:"foreign_column"`
}
ForeignKey is a detected relationship, neutral.
type Index ¶
type Index struct {
Name string `json:"name"`
Columns []string `json:"columns"`
Unique bool `json:"unique"`
}
Index is a declared index, neutral. Data Studio uses unique indexes to detect existing records on import.
type ModelInfo ¶
type ModelInfo struct {
Name string `json:"name"`
Plural string `json:"plural"`
Table string `json:"table"`
PrimaryKey string `json:"primary_key"`
DatabaseAlias string `json:"database_alias"`
Icon string `json:"icon"`
ReadOnly bool `json:"read_only"`
TenantField string `json:"tenant_field"`
Fields []FieldInfo `json:"fields"`
ForeignKeys []ForeignKey `json:"foreign_keys"`
Indexes []Index `json:"indexes"`
}
ModelInfo is a backend-neutral description of a model. TenantField is the resolved tenant column ("" when the model is not tenant-scoped).
type ModelSource ¶
ModelSource is the catalogue half of a DataSource: model discovery and lookup.
type Page ¶
type Page struct {
Items []Record `json:"items"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
TotalPages int `json:"total_pages"`
IsEstimated bool `json:"is_estimated"`
HasMore bool `json:"has_more"`
}
Page is a slice of records plus pagination metadata. Its JSON shape is frozen to what the embedded SPA already consumes (ADR-001 O3): the Nucleus backend's native paginated envelope had exactly these keys, so the SPA is unchanged.
type Query ¶
Query is a neutral list query. Filters are column→value exact matches (the adapter applies backend-appropriate escaping); OrderBy is a comma-separated "col [asc|desc]" list validated against the model's columns.
type Record ¶
Record is one row as a neutral map. An adapter builds it so it marshals to the exact JSON object the backend's native row would (the Nucleus adapter uses a struct→JSON round-trip), so the embedded SPA reads it unchanged. Keys are a field's storage column or Go name — the SPA looks up either.
type RecordStore ¶
type RecordStore interface {
List(ctx context.Context, q Query) (Page, error)
Get(ctx context.Context, id string) (Record, error)
Create(ctx context.Context, rec Record) (Record, error)
Update(ctx context.Context, id string, rec Record) error
Delete(ctx context.Context, id string) error
Count(ctx context.Context) (CountResult, error)
TableExists(ctx context.Context) bool
}
RecordStore is the access half: CRUD over one (model, dbAlias) pair. IDs are strings at the boundary (D1).