sqlu

package module
v0.0.0-...-4e3c2ae Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: MIT Imports: 5 Imported by: 0

README

sqlu

A very simple util for golang's database/sql package.

Example

import "github.com/ofabricio/sqlu"

func main() {

    u := User{}

    db.QueryRow(`
        SELECT
            33, 'John', JSON_OBJECT('Country', 'Home Sweet Home')
        LIMIT 1
    `).Scan(sqlu.Args(&u.ID, &u.Name, &u.Address)...)

    fmt.Println(u) // {33 John {Home Sweet Home}}
}

type User struct {
    ID      int64
    Name    string
    Address struct {
        Country string
    }
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Args

func Args(vs ...any) args

func ZeroAsNull

func ZeroAsNull(v any) any
Example (Int64)
var a int64

a = 3
fmt.Println(ZeroAsNull(a) == int64(3))
fmt.Println(ZeroAsNull(&a) == int64(3))

a = 0
fmt.Println(ZeroAsNull(a) == nil)
fmt.Println(ZeroAsNull(&a) == int64(0))
fmt.Println(ZeroAsNull((*int64)(nil)) == nil)
Output:

true
true
true
true
true
Example (String)
var a string

a = "a"
fmt.Println(ZeroAsNull(a) == "a")
fmt.Println(ZeroAsNull(&a) == "a")

a = ""
fmt.Println(ZeroAsNull(a) == nil)
fmt.Println(ZeroAsNull(&a) == "")
fmt.Println(ZeroAsNull((*string)(nil)) == nil)
Output:

true
true
true
true
true

func ZeroAsNulls

func ZeroAsNulls(vs ...any) []any

Types

This section is empty.

Jump to

Keyboard shortcuts

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