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 ¶
- Variables
- type DB
- func (d *DB) Exec(query string, params ...interface{}) (int, int, error)
- func (d *DB) ExecNoRes(query string, params ...interface{}) error
- func (d *DB) Query(query string, params ...interface{}) ([]map[string]String, error)
- func (d *DB) QueryRow(query string, params ...interface{}) (map[string]String, error)
- type String
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 (*DB) Exec ¶
Exec behaves the same as sql.DB.Exec, however it does not wrap the last insert ID and rows affected into an interface.
type String ¶
type String string
String is just a string, but it implements numerous functions to convert it to various types.
func (String) 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 ¶
Float32 will convert s to a float32. It will return 0 if conversion failed, with no error.
func (String) Float64 ¶
Float64 will convert s to a float64. It will return 0 if conversion failed, with no error.
func (String) Int ¶
Int will convert s to an int. It will return 0 if conversion failed, with no error.
func (String) Int64 ¶
Int64 will convert s to an int64. It will return 0 if conversion failed, with no error.