externaldatatable

package
v0.0.0-...-19d5731 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: AGPL-3.0 Imports: 50 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ImportStatusCreated = iota
	ImportStatusRunning
	ImportStatusSucceeded
	ImportStatusFailed
	ImportStatusPreviewSucceeded
	ImportStatusPreviewFailed
)
View Source
const (
	JobTypeImport = iota
	JobTypePreview
)
View Source
const (
	// MaxStringLenStr and MaxIDLenStr are strings to avoid conversion.
	MaxStringLenStr = "255"
	MaxIDLenStr     = "36" // uuid len

	MaxStringLen = 255
)
View Source
const (
	SeparatorComma = ","
	SeparatorDot   = "."
	SeparatorSpace = " "
	SeparatorNone  = ""
)

Variables

This section is empty.

Functions

func GetRefParametersLookups

func GetRefParametersLookups() []bson.M

func TransformRefParameters

func TransformRefParameters(ctx context.Context, r []externaldata.RefParameters, dbCollection mongo.DbCollection) ([]externaldata.RefParameters, error)

func ValidateRefParameters

func ValidateRefParameters(sl validator.StructLevel, templateExecutor template.Executor, r []externaldata.RefParameters, availableTypes []string)

Types

type API

type API interface {
	crud.API
	BulkDeleteData(c *gin.Context)
	GetSchema(c *gin.Context)

	Import(*gin.Context)
	ImportStatus(*gin.Context)
	ImportData(*gin.Context)
	Preview(c *gin.Context)
	ImportComplete(*gin.Context)

	Export(c *gin.Context)
	ExportStatus(c *gin.Context)
	ExportDownload(c *gin.Context)

	ListData(c *gin.Context)
	GetData(c *gin.Context)
	CreateData(c *gin.Context)
	UpdateData(c *gin.Context)
	DeleteData(c *gin.Context)
}

func NewAPI

func NewAPI(
	store Store,
	importWorker ImportWorker,
	maxFileSize uint64,
	exportTaskCreator export.TaskCreator,
	exportParamsEncoder encoding.Encoder,
	errorResponder httperror.Responder,
) API

type AggregationDataResult

type AggregationDataResult struct {
	Data       []map[string]any `bson:"data" json:"data"`
	TotalCount int64            `bson:"total_count" json:"total_count"`
}

func (*AggregationDataResult) GetData

func (r *AggregationDataResult) GetData() interface{}

func (*AggregationDataResult) GetTotal

func (r *AggregationDataResult) GetTotal() int64

type AggregationResult

type AggregationResult struct {
	Data       []Table `bson:"data" json:"data"`
	TotalCount int64   `bson:"total_count" json:"total_count"`
}

func (*AggregationResult) GetData

func (r *AggregationResult) GetData() interface{}

func (*AggregationResult) GetTotal

func (r *AggregationResult) GetTotal() int64

type BaseColumnConfig

type BaseColumnConfig struct {
	Name string `bson:"name" json:"name" binding:"required"`
	// Possible type values.
	//   * `1` - type string
	//   * `2` - type boolean
	//   * `3` - type number
	//   * `4` - type string_array
	//   * `5` - type datetime
	//   * `6` - type timestamp
	//   * `7` - type regexp
	Type int `bson:"type" json:"type" binding:"required,min=1,max=7"`
	// Possible thousands separator values.
	//   * `dot` - dot separator
	//   * `comma` - comma separator
	//   * `space` - space separator
	ThousandsSeparator string `bson:"thousands_separator,omitempty" json:"thousands_separator,omitempty" binding:"oneoforempty=dot comma space"`
	// Possible decimal separator values.
	//   * `dot` - dot separator
	//   * `comma` - comma separator
	DecimalSeparator string `bson:"decimal_separator,omitempty" json:"decimal_separator,omitempty" binding:"oneoforempty=dot comma"`
	// Possible string array types.
	//   * `1` - json array
	//   * `2` - custom separator array
	StringArrayType      int    `bson:"string_array_type,omitempty" json:"string_array_type,omitempty" binding:"required_if=Type 4,omitempty,oneof=1 2"`
	StringArraySeparator string `bson:"string_array_separator,omitempty" json:"string_array_separator,omitempty" binding:"required_if=StringArrayType 2"`
}

type BulkDeleteRequestItem

type BulkDeleteRequestItem struct {
	ID string `json:"_id" binding:"required"`
}

type Column

type Column struct {
	InitialValue     string `bson:"initial_value"`
	TransformedValue any    `bson:"transformed_value,omitempty"`
	TransformError   string `bson:"transform_error,omitempty"`
}

type ColumnConfig

type ColumnConfig struct {
	BaseColumnConfig `bson:",inline"`
	Tag              *int `bson:"tag,omitempty" json:"tag,omitempty" binding:"omitempty,oneof=0 1 2"`
}

func (*ColumnConfig) IsRegexp

func (c *ColumnConfig) IsRegexp() bool

type EditRequest

type EditRequest struct {
	Type        *int   `json:"type" binding:"required,oneof=0 1"`
	Name        string `json:"name" binding:"required,table_name"`
	Description string `json:"description" binding:"max=500"`
	Author      string `json:"author" swaggerignore:"true"`
}

type ErrorInfo

type ErrorInfo struct {
	Rows     []int    `json:"rows,omitempty"`
	Messages []string `json:"messages,omitempty"`
}

type ExportFetchParameters

type ExportFetchParameters struct {
	ID       string   `json:"_id" swaggerignore:"true"`
	Search   string   `json:"search"`
	SearchBy []string `json:"search_by"`
}

type ExportRequest

type ExportRequest struct {
	ExportFetchParameters
	Fields    export.Fields `json:"fields"`
	Separator string        `json:"separator" binding:"oneoforempty=comma semicolon tab space"`
}

type ExportResponse

type ExportResponse struct {
	ID     string `json:"_id"`
	Status int64  `json:"status"`
}

type ImportCompleteRequest

type ImportCompleteRequest struct {
	ColumnTags []int `json:"column_tags" binding:"required,dive,oneof=0 1 2"`
}

type ImportJob

type ImportJob struct {
	ID                string            `bson:"_id" json:"_id"`
	Status            int               `bson:"status" json:"status"`
	Type              int               `bson:"type" json:"-"`
	Table             string            `bson:"table" json:"-"`
	ExternalDataTable string            `bson:"exdt" json:"-"`
	Separator         rune              `bson:"separator" json:"-"`
	Filepath          string            `bson:"filepath" json:"-"`
	Created           datetime.CpsTime  `bson:"created" json:"-"`
	LastPing          *datetime.CpsTime `bson:"last_ping" json:"-"`
	Retries           int64             `bson:"retries" json:"-"`
	JobType           int               `bson:"job_type" json:"-"`

	ColumnConfigs     []ColumnConfig `bson:"column_configs,omitempty" json:"column_configs,omitempty"`
	PrevColumnConfigs []ColumnConfig `bson:"prev_column_configs,omitempty" json:"-"`

	ErrorInfo map[string]ErrorInfo `bson:"error_info,omitempty" json:"error_info,omitempty"`

	FailReason string `bson:"fail_reason,omitempty" json:"fail_reason,omitempty"`
}

type ImportWorker

type ImportWorker interface {
	CreateImportJob(ctx context.Context, id string, separator rune, f multipart.File) (_ ImportJob, resErr error)
	ProcessJob(ctx context.Context, id string) error
	GetJob(ctx context.Context, id string) (ImportJob, error)
	CompleteJob(ctx context.Context, id string, columnTags []int) (bool, error)
	ProcessAbandonedJobs(ctx context.Context)
	DeleteOldJobs(ctx context.Context)
	CreatePreviewJob(ctx context.Context, id string, req PreviewRequest) (ImportJob, error)
}

func NewImportWorker

func NewImportWorker(
	dbClient mongo.DbClient,
	pgPoolProvider postgres.PoolProvider,
	tmpImportDir string,
	jobPublisher workers.JobPublisher,
	logger zerolog.Logger,
) ImportWorker

type ListDataRequest

type ListDataRequest struct {
	pagination.FilteredQuery
	SearchBy []string `json:"search_by" form:"search_by[]"`
	SortBy   string   `json:"sort_by" form:"sort_by"`
}

type ListPreviewRequest

type ListPreviewRequest struct {
	pagination.Query
}

type ListRequest

type ListRequest struct {
	pagination.FilteredQuery
	SortBy string   `form:"sort_by" binding:"oneoforempty=_id name description type"`
	IDs    []string `form:"ids[]"`
}

type Parser

type Parser interface {
	Parse(cfg ColumnConfig, initialValue string) (any, error)
}

func NewParser

func NewParser() Parser

type PreviewRequest

type PreviewRequest struct {
	ColumnConfigs []ColumnConfig `json:"column_configs" binding:"required,dive"`
}

type RefResponse

type RefResponse struct {
	Reference string `bson:"reference" json:"reference"`
	Type      string `json:"type" bson:"type"`

	// are used in db external data
	Table    Table             `json:"table,omitempty" bson:"table,omitempty"`
	Select   map[string]string `json:"select,omitempty" bson:"select,omitempty"`
	Regexp   map[string]string `json:"regexp,omitempty" bson:"regexp,omitempty"`
	SortBy   string            `json:"sort_by,omitempty" bson:"sort_by,omitempty"`
	Sort     string            `json:"sort,omitempty" bson:"sort,omitempty" binding:"oneoforempty=asc desc"`
	Optional bool              `json:"optional,omitempty" bson:"optional,omitempty"`

	// are used in api external data
	Request *request.Parameters `bson:"request,omitempty" json:"request,omitempty"`
}

type Row

type Row struct {
	ID      string            `bson:"_id"`
	Columns map[string]Column `bson:",inline"`
}

type Store

type Store interface {
	Find(ctx context.Context, r ListRequest) (*AggregationResult, error)
	FindOne(ctx context.Context, id string) (Table, error)
	Create(ctx context.Context, r EditRequest) (Table, error)
	Update(ctx context.Context, r UpdateRequest) (Table, error)
	Delete(ctx context.Context, id, author string) (bool, error)
	FindData(ctx context.Context, tableName string, tableType int, columnConfigs []externaldata.ColumnConfig, r ListDataRequest) (*AggregationDataResult, error)
	FindPreviewData(ctx context.Context, job ImportJob, r ListPreviewRequest) (*AggregationDataResult, error)
	FindOneData(ctx context.Context, tableID, id string) (map[string]any, error)
	CreateData(ctx context.Context, tableID string, r map[string]any) (map[string]any, error)
	UpdateData(ctx context.Context, tableID, id string, r map[string]any) (map[string]any, error)
	DeleteData(ctx context.Context, table Table, id string) (bool, error)
	Export(ctx context.Context, t export.Task) (export.DataCursor, error)
}

func NewStore

func NewStore(dbClient mongo.DbClient, pgPoolProvider postgres.PoolProvider, dbExportClient mongo.DbClient, exportDecoder encoding.Decoder) Store

type Table

type Table struct {
	ID                string                      `bson:"_id" json:"_id"`
	Type              int                         `bson:"type" json:"type"`
	Name              string                      `bson:"name" json:"name"`
	Description       string                      `bson:"description" json:"description"`
	ColumnConfigs     []externaldata.ColumnConfig `bson:"column_configs" json:"column_configs"`
	FromConfig        bool                        `bson:"from_config" json:"from_config"`
	RemovedFromConfig bool                        `bson:"removed_from_config" json:"removed_from_config"`
	Created           datetime.CpsTime            `bson:"created" json:"created" swaggertype:"integer"`
	Updated           datetime.CpsTime            `bson:"updated" json:"updated" swaggertype:"integer"`

	LinkedRules map[string][]struct {
		ID   string `bson:"_id" json:"_id"`
		Name string `bson:"name" json:"name"`
	} `bson:"linked_rules,omitempty" json:"linked_rules,omitempty"`
}

type UpdateRequest

type UpdateRequest struct {
	EditRequest
	ID         string `json:"-"`
	ColumnTags []int  `json:"column_tags" binding:"required,dive,oneof=0 1 2"`
}

Source Files

  • api.go
  • import_worker.go
  • models.go
  • parser.go
  • store.go
  • validator.go

Jump to

Keyboard shortcuts

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