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.
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.
A model manages the data storage and interacts with the database.
fn get_allReturn all records.fn create_oneCreate a record.
fn get_oneReturn a record.fn create_get_oneCreate a record and return it.fn update_oneUpdate a record.fn update_get_oneUpdate a record and return it.fn patch_onePatch update a record.fn patch_get_onePatch update a record and return it.fn delete_oneDelete a record.
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.
Aggregate in a table.
A controller manages the connection between model and view.
-
fn get_manyReturn records. -
fn getReturn a record. -
fn createCreate a record and return it. -
fn updateUpdate a record and return it. -
fn patchPatch update a record and return it. -
fn deleteDelete a record. -
type GetManyRequestQueryThe query parameters that can be used for custom requests using indexes. -
type StateThe stateful context of the controller, which contains the database connection. -
type AuthRequest authentication.
AuthToken<()>doesn't do any authentication.
You can implement the authenticate trait for custom authentication and use it likeAuthToken<T>.
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.
Serve the app at address in URL environment variable, defaults to "localhost:80".