database

package
v0.0.0-...-92d8de8 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxIdleConns = 10
	DefaultMaxOpenConns = 5
)

Variables

View Source
var (
	ErrNotImplementation error = errors.New("not implementation")
)

Functions

func Coalesce

func Coalesce(str ...string) string

func ColumnDoc

func ColumnDoc(tableName string, colDesc *ColumnDesc) string

func Columns

func Columns(rows *sql.Rows) ([]string, error)

func QueryExecType

func QueryExecType(prefix, sqlstr string) (string, bool)

QueryExecType is the default way to determine the "EXEC" prefix for a SQL query and whether or not it should be Exec'd or Query'd.

func RegisterFactory

func RegisterFactory(name dialect.DatabaseDriver, factory Factory)

func RegisterOpen

func RegisterOpen(name dialect.DatabaseDriver, opener Opener)

func Registered

func Registered(name dialect.DatabaseDriver) bool

func ScanRows

func ScanRows(rows *sql.Rows, columnLength int) ([][]string, error)

func SubqueryColumnDoc

func SubqueryColumnDoc(identName string, views []*parseutil.SubQueryView, dbCache *DBCache) string

func SubqueryDoc

func SubqueryDoc(name string, views []*parseutil.SubQueryView, dbCache *DBCache) string

func TableDoc

func TableDoc(tableName string, cols []*ColumnDesc) string

Types

type ColumnBase

type ColumnBase struct {
	Schema string
	Table  string
	Name   string
}

type ColumnDesc

type ColumnDesc struct {
	ColumnBase
	Type    string
	Null    string
	Key     string
	Default sql.NullString
	Extra   string
}

func (*ColumnDesc) OnelineDesc

func (cd *ColumnDesc) OnelineDesc() string

type DBCache

type DBCache struct {
	Schemas           map[string]string
	SchemaTables      map[string][]string
	ColumnsWithParent map[string][]*ColumnDesc
	ForeignKeys       map[string]map[string][]*ForeignKey
	// contains filtered or unexported fields
}

func (*DBCache) Column

func (dc *DBCache) Column(tableName, colName string) (*ColumnDesc, bool)

func (*DBCache) ColumnDatabase

func (dc *DBCache) ColumnDatabase(dbName, tableName string) (cols []*ColumnDesc, ok bool)

func (*DBCache) ColumnDescs

func (dc *DBCache) ColumnDescs(tableName string) (cols []*ColumnDesc, ok bool)

func (*DBCache) Database

func (dc *DBCache) Database(dbName string) (db string, ok bool)

func (*DBCache) SortedSchemas

func (dc *DBCache) SortedSchemas() []string

func (*DBCache) SortedTables

func (dc *DBCache) SortedTables() []string

func (*DBCache) SortedTablesByDBName

func (dc *DBCache) SortedTablesByDBName(dbName string) (tbls []string, ok bool)

type DBCacheGenerator

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

func NewDBCacheUpdater

func NewDBCacheUpdater(repo DBRepository) *DBCacheGenerator

func (*DBCacheGenerator) GenerateDBCachePrimary

func (u *DBCacheGenerator) GenerateDBCachePrimary(ctx context.Context) (*DBCache, error)

func (*DBCacheGenerator) GenerateDBCacheSecondary

func (u *DBCacheGenerator) GenerateDBCacheSecondary(ctx context.Context) (map[string][]*ColumnDesc, error)

type DBConnection

type DBConnection struct {
	Conn    *sql.DB
	SSHConn *ssh.Client
	Driver  dialect.DatabaseDriver
}

func Open

func Open(cfg *config.DBConfig) (*DBConnection, error)

func (*DBConnection) Close

func (db *DBConnection) Close() error

type DBOption

type DBOption struct {
	MaxIdleConns int
	MaxOpenConns int
}

type DBRepository

type DBRepository interface {
	Driver() dialect.DatabaseDriver
	CurrentDatabase(ctx context.Context) (string, error)
	Databases(ctx context.Context) ([]string, error)
	CurrentSchema(ctx context.Context) (string, error)
	Schemas(ctx context.Context) ([]string, error)
	SchemaTables(ctx context.Context) (map[string][]string, error)
	DescribeDatabaseTable(ctx context.Context) ([]*ColumnDesc, error)
	DescribeDatabaseTableBySchema(ctx context.Context, schemaName string) ([]*ColumnDesc, error)
	Exec(ctx context.Context, query string) (sql.Result, error)
	Query(ctx context.Context, query string) (*sql.Rows, error)
	DescribeForeignKeysBySchema(ctx context.Context, schemaName string) ([]*ForeignKey, error)
}

func CreateRepository

func CreateRepository(driver dialect.DatabaseDriver, db *sql.DB) (DBRepository, error)

func NewMockDBRepository

func NewMockDBRepository(_ *sql.DB) DBRepository

func NewMssqlDBRepository

func NewMssqlDBRepository(conn *sql.DB) DBRepository

func NewMySQLDBRepository

func NewMySQLDBRepository(conn *sql.DB) DBRepository

func NewOracleDBRepository

func NewOracleDBRepository(conn *sql.DB) DBRepository

func NewPostgreSQLDBRepository

func NewPostgreSQLDBRepository(conn *sql.DB) DBRepository

func NewSQLite3DBRepository

func NewSQLite3DBRepository(conn *sql.DB) DBRepository

type Factory

type Factory func(*sql.DB) DBRepository

type ForeignKey

type ForeignKey [][2]*ColumnBase

type MockDBRepository

type MockDBRepository struct {
	MockDatabase                      func(context.Context) (string, error)
	MockDatabases                     func(context.Context) ([]string, error)
	MockDatabaseTables                func(context.Context) (map[string][]string, error)
	MockTables                        func(context.Context) ([]string, error)
	MockDescribeTable                 func(context.Context, string) ([]*ColumnDesc, error)
	MockDescribeDatabaseTable         func(context.Context) ([]*ColumnDesc, error)
	MockDescribeDatabaseTableBySchema func(context.Context, string) ([]*ColumnDesc, error)
	MockExec                          func(context.Context, string) (sql.Result, error)
	MockQuery                         func(context.Context, string) (*sql.Rows, error)
	MockDescribeForeignKeysBySchema   func(context.Context, string) ([]*ForeignKey, error)
}

func (*MockDBRepository) CurrentDatabase

func (m *MockDBRepository) CurrentDatabase(ctx context.Context) (string, error)

func (*MockDBRepository) CurrentSchema

func (m *MockDBRepository) CurrentSchema(ctx context.Context) (string, error)

func (*MockDBRepository) Databases

func (m *MockDBRepository) Databases(ctx context.Context) ([]string, error)

func (*MockDBRepository) DescribeDatabaseTable

func (m *MockDBRepository) DescribeDatabaseTable(ctx context.Context) ([]*ColumnDesc, error)

func (*MockDBRepository) DescribeDatabaseTableBySchema

func (m *MockDBRepository) DescribeDatabaseTableBySchema(ctx context.Context, schemaName string) ([]*ColumnDesc, error)

func (*MockDBRepository) DescribeForeignKeysBySchema

func (m *MockDBRepository) DescribeForeignKeysBySchema(ctx context.Context, schemaName string) ([]*ForeignKey, error)

func (*MockDBRepository) Driver

func (*MockDBRepository) Exec

func (m *MockDBRepository) Exec(ctx context.Context, query string) (sql.Result, error)

func (*MockDBRepository) Query

func (m *MockDBRepository) Query(ctx context.Context, query string) (*sql.Rows, error)

func (*MockDBRepository) SchemaTables

func (m *MockDBRepository) SchemaTables(ctx context.Context) (map[string][]string, error)

func (*MockDBRepository) Schemas

func (m *MockDBRepository) Schemas(ctx context.Context) ([]string, error)

func (*MockDBRepository) Tables

func (m *MockDBRepository) Tables(ctx context.Context) ([]string, error)

type MockResult

type MockResult struct {
	MockLastInsertID func() (int64, error)
	MockRowsAffected func() (int64, error)
}

func (*MockResult) LastInsertId

func (m *MockResult) LastInsertId() (int64, error)

func (*MockResult) RowsAffected

func (m *MockResult) RowsAffected() (int64, error)

type MssqlDBRepository

type MssqlDBRepository struct {
	Conn *sql.DB
}

func (*MssqlDBRepository) CurrentDatabase

func (db *MssqlDBRepository) CurrentDatabase(ctx context.Context) (string, error)

func (*MssqlDBRepository) CurrentSchema

func (db *MssqlDBRepository) CurrentSchema(ctx context.Context) (string, error)

func (*MssqlDBRepository) Databases

func (db *MssqlDBRepository) Databases(ctx context.Context) ([]string, error)

func (*MssqlDBRepository) DescribeDatabaseTable

func (db *MssqlDBRepository) DescribeDatabaseTable(ctx context.Context) ([]*ColumnDesc, error)

func (*MssqlDBRepository) DescribeDatabaseTableBySchema

func (db *MssqlDBRepository) DescribeDatabaseTableBySchema(ctx context.Context, schemaName string) ([]*ColumnDesc, error)

func (*MssqlDBRepository) DescribeForeignKeysBySchema

func (db *MssqlDBRepository) DescribeForeignKeysBySchema(ctx context.Context, schemaName string) ([]*ForeignKey, error)

func (*MssqlDBRepository) Driver

func (*MssqlDBRepository) Exec

func (db *MssqlDBRepository) Exec(ctx context.Context, query string) (sql.Result, error)

func (*MssqlDBRepository) Query

func (db *MssqlDBRepository) Query(ctx context.Context, query string) (*sql.Rows, error)

func (*MssqlDBRepository) SchemaTables

func (db *MssqlDBRepository) SchemaTables(ctx context.Context) (map[string][]string, error)

func (*MssqlDBRepository) Schemas

func (db *MssqlDBRepository) Schemas(ctx context.Context) ([]string, error)

func (*MssqlDBRepository) Tables

func (db *MssqlDBRepository) Tables(ctx context.Context) ([]string, error)

type MySQLDBRepository

type MySQLDBRepository struct {
	Conn *sql.DB
	// contains filtered or unexported fields
}

func (*MySQLDBRepository) CurrentDatabase

func (db *MySQLDBRepository) CurrentDatabase(ctx context.Context) (string, error)

func (*MySQLDBRepository) CurrentSchema

func (db *MySQLDBRepository) CurrentSchema(ctx context.Context) (string, error)

func (*MySQLDBRepository) Databases

func (db *MySQLDBRepository) Databases(ctx context.Context) ([]string, error)

func (*MySQLDBRepository) DescribeDatabaseTable

func (db *MySQLDBRepository) DescribeDatabaseTable(ctx context.Context) ([]*ColumnDesc, error)

func (*MySQLDBRepository) DescribeDatabaseTableBySchema

func (db *MySQLDBRepository) DescribeDatabaseTableBySchema(ctx context.Context, schemaName string) ([]*ColumnDesc, error)

func (*MySQLDBRepository) DescribeForeignKeysBySchema

func (db *MySQLDBRepository) DescribeForeignKeysBySchema(ctx context.Context, schemaName string) ([]*ForeignKey, error)

func (*MySQLDBRepository) Driver

func (*MySQLDBRepository) Exec

func (db *MySQLDBRepository) Exec(ctx context.Context, query string) (sql.Result, error)

func (*MySQLDBRepository) Query

func (db *MySQLDBRepository) Query(ctx context.Context, query string) (*sql.Rows, error)

func (*MySQLDBRepository) SchemaTables

func (db *MySQLDBRepository) SchemaTables(ctx context.Context) (map[string][]string, error)

func (*MySQLDBRepository) Schemas

func (db *MySQLDBRepository) Schemas(ctx context.Context) ([]string, error)

func (*MySQLDBRepository) Tables

func (db *MySQLDBRepository) Tables(ctx context.Context) ([]string, error)

type MySQLViaSSHDialer

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

func (*MySQLViaSSHDialer) Dial

func (d *MySQLViaSSHDialer) Dial(ctx context.Context, addr string) (net.Conn, error)

type Opener

type Opener func(*config.DBConfig) (*DBConnection, error)

type OracleDBRepository

type OracleDBRepository struct {
	Conn *sql.DB
}

func (*OracleDBRepository) CurrentDatabase

func (db *OracleDBRepository) CurrentDatabase(ctx context.Context) (string, error)

func (*OracleDBRepository) CurrentSchema

func (db *OracleDBRepository) CurrentSchema(ctx context.Context) (string, error)

func (*OracleDBRepository) Databases

func (db *OracleDBRepository) Databases(ctx context.Context) ([]string, error)

func (*OracleDBRepository) DescribeDatabaseTable

func (db *OracleDBRepository) DescribeDatabaseTable(ctx context.Context) ([]*ColumnDesc, error)

func (*OracleDBRepository) DescribeDatabaseTableBySchema

func (db *OracleDBRepository) DescribeDatabaseTableBySchema(ctx context.Context, schemaName string) ([]*ColumnDesc, error)

func (*OracleDBRepository) DescribeForeignKeysBySchema

func (db *OracleDBRepository) DescribeForeignKeysBySchema(ctx context.Context, schemaName string) ([]*ForeignKey, error)

func (*OracleDBRepository) Driver

func (*OracleDBRepository) Exec

func (db *OracleDBRepository) Exec(ctx context.Context, query string) (sql.Result, error)

func (*OracleDBRepository) Query

func (db *OracleDBRepository) Query(ctx context.Context, query string) (*sql.Rows, error)

func (*OracleDBRepository) SchemaTables

func (db *OracleDBRepository) SchemaTables(ctx context.Context) (map[string][]string, error)

func (*OracleDBRepository) Schemas

func (db *OracleDBRepository) Schemas(ctx context.Context) ([]string, error)

func (*OracleDBRepository) Tables

func (db *OracleDBRepository) Tables(ctx context.Context) ([]string, error)

type PostgreSQLDBRepository

type PostgreSQLDBRepository struct {
	Conn *sql.DB
}

func (*PostgreSQLDBRepository) CurrentDatabase

func (db *PostgreSQLDBRepository) CurrentDatabase(ctx context.Context) (string, error)

func (*PostgreSQLDBRepository) CurrentSchema

func (db *PostgreSQLDBRepository) CurrentSchema(ctx context.Context) (string, error)

func (*PostgreSQLDBRepository) Databases

func (db *PostgreSQLDBRepository) Databases(ctx context.Context) ([]string, error)

func (*PostgreSQLDBRepository) DescribeDatabaseTable

func (db *PostgreSQLDBRepository) DescribeDatabaseTable(ctx context.Context) ([]*ColumnDesc, error)

func (*PostgreSQLDBRepository) DescribeDatabaseTableBySchema

func (db *PostgreSQLDBRepository) DescribeDatabaseTableBySchema(ctx context.Context, schemaName string) ([]*ColumnDesc, error)

func (*PostgreSQLDBRepository) DescribeForeignKeysBySchema

func (db *PostgreSQLDBRepository) DescribeForeignKeysBySchema(ctx context.Context, schemaName string) ([]*ForeignKey, error)

func (*PostgreSQLDBRepository) Driver

func (*PostgreSQLDBRepository) Exec

func (db *PostgreSQLDBRepository) Exec(ctx context.Context, query string) (sql.Result, error)

func (*PostgreSQLDBRepository) Query

func (db *PostgreSQLDBRepository) Query(ctx context.Context, query string) (*sql.Rows, error)

func (*PostgreSQLDBRepository) SchemaTables

func (db *PostgreSQLDBRepository) SchemaTables(ctx context.Context) (map[string][]string, error)

func (*PostgreSQLDBRepository) Schemas

func (db *PostgreSQLDBRepository) Schemas(ctx context.Context) ([]string, error)

func (*PostgreSQLDBRepository) Tables

func (db *PostgreSQLDBRepository) Tables(ctx context.Context) ([]string, error)

type SQLite3DBRepository

type SQLite3DBRepository struct {
	Conn *sql.DB
}

func (*SQLite3DBRepository) CurrentDatabase

func (db *SQLite3DBRepository) CurrentDatabase(ctx context.Context) (string, error)

func (*SQLite3DBRepository) CurrentSchema

func (db *SQLite3DBRepository) CurrentSchema(ctx context.Context) (string, error)

func (*SQLite3DBRepository) Databases

func (db *SQLite3DBRepository) Databases(ctx context.Context) ([]string, error)

func (*SQLite3DBRepository) DescribeDatabaseTable

func (db *SQLite3DBRepository) DescribeDatabaseTable(ctx context.Context) ([]*ColumnDesc, error)

func (*SQLite3DBRepository) DescribeDatabaseTableBySchema

func (db *SQLite3DBRepository) DescribeDatabaseTableBySchema(ctx context.Context, _ string) ([]*ColumnDesc, error)

func (*SQLite3DBRepository) DescribeForeignKeysBySchema

func (db *SQLite3DBRepository) DescribeForeignKeysBySchema(ctx context.Context, schemaName string) ([]*ForeignKey, error)

func (*SQLite3DBRepository) Driver

func (*SQLite3DBRepository) Exec

func (db *SQLite3DBRepository) Exec(ctx context.Context, query string) (sql.Result, error)

func (*SQLite3DBRepository) Query

func (db *SQLite3DBRepository) Query(ctx context.Context, query string) (*sql.Rows, error)

func (*SQLite3DBRepository) SchemaTables

func (db *SQLite3DBRepository) SchemaTables(ctx context.Context) (map[string][]string, error)

func (*SQLite3DBRepository) Schemas

func (db *SQLite3DBRepository) Schemas(ctx context.Context) ([]string, error)

func (*SQLite3DBRepository) Tables

func (db *SQLite3DBRepository) Tables(ctx context.Context) ([]string, error)

type Worker

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

func NewWorker

func NewWorker() *Worker

func (*Worker) Cache

func (w *Worker) Cache() *DBCache

func (*Worker) ReCache

func (w *Worker) ReCache(ctx context.Context, repo DBRepository) error

func (*Worker) Start

func (w *Worker) Start()

func (*Worker) Stop

func (w *Worker) Stop()

Jump to

Keyboard shortcuts

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