Skip to content

ludwink/axum-sqlx-postgresql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Axum, SQLx and PostgreSQL

Introduces Axum, SQLx, and PostgreSQL to build scalable, type-safe, and production-ready REST APIs.

Features

  • Axum: Modern async web framework for Rust
  • SQLx: SQL crate that simplifies database interactions
  • PostgreSQL: Robust relational database
  • Docker: Containerized deployment (optional)

Running the Project

1. Prerequisites

Make sure you have the following installed:

Install SQLx CLI:

cargo install sqlx-cli --no-default-features --features rustls,postgres

2. Environment Variables

Copy the example environment file to .env and adjust the values as needed.

3. Database Setup

  1. Create the database (if it doesn't exist)

This will create the database specified in the DATABASE_URL from your .env file.

sqlx database create
  1. Run database migrations
sqlx migrate run

4. Run the Server

Option A: Run locally with Cargo

cargo run

Option B: Run with Docker

  1. Build the image
docker build -t axum-api .
  1. Run the container
docker run -d --name axum-api-container -p 3000:3000 --env-file .env axum-api

Important

This only runs the Axum server. You still need a running PostgreSQL instance accessible via the DATABASE_URL defined in your .env file.

Common Docker Commands:

# Stop the container
docker stop axum-api-container

# Start the container
docker start axum-api-container

# View logs
docker logs axum-api-container

# Remove the container
docker rm -f axum-api-container

# Remove the image
docker rmi axum-api

About

Introduces Axum, SQLx, and PostgreSQL to build scalable, type-safe, and production-ready REST APIs.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published