Crate alaqsam

Crate alaqsam 

Source
Expand description

§alaqsam

Create backend API servers easily using Axum and SQLX.
It uses the MVC paradigm…:

  • Model: manages the data storage and interacts with the database.
  • View: manages the data input/output and interacts with the end user.
  • Controller: manages the connection between model and view.

…and handles the Model and Controller, which the View (frontend client) can interact with.

§macro db

Define a database, tables and columns.
The database is defined using the db attribute macro on a module.
Each table is defined using the db attribute on a struct in the module.
Each column is defined using the db attribute on a field in the struct.

§Model

A model manages the data storage and interacts with the database.

§trait Collection

  • fn get_all Return all records.
  • fn create_one Create a record.

§trait Model

  • fn get_one Return a record.
  • fn create_get_one Create a record and return it.
  • fn update_one Update a record.
  • fn update_get_one Update a record and return it.
  • fn patch_one Patch update a record.
  • fn patch_get_one Patch update a record and return it.
  • fn delete_one Delete a record.

§trait ManyModel

A manymodel is similar to a model but with two columns. The column will be used as an id for multiple values in the other column.
This can be used to create many-to-many relationships.

§trait AggregateMany and trait AggregateOne

Aggregate in a table.

§Controller

A controller manages the connection between model and view.

§trait Controller

  • fn get_many Return records.

  • fn get Return a record.

  • fn create Create a record and return it.

  • fn update Update a record and return it.

  • fn patch Patch update a record and return it.

  • fn delete Delete a record.

  • type GetManyRequestQuery The query parameters that can be used for custom requests using indexes.

  • type State The stateful context of the controller, which contains the database connection.

  • type Auth Request authentication.
    AuthToken<()> doesn’t do any authentication.
    You can implement the authenticate trait for custom authentication and use it like AuthToken<T>.

§macro router

Create a router.
The router has methods and routes. A route is a path and a router, which makes it nested and recursive. If the router has methods, they are created at the start in a use statement. You can either create each method route with curly brackets like a struct expression where the field name is the router method, or you can give the controller, which will create all the method routes and nested method routes for that controller.

§macro serve

Serve the app at address in URL environment variable, defaults to “localhost:80”.

Re-exports§

pub use controller::Controller;
pub use controller::auth::AuthToken;
pub use controller::auth::Authenticate;
pub use controller::auth::AuthenticateToken;
pub use controller::auth::Authorize;
pub use controller::extract::Json;
pub use error::AppError;
pub use error::AuthError;
pub use error::Error;
pub use error::ModelError;
pub use model::AggregateMany;
pub use model::AggregateOne;
pub use model::Collection;
pub use model::Connect;
pub use model::Db;
pub use model::ManyModel;
pub use model::Model;
pub use model::Table;

Modules§

controller
A controller manages the connection between model and view.
error
model
A model manages the data storage and interacts with the database.

Macros§

authorize
Implement authorization for a type that can be compared to the authentication type.
router
Create a router.
serve
Serve the app.
transparent
Implement database encoding/decoding and frontend serializing/deserializing for a transparent wrapper type.
transparent_encode_decode
Implement database encoding/decoding for a transparent wrapper type.
transparent_enum
Define an enum wrapper type for an integer type and implement database encoding/decoding and frontend serializing/deserializing for it.
transparent_serde
Implement frontend serializing/deserializing for a transparent wrapper type.

Attribute Macros§

db
Define a database, tables and columns.