Live data from Hacker News

To ORM or Not to ORM

eli.thegreenplace.net

211–220 of 300 posts

Re: To ORM or Not to ORM

#211

I've come to a couple conclusions, over the years. First, when you get down to it, the most-valued feature of ORMs is not the "writing queries in some language other than SQL" feature, it's the "not having to write a mess of mapping code" feature. Second, the biggest drawbacks to ORMs all derive from the "writing queries in some language other than SQL" feature. Fortunately, there are tools out there that solve the "…

> Fortunately, there are tools out there that solve the "mapping tables to objects" problem without trying to control all access to the database

In javascript land there is PureORM which seeks this balance (https://github.com/craigmichaelmartin/pure-orm)

Re: To ORM or Not to ORM

#212

The number one reason to use SQL is not a reason not to use an ORM. SQL is extremely powerful - it can make your data sit up, roll over, play dead and even speak. Learning how to harness that power is worth while. So maybe use an ORM now, while you are learning SQL.

Or use a "pure orm" (mapping to plain business objects) without a query builder - thus writing native sql and receiving nicely structured objects from the results (eg https://github.com/craigmichaelmartin/pure-orm)

Re: To ORM or Not to ORM

#213
post #35

Personally I think an active record style ORM for Go like gorm is a poor fit for a language that doesn't come across as inherently OOP. Going through some of the documentation for gorm, it seems to rely heavily on method chaining which for Go seems wrong considering how errors are handled in that language. In my opinion, an ORM should be as idiomatic to the language as possible. I've used sqlx[1] before, and it feels…

sqlx + squirrel:

    func dbAllPostsInTag(db *sqlx.DB, tagID int64) ([]post, error) {
        posts := []post{}
        query := squirrel.Select("Post.postID, Post.published, Post.title, Post.content").
            From("Post").
            Join("PostTag using(postID)").
            Where(sq.Eq{"tagID ": tagID})

        qSQL, args, err := query.ToSql()
        if err != nil {
            return nil, errors.Wrap(err, "Error generating dbAllPostsInTag sql")
        }
        err = db.Select(&posts, qSQL, args...)
        if err != nil {
            return nil, errors.Wrap(err, "Error listing dbAllPostsInTag")
        }
        return posts, nil
    }

Re: To ORM or Not to ORM

#214
Hacking is not just about having access to things of other people, it essentially means seeking a solution to a problem, The deep web has been solving these problems for people over decades and putting up smiles on their faces. We offer range and quick hacking services, with the help of our expert tech agents who we employed from various regions because of the good quality of works they give.

are you interested in hiring us for your next hacking service we do a list of wide and range hacking services;

contact our agent/officer on

cipherhacker1@gmail.com for any of the services listed below or more

Criminal case clearing{we clear case from police station and also reduce court sentence by hacking court database}{we also clear past criminal records}

mac computers hacking- we give full strength recovery of data"s on the system

* We do school grade upgrading- we do it a way that your supervisor would not notice and we would change your grade permanently and help you monitor your next grades.

Western union

Car hacking and unlocking, we also do car tracing to get location of your stolen cars

Wifi password cracking

We also do device protection._ we help you protect all your phones and laptops to stop any hacker from gaining access.

DDOS attacking

Ethical hacking learning

Instagram hacking

Whatsapp {we can get past whatsapp chats and media of the person and also direct future messages to you}

snapchat

Facebook

Hotmail

Email and Gmail {we also do mail protection,to protect your mail from being hacked in future}

Mobile phones- we network tracing and stalking to help you stalk your spouse

icloud and iPhone- we original data uploaded to the account database

Blogger hacking

Youtube channel hacking

Wordpress hacking

Skype

Software

Penetration test

CCTV hacking

Phone hacking and tracing

*Gaming and betting site hacking

>>>> You can contact us for other services not listed here.

contact on cipherhacker1@gmail.com

your satisfaction is our goal

Re: To ORM or Not to ORM

#215
post #137

Earlier quoted context omitted.

Have you ever tried it? Your coworkers are right. It also helps you avoid common mistakes like SQL injection. When the ORM doesn't work for a specific case, they usually have ways where you can override the ORM and use your own SQL calls. Virtually every major, popular ORM does this across different languages (can personally confirm with Ruby, Java, & Python ORMs - confident that JS ones support it too).

That is orthogonal. There are ORMs which make SQL injection easy and there are those which make it hard, just as for SQL connector libraries. This is a matter of interface design.

Which ORMs make SQL Injection easy to happen? From my experience input sanitation is one of the main features of every major ORM. I am not aware of any popular ORM that makes it easy for SQL injection to occur.

Re: To ORM or Not to ORM

#216
post #94

I currently work on a project that is based on Django ORM. Before this, I almost exclusively hand-wrote all SQL. I think you can quickly outgrow the limits of ORM... at least Django's. Whether it's needlessly fighting with ORM to get joins correct, ORM deciding it's going to loop through n records instead of joining on DB server, simply doing complex aggregates that ORM won't support, or doing DB-specific stuff. Post…

I got started with ORMs before I knew any SQL, and I wish I had learned to just write SQL earlier in my coding career. I've spent way too many hours wrestling with ORMs that couldn't quite do some query I wanted to write. I think it would have been better to write some SQL and have people push back w/ a better way to write a query than to try & purge everything that looked like SQL from ORM queries. Having learned SQL has made life so much easier for me!

Re: To ORM or Not to ORM

#217
post #61

Earlier quoted context omitted.

Have you ever tried it? Your coworkers are right. It also helps you avoid common mistakes like SQL injection. When the ORM doesn't work for a specific case, they usually have ways where you can override the ORM and use your own SQL calls. Virtually every major, popular ORM does this across different languages (can personally confirm with Ruby, Java, & Python ORMs - confident that JS ones support it too).

SQL injection is prevented by not using user input as a part of the SQL query. It's orthogonal concern to whether to use ORM or not.

I'm not sure I understand since there are common cases where you have no choice but to deal with user input. Sure you can manually escape user input in your manual sql calls, but if you're doing that manually there's no hard guarantee that you'll always escape that input vs using an ORM.

Re: To ORM or Not to ORM

#218
post #4

Sample size one 1 but ORM drives me crazy. Why can't we just use SQL? How does it save time when I have to learn the ORM language, which probably has a lot less support and users? The OP here says it "reduces boilerplate" -- rarely have I created an application and thought its biggest problem was too much boilerplate. But everyone at work loves them so I must be wrong somehow.

All the time allegedly saved is also more than compensated for when the ORM makes bad queries that are roughly impossible to fix.

Yes, this happens with complicated schemas with complicated queries. ORMs account for this. Almost every major ORM allows you to override those "bad" queries when needed with your own manual SQL calls. It's an old problem with an old solution that works in production.

Re: To ORM or Not to ORM

#219
post #208
post #206

Earlier quoted context omitted.

So don't map DB records to objects, then. DB records are records , and their proper typing in your business logic is as records —chunks of plain old data, strongly-typed, that your (OO or otherwise) code can declare DB-side interfaces against. The only responsibilities of the module/class that owns the record type, should be getting things converted into and out of that record type. Plain-old-data DB record types (an…

Would that be a "RRM" (Record-Relational mapper)? If so we're already on board (in a different language). P.S. I bet you would never guess which typed language with great support for records makes it easy (for the most part) to build most type-safe SQL queries on the fly, even with projections, without explicitly defining types for every possible projection variation.

Would you happen to be talking about TypeScript?

Re: To ORM or Not to ORM

#220
post #111

Earlier quoted context omitted.

Actually "writing queries in some language other than SQL" which has static typing and catching issues in compile time is quite big for me. Add automatic database migrations that are also keeping types in line with code and whole bunch of "mess of mapping code" goes away. Though I use .NET EntityFramework which by now is really mature and heavily invested into by MS. Not sure how it is with other environments but I t…

Lack of adequate support for versioning your schema and in general bad support for anything versioning with RDBMS is one of the main dislikes I have for SQL. I find SQL to be a beautifully expressive language when you get the hang of it, but no RDBMS that I know of has been able to adequately tackle the versioning problem at both the schema and the script level. Everyone's schema evolves over time, why is it so diffi…

This is a big thing for me. Most ORMs I’ve used have decent migration tools which is a huge benefit for managing your schema. We enforce changing Schemas via migrations as opposed to any sort of auto-migrations some packages offer. Makes life a ton easier being able to put these changes into a build pipeline.
Post reply on HN