@tursodatabase/serverless
v1.0.0 MIT<p align="center"> <h1 align="center">Turso Serverless Driver for JavaScript</h1> </p>
@tursodatabase/serverless Download Trends
About @tursodatabase/serverless
The `@tursodatabase/serverless` package provides a JavaScript driver specifically designed for interacting with Turso, a distributed, local-first, and serverless SQL database. It bridges the gap between serverless compute environments and the Turso database, enabling developers to easily query and manage data without the complexities of traditional database connections, connection pooling, or long-running server processes.
This driver is built with a serverless-first philosophy, aiming to be lightweight and efficient for ephemeral compute contexts like AWS Lambda, Vercel Functions, or Cloudflare Workers. Its primary audience includes developers building modern web applications, APIs, and backend services who want to leverage the benefits of Turso's offline-first capabilities and distributed nature within a serverless architecture.
The core API revolves around executing SQL statements and retrieving results. Developers will primarily use methods like `execute` and `batch` on a database client instance. The `execute` method allows for single SQL queries, accepting a SQL string and optional bind parameters, while `batch` enables the execution of multiple statements atomically. The driver handles serialization and deserialization of data types between JavaScript and Turso's wire protocol.
Integration with popular JavaScript frameworks and tools is straightforward. It can be imported and used directly within Node.js environments, making it suitable for use with Express.js, NestJS, or even simple scripts. In frontend contexts, the driver can be employed within server-side rendering (SSR) or server components of frameworks like Next.js or Nuxt.js, where direct database access is feasible and secure.
With an unpacked size of 77.7 kB and a gzipped bundle size of only 3.4 kB, this package is exceptionally small, making it ideal for serverless function cold starts and environments where minimizing deployment package size is critical. This contributes to faster function invocations and reduced resource consumption.
A notable consideration is that this package is primarily intended for serverless or Node.js environments. Direct use within a standard browser client is not recommended due to security implications of exposing database credentials or relying on direct network access to Turso services from the client-side.
When to use
- When building serverless APIs on platforms like Vercel or AWS Lambda that need to interact with a Turso database.
- When developing applications that require offline capabilities and local data synchronization facilitated by Turso.
- When integrating Turso's SQL capabilities into Next.js server components or API routes for dynamic data fetching.
- When minimizing the bundle size of your serverless functions is a priority, given its 3.4 kB gzipped size and 77.7 kB unpacked size.
- When you need to perform batch operations on the Turso database from your JavaScript backend code using the `batch` method.
- When developing applications that can benefit from Turso's distributed nature and require a simple, efficient driver for JavaScript.
When NOT to use
- If your application exclusively runs in a browser and does not have a serverless backend component to host the driver logic.
- If your data needs are met by simpler key-value stores, consider using lighter storage solutions or in-memory caches available in your runtime.
- When direct, long-lived database connections are required and connection pooling management is a primary concern, as this driver is optimized for ephemeral serverless environments.
- If you are not using Turso as your database and are looking for a general-purpose SQL driver for other database systems.
- When building highly sensitive backend services that require complex authentication mechanisms not natively supported by the Turso serverless driver's standard client initialization.