Skip to content

Commit

Permalink
docs(README): use --help text & Typo fixes (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelMarks authored Nov 28, 2024
1 parent d307512 commit 2797966
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 24 deletions.
142 changes: 122 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,134 @@ Setting up a custom binary allows you to completely customize the generation; ho
cargo install dsync
```

**CLI Usage**

* `-i`: path to the diesel schema file
* `-o`: model output directory
* `-c`: connection type (for example: `diesel::sqlite::SqliteConnection`)
* `-g`: (optional, repeatable) list of columns that are automatically generated by create/update triggers (for example, `created_at`, `updated_at`)
* `--tsync`: (optional) adds `#[tsync]` attribute to generated structs for the [`tsync` crate](https://github.com/Wulf/tsync)
* `--model-path`: (optional) set a custom model import path, default `crate::models::`
* `--schema-path`: (optional) set a custom schema import path, default `crate::schema::`
* `--no-serde`: (optional) if set, does not output any serde related code
* `--no-crud`: (optional) Do not generate the CRUD functions for generated models
* `--create-str`: (optional) Set which string type to use for `Create*` structs (possible are `string`, `str`, `cow`)
* `--update-str`: (optional) Set which string type to use for `Update*` structs (possible are `string`, `str`, `cow`)
* `--single-model-file`: (optional) Generate only a single model file, instead of a directory with `mod.rs` and `generated.rs`
* `--readonly-prefix`: (optional, repeatable) A prefix to treat a table matching this as readonly *2
* `--readonly-suffix`: (optional, repeatable) A suffix to treat a table matching this as readonly *2
* `--diesel-backend`: (when the "advanced-queries" feature is enabled) The diesel backend in use (possible values include `diesel::pg::Pg`, `diesel::sqlite::Sqlite`, `diesel::mysql::Mysql`, or your custom backend type)
### CLI Usage

```sh
Generate rust structs & query functions from diesel schema files.
Usage: dsync [OPTIONS] --input <INPUT> --output <OUTPUT> --connection-type <CONNECTION_TYPE>
dsync [OPTIONS] <COMMAND>
Commands:
completions Generate shell completions
Options:
-i, --input <INPUT>
Input diesel schema file
-o, --output <OUTPUT>
Output file, stdout if not present
--tsync
adds the #[tsync] attribute to all structs; see
https://github.com/Wulf/tsync
-g, --autogenerated-columns <AUTOGENERATED_COLUMNS>
List of columns which are automatically generated but are not primary
keys (for example: "created_at", "updated_at", etc.)
-c, --connection-type <CONNECTION_TYPE>
rust type which describes a connection
For example:
- `diesel::pg::PgConnection`
- `diesel::sqlite::SqliteConnection`
- `diesel::mysql::MysqlConnection`
-
`diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>`
- or, your custom diesel connection type (struct which implements
`diesel::connection::Connection`)
--no-serde
Disable generating serde implementations
--schema-path <SCHEMA_PATH>
Set custom schema use path
[default: crate::schema::]
--model-path <MODEL_PATH>
Set custom model use path
[default: crate::models::]
--no-crud
Do not generate the CRUD (impl) functions for generated models
--create-str <CREATE_STR>
Set which string type to use for Create* structs
[default: string]
Possible values:
- string: Use "String"
- str: Use "&str"
- cow: Use "Cow<str>"
--update-str <UPDATE_STR>
Set which string type to use for Update* structs
[default: string]
Possible values:
- string: Use "String"
- str: Use "&str"
- cow: Use "Cow<str>"
--create-bytes <CREATE_BYTES>
Set which bytes type to use for Create* structs
[default: vec]
Possible values:
- vec: Use "Vec<u8>"
- slice: Use "&[u8]"
- cow: Use "Cow<[u8]>"
--update-bytes <UPDATE_BYTES>
Set which bytes type to use for Update* structs
[default: vec]
Possible values:
- vec: Use "Vec<u8>"
- slice: Use "&[u8]"
- cow: Use "Cow<[u8]>"
--single-model-file
Only Generate a single model file instead of a directory with "mod.rs"
and "generated.rs"
--once-common-structs
Generate common structs only once in a "common.rs" file
--once-connection-type
Generate the "ConnectionType" type only once in a "common.rs" file
--readonly-prefix <READONLY_PREFIXES>
A Prefix to treat a table matching this as readonly (only generate the
Read struct)
--readonly-suffix <READONLY_SUFFIXES>
A Suffix to treat a table matching this as readonly (only generate the
Read struct)
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
```
#### Example
```sh
dsync -i src/schema.rs -o src/models
```
Notes:
#### Notes
- the CLI has fail-safes to prevent accidental file overwriting
- *2: "readonly" tables dont have `Update*`(`UpdateTodos`) & `Create*`(`CreateTodos`) structs, only `*`(`Todos`, no suffix / prefix) structs.
- *2: "readonly" tables don't have `Update*`(`UpdateTodos`) & `Create*`(`CreateTodos`) structs, only `*`(`Todos`, no suffix / prefix) structs.
For example this is useful for Sqlite views, which are read-only (cannot be written to, but can be read)
## Experimental API
Expand All @@ -139,7 +241,7 @@ We're currently experimenting with advanced query generation. This includes pagi
Alternatively, you can see what gets generated in the advanced queries test here: [`test/advanced_queries/models`](test/advanced_queries/models)
Feel free to open an issue to discuss these API and provide your feeedback.
Feel free to open an issue to discuss these API and provide your feedback.
## Docs
Expand Down
2 changes: 1 addition & 1 deletion src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ fn get_async(table_options: &TableOptions<'_>) -> (&'static str, &'static str) {
("", "")
}

/// Generate all functions (insides of the `impl StuctName { here }`)
/// Generate all functions (insides of the `impl StructName { here }`)
fn build_table_fns(
table: &ParsedTableMacro,
config: &GenerationConfig,
Expand Down
2 changes: 1 addition & 1 deletion src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub struct TableOptions<'a> {
/// Only Generate a single model file instead of a directory with "mod.rs" and "generated.rs"
single_model_file: bool,

/// Indiciates this table is meant to be read-only (dont generate Update & Create structs)
/// Indicates this table is meant to be read-only (don't generate Update & Create structs)
read_only: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ fn handle_table_macro(
let mut had_hashtag = false;

for column_tokens in group.stream().into_iter() {
// reset "had_hastag" but still make it available for checking
// reset "had_hashtag" but still make it available for checking
let had_hashtag_last = had_hashtag;
had_hashtag = false;
match column_tokens {
Expand Down
2 changes: 1 addition & 1 deletion test/test_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ echo "Testing Generation"
# extra separator
echo ""

echo "Testing Compiliation"
echo "Testing Compilation"
./test_compile.sh

0 comments on commit 2797966

Please sign in to comment.