datasource

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 1 Imported by: ? 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 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 — the Nucleus adapter in the sibling package datasource/nucleus, and the Quark adapter in the quarkdatasource module.

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

func HonoursFilterOperators

func HonoursFilterOperators(store RecordStore) bool

HonoursFilterOperators reports whether store applies Query.Where.

Types

type Choice

type Choice struct {
	Value string `json:"value"`
	Label string `json:"label"`
}

Choice is a select/enum option for a field.

type CountResult

type CountResult struct {
	Count       int64
	IsEstimated bool
	Present     bool
}

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 Filter

type Filter struct {
	Column string
	Op     FilterOp
	Value  string
	Values []string
}

Filter is one comparison against one column. Value carries the text form for every operator that takes a single one — including isnull, where it is "true" or "false" — and Values carries the set for in and not_in.

Two rules a data source must keep, because getting either wrong turns a filter into a lie: the pattern operators (contains, startswith, endswith) match the text LITERALLY, so a value holding % or _ matches those characters and nothing more; and an in with no values matches NOTHING, rather than being dropped — a filter that quietly means "no filter" answers every row and looks like a result.

type FilterOp

type FilterOp string

FilterOp is the comparison a Filter applies. The set is closed on purpose: the panel turns a query string into one of these and nothing else, so a data source never has to interpret an operator it was handed.

const (
	OpEqual        FilterOp = "eq"
	OpNotEqual     FilterOp = "ne"
	OpGreater      FilterOp = "gt"
	OpGreaterEqual FilterOp = "gte"
	OpLess         FilterOp = "lt"
	OpLessEqual    FilterOp = "lte"
	OpContains     FilterOp = "contains"
	OpStartsWith   FilterOp = "startswith"
	OpEndsWith     FilterOp = "endswith"
	OpIn           FilterOp = "in"
	OpNotIn        FilterOp = "not_in"
	OpIsNull       FilterOp = "isnull"
)

func ParseFilterOp

func ParseFilterOp(raw string) (FilterOp, bool)

ParseFilterOp maps the text form of an operator to a FilterOp, reporting whether it is one this contract knows. An unknown operator is refused by the caller rather than treated as equality.

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).

func (ModelInfo) Field

func (m ModelInfo) Field(key string) (FieldInfo, bool)

Field returns the FieldInfo whose column or Go name matches key (case-insensitive), and whether it was found. It is the neutral replacement for the panel's old resolveField over model.FieldMeta.

type ModelSource

type ModelSource interface {
	All() []ModelInfo
	Get(name string) (ModelInfo, bool)
}

ModelSource is the catalogue half of a DataSource: model discovery and lookup.

type OperatorFilterSource

type OperatorFilterSource interface {
	RecordStore
	HonoursFilterOperators() bool
}

OperatorFilterSource is a RecordStore that applies Query.Where. It is a separate, optional interface because Where arrived AFTER the contract froze, so every data source written before it compiles unchanged and ignores the field — and a list that ignores a filter answers every row while looking like it filtered, which is the worst thing this contract can do.

The panel therefore asks before it sends: a store that does not implement this, or that answers false, gets no operator filters and the request is REFUSED rather than answered unfiltered. Implement it (returning true) when your store honours every operator in the closed set; return false to decline on a backend where you cannot.

ExactTotal needs no such promise, because a store that ignores it already says so in the envelope it returns: Total -1 with IsEstimated true is the answer "I did not count", which no caller can mistake for a count.

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

type Query struct {
	Page     int
	PageSize int
	Search   string
	Filters  map[string]string
	OrderBy  string

	// Where holds the filters that need an operator — a range, a prefix, a
	// set, a null check. Filters keeps its meaning (column → value, equality)
	// and the two are ANDed, so a data source that has never read this field
	// answers exactly what it answered before. It is a new field rather than a
	// richer Filters because Query is frozen (QADR-0010): the shape third
	// parties implement against does not change under them.
	Where []Filter

	// ExactTotal asks for a real count of the matching rows. A data source
	// that cannot count cheaply answers Page.Total -1 with IsEstimated true,
	// which no pager can divide into pages; one that counts always (see
	// quarkdatasource) can ignore this. It is the caller's choice because
	// counting is a second query: a grid with a pager asks for it, an export
	// walking every page does not.
	ExactTotal bool
}

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

type Record = map[string]any

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).

Directories

Path Synopsis
Package nucleus is the Nucleus-backed implementation of Orbit's neutral datasource contract (ADR-001).
Package nucleus is the Nucleus-backed implementation of Orbit's neutral datasource contract (ADR-001).

Jump to

Keyboard shortcuts

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