Skip to content

Commit

Permalink
Rework internals
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshaw committed Nov 9, 2024
1 parent 2d63b05 commit 3d5325f
Show file tree
Hide file tree
Showing 28 changed files with 3,267 additions and 2,943 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-2024 Kenneth Shaw
Copyright (c) 2015-2024 Kenneth Shaw

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -705,25 +705,30 @@ General
Query Execute
\g [(OPTIONS)] [FILE] or ; execute query (and send results to file or |pipe)
\crosstabview [(OPTIONS)] [COLUMNS] execute query and display results in crosstab
\go [(OPTIONS)] [FILE] alias for \g
\G [(OPTIONS)] [FILE] as \g, but forces vertical output mode
\ego [(OPTIONS)] [FILE] alias for \G
\gx [(OPTIONS)] [FILE] as \g, but forces expanded output mode
\gexec execute query and execute each value of the result
\gset [PREFIX] execute query and store results in usql variables
\gx [(OPTIONS)] [FILE] as \g, but forces expanded output mode
\crosstabview [(OPTIONS)] [COLUMNS] execute query and display results in crosstab
\chart CHART [(OPTIONS)] execute query and display results as a chart
\watch [(OPTIONS)] [DURATION] execute query every specified interval
\bind [PARAM]... set query parameters
Query Buffer
\e [FILE] [LINE] edit the query buffer (or file) with external editor
\edit [-exec] edit the query (or exec) buffer
\p show the contents of the query buffer
\raw show the raw (non-interpolated) contents of the query buffer
\exec show the contents of the exec buffer
\r reset (clear) the query buffer
\w FILE write query buffer to file
Help
\? [commands] show help on backslash commands
\? options show help on usql command-line options
\? variables show help on special variables
\? variables show help on special usql variables
Input/Output
\copy SRC DST QUERY TABLE copy query from source url to table on destination url
Expand All @@ -735,6 +740,12 @@ Input/Output
\i FILE execute commands from file
\ir FILE as \i, but relative to location of current script
Conditional
\if EXPR begin conditional block
\elif EXPR alternative within current conditional block
\else final alternative within current conditional block
\endif end conditional block
Informational
\d[S+] [NAME] list tables, views, and sequences or describe table, view, sequence, or index
\da[S+] [PATTERN] list aggregates
Expand All @@ -761,17 +772,18 @@ Formatting
Transaction
\begin begin a transaction
\begin [-read-only] [ISOLATION] begin a transaction with isolation level
\begin -read-only ISOLATION begin a transaction with isolation level
\commit commit current transaction
\rollback rollback (abort) current transaction
Connection
\c DSN connect to database url
\c DRIVER PARAMS... connect to database with driver and parameters
\cset [NAME [DSN]] set named connection, or list all if no parameters
\cset show named connections
\cset NAME DSN set named connection
\cset NAME DRIVER PARAMS... define named connection for database driver
\Z close database connection
\password [USERNAME] change the password for a user
\password [USER] change password for user
\conninfo display information about the current database connection
Operating System
Expand All @@ -782,7 +794,7 @@ Operating System
\timing [on|off] toggle timing of commands
Variables
\prompt [-TYPE] VAR [PROMPT] prompt user to set variable
\prompt [-TYPE] VAR [PROMPT] prompt user to set variable
\set [NAME [VALUE]] set internal variable, or list all if no parameters
\unset NAME unset (delete) internal variable
```
Expand Down
7 changes: 3 additions & 4 deletions drivers/completer/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package completer

import (
"fmt"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -690,13 +689,13 @@ func CompleteFromListCase(ct caseType, text []rune, options ...string) [][]rune
}

func completeFromVariables(text []rune, prefix, suffix string, needValue bool) [][]rune {
vars := env.All()
vars := env.Vars().Vars()
names := make([]string, 0, len(vars))
for name, value := range vars {
if needValue && value == "" {
continue
}
names = append(names, fmt.Sprintf("%s%s%s", prefix, name, suffix))
names = append(names, prefix+name+suffix)
}
return CompleteFromListCase(MATCH_CASE, text, names...)
}
Expand Down Expand Up @@ -930,7 +929,7 @@ func (c completer) getNamespaces(f metadata.Filter) []string {
return names
}

func (c completer) completeWithAttributes(ct caseType, selectable string, text []rune, options ...string) [][]rune {
func (c completer) completeWithAttributes(_ caseType, selectable string, text []rune, options ...string) [][]rune {
names := make([]string, 0, 10)
if r, ok := c.reader.(metadata.ColumnReader); ok {
parent := parseParentIdentifier(selectable)
Expand Down
20 changes: 10 additions & 10 deletions drivers/metadata/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (w DefaultWriter) DescribeFunctions(u *dburl.URL, funcTypes, pattern string
}
return v
})
params := env.Pall()
params := env.Vars().Print()
params["title"] = "List of functions"
return tblfmt.EncodeAll(w.w, res, params)
}
Expand Down Expand Up @@ -271,7 +271,7 @@ func (w DefaultWriter) describeTableDetails(typ, sp, tp string, verbose, showSys
}
return v
})
params := env.Pall()
params := env.Vars().Print()
params["title"] = fmt.Sprintf("%s %s\n", typ, qualifiedIdentifier(sp, tp))
return w.encodeWithSummary(res, params, w.tableDetailsSummary(sp, tp))
}
Expand Down Expand Up @@ -501,7 +501,7 @@ func (w DefaultWriter) describeSequences(sp, tp string, verbose, showSystem bool
s := res.Get()
// wrap current record into a separate recordSet
rows := NewSequenceSet([]Sequence{*s})
params := env.Pall()
params := env.Vars().Print()
params["footer"] = "off"
params["title"] = fmt.Sprintf("Sequence \"%s.%s\"\n", s.Schema, s.Name)
err = tblfmt.EncodeAll(w.w, rows, params)
Expand Down Expand Up @@ -532,7 +532,7 @@ func (w DefaultWriter) describeIndex(i *Index) error {
return []interface{}{f.Name, f.DataType}
})

params := env.Pall()
params := env.Vars().Print()
params["title"] = fmt.Sprintf("Index %s\n", qualifiedIdentifier(i.Schema, i.Name))
return w.encodeWithSummary(res, params, func(out io.Writer, _ int) (int, error) {
primary := ""
Expand All @@ -559,7 +559,7 @@ func (w DefaultWriter) ListAllDbs(u *dburl.URL, pattern string, verbose bool) er
}
defer res.Close()

params := env.Pall()
params := env.Vars().Print()
params["title"] = "List of databases"
return tblfmt.EncodeAll(w.w, res, params)
}
Expand Down Expand Up @@ -611,7 +611,7 @@ func (w DefaultWriter) ListTables(u *dburl.URL, tableTypes, pattern string, verb
return v
})

params := env.Pall()
params := env.Vars().Print()
params["title"] = "List of relations"
return tblfmt.EncodeAll(w.w, res, params)
}
Expand All @@ -635,7 +635,7 @@ func (w DefaultWriter) ListSchemas(u *dburl.URL, pattern string, verbose, showSy
return !ok
})
}
params := env.Pall()
params := env.Vars().Print()
params["title"] = "List of schemas"
return tblfmt.EncodeAll(w.w, res, params)
}
Expand Down Expand Up @@ -683,7 +683,7 @@ func (w DefaultWriter) ListIndexes(u *dburl.URL, pattern string, verbose, showSy
return v
})

params := env.Pall()
params := env.Vars().Print()
params["title"] = "List of indexes"
return tblfmt.EncodeAll(w.w, res, params)
}
Expand Down Expand Up @@ -767,7 +767,7 @@ func (w DefaultWriter) ShowStats(u *dburl.URL, statTypes, pattern string, verbos
return v
})

params := env.Pall()
params := env.Vars().Print()
params["title"] = "Column stats"
return tblfmt.EncodeAll(w.w, res, params)
}
Expand Down Expand Up @@ -816,7 +816,7 @@ func (w DefaultWriter) ListPrivilegeSummaries(u *dburl.URL, pattern string, show
return v
})

params := env.Pall()
params := env.Vars().Print()
params["title"] = "Access privileges"
return tblfmt.EncodeAll(w.w, res, params)
}
Expand Down
5 changes: 2 additions & 3 deletions drivers/snowflake/snowflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ func init() {
})
}

func listAllDbs(db drivers.DB, w io.Writer, pattern string, verbose bool) error {
func listAllDbs(db drivers.DB, w io.Writer, _ string, _ bool) error {
rows, err := db.Query("SHOW databases")
if err != nil {
return err
}
defer rows.Close()

params := env.Pall()
params := env.Vars().Print()
params["title"] = "List of databases"
return tblfmt.EncodeAll(w, rows, params)
}
Loading

0 comments on commit 3d5325f

Please sign in to comment.