Skip to content

Commit f0dc3a2

Browse files
committed
Updated getting started
1 parent 1a62407 commit f0dc3a2

File tree

2 files changed

+23
-66
lines changed

2 files changed

+23
-66
lines changed

docs/rorm/getting_started.md

Lines changed: 18 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
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

8235
Make sure to have the CLI utility `rorm-cli` available:
8336

@@ -88,6 +41,9 @@ cargo install -f rorm-cli
8841
Head over to [project setup](project_setup.md) for more details,
8942
especially 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

13894
After 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

145101
This will create a file `.models.json` to be processed by the migrator. So,
146102
you 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
154109
rorm-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-
160112
This command will read the previously generated JSON file `.models.json`
161113
to compute the required database migrations as TOML files in the
162114
directory `migrations/`. Note that those TOML files need to be applied

docs/rorm/project_setup.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Project setup
22

3+
!!! warning
4+
5+
This page is outdated and does not reflect the current
6+
recommendations of the rorm authors.
7+
38
Install the necessary CLI tools:
49
```bash
510
cargo install -f cargo-make rorm-cli

0 commit comments

Comments
 (0)