services

package
v0.0.0-...-caaa3fa Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JobStatusPending   = "pending"
	JobStatusRunning   = "running"
	JobStatusCompleted = "completed"
	JobStatusFailed    = "failed"
	JobStatusCancelled = "cancelled"
)

JobStatus constants

View Source
const (
	JobTypeGenerateEmbeddings   = "generate_embeddings"
	JobTypeRegenerateEmbeddings = "regenerate_embeddings"
)

JobType constants

Variables

This section is empty.

Functions

func BooleanLiteral

func BooleanLiteral(dialect string, value bool) string

BooleanLiteral returns the appropriate boolean literal for the dialect

func CloseVectorDB

func CloseVectorDB() error

CloseVectorDB closes the vector database connection (if it's separate from main DB)

func CoalesceExpr

func CoalesceExpr(column string, defaultValue string) string

CoalesceExpr returns the appropriate COALESCE expression

func CurrentTimestampExpr

func CurrentTimestampExpr(dialect string) string

CurrentTimestampExpr returns the appropriate current timestamp expression for the dialect

func Example1_BasicInitialization

func Example1_BasicInitialization()

Example1_BasicInitialization shows basic service initialization

func Example2_CustomDatabaseQuery

func Example2_CustomDatabaseQuery(serviceFactory *ServiceFactory)

Example2_CustomDatabaseQuery shows how to execute custom queries against user databases

func Example3_DialectAwareQueries

func Example3_DialectAwareQueries(serviceFactory *ServiceFactory)

Example3_DialectAwareQueries shows how to use dialect helper functions

func Example4_SchemaDiscovery

func Example4_SchemaDiscovery(serviceFactory *ServiceFactory)

Example4_SchemaDiscovery shows comprehensive schema discovery

func Example5_ServiceWithCustomLogic

func Example5_ServiceWithCustomLogic(serviceFactory *ServiceFactory)

Example5_ServiceWithCustomLogic shows how to create a custom service using DatabaseHelper

func Example6_TransactionSupport

func Example6_TransactionSupport(serviceFactory *ServiceFactory)

Example6_TransactionSupport shows how to use transactions with multi-database support

func Example7_HealthChecksAndMonitoring

func Example7_HealthChecksAndMonitoring(serviceFactory *ServiceFactory)

Example7_HealthChecksAndMonitoring shows how to monitor database health

func GetColumnsQuery

func GetColumnsQuery(dialect string, schemaName string, tableName string) string

GetColumnsQuery returns the appropriate query to discover columns for each database type

func GetDatabaseListQuery

func GetDatabaseListQuery(dialect string) string

GetDatabaseListQuery returns the appropriate query to list all databases/schemas

func GetIndexesQuery

func GetIndexesQuery(dialect string, schemaName string, tableName string) string

GetIndexesQuery returns the appropriate query to discover indexes for each database type

func GetTablesQuery

func GetTablesQuery(dialect string, schemaName string) string

GetTablesQuery returns the appropriate query to discover tables for each database type

func GetVectorDB

func GetVectorDB(mainDB *gorm.DB) (*gorm.DB, error)

GetVectorDB returns the vector database connection based on aiconfig.json If use_main_db is true, it returns the main database connection Otherwise, it establishes a separate connection to the vector database

func GetVectorDBSchema

func GetVectorDBSchema() string

GetVectorDBSchema returns the schema name for vector database operations

func GetVectorDBTablePrefix

func GetVectorDBTablePrefix() string

GetVectorDBTablePrefix returns the table prefix for vector database tables

func InitializeVectorDatabase

func InitializeVectorDatabase(db *gorm.DB) error

InitializeVectorDatabase initializes the vector database tables if configured

func JSONExtractExpr

func JSONExtractExpr(dialect string, column string, path string) string

JSONExtractExpr returns the appropriate JSON extract expression

func LikeOperator

func LikeOperator(dialect string, caseSensitive bool) string

LikeOperator returns the appropriate LIKE operator for the dialect

func LimitOffsetClause

func LimitOffsetClause(dialect string, limit, offset int) string

LimitOffsetClause returns the appropriate pagination clause for the dialect

func NormalizeDataType

func NormalizeDataType(dialect string, dataType string) string

NormalizeDataType normalizes database-specific data types to common types

func StringConcatExpr

func StringConcatExpr(dialect string, parts ...string) string

StringConcatExpr returns the appropriate string concatenation expression

Types

type AIAgencyRequest

type AIAgencyRequest struct {
	SessionID           string                   `json:"session_id"`
	UserID              string                   `json:"user_id"`
	Question            string                   `json:"question"`
	EditorType          string                   `json:"editor_type"`
	DatabaseAlias       string                   `json:"database_alias,omitempty"`
	EntityID            string                   `json:"entity_id,omitempty"`
	EntityContext       map[string]interface{}   `json:"entity_context,omitempty"`
	PageContext         map[string]interface{}   `json:"page_context,omitempty"`
	ConversationHistory []map[string]interface{} `json:"conversation_history,omitempty"`
	Options             map[string]interface{}   `json:"options,omitempty"`
}

AIAgencyRequest represents a request to the AI agency

type AIAgencyResponse

type AIAgencyResponse struct {
	SessionID      string                  `json:"session_id"`
	Answer         string                  `json:"answer"`
	ResponseType   string                  `json:"response_type"`       // "answer", "question", "code_generation", "clarification"
	IntentType     string                  `json:"intent_type"`         // "general", "bpm_generation", "query_generation", etc.
	Data           map[string]interface{}  `json:"data,omitempty"`      // Generated code, SQL, etc.
	Questions      []ClarificationQuestion `json:"questions,omitempty"` // Follow-up questions if needed
	Confidence     float64                 `json:"confidence"`
	RequiresAction bool                    `json:"requires_action"` // If user needs to approve/provide more info
	NextStep       string                  `json:"next_step,omitempty"`
	Metadata       map[string]interface{}  `json:"metadata,omitempty"`
}

AIAgencyResponse represents a response from the AI agency

type AIAgencyService

type AIAgencyService struct {
	DB                     *gorm.DB
	OpenAIKey              string
	OpenAIModel            string
	ChatService            *ChatService
	AIReportService        *AIReportService
	SchemaMetadataService  *SchemaMetadataService
	SchemaEmbeddingService *SchemaEmbeddingService
	// contains filtered or unexported fields
}

AIAgencyService provides unified AI assistant functionality across all editors It acts as an AI agency that can route questions to specialized handlers

func NewAIAgencyService

func NewAIAgencyService(
	db *gorm.DB,
	openAIKey, openAIModel string,
	chatService *ChatService,
	aiReportService *AIReportService,
	schemaService *SchemaMetadataService,
	embeddingService *SchemaEmbeddingService,
) *AIAgencyService

NewAIAgencyService creates a new AI agency service

func (*AIAgencyService) HandleRequest

func (s *AIAgencyService) HandleRequest(ctx context.Context, request *AIAgencyRequest) (*AIAgencyResponse, error)

HandleRequest is the main entry point for AI agency requests

type AIColumnInfo

type AIColumnInfo struct {
	ColumnName  string  `json:"column_name"`
	DataType    string  `json:"data_type"`
	Description string  `json:"description"`
	Similarity  float64 `json:"similarity,omitempty"`
}

AIColumnInfo contains column information for AI context

type AIEmbeddingService

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

func NewAIEmbeddingService

func NewAIEmbeddingService(db *gorm.DB) *AIEmbeddingService

NewAIEmbeddingService creates a new AI embedding service

func (*AIEmbeddingService) CreateBusinessEntity

func (s *AIEmbeddingService) CreateBusinessEntity(ctx context.Context, req models.BusinessEntityRequest, embeddingFunc func(string) ([]float32, error), iLog *logger.Log) (*models.AIBusinessEntity, error)

CreateBusinessEntity creates a new business entity with embedding

func (*AIEmbeddingService) CreateQueryTemplate

func (s *AIEmbeddingService) CreateQueryTemplate(ctx context.Context, req models.QueryTemplateRequest, embeddingFunc func(string) ([]float32, error), iLog *logger.Log) (*models.AIQueryTemplate, error)

CreateQueryTemplate creates a new query template with embedding

func (*AIEmbeddingService) DeleteBusinessEntity

func (s *AIEmbeddingService) DeleteBusinessEntity(id int, iLog *logger.Log) error

DeleteBusinessEntity soft deletes a business entity

func (*AIEmbeddingService) DeleteQueryTemplate

func (s *AIEmbeddingService) DeleteQueryTemplate(id int, iLog *logger.Log) error

DeleteQueryTemplate soft deletes a query template

func (*AIEmbeddingService) GenerateSchemaEmbeddings

func (s *AIEmbeddingService) GenerateSchemaEmbeddings(ctx context.Context, req models.SchemaMetadataRequest, embeddingFunc func(string) ([]float32, error), iLog *logger.Log) error

GenerateSchemaEmbeddings generates vector embeddings for database schema metadata

func (*AIEmbeddingService) GetBusinessEntities

func (s *AIEmbeddingService) GetBusinessEntities(configID int, iLog *logger.Log) ([]models.AIBusinessEntity, error)

GetBusinessEntities retrieves all business entities

func (*AIEmbeddingService) GetDatabaseSchemaMetadata

func (s *AIEmbeddingService) GetDatabaseSchemaMetadata(configID int, databaseAlias string, iLog *logger.Log) ([]models.DatabaseSchemaEmbedding, error)

GetDatabaseSchemaMetadata retrieves schema metadata for a database

func (*AIEmbeddingService) GetDatabasesWithEmbeddings

func (s *AIEmbeddingService) GetDatabasesWithEmbeddings(configID int, iLog *logger.Log) ([]string, error)

GetDatabasesWithEmbeddings retrieves list of databases that have embeddings

func (*AIEmbeddingService) GetEmbeddingConfigStats

func (s *AIEmbeddingService) GetEmbeddingConfigStats(iLog *logger.Log) ([]models.EmbeddingConfigStats, error)

GetEmbeddingConfigStats retrieves embedding configuration statistics

func (*AIEmbeddingService) GetEmbeddingConfigurations

func (s *AIEmbeddingService) GetEmbeddingConfigurations(iLog *logger.Log) ([]models.AIEmbeddingConfiguration, error)

GetEmbeddingConfigurations retrieves all embedding configurations

func (*AIEmbeddingService) GetQueryTemplates

func (s *AIEmbeddingService) GetQueryTemplates(configID int, iLog *logger.Log) ([]models.AIQueryTemplate, error)

GetQueryTemplates retrieves all query templates

func (*AIEmbeddingService) SearchSchema

func (s *AIEmbeddingService) SearchSchema(ctx context.Context, req models.SearchRequest, embeddingFunc func(string) ([]float32, error), iLog *logger.Log) (*models.SearchResponse, error)

SearchSchema performs vector similarity search on schema embeddings

func (*AIEmbeddingService) UpdateBusinessEntity

func (s *AIEmbeddingService) UpdateBusinessEntity(ctx context.Context, id int, req models.BusinessEntityRequest, embeddingFunc func(string) ([]float32, error), iLog *logger.Log) (*models.AIBusinessEntity, error)

UpdateBusinessEntity updates an existing business entity

func (*AIEmbeddingService) UpdateQueryTemplate

func (s *AIEmbeddingService) UpdateQueryTemplate(ctx context.Context, id int, req models.QueryTemplateRequest, embeddingFunc func(string) ([]float32, error), iLog *logger.Log) (*models.AIQueryTemplate, error)

UpdateQueryTemplate updates an existing query template

type AIReportService

type AIReportService struct {
	OpenAIKey   string
	OpenAIModel string
}

AIReportService handles AI-powered report generation

func NewAIReportService

func NewAIReportService(openAIKey, openAIModel string) *AIReportService

NewAIReportService creates a new AI report service

func (*AIReportService) GenerateReport

GenerateReport generates report structure from query results

func (*AIReportService) GenerateSQL

func (s *AIReportService) GenerateSQL(ctx context.Context, request Text2SQLRequest, schemaInfo string) (*Text2SQLResponse, error)

GenerateSQL generates SQL from natural language using AI

type AITableInfo

type AITableInfo struct {
	TableName   string         `json:"table_name"`
	SchemaName  string         `json:"schema_name"`
	Description string         `json:"description"`
	Similarity  float64        `json:"similarity,omitempty"`
	Columns     []AIColumnInfo `json:"columns"`
}

AITableInfo contains table and its columns information for AI context

type BPMGenerationHandler

type BPMGenerationHandler struct {
	OpenAIKey   string
	OpenAIModel string
	// contains filtered or unexported fields
}

BPMGenerationHandler handles BPM flow generation

func (*BPMGenerationHandler) CanHandle

func (h *BPMGenerationHandler) CanHandle(ctx context.Context, intent string, editorType string) bool

func (*BPMGenerationHandler) GetName

func (h *BPMGenerationHandler) GetName() string

func (*BPMGenerationHandler) Handle

type BusinessEntityInfo

type BusinessEntityInfo struct {
	EntityName  string  `json:"entity_name"`
	EntityType  string  `json:"entity_type"`
	Description string  `json:"description"`
	Formula     string  `json:"formula,omitempty"`
	Similarity  float64 `json:"similarity,omitempty"`
}

BusinessEntityInfo contains business entity information

type BusinessEntityService

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

BusinessEntityService handles business entity management

func NewBusinessEntityService

func NewBusinessEntityService(db *gorm.DB) *BusinessEntityService

NewBusinessEntityService creates a new business entity service

func (*BusinessEntityService) CreateEntity

func (s *BusinessEntityService) CreateEntity(ctx context.Context, entity *models.BusinessEntity) error

CreateEntity creates a new business entity

func (*BusinessEntityService) DeleteEntity

func (s *BusinessEntityService) DeleteEntity(ctx context.Context, id string) error

DeleteEntity deletes a business entity

func (*BusinessEntityService) GetEntitiesByTable

func (s *BusinessEntityService) GetEntitiesByTable(ctx context.Context, databaseAlias, tableName string) ([]models.BusinessEntity, error)

GetEntitiesByTable retrieves business entities mapped to a specific table

func (*BusinessEntityService) GetEntity

GetEntity retrieves a business entity by ID

func (*BusinessEntityService) GetEntityContext

func (s *BusinessEntityService) GetEntityContext(ctx context.Context, databaseAlias string, entityNames []string) (string, error)

GetEntityContext builds business entity context for AI

func (*BusinessEntityService) ListEntities

func (s *BusinessEntityService) ListEntities(ctx context.Context, databaseAlias string) ([]models.BusinessEntity, error)

ListEntities retrieves all business entities for a database

func (*BusinessEntityService) SearchEntities

func (s *BusinessEntityService) SearchEntities(ctx context.Context, databaseAlias, keyword string) ([]models.BusinessEntity, error)

SearchEntities searches business entities by keyword

func (*BusinessEntityService) UpdateEntity

func (s *BusinessEntityService) UpdateEntity(ctx context.Context, id string, updates map[string]interface{}) error

UpdateEntity updates a business entity

type ChatService

type ChatService struct {
	DB                     *gorm.DB
	OpenAIKey              string
	OpenAIModel            string
	SchemaMetadataService  SchemaDiscoveryService
	SchemaEmbeddingService *SchemaEmbeddingService
	// contains filtered or unexported fields
}

ChatService handles chat and AI conversation features

func NewChatService

func NewChatService(db *gorm.DB, openAIKey, openAIModel string, schemaService SchemaDiscoveryService) *ChatService

NewChatService creates a new chat service

func (*ChatService) CreateConversation

func (s *ChatService) CreateConversation(userID, databaseAlias, title string, autoExecute bool) (*models.Conversation, error)

CreateConversation creates a new conversation

func (*ChatService) CreateEmbedding

func (s *ChatService) CreateEmbedding(ctx context.Context, text string) ([]float64, error)

CreateEmbedding creates a vector embedding for text using OpenAI

func (*ChatService) DeleteConversation

func (s *ChatService) DeleteConversation(id string) error

DeleteConversation soft deletes a conversation

func (*ChatService) ExecuteMessageSQL

func (s *ChatService) ExecuteMessageSQL(ctx context.Context, messageID string, modifiedSQL *string) (*models.ChatMessage, error)

ExecuteMessageSQL executes or re-executes SQL for a specific message

func (*ChatService) GetConversation

func (s *ChatService) GetConversation(id string) (*models.Conversation, error)

GetConversation retrieves a conversation by ID

func (*ChatService) GetMessage

func (s *ChatService) GetMessage(messageID string) (*models.ChatMessage, error)

GetMessage retrieves a single message by ID

func (*ChatService) ListConversations

func (s *ChatService) ListConversations(userID string, limit int) ([]models.Conversation, error)

ListConversations retrieves conversations for a user

func (*ChatService) ProcessMessage

func (s *ChatService) ProcessMessage(ctx context.Context, conversationID, userMessage, databaseAlias string, autoExecute bool) (*models.ChatMessage, error)

ProcessMessage processes a user message and generates AI response

func (*ChatService) SaveSchemaEmbedding

func (s *ChatService) SaveSchemaEmbedding(databaseAlias string, entityType models.EntityType, entityID, entityText string, embedding []float64) error

SaveSchemaEmbedding saves a schema embedding to the database

func (*ChatService) SearchSimilarSchemaElements

func (s *ChatService) SearchSimilarSchemaElements(ctx context.Context, databaseAlias, query string, limit int) ([]models.SchemaEmbedding, error)

SearchSimilarSchemaElements finds similar schema elements using vector search

type ClarificationQuestion

type ClarificationQuestion struct {
	Question string   `json:"question"`
	Type     string   `json:"type"` // "text", "choice", "confirm"
	Options  []string `json:"options,omitempty"`
	Required bool     `json:"required"`
}

ClarificationQuestion represents a question the AI needs answered

type CodeModificationHandler

type CodeModificationHandler struct {
	OpenAIKey   string
	OpenAIModel string
	// contains filtered or unexported fields
}

CodeModificationHandler handles code/query/script modifications for existing functions

func (*CodeModificationHandler) CanHandle

func (h *CodeModificationHandler) CanHandle(ctx context.Context, intent string, editorType string) bool

func (*CodeModificationHandler) GetName

func (h *CodeModificationHandler) GetName() string

func (*CodeModificationHandler) Handle

type CollectionService

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

CollectionService provides collection operations that work across multiple document DB types

func NewCollectionService

func NewCollectionService() *CollectionService

NewCollectionService creates a new collection service instance

func (*CollectionService) DeleteItem

func (s *CollectionService) DeleteItem(collectionName string, filter map[string]interface{}) error

DeleteItem deletes an item from the collection

func (*CollectionService) GetItemByField

func (s *CollectionService) GetItemByField(collectionName string, field string, value interface{}) (map[string]interface{}, error)

GetItemByField retrieves a single item by a specific field

func (*CollectionService) GetItemByID

func (s *CollectionService) GetItemByID(collectionName string, id string) (map[string]interface{}, error)

GetItemByID retrieves a single item by its ID

func (*CollectionService) InsertItem

func (s *CollectionService) InsertItem(collectionName string, data map[string]interface{}) (string, error)

InsertItem inserts a new item into the collection

func (*CollectionService) QueryCollection

func (s *CollectionService) QueryCollection(collectionName string, opts *QueryOptions) (*QueryResult, error)

QueryCollection queries a collection with pagination and filtering

func (*CollectionService) QueryCollectionLegacy

func (s *CollectionService) QueryCollectionLegacy(collectionName string, filter bson.M, projection bson.M) ([]bson.M, error)

QueryCollectionLegacy provides backward compatibility with the old DocDB.QueryCollection method

func (*CollectionService) UpdateItem

func (s *CollectionService) UpdateItem(collectionName string, filter map[string]interface{}, update map[string]interface{}) error

UpdateItem updates an item in the collection

type ColumnInfo

type ColumnInfo struct {
	ColumnName    string
	DataType      string
	IsNullable    string
	ColumnKey     string
	ColumnComment string
	OrdinalPos    int
}

ColumnInfo represents column metadata structure

type ComponentRecommendation

type ComponentRecommendation struct {
	ComponentType string                 `json:"component_type"`
	Name          string                 `json:"name"`
	X             float64                `json:"x"`
	Y             float64                `json:"y"`
	Width         float64                `json:"width"`
	Height        float64                `json:"height"`
	DataConfig    map[string]interface{} `json:"data_config"`
	ChartType     string                 `json:"chart_type,omitempty"`
	ChartConfig   map[string]interface{} `json:"chart_config,omitempty"`
	StyleConfig   map[string]interface{} `json:"style_config,omitempty"`
}

ComponentRecommendation represents an AI-recommended report component

type ConversationContext

type ConversationContext struct {
	SessionID           string                 `json:"session_id"`
	UserID              string                 `json:"user_id"`
	EditorType          string                 `json:"editor_type"` // "bpm", "page", "view", "workflow", "whiteboard", "report", "general"
	DatabaseAlias       string                 `json:"database_alias"`
	EntityID            string                 `json:"entity_id"`      // ID of BPM/Page/View being edited
	EntityContext       map[string]interface{} `json:"entity_context"` // Current state of the entity
	PageContext         map[string]interface{} `json:"page_context"`   // Current page context
	ConversationHistory []ConversationMessage  `json:"conversation_history"`
	Metadata            map[string]interface{} `json:"metadata"`
}

ConversationContext holds context about the current conversation

type ConversationMessage

type ConversationMessage struct {
	Role      string                 `json:"role"` // "user", "assistant", "system"
	Content   string                 `json:"content"`
	Timestamp time.Time              `json:"timestamp"`
	Metadata  map[string]interface{} `json:"metadata"`
}

ConversationMessage represents a single message in the conversation

type DataInsights

type DataInsights struct {
	Summary        string              `json:"summary"`
	KeyInsights    []string            `json:"key_insights"`
	Visualizations []VisualizationSpec `json:"visualizations"`
	DataAnalysis   DataStatistics      `json:"data_analysis"`
}

DataInsights represents AI-generated insights from query results

type DataStatistics

type DataStatistics struct {
	RowCount       int                    `json:"row_count"`
	ColumnCount    int                    `json:"column_count"`
	NumericColumns []string               `json:"numeric_columns"`
	DateColumns    []string               `json:"date_columns"`
	TextColumns    []string               `json:"text_columns"`
	TopValues      map[string]interface{} `json:"top_values,omitempty"`
}

DataStatistics contains basic statistics about the data

type DatabaseHelper

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

DatabaseHelper provides multi-database support for services It wraps the database selector and provides dialect-aware operations

func NewDatabaseHelper

func NewDatabaseHelper(selector *dbconn.DatabaseSelector, gormDB *gorm.DB) *DatabaseHelper

NewDatabaseHelper creates a new database helper

func (*DatabaseHelper) ExecuteDialectQuery

func (h *DatabaseHelper) ExecuteDialectQuery(ctx context.Context, db dbconn.RelationalDB, queryFunc func(dialectName string) string, args ...interface{}) (*sql.Rows, error)

ExecuteDialectQuery executes a query using the appropriate dialect

func (*DatabaseHelper) GetAppDB

func (h *DatabaseHelper) GetAppDB() *gorm.DB

GetAppDB returns the GORM database for IAC application's own tables

func (*DatabaseHelper) GetUserDB

func (h *DatabaseHelper) GetUserDB(ctx context.Context, databaseAlias string) (dbconn.RelationalDB, error)

GetUserDB gets a database connection for a user's database This uses the database selector to choose the appropriate database

func (*DatabaseHelper) GetUserDBForWrite

func (h *DatabaseHelper) GetUserDBForWrite(ctx context.Context, databaseAlias string) (dbconn.RelationalDB, error)

GetUserDBForWrite gets a database connection for write operations

type DatasourceExecutionResult

type DatasourceExecutionResult struct {
	Alias           string                   `json:"alias"`
	Columns         []string                 `json:"columns"`
	Rows            []map[string]interface{} `json:"rows"` // Primary field for frontend TableRenderer
	Data            []map[string]interface{} `json:"data"` // Backward compatibility
	TotalRows       int                      `json:"total_rows"`
	ExecutionTimeMs int64                    `json:"execution_time_ms"`
	SQL             string                   `json:"sql,omitempty"`
	Error           string                   `json:"error,omitempty"`
}

DatasourceExecutionResult represents the execution result of a single datasource

type EmbeddingField

type EmbeddingField []float64

EmbeddingField is a custom type for handling vector embeddings

func (*EmbeddingField) Scan

func (e *EmbeddingField) Scan(value interface{}) error

Scan implements the sql.Scanner interface

func (EmbeddingField) Value

func (e EmbeddingField) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type EmbeddingJobService

type EmbeddingJobService struct {
	DB                     *gorm.DB
	VectorDB               *gorm.DB // Vector database connection
	SchemaEmbeddingService *SchemaEmbeddingService
	// contains filtered or unexported fields
}

EmbeddingJobService handles async embedding generation jobs

func NewEmbeddingJobService

func NewEmbeddingJobService(db *gorm.DB, openAIKey string) *EmbeddingJobService

NewEmbeddingJobService creates a new embedding job service

func (*EmbeddingJobService) CreateEmbeddingJob

func (s *EmbeddingJobService) CreateEmbeddingJob(databaseAlias string, jobType string, tableNames []string, force bool) (*models.EmbeddingGenerationJob, error)

CreateEmbeddingJob creates a new embedding generation job

func (*EmbeddingJobService) GetJob

GetJob retrieves a job by ID

func (*EmbeddingJobService) GetJobByUUID

func (s *EmbeddingJobService) GetJobByUUID(uuid string) (*models.EmbeddingGenerationJob, error)

GetJobByUUID retrieves a job by UUID

func (*EmbeddingJobService) ProcessEmbeddingJobAsync

func (s *EmbeddingJobService) ProcessEmbeddingJobAsync(jobID int, databaseAlias string, tableNames []string, force bool)

ProcessEmbeddingJobAsync starts an async job to generate embeddings

func (*EmbeddingJobService) UpdateJobProgress

func (s *EmbeddingJobService) UpdateJobProgress(jobID int, totalItems, processedItems, failedItems int) error

UpdateJobProgress updates the job progress

func (*EmbeddingJobService) UpdateJobStatus

func (s *EmbeddingJobService) UpdateJobStatus(jobID int, status string, errorMsg *string) error

UpdateJobStatus updates the job status and related fields

type EmbeddingRequest

type EmbeddingRequest struct {
	Input string `json:"input"`
	Model string `json:"model"`
}

EmbeddingRequest represents OpenAI embedding API request

type EmbeddingResponse

type EmbeddingResponse struct {
	Data []struct {
		Embedding []float64 `json:"embedding"`
		Index     int       `json:"index"`
	} `json:"data"`
	Model string `json:"model"`
	Usage struct {
		PromptTokens int `json:"prompt_tokens"`
		TotalTokens  int `json:"total_tokens"`
	} `json:"usage"`
}

EmbeddingResponse represents OpenAI embedding API response

type ExecutionData

type ExecutionData struct {
	Datasources map[string]DatasourceExecutionResult `json:"datasources"`
}

ExecutionData wraps the datasource results to match frontend expectations

type ExecutionRequest

type ExecutionRequest struct {
	Parameters   map[string]interface{} `json:"parameters"`
	OutputFormat string                 `json:"output_format"`
}

ExecutionRequest represents a report execution request

type ExecutionResult

type ExecutionResult struct {
	ReportID        string                 `json:"report_id"`
	ReportName      string                 `json:"report_name"`
	ExecutedBy      string                 `json:"executed_by"`
	ExecutedAt      time.Time              `json:"executed_at"`
	Parameters      map[string]interface{} `json:"parameters"`
	OutputFormat    string                 `json:"output_format"`
	Status          string                 `json:"status"`
	ExecutionTimeMs int64                  `json:"execution_time_ms"`
	Data            ExecutionData          `json:"data"`
	ErrorMessage    string                 `json:"error_message,omitempty"`
}

ExecutionResult represents the result of a report execution

type GeneralQuestionHandler

type GeneralQuestionHandler struct {
	OpenAIKey   string
	OpenAIModel string
	// contains filtered or unexported fields
}

GeneralQuestionHandler handles general Q&A questions

func (*GeneralQuestionHandler) CanHandle

func (h *GeneralQuestionHandler) CanHandle(ctx context.Context, intent string, editorType string) bool

func (*GeneralQuestionHandler) GetName

func (h *GeneralQuestionHandler) GetName() string

func (*GeneralQuestionHandler) Handle

type IndexInfo

type IndexInfo struct {
	IndexName  string
	ColumnName string
	NonUnique  int
	SeqInIndex int
	IndexType  string
}

IndexInfo represents index information

type JobService

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

JobService provides methods for managing jobs

func NewJobService

func NewJobService(db *sql.DB) *JobService

NewJobService creates a new job service instance

func (*JobService) CreateJobFromIntegrationMessage

func (js *JobService) CreateJobFromIntegrationMessage(ctx context.Context, method, protocol, direction, handler, payload string, metadata models.JobMetadata) (*models.QueueJob, error)

CreateJobFromIntegrationMessage creates a queue job from an integration message

func (*JobService) CreateJobHistory

func (js *JobService) CreateJobHistory(ctx context.Context, history *models.JobHistory) error

CreateJobHistory creates a job execution history record

func (*JobService) CreateQueueJob

func (js *JobService) CreateQueueJob(ctx context.Context, job *models.QueueJob) error

CreateQueueJob creates a new job in the queue

func (*JobService) GetJobByID

func (js *JobService) GetJobByID(ctx context.Context, jobID string) (*models.QueueJob, error)

GetJobByID retrieves a job by its ID

func (*JobService) GetJobStatistics

func (js *JobService) GetJobStatistics(ctx context.Context) (map[string]interface{}, error)

GetJobStatistics retrieves job statistics

func (*JobService) GetNextPendingJob

func (js *JobService) GetNextPendingJob(ctx context.Context) (*models.QueueJob, error)

GetNextPendingJob retrieves the next pending job from the queue

func (*JobService) GetScheduledJobs

func (js *JobService) GetScheduledJobs(ctx context.Context) ([]*models.Job, error)

GetScheduledJobs retrieves all enabled scheduled jobs that should run

func (*JobService) IncrementRetryCount

func (js *JobService) IncrementRetryCount(ctx context.Context, jobID string) error

IncrementRetryCount increments the retry count for a job

func (*JobService) UpdateQueueJobStatus

func (js *JobService) UpdateQueueJobStatus(ctx context.Context, jobID string, statusID int, result string, errorMsg string) error

UpdateQueueJobStatus updates the status of a queue job

func (*JobService) UpdateScheduledJobNextRun

func (js *JobService) UpdateScheduledJobNextRun(ctx context.Context, jobID string, nextRunAt time.Time) error

UpdateScheduledJobNextRun updates the next run time for a scheduled job

type OpenAIMessage

type OpenAIMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

OpenAIMessage represents a message in the OpenAI API

type OpenAIRequest

type OpenAIRequest struct {
	Model       string          `json:"model"`
	Messages    []OpenAIMessage `json:"messages"`
	Temperature float64         `json:"temperature"`
}

OpenAIRequest represents a request to the OpenAI API

type OpenAIResponse

type OpenAIResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Created int64  `json:"created"`
	Model   string `json:"model"`
	Choices []struct {
		Index   int `json:"index"`
		Message struct {
			Role    string `json:"role"`
			Content string `json:"content"`
		} `json:"message"`
		FinishReason string `json:"finish_reason"`
	} `json:"choices"`
}

OpenAIResponse represents a response from the OpenAI API

type PageGenerationHandler

type PageGenerationHandler struct {
	OpenAIKey   string
	OpenAIModel string
	// contains filtered or unexported fields
}

PageGenerationHandler handles page structure generation

func (*PageGenerationHandler) CanHandle

func (h *PageGenerationHandler) CanHandle(ctx context.Context, intent string, editorType string) bool

func (*PageGenerationHandler) GetName

func (h *PageGenerationHandler) GetName() string

func (*PageGenerationHandler) Handle

type QueryGenerationHandler

type QueryGenerationHandler struct {
	AIReportService        *AIReportService
	SchemaMetadataService  *SchemaMetadataService
	SchemaEmbeddingService *SchemaEmbeddingService
	OpenAIKey              string
	OpenAIModel            string
	// contains filtered or unexported fields
}

QueryGenerationHandler handles SQL query generation

func (*QueryGenerationHandler) CanHandle

func (h *QueryGenerationHandler) CanHandle(ctx context.Context, intent string, editorType string) bool

func (*QueryGenerationHandler) GetName

func (h *QueryGenerationHandler) GetName() string

func (*QueryGenerationHandler) Handle

type QueryOptions

type QueryOptions struct {
	Filter     map[string]interface{} // Root element filters
	Projection map[string]interface{} // Fields to include/exclude
	PageSize   int                    // Number of items per page (limit)
	Page       int                    // Page number (starts at 1)
	Sort       map[string]int         // Sort fields: 1 for asc, -1 for desc
}

QueryOptions represents options for querying collections

type QueryResult

type QueryResult struct {
	Data       []map[string]interface{} `json:"data"`
	TotalCount int64                    `json:"total_count"`
	Page       int                      `json:"page"`
	PageSize   int                      `json:"page_size"`
	TotalPages int                      `json:"total_pages"`
}

QueryResult represents the result of a collection query with pagination

type QueryTemplateInfo

type QueryTemplateInfo struct {
	TemplateName string  `json:"template_name"`
	Category     string  `json:"category"`
	Description  string  `json:"description"`
	SQLTemplate  string  `json:"sql_template"`
	Similarity   float64 `json:"similarity,omitempty"`
}

QueryTemplateInfo contains query template information

type QueryTemplateService

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

QueryTemplateService handles query template management

func NewQueryTemplateService

func NewQueryTemplateService(db *gorm.DB) *QueryTemplateService

NewQueryTemplateService creates a new query template service

func (*QueryTemplateService) CreateTemplate

func (s *QueryTemplateService) CreateTemplate(ctx context.Context, template *models.QueryTemplate) error

CreateTemplate creates a new query template

func (*QueryTemplateService) DeleteTemplate

func (s *QueryTemplateService) DeleteTemplate(ctx context.Context, id string) error

DeleteTemplate deletes a query template

func (*QueryTemplateService) GetCategories

func (s *QueryTemplateService) GetCategories(ctx context.Context, databaseAlias string) ([]string, error)

GetCategories retrieves distinct categories for a database

func (*QueryTemplateService) GetTemplate

func (s *QueryTemplateService) GetTemplate(ctx context.Context, id string) (*models.QueryTemplate, error)

GetTemplate retrieves a query template by ID

func (*QueryTemplateService) GetTemplateContext

func (s *QueryTemplateService) GetTemplateContext(ctx context.Context, databaseAlias string, limit int) (string, error)

GetTemplateContext builds query template context for AI

func (*QueryTemplateService) GetTemplatesByIntent

func (s *QueryTemplateService) GetTemplatesByIntent(ctx context.Context, databaseAlias, intent string) ([]models.QueryTemplate, error)

GetTemplatesByIntent searches templates by natural language intent

func (*QueryTemplateService) IncrementUsageCount

func (s *QueryTemplateService) IncrementUsageCount(ctx context.Context, id string) error

IncrementUsageCount increments the usage count of a template

func (*QueryTemplateService) ListTemplates

func (s *QueryTemplateService) ListTemplates(ctx context.Context, databaseAlias string) ([]models.QueryTemplate, error)

ListTemplates retrieves all query templates for a database

func (*QueryTemplateService) SearchTemplates

func (s *QueryTemplateService) SearchTemplates(ctx context.Context, databaseAlias, keyword string) ([]models.QueryTemplate, error)

SearchTemplates searches query templates by keyword

func (*QueryTemplateService) UpdateTemplate

func (s *QueryTemplateService) UpdateTemplate(ctx context.Context, id string, updates map[string]interface{}) error

UpdateTemplate updates a query template

type ReportDocService

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

ReportDocService handles business logic for report documents in MongoDB

func NewReportDocService

func NewReportDocService(docDB documents.DocumentDB) *ReportDocService

NewReportDocService creates a new report document service

func (*ReportDocService) AddComponent

func (s *ReportDocService) AddComponent(ctx context.Context, reportID string, component schema.ReportComponentDoc, modifiedBy string) error

AddComponent adds a component to a report

func (*ReportDocService) AddDatasource

func (s *ReportDocService) AddDatasource(ctx context.Context, reportID string, datasource schema.ReportDatasourceDoc, modifiedBy string) error

AddDatasource adds a data source to a report

func (*ReportDocService) AddExecution

func (s *ReportDocService) AddExecution(ctx context.Context, reportID string, execution schema.ReportExecutionDoc) error

AddExecution records a report execution

func (*ReportDocService) AddParameter

func (s *ReportDocService) AddParameter(ctx context.Context, reportID string, parameter schema.ReportParameterDoc, modifiedBy string) error

AddParameter adds a parameter to a report

func (*ReportDocService) CreateReport

func (s *ReportDocService) CreateReport(ctx context.Context, report *schema.ReportDocument, createdBy string) (string, error)

CreateReport creates a new report document

func (*ReportDocService) DeleteReport

func (s *ReportDocService) DeleteReport(ctx context.Context, id string, deletedBy string) error

DeleteReport soft deletes a report

func (*ReportDocService) GetDefaultReport

func (s *ReportDocService) GetDefaultReport(ctx context.Context) (*schema.ReportDocument, error)

GetDefaultReport retrieves the default report

func (*ReportDocService) GetReportByID

func (s *ReportDocService) GetReportByID(ctx context.Context, id string) (*schema.ReportDocument, error)

GetReportByID retrieves a report by its ID

func (*ReportDocService) GetReportByName

func (s *ReportDocService) GetReportByName(ctx context.Context, name string) (*schema.ReportDocument, error)

GetReportByName retrieves a report by its name

func (*ReportDocService) GetReportsByCategory

func (s *ReportDocService) GetReportsByCategory(ctx context.Context, category string, page, pageSize int) ([]*schema.ReportDocument, int64, error)

GetReportsByCategory retrieves reports by category

func (*ReportDocService) InitializeIndexes

func (s *ReportDocService) InitializeIndexes(ctx context.Context) error

InitializeIndexes creates the required indexes for the Reports collection

func (*ReportDocService) ListReports

func (s *ReportDocService) ListReports(ctx context.Context, userID string, isPublic bool, category string, reportType string, page, pageSize int) ([]*schema.ReportDocument, int64, error)

ListReports retrieves reports with filtering, sorting, and pagination

func (*ReportDocService) SearchReports

func (s *ReportDocService) SearchReports(ctx context.Context, searchText string, page, pageSize int) ([]*schema.ReportDocument, int64, error)

SearchReports performs text search on reports

func (*ReportDocService) SetDefaultReport

func (s *ReportDocService) SetDefaultReport(ctx context.Context, reportID string, modifiedBy string) error

SetDefaultReport sets a report as the default

func (*ReportDocService) UpdateReport

func (s *ReportDocService) UpdateReport(ctx context.Context, id string, updates map[string]interface{}, modifiedBy string) error

UpdateReport updates a report document

func (*ReportDocService) UpdateReportRevision

func (s *ReportDocService) UpdateReportRevision(ctx context.Context, id string, modifiedBy string) error

UpdateReportRevision increments the revision number

type ReportExecutionService

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

ReportExecutionService handles report execution logic

func NewReportExecutionService

func NewReportExecutionService(schemaMetadataService *SchemaMetadataService) *ReportExecutionService

NewReportExecutionService creates a new report execution service

func (*ReportExecutionService) ExecuteReport

func (s *ReportExecutionService) ExecuteReport(
	ctx context.Context,
	report *schema.ReportDocument,
	request ExecutionRequest,
	executedBy string,
) (*ExecutionResult, error)

ExecuteReport executes a report and returns the results

type ReportGenerationRequest

type ReportGenerationRequest struct {
	Question   string                   `json:"question"`
	SQL        string                   `json:"sql"`
	Data       []map[string]interface{} `json:"data"`
	ReportName string                   `json:"report_name,omitempty"`
}

ReportGenerationRequest represents a request to generate a report from data

type ReportGenerationResponse

type ReportGenerationResponse struct {
	Title       string                    `json:"title"`
	Description string                    `json:"description"`
	Components  []ComponentRecommendation `json:"components"`
	Insights    []string                  `json:"insights"`
}

ReportGenerationResponse represents the AI-generated report structure

type ReportService

type ReportService struct {
	DB *gorm.DB
}

ReportService handles report business logic

func NewReportService

func NewReportService(db *gorm.DB) *ReportService

NewReportService creates a new report service

func (*ReportService) AddComponent

func (s *ReportService) AddComponent(component *models.ReportComponent) error

AddComponent adds a component to a report

func (*ReportService) AddDatasource

func (s *ReportService) AddDatasource(datasource *models.ReportDatasource) error

AddDatasource adds a datasource to a report

func (*ReportService) AddParameter

func (s *ReportService) AddParameter(parameter *models.ReportParameter) error

AddParameter adds a parameter to a report

func (*ReportService) CreateExecution

func (s *ReportService) CreateExecution(execution *models.ReportExecution) error

CreateExecution creates a new execution record

func (*ReportService) CreateFromTemplate

func (s *ReportService) CreateFromTemplate(templateID, userID string) (*models.Report, error)

CreateFromTemplate creates a report from a template

func (*ReportService) CreateReport

func (s *ReportService) CreateReport(report *models.Report) error

CreateReport creates a new report

func (*ReportService) DeleteComponent

func (s *ReportService) DeleteComponent(id string) error

DeleteComponent deletes a component

func (*ReportService) DeleteDatasource

func (s *ReportService) DeleteDatasource(id string) error

DeleteDatasource deletes a datasource

func (*ReportService) DeleteParameter

func (s *ReportService) DeleteParameter(id string) error

DeleteParameter deletes a parameter

func (*ReportService) DeleteReport

func (s *ReportService) DeleteReport(id string) error

DeleteReport soft deletes a report

func (*ReportService) DuplicateReport

func (s *ReportService) DuplicateReport(reportID, userID string) (*models.Report, error)

DuplicateReport creates a copy of an existing report

func (*ReportService) ExecuteReportQuery

func (s *ReportService) ExecuteReportQuery(reportID string, parameters map[string]interface{}) (map[string]interface{}, error)

ExecuteReportQuery executes all datasource queries for a report

func (*ReportService) GetAllComponents

func (s *ReportService) GetAllComponents(reportID string) ([]models.ReportComponent, error)

GetAllComponents retrieves all components for a report (including invisible)

func (*ReportService) GetComponents

func (s *ReportService) GetComponents(reportID string) ([]models.ReportComponent, error)

GetComponents retrieves all visible components for a report

func (*ReportService) GetDatasources

func (s *ReportService) GetDatasources(reportID string) ([]models.ReportDatasource, error)

GetDatasources retrieves all datasources for a report

func (*ReportService) GetExecutionHistory

func (s *ReportService) GetExecutionHistory(reportID string, limit int) ([]models.ReportExecution, error)

GetExecutionHistory retrieves execution history for a report

func (*ReportService) GetParameters

func (s *ReportService) GetParameters(reportID string) ([]models.ReportParameter, error)

GetParameters retrieves all parameters for a report

func (*ReportService) GetReportByID

func (s *ReportService) GetReportByID(id string) (*models.Report, error)

GetReportByID retrieves a report by ID with all relationships

func (*ReportService) GetShareByToken

func (s *ReportService) GetShareByToken(token string) (*models.ReportShare, error)

GetShareByToken retrieves a share by token

func (*ReportService) GetShares

func (s *ReportService) GetShares(reportID string) ([]models.ReportShare, error)

GetShares retrieves all shares for a report

func (*ReportService) GetTemplateByID

func (s *ReportService) GetTemplateByID(id string) (*models.ReportTemplate, error)

GetTemplateByID retrieves a template by ID

func (*ReportService) HardDeleteReport

func (s *ReportService) HardDeleteReport(id string) error

HardDeleteReport permanently deletes a report

func (*ReportService) ListReports

func (s *ReportService) ListReports(userID string, isPublic bool, reportType string, page, pageSize int) ([]models.Report, int64, error)

ListReports retrieves reports with pagination and filtering

func (*ReportService) ListTemplates

func (s *ReportService) ListTemplates(category string, isPublic bool) ([]models.ReportTemplate, error)

ListTemplates retrieves report templates

func (*ReportService) RevokeShare

func (s *ReportService) RevokeShare(id string) error

RevokeShare deactivates a share

func (*ReportService) SearchReports

func (s *ReportService) SearchReports(keyword string, userID string, limit int) ([]models.Report, error)

SearchReports searches reports by name or description

func (*ReportService) ShareReport

func (s *ReportService) ShareReport(share *models.ReportShare) error

ShareReport creates a share record

func (*ReportService) UpdateComponent

func (s *ReportService) UpdateComponent(id string, updates map[string]interface{}) error

UpdateComponent updates a component

func (*ReportService) UpdateDatasource

func (s *ReportService) UpdateDatasource(id string, updates map[string]interface{}) error

UpdateDatasource updates a datasource

func (*ReportService) UpdateExecution

func (s *ReportService) UpdateExecution(id string, updates map[string]interface{}) error

UpdateExecution updates an execution record

func (*ReportService) UpdateLastExecutedAt

func (s *ReportService) UpdateLastExecutedAt(reportID string) error

UpdateLastExecutedAt updates the last execution timestamp

func (*ReportService) UpdateParameter

func (s *ReportService) UpdateParameter(id string, updates map[string]interface{}) error

UpdateParameter updates a parameter

func (*ReportService) UpdateReport

func (s *ReportService) UpdateReport(id string, updates map[string]interface{}) error

UpdateReport updates an existing report

type SchemaContext

type SchemaContext struct {
	Tables           []AITableInfo        `json:"tables"`
	BusinessEntities []BusinessEntityInfo `json:"business_entities"`
	QueryTemplates   []QueryTemplateInfo  `json:"query_templates"`
	TotalTables      int                  `json:"total_tables"`
	TotalEntities    int                  `json:"total_entities"`
	TotalTemplates   int                  `json:"total_templates"`
}

SchemaContext represents the schema context for AI

type SchemaContextService

type SchemaContextService struct {
	DB                     *gorm.DB
	VectorDB               *gorm.DB
	SchemaEmbeddingService *SchemaEmbeddingService
	// contains filtered or unexported fields
}

SchemaContextService provides schema context for AI chat and report generation Uses vector search to find relevant tables, columns, business entities, and query templates

func NewSchemaContextService

func NewSchemaContextService(db *gorm.DB, openAIKey string) *SchemaContextService

NewSchemaContextService creates a new schema context service

func (*SchemaContextService) FormatSchemaContextForAI

func (s *SchemaContextService) FormatSchemaContextForAI(context *SchemaContext) string

FormatSchemaContextForAI formats the schema context as a string for AI prompt

func (*SchemaContextService) GetSchemaContextByQuery

func (s *SchemaContextService) GetSchemaContextByQuery(ctx context.Context, databaseAlias, naturalLanguageQuery string, maxTables int) (*SchemaContext, error)

GetSchemaContextByQuery retrieves relevant schema context using natural language query Uses vector search to find the most relevant tables, columns, entities, and templates

type SchemaDiscoveryService

type SchemaDiscoveryService interface {
	GetDatabaseMetadata(ctx context.Context, databaseAlias string) ([]models.DatabaseSchemaMetadata, error)
}

SchemaDiscoveryService is an interface for services that can discover database schema

type SchemaEmbeddingService

type SchemaEmbeddingService struct {
	DB                    *gorm.DB
	VectorDB              *gorm.DB // Separate vector database connection
	OpenAIKey             string
	ModelName             string
	ConfigID              int // Default config ID for embeddings in vector tables
	SchemaMetadataService *SchemaMetadataService
	// contains filtered or unexported fields
}

SchemaEmbeddingService handles vector embedding generation and storage for schema elements

func NewSchemaEmbeddingService

func NewSchemaEmbeddingService(db *gorm.DB, openAIKey string) *SchemaEmbeddingService

NewSchemaEmbeddingService creates a new schema embedding service

func (*SchemaEmbeddingService) GenerateAndStoreColumnEmbedding

func (s *SchemaEmbeddingService) GenerateAndStoreColumnEmbedding(ctx context.Context, databaseAlias string, meta *models.DatabaseSchemaMetadata) error

GenerateAndStoreColumnEmbedding generates and stores embedding for a column in database_schema_embeddings

func (*SchemaEmbeddingService) GenerateAndStoreTableEmbedding

func (s *SchemaEmbeddingService) GenerateAndStoreTableEmbedding(ctx context.Context, databaseAlias string, meta *models.DatabaseSchemaMetadata) error

GenerateAndStoreTableEmbedding generates and stores embedding for a table in database_schema_embeddings

func (*SchemaEmbeddingService) GenerateBusinessEntityEmbedding

func (s *SchemaEmbeddingService) GenerateBusinessEntityEmbedding(ctx context.Context, entity *models.BusinessEntity) error

GenerateBusinessEntityEmbedding generates and stores embedding for a business entity

func (*SchemaEmbeddingService) GenerateColumnEmbedding

func (s *SchemaEmbeddingService) GenerateColumnEmbedding(ctx context.Context, metadata *models.DatabaseSchemaMetadata) error

GenerateColumnEmbedding generates and stores embedding for a column metadata entry

func (*SchemaEmbeddingService) GenerateEmbedding

func (s *SchemaEmbeddingService) GenerateEmbedding(ctx context.Context, text string) ([]float64, error)

GenerateEmbedding generates a vector embedding for text using OpenAI

func (*SchemaEmbeddingService) GenerateEmbeddingsForDatabase

func (s *SchemaEmbeddingService) GenerateEmbeddingsForDatabase(ctx context.Context, databaseAlias string) error

GenerateEmbeddingsForDatabase generates embeddings for all schema metadata in a database Stores embeddings in the database_schema_embeddings vector table

func (*SchemaEmbeddingService) GenerateTableEmbedding

func (s *SchemaEmbeddingService) GenerateTableEmbedding(ctx context.Context, metadata *models.DatabaseSchemaMetadata) error

GenerateTableEmbedding generates and stores embedding for a table metadata entry

func (*SchemaEmbeddingService) SearchSimilarBusinessEntities

func (s *SchemaEmbeddingService) SearchSimilarBusinessEntities(ctx context.Context, databaseAlias, query string, limit int) ([]models.BusinessEntity, error)

SearchSimilarBusinessEntities finds business entities similar to the query using vector search

func (*SchemaEmbeddingService) SearchSimilarColumns

func (s *SchemaEmbeddingService) SearchSimilarColumns(ctx context.Context, databaseAlias, query string, limit int) ([]models.DatabaseSchemaMetadata, error)

SearchSimilarColumns finds columns by first doing vector search on tables, then retrieving all columns for those tables This approach ensures we don't miss any columns that might not have embeddings

func (*SchemaEmbeddingService) SearchSimilarTables

func (s *SchemaEmbeddingService) SearchSimilarTables(ctx context.Context, databaseAlias, query string, limit int) ([]models.DatabaseSchemaMetadata, error)

SearchSimilarTables finds tables similar to the query using vector search

type SchemaMetadataService

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

SchemaMetadataService handles database schema discovery and metadata management

func NewSchemaMetadataService

func NewSchemaMetadataService(db *gorm.DB) *SchemaMetadataService

NewSchemaMetadataService creates a new schema metadata service db: The vector database connection for storing/checking embeddings

func (*SchemaMetadataService) DeleteMetadata

func (s *SchemaMetadataService) DeleteMetadata(ctx context.Context, id string) error

DeleteMetadata deletes a metadata entry

func (*SchemaMetadataService) DiscoverDatabaseSchema

func (s *SchemaMetadataService) DiscoverDatabaseSchema(ctx context.Context, databaseAlias, dbName string) error

DiscoverDatabaseSchema discovers all tables and columns in a database

func (*SchemaMetadataService) ExecuteCustomSQL

func (s *SchemaMetadataService) ExecuteCustomSQL(ctx context.Context, databaseAlias string, sqlQuery string) (map[string]interface{}, error)

ExecuteCustomSQL executes a custom SQL query

func (*SchemaMetadataService) ExecuteVisualQuery

func (s *SchemaMetadataService) ExecuteVisualQuery(ctx context.Context, databaseAlias string, visualQuery map[string]interface{}) (map[string]interface{}, error)

ExecuteVisualQuery converts a visual query structure to SQL and executes it

func (*SchemaMetadataService) GetAllDatabases

func (s *SchemaMetadataService) GetAllDatabases(ctx context.Context) ([]string, error)

GetAllDatabases returns a list of all unique database aliases

func (*SchemaMetadataService) GetColumnMetadata

func (s *SchemaMetadataService) GetColumnMetadata(ctx context.Context, databaseAlias, tableName string) ([]models.DatabaseSchemaMetadata, error)

GetColumnMetadata retrieves metadata for all columns in a table IMPORTANT: This dynamically discovers columns from the actual target database Columns are NOT stored or embedded - always retrieved fresh from the database

func (*SchemaMetadataService) GetDatabaseMetadata

func (s *SchemaMetadataService) GetDatabaseMetadata(ctx context.Context, databaseAlias string) ([]models.DatabaseSchemaMetadata, error)

GetDatabaseMetadata retrieves complete metadata (tables and columns) for a database If no metadata exists or existing metadata is incomplete, it automatically discovers and populates it from information_schema

func (*SchemaMetadataService) GetSchemaContext

func (s *SchemaMetadataService) GetSchemaContext(ctx context.Context, databaseAlias string, tableNames []string) (string, error)

GetSchemaContext builds a comprehensive schema context for AI

func (*SchemaMetadataService) GetTableDetail

func (s *SchemaMetadataService) GetTableDetail(ctx context.Context, databaseAlias, tableName, schemaName string) (map[string]interface{}, error)

GetTableDetail retrieves detailed information about a specific table including its columns

func (*SchemaMetadataService) GetTableMetadata

func (s *SchemaMetadataService) GetTableMetadata(ctx context.Context, databaseAlias string) ([]models.DatabaseSchemaMetadata, error)

GetTableMetadata retrieves metadata for all tables in a database IMPORTANT: This dynamically discovers tables from the actual target database and checks the vector database for embeddings (does NOT query stored metadata)

func (*SchemaMetadataService) SearchMetadata

func (s *SchemaMetadataService) SearchMetadata(ctx context.Context, databaseAlias, keyword string) ([]models.DatabaseSchemaMetadata, error)

SearchMetadata searches metadata by keyword

func (*SchemaMetadataService) UpdateMetadata

func (s *SchemaMetadataService) UpdateMetadata(ctx context.Context, id string, description *string) error

UpdateMetadata updates the description for a metadata entry

func (*SchemaMetadataService) ValidateSQL

func (s *SchemaMetadataService) ValidateSQL(ctx context.Context, databaseAlias string, sqlQuery string) (map[string]interface{}, error)

ValidateSQL validates SQL syntax without executing it

type SchemaMetadataServiceMultiDB

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

SchemaMetadataServiceMultiDB provides multi-database schema discovery This is an enhanced version of SchemaMetadataService that supports all database types

func NewSchemaMetadataServiceMultiDB

func NewSchemaMetadataServiceMultiDB(dbHelper *DatabaseHelper, appDB *gorm.DB) *SchemaMetadataServiceMultiDB

NewSchemaMetadataServiceMultiDB creates a new multi-database schema metadata service

func (*SchemaMetadataServiceMultiDB) DiscoverIndexes

func (s *SchemaMetadataServiceMultiDB) DiscoverIndexes(ctx context.Context, databaseAlias, schemaName, tableName string) ([]IndexInfo, error)

DiscoverIndexes discovers all indexes for a specific table

func (*SchemaMetadataServiceMultiDB) DiscoverSchema

func (s *SchemaMetadataServiceMultiDB) DiscoverSchema(ctx context.Context, databaseAlias, schemaName string) error

DiscoverSchema discovers all tables and columns in a user database This method supports all database types (MySQL, PostgreSQL, MSSQL, Oracle)

func (*SchemaMetadataServiceMultiDB) ExecuteQuery

func (s *SchemaMetadataServiceMultiDB) ExecuteQuery(ctx context.Context, databaseAlias, query string, args ...interface{}) (*sql.Rows, error)

ExecuteQuery executes a custom SQL query against a user database This is useful for ad-hoc queries with dialect-aware execution

func (*SchemaMetadataServiceMultiDB) GetColumnMetadata

func (s *SchemaMetadataServiceMultiDB) GetColumnMetadata(ctx context.Context, databaseAlias, tableName string) ([]models.DatabaseSchemaMetadata, error)

GetColumnMetadata retrieves metadata for all columns in a table

func (*SchemaMetadataServiceMultiDB) GetDatabaseMetadata

func (s *SchemaMetadataServiceMultiDB) GetDatabaseMetadata(ctx context.Context, databaseAlias string) ([]models.DatabaseSchemaMetadata, error)

GetDatabaseMetadata retrieves complete metadata (tables and columns) for a database If no metadata exists, it automatically discovers and populates it from the database schema

func (*SchemaMetadataServiceMultiDB) GetSchemaContext

func (s *SchemaMetadataServiceMultiDB) GetSchemaContext(ctx context.Context, databaseAlias string, tableNames []string) (string, error)

GetSchemaContext builds a comprehensive schema context for AI

func (*SchemaMetadataServiceMultiDB) GetTableMetadata

func (s *SchemaMetadataServiceMultiDB) GetTableMetadata(ctx context.Context, databaseAlias string) ([]models.DatabaseSchemaMetadata, error)

GetTableMetadata retrieves metadata for all tables in a database

func (*SchemaMetadataServiceMultiDB) UpdateMetadata

func (s *SchemaMetadataServiceMultiDB) UpdateMetadata(ctx context.Context, id string, description *string) error

UpdateMetadata updates the description for a metadata entry

type SchemaQuery

type SchemaQuery struct {
	Dialect string
	Query   string
}

SchemaQuery represents a database schema discovery query

type ServiceFactory

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

ServiceFactory creates service instances with multi-database support

func NewServiceFactory

func NewServiceFactory(poolManager *dbconn.PoolManager, appDB *gorm.DB) (*ServiceFactory, error)

NewServiceFactory creates a new service factory

func (*ServiceFactory) Close

func (f *ServiceFactory) Close() error

Close closes all database connections (call on shutdown)

func (*ServiceFactory) GetAIEmbeddingService

func (f *ServiceFactory) GetAIEmbeddingService() *AIEmbeddingService

GetAIEmbeddingService returns the AI embedding service

func (*ServiceFactory) GetAppDB

func (f *ServiceFactory) GetAppDB() *gorm.DB

GetAppDB returns the application's GORM database instance

func (*ServiceFactory) GetBusinessEntityService

func (f *ServiceFactory) GetBusinessEntityService() *BusinessEntityService

GetBusinessEntityService returns the business entity service

func (*ServiceFactory) GetDatabaseHelper

func (f *ServiceFactory) GetDatabaseHelper() *DatabaseHelper

GetDatabaseHelper returns the database helper for custom operations

func (*ServiceFactory) GetQueryTemplateService

func (f *ServiceFactory) GetQueryTemplateService() *QueryTemplateService

GetQueryTemplateService returns the query template service

func (*ServiceFactory) GetSchemaMetadataService

func (f *ServiceFactory) GetSchemaMetadataService() *SchemaMetadataService

GetSchemaMetadataService returns the schema metadata service (legacy)

func (*ServiceFactory) GetSchemaMetadataServiceMultiDB

func (f *ServiceFactory) GetSchemaMetadataServiceMultiDB() *SchemaMetadataServiceMultiDB

GetSchemaMetadataServiceMultiDB returns the multi-database schema metadata service

type TableColumnInfo

type TableColumnInfo struct {
	Name string
	Type string
}

type TableInfo

type TableInfo struct {
	TableName    string
	TableComment string
	TableSchema  string
}

TableInfo represents table metadata structure

type Text2SQLRequest

type Text2SQLRequest struct {
	Question    string `json:"question"`
	DatabaseID  string `json:"database_id"`
	AutoExecute bool   `json:"auto_execute"`
	ThreadID    string `json:"thread_id,omitempty"`
}

Text2SQLRequest represents a natural language question

type Text2SQLResponse

type Text2SQLResponse struct {
	SQL         string                   `json:"sql"`
	Explanation string                   `json:"explanation"`
	Confidence  float64                  `json:"confidence"`
	TablesUsed  []string                 `json:"tables_used"`
	ColumnsUsed []string                 `json:"columns_used"`
	Reasoning   string                   `json:"reasoning"`
	QueryType   string                   `json:"query_type"`
	Data        []map[string]interface{} `json:"data,omitempty"`
	RowCount    int                      `json:"row_count,omitempty"`
}

Text2SQLResponse represents the AI-generated SQL

type TransactionHandler

type TransactionHandler interface {
	CanHandle(ctx context.Context, intent string, editorType string) bool
	Handle(ctx context.Context, request *AIAgencyRequest, conversation *ConversationContext) (*AIAgencyResponse, error)
	GetName() string
}

TransactionHandler interface for specialized handlers

type ViewGenerationHandler

type ViewGenerationHandler struct {
	OpenAIKey   string
	OpenAIModel string
	// contains filtered or unexported fields
}

ViewGenerationHandler handles view structure generation

func (*ViewGenerationHandler) CanHandle

func (h *ViewGenerationHandler) CanHandle(ctx context.Context, intent string, editorType string) bool

func (*ViewGenerationHandler) GetName

func (h *ViewGenerationHandler) GetName() string

func (*ViewGenerationHandler) Handle

type VisualQuery

type VisualQuery struct {
	Tables  []string            `json:"tables"`
	Fields  []VisualQueryField  `json:"fields"`
	Filters []VisualQueryFilter `json:"filters,omitempty"`
	Joins   []VisualQueryJoin   `json:"joins,omitempty"`
	Sorts   []VisualQuerySort   `json:"sorts,omitempty"`
	GroupBy []string            `json:"groupBy,omitempty"`
	Limit   int                 `json:"limit,omitempty"`
	Offset  int                 `json:"offset,omitempty"`
}

VisualQuery represents the complete visual query structure

func ParseVisualQuery

func ParseVisualQuery(queryMap map[string]interface{}) (*VisualQuery, error)

ParseVisualQuery parses a visual query map into structured VisualQuery

func (*VisualQuery) GenerateSQL

func (vq *VisualQuery) GenerateSQL() (string, []interface{}, error)

GenerateSQL generates SQL from a visual query

type VisualQueryField

type VisualQueryField struct {
	Table       string `json:"table"`
	Column      string `json:"column"`
	Alias       string `json:"alias,omitempty"`
	Aggregation string `json:"aggregation,omitempty"` // SUM, AVG, COUNT, MAX, MIN
}

VisualQueryField represents a field in the visual query

type VisualQueryFilter

type VisualQueryFilter struct {
	Field    string      `json:"field"`
	Operator string      `json:"operator"` // =, !=, >, <, >=, <=, LIKE, IN, BETWEEN
	Value    interface{} `json:"value"`
	Logic    string      `json:"logic,omitempty"` // AND, OR
}

VisualQueryFilter represents a filter condition

type VisualQueryJoin

type VisualQueryJoin struct {
	Type        string `json:"type"` // INNER, LEFT, RIGHT, FULL
	Table       string `json:"table"`
	LeftColumn  string `json:"leftColumn"`
	RightColumn string `json:"rightColumn"`
}

VisualQueryJoin represents a table join

type VisualQuerySort

type VisualQuerySort struct {
	Field     string `json:"field"`
	Direction string `json:"direction"` // ASC, DESC
}

VisualQuerySort represents a sort order

type VisualizationSpec

type VisualizationSpec struct {
	Type        string            `json:"type"` // bar, line, pie, table, area, scatter
	Title       string            `json:"title"`
	Description string            `json:"description,omitempty"`
	XAxis       string            `json:"x_axis,omitempty"`
	YAxis       string            `json:"y_axis,omitempty"`
	YAxisMulti  []string          `json:"y_axis_multi,omitempty"`
	GroupBy     string            `json:"group_by,omitempty"`
	Config      map[string]string `json:"config,omitempty"`
}

VisualizationSpec defines a recommended chart/visualization

type WhiteboardGenerationHandler

type WhiteboardGenerationHandler struct {
	OpenAIKey   string
	OpenAIModel string
	// contains filtered or unexported fields
}

WhiteboardGenerationHandler handles whiteboard structure generation

func (*WhiteboardGenerationHandler) CanHandle

func (h *WhiteboardGenerationHandler) CanHandle(ctx context.Context, intent string, editorType string) bool

func (*WhiteboardGenerationHandler) GetName

func (h *WhiteboardGenerationHandler) GetName() string

func (*WhiteboardGenerationHandler) Handle

type WorkflowGenerationHandler

type WorkflowGenerationHandler struct {
	OpenAIKey   string
	OpenAIModel string
	// contains filtered or unexported fields
}

WorkflowGenerationHandler handles workflow structure generation

func (*WorkflowGenerationHandler) CanHandle

func (h *WorkflowGenerationHandler) CanHandle(ctx context.Context, intent string, editorType string) bool

func (*WorkflowGenerationHandler) GetName

func (h *WorkflowGenerationHandler) GetName() string

func (*WorkflowGenerationHandler) Handle

Jump to

Keyboard shortcuts

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