Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Remember kids, writing queries in an ORM is a betrayal to the ORM gods.

You are supposed to manually count the question marks in your raw SQL like the JDBC gods intended.

    String sql = "INSERT INTO users (name, email, age, status, country) VALUES (?, ?, ?, ?, ?)";
    PreparedStatement pstmt = conn.prepareStatement(sql);
    pstmt.setString(1, "Alice");
    pstmt.setString(2, "alice@example.com");
    pstmt.setInt(3, 30);
    pstmt.setString(4, "ACTIVE");
    pstmt.setString(5, "US");
There is absolutely zero chance an ORM can ever get close to the performance of this query, so write it by hand!

After all, the primary promise of ORMs has been that you do not have to write queries, it's right in the name! Object Relational Mapper!



> You are supposed to manually count the question marks in your raw SQL like the JDBC gods intended.

    String sql = "INSERT INTO users (name, email, age, status, country) " +
                 "VALUES            (?,    ?,     ?,   ?,      ?      )";
But I get your point.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: