diff --git a/README.md b/README.md index 5e6aef8d..eb4d6633 100644 --- a/README.md +++ b/README.md @@ -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 --output --connection-type + dsync [OPTIONS] + +Commands: + completions Generate shell completions + +Options: + -i, --input + Input diesel schema file + + -o, --output + Output file, stdout if not present + + --tsync + adds the #[tsync] attribute to all structs; see + https://github.com/Wulf/tsync + + -g, --autogenerated-columns + List of columns which are automatically generated but are not primary + keys (for example: "created_at", "updated_at", etc.) + + -c, --connection-type + rust type which describes a connection + + For example: + - `diesel::pg::PgConnection` + - `diesel::sqlite::SqliteConnection` + - `diesel::mysql::MysqlConnection` + - + `diesel::r2d2::PooledConnection>` + - or, your custom diesel connection type (struct which implements + `diesel::connection::Connection`) + + --no-serde + Disable generating serde implementations + + --schema-path + Set custom schema use path + + [default: crate::schema::] + + --model-path + Set custom model use path + + [default: crate::models::] + + --no-crud + Do not generate the CRUD (impl) functions for generated models + + --create-str + Set which string type to use for Create* structs + + [default: string] + + Possible values: + - string: Use "String" + - str: Use "&str" + - cow: Use "Cow" + + --update-str + Set which string type to use for Update* structs + + [default: string] + + Possible values: + - string: Use "String" + - str: Use "&str" + - cow: Use "Cow" + + --create-bytes + Set which bytes type to use for Create* structs + + [default: vec] + + Possible values: + - vec: Use "Vec" + - slice: Use "&[u8]" + - cow: Use "Cow<[u8]>" + + --update-bytes + Set which bytes type to use for Update* structs + + [default: vec] + + Possible values: + - vec: Use "Vec" + - 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 + A Prefix to treat a table matching this as readonly (only generate the + Read struct) + + --readonly-suffix + 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 @@ -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 diff --git a/src/code.rs b/src/code.rs index b4388310..29367b5c 100644 --- a/src/code.rs +++ b/src/code.rs @@ -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, diff --git a/src/global.rs b/src/global.rs index 9c951bac..ad1eaa0c 100644 --- a/src/global.rs +++ b/src/global.rs @@ -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, } diff --git a/src/parser.rs b/src/parser.rs index 995d649a..bfa1b728 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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 { diff --git a/test/test_all.sh b/test/test_all.sh index ece659d3..24817f96 100755 --- a/test/test_all.sh +++ b/test/test_all.sh @@ -15,5 +15,5 @@ echo "Testing Generation" # extra separator echo "" -echo "Testing Compiliation" +echo "Testing Compilation" ./test_compile.sh