core

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 16 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

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")
View Source
var ErrWarehouseCommitUnknown = errors.New("目标库提交结果未确认")
View Source
var ErrWarehouseTargetInUse = errors.New("已有沉淀计划或数据表使用此目标,请更换保存表名")
View Source
var SemanticTypeOptions = []SemanticTypeOption{
	{Value: "EntityKey", Label: "主键(实体标识)"},
	{Value: "ForeignKey", Label: "外键"},
	{Value: "Quantity", Label: "数量"},
	{Value: "Score", Label: "评分"},
	{Value: "Percentage", Label: "百分比"},
	{Value: "Currency", Label: "金额(货币)"},
	{Value: "Discount", Label: "折扣"},
	{Value: "Income", Label: "收入"},
	{Value: "Latitude", Label: "纬度"},
	{Value: "Longitude", Label: "经度"},
	{Value: "CreationDate", Label: "创建日期"},
	{Value: "CreationTime", Label: "创建时间"},
	{Value: "CreationTimestamp", Label: "创建日期时间"},
	{Value: "JoinedDate", Label: "加入日期"},
	{Value: "JoinedTime", Label: "加入时间"},
	{Value: "JoinedTimestamp", Label: "加入日期时间"},
	{Value: "Birthday", Label: "生日", Sensitive: true},
	{Value: "EntityName", Label: "实体名称"},
	{Value: "PersonName", Label: "姓名", Sensitive: true},
	{Value: "MobilePhone", Label: "手机号", Sensitive: true},
	{Value: "NationalID", Label: "身份证号", Sensitive: true},
	{Value: "BankCard", Label: "银行卡号", Sensitive: true},
	{Value: "Email", Label: "电子邮箱", Sensitive: true},
	{Value: "Address", Label: "详细地址", Sensitive: true},
	{Value: "URL", Label: "网页地址"},
	{Value: "ImageURL", Label: "图片地址"},
	{Value: "AvatarURL", Label: "头像地址"},
	{Value: "Category", Label: "分类"},
	{Value: "Name", Label: "名称"},
	{Value: "Title", Label: "标题"},
	{Value: "Description", Label: "说明"},
	{Value: "Product", Label: "产品"},
	{Value: "Source", Label: "来源"},
	{Value: "City", Label: "城市"},
	{Value: "State", Label: "省/州"},
	{Value: "Country", Label: "国家/地区"},
	{Value: "ZipCode", Label: "邮政编码"},
	{Value: "IPAddress", Label: "IP 地址", Sensitive: true},
	{Value: "FieldContainingJSON", Label: "JSON 数据"},
}
View Source
var SemanticTypes = []string{
	"EntityKey", "ForeignKey",
	"Quantity", "Score", "Percentage", "Currency", "Discount", "Income", "Latitude", "Longitude",
	"CreationDate", "CreationTime", "CreationTimestamp",
	"JoinedDate", "JoinedTime", "JoinedTimestamp", "Birthday",
	"EntityName", "PersonName", "MobilePhone", "NationalID", "BankCard", "Email", "Address", "URL", "ImageURL", "AvatarURL", "Category", "Name", "Title",
	"Description", "Product", "Source", "City", "State", "Country", "ZipCode",
	"IPAddress", "FieldContainingJSON",
}

Functions

func HashAPIKey

func HashAPIKey(raw string) string

func HashPassword

func HashPassword(password string) (string, error)

func NewAPIKeySecret

func NewAPIKeySecret() (raw, prefix, hash string, err error)

func NewID

func NewID(prefix string) string

func ParseWarehouseTarget

func ParseWarehouseTarget(raw string) (schema, table string, err error)

func ValidSemanticType

func ValidSemanticType(value string) bool

func ValidateWebhookURL

func ValidateWebhookURL(provider, raw string) error

ValidateWebhookURL checks the address without echoing credentials or contacting the provider. Generic webhooks may point to an organization's own HTTP server.

func VerifyPassword

func VerifyPassword(encoded, password string) bool

Types

type AIProvider

type AIProvider interface {
	Ask(context.Context, string, string) (ChatResponse, error)
}

type APIKey

type APIKey struct {
	ID        string     `json:"id"`
	Name      string     `json:"name"`
	Prefix    string     `json:"prefix"`
	Hash      string     `json:"-"`
	UserID    string     `json:"user_id,omitempty"`
	Key       string     `json:"key,omitempty"`
	CreatedAt time.Time  `json:"created_at"`
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
}

type APIKeyStore

type APIKeyStore interface {
	Create(APIKey) error
	ListByUser(userID string) ([]APIKey, error)
	List() ([]APIKey, error)
	ByHash(hash string) (APIKey, error)
	Delete(id string) error
}

type AdminSettings

type AdminSettings struct {
	SiteName             string `json:"site_name"`
	Timezone             string `json:"timezone"`
	PublicScheme         string `json:"public_scheme"`
	CustomDomain         string `json:"custom_domain,omitempty"`
	PublicPort           int    `json:"public_port,omitempty"`
	PublicSharingEnabled bool   `json:"public_sharing_enabled"`
	EmbeddingEnabled     bool   `json:"embedding_enabled"`
}

AdminSettings contains instance-wide switches that must be enforced by the HTTP layer, rather than merely hidden in the UI.

type Alert

type Alert struct {
	ID         string    `json:"id"`
	QuestionID string    `json:"question_id"`
	Name       string    `json:"name"`
	Kind       string    `json:"kind"` // results | goal | progress
	Cron       string    `json:"cron,omitempty"`
	Channel    string    `json:"channel"`
	Goal       float64   `json:"goal,omitempty"`
	Once       bool      `json:"once"`
	Enabled    bool      `json:"enabled"`
	CreatedBy  string    `json:"created_by,omitempty"`
	CreatedAt  time.Time `json:"created_at"`
}

type AlertStore

type AlertStore interface {
	Create(Alert) error
	Update(Alert) error
	ByID(id string) (Alert, error)
	List() ([]Alert, error)
	Delete(id string) error
}

type AuthSettings

type AuthSettings struct {
	PasswordLoginEnabled bool     `json:"password_login_enabled"`
	EnabledProviderIDs   []string `json:"enabled_provider_ids"`
}

AuthSettings governs which sign-in methods are available to end users. Password sign-in is on by default so an administrator cannot be locked out before a third-party provider has been configured.

type Bookmark

type Bookmark struct {
	ID         string    `json:"id"`
	UserID     string    `json:"user_id,omitempty"`
	TargetType string    `json:"target_type"`
	TargetID   string    `json:"target_id"`
	Name       string    `json:"name,omitempty"`
	CreatedAt  time.Time `json:"created_at"`
}

type BookmarkStore

type BookmarkStore interface {
	Create(Bookmark) error
	ListByUser(userID string) ([]Bookmark, error)
	Delete(id, userID string) error
}

type CatalogService

type CatalogService struct {
	Store     DatabaseStore
	Connector DatabaseConnector
	Secrets   ConnectionSecretStore
	Snapshots SchemaSnapshotStore
}

func (CatalogService) Add

func (CatalogService) ConnectionSettings

func (s CatalogService) ConnectionSettings(id string) (ConnectionRequest, error)

func (CatalogService) EnsureConnected

func (s CatalogService) EnsureConnected(ctx context.Context, databaseID string) error

func (CatalogService) LiveStatus

func (s CatalogService) LiveStatus(item Database) Database

func (CatalogService) Remove

func (s CatalogService) Remove(id string) error

func (CatalogService) RescanTable

func (s CatalogService) RescanTable(ctx context.Context, databaseID, schema, table string) (SchemaSnapshot, error)

func (CatalogService) Snapshot

func (s CatalogService) Snapshot(databaseID string) (SchemaSnapshot, error)

func (CatalogService) Sync

func (s CatalogService) Sync(ctx context.Context, databaseID string) (SchemaSnapshot, error)

func (CatalogService) Test

Test validates every network hop without writing catalog metadata.

func (CatalogService) Update

func (s CatalogService) Update(ctx context.Context, id string, input ConnectionRequest) (Database, error)

type ChartAxisSpec

type ChartAxisSpec struct {
	Title     string   `json:"title,omitempty"`
	Scale     string   `json:"scale,omitempty"` // linear | log | pow | timeseries | ordinal | histogram
	Enabled   string   `json:"enabled,omitempty"`
	Labels    *bool    `json:"labels,omitempty"`
	AutoRange *bool    `json:"auto_range,omitempty"`
	Min       *float64 `json:"min,omitempty"`
	Max       *float64 `json:"max,omitempty"`
	UnpinZero bool     `json:"unpin_zero,omitempty"`
	Ticks     *int     `json:"ticks,omitempty"`
}

type ChartColorSegment

type ChartColorSegment struct {
	Min   *float64 `json:"min,omitempty"`
	Max   *float64 `json:"max,omitempty"`
	Color string   `json:"color,omitempty"`
}

type ChartColumnStyle

type ChartColumnStyle struct {
	Title   string `json:"title,omitempty"`
	Visible *bool  `json:"visible,omitempty"`
	Filter  string `json:"filter,omitempty"`
}

type ChartSeriesStyle

type ChartSeriesStyle struct {
	Color       string `json:"color,omitempty"`
	Title       string `json:"title,omitempty"`
	Display     string `json:"display,omitempty"` // line | bar | area
	Axis        string `json:"axis,omitempty"`    // left | right | auto
	LineStyle   string `json:"line_style,omitempty"`
	LineSize    string `json:"line_size,omitempty"`
	Visible     *bool  `json:"visible,omitempty"`
	Markers     string `json:"markers,omitempty"` // auto | on | off
	Missing     string `json:"missing,omitempty"`
	Interpolate string `json:"interpolate,omitempty"`
	ShowValues  *bool  `json:"show_values,omitempty"`
	ShowTrend   *bool  `json:"show_trend,omitempty"`
}

type ChartSpec

type ChartSpec struct {
	Type           string                      `json:"type"`
	X              string                      `json:"x,omitempty"`
	Y              []string                    `json:"y,omitempty"`
	Breakout       string                      `json:"breakout,omitempty"`
	Stacked        bool                        `json:"stacked,omitempty"`
	Stacking       string                      `json:"stacking,omitempty"`
	ShowLegend     *bool                       `json:"show_legend,omitempty"`
	Legend         string                      `json:"legend,omitempty"`
	ShowLabels     bool                        `json:"show_labels,omitempty"`
	Smooth         *bool                       `json:"smooth,omitempty"`
	Interpolation  string                      `json:"interpolation,omitempty"`
	Missing        string                      `json:"missing,omitempty"`
	XTitle         string                      `json:"x_title,omitempty"`
	YTitle         string                      `json:"y_title,omitempty"`
	XAxis          *ChartAxisSpec              `json:"x_axis,omitempty"`
	YAxis          *ChartAxisSpec              `json:"y_axis,omitempty"`
	Series         map[string]ChartSeriesStyle `json:"series,omitempty"`
	Columns        map[string]ChartColumnStyle `json:"columns,omitempty"`
	Search         string                      `json:"search,omitempty"`
	Sort           string                      `json:"sort,omitempty"`
	SortDir        string                      `json:"sort_dir,omitempty"`
	MaxCategories  int                         `json:"max_categories,omitempty"`
	OtherColor     string                      `json:"other_color,omitempty"`
	SliceThreshold *float64                    `json:"slice_threshold,omitempty"`
	ShowGoal       *bool                       `json:"show_goal,omitempty"`
	Goal           *float64                    `json:"goal,omitempty"`
	GoalLabel      string                      `json:"goal_label,omitempty"`
	Trendline      bool                        `json:"trendline,omitempty"`
	AutoSplit      *bool                       `json:"auto_split,omitempty"`
	LabelFrequency string                      `json:"label_frequency,omitempty"`
	ValueFormat    string                      `json:"value_format,omitempty"`
	StackValues    string                      `json:"stack_values,omitempty"`
	Markers        string                      `json:"markers,omitempty"`
	ShowTotal      *bool                       `json:"show_total,omitempty"`
	Percent        string                      `json:"percent,omitempty"`
	Donut          *bool                       `json:"donut,omitempty"`
	Prefix         string                      `json:"prefix,omitempty"`
	Suffix         string                      `json:"suffix,omitempty"`
	Decimals       *int                        `json:"decimals,omitempty"`
	NumberStyle    string                      `json:"number_style,omitempty"`
	Multiply       *float64                    `json:"multiply,omitempty"`
	Color          string                      `json:"color,omitempty"`
	Segments       []ChartColorSegment         `json:"segments,omitempty"`
}

type ChatRequest

type ChatRequest struct {
	Message    string
	DatabaseID string
}

type ChatResponse

type ChatResponse struct {
	Answer string
	SQL    string
	Safe   bool
}

type ClickBehavior

type ClickBehavior struct {
	Type        string `json:"type,omitempty"` // update_filter | link
	FilterID    string `json:"filter_id,omitempty"`
	URL         string `json:"url,omitempty"`
	QuestionID  string `json:"question_id,omitempty"`
	DashboardID string `json:"dashboard_id,omitempty"`
}

type Collection

type Collection struct {
	ID                  string    `json:"id"`
	ParentID            string    `json:"parent_id,omitempty"`
	Name                string    `json:"name"`
	PersonalOwnerUserID string    `json:"personal_owner_user_id,omitempty"`
	OwnerGroupID        string    `json:"owner_group_id,omitempty"`
	Kind                string    `json:"kind"` // personal_project | team_project
	CreatedAt           time.Time `json:"created_at"`
	// These are presentation fields, populated only for a recipient of a
	// personal-group share. Shared groups are always view-only.
	ReadOnly     bool   `json:"read_only,omitempty"`
	SharedByName string `json:"shared_by_name,omitempty"`
}

type CollectionShare

type CollectionShare struct {
	CollectionID string    `json:"collection_id"`
	UserID       string    `json:"user_id"`
	CreatedAt    time.Time `json:"created_at"`
}

type CollectionStore

type CollectionStore interface {
	Create(Collection) error
	Update(Collection) error
	List() ([]Collection, error)
	ByID(id string) (Collection, error)
	Delete(id string) error
}

type Column

type Column struct {
	Name         string    `json:"name"`
	DataType     string    `json:"data_type"`
	Nullable     bool      `json:"nullable"`
	Description  string    `json:"description,omitempty"`
	DefaultValue string    `json:"default_value,omitempty"`
	PrimaryKey   bool      `json:"primary_key,omitempty"`
	ForeignKey   *FieldRef `json:"foreign_key,omitempty"`
}

type ConnectionRequest

type ConnectionRequest struct {
	// ID is the catalog id. Add ignores a client-supplied value; Update/Test use it to merge secrets.
	ID       string            `json:"id,omitempty"`
	Name     string            `json:"name"`
	Engine   string            `json:"engine"`
	Host     string            `json:"host"`
	Port     int               `json:"port"`
	Database string            `json:"database"`
	Username string            `json:"username"`
	Password string            `json:"password"`
	SSLMode  string            `json:"ssl_mode"`
	DSN      string            `json:"dsn"`
	SSH      *SSHTunnelRequest `json:"ssh,omitempty"`
	ClearSSH bool              `json:"clear_ssh,omitempty"`
}

type ConnectionSecretStore

type ConnectionSecretStore interface {
	SaveConnectionSecret(string, ConnectionRequest) error
	GetConnectionSecret(id string) (ConnectionRequest, error)
	ListConnectionSecrets() (map[string]ConnectionRequest, error)
	DeleteConnectionSecret(string) error
}

ConnectionSecretStore stores the connection settings required to reopen a catalog entry. Production implementations should use a managed secret store.

type Dashboard

type Dashboard struct {
	ID                 string            `json:"id"`
	CollectionID       string            `json:"collection_id,omitempty"`
	Name               string            `json:"name"`
	Description        string            `json:"description,omitempty"`
	AutoRefreshSeconds int               `json:"auto_refresh_seconds,omitempty"`
	Appearance         map[string]any    `json:"appearance,omitempty"`
	Tabs               []DashboardTab    `json:"tabs,omitempty"`
	Cards              []DashboardCard   `json:"cards,omitempty"`
	Filters            []DashboardFilter `json:"filters,omitempty"`
	ArchivedAt         *time.Time        `json:"archived_at,omitempty"`
	CreatedBy          string            `json:"created_by,omitempty"`
	CreatedAt          time.Time         `json:"created_at"`
	PublicUUID         string            `json:"public_uuid,omitempty"`
	PublicEmbedEnabled bool              `json:"public_embed_enabled"`
	PublicExpiresAt    *time.Time        `json:"public_expires_at,omitempty"`
	PublicPasswordHash string            `json:"-"`
}

type DashboardCard

type DashboardCard struct {
	ID          string         `json:"id"`
	DashboardID string         `json:"dashboard_id,omitempty"`
	TabID       string         `json:"tab_id,omitempty"`
	Type        string         `json:"type"` // question | heading | text | link | iframe
	QuestionID  string         `json:"question_id,omitempty"`
	Title       string         `json:"title,omitempty"`
	Body        string         `json:"body,omitempty"`
	Config      map[string]any `json:"config,omitempty"`
	Click       *ClickBehavior `json:"click,omitempty"`
	Layout      Layout         `json:"layout"`
}

type DashboardFilter

type DashboardFilter struct {
	ID          string          `json:"id"`
	DashboardID string          `json:"dashboard_id,omitempty"`
	Name        string          `json:"name"`
	Type        string          `json:"type"` // date | category | id | number | text | boolean
	Config      map[string]any  `json:"config,omitempty"`
	Mappings    []FilterMapping `json:"mappings,omitempty"`
}

type DashboardPublicAccess

type DashboardPublicAccess struct {
	ExpiresAt    *time.Time
	PasswordHash string `json:"-"`
	EmbedEnabled bool
}

type DashboardPublicLinkUpdate

type DashboardPublicLinkUpdate struct {
	SetExpiry bool
	ExpiresAt *time.Time
	Password  *string `json:"-"`
}

SetExpiry distinguishes an omitted expiry from an explicit return to a permanent link. Password follows the same convention (nil keeps it).

type DashboardStore

type DashboardStore interface {
	Create(Dashboard) error
	Update(Dashboard) error
	ByID(id string) (Dashboard, error)
	ByPublicUUID(uuid string) (Dashboard, error)
	SetPublicLink(id, publishUUID string, setExpiry bool, expiresAt *time.Time, passwordHash *string) error
	ClearPublicLink(id string) error
	SetEmbedding(id string, enabled bool) error
	List(includeArchived bool) ([]Dashboard, error)
	SetArchived(id string, archivedAt *time.Time) error
}

type DashboardTab

type DashboardTab struct {
	ID          string `json:"id"`
	DashboardID string `json:"dashboard_id,omitempty"`
	Name        string `json:"name"`
	Position    int    `json:"position"`
}

type Database

type Database struct {
	ID           string     `json:"id"`
	Name         string     `json:"name"`
	Engine       string     `json:"engine"`
	Host         string     `json:"host"`
	Status       string     `json:"status"`
	Connected    bool       `json:"connected"`
	CreatedAt    time.Time  `json:"created_at"`
	LastSyncedAt *time.Time `json:"last_synced_at,omitempty"`
	TableCount   int        `json:"table_count,omitempty"`
}

type DatabaseConnector

type DatabaseConnector interface {
	Connect(context.Context, ConnectionRequest) (Database, error)
	Tables(context.Context, string) ([]Table, error)
	Connected(id string) bool
	Close(string) error
}

type DatabaseStore

type DatabaseStore interface {
	List() ([]Database, error)
	Save(Database) error
	Delete(string) error
}

type DeveloperSettings

type DeveloperSettings struct {
	Enabled            bool   `json:"enabled"`
	AllowPersonalKeys  bool   `json:"allow_personal_keys"`
	AllowAnalysisWrite bool   `json:"allow_analysis_write"`
	DefaultKeyTTLDays  int    `json:"default_key_ttl_days"`
	MaxQueryRows       int    `json:"max_query_rows"`
	PublicBaseURL      string `json:"public_base_url,omitempty"`
}

DeveloperSettings controls every non-browser API entry point. Developer mode is intentionally opt-in: disabling it invalidates all API keys at the authentication boundary without deleting them.

type ExternalIdentityLink struct {
	ProviderID string `json:"provider_id"`
	Subject    string `json:"subject"`
	UserID     string `json:"user_id"`
}

type FieldMeta

type FieldMeta struct {
	DatabaseID   string         `json:"database_id"`
	Schema       string         `json:"schema"`
	Table        string         `json:"table"`
	Name         string         `json:"name"`
	DisplayName  string         `json:"display_name,omitempty"`
	Description  string         `json:"description,omitempty"`
	SemanticType string         `json:"semantic_type,omitempty"`
	Visibility   string         `json:"visibility,omitempty"`
	Format       map[string]any `json:"format,omitempty"`
	FKTarget     *FieldRef      `json:"fk_target,omitempty"`
}

type FieldRef

type FieldRef struct {
	Schema string `json:"schema"`
	Table  string `json:"table"`
	Name   string `json:"name"`
}

type FieldStore

type FieldStore interface {
	SaveField(FieldMeta) error
	ListFields(databaseID, schema, table string) ([]FieldMeta, error)
	ListDatabaseFields(databaseID string) ([]FieldMeta, error)
}

type FilterMapping

type FilterMapping struct {
	CardID string `json:"card_id"`
	Field  string `json:"field"`
}

type FilterValue

type FilterValue map[string]any

type GlossaryStore

type GlossaryStore interface {
	Create(GlossaryTerm) error
	List() ([]GlossaryTerm, error)
}

type GlossaryTerm

type GlossaryTerm struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	Definition string `json:"definition"`
}

type Group

type Group struct {
	ID        string   `json:"id"`
	Name      string   `json:"name"`
	Kind      string   `json:"kind"`
	MemberIDs []string `json:"member_ids,omitempty"`
}

type GroupStore

type GroupStore interface {
	Create(Group) error
	AddMember(groupID, userID string) error
	List() ([]Group, error)
	Upsert(Group) error
	ReplaceMembers(groupID string, userIDs []string) error
	HasMember(groupID, userID string) (bool, error)
	GroupsForUser(userID string) ([]Group, error)
}

type IdentityProvider

type IdentityProvider struct {
	ID               string            `json:"id"`
	Type             string            `json:"type"` // feishu | dingtalk | wecom | oidc
	Name             string            `json:"name"`
	Enabled          bool              `json:"enabled"`
	ClientID         string            `json:"client_id"`
	ClientSecret     string            `json:"client_secret,omitempty"`
	Configured       bool              `json:"configured,omitempty"`
	AuthorizationURL string            `json:"authorization_url"`
	TokenURL         string            `json:"token_url"`
	Scopes           []string          `json:"scopes,omitempty"`
	GroupMappings    map[string]string `json:"group_mappings,omitempty"` // external group ID -> Topbase group ID
}

IdentityProvider is deliberately provider-neutral. Each office suite can supply its OAuth endpoints and organisation-sync adapter without changing the user, group, or permission model.

type Layout

type Layout struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
	W float64 `json:"w"`
	H float64 `json:"h"`
}

type LineageEdge

type LineageEdge struct {
	FromType string `json:"from_type"`
	FromID   string `json:"from_id"`
	ToType   string `json:"to_type"`
	ToID     string `json:"to_id"`
}

type LineageStore

type LineageStore interface {
	Add(LineageEdge) error
	List(entityType, id string) ([]LineageEdge, error)
}

type MaterializeResult

type MaterializeResult struct {
	RowCount  int
	Watermark string
}

type MaterializeSpec

type MaterializeSpec struct {
	RequireNewTarget bool
	DatabaseID       string
	Schema           string
	Table            string
	Strategy         string
	SQL              string
	Args             []any
	WatermarkField   string
}

type MaterializedTable

type MaterializedTable struct {
	ID         string     `json:"id"`
	DatabaseID string     `json:"database_id"`
	Schema     string     `json:"schema"`
	Name       string     `json:"name"`
	ScheduleID string     `json:"schedule_id,omitempty"`
	QuestionID string     `json:"question_id,omitempty"`
	Warehouse  bool       `json:"warehouse"`
	LastRunAt  *time.Time `json:"last_run_at,omitempty"`
	LastStatus string     `json:"last_status,omitempty"`
	RowCount   int        `json:"row_count,omitempty"`
	Watermark  string     `json:"watermark,omitempty"`
}

type MaterializedTableStore

type MaterializedTableStore interface {
	Upsert(MaterializedTable) error
	List() ([]MaterializedTable, error)
	ListByDatabase(databaseID string) ([]MaterializedTable, error)
	ByTarget(databaseID, schema, name string) (MaterializedTable, error)
}

type MetadataStore

type MetadataStore interface {
	GetTableAnnotation(databaseID, schema, table string) (TableAnnotation, error)
	SaveTableAnnotation(databaseID, schema, table string, annotation TableAnnotation) error
}

type Metric

type Metric struct {
	ID          string              `json:"id"`
	Name        string              `json:"name"`
	DatabaseID  string              `json:"database_id"`
	Schema      string              `json:"schema"`
	Table       string              `json:"table"`
	Aggregation queryir.Aggregation `json:"aggregation"`
	Filters     []queryir.Filter    `json:"filters,omitempty"`
	CreatedAt   time.Time           `json:"created_at"`
}

type MetricStore

type MetricStore interface {
	Create(Metric) error
	ByID(id string) (Metric, error)
	List() ([]Metric, error)
}

type Model

type Model struct {
	ID           string         `json:"id"`
	CollectionID string         `json:"collection_id,omitempty"`
	Name         string         `json:"name"`
	DatabaseID   string         `json:"database_id"`
	QueryIR      *queryir.Query `json:"queryir,omitempty"`
	NativeSQL    string         `json:"native_sql,omitempty"`
	Columns      []ModelColumn  `json:"columns,omitempty"`
	CreatedBy    string         `json:"created_by,omitempty"`
	CreatedAt    time.Time      `json:"created_at"`
}

type ModelColumn

type ModelColumn struct {
	Name         string `json:"name"`
	DisplayName  string `json:"display_name,omitempty"`
	SemanticType string `json:"semantic_type,omitempty"`
	Description  string `json:"description,omitempty"`
}

type ModelStore

type ModelStore interface {
	Create(Model) error
	Update(Model) error
	ByID(id string) (Model, error)
	List() ([]Model, error)
}

type Notification

type Notification struct {
	ID        string     `json:"id"`
	UserID    string     `json:"user_id,omitempty"`
	AlertID   string     `json:"alert_id,omitempty"`
	Title     string     `json:"title"`
	Body      string     `json:"body,omitempty"`
	CreatedAt time.Time  `json:"created_at"`
	ReadAt    *time.Time `json:"read_at,omitempty"`
}

type NotificationStore

type NotificationStore interface {
	Create(Notification) error
	List(userID string) ([]Notification, error)
	ListAllNotifications() ([]Notification, error)
}

type OrgDirectory

type OrgDirectory interface {
	ListUnits(context.Context) ([]OrgUnit, error)
}

type OrgUnit

type OrgUnit struct {
	ExternalID string   `json:"external_id"`
	Name       string   `json:"name"`
	MemberIDs  []string `json:"member_ids,omitempty"`
}

type PermissionGraph

type PermissionGraph struct {
	Revision        int            `json:"revision"`
	DataGraph       map[string]any `json:"data_graph"`
	CollectionGraph map[string]any `json:"collection_graph"`
}

type ProjectAccessRule

type ProjectAccessRule struct {
	ProjectID string `json:"project_id"`
	GroupID   string `json:"group_id"`
	Role      string `json:"role"`
}

ProjectAccessRule grants a team group access to a team project. Roles are cumulative: view < edit < manage. Personal projects do not use these rules.

type QueryExecutor

type QueryExecutor interface {
	Execute(ctx context.Context, databaseID, sql string, args ...any) (QueryResult, error)
}

type QueryResult

type QueryResult struct {
	Columns []string
	Rows    [][]any
	Meta    map[string]any
}

type QueryService

type QueryService struct{ Executor QueryExecutor }

func (QueryService) Run

func (s QueryService) Run(ctx context.Context, databaseID, sql string) (QueryResult, error)

func (QueryService) RunArgs

func (s QueryService) RunArgs(ctx context.Context, databaseID, sql string, args []any) (QueryResult, error)

type Question

type Question struct {
	ID           string              `json:"id"`
	CollectionID string              `json:"collection_id,omitempty"`
	DashboardID  string              `json:"dashboard_id,omitempty"`
	Name         string              `json:"name"`
	Description  string              `json:"description,omitempty"`
	QueryIR      *queryir.Query      `json:"queryir,omitempty"`
	NativeSQL    string              `json:"native_sql,omitempty"`
	ChartSpec    *ChartSpec          `json:"chartspec,omitempty"`
	QueryType    string              `json:"query_type"`
	DatabaseID   string              `json:"database_id,omitempty"`
	CreatedBy    string              `json:"created_by,omitempty"`
	CreatedAt    time.Time           `json:"created_at"`
	ArchivedAt   *time.Time          `json:"archived_at,omitempty"`
	Parameters   []queryir.Parameter `json:"parameters,omitempty"`
	RawQueryIR   json.RawMessage     `json:"-"`
}

type QuestionStore

type QuestionStore interface {
	Create(Question) error
	Update(Question) error
	ByID(id string) (Question, error)
	List(includeArchived bool) ([]Question, error)
	SetArchived(id string, archivedAt *time.Time) error
}

type Revision

type Revision struct {
	ID         string    `json:"id"`
	TargetType string    `json:"target_type"`
	TargetID   string    `json:"target_id"`
	ActorID    string    `json:"actor_id,omitempty"`
	Snapshot   string    `json:"snapshot"`
	CreatedAt  time.Time `json:"created_at"`
}

type RevisionStore

type RevisionStore interface {
	Create(Revision) error
	List(targetType, targetID string) ([]Revision, error)
}

type Run

type Run struct {
	ID          string     `json:"id"`
	ScheduleID  string     `json:"schedule_id"`
	Status      string     `json:"status"`
	SQLCompiled string     `json:"sql_compiled,omitempty"`
	RowCount    int        `json:"row_count"`
	Error       string     `json:"error,omitempty"`
	StartedAt   time.Time  `json:"started_at"`
	FinishedAt  *time.Time `json:"finished_at,omitempty"`
}

type RunStore

type RunStore interface {
	Create(Run) error
	Update(Run) error
	List(scheduleID string) ([]Run, error)
	Unconfirmed(scheduleID string) (Run, *MaterializedTable, error)
	// Finish commits the final run, schedule timestamp and (when supplied)
	// materialization metadata and lineage together.
	Finish(Run, *MaterializedTable) error
	// MarkUncertain may only change a run whose external write is pending.
	MarkUncertain(Run, *MaterializedTable) error
}

type SSHTunnelRequest

type SSHTunnelRequest struct {
	Host               string `json:"host"`
	Port               int    `json:"port"`
	Username           string `json:"username"`
	AuthenticationType string `json:"authentication_type,omitempty"`
	Password           string `json:"password,omitempty"`
	PrivateKey         string `json:"private_key,omitempty"`
	PrivateKeyPassword string `json:"private_key_password,omitempty"`
	HostKeyFingerprint string `json:"host_key_fingerprint"`
}

SSHTunnelRequest describes the bastion host, never the target database. HostKeyFingerprint is optional. When supplied, it must be the SHA256 fingerprint shown by the SSH server and will be verified.

type Schedule

type Schedule struct {
	ClaimedTarget      bool       `json:"-"`
	ID                 string     `json:"id"`
	Name               string     `json:"name"`
	QuestionID         string     `json:"question_id,omitempty"`
	ModelID            string     `json:"model_id,omitempty"`
	DatabaseID         string     `json:"database_id,omitempty"`
	Cron               string     `json:"cron"`
	Timezone           string     `json:"timezone,omitempty"`
	MaterializeTo      string     `json:"materialize_to"`
	Strategy           string     `json:"strategy,omitempty"`
	WatermarkField     string     `json:"watermark_field,omitempty"`
	ConfirmSourceWrite bool       `json:"confirm_source_write,omitempty"`
	Enabled            bool       `json:"enabled"`
	LastRunAt          *time.Time `json:"last_run_at,omitempty"`
	CreatedBy          string     `json:"created_by,omitempty"`
	CreatedAt          time.Time  `json:"created_at"`
}

type ScheduleProposal

type ScheduleProposal struct {
	Name            string `json:"name"`
	QuestionID      string `json:"question_id"`
	Cron            string `json:"cron"`
	Timezone        string `json:"timezone"`
	MaterializeTo   string `json:"materialize_to"`
	Strategy        string `json:"strategy"`
	WatermarkField  string `json:"watermark_field,omitempty"`
	RequiresConfirm bool   `json:"requires_confirm"`
	Rationale       string `json:"rationale,omitempty"`
}

type ScheduleStore

type ScheduleStore interface {
	Create(Schedule) error
	Update(Schedule) error
	ByID(id string) (Schedule, error)
	List() ([]Schedule, error)
}

type ScheduleSummary

type ScheduleSummary struct {
	Schedule
	LastStatus string `json:"last_status,omitempty"`
	LastError  string `json:"last_error,omitempty"`
}

type SchemaSnapshot

type SchemaSnapshot struct {
	DatabaseID string    `json:"database_id"`
	Tables     []Table   `json:"tables"`
	SyncedAt   time.Time `json:"synced_at"`
}

type SchemaSnapshotStore

type SchemaSnapshotStore interface {
	SaveSnapshot(SchemaSnapshot) error
	GetSnapshot(databaseID string) (SchemaSnapshot, error)
	DeleteSnapshot(databaseID string) error
}

type SearchHit

type SearchHit struct {
	Type string `json:"type"`
	ID   string `json:"id"`
	Name string `json:"name"`
}

type SearchStore

type SearchStore interface {
	Search(query string) ([]SearchHit, error)
}

type Segment

type Segment struct {
	ID         string           `json:"id"`
	Name       string           `json:"name"`
	DatabaseID string           `json:"database_id"`
	Schema     string           `json:"schema"`
	Table      string           `json:"table"`
	Filters    []queryir.Filter `json:"filters"`
	CreatedAt  time.Time        `json:"created_at"`
}

type SegmentStore

type SegmentStore interface {
	Create(Segment) error
	ByID(id string) (Segment, error)
	List() ([]Segment, error)
}

type SemanticTypeOption

type SemanticTypeOption struct {
	Value     string `json:"value"`
	Label     string `json:"label"`
	Sensitive bool   `json:"sensitive,omitempty"`
}

type Session

type Session struct {
	ID        string
	UserID    string
	ExpiresAt time.Time
}

type SessionStore

type SessionStore interface {
	Create(Session) error
	ByID(id string) (Session, error)
	Delete(id string) error
	DeleteExpired(now time.Time) error
}

type SettingStore

type SettingStore interface {
	Get(key string) (string, bool, error)
	Set(key, value string) error
}

type SetupRequest

type SetupRequest struct {
	Language      string `json:"language"`
	AdminName     string `json:"admin_name"`
	AdminEmail    string `json:"admin_email"`
	AdminPassword string `json:"admin_password"`
	SiteName      string `json:"site_name"`
}

type Subscription

type Subscription struct {
	ID          string     `json:"id"`
	DashboardID string     `json:"dashboard_id"`
	Cron        string     `json:"cron"`
	Timezone    string     `json:"timezone,omitempty"`
	Channel     string     `json:"channel"`
	Enabled     bool       `json:"enabled"`
	LastRunAt   *time.Time `json:"last_run_at,omitempty"`
	CreatedBy   string     `json:"created_by,omitempty"`
	CreatedAt   time.Time  `json:"created_at"`
}

type SubscriptionStore

type SubscriptionStore interface {
	Create(Subscription) error
	Update(Subscription) error
	Delete(id string) error
	ByID(id string) (Subscription, error)
	ListByDashboard(dashboardID string) ([]Subscription, error)
	List() ([]Subscription, error)
}

type Table

type Table struct {
	Schema      string   `json:"schema"`
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Columns     []Column `json:"columns"`
}

type TableAnnotation

type TableAnnotation struct {
	DisplayName string            `json:"display_name"`
	Description string            `json:"description"`
	UserNote    string            `json:"user_note"`
	Hidden      bool              `json:"hidden"`
	FieldTypes  map[string]string `json:"field_types"`
}

type TrashItem

type TrashItem struct {
	Type       string    `json:"type"`
	ID         string    `json:"id"`
	Name       string    `json:"name"`
	ArchivedAt time.Time `json:"archived_at"`
}

type UploadedTable

type UploadedTable struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	FileName  string    `json:"file_name"`
	SheetName string    `json:"sheet_name"`
	Columns   []Column  `json:"columns"`
	RowCount  int       `json:"row_count"`
	CreatedAt time.Time `json:"created_at"`
}

UploadedTable is a user-provided workbook sheet retained by Topbase as part of its local warehouse. Rows are intentionally kept behind the store API; callers receive only safe catalog metadata.

type UploadedTablePreview

type UploadedTablePreview struct {
	Rows        [][]string `json:"rows"`
	TotalRows   int        `json:"total_rows"`
	ByteLimited bool       `json:"byte_limited"`
}

type User

type User struct {
	ID           string    `json:"id"`
	Email        string    `json:"email"`
	Name         string    `json:"name"`
	AvatarURL    string    `json:"avatar_url,omitempty"`
	Locale       string    `json:"locale"`
	Theme        string    `json:"theme"`
	IsActive     bool      `json:"is_active"`
	PasswordHash string    `json:"-"`
	FeishuOpenID string    `json:"feishu_open_id,omitempty"`
	IsAdmin      bool      `json:"is_admin,omitempty"`
	CreatedAt    time.Time `json:"created_at"`
}

type UserStore

type UserStore interface {
	Create(User) error
	ByEmail(email string) (User, error)
	ByID(id string) (User, error)
	ByFeishuOpenID(openID string) (User, error)
	List() ([]User, error)
	SetActive(id string, active bool) error
	SetPassword(id, passwordHash string) error
	UpdateProfile(id, name, email, locale, theme, avatarURL string) error
}

type WarehouseWriter

type WarehouseWriter interface {
	Materialize(ctx context.Context, spec MaterializeSpec) (MaterializeResult, error)
}

type WebhookEndpoint

type WebhookEndpoint struct {
	ID            string    `json:"id"`
	Name          string    `json:"name"`
	Provider      string    `json:"provider"` // feishu | dingtalk | wecom | slack | teams | google_chat | generic
	URL           string    `json:"url"`
	Secret        string    `json:"secret,omitempty"`
	TemplateType  string    `json:"template_type,omitempty"` // text | post | card | custom
	Template      string    `json:"template,omitempty"`      // custom JSON or legacy preset JSON
	TemplateTitle string    `json:"template_title,omitempty"`
	TemplateBody  string    `json:"template_body,omitempty"`
	Enabled       bool      `json:"enabled"`
	CreatedAt     time.Time `json:"created_at"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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