dba

package module
v0.0.0-...-334307e Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: MIT Imports: 12 Imported by: 0

README

dba

Tools for working with databases in the shell

dba

A shell tool for connecting to mysql databases and running tools/commands, also works with wps go tool to create wps entries when creating users.

install
git clone git@github.com:drewart/dba.git
cd dba
go install ./cmd/dba/.

# install mycli mysql connection tool
pip3 install mycli
shell commands
  • list : lists servers from $HOME/..cnf files and $(pwd)/..cnf
  • list dev : lists dev servers or servers with dev in the name
  • pick digit : picks server number for current context
  • mpick digit,digit : picks many server number for current context used with mcli*
  • digit : picks the server context
  • database context commands
    • cli : (mac/linux gnome) opens new terminal with mycli
    • cli2 : opens mycli connection in dba shell
    • mcli : (mac/linux gnome) opens new terminal with mycli
    • my : (mac/linux gnome) opens mysql client in new terminal
    • my2 : opens mysql client connection in dba shell
    • cu foobar : creates user foobar
    • cur foobar : creates read only user foobar
    • init foobar : WIP creates database foobar create user foobar and foobar_ro
    • databases : list database on server
    • tables : list tables for current database selected
    • use foobar : switches database context for current server
  • mcli needs tmux + xpanes installed
future
  • select prod: auto selects prod databases
  • combine cli mcli base on connection context
  • cache obj storage for server -> databases -> tables, user -> grants, refresh
  • find table
  • find column
  • mysqldump schema and/or data
  • auto fill database/tables from like mycli based on commands
  • auto fill users like mycli based on employee data or mysql.user data
  • easy standard grant ui
  • add mongo support or mongo mode

web server

list databases

future
  • mysqladmin like tool but for user management
  • list of users and database they are in
  • list databases
  • tabs tables
  • find user
  • add user
  • update passwords
  • remove passwords

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDatabase

func GetDatabase(conn *sql.DB) string

add users

func GetDatabases

func GetDatabases(conn *sql.DB) []string

add users

func GetTables

func GetTables(conn *sql.DB) []string

add users

func GetTime

func GetTime(conn *sql.DB) string

add users

func ListFiles

func ListFiles(dir string, filter string) ([]string, error)

FilteredFiles returns file from a directory based on filter string i.e. .cnf

func Run

func Run(conn *sql.DB, sql string) error

func UseDB

func UseDB(conn *sql.DB, db string)

Types

type Admin

type Admin struct {
	Database string
	UserList []User
	// contains filtered or unexported fields
}

func (*Admin) AddGrant

func (a *Admin) AddGrant(g Grant) error

func (*Admin) AddUser

func (a *Admin) AddUser(user User) error

func (*Admin) Close

func (a *Admin) Close()

func (*Admin) CreateDB

func (a *Admin) CreateDB(name string) error

func (*Admin) GenPassword

func (a *Admin) GenPassword() string

func (*Admin) GetUsers

func (a *Admin) GetUsers() []User

func (*Admin) GetUsersWithGrants

func (a *Admin) GetUsersWithGrants() []User

list users

func (*Admin) ListGrants

func (a *Admin) ListGrants(user User)

list grants

func (*Admin) SetConn

func (a *Admin) SetConn(conn *sql.DB)

type Column

type Column struct {
	Name string
	Type string
}

type Connection

type Connection struct {
	Name string
}

type ConnectionConfig

type ConnectionConfig struct {
	Name string
	File string
}

func (ConnectionConfig) Connect

func (c ConnectionConfig) Connect() Connection

type Database

type Database struct {
	Name   string
	Tables []Table
}

type Grant

type Grant struct {
	Raw string
}

type Picker

type Picker struct {
	CurrentDB      *config.Config
	MultiCurrentDB []int
	AllConfigs     []config.Config
	// contains filtered or unexported fields
}

func (*Picker) ClearMultiCurrent

func (p *Picker) ClearMultiCurrent()

func (*Picker) Close

func (p *Picker) Close()

func (*Picker) FindConfigs

func (p *Picker) FindConfigs()

func (*Picker) GetCurrentConn

func (p *Picker) GetCurrentConn() *sql.DB

func (*Picker) IsCurrentSet

func (p *Picker) IsCurrentSet() bool

func (*Picker) ListDatabases

func (p *Picker) ListDatabases()

func (*Picker) ListFilter

func (p *Picker) ListFilter(filter string)

func (*Picker) SetCurrent

func (p *Picker) SetCurrent(i int)

func (*Picker) SetMultiCurrent

func (p *Picker) SetMultiCurrent(indexes []int)

type Table

type Table struct {
	Name    string
	Columns []Column
}

type User

type User struct {
	Username string
	Password string
	Host     string
	Grants   []Grant
}

func (*User) AddGrant

func (u *User) AddGrant(g Grant)

func (*User) ToString

func (u *User) ToString() string

Directories

Path Synopsis
cmd
db
dba

Jump to

Keyboard shortcuts

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