db

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const DB_CONN_POSTGRES = `postgres`

Connection type for postgres db

Variables

This section is empty.

Functions

This section is empty.

Types

type DBColumnDefinition

type DBColumnDefinition struct {
	ColumnName string
	ColumnType reflect.Type
}

type DBConn

type DBConn interface {
	//Returns an active db connection
	GetConnection() (*sql.DB, error)

	//Select a single row with the provided selects
	GetSelectSingle(tableName string, selects []string) (*sql.Rows, error)

	//query to return a single row from specifeid table in a sql.Rows object (so we get metadata)
	GetSelectAllColumnsSingle(tableName string) (*sql.Rows, error)

	//Checks if a table exists
	DoesTableExist(tableName string) (bool, error)

	//Creates a table with the specified colums and an "id" column as primary key
	CreateTable(tableName string, columns []DBColumnDefinition) error

	//Wrapper to check if table exists and if not create table
	CreateTableIfNotExists(tableName string, columns []DBColumnDefinition) error

	//Checks it a table column exists
	DoesTableColumnExist(tableName string, columnName string) (bool, error)

	//Adds a table column to an existing table
	AddTableColumn(tableName string, column DBColumnDefinition) error

	//Returns a map of column name to sql query string for a sprintf to profile
	ProfilesByType(columnType string) map[string]string

	//Inserts a row into the table and returns the id of the new row
	InsertRowAndReturnID(tableName string, values map[string]interface{}) int

	//Query table with provided where values
	GetRows(tableName string, wheres map[string]interface{}) (*sql.Rows, error)

	GetRowsSelectWhere(tableName string, selects []string, wheres map[string]interface{}) (*sql.Rows, error)

	GetRowsSelect(tableName string, selects []string) (*sql.Rows, error)

	GetTableRowCount(tableName string) (int, error)

	//Get the data size of the table
	GetTableSize(tableName string) (int64, error)
}

Struct to house the required methods for use in profiler

func GetDBConnByType

func GetDBConnByType(dbType string, dbConnString string) (DBConn, error)

type PostgresConn

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

func NewPostgresConn

func NewPostgresConn(dataSourceName string) *PostgresConn

Creates a new postgres connection object

func (*PostgresConn) AddTableColumn

func (p *PostgresConn) AddTableColumn(tableName string, column DBColumnDefinition) error

func (*PostgresConn) AddTableColumns

func (p *PostgresConn) AddTableColumns(tableName string, columns []DBColumnDefinition) error

func (*PostgresConn) CreateTable

func (p *PostgresConn) CreateTable(tableName string, columns []DBColumnDefinition) error

func (*PostgresConn) CreateTableIfNotExists

func (p *PostgresConn) CreateTableIfNotExists(tableName string, columns []DBColumnDefinition) error

func (*PostgresConn) DoesTableColumnExist

func (p *PostgresConn) DoesTableColumnExist(tableName string, columnName string) (bool, error)

func (*PostgresConn) DoesTableExist

func (p *PostgresConn) DoesTableExist(tableName string) (bool, error)

func (*PostgresConn) GetConnection

func (p *PostgresConn) GetConnection() (*sql.DB, error)

Connect to default database

func (*PostgresConn) GetRows

func (p *PostgresConn) GetRows(tableName string, wheres map[string]interface{}) (*sql.Rows, error)

func (*PostgresConn) GetRowsSelect

func (p *PostgresConn) GetRowsSelect(tableName string, selects []string) (*sql.Rows, error)

func (*PostgresConn) GetRowsSelectWhere

func (p *PostgresConn) GetRowsSelectWhere(tableName string, selects []string, wheres map[string]interface{}) (*sql.Rows, error)

func (*PostgresConn) GetSelectAllColumnsSingle

func (p *PostgresConn) GetSelectAllColumnsSingle(tableName string) (*sql.Rows, error)

func (*PostgresConn) GetSelectSingle

func (p *PostgresConn) GetSelectSingle(tableName string, selects []string) (*sql.Rows, error)

func (*PostgresConn) GetTableRowCount

func (p *PostgresConn) GetTableRowCount(tableName string) (int, error)

func (*PostgresConn) GetTableSize

func (p *PostgresConn) GetTableSize(tableName string) (int64, error)

func (*PostgresConn) InsertRowAndReturnID

func (p *PostgresConn) InsertRowAndReturnID(tableName string, values map[string]interface{}) int

func (*PostgresConn) ProfilesByType

func (p *PostgresConn) ProfilesByType(columnType string) map[string]string

Jump to

Keyboard shortcuts

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