
🌍 Atmosphere
A lightweight sql framework for sustainable database reliant systems
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 *;
async
Atmosphere introspects the User and Post structs at compile time and
generates const available type information about the schema into the Table
trait.
Roadmap
Alpha Release
- Advanced SQL Trait System (
Table,Column,Relation..) - SQL Field Attributes (
#[sql(pk)],#[sql(fk -> Model)]and so on) - SQL Query Generation
- Automated Integration Testing
- Attribute Macro (
#[table])
Beta Release
- Transaction Support
- Getting Database Agnostic
- Hook into query execution using
atmosphere::hooks - Errors using
miette - Combined Primary and Foreign Keys
Stable Release
- Postgres Composite Types
- Support Custom Types
- Runtime Inspection
- Provide Application Utils
- Stabilize Traits
- Stabilize Query Generation
- Table Lenses (subsets / views)
-
validatorsupport - Auto Timestamping
Advanced
- Virtual Columns using (
#[virtual = "<sql>"]) - Soft Delete Support
- Attribute Macro (
#[query]) - Custom queries
Longterm
- Generate GraphQL + HTTP Servers?
- Generate Graphs
Functionalities
Given a struct Model that derives its atmosphere schema using #[table]:
use *;
Atmosphere is able to derive and generate the following queries:
CRUD
atmosphere::Create
Model::create
atmosphere::Read
Model::read: read aModelby its primary key, returning aModel.Model::find: find aModelby its primary key, returning anOption<Model>.Model::read_all: read allModels, returning aVec<Model>.Model::reload
atmosphere::Update
Model::updateModel::upsert
atmosphere::Delete
Model::deleteModel::delete_by
Field Queries
Each struct field that is marked with #[sql(unique)] becomes queryable.
In the above example b was marked as unique so atmosphere implements:
Model::find_by_b: find aModelby itsbfield, returning anOption<Model>.Model::delete_by_b: delete aModelby itsbfield.
Relationships & Inter-Table Queries
Given that a model contains fields are marked as a foreign key / point to
another atmosphere::Table atmosphere – for example:
Atmosphere is able to generate utility queries to move across Table boundaries:
Model::submodelsModel::delete_submodelsSubmodel::modelSubmodel::find_by_modelSubmodel::delete_by_model
Note that the function names contain
modelandsubmodel– they are derived from the respective struct names.
Json support
Several databases support a JSON (and often JSONB) type, for which sqlx has native support through #[sqlx(json)] and #[sqlx(json(nullable))].
Since atmosphere only needs to know whether the column is JSON and to stay forward-compatible with future changes to sqlx's attribute, we use the following syntax:
You can also manually handle the JSON support using the following (it will mean accessing the inner type through .as_ref() or .0):
use Json;
Contribution
We welcome contributions! Please see our contribution guidelines for more details.
License
Atmosphere is licensed under Apache 2.0.