Skip to content

CleverCloud/bun-addons-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clever Cloud add-ons - Bun examples

This repository contains examples of how to use Clever Cloud add-ons thanks to native Bun support. To use them you need Bun, Clever Tools CLI and git installed.

Setup

Clone this repository:

git clone https://github.com/CleverCloud/bun-addons-examples
cd bun-addons-examples

# create a .env file to store your add-ons credentials
touch .env

PostgreSQL / MySQL

Create a PostgreSQL or MySQL add-on:

clever addon create postgresql-addon <addon-name>
clever addon create mysql-addon <addon-name>

# Add credentials to .env
clever addon env <addon-name> >> .env

Basic usage

Test connection, if a MySQL add-on and a PostgreSQL add-on are available, you'll be prompted to choose one:

bun sql-connect.js

SQL TODO CLI

# Show all todos
bun sql-todo.js

# Add a todo
bun sql-todo.js add "Learn Bun with PostgreSQL"

# Toggle completion
bun sql-todo.js toggle 1

# Show statistics
bun sql-todo.js stats

# Delete a todo
bun sql-todo.js delete 1

Cellar (S3-compatible Object Storage)

Create a Cellar add-on:

clever addon create cellar <addon-name>

# Add credentials to .env
clever addon env <addon-name> >> .env

Go to the Clever Cloud Console, open your Cellar add-on and create a bucket.

Basic usage

Connect and list bucket contents:

bun s3-connect.js <bucket-name>

S3 file management, presigned URL

# Run full demo
bun s3.js <bucket-name>

# List files
bun s3.js <bucket-name> list

# Upload a file
echo 'Hello, Clever Cloud!' > myfile.txt
bun s3.js <bucket-name> upload myfile.txt

# Print file contents
bun s3.js <bucket-name> print myfile.txt

# Generate presigned URL (5 minutes default)
bun s3.js <bucket-name> presign myfile.txt

# Generate presigned URL (custom duration)
bun s3.js <bucket-name> presign myfile.txt 3600

# Delete a file
bun s3.js mybucket delete myfile.txt

Materia KV / Redis

Create a Materia KV or Redis add-on (both work with this script):

clever addon create kv <addon-name>
# or
clever addon create redis <addon-name>

# Add credentials to .env
clever addon env <addon-name> >> .env

Key-Value client

# Set a key
bun kv-client.js SET mykey "Hello World"

# Get a key
bun kv-client.js GET mykey

# List all keys
bun kv-client.js KEYS "*"

# JSON operations (Materia KV)
bun kv-client.js JSON.SET myJsonKey $ '{"name":"John","age":30}'
bun kv-client.js JSON.GET myJsonKey
bun kv-client.js JSON.GET myJsonKey $.name

# Get info
bun kv-client.js PING

Documentation