handler

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: MIT Imports: 37 Imported by: 7

Documentation

Overview

Package handler provides a input process handler implementation for usql.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapErr added in v0.7.12

func WrapErr(buf string, err error) error

WrapErr wraps an error using the specified driver when err is not nil.

Types

type Error

type Error struct {
	Buf string
	Err error
}

Error wraps handler errors

func (*Error) Error

func (e *Error) Error() string

Error satisfies the error interface, returning the original error message

func (*Error) Unwrap added in v0.7.12

func (e *Error) Unwrap() error

Unwrap returns the original error

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler is a input process handler.

Glues together usql's components to provide a "read-eval-print loop" (REPL) for usql's interactive command-line and manages most of the core/high-level logic.

Manages the active statement buffer, application IO, executing/querying SQL statements, and handles backslash (\) commands encountered in the input stream.

func New

func New(l rline.IO, user *user.User, wd string, nopw bool) *Handler

New creates a new input handler.

func (*Handler) Begin added in v0.5.0

func (h *Handler) Begin(txOpts *sql.TxOptions) error

Begin begins a transaction.

func (*Handler) BeginTx added in v0.9.0

func (h *Handler) BeginTx(ctx context.Context, txOpts *sql.TxOptions) error

Begin begins a transaction in a context.

func (*Handler) Buf added in v0.4.0

func (h *Handler) Buf() *stmt.Stmt

Buf returns the current query statement buffer.

func (*Handler) ChangePassword added in v0.5.0

func (h *Handler) ChangePassword(user string) (string, error)

ChangePassword changes a password for the user.

func (*Handler) Close

func (h *Handler) Close() error

Close closes the database connection if it is open.

func (*Handler) Commit added in v0.5.0

func (h *Handler) Commit() error

Commit commits a transaction.

func (*Handler) DB added in v0.4.0

func (h *Handler) DB() drivers.DB

DB returns the sql.DB for the handler.

func (*Handler) Execute

func (h *Handler) Execute(ctx context.Context, w io.Writer, opt metacmd.Option, prefix, sqlstr string, forceTrans bool) error

Execute executes a query against the connected database.

func (*Handler) GetOutput added in v0.9.0

func (h *Handler) GetOutput() io.Writer

GetOutput gets the output writer.

func (*Handler) GetTiming added in v0.8.2

func (h *Handler) GetTiming() bool

GetTiming gets the timing toggle.

func (*Handler) Highlight added in v0.6.0

func (h *Handler) Highlight(w io.Writer, buf string) error

Highlight highlights using the current environment settings.

func (*Handler) IO added in v0.4.0

func (h *Handler) IO() rline.IO

IO returns the io for the handler.

func (*Handler) Include added in v0.4.0

func (h *Handler) Include(path string, relative bool) error

Include includes the specified path.

func (*Handler) Last added in v0.4.0

func (h *Handler) Last() string

Last returns the last executed statement.

func (*Handler) LastRaw added in v0.7.0

func (h *Handler) LastRaw() string

LastRaw returns the last raw (non-interpolated) executed statement.

func (*Handler) MetadataWriter added in v0.9.0

func (h *Handler) MetadataWriter(ctx context.Context) (metadata.Writer, error)

MetadataWriter loads the metadata writer for the

func (*Handler) Open

func (h *Handler) Open(ctx context.Context, params ...string) error

Open handles opening a specified database URL, passing either a single string in the form of a URL, or more than one string, in which case the first string is treated as a driver name, and the remaining strings are joined (with a space) and passed as a DSN to sql.Open.

If there is only one parameter, and it is not a well formatted URL, but appears to be a file on disk, then an attempt will be made to open it with an appropriate driver (mysql, postgres, sqlite3) depending on the type (unix domain socket, directory, or regular file, respectively).

func (*Handler) Password added in v0.4.0

func (h *Handler) Password(dsn string) (string, error)

Password collects a password from input, and returns a modified DSN including the collected password.

func (*Handler) Print added in v0.9.0

func (h *Handler) Print(format string, a ...interface{})

Print formats according to a format specifier and writes to handler's standard output.

func (*Handler) Prompt added in v0.4.0

func (h *Handler) Prompt() string

Prompt creates the prompt text.

func (*Handler) ReadVar added in v0.5.0

func (h *Handler) ReadVar(typ, prompt string) (string, error)

ReadVar reads a variable from the interactive prompt, saving it to environment variables.

func (*Handler) Reset

func (h *Handler) Reset(r []rune)

Reset resets the handler's query statement buffer.

func (*Handler) Rollback added in v0.5.0

func (h *Handler) Rollback() error

Rollback rollbacks a transaction.

func (*Handler) Run added in v0.4.0

func (h *Handler) Run() error

Run executes queries and commands.

func (*Handler) SetOutput added in v0.9.0

func (h *Handler) SetOutput(o io.WriteCloser)

SetOutput sets the output writer.

func (*Handler) SetSingleLineMode added in v0.7.1

func (h *Handler) SetSingleLineMode(singleLineMode bool)

SetSingleLineMode sets the single line mode toggle.

func (*Handler) SetTiming added in v0.8.2

func (h *Handler) SetTiming(timing bool)

SetTiming sets the timing toggle.

func (*Handler) URL added in v0.4.0

func (h *Handler) URL() *dburl.URL

URL returns the URL for the handler.

func (*Handler) User added in v0.4.0

func (h *Handler) User() *user.User

User returns the user for the handler.

func (*Handler) Version added in v0.4.0

func (h *Handler) Version(ctx context.Context) error

Version prints the database version information after a successful connection.

Jump to

Keyboard shortcuts

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