Drizzle
Let’s connect Drizzle to anyquery so that you can bridge the JavaScript world with anyquery. To do so, we’ll use the MySQL driver for Drizzle.
Prerequisites
Before you begin, ensure that you have the following:
- A working installation of anyquery
- A JavaScript environment (npm, Node.js, etc.)
Step 1: Set up the project
First, create a new project and install drizzle
:
Once done, let’s create the configuration file for Drizzle:
and add the following content:
Step 2: Pull the schema
Once done, let’s launch the anyquery server on a second terminal:
Now, let’s pull the schema:
Congratulations! We have generated a schema of all the tables in the database.
Step 3: Query the database
Let’s do a simple query. We’ll fetch all the commits from the drizzle-team/drizzle-orm repository:
Make sure to install the git
plugin first:
Once done, launch the server in the first terminal:
Now, let’s create a new file called print.ts
and add the following content:
Now, let’s run the script.
Personally, to avoid transpiling the TypeScript code, I use bun
:
You should see the commits from the repository.
Conclusion
You’ve successfully connected Drizzle to anyquery. You can now query your database using Drizzle and anyquery. Don’t hesitate to share your use cases with us in the GitHub discussions. I’m trying to prioritize development based on the community’s needs.
You can see the resulting code at https://github.com/julien040/anyquery/tree/main/_examples/drizzle