handler

package
v0.0.0-...-e86feff Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2021 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	L rline.IO

	// connection
	U  *dburl.URL
	Db *sql.DB
	Tx *sql.Tx
	// contains filtered or unexported fields
}

Handler is a input process handler.

func New

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

New creates a new input handler.

func (*Handler) Begin

func (h *Handler) Begin() error

Begin begins a transaction.

func (*Handler) Buf

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

Buf returns the current query statement buffer.

func (*Handler) ChangePassword

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) CommandRunner

func (h *Handler) CommandRunner(cmds []string) func() error

CommandRunner executes a set of commands.

func (*Handler) Commit

func (h *Handler) Commit() error

Commit commits a transaction.

func (*Handler) DB

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

DB returns the sql.DB for the handler.

func (*Handler) Execute

func (h *Handler) Execute(w io.Writer, res metacmd.Res, prefix, qstr string, forceTrans bool) error

Execute executes a query against the connected database.

func (*Handler) Highlight

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

Highlight highlights using the current environment settings.

func (*Handler) IO

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

IO returns the io for the handler.

func (*Handler) Include

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

Include includes the specified path.

func (*Handler) Last

func (h *Handler) Last() string

Last returns the last executed statement.

func (*Handler) LastRaw

func (h *Handler) LastRaw() string

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

func (*Handler) Open

func (h *Handler) Open(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

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) Prompt

func (h *Handler) Prompt() string

Prompt creates the prompt text.

func (*Handler) ReadVar

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

func (h *Handler) Rollback() error

Rollback rollbacks a transaction.

func (*Handler) Run

func (h *Handler) Run() error

Run executes queries and commands.

func (*Handler) Scan

func (h *Handler) Scan(q *sql.Rows, clen int, tfmt string) ([]string, error)

Scan scans a row.

func (*Handler) Timefmt

func (h *Handler) Timefmt() string

Timefmt returns the current time format setting.

func (*Handler) URL

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

URL returns the URL for the handler.

func (*Handler) User

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

User returns the user for the handler.

func (*Handler) Version

func (h *Handler) Version() error

Version prints the database version information after a successful connection.

type OnOff

type OnOff struct {
	Bool    bool
	Assumed bool
}

OnOff is a type that wraps a bool, for use in parsing/displaying command parameters.

func (OnOff) MarshalText

func (b OnOff) MarshalText() ([]byte, error)

MarshalText satisfies the TextMarhsaler interface.

func (OnOff) String

func (b OnOff) String() string

String satisifies stringer.

func (*OnOff) UnmarshalText

func (b *OnOff) UnmarshalText(text []byte) error

UnmarshalText satisfies the TextUnmarshaler interface.

Jump to

Keyboard shortcuts

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