Set up serverless databases (PlanetScale, Neon, Turso)
✓Works with OpenClaudeYou are a serverless infrastructure specialist. The user wants to set up and configure a serverless database using PlanetScale, Neon, or Turso.
What to check first
- Verify you have a cloud account (PlanetScale requires MySQL-compatible access, Neon requires PostgreSQL knowledge, Turso uses SQLite)
- Run
node --versionandnpm --versionto confirm Node.js is installed for connection pooling libraries - Check your project has a
.envor.env.localfile for storing database credentials
Steps
- Choose your serverless database provider based on your stack: PlanetScale for MySQL workloads, Neon for PostgreSQL with auto-scaling, or Turso for edge-distributed SQLite
- Create an account and new database instance on your chosen platform's dashboard
- Generate an API key or access token from your provider's settings page
- Retrieve the connection string (includes host, username, password, database name) from the platform
- Store the connection string in your
.env.localfile as a singleDATABASE_URLvariable - Install the appropriate client library:
npm install @planetscale/databasefor PlanetScale,npm install pgfor Neon, ornpm install @libsql/clientfor Turso - Create a database connection file that imports the client library and initializes the connection using your
DATABASE_URL - Test the connection by running a simple query to verify credentials and network access are working
Code
// For PlanetScale with MySQL
import { connect } from '@planetscale/database';
const db = connect({
url: process.env.DATABASE_URL,
});
export async function queryDatabase(sql, values = []) {
try {
const results = await db.execute(sql, values);
return results.rows;
} catch (error) {
console.error('Database query failed:', error);
throw error;
}
}
// Usage example
const users = await queryDatabase('SELECT * FROM users WHERE id = ?', [1]);
console.log(users);
// For Neon with PostgreSQL
import { Pool } from 'pg';
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
ssl: { rejectUnauthorized: false },
});
export async function queryDatabase(sql, values = []) {
const client = await pool.connect();
try {
const result = await client.query(sql, values);
return result.rows;
} finally {
client.release();
}
}
// Usage example
const users = await queryDatabase('SELECT * FROM users WHERE id = $1', [1]);
console.log(users);
// For Turso with SQLite
import { createClient } from '@libsql/client';
const db = createClient({
url: process.env.TURSO_CONNECTION_URL,
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Serverless Skills
Other Claude Code skills in the same category — free to download.
Vercel Deploy
Deploy and configure applications on Vercel
Netlify Deploy
Deploy and configure applications on Netlify
SST Setup
Set up SST (Serverless Stack) for full-stack serverless apps
Serverless Framework
Configure Serverless Framework for multi-cloud deployment
Edge Functions
Build and deploy edge functions (Vercel, Cloudflare Workers)
Serverless Cron
Set up serverless cron jobs and scheduled functions
Serverless Queue
Implement serverless queues and event-driven processing
Want a Serverless skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.