Neon Integration Guide

Neon Integration Guide

Complete guide for connecting serverless PostgreSQL with Neon to Tellus

Guide Contents

  1. Overview
  2. Getting Started
  3. Obtaining Credentials
  4. Configuration
  5. Tellus Integration
  6. Basic Operations (CRUD)
  7. Using Neon
  8. Example Setup
  9. Neon Features
  10. Security

Overview

Neon is a serverless PostgreSQL database with automatic scaling and free branching. It provides PostgreSQL compatibility with modern, consumption-based pricing.

Integration Type: PostgreSQL-compatible (serverless)
Authentication: Connection string with credentials OR username/password
Protocol: PostgreSQL wire protocol (over HTTPS)
Database Type: PostgreSQL (100% compatible)

Getting Started

Prerequisites:

Steps to Create a Neon Project:

  1. Go to https://neon.tech
  2. Click "Sign Up" and create an account (or sign in)
  3. Click "Create a project"
  4. Give your project a name
  5. Select your region (choose closest to your location)
  6. Select PostgreSQL version (default is fine)
  7. Click "Create project" - your database will initialize in ~30 seconds

Obtaining Credentials

Connection String (Recommended)

Location: Neon Console > Your Project > "Connect" button
Format: postgresql://user:password@host/dbname?sslmode=require

Project ID

Found in project URL or settings. Format: unique project identifier

Branch ID

Usually "main" for the default branch

Steps to Get Connection String:
1. Go to Neon Console
2. Click on your project
3. Click "Connect" (top right)
4. Select "Connection string" tab
5. Copy the complete connection string

Configuration in Dashboard

  1. Click "Add Project"
  2. Select "Neon" as Database Provider
  3. Fill in Credentials:
    • Connection String: Paste your Neon connection string
    • API Key: (Optional) Your Neon API key
    • Project ID: (Optional) Your Neon project ID
  4. Click "Test Connection" to verify
  5. Click "Save Project"

Tellus Integration

Integrating Neon with Tellus allows you to leverage serverless PostgreSQL effortlessly. In your tellus.config.js or within your initialized client instance, define the connection:

import { Tellus } from '@tellus/client';

const tellus = new Tellus({
  databases: {
    inventory: {
      provider: 'neon',
      connectionString: process.env.NEON_DATABASE_URL
    }
  }
});
Connection Pooling: Neon is serverless, so connection handling is slightly different. Tellus automatically optimizes connections to Neon's pooling architecture.

Basic Operations (CRUD)

With Tellus, querying your serverless PostgreSQL database uses the standard Tellus unified API. Note how it abstracts away direct SQL execution.

1. Create (Insert)

// Insert a new product into the 'products' table
const newProduct = await tellus.db('inventory').collection('products').insert({
  name: 'Wireless Keyboard',
  price: 49.99,
  stock: 150
});

2. Read (Select)

// Fetch in-stock products, sorted by price
const availableProducts = await tellus.db('inventory').collection('products')
  .find({ stock: { $gt: 0 } })
  .orderBy('price', 'asc')
  .limit(20)
  .execute();

3. Update

// Update stock after a purchase
await tellus.db('inventory').collection('products')
  .where('id', '==', 101)
  .update({ stock: 149 });

4. Delete

// Remove discontinued products
await tellus.db('inventory').collection('products')
  .where('stock', '==', 0)
  .delete();

Using Neon in the Dashboard

Example Setup: E-commerce Database

CREATE TABLE categories (
  id SERIAL PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  description TEXT
);

CREATE TABLE products (
  id SERIAL PRIMARY KEY,
  name VARCHAR(255) NOT NULL,
  description TEXT,
  category_id INTEGER REFERENCES categories(id),
  price DECIMAL(10, 2) NOT NULL,
  stock INTEGER DEFAULT 0
);

CREATE TABLE orders (
  id SERIAL PRIMARY KEY,
  customer_email VARCHAR(255) NOT NULL,
  total_amount DECIMAL(10, 2) NOT NULL,
  status VARCHAR(20) DEFAULT 'pending'
);

Then add indexes for performance:

CREATE INDEX idx_products_category ON products(category_id);
CREATE INDEX idx_orders_customer ON orders(customer_email);

Neon-Specific Features

Security Best Practices

Useful Links

← SupabaseFirebase →