beego 连接postgres
2024-08-27 23:25:13
package main import (
"fmt"
"github.com/astaxie/beego/orm"
"mybee/models"
_ "mybee/routers"
"github.com/astaxie/beego" _ "github.com/lib/pq"
) func init() {
// PostgreSQL 配置
orm.RegisterDriver("postgres", orm.DRPostgres) // 注册驱动
orm.RegisterDataBase("default", "postgres", "user=odoo password=odoo dbname=mybee host=127.0.0.1 port=15432 sslmode=disable") // 自动建表
orm.RunSyncdb("default", false, true)
} func main() {
orm.Debug = true
o := orm.NewOrm()
o.Using("default")
user := new(models.User)
user.Name = "tom"
user.Age = 25 fmt.Println(o.Insert(user))
beego.Run()
}
package models import (
"github.com/astaxie/beego/orm"
) type User struct {
Id int64
Name string
Age int
} func init() {
orm.RegisterModel(new(User))
}
最新文章
- HDU3371 最小生成树
- Java将文件转为字节数组
- this和$(this)区别
- yii::app(); 怎么得到module、controller、action的名字
- 移动设备上的媒体查询 CSS media queries for mobile device
- 使用git批量删除分支
- 04_天气查询_JAX-WS方式_服务端
- windows for windows:下载、安装
- Android TimeAnimator
- LOJ 534 花团(线段树+dfs栈)
- codesmith连接postgresql修复bug
- Grasshopper操作shp
- phper必知必会(二)
- react中的children使用方法
- STM32启动代码分析
- 3.Hadoop测试Yarn和MapReduce
- yum命令具体解释
- 微信支付的SDK曝出重大漏洞(XXE漏洞)
- shell set 命令
- 【整理】mysql中information_schema.tables字段说明
热门文章
- ORA-00904: 标识符无效——解决方案
- Struts1使用技巧
- DAY11-MYSQL补充之SQL逻辑查询语句执行顺序
- AOP基础-JDK动态代理
- mahout in Action研读(1)-给用户推荐图书
- Eclipse Maven 编译错误 Dynamic Web Module 3.0 requires Java 1.6 or newer 解决方案
- Android中pull解析XML文件的简单使用
- [patl2-007]家庭房产
- 数组中的最大值以及最小值的位置变换的问题(C++)
- cakephp静态资源404