@planetscale/database

v1.20.1 Apache-2.0

A Fetch API-compatible PlanetScale database driver

Weekly Downloads
195.4K
Stars
1.2K
Forks
41
Open Issues
20
Gzip Size
2.1 kB
Unpacked Size
52.0 kB
Dependencies
0
Last Updated
7mo ago

@planetscale/database Download Trends

Download trends for @planetscale/database0213.7K427.4K641.1K854.9KFeb 2025MayAugNovFebApr 2026
@planetscale/database

About @planetscale/database

The @planetscale/database package provides a modern, Fetch API-compatible driver for interacting with PlanetScale's MySQL-compatible database. It's designed to address the challenges of database connectivity in serverless and edge environments, where traditional persistent connections can be problematic. This driver simplifies database access by offering a familiar interface, enabling developers to query and manipulate data seamlessly.

The package's core philosophy centers around developer experience and runtime efficiency, particularly for modern JavaScript runtimes like Vercel Edge Functions or Cloudflare Workers. It aims to make PlanetScale databases easily accessible from these distributed environments without the overhead of managing connection pools manually. The primary audience is developers building applications on serverless platforms who need a reliable and performant database solution.

Key API patterns leverage standard JavaScript `fetch` capabilities, allowing for intuitive database operations. Developers can use methods like `db.execute()` for DML statements and `db.execute` with `type: 'rows'` for SELECT queries, returning data in a convenient format. It supports parameterized queries to prevent SQL injection vulnerabilities, a critical security feature.

Integration points are broad, fitting naturally into JAMstack architectures and modern full-stack frameworks. It's particularly well-suited for platforms like Vercel, where its edge-friendly nature shines. The driver can be used with various ORMs or directly for greater control over SQL queries. Its design encourages a stateless approach to database interactions.

With a minimal unpacked size of 52.0 kB and a gzipped bundle size of just 2.1 kB, this package is highly optimized for performance-sensitive environments. This small footprint ensures fast load times and reduced resource consumption, crucial for edge and serverless deployments. The package is actively maintained, as indicated by its recent update, suggesting a level of maturity and ongoing support.

One consideration is that this driver is optimized for PlanetScale's specific infrastructure and connection method. While it uses MySQL compatibility, it might not be a drop-in replacement for all existing MySQL drivers in every scenario, especially those requiring very specific low-level MySQL protocol features or extensive connection pooling configurations not exposed through the driver's abstractions.

When to use

  • When building serverless applications on platforms like Vercel or Cloudflare Workers that benefit from a lightweight, edge-optimized database driver.
  • When integrating with PlanetScale's MySQL-compatible database from JavaScript or TypeScript environments.
  • For applications requiring direct database access using a Fetch API-compatible interface, simplifying query execution with `db.execute()`.
  • When prioritizing a minimal bundle size (2.1 kB gzipped) for faster cold starts and improved runtime performance.
  • For developing applications that leverage PlanetScale's features such as branch-based workflows alongside a modern serverless backend.
  • When protecting against SQL injection by utilizing the driver's built-in support for parameterized queries.

When NOT to use

  • If your application requires deep integration with specific MySQL protocol features not exposed by the `fetch`-like API.
  • When working with legacy Node.js applications that rely heavily on older connection pooling mechanisms unsupported by this driver's design.
  • If you need to connect to a database that does not offer a MySQL-compatible endpoint or requires a different query language.
  • For scenarios where a traditional, long-lived database connection pool managed at the application layer is a strict requirement.
  • If your needs are limited to simple key-value storage, consider using simpler in-memory solutions or dedicated key-value stores.

@planetscale/database Alternatives

@planetscale/database Categories