db

package module
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 9 Imported by: 0

README

db

sqlx wrapper for mysql

how to use

conf

conf.toml

[db]
IP = "your ip default 127.0.0.1"
Port = "your port default :3306"
Uname = "your uname default null"
Passwd = "your passwd default null"
DB = "your db default null"

read

  1. List

    db.NewRead().List(query, args)

  2. ListNamed

    db.NewRead().ListNamed(query, args)

  3. ListStruct

    package main
    
    import (
        "database/sql"
        "fmt"
        "log"
    
        "github.com/tiantour/db"
    )
    
    type Person struct {
        Name string
        Age  int
    }
    
    func main() {
        var person []*Person
        query := "SELECT name, age FROM `demo` WHERE age = ? LIMIT 10;"
        err := db.NewRead().ListStruct(&person, query, 18)
        if err!=nil{
            log.Panic(err)
        }
        fmt.Println(person)
    }
    
  4. ListStructNamed

        package main
    
        import (
            "database/sql"
            "fmt"
            "log"
    
            "github.com/tiantour/db"
        )
    
        type Person struct {
            Name string
            Age  int
        }
    
        func main() {
            args := Person{
                Age: 18,
            }
    
            var person []*Person
            query := "SELECT name, age FROM `demo` WHERE age = :age LIMIT 10;"
            err := db.NewRead().ListStruct(&person, query, person)
            if err!=nil{
                log.Panic(err)
            }
            fmt.Println(person)
        }
        ```
    
    
  5. Item

    db.NewRead().Item(query, args)

  6. ItemNamed

    db.NewRead().ItemNamed(query, args)

  7. ItemStruct

    db.NewRead().ItemStruct(dest, query, args)

  8. ItemStructNamed

    db.NewRead().ItemStructNamed(dest, query, args)

write

  1. List

    db.NewWrite().List(query, args)

  2. ListNamed

    db.NewWrite().List(query, args)

  3. Item

    db.NewWrite().Item(query, args)

  4. ItemNamed

    db.NewWrite().ItemNamed(query, args)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New added in v1.1.6

func New() *sqlx.DB

Types

type Read

type Read struct{}

Read Read

func NewRead

func NewRead() *Read

NewRead new read

func (*Read) Item

func (r *Read) Item(query string, args ...interface{}) (*sqlx.Row, error)

Item read item

func (*Read) ItemNamed

func (r *Read) ItemNamed(query string, args interface{}) (*sqlx.Row, error)

ItemNamed read item named

func (*Read) ItemStruct

func (r *Read) ItemStruct(dest interface{}, query string, args ...interface{}) error

ItemStruct read item struct

func (*Read) ItemStructNamed

func (r *Read) ItemStructNamed(dest interface{}, query string, args interface{}) error

ItemStructNamed item struct named

func (*Read) List

func (r *Read) List(query string, args ...interface{}) (*sqlx.Rows, error)

List read list

func (*Read) ListNamed

func (r *Read) ListNamed(query string, args interface{}) (*sqlx.Rows, error)

ListNamed read list named

func (*Read) ListStruct

func (r *Read) ListStruct(dest interface{}, query string, args ...interface{}) error

ListStruct read list struct

func (*Read) ListStructNamed

func (r *Read) ListStructNamed(dest interface{}, query string, args interface{}) error

ListStructNamed list struct named

type Write

type Write struct{}

Write write

func NewWrite

func NewWrite() *Write

NewWrite new *Write

func (*Write) Item

func (w *Write) Item(query string, args ...interface{}) (sql.Result, error)

Item write

func (*Write) ItemNamed

func (w *Write) ItemNamed(query string, args interface{}) (sql.Result, error)

ItemNamed wirte item named

func (*Write) List

func (w *Write) List(query string, args ...[]interface{}) (sql.Result, error)

List write list

func (*Write) ListNamed

func (w *Write) ListNamed(query string, args ...interface{}) (sql.Result, error)

ListNamed write list named

Jump to

Keyboard shortcuts

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