我只是想知道是否有人使用过 xo .我有一个 Postgres 数据库,里面有一堆表和东西。
我似乎无法使用 xo
从 postgres 表结构生成 DTO struct
。
这个内置的xo
template似乎创建了一个 struct
,我相信 xo
默认使用内置模板,但我在运行时得到的都是
xo --verbose --suffix '.go' pgsql://myusername:mypass@localhost:myport/mydb?sslmode=disable -o internal/qo/models -p qo
最佳答案
所以根据我的发现,xo
包裹的 postgreSQL loader使用“public”作为默认模式,在我的数据库中,名为“public”的模式只有名为 schema_migrations
的表和很多存储过程,从而导致上述一组适当生成的代码。
关于使用--schema <correct_schema_name>
其中 <correct_schema_name>
是要为其生成 dto 结构的架构,则生成正确的代码。
所以,正确的命令是:
xo --verbose --schema <correct_schema_name> --suffix '.go' pgsql://myusername:mypass@localhost:myport/mydb?sslmode=disable -o internal/qo/models -p qo
gen.sh 中还有一些设置。还必须更改的文件,例如类型信息(特别是默认值),以便生成具有正确字段类型的结构。
例如,时间戳的默认类型是 pq.NullTime
(pq 是 PostgreSQL 的 Golang 驱动程序),将在 gen.sh
中更改文件以便设置正确的默认类型。
关于postgresql - 使用 xo 从 postgres 数据库表模式生成 DTO 结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54996599/