This guide explains how to set up and use Neon PostgreSQL with this project.
We’ve migrated from MongoDB to Neon PostgreSQL for better serverless compatibility and performance. Neon is a serverless PostgreSQL service that offers:
Make sure these environment variables are set:
NEON_CONNECTION_STRING="postgresql://user:password@endpoint/dbname?sslmode=require"
NEON_DATABASE_URL="postgresql://user:password@endpoint/dbname?sslmode=require"
These should be set in:
.env.development for local developmentwrangler.jsonc for Cloudflare deploymentTo set up the database schema:
node scripts/setup-neon-db.js
This will create all necessary tables and functions in your Neon database.
The main tables include:
review_views: Tracks view counts for reviews (migrated from MongoDB)marketing_popup_impressions: Tracks popup impressionsmarketing_popup_conversions: Tracks popup conversionsThe database can be accessed in two ways:
locals.neonDb in any Astro endpoint:export const GET: APIRoute = async ({ locals }) => {
const result = await locals.neonDb.query('SELECT * FROM review_views');
return new Response(JSON.stringify(result));
};
import { executeQuery } from '../utils/db/neon-serverless';
const result = await executeQuery('SELECT * FROM review_views');
If you encounter connection issues:
sslmode=require)