db

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Migrations string `mapstructure:"MIGRATIONS_DIR"`  // The path to the database migration files
	Driver     string `mapstructure:"DATABASE_DRIVER"` // The database driver to use: postgres, mysql
	Name       string `mapstructure:"DATABASE_NAME"`   // The name of the database
	Host       string `mapstructure:"DATABASE_HOST"`   // The hostname or IP address of the database server
	Port       string `mapstructure:"DATABASE_PORT"`   // The port number on which the database server is listening
	User       string `mapstructure:"DATABASE_USER"`   // The username for authenticating with the database server
	Pass       string `mapstructure:"DATABASE_PASS"`   // The password for authenticating with the database server
	Args       string `mapstructure:"DATABASE_ARGS"`   // Additional arguments for the database connection
	URL        string // The URL for the database connection (derived from other fields)
	RedisURL   string `mapstructure:"REDIS_URL"`      // The URL for the redis connction
	RedisAddr  string `mapstructure:"REDIS_ADDRESS"`  // The URL for the redis connction
	RedisUser  string `mapstructure:"REDIS_USERNAME"` // The username for authenticating with the redis server
	RedisPass  string `mapstructure:"REDIS_PASSWORD"` // The password for authenticating with the redis server
	RedisPort  string `mapstructure:"REDIS_PORT"`     // The port number on which the redis server is listening
}

type Database

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

Database represents a database connection.

func NewDatabae

func NewDatabae(
	ctx context.Context,
	config Config,
	logr zerolog.Logger,
) (*Database, *pgxpool.Pool, error)

NewConnection creates a new database connection based on the provided configuration. It returns a Database instance and any error encountered during the connection process.

func (*Database) Close

func (database *Database) Close()

Close closes the database connection.

func (*Database) MigrateUsingBindata added in v0.3.2

func (d *Database) MigrateUsingBindata() (err error)

MigrateUsingBindata applies database migrations using the `go-bindata` package as the source driver. It creates a migration source using the binary data generated by the `migrations` package, and then creates a new migrate instance with the `go-bindata` source driver and the provided database URL. It then applies any pending migrations to the database and logs the result.

type RedisClient

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

RedisClient is a wrapper around redis.Client

func NewRedisClient

func NewRedisClient(address string, logr zerolog.Logger) (*RedisClient, error)

NewRedisClient creates a new RedisClient

func (*RedisClient) Close

func (r *RedisClient) Close()

Close closes the Redis connection

func (*RedisClient) Del added in v0.3.2

func (r *RedisClient) Del(ctx context.Context, keys ...string) error

Del deletes a key in Redis

func (*RedisClient) Get added in v0.3.2

func (r *RedisClient) Get(ctx context.Context, key string) ([]byte, error)

Get gets the value of a key in Redis

func (*RedisClient) GetKeysWithPrefix added in v0.3.2

func (r *RedisClient) GetKeysWithPrefix(ctx context.Context, prefix string) ([]string, error)

GetKeysWithPrefix returns all keys with a given prefix

func (*RedisClient) Ping added in v0.3.2

func (r *RedisClient) Ping(ctx context.Context) error

Ping checks if the Redis server is available

func (*RedisClient) Set added in v0.3.2

func (r *RedisClient) Set(
	ctx context.Context,
	key string,
	data interface{},
	expiration time.Duration,
) error

Set sets the value of a key in Redis

func (*RedisClient) Transaction added in v0.3.2

func (r *RedisClient) Transaction(
	ctx context.Context,
	commands []redis.Cmder,
) ([]redis.Cmder, error)

Transaction executes a transaction

Jump to

Keyboard shortcuts

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