queriessvc

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParameterDataTypeUnknown = model.ParameterDataTypeUnknown
	ParameterDataTypeText    = model.ParameterDataTypeText
	ParameterDataTypeInteger = model.ParameterDataTypeInteger
	ParameterDataTypeBoolean = model.ParameterDataTypeBoolean
	ParameterDataTypeDate    = model.ParameterDataTypeDate
	ParameterDataTypeUUID    = model.ParameterDataTypeUUID
)

Variables

View Source
var (
	ErrQueryNotFound   = repoq.ErrQueryNotFound
	ErrQueryNotDeleted = repoq.ErrQueryNotDeleted
	ErrSlugTaken       = repoq.ErrSlugTaken
)

Re-exported from repository layer — single source of truth.

View Source
var (
	ErrOperationSnapshotRequired = xerror.New(xerror.KindInvalidInput, "OPERATION_SNAPSHOT_REQUIRED", "saved operation contracts require an immutable compiled snapshot")
	ErrInvalidInput              = xerror.ValidationFailed()
	ErrParameterValidationFailed = xerror.ParameterValidationFailed()
	ErrQueryExecutionFailed      = xerror.Unavailable(xerror.Query)
	ErrQueryTimeout              = xerror.Timeout(xerror.Query)
	ErrDataSourceUnavailable     = xerror.Unavailable(xerror.DataSource)
	ErrUnsupportedDataSourceType = xerror.Unsupported(xerror.DataSource)
)

Service-only errors.

Functions

func ExtractQueryStatement

func ExtractQueryStatement(data json.RawMessage) (json.RawMessage, error)

ExtractQueryStatement extracts the polymorphic query statement from the wrapped query data JSON. The data structure is: {"statement": "...", "timeout_seconds": ...} This function returns just the polymorphic statement part as JSON.

Types

type ConnectorExecutionRequest

type ConnectorExecutionRequest struct {
	SinkExecution           bool                        `json:"sink_execution,omitempty"`
	PinnedConfigDigest      string                      `json:"pinned_config_digest,omitempty"`
	ResourceScope           *resourcescope.Scope        `json:"resource_scope,omitempty"`
	OrganizationSlug        slug.Slug                   `json:"organization_slug"`
	DataSourceSlug          slug.Slug                   `json:"data_source_slug"`
	DataSourceType          model.DataSourceType        `json:"data_source_type"`
	ConfigVersion           string                      `json:"config_version"`
	CredentialReference     string                      `json:"credential_reference"`
	CredentialVersion       string                      `json:"credential_version"`
	ConcurrencyLimit        int                         `json:"concurrency_limit"`
	ConcurrencyQueueLimit   int                         `json:"concurrency_queue_limit"`
	ConcurrencyQueueTimeout time.Duration               `json:"concurrency_queue_timeout"`
	ConfigJSON              []byte                      `json:"config_json"`
	CredentialsJSON         []byte                      `json:"credentials_json"`
	StatementJSON           json.RawMessage             `json:"statement_json"`
	Parameters              map[string]types.TypedParam `json:"parameters"`
	Limits                  types.ExecutionLimits       `json:"limits"`
}

ConnectorExecutionRequest is the complete connector payload executed by a worker. Remote implementations must encrypt it before persistence.

type ConnectorExecutor

type ConnectorExecutor interface {
	ExecuteConnector(context.Context, ConnectorExecutionRequest) (*result.ExecutionResult, error)
}

ConnectorExecutor crosses the connector-capable execution boundary.

func NewLocalConnectorExecutor

func NewLocalConnectorExecutor(manager *connector.Manager) (ConnectorExecutor, error)

NewLocalConnectorExecutor creates the direct-mode executor around a process-owned connector manager. The caller owns and must close the manager.

type CreateParams

type CreateParams struct {
	Slug                     slug.Slug // empty → generated from Name
	Name                     string    `validate:"required,min=1,max=255"`
	Description              *string
	Data                     json.RawMessage `validate:"required"`
	ExpectedInputContract    *payload.Contract
	ExpectedInputContractRef *pipelinespec.ODCSContractRef
	OutputContract           *payload.Contract
	OutputContractRef        *pipelinespec.ODCSContractRef
	Parameters               []*QueryParameter `validate:"omitempty,dive,required"`
}

CreateParams are parameters for creating a new query.

type ExecuteOption

type ExecuteOption func(*ExecuteOptions)

ExecuteOption mutates saved-query execution behavior.

func WithoutExecutionRecording

func WithoutExecutionRecording() ExecuteOption

WithoutExecutionRecording skips persistence of the query execution record.

type ExecuteOptions

type ExecuteOptions struct {
	RecordExecution bool
}

ExecuteOptions configures saved-query execution behavior.

type ExecutionLimits

type ExecutionLimits struct {
	QueryTimeout                      time.Duration
	ConnectorTimeout                  time.Duration
	MaxResultRows                     int
	MaxFileBytes                      int64
	MaxResponseBytes                  int64
	ConnectorConcurrencyPerDataSource int
	ConnectorConcurrencyQueueTimeout  time.Duration
	ConnectorConcurrencyMaxQueued     int
	HTTPTimeout                       time.Duration
	HTTPMaxRedirects                  int
	HTTPMaxRequestBytes               int64
	HTTPMaxResponseBytes              int64
	HTTPRetryAttempts                 int
	HTTPRetryBackoff                  time.Duration
}

ExecutionLimits contains runtime guardrails for query and connector execution.

type ParameterDataType

type ParameterDataType = model.ParameterDataType

ParameterDataType is the data type of a query parameter.

func ParameterDataTypeString

func ParameterDataTypeString(value string) ParameterDataType

ParameterDataTypeString maps stored or transport text to a query parameter data type.

type Query

type Query struct {
	Slug           slug.Slug
	Name           string
	Description    *string
	DataSourceSlug slug.Slug
	// Data contains query-type-specific configuration (e.g. SQL statement, row limit, timeout).
	Data                     json.RawMessage
	ExpectedInputContract    *payload.Contract
	ExpectedInputContractRef *pipelinespec.ODCSContractRef
	OutputContract           *payload.Contract
	OutputContractRef        *pipelinespec.ODCSContractRef
	Parameters               []*QueryParameter
	CreatedAt                time.Time
	UpdatedAt                time.Time
	DeletedAt                *time.Time
}

Query is a saved query definition.

type QueryExecution

type QueryExecution struct {
	Slug       slug.Slug
	Status     string
	Result     json.RawMessage
	ExecutedAt time.Time
}

QueryExecution is a persisted query execution result.

type QueryExecutionIdentity

type QueryExecutionIdentity struct {
	ExecutionSlug  slug.Slug
	DataSourceSlug slug.Slug
	QuerySlug      slug.Slug
	ExecutedAt     time.Time
}

QueryExecutionIdentity identifies a recorded successful saved-query execution.

type QueryParameter

type QueryParameter struct {
	Slug         slug.Slug         `validate:"omitempty,slug"`
	Name         string            `validate:"required,min=1,max=255"`
	DataType     ParameterDataType `validate:"queryparamdatatype"`
	IsRequired   bool
	DefaultValue *string `validate:"omitempty,max=4000"`
	Description  *string `validate:"omitempty,max=2000"`
}

QueryParameter defines a named parameter accepted by a query.

type Service

type Service interface {
	ExecuteSnapshot(context.Context, slug.Slug, slug.Slug, contractplan.OperationContent, map[string]any, *pipelinerun.IncrementalCheckpointInput) (*result.ExecutionResult, *pipelinerun.IncrementalCheckpointObservation, error)

	Create(
		ctx context.Context,
		orgSlug, dsSlug slug.Slug,
		actor model.EventActor,
		params *CreateParams,
	) (*Query, error)
	FindBySlug(ctx context.Context, orgSlug, dsSlug, querySlug slug.Slug) (*Query, error)
	GetExpectedInputContract(
		ctx context.Context,
		orgSlug, dsSlug, querySlug slug.Slug,
	) (*payload.Contract, error)
	ListExecutions(
		ctx context.Context,
		orgSlug, dsSlug, querySlug slug.Slug,
		req model.ListRequest,
	) (model.ListResponse[*QueryExecution], error)
	GetExecution(
		ctx context.Context,
		orgSlug, dsSlug, querySlug, executionSlug slug.Slug,
	) (*QueryExecution, error)
	GetExecutionSummary(context.Context, slug.Slug) (*QueryExecutionIdentity, error)
	ListByDataSource(
		ctx context.Context,
		orgSlug, dsSlug slug.Slug,
		req model.ListRequest,
		includeDeleted bool,
	) (model.ListResponse[*Query], error)
	Update(
		ctx context.Context,
		orgSlug, dsSlug, querySlug slug.Slug,
		actor model.EventActor,
		params *UpdateParams,
	) (*Query, error)
	Delete(ctx context.Context, orgSlug, dsSlug, querySlug slug.Slug, actor model.EventActor) error
	Restore(ctx context.Context, orgSlug, dsSlug, querySlug slug.Slug, actor model.EventActor) error
	Purge(ctx context.Context, orgSlug, dsSlug, querySlug slug.Slug, actor model.EventActor) error
	Execute(
		ctx context.Context,
		orgSlug, dsSlug, querySlug slug.Slug,
		actor model.EventActor,
		paramValues map[string]any,
		opts ...ExecuteOption,
	) (*result.ExecutionResult, error)
	ExecuteInline(
		ctx context.Context,
		orgSlug, dsSlug slug.Slug,
		operationInline map[string]any,
		paramValues map[string]any,
	) (*result.ExecutionResult, error)
	ExecuteIncremental(
		ctx context.Context,
		orgSlug, dsSlug, querySlug slug.Slug,
		paramValues map[string]any,
		checkpoint *pipelinerun.IncrementalCheckpointInput,
	) (*result.ExecutionResult, *pipelinerun.IncrementalCheckpointObservation, error)
	ExecuteInlineIncremental(
		ctx context.Context,
		orgSlug, dsSlug slug.Slug,
		operationInline map[string]any,
		paramValues map[string]any,
		checkpoint *pipelinerun.IncrementalCheckpointInput,
	) (*result.ExecutionResult, *pipelinerun.IncrementalCheckpointObservation, error)
}

Service defines the interface for query business logic.

func NewServiceWithLogging

func NewServiceWithLogging(base Service, logger *slog.Logger) Service

NewServiceWithLogging wraps base with method completion logging.

func NewWithExecutionLimits

func NewWithExecutionLimits(
	txm postgres.TransactionManager,
	repo repoq.Repository,
	datasourcesSvc datasourcessvc.Service,
	connectorExecutor ConnectorExecutor,
	credentials credentialssvc.Service,
	clock clock.Clock,
	limits ExecutionLimits,
	eventProducer workerproducer.EventProducer,
) (Service, error)

NewWithExecutionLimits creates a query service with explicit runtime safety limits.

type ServiceWithLogging

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

ServiceWithLogging implements Service with method completion logging.

func (ServiceWithLogging) Create

func (_d ServiceWithLogging) Create(ctx context.Context, orgSlug slug.Slug, dsSlug slug.Slug, actor model.EventActor, params *CreateParams) (qp1 *Query, err error)

Create implements Service.

func (ServiceWithLogging) Delete

func (_d ServiceWithLogging) Delete(ctx context.Context, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug, actor model.EventActor) (err error)

Delete implements Service.

func (ServiceWithLogging) Execute

func (_d ServiceWithLogging) Execute(ctx context.Context, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug, actor model.EventActor, paramValues map[string]any, opts ...ExecuteOption) (ep1 *result.ExecutionResult, err error)

Execute implements Service.

func (ServiceWithLogging) ExecuteIncremental

func (_d ServiceWithLogging) ExecuteIncremental(ctx context.Context, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug, paramValues map[string]any, checkpoint *pipelinerun.IncrementalCheckpointInput) (ep1 *result.ExecutionResult, ip1 *pipelinerun.IncrementalCheckpointObservation, err error)

ExecuteIncremental implements Service.

func (ServiceWithLogging) ExecuteInline

func (_d ServiceWithLogging) ExecuteInline(ctx context.Context, orgSlug slug.Slug, dsSlug slug.Slug, operationInline map[string]any, paramValues map[string]any) (ep1 *result.ExecutionResult, err error)

ExecuteInline implements Service.

func (ServiceWithLogging) ExecuteInlineIncremental

func (_d ServiceWithLogging) ExecuteInlineIncremental(ctx context.Context, orgSlug slug.Slug, dsSlug slug.Slug, operationInline map[string]any, paramValues map[string]any, checkpoint *pipelinerun.IncrementalCheckpointInput) (ep1 *result.ExecutionResult, ip1 *pipelinerun.IncrementalCheckpointObservation, err error)

ExecuteInlineIncremental implements Service.

func (ServiceWithLogging) ExecuteSnapshot

ExecuteSnapshot implements Service.

func (ServiceWithLogging) FindBySlug

func (_d ServiceWithLogging) FindBySlug(ctx context.Context, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug) (qp1 *Query, err error)

FindBySlug implements Service.

func (ServiceWithLogging) GetExecution

func (_d ServiceWithLogging) GetExecution(ctx context.Context, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug, executionSlug slug.Slug) (qp1 *QueryExecution, err error)

GetExecution implements Service.

func (ServiceWithLogging) GetExecutionSummary

func (_d ServiceWithLogging) GetExecutionSummary(ctx context.Context, s1 slug.Slug) (qp1 *QueryExecutionIdentity, err error)

GetExecutionSummary implements Service.

func (ServiceWithLogging) GetExpectedInputContract

func (_d ServiceWithLogging) GetExpectedInputContract(ctx context.Context, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug) (cp1 *payload.Contract, err error)

GetExpectedInputContract implements Service.

func (ServiceWithLogging) ListByDataSource

func (_d ServiceWithLogging) ListByDataSource(ctx context.Context, orgSlug slug.Slug, dsSlug slug.Slug, req model.ListRequest, includeDeleted bool) (p1 model.ListResponse[*Query], err error)

ListByDataSource implements Service.

func (ServiceWithLogging) ListExecutions

func (_d ServiceWithLogging) ListExecutions(ctx context.Context, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug, req model.ListRequest) (p1 model.ListResponse[*QueryExecution], err error)

ListExecutions implements Service.

func (ServiceWithLogging) Purge

func (_d ServiceWithLogging) Purge(ctx context.Context, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug, actor model.EventActor) (err error)

Purge implements Service.

func (ServiceWithLogging) Restore

func (_d ServiceWithLogging) Restore(ctx context.Context, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug, actor model.EventActor) (err error)

Restore implements Service.

func (ServiceWithLogging) Update

func (_d ServiceWithLogging) Update(ctx context.Context, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug, actor model.EventActor, params *UpdateParams) (qp1 *Query, err error)

Update implements Service.

type UpdateParams

type UpdateParams struct {
	Name                     string `validate:"required,min=1,max=255"`
	Description              *string
	Data                     json.RawMessage `validate:"required"`
	ExpectedInputContract    *payload.Contract
	ExpectedInputContractRef *pipelinespec.ODCSContractRef
	OutputContract           *payload.Contract
	OutputContractRef        *pipelinespec.ODCSContractRef
	Parameters               []*QueryParameter `validate:"omitempty,dive,required"`
}

UpdateParams are parameters for updating a query (full replacement). RowLimit is embedded in Data rather than being a separate field.

Jump to

Keyboard shortcuts

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