Crates.io | awto-compile |
lib.rs | awto-compile |
version | 0.1.2 |
source | src |
created_at | 2021-10-17 16:48:58.568846 |
updated_at | 2021-10-21 17:31:19.133696 |
description | Compile microservices built with Awto |
homepage | |
repository | https://github.com/awto-rs/awto |
max_upload_size | |
id | 466299 |
size | 41,491 |
Awto treats your rust project as the source of truth for microservices, and generates database tables and protobufs based on your schema and service.
With awto, you create a Cargo workspace for each microservice. Under your workspace, you create two libs: schema
and service
The schema lib's purpose is to define your microservice models which will be used to generate database tables.
// schema/src/lib.rs
use awto::prelude::*;
schema! {
#[database_table]
#[protobuf_message]
pub struct Product {
pub id: Uuid,
pub created_at: DateTime<FixedOffset>,
pub updated_at: DateTime<FixedOffset>,
pub name: String,
#[awto(max_len = 120)]
pub description: Option<String>,
#[awto(default = 0)]
pub price: i64,
}
}
See example schema in examples/ecom
.
The service lib is where you write your business logic. This business logic can later be used to create a protobuf API (and in the future a graphql API).
// service/src/lib.rs
register_services!(ProductService);
pub struct ProductService {
pub conn: DatabaseConnection,
}
#[protobuf_service]
impl ProductService {
pub async fn find_by_id(&self, request: ProductId) -> Result<Product, Status> {
let product = product::Entity::find_by_id(request.id)
.one(&self.conn)
.await
.map_err(|err| Status::internal(err.to_string()))?
.ok_or_else(|| Status::not_found("product not found"))?;
Ok(product.into())
}
}
See example service in examples/ecom
.
Your schema and service libs should be under a cargo workspace.
# root Cargo.toml
[workspace]
members = ["schema", "service"]
See example project in examples/ecom
.
Awto provides a cli for generating additional libraries with the awto compile <lib>
command.
Currently the available libraries are:
database
- based on SeaORM, provides a database library for use in your serviceprotobuf
- based on tonic, provides a protobuf server libraryThe cli can be installed with:
cargo install awto-cli
This will provide a binary called awto
.
Check installation with awto --help
.
To compile a library, you can run:
awto compile <output>
The available outputs currently are:
database
- syncs your database with your schema and generates a lib for performing operations with the database via SeaORM.protobuf
- generates a protobuf file and lib which can be used as a protobuf server & client via tonic.Awto is still in alpha stages and is made mostly as an experiment at this point. If it gets some attention, serious effort will be put into it to make it a meaningful tool for the Rust community.
Whether you want to share ideas, bugs, suggestions, or other, your contributions to this project are welcomed 🤌
By contributing, you agree that your contributions will be licensed under this repository's MIT or Apache-2.0 License.