jjzjj

em-postgresql-adapter

全部标签

postgresql - 如何将 pq.Int64Array 转换为字符串?

在Golang应用程序中,我对PostgreSQL数据库进行sql查询,它返回了一个int数组。varidentifiers[]pq.Int64Array//ExecuteSQLqueryby"database/sql"package.iferr:=database.DBSQL.QueryRow(sqlStatement.String()).Scan(&identifiers);err!=nil{log.Println(err)utils.ResponseWithError(responseWriter,http.StatusInternalServerError,err.Error(

postgresql - 使用嵌套对象(结构)在 Go API 中插入数据

我正在创建一个GolangAPI,但遇到了障碍。对于每个POST,这就是我得到的:“错误”:“sql:转换参数$2类型:不支持的类型main.Data,一个结构”我希望我的数据是格式化的"name":"test","other":{"age":"","height":""}}我怎样才能做到这一点?请参阅下面的代码,了解我到目前为止所尝试的内容。模型.gotypeDatastruct{IDint`json:"id"`Namestring`json:"name,omitempty"`Other*Other`json:"other,omitempty"`}typeOtherstruct{Ag

postgresql - 如何使用 go pg CRUD Postgres Point 数据类型

我正在使用Point数据类型在Postgres数据库中存储坐标。如何将Point数据类型映射到Golang数据类型?我没有找到任何相同的文档。 最佳答案 go-pg没有对点类型的本地支持(从PostGIS开始)。我所做的立交桥(可能不是最好的解决方案,但我确实设法让它工作)是在我的模型上放置单独的纬度和经度字段,并在查询本身上使用ColumnExpr使用ST_X(对于经度)和ST_Y(对于纬度,不要忘记)获取单个值。型号:typeMyModelstruct{IDint64NamestringLocationLatfloat64Loc

postgresql - 将 postgresql jsonb 查询响应字符串解码为 golang 嵌套结构

我能够以字符串形式检索数据。但是我不知道如何将它解码到结构中。packagemainimport("database/sql""fmt""log""strconv"_"github.com/lib/pq")typeTokenstruct{NamestringValuestringPathstringHttpOnlybool}typeSessionstruct{Phishletstring`json:"phishlet,omitempty"`LandingURLstring`json:"landing_url,omitempty"`Usernamestring`json:"usernam

postgresql - Gorm 无法连接到本地 postgres 数据库

我是GoLang的新手,在将我的Go网络服务器与Postgres数据库连接时遇到了问题。有人可以告诉我我在这里做错了什么吗?顺便说一句,所有这些凭据都是正确的。用户存在,密码正确,数据库存在且属于用户。packageappimport("github.com/jinzhu/gorm"_"github.com/jinzhu/gorm/dialects/postgres")funcconnectDB(){db,err:=gorm.Open("postgres","host=localhostport=5432user=power_userdbname=local_dbpassword=po

Mongodb-go-adapter FindOne 吐出 { } 和 { 0}

一般FindOnefmt.printresult{}。我需要输出值。我正在使用来自文档的几乎标准设置:https://docs.mongodb.com/ecosystem/drivers/go/我在创建查询时遇到问题,因为大多数示例都是不同的;我试图遵循这种模式:https://github.com/ruanbekker/code-examples/blob/master/mongodb/golang/examples.go引用对象:_id:5d1a8829cf5042c071458db6name:"!hello"Value:"World%cend"Counter:0代码示例:type

postgresql - 从查询到 c.JSON 非常慢

我正在使用Gorm查询我的数据库,然后使用gin的c.JSON将结构编码为json。这是一个大型查询,结果不多(我不知道从哪里开始解决这个问题。[2019-07-0214:41:04][946.63ms]SELECTbigslowquery[62861rowsaffectedorreturned][GIN]2019/07/02-14:41:11|200|7.92347114s|ip|GET/api/date/2019-05-30[2019-07-0214:40:44][660.47ms]SELECTbigslowquery[7583rowsaffectedorreturned][GIN

postgresql - 如何创建一个在列中包含 slice 的表

我有一个看起来像这样的模型:typeInventorystruct{gorm.ModelLocationIDstringItems[]Item//thisisasliceofstructsCategories[]Category//thisisasliceofstructs}当我使用gorm为它创建一个表时,我没有项目或类别的列。我错过了什么? 最佳答案 因为数组在SQL中不支持列类型——至少大多数SQL版本是这样——gorm不会为slice类型的字段创建列。但是,您可以在使用关联后创建您现在的关系结构。在这种情况下,has-man

postgresql - 将字符串插入 jsonb 类型的 postgres

我的结构看起来像:typestruct1struct{idintcommentstringextrastring}我的表架构如下所示:createtabledeal(idbigserial,commentvarchar(75),extrajsonb)我想将[]struct1转储到PostgresDB“交易”。我生成准备好的语句的函数如下所示:funcBulkInsert(str[]struct1,ctxcontext.Context)string{log.Debug("insertingrecordstoDB")query:=fmt.Sprintf(`insertintodeal(%s

postgresql - 如何将 Google App Engine (Flex) Go 应用程序连接到 Google Cloud Postgres 实例

我正在使用Go构建应用程序并使用GoogleAppEngine进行部署。我已经在GoogleCloud上设置了一个PostgreSQL实例,启用了API并使用本地计算机上的SQL代理成功连接到它,包括本地PSequel客户端和我的应用程序。但是,当我执行gcloudappdeploy时,出现此错误:ERROR:(gcloud.app.deploy)ErrorResponse:[9]Applicationstartuperror:panic:dialunix/cloudsql/sapling:europe-west1:sapling/.s.PGSQL.5432:connect:nosuc