草庐IT

postgresql-9.6

全部标签

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我还尝试了其他几种没有奏效的方

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我还尝试了其他几种没有奏效的方

postgresql - Golang SQL封装jsonb算子

在postgresqljsonb的sql包中,我如何使用@>运算符进行字符串查询,例如WHEREdata@>'{"stringdata":$1}'或WHEREdata@>'{"stringdata":"$1"}'不起作用替代方案是data->>'string_data'=$1我不喜欢用于多个语句错误是:"Message":"invalidinputsyntaxfortypejson","Detail":"Token\"$\"isinvalid.”,"Where":"JSONdata,line1:$...","Routine":"report_invalid_token"

postgresql - Golang SQL封装jsonb算子

在postgresqljsonb的sql包中,我如何使用@>运算符进行字符串查询,例如WHEREdata@>'{"stringdata":$1}'或WHEREdata@>'{"stringdata":"$1"}'不起作用替代方案是data->>'string_data'=$1我不喜欢用于多个语句错误是:"Message":"invalidinputsyntaxfortypejson","Detail":"Token\"$\"isinvalid.”,"Where":"JSONdata,line1:$...","Routine":"report_invalid_token"