Skip to main content
You can connect Magic Container apps to your database by adding credentials as environment variables directly from the database dashboard.
1

Go to the Access page

Navigate to Dashboard > Edge Platform > Database > [Select Database] > Access.
2

Generate tokens

Click Generate Tokens to create new access credentials for your database.
Generate Tokens
3

Add to Magic Container

Once the tokens are generated, click Add Secrets to Magic Container App.
Add to Magic
Container
4

Select your app

Choose the Magic Container app you want to connect to your database.
Select App
5

Access the environment variables

The database URL and access token are now available as environment variables in your app. Use them to connect to your database:
import { createClient } from "@libsql/client/web";

const client = createClient({
  url: process.env.DB_URL,
  authToken: process.env.DB_TOKEN,
});

const result = await client.execute("SELECT * FROM users");