github.com/angenalZZZ/gofunc@v0.0.0-20210507121333-48ff1be3917b/data/bulk/gorm-bulk/struct.go.sample (about)

     1  package main
     2  
     3  import (
     4  	"time"
     5  	// "github.com/jinzhu/gorm"
     6  )
     7  
     8  // ONCE_INSERT_NUM should be under 200 because if over it, occurred error `too many SQL variables`
     9  const onceInsertNum = 199
    10  
    11  type Record struct {
    12  	// If valid belowe, add columns id, created_at, updated_at and deleted_at automatically.
    13  	// gorm.Model
    14  
    15  	ID           int        `gorm:"AUTO_INCREMENT" json:"id"` // set id to auto incrementable
    16  	Name         string     `json:"name"`
    17  	Age          int        `json:"age"`
    18  	Birthday     *time.Time `json:"birthday"`
    19  	Email        string     `gorm:"type:varchar(100);unique_index" json:"email"`
    20  	Role         string     `gorm:"size:255" json:"role"`                 // set field size to 255
    21  	MemberNumber *string    `gorm:"unique;not null" json:"member_number"` // set member number to unique and not null
    22  	Address      string     `gorm:"index:addr" json:"address"`            // create index with name `addr` for address
    23  	IgnoreMe     int        `gorm:"-" json:"ignore_me"`                   // ignore this field
    24  }
    25  
    26  func (r Record) TableName() string {
    27  	// Set table name what you want as plural
    28  	return "records"
    29  }
    30  
    31  // Specify file name
    32  var dbFileName = "analysis.db"