database

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateOffset

func CalculateOffset(page, limit int) int

CalculateOffset calculates `OFFSET` value for query.

Types

type Database

type Database struct {
	*sql.DB
}

func New

func New(driver, address string, maxIdleConn int) (Database, error)

New returns `Database` instance.

func (Database) ExecuteQuery added in v0.0.3

func (d Database) ExecuteQuery(query string, args ...interface{}) (sql.Result, error)

ExecuteQuery is dedicated to `INSERT`, `UPDATE` and `DELETE` queries. Prefer this if you are 100% sure that the query arguments are SQL Injection free. It is a fast operation as it issues a single network round-trip (`Query`). The query string must be prepared with `fmt.Sprintf` function using appropriate formatters.

fmt.Sprintf(`INSERT INTO table (name, age, active) VALUES (%q, %d, %t)`)

func (Database) PreparedQuery added in v0.0.3

func (d Database) PreparedQuery(query string, args ...interface{}) (sql.Result, error)

PreparedQuery is dedicated to `INSERT`, `UPDATE` and `DELETE` queries. Prefer this if you are not 100% sure that the query arguments are SQL Injection free. It is a slow operation as it triples the number of network round-trips (`Prepare`, `Execute` and `Close`). The query must use `?` placeholders.

`INSERT INTO table (name, age, active) VALUES (?, ?, ?)`

Jump to

Keyboard shortcuts

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