arysn is Rust ORM code generator.
see arysn-test/build.rs, arysn-test/tests
Connection
To access Postgresql, tokio-postgres to be used. You can also use deadpool-postgres.
Code generation
define_ar
is used to generate the code.
use ;
use define_ar;
The following four files will be generated.
- user.rs
- user_impl.rs
- role.rs
- role_impl.rs
- enums.rs
user.rs and role.rs are intended to be used in frontend applications such as Yew.
user_impl.rs and role_impl.rs contain DB access code.
enums.rs is generated by CREATE TYPE
SQL.
Query
let conn = ... // tokio-postgres or deadpool-postgres client
let users: = select.active.eq.load.await?;
let user: User = select.id.first.await?;
use Optional;
let user: = select.id.first.await.optional?;
Join
let users: = select.roles
.load.await?;
N+1
let users: = select.roles
.load.await?;
SQL looks like this
SELECT * FORM users;
SELECT * FROM rolse WERE WHERE id IN (....);
The conditions before the preload are used to join.
let users: = select
.roles
.load.await?;
SQL looks like this
SELECT * FORM users INNER JOIN roles ON roles.user_id=users.id
WHERE roles.role_types='admin';
SELECT * FROM rolse WERE WHERE role_types='admin' id IN (....);
Conditions after the preload are not used when joining.
let users: = select
.roles
.load.await?;
SQL looks like this
SELECT * FORM users;
SELECT * FROM rolse WERE WHERE role_types='admin' id IN (....);
UUID
To use the UUID, you need to specify features for tokio-postgres and uuid.
Cargo.toml
[]
= { = "0.7", = ["with-chrono-0_4", "with-uuid-0_8"] }
= { = "0.8", = ["serde"] }
PostGIS
Only PostGIS POINT
is supported.
You must specify gis
featuers.
Cargo.toml
[]
= { = "0.3", = ["gis"] }