|
| 1 | +# Bootstrap Project |
| 2 | + |
| 3 | +## Install cli tools |
| 4 | + |
| 5 | +First, install our cli tools with `cargo`. |
| 6 | + |
| 7 | +```shell |
| 8 | +cargo install sea-orm-cli@^2.0.0-rc |
| 9 | +cargo install seaography-cli@^2.0.0-rc |
| 10 | +``` |
| 11 | + |
| 12 | +## Config database url |
| 13 | + |
| 14 | +Set `DATABASE_URL` in your environment to your database connection. |
| 15 | + |
| 16 | +```sh |
| 17 | +export DATABASE_URL=protocol://username:password@localhost/database |
| 18 | +``` |
| 19 | + |
| 20 | +Here are some tips for database specific options: |
| 21 | + |
| 22 | +#### MySQL |
| 23 | + |
| 24 | +``` |
| 25 | +mysql://username:password@host/database |
| 26 | +``` |
| 27 | + |
| 28 | +#### Postgres |
| 29 | + |
| 30 | +Specify a schema |
| 31 | + |
| 32 | +``` |
| 33 | +postgres://username:password@host/database?currentSchema=my_schema |
| 34 | +``` |
| 35 | + |
| 36 | +#### SQLite |
| 37 | + |
| 38 | +In memory |
| 39 | + |
| 40 | +``` |
| 41 | +sqlite::memory: |
| 42 | +``` |
| 43 | + |
| 44 | +Create file if not exists |
| 45 | + |
| 46 | +``` |
| 47 | +sqlite://path/to/db.sqlite?mode=rwc |
| 48 | +``` |
| 49 | + |
| 50 | +Read only |
| 51 | + |
| 52 | +``` |
| 53 | +sqlite://path/to/db.sqlite?mode=ro |
| 54 | +``` |
| 55 | + |
| 56 | +## Generate SeaORM Entities |
| 57 | + |
| 58 | +```sh |
| 59 | +sea-orm-cli generate entity -o src/entities --seaography |
| 60 | +``` |
| 61 | + |
| 62 | +You will see something like: |
| 63 | + |
| 64 | +``` |
| 65 | +Writing src/entities/actor.rs |
| 66 | +Writing src/entities/address.rs |
| 67 | +Writing src/entities/category.rs |
| 68 | +Writing src/entities/city.rs |
| 69 | +Writing src/entities/country.rs |
| 70 | +Writing src/entities/customer.rs |
| 71 | +Writing src/entities/film.rs |
| 72 | +Writing src/entities/film_actor.rs |
| 73 | +Writing src/entities/film_category.rs |
| 74 | +Writing src/entities/inventory.rs |
| 75 | +Writing src/entities/language.rs |
| 76 | +Writing src/entities/payment.rs |
| 77 | +Writing src/entities/rental.rs |
| 78 | +Writing src/entities/staff.rs |
| 79 | +Writing src/entities/store.rs |
| 80 | +Writing src/entities/mod.rs |
| 81 | +Writing src/entities/prelude.rs |
| 82 | +Writing src/entities/sea_orm_active_enums.rs |
| 83 | +... Done. |
| 84 | +``` |
| 85 | + |
| 86 | +## Generate Seaography Project |
| 87 | + |
| 88 | +```sh |
| 89 | +seaography-cli -o . -e src/entities --framework axum my-seaography-project |
| 90 | +``` |
| 91 | + |
| 92 | +You can choose between `actix`, `poem`, `axum` as the web framework. The generated project will have a crate named `my-seaography-project`. |
| 93 | + |
| 94 | +### CLI options |
| 95 | + |
| 96 | +```sh |
| 97 | +🧭 A dynamic GraphQL framework for SeaORM |
| 98 | + |
| 99 | +Usage: seaography-cli [OPTIONS] --entities <ENTITIES> --database-url <DATABASE_URL> <CRATE_NAME> |
| 100 | + |
| 101 | +Arguments: |
| 102 | + <CRATE_NAME> Crate name for generated project |
| 103 | + |
| 104 | +Options: |
| 105 | + -o, --output-dir <OUTPUT_DIR> |
| 106 | + Project output directory [default: ./] |
| 107 | + -e, --entities <ENTITIES> |
| 108 | + Entities directory |
| 109 | + -u, --database-url <DATABASE_URL> |
| 110 | + Database URL [env: DATABASE_URL] |
| 111 | + -f, --framework <FRAMEWORK> |
| 112 | + Which web framework to use [default: poem] [possible values: actix, poem, axum] |
| 113 | + --depth-limit <DEPTH_LIMIT> |
| 114 | + GraphQL depth limit |
| 115 | + --complexity-limit <COMPLEXITY_LIMIT> |
| 116 | + GraphQL complexity limit |
| 117 | + -h, --help |
| 118 | + Print help |
| 119 | + -V, --version |
| 120 | + Print version |
| 121 | +``` |
| 122 | + |
| 123 | +## Launch! |
| 124 | + |
| 125 | +```sh |
| 126 | +cargo build |
| 127 | +``` |
| 128 | + |
| 129 | +You should see something like: |
| 130 | + |
| 131 | +```sh |
| 132 | + Compiling seaography v2.0.0-rc.2 |
| 133 | + Compiling seaography-postgres-example v0.1.0 (/Users/chris/seaography/examples/postgres) |
| 134 | + Finished `dev` profile [unoptimized + debuginfo] target(s) in 28.24s |
| 135 | +``` |
| 136 | + |
| 137 | +If the build succeeds, then you can launch it: |
| 138 | + |
| 139 | +```sh |
| 140 | +cargo run |
| 141 | +``` |
| 142 | + |
| 143 | +You should see something like: |
| 144 | + |
| 145 | +```sh |
| 146 | +Visit GraphQL Playground at http://localhost:8000 |
| 147 | +``` |
0 commit comments