Documentation
¶
Overview ¶
Package db provides database connections and migrations for the Gate service. It includes a DynamoDB client singleton (see dynamo.go) and PostgreSQL/GORM connection and migration helpers (see sql.go). Both use package-level singletons protected by mutexes.
Index ¶
- Constants
- Variables
- func NewDB(ctx context.Context, dsn string, databaseType config.AuditBackendType) (*gorm.DB, error)
- func NewDBMigrator(ctx context.Context, dsn string, databaseType config.AuditBackendType) (*migrate.Migrate, error)
- func NewDynamoDB(ctx context.Context, region string) (*dynamodb.Client, error)
- type DynamoDBAPI
- type MockDynamoDB
- func (m *MockDynamoDB) GetItem(ctx context.Context, params *dynamodb.GetItemInput, ...) (*dynamodb.GetItemOutput, error)
- func (m *MockDynamoDB) PutItem(ctx context.Context, params *dynamodb.PutItemInput, ...) (*dynamodb.PutItemOutput, error)
- func (m *MockDynamoDB) Scan(ctx context.Context, params *dynamodb.ScanInput, ...) (*dynamodb.ScanOutput, error)
Constants ¶
View Source
const ( // MigrateSource is the name passed to migrate.NewWithInstance for the migration source (iofs). MigrateSource = "iofs" // Postgres is the database driver name used for migrations and the embedded migration directory. Postgres = "postgres" )
Variables ¶
View Source
var ( // ErrDynamoDBLoadConfig is returned when the AWS SDK fails to load default config. ErrDynamoDBLoadConfig = errors.New("failed to load AWS config") // ErrDynamoDBRegionConflict is returned when NewDynamoDB is called // with a different region after the singleton was already initialized. ErrDynamoDBRegionConflict = errors.New("DynamoDB singleton already initialized with a different region") )
View Source
var ( // ErrMigrationSource is returned when the embedded migration source cannot be read. ErrMigrationSource = errors.New("failed to read migration source") // ErrUnderlyingDB is returned when the underlying *sql.DB cannot be extracted from the GORM DB. ErrUnderlyingDB = errors.New("failed to extract underlying sql.DB") // ErrMigrateDriver is returned when the PostgreSQL migrate driver cannot be created. ErrMigrateDriver = errors.New("failed to create migrate driver") )
Functions ¶
func NewDBMigrator ¶
func NewDBMigrator(ctx context.Context, dsn string, databaseType config.AuditBackendType) (*migrate.Migrate, error)
NewDBMigrator returns a migrate instance for the given database.
Types ¶
type DynamoDBAPI ¶
type DynamoDBAPI interface {
// PutItem writes a single item to the table.
PutItem(ctx context.Context, params *dynamodb.PutItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.PutItemOutput, error)
// GetItem retrieves a single item by key.
GetItem(ctx context.Context, params *dynamodb.GetItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.GetItemOutput, error)
// Scan reads items from the table (optionally filtered).
Scan(ctx context.Context, params *dynamodb.ScanInput, optFns ...func(*dynamodb.Options)) (*dynamodb.ScanOutput, error)
}
DynamoDBAPI defines the subset of DynamoDB operations used by the application. The real *dynamodb.Client satisfies this interface. Implementations must be safe for concurrent use.
type MockDynamoDB ¶
MockDynamoDB is a testify mock implementing DynamoDBAPI.
func (*MockDynamoDB) GetItem ¶
func (m *MockDynamoDB) GetItem( ctx context.Context, params *dynamodb.GetItemInput, optFns ...func(*dynamodb.Options), ) (*dynamodb.GetItemOutput, error)
func (*MockDynamoDB) PutItem ¶
func (m *MockDynamoDB) PutItem( ctx context.Context, params *dynamodb.PutItemInput, optFns ...func(*dynamodb.Options), ) (*dynamodb.PutItemOutput, error)
Directories
¶
| Path | Synopsis |
|---|---|
|
Package migrations embeds the database migration files for PostgreSQL.
|
Package migrations embeds the database migration files for PostgreSQL. |
Click to show internal directories.
Click to hide internal directories.