GithubHelp home page GithubHelp logo

toursslivers / awto Goto Github PK

View Code? Open in Web Editor NEW

This project forked from awto-rs/awto

0.0 0.0 0.0 102 KB

Awtomate your ๐Ÿฆ€ microservices with awto

License: Apache License 2.0

Rust 100.00%

awto's Introduction

awto

Awtomate your ๐Ÿฆ€ microservices with awto

crate

What is awto?

Awto treats your rust project as the source of truth for microservices, and generates database tables and protobufs based on your schema and service.

Database Generation

  • Database tables are generated from your Rust structs
  • Changes to your structs are detected and will modify the table schema accordingly

Protobuf Generation

  • Generate protobuf schemas from your models
  • Compile a protobuf server from your app's service

Concepts

With awto, you create a Cargo workspace for each microservice. Under your workspace, you create two libs: schema and service

Schema

The schema lib's purpose is to define your microservice models which will be used to generate database tables.

// schema/src/lib.rs

register_schemas!(Product);

#[derive(Model)]
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.

Service

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.

Cargo workspace

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 CLI

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 service
  • protobuf - based on tonic, provides a protobuf server library

Roadmap

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.

Contributing

Whether you want to share ideas, bugs, suggestions, or other, your contributions to this project are welcomed ๐ŸคŒ

License

By contributing, you agree that your contributions will be licensed under this repository's MIT or Apache-2.0 License.

awto's People

Contributors

tqwewe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.