sqlexec

package
v1.0.0-rc8 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 14 Imported by: 2

Documentation

Overview

Package sqlexec provides primitives and functions to work with raw SQL statements and pre-defined SQL Scripts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PathDriver

func PathDriver(path string) string

PathDriver returns the driver name from a given path

Types

type FileSystem

type FileSystem = fs.FS

FileSystem provides with primitives to work with the underlying file system

type Generator

type Generator struct {
	// FileSystem represents the project directory file system.
	FileSystem WriteFileSystem
}

Generator generates a new command.

func (*Generator) Create

func (g *Generator) Create(path, name string) (string, string, error)

Create crates a new file and command for given file name and command name.

type Param

type Param = interface{}

Param is a command parameter for given query.

type Provider

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

Provider loads SQL sqlexecs and provides all SQL statements as commands.

func (*Provider) Dialect

func (p *Provider) Dialect() string

Dialect returns the dialect

func (*Provider) Query

func (p *Provider) Query(name string) (string, error)

Query returns a query statement for given name and parameters. The operation can err if the command cannot be found.

func (*Provider) ReadDir

func (p *Provider) ReadDir(storage FileSystem) error

ReadDir loads all sqlexec commands from a given directory. Note that all sqlexecs should have .sql extension.

func (*Provider) ReadFile

func (p *Provider) ReadFile(path string, storage FileSystem) error

ReadFile reads a given file

func (*Provider) ReadFrom

func (p *Provider) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the sqlexec from a reader

func (*Provider) SetDialect

func (p *Provider) SetDialect(value string)

SetDialect sets the dialect

type Rows

type Rows = sqlx.Rows

Rows is a wrapper around sql.Rows which caches costly reflect operations during a looped StructScan.

type Runner

type Runner struct {
	// FileSystem represents the project directory file system.
	FileSystem FileSystem
	// DB is a client to underlying database.
	DB *sqlx.DB
}

Runner runs a SQL statement for given command name and parameters.

func (*Runner) Print

func (r *Runner) Print(writer io.Writer, rows *sqlx.Rows) error

Print prints the rows

func (*Runner) Run

func (r *Runner) Run(name string, args ...Param) (*Rows, error)

Run runs a given command with provided parameters.

type Scanner

type Scanner struct{}

Scanner loads a SQL statements for given SQL Script

func (*Scanner) Scan

func (s *Scanner) Scan(reader io.Reader) map[string]string

Scan scans a reader for SQL commands that have name tag

type Splitter

type Splitter struct{}

Splitter splits a statement by GO separator

func (*Splitter) Split

func (s *Splitter) Split(reader io.Reader) []string

Split splits a statement by GO separator

type WriteFileSystem

type WriteFileSystem interface {
	FileSystem

	// OpenFile opens a new file
	OpenFile(string, int, fs.FileMode) (fs.File, error)
}

WriteFileSystem represents a wriable file system

Jump to

Keyboard shortcuts

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