Documentation ¶
Overview ¶
Package datasource manage the list of datasources and their selection from tags
Index ¶
- func EngineToString(engine Engine) string
- func TypeToString(dsType Type) string
- type Datasource
- func (ds *Datasource) CloseDatabase(log *logrus.Entry, admin bool, nodb bool) error
- func (ds *Datasource) CloseFile(log *logrus.Entry) error
- func (ds *Datasource) FillTmplValues() TmplValues
- func (ds *Datasource) GetEngine() Engine
- func (ds *Datasource) GetHash(log *logrus.Entry, admin bool, nodb bool) string
- func (ds *Datasource) GetName() string
- func (ds *Datasource) GetNamedTag(name string) string
- func (ds *Datasource) GetType() Type
- func (ds *Datasource) IsTableEmpty(ctx context.Context, log *logrus.Entry, table string) (bool, error)
- func (ds *Datasource) IsTableExists(ctx context.Context, log *logrus.Entry, table string) (bool, error)
- func (ds *Datasource) IsTransaction() bool
- func (ds *Datasource) OpenDatabase(log *logrus.Entry, admin bool, nodb bool) (*sql.DB, error)
- func (ds *Datasource) OpenReadFile(log *logrus.Entry) (io.ReadCloser, error)
- func (ds *Datasource) OpenWriteFile(log *logrus.Entry) (io.WriteCloser, error)
- func (ds *Datasource) ResetFile(log *logrus.Entry) error
- func (ds *Datasource) Stat() (os.FileInfo, error)
- type Datasourcer
- type Datasourcers
- type Datasources
- func (dss *Datasources) CloseAll(log *logrus.Entry)
- func (dss *Datasources) LoadAll(recipePath string, log *logrus.Entry) error
- func (dss *Datasources) Lookup(log *logrus.Entry, tagList []string, limitedTags []string, dsTypes []Type, ...) (selectedDs []Datasourcer, notLimitedDs []Datasourcer, err error)
- type Engine
- type TmplValues
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EngineToString ¶
EngineToString return do the conversion.
Types ¶
type Datasource ¶
type Datasource struct {
// contains filtered or unexported fields
}
Datasource is handle to the corresponding datasource (either file/database).
func (*Datasource) CloseDatabase ¶ added in v1.3.0
CloseDatabase close connection to the corresponding database only if no more used.
func (*Datasource) CloseFile ¶
func (ds *Datasource) CloseFile(log *logrus.Entry) error
CloseFile close the file and rename the temporary file to real name (if exists).
func (*Datasource) FillTmplValues ¶
func (ds *Datasource) FillTmplValues() TmplValues
FillTmplValues return a struct for template operation with value corresponding to the provided datasource.
func (*Datasource) GetEngine ¶
func (ds *Datasource) GetEngine() Engine
GetEngine return the engine enum value.
func (*Datasource) GetHash ¶ added in v1.1.0
GetHash returns uniq hash for the datasource final destination (more than one datasource could have the same hash by example same database engine).
func (*Datasource) GetName ¶
func (ds *Datasource) GetName() string
GetName return the name of the datasource.
func (*Datasource) GetNamedTag ¶
func (ds *Datasource) GetNamedTag(name string) string
GetNamedTag return the value of the tag with the provided name or "" if not exists.
func (*Datasource) GetType ¶
func (ds *Datasource) GetType() Type
GetType return the type enum value.
func (*Datasource) IsTableEmpty ¶ added in v1.2.2
func (ds *Datasource) IsTableEmpty(ctx context.Context, log *logrus.Entry, table string) (bool, error)
IsTableEmpty return true if the table empty.
func (*Datasource) IsTableExists ¶ added in v1.2.2
func (ds *Datasource) IsTableExists(ctx context.Context, log *logrus.Entry, table string) (bool, error)
IsTableExists return true if the table exists.
func (*Datasource) IsTransaction ¶
func (ds *Datasource) IsTransaction() bool
IsTransaction return true if the datasource has transaction.
func (*Datasource) OpenDatabase ¶
OpenDatabase open connection to the corresponding database.
func (*Datasource) OpenReadFile ¶
func (ds *Datasource) OpenReadFile(log *logrus.Entry) (io.ReadCloser, error)
OpenReadFile open and return a io.ReadCloser corresponding to the datasource to be used by providers.
func (*Datasource) OpenWriteFile ¶
func (ds *Datasource) OpenWriteFile(log *logrus.Entry) (io.WriteCloser, error)
OpenWriteFile open and return a io.WriteCloser corresponding to the datasource to be used by providers.
type Datasourcer ¶
type Datasourcer interface { FillTmplValues() TmplValues OpenDatabase(*logrus.Entry, bool, bool) (*sql.DB, error) OpenReadFile(*logrus.Entry) (io.ReadCloser, error) OpenWriteFile(*logrus.Entry) (io.WriteCloser, error) ResetFile(*logrus.Entry) error CloseFile(*logrus.Entry) error CloseDatabase(*logrus.Entry, bool, bool) error GetName() string GetHash(*logrus.Entry, bool, bool) string GetEngine() Engine GetType() Type IsTransaction() bool IsTableEmpty(context.Context, *logrus.Entry, string) (bool, error) IsTableExists(context.Context, *logrus.Entry, string) (bool, error) Stat() (os.FileInfo, error) }
Datasourcer interface for allowing mocking of Datasource object.
type Datasourcers ¶
type Datasourcers interface { LoadAll(string, *logrus.Entry) error CloseAll(*logrus.Entry) Lookup(*logrus.Entry, []string, []string, []Type, []Engine) ([]Datasourcer, []Datasourcer, error) }
Datasourcers interface to allow switching the way of storing the datasources.
type Datasources ¶
type Datasources struct {
// contains filtered or unexported fields
}
Datasources is a collection of Datasource.
func New ¶
func New(connectionTimeout time.Duration, connectionRetry int) *Datasources
New returns a new Datasources object with elments initialized.
func (*Datasources) CloseAll ¶
func (dss *Datasources) CloseAll(log *logrus.Entry)
CloseAll close all filehandle and database connection still opened.
func (*Datasources) LoadAll ¶
func (dss *Datasources) LoadAll(recipePath string, log *logrus.Entry) error
LoadAll Lookup the provided folder for datasource configuration files.
func (*Datasources) Lookup ¶
func (dss *Datasources) Lookup(log *logrus.Entry, tagList []string, limitedTags []string, dsTypes []Type, engines []Engine) (selectedDs []Datasourcer, notLimitedDs []Datasourcer, err error)
Lookup return a list of *Datasource that correspond to the list of tag expression.
type Engine ¶
type Engine int
Engine constants for file/database engine.
func StringToEngine ¶
StringToEngine convert string to corresponding Engine typed value.
func StringsToEngines ¶
StringsToEngines convert string slice to an slice of corresponding Engine typed values.
type TmplValues ¶
type TmplValues struct { Name string Datasource string Database string User string Password string Schema string Host string Port string Tags []string Type string Engine string FilePath string Transaction bool NamedTags map[string]string Environments map[string]string }
TmplValues structure use for template rendering to avoid exposing the datasource structure to the template.
type Type ¶
type Type int
Type discriminate the type of datasource.
func StringToType ¶
StringToType convert string to corresponding Type typed value.
func StringsToTypes ¶
StringsToTypes convert string slice to an slice of corresponding Type typed values.