Drizzle Queries + CRUD
- How to define your schema - Schema Fundamentals
- How to connect to the database - Connection Fundamentals
Drizzle gives you a few ways for querying you database and it’s up to you to decide which one you’ll need in your next project. It can be either SQL-like syntax or Relational Syntax. Let’s check them:
Why SQL-like?
If you know SQL, you know Drizzle.
Other ORMs and data frameworks tend to deviate from or abstract away SQL, leading to a double learning curve: you need to learn both SQL and the framework’s API.
Drizzle is the opposite. We embrace SQL and built Drizzle to be SQL-like at its core, so you have little to no learning curve and full access to the power of SQL.
With SQL-like syntax, you can replicate much of what you can do with pure SQL and know exactly what Drizzle will do and what query will be generated. You can perform a wide range of queries, including select, insert, update, delete, as well as using aliases, WITH clauses, subqueries, prepared statements, and more. Let’s look at more examples
Why not SQL-like?
We’re always striving for a perfectly balanced solution. While SQL-like queries cover 100% of your needs, there are certain common scenarios where data can be queried more efficiently.
We’ve built the Queries API so you can fetch relational, nested data from the database in the most convenient and performant way, without worrying about joins or data mapping.
Drizzle always outputs exactly one SQL query. Feel free to use it with serverless databases, and never worry about performance or roundtrip costs!
Advanced
With Drizzle, queries can be composed and partitioned in any way you want. You can compose filters independently from the main query, separate subqueries or conditional statements, and much more. Let’s check a few advanced examples:
Compose a WHERE statement and then use it in a query
Separate subqueries into different variables, and then use them in the main query
What’s next?
Zero to Hero