sql

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sql implements a SQL database.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRows = sql.ErrNoRows

ErrNoRows is returned by the Scanner when there are no rows to scan.

Functions

This section is empty.

Types

type Database

type Database struct {
	DB *sql.DB
	db.Config
}

Database is a SQL db.Database with additional configuration

func (Database) Exec

func (db Database) Exec(ctx context.Context, queries ...Query) error

Exec evaluates multiple queries in a transaction, ensuring each execSQLFunction one only updates one row.

func (Database) Query

func (db Database) Query(ctx context.Context, q Query, dest ...interface{}) error

Query queries a single row, scanning into the destination array.

func (Database) Setup

func (db Database) Setup(ctx context.Context, files []io.Reader) error

Setup initializes the database by reading the files and executing their contents as raw queries.

type ExecFunction

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

ExecFunction is a db Query that changes data.

func NewExecFunction

func NewExecFunction(name string, args ...interface{}) ExecFunction

NewExecFunction creates a Query to call an exec function.

func (ExecFunction) Args

func (e ExecFunction) Args() []interface{}

Args returns the arguments for the exec function.

func (ExecFunction) Cmd

func (e ExecFunction) Cmd() string

Cmd returns a SQL string to execute the function with arguments.

type Query

type Query interface {
	// cmd is the injection-safe message to send to the database.
	Cmd() string
	// args are the user-provided properties of the messages which should be escaped.
	Args() []interface{}
}

Query is a message that is sent to the database.

type QueryFunction

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

QueryFunction is a db Query that reads data.

func NewQueryFunction

func NewQueryFunction(name string, cols []string, args ...interface{}) QueryFunction

NewQueryFunction creates a Query to call a query function.

func (QueryFunction) Args

func (q QueryFunction) Args() []interface{}

Args returns the arguments for the query function.

func (QueryFunction) Cmd

func (q QueryFunction) Cmd() string

Cmd returns a SQL string to execute the function with arguments.

type RawQuery

type RawQuery string

RawQuery is a db Query that changes data and has no arguments..

func (RawQuery) Args

func (RawQuery) Args() []interface{}

Args returns nil for the raw SQL query.

func (RawQuery) Cmd

func (r RawQuery) Cmd() string

Cmd returns the raw SQL query.

Directories

Path Synopsis
Package postgres implements an SQL Database for Postgres servers.
Package postgres implements an SQL Database for Postgres servers.

Jump to

Keyboard shortcuts

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