草庐IT

mysql_field_name

全部标签

database - SQLX "missing destination name"在结构标记中使用表名时

问题是当我对对象使用结构标签时,它们无法正常工作。我以前做过同样的事情但没有遇到任何问题的项目,但我不明白为什么。示例:这不起作用:typeCategorystruct{IDint`json:"id"db:"category.id"`Namestring`json:"name"db:"category.name"`Descriptionstring`json:"description"db:"category.description"`}收到错误:*[]Category中缺少目的地名称ID这很好用:typeCategorystruct{IDint`json:"id"db:"id"`Na

mysql - golang sql.open() 期望 0 个参数得到 1

我正在尝试使用golang连接到我在本地拥有的mysql数据库,它构建得很好,但运行它时出现以下错误:panic:sql:expected0arguments,got1我的连接是这样的:packagemainimport("database/sql""fmt"_"github.com/go-sql-driver/mysql")funcDBConn(){team:="software"db,err:=sql.Open("mysql","root:12345678@tcp(localhost:3306)/flexlocal")iferr!=nil{fmt.Println("thisiswh

mysql - 如何在 golang 中编写一个通用方法以在任何 mysql 表中插入记录

我正在golang中创建一个restapi,并向表中发出一个POST请求。为此,我创建了一个结构。基本上,struct中的变量与名为users的表中的列相同。并编写了一个函数来发出POST请求。代码运行良好,发出POST请求时的参数已成功插入表中。typeUserstruct{IDintNamestringLnamestringCountrystring}funcinsertUser(responsehttp.ResponseWriter,request*http.Request){varuserDetailsUserdecoder:=json.NewDecoder(request.B

mysql - 使用 Gorm 更新为 0 值

我正在尝试使用gorm库更新一些值,但是没有更新值为0的字节和整数vartreatmentmodel.TreatmentDBerr=json.Unmarshal(b,&treatment)iferr!=nil{http.Error(w,err.Error(),500)return}fmt.Println(&treatment)db:=db.DB.Table("treatment").Where("id=?",nID).Updates(&treatment)此打印值是{0310002018-01-014001-01-01}那些0是字节值(数据库中的tinyint(1),如果我更改为int

go - 如何与本地主机上的 mysql 服务器建立连接?

我想与本地主机上的sqlserver建立新连接,以便能够从sqlserver获取数据。但是在连接时出现了一些问题。错误:-[mysql]2019/02/1115:30:00driver.go:81:net.ErrorfromDial()':dialtcpserverPort:3306:connect:connectiontimedout我使用的代码是funcConnectMsqlDb()(db*sql.DB,errerror){db,err=sql.Open("mysql",fmt.Sprintf("%s:%s@tcp(%s:"+SqlDbPort+")/"+SqlDatabase,S

sql-server - sql : Scan error on column index 0, name "": unsupported Scan, 将 driver.Value 类型 int64 存储到类型 *main.SMSBlast 中?

我现在正在尝试restfulapi,其中列SequenceID不是自动增量,因为故意的,当我像这样计数时,我的问题是库gormcountSequenceId:=db.Debug().Table("SMSBlast2").Count(&smsblast1),结果是sql:列索引0上的扫描错误,名称“”:不支持的扫描,将driver.Value类型int64存储到类型*main.SMSBlastpackagemainimport("encoding/json""fmt""github.com/gorilla/mux""github.com/jinzhu/gorm"_"github.com/

xml - 在 Golang 中编码 XML : field is empty (APPEND doesn't work? )

我正在学习用Go创建XML。这是我的代码:typeRequeststruct{XMLNamexml.Name`xml:"request"`Actionstring`xml:"action,attr"`...Point[]point`xml:"point,omitempty"`}typepointstruct{geostring`xml:"point"`radiusint`xml:"radius,attr"`}funcmain(){v:=&Request{Action:"get-objects"}v.Point=append(v.Point,point{geo:"55.703038,37

mysql - 无法将 mysql 中的时间戳值提取到 time.Time 变量中

我无法将mysql时间戳值放入time.Time变量中我正在尝试扫描一行,除了mysql中的时间戳类型外,所有值都已成功扫描,我已经在使用dsnparseTime=true,这是我搜索的问题之一,但它没有帮助typeTagsstruct{IDintCreatedAttime.Time`json:"created_at"`}funcfoo5(){http.HandleFunc("/tags/",bar5)http.ListenAndServe(":8080",nil)}funcbar5(whttp.ResponseWriter,r*http.Request){db,err:=sql.Op

go - 如何通过struct field Name取值

typemcatstruct{IDint}typecatstruct{NamestringMmcat}funcgetValue(pathstring,mcatcat){//throuthstructpathgetthevalue}funcmain(){mycat:=cat{"cat",mcat{1}}id:=getvalue("/M/ID",mycat)}我可以通过反射获取基于字段名称的值来做到这一点吗? 最佳答案 你可以用Value.FieldByName()做你想做的事功能。只需覆盖可能使用strings.Split()分割的路

采空区 : type mismatch: no fields matched compiling decoder - Golang

我在两个不同的流上使用PubSub,我们从一个流接收消息,运行一些逻辑,如果它符合特定条件,我们将它发布到第二个流。第二个流也在goroutine中接收。现在,我有两个主要函数HandleMessage和HandleRetry,其中前者来自第一个流,第二个用于第二个流。HandleMessage的相关代码如下:ifc.handler.ShouldProcess(tx){err:=c.handler.Process(tx)iferr!=nil{c.log.WithError(err).WithField("tx_hash",tx.TxHash.String()).Error("faile