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.
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 .envCreate 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> >> .envTest connection, if a MySQL add-on and a PostgreSQL add-on are available, you'll be prompted to choose one:
bun sql-connect.js# 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 1Create a Cellar add-on:
clever addon create cellar <addon-name>
# Add credentials to .env
clever addon env <addon-name> >> .envGo to the Clever Cloud Console, open your Cellar add-on and create a bucket.
Connect and list bucket contents:
bun s3-connect.js <bucket-name># 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.txtCreate 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# 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