Reputation: 835
I'm using Drizzle ORM with a Postgres database. It's not obvious to me when to use Select vs. Query to access data. For example:
db.select().from(schema.users);
// OR
db.query.users.findMany()
The one advantage I see for using select()
is that the the type is unknown when using query
:
// select() expected type:
Promise<{
id: string;
email: string;
}[]>
// query expected type:
const user: {
[x: string]: unknown;
}[]
The documentation says query
can be used for accessing relations:
Relational queries are meant to provide you with a great developer experience for querying nested relational data from an SQL database, avoiding multiple joins and complex data mappings.
Is that the only time it should be used?
Upvotes: 1
Views: 1336
Reputation: 1
So far, I haven't had a need to use query(). I can get anything done with select().
Upvotes: 0
Reputation: 147
I highly recommend Orange ORM. https://github.com/alfateam/orange-orm .
It is not new, but has existed on npm since 2014 (previously known as rdb).
It is mature, reliable and has a straightforward syntax. It supports mysql, mssql, postgres, oracle, sap ase and sqlite.
It does not separate query and select. You can also do nested updates/inserts.
Upvotes: -6