sqlutils

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IsTableExistentQueryTemplate = map[DatabaseType]string{
	MySQL:       "SELECT 1 FROM `%s`;",
	MariaDB:     "SELECT 1 FROM `%s`;",
	SQLServer:   "SELECT 1 FROM %s;",
	PostgreSQL:  "SELECT 1 FROM \"%s\";",
	SQLite:      "SELECT 1 FROM `%s`;",
	Oracle:      "SELECT 1 FROM %s;",
	CockroachDB: "SELECT 1 FROM \"%s\";",
}

Functions

func ConnectDB

func ConnectDB(connInfo *SQLConnectionInfo) (*sql.DB, error)

func DeleteTable

func DeleteTable(db *sql.DB, tableName string, databaseType DatabaseType) error

func DuplicateTable

func DuplicateTable(db *sql.DB, originalTableName, newTableName string, databaseType DatabaseType) error

func EditRecord

func EditRecord(
	db *sql.DB,
	tableName string,
	recordIdColumn string,
	recordIdValue any,
	updateColumn string,
	updateValue any,
	databaseType DatabaseType,
) error

func GetColumns

func GetColumns(db *sql.DB, tableName string, databaseType DatabaseType) ([]string, error)

func GetPrimaryKeys

func GetPrimaryKeys(db *sql.DB, dbName, tableName string, databaseType DatabaseType) ([]string, error)

func GetTable

func GetTable(db *sql.DB, tableName string, dbType DatabaseType) ([]map[string]interface{}, error)

func GetTables

func GetTables(db *sql.DB, dbName string, dbType DatabaseType) ([]string, error)

func InsertRecord

func InsertRecord(db *sql.DB, tableName string, columns []string, values []interface{}, databaseType DatabaseType) (int64, error)

func IsTableExistent

func IsTableExistent(db *sql.DB, tableName string, dbType DatabaseType) error

func RemoveRecord

func RemoveRecord(db *sql.DB, dbName, tableName string, databaseType DatabaseType, values []interface{}) (int64, error)

First tries to remove record by primary keys, if no primary keys exist then remove record(s) which meets all values

func RenameTable

func RenameTable(db *sql.DB, oldTableName string, newTableName string, databaseType DatabaseType) error

Types

type DatabaseInfo

type DatabaseInfo struct {
	PlaceholderFormat func(int) string
	QuoteChar         string
}

type DatabaseType

type DatabaseType string
const (
	PostgreSQL  DatabaseType = "postgres"
	MySQL       DatabaseType = "mysql"
	SQLite      DatabaseType = "sqlite3"
	SQLServer   DatabaseType = "sqlserver"
	Oracle      DatabaseType = "oracle"
	MariaDB     DatabaseType = "mariadb"
	CockroachDB DatabaseType = "cockroachdb"
)

type SQLConnectionInfo

type SQLConnectionInfo struct {
	Type   DatabaseType `json:"type"`
	Host   string       `json:"host"`
	Port   string       `json:"port"`
	DBName string       `json:"dbName"`
	User   string       `json:"user"`
	Passwd string       `json:"password"`
}

Jump to

Keyboard shortcuts

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