sqls

package module
v0.0.0-...-6d9a0ad Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2020 License: MIT Imports: 2 Imported by: 0

README

sqls

go sql utility

nonull

wrap type to a shadow type for skip NULL value from query result.

usage
func QueryNullable() {
	type User struct {
		Id   int `nonull:"-"`
		Name string
		Age  int
	}
	db := sqlx.MustOpen("sqlite3", ":memory:")
	defer db.Close()
	db.MustExec(`CREATE TABLE user (id int not null primary key, name varchar(10), age int)`)
	db.MustExec(`insert into user (id, name, age) values (?, ?, ?)`, 1, "user1", 10)
	db.MustExec(`insert into user (id, name) values (?, ?)`, 2, "user2")
	var user User
	err := db.Get(&user, `select * from user where id = ?`, 2)
	fmt.Println("try get user 2", err)
	err = db.Get(nonull.Wrap(&user), `select * from user where id = ?`, 2)
	fmt.Println("get user 2", err, user)
	var users []User
	err = db.Select(nonull.Wrap(&users), `select * from user`, 2)
	fmt.Println("get all users", err, users)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool bool

func (*Bool) Scan

func (p *Bool) Scan(src interface{}) error

type F64

type F64 float64

func (*F64) Scan

func (p *F64) Scan(src interface{}) error

type I32

type I32 int32

func (*I32) Scan

func (p *I32) Scan(src interface{}) error

type I64

type I64 int64

func (*I64) Scan

func (p *I64) Scan(src interface{}) error

type String

type String string

func (*String) Scan

func (p *String) Scan(src interface{}) error

type Time

type Time time.Time

func (*Time) Scan

func (p *Time) Scan(src interface{}) error

type U32

type U32 int32

func (*U32) Scan

func (p *U32) Scan(src interface{}) error

type U64

type U64 int64

func (*U64) Scan

func (p *U64) Scan(src interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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