database

package
v0.24.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package database provides the ability for Vela to integrate with different supported SQL backends.

Usage:

import "github.com/go-vela/server/database"

Index

Constants

This section is empty.

Variables

View Source
var Flags = []cli.Flag{
	&cli.StringFlag{
		EnvVars:  []string{"VELA_DATABASE_DRIVER", "DATABASE_DRIVER"},
		FilePath: "/vela/database/driver",
		Name:     "database.driver",
		Usage:    "driver to be used for the database system",
		Value:    "sqlite3",
	},
	&cli.StringFlag{
		EnvVars:  []string{"VELA_DATABASE_ADDR", "DATABASE_ADDR"},
		FilePath: "/vela/database/addr",
		Name:     "database.addr",
		Usage:    "fully qualified url (<scheme>://<host>) for the database",
		Value:    "vela.sqlite",
	},
	&cli.IntFlag{
		EnvVars:  []string{"VELA_DATABASE_CONNECTION_OPEN", "DATABASE_CONNECTION_OPEN"},
		FilePath: "/vela/database/connection_open",
		Name:     "database.connection.open",
		Usage:    "maximum number of open connections to the database",
		Value:    0,
	},
	&cli.IntFlag{
		EnvVars:  []string{"VELA_DATABASE_CONNECTION_IDLE", "DATABASE_CONNECTION_IDLE"},
		FilePath: "/vela/database/connection_idle",
		Name:     "database.connection.idle",
		Usage:    "maximum number of idle connections to the database",
		Value:    2,
	},
	&cli.DurationFlag{
		EnvVars:  []string{"VELA_DATABASE_CONNECTION_LIFE", "DATABASE_CONNECTION_LIFE"},
		FilePath: "/vela/database/connection_life",
		Name:     "database.connection.life",
		Usage:    "duration of time a connection may be reused for the database",
		Value:    30 * time.Minute,
	},
	&cli.IntFlag{
		EnvVars:  []string{"VELA_DATABASE_COMPRESSION_LEVEL", "DATABASE_COMPRESSION_LEVEL"},
		FilePath: "/vela/database/compression_level",
		Name:     "database.compression.level",
		Usage:    "level of compression for logs stored in the database",
		Value:    constants.CompressionThree,
	},
	&cli.StringFlag{
		EnvVars:  []string{"VELA_DATABASE_ENCRYPTION_KEY", "DATABASE_ENCRYPTION_KEY"},
		FilePath: "/vela/database/encryption_key",
		Name:     "database.encryption.key",
		Usage:    "AES-256 key for encrypting and decrypting values in the database",
	},
	&cli.StringFlag{
		EnvVars:  []string{"VELA_DATABASE_LOG_LEVEL", "DATABASE_LOG_LEVEL"},
		FilePath: "/vela/database/log_level",
		Name:     "database.log.level",
		Usage:    "set log level - options: (trace|debug|info|warn|error|fatal|panic)",
		Value:    "warn",
	},
	&cli.BoolFlag{
		EnvVars:  []string{"VELA_DATABASE_LOG_SHOW_SQL", "DATABASE_LOG_SHOW_SQL"},
		FilePath: "/vela/database/log_show_sql",
		Name:     "database.log.show_sql",
		Usage:    "show the SQL query in the logs",
	},
	&cli.BoolFlag{
		EnvVars:  []string{"VELA_DATABASE_LOG_SKIP_NOTFOUND", "DATABASE_LOG_SKIP_NOTFOUND"},
		FilePath: "/vela/database/log_skip_notfound",
		Name:     "database.log.skip_notfound",
		Usage:    "skip logging when a resource is not found in the database",
		Value:    true,
	},
	&cli.DurationFlag{
		EnvVars:  []string{"VELA_DATABASE_LOG_SLOW_THRESHOLD", "DATABASE_LOG_SLOW_THRESHOLD"},
		FilePath: "/vela/database/log_slow_threshold",
		Name:     "database.log.slow_threshold",
		Usage:    "queries that take longer than this threshold are considered slow and will be logged",
		Value:    200 * time.Millisecond,
	},
	&cli.BoolFlag{
		EnvVars:  []string{"VELA_DATABASE_SKIP_CREATION", "DATABASE_SKIP_CREATION"},
		FilePath: "/vela/database/skip_creation",
		Name:     "database.skip_creation",
		Usage:    "enables skipping the creation of tables and indexes in the database",
	},
}

Flags represents all supported command line interface (CLI) flags for the database.

Functions

func ToContext

func ToContext(c Setter, d Interface)

ToContext adds the database Interface to this context if it supports the Setter interface.

Types

type EngineOpt added in v0.20.0

type EngineOpt func(*engine) error

EngineOpt represents a configuration option to initialize the database engine.

func WithAddress added in v0.20.0

func WithAddress(address string) EngineOpt

WithAddress sets the address in the database engine.

func WithCompressionLevel added in v0.20.0

func WithCompressionLevel(level int) EngineOpt

WithCompressionLevel sets the compression level in the database engine.

func WithConnectionIdle added in v0.20.0

func WithConnectionIdle(connectionIdle int) EngineOpt

WithConnectionIdle sets the idle connections in the database engine.

func WithConnectionLife added in v0.20.0

func WithConnectionLife(connectionLife time.Duration) EngineOpt

WithConnectionLife sets the life of connections in the database engine.

func WithConnectionOpen added in v0.20.0

func WithConnectionOpen(connectionOpen int) EngineOpt

WithConnectionOpen sets the open connections in the database engine.

func WithContext added in v0.21.0

func WithContext(ctx context.Context) EngineOpt

WithContext sets the context in the database engine.

func WithDriver added in v0.20.0

func WithDriver(driver string) EngineOpt

WithDriver sets the driver in the database engine.

func WithEncryptionKey added in v0.20.0

func WithEncryptionKey(encryptionKey string) EngineOpt

WithEncryptionKey sets the encryption key in the database engine.

func WithLogLevel added in v0.24.0

func WithLogLevel(logLevel string) EngineOpt

WithLogLevel sets the log level in the database engine.

func WithLogShowSQL added in v0.24.0

func WithLogShowSQL(logShowSQL bool) EngineOpt

WithLogShowSQL sets the log show SQL option in the database engine.

func WithLogSkipNotFound added in v0.24.0

func WithLogSkipNotFound(logSkipNotFound bool) EngineOpt

WithLogSkipNotFound sets the log skip not found option in the database engine.

func WithLogSlowThreshold added in v0.24.0

func WithLogSlowThreshold(logSlowThreshold time.Duration) EngineOpt

WithLogSlowThreshold sets the log slow query threshold in the database engine.

func WithSkipCreation added in v0.20.0

func WithSkipCreation(skipCreation bool) EngineOpt

WithSkipCreation sets the skip creation logic in the database engine.

type GormLogger added in v0.24.0

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

GormLogger is a custom logger for Gorm.

func NewGormLogger added in v0.24.0

func NewGormLogger(logger *logrus.Entry, slowThreshold time.Duration, skipNotFound, showSQL bool) *GormLogger

NewGormLogger creates a new Gorm logger.

func (*GormLogger) Error added in v0.24.0

func (l *GormLogger) Error(ctx context.Context, msg string, args ...interface{})

Error implements the logger.Interface.

func (*GormLogger) Info added in v0.24.0

func (l *GormLogger) Info(ctx context.Context, msg string, args ...interface{})

Info implements the logger.Interface.

func (*GormLogger) LogMode added in v0.24.0

LogMode sets the log mode for the logger.

func (*GormLogger) Trace added in v0.24.0

func (l *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

Trace implements the logger.Interface.

func (*GormLogger) Warn added in v0.24.0

func (l *GormLogger) Warn(ctx context.Context, msg string, args ...interface{})

Warn implements the logger.Interface.

type Interface added in v0.20.0

type Interface interface {

	// Close defines a function that stops and terminates the connection to the database.
	Close() error

	// Driver defines a function that outputs the configured database driver.
	Driver() string

	// Ping defines a function that sends a "ping" request to the configured database.
	Ping() error

	// SettingsInterface defines the interface for platform settings stored in the database.
	settings.SettingsInterface

	// BuildInterface defines the interface for builds stored in the database.
	build.BuildInterface

	// BuildExecutableInterface defines the interface for build executables stored in the database.
	executable.BuildExecutableInterface

	// DashboardInterface defines the interface for builds store in the database.
	dashboard.DashboardInterface

	// DeploymentInterface defines the interface for deployments stored in the database.
	deployment.DeploymentInterface

	// HookInterface defines the interface for hooks stored in the database.
	hook.HookInterface

	// JWKInterface defines the interface for JWKs stored in the database.
	jwk.JWKInterface

	// LogInterface defines the interface for logs stored in the database.
	log.LogInterface

	// PipelineInterface defines the interface for pipelines stored in the database.
	pipeline.PipelineInterface

	// RepoInterface defines the interface for repos stored in the database.
	repo.RepoInterface

	// ScheduleInterface defines the interface for schedules stored in the database.
	schedule.ScheduleInterface

	// SecretInterface defines the interface for secrets stored in the database.
	secret.SecretInterface

	// ServiceInterface defines the interface for services stored in the database.
	service.ServiceInterface

	// StepInterface defines the interface for steps stored in the database.
	step.StepInterface

	// UserInterface defines the interface for users stored in the database.
	user.UserInterface

	// WorkerInterface defines the interface for workers stored in the database.
	worker.WorkerInterface
}

Interface represents the interface for integrating with the supported database providers.

func FromCLIContext added in v0.20.0

func FromCLIContext(c *cli.Context) (Interface, error)

FromCLIContext creates and returns a database engine from the urfave/cli context.

func FromContext

func FromContext(c context.Context) Interface

FromContext returns the database Interface associated with this context.

func New

func New(opts ...EngineOpt) (Interface, error)

New creates and returns an engine capable of integrating with the configured database provider.

Currently, the following database providers are supported:

* postgres * sqlite3 .

func NewTest

func NewTest() (Interface, error)

NewTest creates and returns an engine that integrates with an in-memory database provider.

This function is ONLY intended to be used for testing purposes.

type Setter

type Setter interface {
	Set(string, interface{})
}

Setter defines a context that enables setting values.

Jump to

Keyboard shortcuts

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