#postgresql #tokio-postgres #driver #database-migrations #opinionated #migration #degen

bin+lib degen-sql

A postgres database engine for rust that builds on top of tokio-postgres and deadpool

24 releases

new 0.2.16 Mar 20, 2025
0.2.15 Mar 17, 2025
0.2.1 Feb 25, 2025
0.1.16 Feb 23, 2025
0.1.2 Oct 20, 2023

#1014 in Database interfaces

Download history 4/week @ 2024-12-04 9/week @ 2024-12-11 1/week @ 2024-12-18 502/week @ 2025-01-29 264/week @ 2025-02-05 132/week @ 2025-02-12 564/week @ 2025-02-19 796/week @ 2025-02-26 91/week @ 2025-03-05 824/week @ 2025-03-12

2,291 downloads per month
Used in vibegraph

MIT license

75KB
1.5K SLoC

Degen Sql

An opinionated postgres driver for rust and a light wrapper around tokio-postgres.

Easily establish a postgres connection and run migrations from a folder.


cargo add degen-sql

A note about the migrate and rollback_full scripts

Since you cannot run scripts of dependencies, it is recommended that you copy and paste the 'scripts' folder from this repo into your project and then set up binaries in your Cargo.toml to run them.

Then, you will have a migrate script and a rollback script to use in your project.

Step 1.

Set your env vars for postgres



DB_HOST="db.co....blb.supabase.co"

DB_USER="postgres"
DB_NAME="postgres"

DB_PASSWORD="Foo....baR"


Step 2.

Use in your code


 
 
use degen_sql::db::postgres::postgres_db::{Database,DatabaseCredentials};
  

use dotenvy::dotenv;
use std::env;
 
 
async fn main() -> io::Result<()> {
    dotenv().ok();  //you dont HAVE to load them in like this but this is typical. Do not forget this if you use ::from_env()!!

   
 
   
    let database_credentials = DatabaseCredentials::from_env();   //or you can use DatabaseCredentials { ... } and create the struct manually
  
    let database = Arc::new(
        Database::connect(
        database_credentials, None
    ).await.unwrap());
      
  
    //EXAMPLE USING THE DATABASE CONNECTION WITH ACTIX 
     
    HttpServer::new(move || {
        

        let app_state = AppState {
            database: Arc::clone(&database) 
        };

        App::new()
            .app_data(Data::new(app_state)) // Here is where we inject our database for our endpoints to use 
             
            .configure(  ...routes ...   )
             
            
    })
    .bind("0.0.0.0:3000")?
    .run()
    .await
}




Step 3

Build your migrations and models. If you would like to see an example of this in action, see the vibegraph project

Dependencies

~16–28MB
~415K SLoC