1- ## Add ` rorm ` to your dependencies
1+ ## Dependencies
2+
3+ ### ` tokio `
4+
5+ Rorm uses ` async ` rust and the only supported runtime is ` tokio ` .
6+
7+ If you never heard of it, you probably should look up some quick introduction to ` async ` .
8+
9+ ### ` rorm `
210
311``` toml
412[dependencies ]
@@ -22,62 +30,7 @@ rorm = { git = "https://github.com/rorm-orm/rorm", branch = "dev" }
2230 To use the dev branch you want to use the docs generated by
2331 executing `cargo doc`.
2432
25- ### Choose your async runtime
26-
27- Currently, there are two runtimes supported.
28- Choose one of them and enable the respective crate feature to make ` rorm ` work:
29-
30- - ` tokio `
31- - ` async-std `
32-
33- Add the chosen runtime to the features of ` rorm ` , for example:
34-
35- ``` toml
36- [dependencies ]
37- rorm = { version = " *" , features = [" tokio" ] }
38- ```
39-
40- ### Setup ` rorm-main `
41-
42- This step is strictly speaking optional, but it's highly recommended.
43- ` rorm-main ` is a feature to ease the integration with the migrator,
44- therefore it's unnecessary if the migrator isn't used. It overwrites the
45- ` main ` function when activated, which will produce a JSON file of the
46- currently known models in the source code. The recommended procedure is to
47- use this feature in a build pipeline, for extended testing purposes or
48- whenever you want to make new migrations of the models.
49-
50- 1 . Add the ` rorm-main ` feature in your ` Cargo.toml ` :
51- ``` toml
52- [features ]
53- rorm-main = []
54- ```
55- Make sure to disable this feature by default. For example,
56- IntelliJ manages which features will be enabled
57- internally. When looking at the ` [features] ` section,
58- it will show them using checkboxes at the left edge.
59- ` rorm-main ` should not be set.
60-
61- 2 . Annotate your main function:
62- ``` rust
63- #[rorm:: rorm_main]
64- fn main () {
65- // ...
66- }
67- ```
68- This attribute won't do anything unless the ` rorm-main ` feature
69- becomes enabled. Depending on the chosen runtime implementation,
70- you may need another annotation for that. For example, for Tokio
71- you would combine the annotations in one piece as follows:
72- ``` rust
73- #[rorm:: rorm_main]
74- #[tokio:: main]
75- async fn main () {
76- // ...
77- }
78- ```
79-
80- ### Project setup
33+ ### CLI tool
8134
8235Make sure to have the CLI utility ` rorm-cli ` available:
8336
@@ -88,6 +41,9 @@ cargo install -f rorm-cli
8841Head over to [ project setup] ( project_setup.md ) for more details,
8942especially if you want to take some additional configuration for your setup.
9043
44+ Alternatively you can enable ` rorm ` 's ` cli ` feature which re-exports the binaries functions.
45+ This allows you to integrate the ` migrate ` command into your binary's cli.
46+
9147## Define a model
9248
9349``` rust
@@ -136,27 +92,23 @@ pub(crate) struct UserNew {
13692### Generate migrator files
13793
13894After the first database model has been added, the current models
139- can be extracted from the Rust source code:
95+ can be extracted from the Rust source code.
14096
141- ``` bash
142- cargo run --features rorm-main
97+ ``` rust
98+ rorm :: write_models ( File :: create ( " .models.json " ) ? ) ?
14399```
144100
145101This will create a file ` .models.json ` to be processed by the migrator. So,
146102you need to run this every time you want to generate new migrations.
147- You might want to add it to a build chain if you're using any.
148- It requires the ` rorm-main ` feature to be set up properly
149- (see [ above] ( #setup-rorm-main ) ).
103+
104+ You could run this snippet through some kind of subcommand in your binary's development builds.
150105
151106### Make migration TOML files from the migrator JSON file
152107
153108``` sh
154109rorm-cli make-migrations
155110```
156111
157- Otherwise, if you configured the commands as outlined [ here] ( project_setup.md ) ,
158- it's also possible to invoke those ` rorm-cli ` commands via ` cargo make <cmd> ` .
159-
160112This command will read the previously generated JSON file ` .models.json `
161113to compute the required database migrations as TOML files in the
162114directory ` migrations/ ` . Note that those TOML files need to be applied
0 commit comments