database

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: Apache-2.0 Imports: 22 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.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 WithSkipCreation added in v0.20.0

func WithSkipCreation(skipCreation bool) EngineOpt

WithSkipCreation sets the skip creation logic in the database engine.

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

	// 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

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

	// 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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