草庐IT

language-postgresql

全部标签

postgresql - 如何使用 beego/orm 解决 'no LastInsertId available'

我正在尝试使用https://github.com/astaxie/beego/tree/master/orm将struct插入到postgres数据库中。操作要简单import"github.com/astaxie/beego/orm"typeProductstruct{IDstring`orm:"pk"`...}product:=&Product{ID:productID}_,err:=orm.NewOrm().Insert(product)iferr!=nil{log.Fatal(err)}我不断得到这个;没有可用的LastInsertId每当代码运行时(否则插入成功)但我遇到了

postgresql - 将客户端 UUID 转换为 SQL UUID

我正在使用go和包uuid生成类型为[16]byte的uuid。但是,当我尝试将该uuid插入类型为uuid的postgres列时,出现错误convertingargument$1type:unsupportedtype[16]uint8,aarray。所以显然我应该在将它插入数据库之前转换客户端上的uuid。我该怎么做?我应该将其转换为什么类型?简而言之:在postgres中,什么go数据类型可以与uuid一起使用? 最佳答案 感谢来自@sberry的链接,我找到了成功。以下是有益于您的代码片段(使用PostgreSQL9.5数据

postgresql - 将客户端 UUID 转换为 SQL UUID

我正在使用go和包uuid生成类型为[16]byte的uuid。但是,当我尝试将该uuid插入类型为uuid的postgres列时,出现错误convertingargument$1type:unsupportedtype[16]uint8,aarray。所以显然我应该在将它插入数据库之前转换客户端上的uuid。我该怎么做?我应该将其转换为什么类型?简而言之:在postgres中,什么go数据类型可以与uuid一起使用? 最佳答案 感谢来自@sberry的链接,我找到了成功。以下是有益于您的代码片段(使用PostgreSQL9.5数据

postgresql - DefaultServeMux 中的 SQL 给出错误

我正在尝试在Go中做一个RESTAPI。查询在放置在主处理程序中时有效(显示在终端中),但在移动到所需的处理程序时会在浏览器中出错。localhost:8080/http:panicserving[::1]:51100:runtimeerror:invalidmemoryaddressornilpointerdereferencelocalhost:8080/getuserGetuserpackagemainimport("fmt""log""net/http""database/sql"_"github.com/lib/pq")const(host="127.0.0.1"port=5

postgresql - DefaultServeMux 中的 SQL 给出错误

我正在尝试在Go中做一个RESTAPI。查询在放置在主处理程序中时有效(显示在终端中),但在移动到所需的处理程序时会在浏览器中出错。localhost:8080/http:panicserving[::1]:51100:runtimeerror:invalidmemoryaddressornilpointerdereferencelocalhost:8080/getuserGetuserpackagemainimport("fmt""log""net/http""database/sql"_"github.com/lib/pq")const(host="127.0.0.1"port=5

postgresql - Sqlx 获取准备好的语句

我正在尝试使用准备好的语句从postgress表中获取一些数据如果我尝试使用database.Get()返回所有内容。表格:createtableaccounts(idbigserialnotnullconstraintaccounts_pkeyprimarykey,identificatortextnotnull,passwordtextnotnull,salttextnotnull,typesmallintnotnull,levelsmallintnotnull,created_attimestampnotnull,updatedtimestampnotnull,expiry_da

postgresql - Sqlx 获取准备好的语句

我正在尝试使用准备好的语句从postgress表中获取一些数据如果我尝试使用database.Get()返回所有内容。表格:createtableaccounts(idbigserialnotnullconstraintaccounts_pkeyprimarykey,identificatortextnotnull,passwordtextnotnull,salttextnotnull,typesmallintnotnull,levelsmallintnotnull,created_attimestampnotnull,updatedtimestampnotnull,expiry_da

postgresql - 使用 SQLX 转到可选字段

我正在学习Go并尝试创建一个具有“字段”参数的API端点。当我尝试将sqlx结果行扫描到结构中时,但是用户省略的字段将作为空字符串返回。有没有办法可以更改结构以仅反射(reflect)用户传递的字段?我不认为我想使用omitempty以防例如user_name是一个空字符串。typeUserstruct{Idint`db:"id"`UserNamestring`db:"user_name"`}funcGetUsers(whttp.ResponseWriter,r*http.Request,db*sqlx.DB){acceptedFields:=map[string]bool{"id":

postgresql - 使用 SQLX 转到可选字段

我正在学习Go并尝试创建一个具有“字段”参数的API端点。当我尝试将sqlx结果行扫描到结构中时,但是用户省略的字段将作为空字符串返回。有没有办法可以更改结构以仅反射(reflect)用户传递的字段?我不认为我想使用omitempty以防例如user_name是一个空字符串。typeUserstruct{Idint`db:"id"`UserNamestring`db:"user_name"`}funcGetUsers(whttp.ResponseWriter,r*http.Request,db*sqlx.DB){acceptedFields:=map[string]bool{"id":

postgresql - 使用 gorm 更新 postgres 表

我在尝试更新表格中的行时遇到问题。我尝试了以下方法:returnss.db.Where("name=?",sub.Name).Save(&sub).Error和returnss.db.Save(sub).Error我也试过这个的变体s:=ss.db.Where("Name=?",sub.Name)returnss.db.Model(&s).Updates(Subscription{Name:sub.Name,DevicesAllowed:sub.DevicesAllowed,Price:sub.Price,Active:sub.Active}).Error我还尝试了其他几种没有奏效的方