datasource

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: BSD-2-Clause Imports: 22 Imported by: 0

Documentation

Overview

Package datasource manage the list of datasources and their selection from tags

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EngineToString

func EngineToString(engine Engine) string

EngineToString return do the conversion.

func TypeToString

func TypeToString(dsType Type) string

TypeToString 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

func (ds *Datasource) CloseDatabase(log *logrus.Entry, admin bool, nodb bool) error

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

func (ds *Datasource) GetHash(log *logrus.Entry, admin bool, nodb bool) string

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

func (ds *Datasource) OpenDatabase(log *logrus.Entry, admin bool, nodb bool) (*sql.DB, error)

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.

func (*Datasource) ResetFile

func (ds *Datasource) ResetFile(log *logrus.Entry) error

ResetFile close the file and remove the temporary file.

func (*Datasource) Stat

func (ds *Datasource) Stat() (os.FileInfo, error)

Stat returns os.FileInfo on the file of the datasource.

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.

const (
	// Mysql / MariaDB database engine
	Mysql Engine = iota
	// Postgres database engine
	Postgres Engine = iota
	// JSON file engine
	JSON Engine = iota
	// YAML file engine
	YAML Engine = iota
	// CSV file engine
	CSV Engine = iota
)

func StringToEngine

func StringToEngine(engine string) (Engine, error)

StringToEngine convert string to corresponding Engine typed value.

func StringsToEngines

func StringsToEngines(engines []string) ([]Engine, error)

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.

const (
	// Database (mariadb, mysql, postgres, ...)
	Database Type = iota
	// File (JSON,YAML,CSV, ...)
	File Type = iota
)

func StringToType

func StringToType(dsType string) (Type, error)

StringToType convert string to corresponding Type typed value.

func StringsToTypes

func StringsToTypes(dsTypes []string) ([]Type, error)

StringsToTypes convert string slice to an slice of corresponding Type typed values.

Jump to

Keyboard shortcuts

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