12 releases
Uses new Rust 2024
| new 0.2.6 | Oct 31, 2025 |
|---|---|
| 0.2.5 | Oct 31, 2025 |
| 0.1.5 | Oct 1, 2025 |
| 0.1.4 | Aug 22, 2025 |
| 0.1.2 | Jul 29, 2025 |
#886 in Database interfaces
220 downloads per month
58KB
1K
SLoC
Laraxum
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_allReturn all records.fn create_oneCreate a record.
trait Model
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.
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_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>.
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".
Dependencies
~11–30MB
~408K SLoC