I was just wondering if anyone has worked with xo. I have a Postgres DB, with a bunch of tables and stuff.
I can't seem to generate DTO struct
s from postgres table structures using xo
.
This builtin xo
template seems to create a struct
, and I believe xo
uses the built-in templates by default, but all I get when I run
xo --verbose --suffix '.go' pgsql://myusername:mypass@localhost:myport/mydb?sslmode=disable -o internal/qo/models -p qo
is a bunch of files which are compl etely unrelated to my project or the schemas in my DB.
So from what I've found, the xo
package's postgreSQL loader uses "public" as the default schema, and in my DB, the schema named "public" only has the table named schema_migrations
and a lot of stored procedures, thus resulting in the above set of appropriately generated code.
On using --schema <correct_schema_name>
where <correct_schema_name>
is the schema for which the dto structs are to be generated, the correct code is generated.
So, the correct command is :
xo --verbose --schema <correct_schema_name> --suffix '.go' pgsql://myusername:mypass@localhost:myport/mydb?sslmode=disable -o internal/qo/models -p qo
There are also a couple of settings in the gen.sh file which have to be changed as well, such as the type information (specifically the default values) in order to generate the structs with the correct field types.
For example, the default type for timestamps is pq.NullTime
(pq is a Golang Driver for PostgreSQL), and is to be changed in the gen.sh
file in order to set the proper default type.