qsql

package module
v0.0.0-...-9b94054 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2016 License: MIT Imports: 3 Imported by: 41

README

qsql

Quick SQL queries, with maps and slices. See godoc.

Documentation

Overview

Package qsql implements SQL queries for the lazy, in the good ol' hashtable or list of hashtable format.

Example
package main

import (
	"fmt"

	_ "github.com/go-sql-driver/mysql"
	"github.com/thehowl/qsql"
)

func main() {
	db, err := qsql.Open("mysql", "root@/")
	if err != nil {
		panic(err)
	}
	defer db.Close()
	row, err := db.QueryRow("SELECT 5 AS test, 1 AS test_bool, 13.37 AS test_float")
	if err != nil {
		panic(err)
	}
	fmt.Printf(
		"test: %d | test_bool: %v | test_float: %.3f\n",
		row["test"].Int(), row["test_bool"].Bool(), row["test_float"].Float64(),
	)
}
Output:

test: 5 | test_bool: true | test_float: 13.370

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrDBIsNil = errors.New("qsql: db is nil")

ErrDBIsNil is returned when the *sql.DB inside DB is nil.

Functions

This section is empty.

Types

type DB

type DB struct {
	sql.DB
}

DB wraps an sql.DB around a custom DB.

If you're hardcore and want to create one without New(), you should &qsql.DB{*db}.

func New

func New(db *sql.DB) *DB

New creates a new *DB having an *sql.DB.

func Open

func Open(driverName, dsn string) (*DB, error)

Open behaves the same as sql.Open, but creates an *qsql.DB instead.

func (*DB) Exec

func (d *DB) Exec(query string, params ...interface{}) (int, int, error)

Exec behaves the same as sql.DB.Exec, however it does not wrap the last insert ID and rows affected into an interface.

func (*DB) ExecNoRes

func (d *DB) ExecNoRes(query string, params ...interface{}) error

ExecNoRes returns sql.DB.Exec without Result.

func (*DB) Query

func (d *DB) Query(query string, params ...interface{}) ([]map[string]String, error)

Query queries the database for multiple rows. See sql.DB.Query.

func (*DB) QueryRow

func (d *DB) QueryRow(query string, params ...interface{}) (map[string]String, error)

QueryRow queries the database for one row. See sql.DB.QueryRow.

type String

type String string

String is just a string, but it implements numerous functions to convert it to various types.

func (String) Bool

func (s String) Bool() bool

Bool converts s to a bool.

The following values are true:

  • 1
  • t
  • true
  • y
  • yes

All other values are false. Bool is not case sensitive.

func (String) Float32

func (s String) Float32() float32

Float32 will convert s to a float32. It will return 0 if conversion failed, with no error.

func (String) Float64

func (s String) Float64() float64

Float64 will convert s to a float64. It will return 0 if conversion failed, with no error.

func (String) Int

func (s String) Int() int

Int will convert s to an int. It will return 0 if conversion failed, with no error.

func (String) Int64

func (s String) Int64() int64

Int64 will convert s to an int64. It will return 0 if conversion failed, with no error.

func (String) String

func (s String) String() string

String is a shorthand for string(s).

func (String) Uint

func (s String) Uint() uint

Uint will convert s to an uint. It will return 0 if conversion failed, with no error.

func (String) Uint64

func (s String) Uint64() uint64

Uint64 will convert s to an uint64. It will return 0 if conversion failed, with no error.

Jump to

Keyboard shortcuts

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