queries

package
v0.4.0-rc.2-linux-arm64 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 14 Imported by: 1 module, 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 (
	// ErrQueryNotFound is returned when a query does not exist.
	ErrQueryNotFound = xerror.NotFound(xerror.Query)

	// ErrSlugTaken is returned when the query slug is already in use within the organization.
	ErrSlugTaken = xerror.AlreadyExists(xerror.Query)

	// ErrDataSourceNotFound is returned when the referenced data source does not exist.
	ErrDataSourceNotFound = xerror.NotFound(xerror.DataSource)

	// ErrQueryNotDeleted is returned when a query must be soft-deleted before the operation can proceed.
	ErrQueryNotDeleted = xerror.New(
		xerror.KindAlreadyExists,
		"QUERY_NOT_DELETED",
		"query must be deleted before purge",
	)

	// ErrInvalidQueryStatement is returned when the query statement is malformed.
	ErrInvalidQueryStatement = xerror.InvalidInput(xerror.Query)

	// ErrParameterValidationFailed is returned when query parameters fail validation.
	ErrParameterValidationFailed = xerror.ParameterValidationFailed()

	// ErrExecutionTimeout is returned when query execution exceeds the timeout.
	ErrExecutionTimeout = xerror.Timeout(xerror.Query)
)

Functions

This section is empty.

Types

type CreateExecutionParams

type CreateExecutionParams struct {
	Slug   slug.Slug
	Status string
	Result json.RawMessage
}

CreateExecutionParams contains parameters for creating a query execution record.

type CreateParams

type CreateParams struct {
	Slug                     slug.Slug
	Name                     string
	Description              *string
	DataSourceSlug           slug.Slug
	Data                     json.RawMessage
	ExpectedInputContract    json.RawMessage
	ExpectedInputContractRef json.RawMessage
	OutputContract           json.RawMessage
	OutputContractRef        json.RawMessage
	Parameters               []*QueryParameterParams
}

CreateParams contains parameters for creating a query.

type OperationSnapshot

type OperationSnapshot struct {
	DataSourceType           model.DataSourceType
	Data                     json.RawMessage
	ExpectedInputContract    json.RawMessage
	ExpectedInputContractRef json.RawMessage
	OutputContract           json.RawMessage
	OutputContractRef        json.RawMessage
	Parameters               json.RawMessage
	UpdatedAt                time.Time
}

OperationSnapshot is an atomic statement, parameter, and input-requirement read.

type Query

type Query struct {
	Slug                     slug.Slug
	Name                     string
	Description              *string
	Data                     json.RawMessage
	ExpectedInputContract    json.RawMessage
	ExpectedInputContractRef json.RawMessage
	OutputContract           json.RawMessage
	OutputContractRef        json.RawMessage
	DataSourceSlug           slug.Slug
	CreatedAt                time.Time
	UpdatedAt                time.Time
	DeletedAt                *time.Time
}

Query represents a saved query definition.

type QueryExecution

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

QueryExecution represents a query execution record.

type QueryExecutionIdentity

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

QueryExecutionIdentity identifies a recorded successful query execution.

type QueryParameter

type QueryParameter struct {
	Slug         slug.Slug
	Name         string
	DataType     string
	IsRequired   bool
	DefaultValue *string
	Description  *string
	CreatedAt    time.Time
}

QueryParameter represents a parameter definition for a query.

type QueryParameterParams

type QueryParameterParams struct {
	Slug         slug.Slug
	Name         string
	DataType     string
	IsRequired   bool
	DefaultValue *string
	Description  *string
}

QueryParameterParams contains parameters for a query parameter.

type Repository

type Repository interface {
	ExistsOnOtherDataSource(context.Context, postgres.DBTX, slug.Slug, slug.Slug, slug.Slug) (bool, error)
	FindSnapshot(context.Context, postgres.DBTX, slug.Slug, slug.Slug, slug.Slug) (*OperationSnapshot, error)
	// Create inserts a new query and returns it with its parameters.
	Create(
		ctx context.Context,
		tx postgres.DBTX,
		orgSlug slug.Slug,
		dsSlug slug.Slug,
		params *CreateParams,
	) (*Query, []*QueryParameter, error)

	// FindBySlug fetches a query by its slug within a data source with its parameters.
	FindBySlug(
		ctx context.Context,
		tx postgres.DBTX,
		orgSlug, dsSlug, querySlug slug.Slug,
	) (*Query, []*QueryParameter, error)

	// ListByDataSource lists all queries in a data source with pagination.
	ListByDataSource(
		ctx context.Context,
		tx postgres.DBTX,
		orgSlug, dsSlug slug.Slug,
		req model.ListRequest,
		includeDeleted bool,
	) ([]*Query, error)

	// Update updates an existing query by slug and replaces its parameters.
	Update(
		ctx context.Context,
		tx postgres.DBTX,
		orgSlug, dsSlug, querySlug slug.Slug,
		params *UpdateParams,
	) (*Query, []*QueryParameter, error)

	// Delete soft-deletes a query by slug.
	Delete(ctx context.Context, tx postgres.DBTX, orgSlug, dsSlug, querySlug slug.Slug) error

	// Restore clears the deletion tombstone for a query by slug.
	Restore(ctx context.Context, tx postgres.DBTX, orgSlug, dsSlug, querySlug slug.Slug) error

	// Purge permanently deletes a soft-deleted query by slug.
	Purge(ctx context.Context, tx postgres.DBTX, orgSlug, dsSlug, querySlug slug.Slug) error

	// CreateExecution records a query execution.
	CreateExecution(
		ctx context.Context,
		tx postgres.DBTX,
		orgSlug, dsSlug, querySlug slug.Slug,
		params *CreateExecutionParams,
	) (*QueryExecution, error)

	// ListExecutions lists query executions for a query with pagination.
	ListExecutions(
		ctx context.Context,
		tx postgres.DBTX,
		orgSlug, dsSlug, querySlug slug.Slug,
		req model.ListRequest,
	) ([]*QueryExecution, error)

	// GetExecution fetches a query execution by slug.
	GetExecution(
		ctx context.Context,
		tx postgres.DBTX,
		orgSlug, dsSlug, querySlug, executionSlug slug.Slug,
	) (*QueryExecution, error)

	// FindLatestSuccessfulExecution returns the latest recorded successful execution in an organization.
	FindLatestSuccessfulExecution(context.Context, postgres.DBTX, slug.Slug) (*QueryExecutionIdentity, error)
}

Repository provides access to query data.

func New

func New() Repository

New creates a new query repository.

func NewRepositoryWithLogging

func NewRepositoryWithLogging(base Repository, logger *slog.Logger) Repository

NewRepositoryWithLogging wraps base with method completion logging.

type RepositoryWithLogging

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

RepositoryWithLogging implements Repository with method completion logging.

func (RepositoryWithLogging) Create

func (_d RepositoryWithLogging) Create(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, params *CreateParams) (qp1 *Query, qpa1 []*QueryParameter, err error)

Create implements Repository.

func (RepositoryWithLogging) CreateExecution

func (_d RepositoryWithLogging) CreateExecution(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug, params *CreateExecutionParams) (qp1 *QueryExecution, err error)

CreateExecution implements Repository.

func (RepositoryWithLogging) Delete

func (_d RepositoryWithLogging) Delete(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug) (err error)

Delete implements Repository.

func (RepositoryWithLogging) ExistsOnOtherDataSource

func (_d RepositoryWithLogging) ExistsOnOtherDataSource(ctx context.Context, d1 postgres.DBTX, s1 slug.Slug, s2 slug.Slug, s3 slug.Slug) (b1 bool, err error)

ExistsOnOtherDataSource implements Repository.

func (RepositoryWithLogging) FindBySlug

func (_d RepositoryWithLogging) FindBySlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug) (qp1 *Query, qpa1 []*QueryParameter, err error)

FindBySlug implements Repository.

func (RepositoryWithLogging) FindLatestSuccessfulExecution

func (_d RepositoryWithLogging) FindLatestSuccessfulExecution(ctx context.Context, d1 postgres.DBTX, s1 slug.Slug) (qp1 *QueryExecutionIdentity, err error)

FindLatestSuccessfulExecution implements Repository.

func (RepositoryWithLogging) FindSnapshot

func (_d RepositoryWithLogging) FindSnapshot(ctx context.Context, d1 postgres.DBTX, s1 slug.Slug, s2 slug.Slug, s3 slug.Slug) (op1 *OperationSnapshot, err error)

FindSnapshot implements Repository.

func (RepositoryWithLogging) GetExecution

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

GetExecution implements Repository.

func (RepositoryWithLogging) ListByDataSource

func (_d RepositoryWithLogging) ListByDataSource(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, req model.ListRequest, includeDeleted bool) (qpa1 []*Query, err error)

ListByDataSource implements Repository.

func (RepositoryWithLogging) ListExecutions

func (_d RepositoryWithLogging) ListExecutions(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug, req model.ListRequest) (qpa1 []*QueryExecution, err error)

ListExecutions implements Repository.

func (RepositoryWithLogging) Purge

func (_d RepositoryWithLogging) Purge(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug) (err error)

Purge implements Repository.

func (RepositoryWithLogging) Restore

func (_d RepositoryWithLogging) Restore(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug) (err error)

Restore implements Repository.

func (RepositoryWithLogging) Update

func (_d RepositoryWithLogging) Update(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, querySlug slug.Slug, params *UpdateParams) (qp1 *Query, qpa1 []*QueryParameter, err error)

Update implements Repository.

type UpdateParams

type UpdateParams struct {
	Name                     string
	Description              *string
	Data                     json.RawMessage
	ExpectedInputContract    json.RawMessage
	ExpectedInputContractRef json.RawMessage
	OutputContract           json.RawMessage
	OutputContractRef        json.RawMessage
	Parameters               []*QueryParameterParams
}

UpdateParams contains parameters for updating a query.

Jump to

Keyboard shortcuts

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