Dare is a JavaScript library (shipping TypeScript types) designed to streamline the creation of REST APIs from database schemas by generating SQL queries from structured JavaScript objects. It acts as an abstraction layer, allowing developers to define database interactions using a declarative object syntax rather than writing raw SQL directly. The current stable version is `0.98.4`, indicating it is still in pre-1.0 development, though it sees consistent maintenance with several bug fix and feature releases throughout 2025. Key differentiators include its 'brave API' approach to SQL generation, requiring users to define a custom `dare.execute` handler for database interaction, and its explicit support for MySQL (5.6, 5.7, 8.0) and PostgreSQL (16+), abstracting away direct driver calls.
npm install dareVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize Dare, configure its `dare.execute` handler with a `mysql2/promise` connection pool, and perform basic `get` (SELECT) and `post` (INSERT) operations, including field aliasing.
Upgrade your Node.js environment to version 20 or newer. Use `nvm` or your preferred Node.js version manager.
Always assign an async function to `dare.execute` that accepts a `request` object and performs the actual database query using your chosen database driver (e.g., `mysql2`, `pg`). Ensure it returns appropriate results (array of rows for SELECT, object with `insertId`/`affectedRows` for DML).
Inspect the `request` object within `dare.execute`. For MySQL/MariaDB connections, use `dbconn.query(request.sql, request.values)`. For PostgreSQL, use `dbconn.query(request.text, request.values)` or `dbconn.query(request.sql, request.values)` depending on your `pg` client setup if it maps `request.sql` to `text`.
Pin `dare` to exact versions or use tilde (~) for minor version updates (`~0.98.0`) rather than caret (^) (`^0.98.0`) to avoid unexpected changes. Review changelogs carefully before upgrading.
Assign an asynchronous function to `dare.execute` that takes a `request` object and performs database operations. Example: `dare.execute = async (request) => { /* ... */ };`Enable logging for `request.sql` and `request.values` within `dare.execute` to inspect the generated query. Verify your `engine` option in the `Dare` constructor matches your database. Check the Dare documentation for complex query patterns or filters.
Ensure your Node.js project is configured for ESM by setting `"type": "module"` in `package.json`, or explicitly use CommonJS `require()` syntax if supported, though `dare` is primarily designed for ESM. For Node.js versions requiring `--experimental-modules`, ensure that flag is used.
Pass a valid `engine` string to the `Dare` constructor, e.g., `new Dare({ engine: 'mysql:8.0' })` or `new Dare({ engine: 'postgres:16' })`.