Tag:gorm

  • A detailed explanation of formatting time in golang Gorm

    Time:2019-12-11

    Preface Recently, I encountered a problem when I was developing a project, Gorm can automatically help you maintain the created at, updated at, and deleted at key time fields. But its principle and disadvantages need to be understood. 1. Usage Control the time format by customizing the structure of a Localtime package utils import ( […]

  • The solution of Gorm golang concurrent connection database error reporting

    Time:2019-12-7

    Error: cannot assign requested address Reason In the concurrent scenario, the client frequently requests the port to establish a TCP connection, which results in the port being exhausted Solution Root Sysctl – W net. IPv4. Tcp_timestamps = 1 enable support for TCP timestamps. If this is set to 0, the following setting will not work […]

  • Gorm associated query

    Time:2019-10-28

    Defined aUserandCompany, UserCan contain multipleCompanyAs follows: type User struct { ID int `gorm:”TYPE:int(11);NOT NULL;PRIMARY_KEY;INDEX”` Name string `gorm:”TYPE: VARCHAR(255); DEFAULT:”;INDEX”` Companies []Company `gorm:”FOREIGNKEY:UserId;ASSOCIATION_FOREIGNKEY:ID”` CreatedAt time.Time `gorm:”TYPE:DATETIME”` UpdatedAt time.Time `gorm:”TYPE:DATETIME”` DeletedAt *time.Time `gorm:”TYPE:DATETIME;DEFAULT:NULL”` } type Company struct { gorm.Model Industry int `gorm:”TYPE:INT(11);DEFAULT:0″` Name string `gorm:”TYPE:VARCHAR(255);DEFAULT:”;INDEX”` Job string `gorm:”TYPE:VARCHAR(255);DEFAULT:””` UserId int `gorm:”TYPE:int(11);NOT NULL;INDEX”` } QueryUserHope to bringCompanyThere are […]

  • SQL + RESTful Open Source GO Scaffolding Tool ginbro (gin and gorm’s brother) Detailed

    Time:2019-9-20

    Install Felix git clone https://github.com/dejavuzhou/felix cd felix go mod download go install Echo “Add GOBIN to PATH environment variables” Echo “or” go get github.com/dejavuzhou/felix echo “go build && ./felix -h” What is Ginbro Gin Scaffolding Tool: Because MySQL database + gin + GORM is used many times to develop RESTful API program in work, so […]

  • Basic usage of golang Gorm operation MySQL and Gorm

    Time:2019-3-22

    Golang’s official operation of MySQL is a little troublesome, so it uses gorm. Here’s a brief introduction to the use of Gorm Download gorm: go get -u github.com/jinzhu/gorm Introduce Gorm into the project: import ( “github.com/jinzhu/gorm” _ “github.com/jinzhu/gorm/dialects/mysql” ) Define DB connection information func DbConn(MyUser, Password, Host, Db string, Port int) *gorm.DB { connArgs := […]

  • PHP turns to Go, and uses Laravel and ThinkPHP to build a ThinkGo framework

    Time:2019-3-12

    ThinkGo is a lightweight MVC framework of Go language. At present, it supports the basic functions of Web frameworks such as routing, middleware, controller, request, response, Session, view and log. It is dedicated to making the code concise and expressive, and helping developers build a Web application quickly. install go get -u github.com/thinkoner/thinkgo usage package […]