atmosphere 0.0.2

Atmosphere for sustainable growth of sqlx projects
Documentation

Atmosphere

🌍 Atmosphere

A lightweight sql framework for sustainable database reliant systems

SQLx Crate Book Docs

Overview

Atmosphere is a lightweight SQL framework designed for sustainable, database-reliant systems. It leverages Rust's powerful type and macro systems to derive SQL schemas from your rust struct definitions into an advanced trait system.

Key Features

  • SQL schema derivation from Rust structs.
  • Advanced trait system for query generation.
  • Automated database code testing with atmosphere::testing
  • ORM-like CRUD traits.
  • Code reusability across API layers using generics.
  • Compile-time introspection for type-safe schema generation.

Quickstart

use atmosphere::prelude::*;
use sqlx::PgPool;

#[derive(Schema, Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
#[table(name = "user", schema = "public")]
struct User {
    #[primary_key]
    id: i32,
    name: String,
    email: String,
}

#[tokio::main]
async fn main() -> sqlx::Result<()> {
    let pool = PgPool::connect(&std::env::var("DATABASE_URL").unwrap()).await?;

    User {
        id: 0,
        name: "demo".to_owned(),
        location: "some@email.com".to_owned(),
    }
    .save(&pool)
    .await?;

    Ok(())
}

Atmosphere introspects the User struct at compile time and generates const available type information about the schema into the Table trait:

impl Table for User {
    const SCHEMA: &str = "public"
    const TABLE: &str = "user"
    const PRIMARY_KEY: Column = Column { name: "id", ty: PrimaryKey, .. };
    const FOREIGN_KEYS: &'static [Column; 0] = &[];
    const DATA: &'static [Column; 2] = &[
        Column { name: "name", ty: Value, .. },
        Column { name: "email", ty: Value, .. }
    ];
}

Roadmap

Alpha Release

  • Advanced SQL Trait System (Table, Column, Relation ..)
  • Derive Macro (Schema)
  • Field Attributes (#[primary_key], #[foreign_key] and so on)
  • SQL Query Generation
  • Automated Integration Testing
  • Attribute Macro (#[table])

Beta Release

  • Transaction Support
  • Hook into query execution using atmosphere::hooks
  • Virtual Columns using (#[virtual = "<sql>"])
  • Getting Database Agnostic
  • Errors using miette
  • Attribute Macro (#[relation])
  • Attribute Macro (#[query])

Stable Release

  • Custom queries
  • Stabilize Traits
  • Provide Application Utils
  • Stabilize Query Generation
  • Table Lenses (subsets / views)

Advanced

  • Postgres Composite Types
  • Support custom types
  • Runtime Inspection
  • Generate Graphs
  • validator support

Longterm

  • Generate GraphQL + HTTP Servers?

Contribution

We welcome contributions! Please see our contribution guidelines for more details.

License

Atmosphere is licensed under Apache 2.0.