database

package
v0.0.0-...-8f9caf9 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*sqlx.DB
	// contains filtered or unexported fields
}

DB wraps sqlx.DB and provides additional functionality

func New

func New(cfg config.DatabaseConfig, logger *logger.Logger) (*DB, error)

New creates a new database connection

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection

func (*DB) CreateEvent

func (db *DB) CreateEvent(ctx context.Context, event *models.Event) error

CreateEvent creates a new event

func (*DB) CreateLog

func (db *DB) CreateLog(ctx context.Context, log *models.Log) error

CreateLog creates a new log entry

func (*DB) CreateMetric

func (db *DB) CreateMetric(ctx context.Context, metric *models.Metric) error

CreateMetric creates a new metric

func (*DB) CreateService

func (db *DB) CreateService(ctx context.Context, service *models.Service) error

CreateService creates a new service

func (*DB) CreateTrace

func (db *DB) CreateTrace(ctx context.Context, trace *models.Trace) error

CreateTrace creates a new trace

func (*DB) ExecContext

func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecContext executes a query without returning any rows with context

func (*DB) GetContext

func (db *DB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

GetContext executes a query and binds the result to dest with context

func (*DB) GetServiceByName

func (db *DB) GetServiceByName(ctx context.Context, name string) (*models.Service, error)

GetServiceByName gets a service by name using the default environment

func (*DB) GetServiceByNameAndEnvironment

func (db *DB) GetServiceByNameAndEnvironment(ctx context.Context, name, environment string) (*models.Service, error)

GetServiceByNameAndEnvironment gets a service by name and environment

func (*DB) HealthCheck

func (db *DB) HealthCheck(ctx context.Context) error

HealthCheck performs a health check on the database

func (*DB) QueryRowContext

func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRowContext executes a query that returns a single row with context

func (*DB) SelectContext

func (db *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

SelectContext executes a query and binds the result to dest with context

func (*DB) WithTransaction

func (db *DB) WithTransaction(ctx context.Context, fn func(*sqlx.Tx) error) error

WithTransaction executes a function within a database transaction

type MetricRepository

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

MetricRepository handles database operations for metrics

func NewMetricRepository

func NewMetricRepository(db *DB) *MetricRepository

NewMetricRepository creates a new metric repository

func (*MetricRepository) Create

func (r *MetricRepository) Create(ctx context.Context, metric *models.Metric) error

Create creates a new metric entry

func (*MetricRepository) CreateBatch

func (r *MetricRepository) CreateBatch(ctx context.Context, metrics []*models.Metric) error

CreateBatch creates multiple metrics in a single transaction

func (*MetricRepository) Query

Query retrieves metrics based on query parameters

type ServiceRepository

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

ServiceRepository handles database operations for services

func NewServiceRepository

func NewServiceRepository(db *DB) *ServiceRepository

NewServiceRepository creates a new service repository

func (*ServiceRepository) Create

func (r *ServiceRepository) Create(ctx context.Context, name, environment string) (*models.Service, error)

Create creates a new service or returns existing one

func (*ServiceRepository) Delete

func (r *ServiceRepository) Delete(ctx context.Context, id uuid.UUID) error

Delete deletes a service by ID

func (*ServiceRepository) GetByID

func (r *ServiceRepository) GetByID(ctx context.Context, id uuid.UUID) (*models.Service, error)

GetByID retrieves a service by ID

func (*ServiceRepository) GetByNameAndEnvironment

func (r *ServiceRepository) GetByNameAndEnvironment(ctx context.Context, name, environment string) (*models.Service, error)

GetByNameAndEnvironment retrieves a service by name and environment

func (*ServiceRepository) GetOrCreate

func (r *ServiceRepository) GetOrCreate(ctx context.Context, name, environment string) (*models.Service, error)

GetOrCreate gets an existing service or creates a new one

func (*ServiceRepository) List

func (r *ServiceRepository) List(ctx context.Context, environment string, limit, offset int) ([]*models.Service, int64, error)

List retrieves all services with optional filtering

func (*ServiceRepository) Update

func (r *ServiceRepository) Update(ctx context.Context, service *models.Service) error

Update updates an existing service

Jump to

Keyboard shortcuts

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