Skip to content

Commit

Permalink
feat(database): add engine options
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockopp committed Jun 17, 2023
1 parent d63abfe commit df0b08a
Show file tree
Hide file tree
Showing 2 changed files with 499 additions and 0 deletions.
90 changes: 90 additions & 0 deletions database/opts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright (c) 2023 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

package database

import "time"

// EngineOpt represents a configuration option to initialize the database engine.
type EngineOpt func(*engine) error

// WithAddress sets the address in the database engine.
func WithAddress(address string) EngineOpt {
return func(e *engine) error {
// set the fully qualified connection string in the database engine
e.config.Address = address

return nil
}
}

// WithCompressionLevel sets the compression level in the database engine.
func WithCompressionLevel(level int) EngineOpt {
return func(e *engine) error {
// set the level of compression for resources in the database engine
e.config.CompressionLevel = level

return nil
}
}

// WithConnectionLife sets the life of connections in the database engine.
func WithConnectionLife(connectionLife time.Duration) EngineOpt {
return func(e *engine) error {
// set the maximum duration of time for connection in the database engine
e.config.ConnectionLife = connectionLife

return nil
}
}

// WithConnectionIdle sets the idle connections in the database engine.
func WithConnectionIdle(connectionIdle int) EngineOpt {
return func(e *engine) error {
// set the maximum allowed idle connections in the database engine
e.config.ConnectionIdle = connectionIdle

return nil
}
}

// WithConnectionOpen sets the open connections in the database engine.
func WithConnectionOpen(connectionOpen int) EngineOpt {
return func(e *engine) error {
// set the maximum allowed open connections in the database engine
e.config.ConnectionOpen = connectionOpen

return nil
}
}

// WithDriver sets the driver in the database engine.
func WithDriver(driver string) EngineOpt {
return func(e *engine) error {
// set the database type to interact with in the database engine
e.config.Driver = driver

return nil
}
}

// WithEncryptionKey sets the encryption key in the database engine.
func WithEncryptionKey(encryptionKey string) EngineOpt {
return func(e *engine) error {
// set the key for encrypting resources in the database engine
e.config.EncryptionKey = encryptionKey

return nil
}
}

// WithSkipCreation sets the skip creation logic in the database engine.
func WithSkipCreation(skipCreation bool) EngineOpt {
return func(e *engine) error {
// set to skip creating tables and indexes in the database engine
e.config.SkipCreation = skipCreation

return nil
}
}
Loading

0 comments on commit df0b08a

Please sign in to comment.