Back to articles
Neon Has a Free API That Gives You Serverless Postgres That Scales to Zero

Neon Has a Free API That Gives You Serverless Postgres That Scales to Zero

via Dev.to JavaScriptAlex Spinov

Neon is serverless Postgres with branching, autoscaling, and a JavaScript SDK. Your database scales to zero when idle — you only pay for what you use. Neon Serverless Driver import { neon } from " @neondatabase/serverless " ; const sql = neon ( process . env . DATABASE_URL ); // Simple query const products = await sql `SELECT * FROM products WHERE price < ${ 50 } ORDER BY created_at DESC LIMIT 20` ; // Insert await sql `INSERT INTO products (title, price, url) VALUES ( ${ title } , ${ price } , ${ url } )` ; // Transaction const result = await sql . transaction ([ sql `INSERT INTO orders (user_id, total) VALUES ( ${ userId } , ${ total } ) RETURNING id` , sql `UPDATE inventory SET stock = stock - ${ qty } WHERE product_id = ${ productId } ` , ]); Works Everywhere: Edge, Serverless, Browser // Cloudflare Workers export default { async fetch ( request , env ) { const sql = neon ( env . DATABASE_URL ); const data = await sql `SELECT * FROM products` ; return Response . json ( data ); }, }

Continue reading on Dev.to JavaScript

Opens in a new tab

Read Full Article
3 views

Related Articles