Integrate Daytonia in a Url Shortener App
December 22, 2024

Integrate Daytonia in a Url Shortener App


What is Daytona?

Daytona is powerful Open source tools This makes development environment management effortless. With just one command, developers can instantly launch a standardized environment that works seamlessly with popular IDEs, including VS Code, Cursors, Jupyter and the full JetBrains suite. Our free product includes a comprehensive SDK that gives developers and AI agents programmatic control over environment creation, Git operations, and workspace configuration.

learn more


How do I integrate Daytona into a URL shortener application

**Daytonia** is a hosted database platform that allows you to easily deploy and manage your database. I’m using Daytonia to host the MySQL database for the URL Shortener application. Here’s how I integrated Daytonia into the project:


Steps to integrate Datonia with URL shortener application


Set up MySQL database on Daytonia

  1. Visit Datonia GitHub repository Or go directly to their website.
  2. Create an account on Datonia (log in if you already have an account).
  3. Deploy a new MySQL database instance:
  • Specify your database name, username, and password.
  • Copy the connection details (e.g. host, port, username, password, database name).


Update environment variables

In the URL Shortener project, find the .env file.

Update the database connection settings using the details provided by Datonia:

For example:

DB_HOST=mysql.datonia.io
DB_PORT=3306
DB_DATABASE=url_shortener
DB_USERNAME=admin
DB_PASSWORD=supersecurepassword
Enter full screen mode

Exit full screen mode


Update Docker Compose archive (if using Docker)

If you use Docker to run your application (like me), make sure your docker-compose.yml file is configured to use the external Datonia repository. Replace the default mysql service configuration with external Datonia details.

For example:

services:
  app:
    build:
      context: .
    ports:
      - "8080:80"
    env_file:
      - .env
Enter full screen mode

Exit full screen mode

Since Datonia is managing the MySQL database, I no longer need mysqlmy servicesocker-compose.yml document.


Import database schema into Datonia

  1. Export the existing database schema or use the url_shortener.sql file provided in the project.
  2. Import the schema into the MySQL instance managed by Datonia:
  • Use a MySQL client (such as MySQL Workbench) or a CLI tool.
  • Example command to import schema:

mysql -h -u -p < database/url_shortener.sql


Test application

  1. Launch the application using Docker or a local server.
  2. The application should now be connected to the MySQL database managed by Daytonia.
  3. Verification function:
  • Create a short URL.
  • Ensure information is saved and retrieved correctly.

Check out my repository here

2024-12-22 00:16:06

Leave a Reply

Your email address will not be published. Required fields are marked *