#What would be the best ORM (except GORM) for Postgres DB?
29 messages · Page 1 of 1 (latest)
Go Databases and ORMs, https://blog.teamortix.com/posts/2021/08/go-databases - hhhapz
To ORM or not to ORM, https://eli.thegreenplace.net/2019/to-orm-or-not-to-orm/ - Etzelia
Dropping Gorm, https://alanilling.com/exiting-the-vietnam-of-programming-our-journey-in-dropping-the-orm-in-golang-3ce7dff24a0f - Madxmike
try https://entgo.io
though, its not ORM and does not have iterator interface.
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
how about its security? Better to use the plain database/sql or orm?
same thing, in both cases, never throw user input into your query
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?
you mean i should use printf() and pass to the query right?
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.
ORMs are no safer than database/sql with parametrized queries
so what would be the suggestion here? use database/sql or orm ?
This is the prevailing advice
what do you mean by "that's cursed" ? if don't use printf() what else can use to make sure we sanitize the input before passing it to the sql query?
printf does not sanitize anything.
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.
what do you mean by ModernDBs? Postgres doesn't have this feature, afaik...
oh... yea that's right.. so i assume the ORMs also don't sanitize the special character..?
Sanitization is not quite the same as parameterization. Sanitization can fail, parameterization cannot
hmm, that means none of those ORM / libs are sql-injection free?
The opposite: using parameterization protects you entirely from SQL injection
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.
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.
Parameterization is what I meant.
thanks guys