Skip to content

Commit

Permalink
feat(client): update the database implementations to be complaint wit…
Browse files Browse the repository at this point in the history
…h databaseQuerier interface
  • Loading branch information
danvergara committed Nov 15, 2024
1 parent 09b3fa6 commit f1b1495
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/client/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ func newMSSQL() *mssql {
return &m
}

func (m *mssql) ShowTablesPerDB(database string) (string, []interface{}, error) {
return fmt.Sprintf(
"SELECT table_name FROM information_schema.tables WHERE table_schema = %s",
database,
), nil, nil
}

func (m *mssql) ShowDatabases() (string, []interface{}, error) {
return "SELECT name FROM master.dbo.sysdatabases", nil, nil
}

func (m *mssql) ShowTables() (string, []interface{}, error) {
psql := sq.StatementBuilder.PlaceholderFormat(sq.AtP)

Expand Down
8 changes: 8 additions & 0 deletions pkg/client/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ func newMySQL() *mysql {
return &m
}

func (m *mysql) ShowTablesPerDB(database string) (string, []interface{}, error) {
return fmt.Sprintf("SHOW TABLES FROM %s;", database), nil, nil
}

func (m *mysql) ShowDatabases() (string, []interface{}, error) {
return "SHOW DATABASES;", nil, nil
}

// ShowTables returns a query to retrieve all the tables.
func (m *mysql) ShowTables() (string, []interface{}, error) {
query := "SHOW TABLES;"
Expand Down
8 changes: 8 additions & 0 deletions pkg/client/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ func newOracle() *oracle {
return &o
}

func (p *oracle) ShowTablesPerDB(dabase string) (string, []interface{}, error) {
return "", nil, nil
}

func (p *oracle) ShowDatabases() (string, []interface{}, error) {
return "", nil, nil
}

// ShowTables returns a query to retrieve all the tables.
func (p *oracle) ShowTables() (string, []interface{}, error) {
query := "SELECT table_name FROM user_tables"
Expand Down
44 changes: 44 additions & 0 deletions pkg/client/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,50 @@ func newPostgres(schema string) *postgres {
return &p
}

func (p *postgres) ShowTablesPerDB(dabase string) (string, []interface{}, error) {
var (
query string
err error
args []interface{}
)
psql := sq.StatementBuilder.PlaceholderFormat(sq.Dollar)
query, args, err = psql.Select("table_name").
From("information_schema.tables").
Where(sq.Eq{"table_type": "BASE TABLE"}).
Where(
sq.And{
sq.Eq{"table_schema": "public"},
sq.Eq{"table_type": "BASE TABLE"},
},
).
OrderBy("table_name").
ToSql()
if err != nil {
return "", nil, err
}

return query, args, nil
}

func (p *postgres) ShowDatabases() (string, []interface{}, error) {
var (
query string
err error
args []interface{}
)
psql := sq.StatementBuilder.PlaceholderFormat(sq.Dollar)
query, args, err = psql.Select("datname").
From("pg_database").
Where(sq.Eq{"datistemplate": "false"}).
OrderBy("datname").
ToSql()
if err != nil {
return "", nil, err
}

return query, args, nil
}

// ShowTables returns a query to retrieve all the tables under a specific schema.
func (p *postgres) ShowTables() (string, []interface{}, error) {
var (
Expand Down
8 changes: 8 additions & 0 deletions pkg/client/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ func newSQLite() *sqlite {
return &s
}

func (s *sqlite) ShowTablesPerDB(dabase string) (string, []interface{}, error) {
return "", nil, nil
}

func (s *sqlite) ShowDatabases() (string, []interface{}, error) {
return "", nil, nil
}

// ShowTables returns a query to retrieve all the tables.
func (s *sqlite) ShowTables() (string, []interface{}, error) {
query := `
Expand Down

0 comments on commit f1b1495

Please sign in to comment.