Drizzle Proxy is used when you need to implement your own driver communication with the database.
It can be used in several cases, such as adding custom logic at the query stage with existing drivers.
The most common use is with an HTTP driver, which sends queries to your server with the database, executes the query
on your database, and responds with raw data that Drizzle ORM can then map to results
How it works under the hood?
Drizzle ORM also supports simply using asynchronous callback function for executing SQL.
sql is a query string with placeholders.
params is an array of parameters.
One of the following values will set for method depending on the SQL statement - run, all, values or get.
Drizzle always waits for {rows: string[][]} or {rows: string[]} for the return value.
When the method is get, you should return a value as {rows: string[]}.
Otherwise, you should return {rows: string[][]}.
PostgreSQL
MySQL
SQLite
Batch support
Sqlite Proxy supports batch requests, the same as it’s done for all other drivers. Check full docs
You will need to specify a specific callback for batch queries and handle requests to proxy server:
And then you can use db.batch([]) method, that will proxy all queries
Response from the batch should be an array of raw values (an array within an array), in the same order as they were sent to the proxy server
Unless you plan on writing every SQL query by hand, a table declaration is helpful: