ezorm

package module
v0.0.0-...-9d28e1e Latest Latest
Warning

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

Go to latest
Published: May 29, 2018 License: MIT Imports: 14 Imported by: 1

README

EZORM

Build Status Code Coverage GoDoc

Introduction

An easy ORM tool for Golang, support MyBatis-Like XML template SQL

Features

  • Full-Featured ORM (almost)
  • MyBatis-Like XML template SQL
  • Developer Friendly

Getting Started

type RowType struct{
	Id int
	Name string
}

type DAO struct{
	Id int
	Name string
	List []RowType `stmt:"complexQueryRowTest"`
}

func main(){
	err := ezorm.Register("default","mysql","root:@tcp(localhost:3306)/mysql?charset=utf8&parseTime=True&loc=Local","./config/")
	if err!=nil{
		log.Fatal(err.Error())
	}

	rs,err := ezorm.Use("default").Update("main","createTestDB",nil)

	if err!=nil{
		log.Fatal(err.Error())
	}

	log.Printf("createTestDB result:%v\n",rs)

	rs,err = ezorm.Use("default").Update("main","createTestTable",nil)

	if err!=nil{
		log.Fatal(err.Error())
	}

	log.Printf("createTestTable result:%v\n",rs)

	rs,err = ezorm.Use("default").Insert("main","insertTest", &struct {
		Name string
	}{
		Name:"hello ezorm",
	})

	if err!=nil{
		log.Fatal(err.Error())
	}

	log.Printf("insertTest result:%v\n",rs)

	rows := make([]RowType,0)

	err = ezorm.Use("default").QueryRows("main","queryRowsTest",nil,&rows)

	if err!=nil{
		log.Fatal(err.Error())
	}

	log.Printf("queryRowsTest result:%v\n",rows)

	row := RowType{
		Id:1,
	}

	err = ezorm.Use("default").QueryRow("main","queryRowTest",&row,&row)

	if err!=nil{
		log.Fatal(err.Error())
	}

	log.Printf("queryRowTest result:%v\n",row)

	dao := DAO{
		Id:1,
		Name:"hello ezorm",
	}

	err = ezorm.Use("default").Query(&dao)

	if err!=nil{
		log.Fatal(err.Error())
	}

	log.Printf("complexQueryRowTest result:%v\n",dao)
}

License

© Schbook, 2018~time.Now

Released under the MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(dbName, driverName, dataSourceName, mapperPath string) error

func ToInt64

func ToInt64(value interface{}) (d int64)

ToInt64 interface to int64

func ToStr

func ToStr(value interface{}, args ...int) (s string)

ToStr interface to string

Types

type SqlFactory

type SqlFactory interface {
	QueryRows(namespace, id string, param interface{}, rows interface{}) error
	QueryRow(namespace, id string, param interface{}, row interface{}) error
	Query(param interface{}) error
	Insert(namespace string, id string, param interface{}) (lastInsertId int64, err error)
	Update(namespace string, id string, param interface{}) (rowsAffected int64, err error)
	Execute(sqlType, namespace string, id string, param interface{}) (cnt int64, err error)
	GetDB() (db *sql.DB, err error)
}

func Use

func Use(dbName string) SqlFactory

type StrTo

type StrTo string

StrTo is the target string

func (StrTo) Bool

func (f StrTo) Bool() (bool, error)

Bool string to bool

func (*StrTo) Clear

func (f *StrTo) Clear()

Clear string

func (StrTo) Exist

func (f StrTo) Exist() bool

Exist check string exist

func (StrTo) Float32

func (f StrTo) Float32() (float32, error)

Float32 string to float32

func (StrTo) Float64

func (f StrTo) Float64() (float64, error)

Float64 string to float64

func (StrTo) Int

func (f StrTo) Int() (int, error)

Int string to int

func (StrTo) Int16

func (f StrTo) Int16() (int16, error)

Int16 string to int16

func (StrTo) Int32

func (f StrTo) Int32() (int32, error)

Int32 string to int32

func (StrTo) Int64

func (f StrTo) Int64() (int64, error)

Int64 string to int64

func (StrTo) Int8

func (f StrTo) Int8() (int8, error)

Int8 string to int8

func (*StrTo) Set

func (f *StrTo) Set(v string)

Set string

func (StrTo) String

func (f StrTo) String() string

String string to string

func (StrTo) Uint

func (f StrTo) Uint() (uint, error)

Uint string to uint

func (StrTo) Uint16

func (f StrTo) Uint16() (uint16, error)

Uint16 string to uint16

func (StrTo) Uint32

func (f StrTo) Uint32() (uint32, error)

Uint32 string to uint31

func (StrTo) Uint64

func (f StrTo) Uint64() (uint64, error)

Uint64 string to uint64

func (StrTo) Uint8

func (f StrTo) Uint8() (uint8, error)

Uint8 string to uint8

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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