-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
499 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.