DEV Community

Cover image for Example Online Postgre with Neon.com – Rune + RedBean CLI Application
Anwar Achilles
Anwar Achilles

Posted on • Edited on

Example Online Postgre with Neon.com – Rune + RedBean CLI Application

This project is an example CLI application demonstrating how to use Neon PostgreSQL (a fully managed cloud PostgreSQL platform) in combination with Rune and RedBeanPHP. The application allows you to perform CRUD operations on a user table directly from the CLI, making it perfect for developers who want a lightweight, fast, and flexible way to interact with a database without building a full web interface.

The project leverages:

  • Neon PostgreSQL – cloud-hosted PostgreSQL database
  • Rune – for CLI management and scripting
  • RedBeanPHP – lightweight ORM for PHP

Features

  • Create, read, update, and delete users using CLI commands.
  • Easily create database tables via scripts.
  • Works with Neon PostgreSQL in the cloud.
  • Clean, simple, and easy-to-extend structure.

Installation & Setup

Follow these steps to get started:

  • 1. Clone the repository
git clone https://github.com/AnwarAchilles/example-online-postgre.git
cd example-online-postgre
Enter fullscreen mode Exit fullscreen mode
  • 2. Load vendor packages
composer install
Enter fullscreen mode Exit fullscreen mode
  • 3. Configure database connection Edit the main setup file where RedBean connects to Neon PostgreSQL. Replace placeholders with your Neon credentials:
$NEON_HOST = '';
$NEON_DB   = '';
$NEON_USER = '';
$NEON_PASS = '';

R::setup(
    "pgsql:host=$NEON_HOST;dbname=$NEON_DB;sslmode=require",
    $NEON_USER,
    $NEON_PASS
);
Enter fullscreen mode Exit fullscreen mode

Using placeholders keeps your credentials safe for sharing or pushing to a repository.


Running the Application

To start the CLI application:

php cast
Enter fullscreen mode Exit fullscreen mode

This will show available commands and let you run scripts, manage users, or view results.

 #  R E G I S T E R E D.
 ♦ php cast script
    #≈ runs a script, e.g., creating database t
    ables.
 ♦ php cast result
    #≈ lists all user emails in the database.
 ♦ php cast create
    #≈ create a new user, --email=(string)
 ♦ php cast update
    #≈ update an existing user, --id=(int) --em
    ail=(string)
 ♦ php cast delete
    #≈ delete an existing user, --id=(int)
Enter fullscreen mode Exit fullscreen mode

Step by Step

  • 1. Create the user table
php cast script
Enter fullscreen mode Exit fullscreen mode

This runs the script to create a user table if it does not exist.

  • 2. Add a new user
php cast create --email=demo@mail.com
Enter fullscreen mode Exit fullscreen mode

Adds a new user to the database.

  • 3. View all users
php cast result
Enter fullscreen mode Exit fullscreen mode

Lists all emails currently stored.

  • 4. Update a user’s email
php cast update --id=1 --email=updated@mail.com
Enter fullscreen mode Exit fullscreen mode

Updates the email for the user with id=1.

  • 5. Delete a user
php cast delete --id=1
Enter fullscreen mode Exit fullscreen mode

Removes the user from the database.


References


Summary

This project is an example showing how to integrate and use Neon PostgreSQL in PHP, with database management organized neatly using Rune. It demonstrates how to perform CRUD operations via CLI commands with RedBean, making it easy to understand the workflow and structure when working with a cloud PostgreSQL database.

Top comments (0)