Skip to content

beanscc/brows

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

brows

将 sql.Rows 绑定赋值给结构体

Installation

  • install brows
go get github.com/beanscc/brows
  • import
import "github.com/beanscc/brows"

Quick start

package main

import (
	"database/sql"

	"github.com/beanscc/brows"
)

func main() {
	type User struct {
		ID   int64  `db:"id"`
		Name string `db:"name"`
		Age  uint   `db:"age"`
	}

	var users []User
	db := getDb()

	query := `select id,name,age from test where age > ?`
	err := brows.New(db).Query(query, 10).Scan(&users)
	if err != nil {
		// error handle
	}
}

func getDb() *sql.DB {
	var db *sql.DB
	// init db

	return db
}

About

将 sql.Rows 绑定赋值给结构体

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages