#What would be the best ORM (except GORM) for Postgres DB?

29 messages · Page 1 of 1 (latest)

amber kelp
#

I've been searching and see many ORMs are changed to Maintenance mode... any suggestion?

halcyon sleet
tawdry linden
#

State of thought here (mine, overall herders and community members) is that most orms are unidiomatic, slow, and often encourage bad patterns

#

If you are having trouble building dynamic queries, a query builder is all you should need

#

squirrel and goqu should fit that purpose

#

goqu is overall an excellent wrapper around database/sql

amber kelp
#

how about its security? Better to use the plain database/sql or orm?

tawdry linden
#

same thing, in both cases, never throw user input into your query

amber kelp
#

thank you

#

i do recall when i wanted to get data of a relational tables, with ORM was pretty easy. But not sure if wanna use the database/sql only, should i write so much code for that?

amber kelp
halcyon sleet
#

No, don't. That's cursed.
ORM might be safer, since you don't write your own query and do some cursed things like constructing query using string function, instead of prepare statement and binding.

boreal knoll
#

ORMs are no safer than database/sql with parametrized queries

amber kelp
#

so what would be the suggestion here? use database/sql or orm ?

amber kelp
halcyon sleet
waxen lake
#

Modern DB engines allow you to specify parameterized queries and do sanitization on your behalf.

You can do this without an ORM, while writing your own SQL.

amber kelp
amber kelp
boreal knoll
#

Sanitization is not quite the same as parameterization. Sanitization can fail, parameterization cannot

amber kelp
#

hmm, that means none of those ORM / libs are sql-injection free?

boreal knoll
#

The opposite: using parameterization protects you entirely from SQL injection

errant rain
# amber kelp so what would be the suggestion here? use `database/sql` or `orm` ?

Most people here from what I've seen recommend https://github.com/kyleconroy/sqlc or https://github.com/jmoiron/sqlx along with database/sql instead of any ORM. They give you some of the benefits without royally screwing you in the future. In fact the methods they use to solve the cost involved in SQL (code generation or data mapping) are fairly widely accepted as better solutions to ORMs in most modern languages from what I've seen as well.

halcyon sleet
#

With prepared statement and binding, query and data are send separately. So there is no injection.

#

Though, both solutions (orm vs not orm) are capable of it.

waxen lake
amber kelp
#

thanks guys