Vercel Postgres To Neon

1.0.0Last update Feb 21, 2025
by@adriancooney

This is a codemod created with codemod init.

Using this codemod

You can run this codemod with the following command:

npx codemod vercel-postgres-to-neon

Before

import { sql } from '@vercel/postgres';
import { NextApiRequest, NextApiResponse } from 'next';
export default async function handler(
request: NextApiRequest,
response: NextApiResponse,
) {
try {
await sql`CREATE TABLE Pets ( Name varchar(255), Owner varchar(255) );`;
const names = ['Fiona', 'Lucy'];
await sql`INSERT INTO Pets (Name, Owner) VALUES (${names[0]}, ${names[1]});`;
} catch (error) {
return response.status(500).json({ error });
}
const pets = await sql`SELECT * FROM Pets;`;
return response.status(200).json({ pets });
}

After

import { neon } from '@neondatabase/serverless';
import { NextApiRequest, NextApiResponse } from 'next';
const sql = neon(process.env.POSTGRES_URL);
export default async function handler(
request: NextApiRequest,
response: NextApiResponse,
) {
try {
await sql`CREATE TABLE Pets ( Name varchar(255), Owner varchar(255) );`;
const names = ['Fiona', 'Lucy'];
await sql`INSERT INTO Pets (Name, Owner) VALUES (${names[0]}, ${names[1]});`;
} catch (error) {
return response.status(500).json({ error });
}
const pets = await sql`SELECT * FROM Pets;`;
return response.status(200).json({ pets });
}

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now