Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement completable methods #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions pkg/trino/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,56 @@ func (s *TrinoDatasource) Converters() (sc []sqlutil.Converter) {
}

func (s *TrinoDatasource) Schemas(ctx context.Context, options sqlds.Options) ([]string, error) {
// TBD
return []string{}, nil
query := "SHOW SCHEMAS"
args := []string{}
if options["database"] != "" {
query += " FOR ?"
args = append(args, options["database"])
}
rows, err := s.db.Query(query, args)
if err != nil {
return nil, err
}
return getNames(rows)
}

func (s *TrinoDatasource) Tables(ctx context.Context, options sqlds.Options) ([]string, error) {
// TBD
return []string{}, nil
query := "SHOW TABLES"
args := []string{}
if options["schema"] != "" {
query += " FOR ?"
args = append(args, options["schema"])
}
rows, err := s.db.Query(query, args)
if err != nil {
return nil, err
}
return getNames(rows)
}

func (s *TrinoDatasource) Columns(ctx context.Context, options sqlds.Options) ([]string, error) {
// TBD
return []string{}, nil
query := "SHOW COLUMNS"
args := []string{}
if options["table"] != "" {
query += " FOR ?"
args = append(args, options["table"])
}
rows, err := s.db.Query(query, args)
if err != nil {
return nil, err
}
return getNames(rows)
}

func getNames(rows *sql.Rows) ([]string, error) {
results := []string{}
name := ""
for rows.Next() {
err := rows.Scan(&name)
if err != nil {
return nil, err
}
results = append(results, name)
}
return results, nil
}