db

package
v0.0.0-...-3cc3e56 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDuplicateError

func IsDuplicateError(err error, dbtype string) bool

func IsStringInSlice

func IsStringInSlice(needle string, haystack []string) bool

isStringInSlice checks if needle (string) is in haystack ([]string).

func TranslateErrors

func TranslateErrors(err error, dbtype string) error

Types

type Column

type Column struct {
	OrdinalPosition        int            `json:"ordinal_position" gorm:"column:ordinal_position"`
	Name                   string         `json:"column_name" gorm:"column:column_name"`
	DataType               string         `json:"data_type" gorm:"column:data_type"`
	DefaultValue           sql.NullString `json:"column_default" gorm:"column:column_default"`
	IsNullable             string         `json:"is_nullable" gorm:"column:is_nullable"`
	CharacterMaximumLength sql.NullInt64  `json:"character_maximum_length" gorm:"column:character_maximum_length"`
	NumericPrecision       sql.NullInt64  `json:"numeric_precision" gorm:"column:numeric_precision"`
	ColumnKey              string         `json:"column_key" gorm:"column:column_key"`           // mysql specific
	Extra                  string         `json:"extra" gorm:"column:extra"`                     // mysql specific
	ConstraintName         sql.NullString `json:"constraint_name" gorm:"column:constraint_name"` // pg specific
	ConstraintType         sql.NullString `json:"constraint_type" gorm:"column:constraint_type"` // pg specific
}

Column stores information about a column.

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func NewConn

func NewConn(db *gorm.DB, config NetworkDB) *Conn

func (*Conn) AutoMigrate

func (c *Conn) AutoMigrate(dst ...interface{}) error

func (*Conn) GetDB

func (c *Conn) GetDB() *gorm.DB

func (*Conn) GetQuery

func (c *Conn) GetQuery() *query.Query

func (*Conn) MustExec

func (c *Conn) MustExec(sql string, values ...interface{})

func (*Conn) Raw

func (c *Conn) Raw(sql string, values ...interface{}) *gorm.DB

func (*Conn) ScanRows

func (c *Conn) ScanRows(rows *sql.Rows, dest interface{}) error

func (*Conn) SourceSQL

func (c *Conn) SourceSQL(filename string)

type DBType

type DBType string
const (
	DBTypePostgresql DBType = "pg"
	DBTypeMySQL      DBType = "mysql"
	DBTypeSQLite     DBType = "sqlite3"
)

type Database

type Database interface {
	GetTables() (tables []*Table, err error)
	// PrepareGetColumnsOfTableStmt() (err error)
	GetColumnsOfTable(table *Table) (err error)

	IsPrimaryKey(column Column) bool
	IsAutoIncrement(column Column) bool
	IsNullable(column Column) bool

	GetStringDatatypes() []string
	IsString(column Column) bool

	GetTextDatatypes() []string
	IsText(column Column) bool

	GetIntegerDatatypes() []string
	IsInteger(column Column) bool

	GetFloatDatatypes() []string
	IsFloat(column Column) bool

	GetTemporalDatatypes() []string
	IsTemporal(column Column) bool
}

Database interface for the concrete databases.

func New

func New() Database

New creates a new Database based on the given type in the settings.

type GeneralDatabase

type GeneralDatabase struct {
	// contains filtered or unexported fields
}

GeneralDatabase represents a base "class" database - for all other concrete databases it implements partly the Database interface.

func (*GeneralDatabase) Close

func (gdb *GeneralDatabase) Close() error

Close closes the database connection.

func (*GeneralDatabase) Connect

func (gdb *GeneralDatabase) Connect(dsn string) (err error)

Connect establishes a connection to the database with the given DSN. It pings the database to ensure it is reachable.

func (*GeneralDatabase) IsNullable

func (gdb *GeneralDatabase) IsNullable(column Column) bool

IsNullable returns true if the column is a nullable column.

type NetworkDB

type NetworkDB struct {
	Database string
	User     string
	Password string
	Host     string
	Port     uint16
	Debug    bool

	ConnectionTimeout int // Seconds

	// database/sql tunables, see
	// https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime and below
	// Note: defaults will be set if these are 0
	MaxOpenConns    int `json:"maxOpenConns"`    // default: 5
	MaxIdleConns    int `json:"maxIdleConns"`    // default: 5
	ConnMaxLifetime int `json:"connMaxLifetime"` // Seconds, default: not set
}

NetworkDB contains options common to SQL databases accessed over network.

type SSL

type SSL struct {
	Mode   string
	CAFile string `json:"cAFile"`
	// Files for client auth.
	KeyFile  string `json:"keyFile"`
	CertFile string `json:"certFile"`
}

SSL represents SSL options for network databases.

type Storage

type Storage interface {
	Open(logger *log.Logger) (*Conn, error)
}

type Table

type Table struct {
	Name    string   `json:"table_name" gorm:"column:table_name"`
	Columns []Column `json:"columns" gorm:"-"`
}

Table has a name and a set (slice) of columns.

func (*Table) ToString

func (t *Table) ToString() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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