next-sql is a Node.js SQL connector and query builder that provides an easy way to query SQL databases and create relationship-linked objects. The current stable version is 1.0.16, released as pre-alpha. It offers a simple API for standard queries, fallback queries, batch insert/update, pagination, and transaction support. Key differentiators include built-in relationship mapping (toOne/toMany/fromOne) without schema configuration, support for multiple hosts, and compatibility with mysql, mysql2, and PlanetScale database drivers. The release cadence is irregular as it is actively developed. Compared to alternatives like Knex or Prisma, next-sql focuses on simplicity and relational linking but lacks schema migrations and advanced type safety.
npm install next-sqlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic setup with environment variables for database config and a simple query using parameterized SQL.
Pin to specific minor version and test thoroughly before upgrading.
Use dynamic import or switch to ESM. Example: const nextSQL = (await import('next-sql')).default;Install at least one peer dependency: npm install mysql2
Use @planetscale/database and configure HTTP connection.
Manually create tables via SQL schema before using next-sql.
npm install mysql2
import nextSQL from 'next-sql' (no curly braces)
Start MySQL service and verify DB_HOST and DB_PORT environment variables.
Switch to @planetscale/database and configure HTTP connection.