facebook的golang orm库:ent

Golang 归档:202004
普通
浏览:143
2020-04-30 11:21:46
ent is a simple, yet powerful entity framework for Go built on SQL/Gremlin with the following principles

An entity framework for Go
Simple, yet powerful ORM for modeling and querying data.

官网地址:

https://entgo.io/

项目地址

https://github.com/facebookincubator/ent

使用文档地址

https://entgo.io/docs/getting-started/

代码演示

mysql client

package main

import (
    "log"

    "<project>/ent"

    _ "github.com/go-sql-driver/mysql"
)

func main() {
    client, err := ent.Open("mysql", "<user>:<pass>@tcp(<host>:<port>)/<database>?parseTime=True")
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()
}

PostgreSQL client

package main

import (
    "log"

    "<project>/ent"

    _ "github.com/lib/pq"
)

func main() {
    client, err := ent.Open("postgres","host=<host> port=<port> user=<user> dbname=<database> password=<pass>")
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()
}
注意事项
  • 此文章对你有帮助,对作者表示感谢(微信):
  • 本文地址:https://22v.net/article/3255/
  • 转载本文时,请注明转载自“SamBlog”的字样。
  • 如此文章有损您的合法权益,请使用页面底部的邮箱与我取得联系。
分类目录
文章归档
友情站点