package
0.0.2
Repository: https://github.com/yubo/golib.git
Documentation: pkg.go.dev

# README

orm

Quick Start

  • Open orm
db, err := orm.Open(driverName, dataSourceName)
  • Define table struct to database
type User struct {
    Name   string
    Age    int
    Passwd *string
}
  • Exec runs a SQL string, it returns error
err := db.ExecNumErr("delete from user where name=?", "test")
  • Insert one record to database
err := db.Insert(&user)
// insert into user () values ()

err := db.Insert(&user, orm.WithTable("system_user"))
// insert into system_user () values ()
  • Query query one record from database
err := db.Query("select * from user limit 1").Row(&user)
  • check if one record or affected exist with query/exec
import "github.com/yubo/golib/api/errors"

if errors.IsNotFound(err) {
	// do something
}
  • Rows query multiple records from database
var users []User
err := db.Query("select * from user where age > ?", 10).Rows(&users)
  • Rows query multiple records from database with Count
var users []User
var total int64
err := db.Query("select * from user where age > ?", 10).Count(&total).Rows(&users)
// select * from user where age > 10
// select count(*) from user where age > 10
  • Update update one record
type User struct {
    Name   string `sql:",where"`
    Age    int
    Passwd *string
}

affected, err := db.Update(&user)
// if user.Passwd == nil
// update user set age=? where name = ?
// else
// update user set age=?, passwd=? where name = ?

affected, err := db.Update(&user, orm.WithTable("system_user"))
// update system_user set ... where name = ?
  • Transation
tx, err := db.Begin()
if err != nil {
	return err
}

// do something...

if err := tx.Insert(&user); err != nil {
	tx.Rollback()
	return err
}

return tx.Commit()

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
{1,2,3} => "(1,2,3)".
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
{"1","2","3"} => "('1', '2', '3')".
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Set is a map of field:value.
No description provided by the author