Categorygithub.com/go-the-way/anorm
repositorypackage
1.2.0-beta1
Repository: https://github.com/go-the-way/anorm.git
Documentation: pkg.go.dev

# Packages

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

# README

anorm

 _____  ____    ___    ____  ____  
(____ ||  _ \  / _ \  / ___)|    \ 
/ ___ || | | || |_| || |    | | | |
\_____||_| |_| \___/ |_|    |_|_|_|

::anorm:: 

An another generic ORM framework implementation using the new way for Go.

{{ Version @VER }}

{{ Powered by go-the-way }}

{{ https://github.com/go-the-way/anorm }}

CircleCI GitHub go.mod Go version codecov Go Report Card GoDoc Release

Features

  • DataSourcePool manage
  • Pager implementation
  • More levels logger
  • Support joins
  • Null fields
  • sql.Null types
  • Migrate DDL
  • Column definition
  • Index definition
  • Simple Tx manager
  • Insert batch
  • Support XmlQuery

Quickstart

package main

import (
	"database/sql"
	"fmt"

	a "github.com/go-the-way/anorm"
)

const (
	testDriverName = "mysql"
	testDSN        = "root:123456@tcp(localhost:3310)/test"
)

type Person struct {
	ID   int    `orm:"pk{T} c{id} ig{T} def{id int not null auto_increment comment 'ID'}"`
	Name string `orm:"pk{F} c{name} def{name varchar(20) not null default 'Coco' comment 'Name'}"`
}

func (p *Person) Configure(c *a.EC) {
	c.Migrate = true
	c.Table = "Table of Person"
}

func main() {
	db, err := sql.Open(testDriverName, testDSN)
	if err != nil {
		fmt.Println(err)
		return
	}
	a.DataSourcePool.Push(db)
	a.Register(new(Person))
	o := a.New(new(Person))
	count, err := o.OpsForSelectCount().Count(nil)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("count = ", count)
	}
}

ORM Struct Tag

TagNamePropertyNameDescriptionDefaultExample
pkPKTable primary keyfalsepk{1},pk{t},pk{T},pk{true},pk{TRUE},pk{True}
igInsertIgnoreIgnore when insertsfalseig{1},ig{t},ig{T},ig{true},ig{TRUE},ig{True}
ugUpdateIgnoreIgnore when updatesfalseug{1},ug{t},ug{T},ug{true},ug{TRUE},ug{True}
cColumnStruct property columnpropertyNamec{id},c{hello_world},c{halo_1234},c{WorldHa}
defDefinitionColumn definition SQLdef{address varchar(100) not null comment 'Address'}
joinJoinRefJoin Ref definitionjoin{inner,self_id,rel_table,rel_id,rel_name}