问题标签 [go-pg]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
go - 无法更新 jsonb(即子数组)列
我刚刚开始使用 go-pg,并且在使用 PostgreSQL DB 的 JSONB 功能时遇到了一些问题。
我已将我的模型结构定义为:
在 Chemical 结构中 - 通过使用sql:",array"ListingDetails 字段上的标签 - 我的理解是这应该映射到目标表中的 jsonb 列。使用 go-pg 的 CreateTable - 使用 listing_details jsonb 列创建化学品表 - 所以在这方面一切都很好。
但是,我似乎无法成功更新此字段(在数据库中)。当我最初在数据库中创建化学记录时 - 没有 ListingInfos - 我稍后会回去更新它们。下面是一个片段,展示了我是如何做到这一点的。
但我总是收到如下所示的错误消息。我究竟做错了什么??
postgresql - Retrieving arbitrary data into nested object with ORM
I am attempting to develop an api in go, to allow the user to specify an arbitrary data structure, and easily set up endpoints that perform CRUD operations on an auto generated postgres database, based on the structure that they define.
For now, I have been using gorm, and am able to have a database automatically generated based on a user-defined set of structs, that support all types of relations (has one, one to many, etc.). I am also able to insert into the generated database, when JSON is sent in through the endpoints.
The issue I have discovered, is when I try to receive the data. It seems where many of the go ORMs fall short on, is mapping data from all tables back into the nested structs of the parent struct.
For example, if the user defines:
The database creates the tables:
Members
- id
- first_name
Hometowns
- id
- city
- province
- member_refer
However, when retrieving the data, all that is mapped back is:
Does anyone know of a go orm that supports this kind of behaviour?
Thanks
go - 处理动态查询(无法扫描到结构中)
当使用查询结构是静态的 go-pg 时 - 直接查询/扫描到已知结构就像做梦一样。但是,我正在努力处理动态查询——那些没有结构可供扫描的查询。
例如,根据一些运行时参数 - 查询可能如下所示:
或者它可能是
或者
我一直在试图弄清楚如何使用将结果加载到地图中。下面的代码抛出错误“无效字符'\'寻找值的开头”
我刚刚开始学习围棋——我完全迷路了。关于如何处理动态查询的任何提示
go - Golang go-pg 关系递归查询
我需要加入递归,像这样:
我的模型定义是:
我尝试使用关系但没有用:
我如何在 go-pg 上实现递归连接,如果有人有经验,请告诉我。非常感谢。
postgresql - go-pg:将 postgresql 复合类型行的数组解析为 golang 结构切片
我正在将复杂的 PostgreSQL 选择结果解析为 golang 结构。我能够将文本数组解析为一个字段并将复合类型的行解析为另一个,但我还需要将第二个字段设为行数组,并且我无法使用 go- 解析此数组(行())结构pg 驱动程序。
这是返回单行作为字段的工作 SQLvariants
这是需要解析的 SQL 请求
请注意,字段变体已从子选择中array()添加和limit 1删除构造函数。
在golang代码中产品结构有这个字段定义
我正在寻找将第二行重写为类似的能力
但是这样(并通过更改 SQL 请求)我得到了 go-pg 错误:panic: got slice, wanted struct
完整代码如下。
用于创建和填充数据库的 SQL
这是从 postgresql 服务器中选择数据的 golang 代码
此 go 代码导致此输出
go - 使用 pg.Array 时如何将 reflect.Pointer() 转换为 []string?
我正在使用 go-pg 编写一个自定义查询缓存系统,该系统接受一个传递给 Query 函数的查询参数并生成一个用于 Redis 的哈希键。我正在使用 Go 的反射来检查有效的参数类型,直到我使用 pg.Array 作为传递的参数。
Reflect 给了我 reflect.Ptr,但是当调用 switch case 块时如何提取指针的结构/数组?
pg.Array 定义:https ://sourcegraph.com/github.com/lib/pq/-/blob/array.go#L29:6
编辑:发布的链接对 pg.Array 的定义不正确。我不小心从 sourcegraph.com 抓取了错误的库。
postgresql - 如何使用 go pg CRUD Postgres Point 数据类型
我正在使用 Point 数据类型在 Postgres DB 中存储坐标。如何将 Point 数据类型映射到 Go lang 数据类型?我没有找到任何相同的文档。
postgresql - 有没有办法用 go-pg 或 go 中的任何方法动态创建 Postgres 数据库?
我正在开展一个项目,该项目涉及我为每个客户动态创建数据库。我可以用 PHP 和 MySQL 做到这一点,但为了优化,项目语言被更改为 Go 和 PostgreSQL。所以我想看看是否有办法用 go-pg 或 Go 中的任何方法来实现这一点。
postgresql - 加入时不明确的列引用
结构
询问
db.Model(&Trade).Where("id = ", tradeId).Relation("Client").Select()
遇到错误:列 ID 不明确。不确定解决此问题的正确方法是什么如果有人可以提供帮助会很棒