Generate rust structs & query functions from diesel schema files

Overview

dsync

License: MIT OR Apache-2.0

A utility to generate database structs and querying code from diesel schema files. Primarily built for create-rust-app.

Currently, it's more advantageous to generate code over deriving code with macros because intellisense and autocompletion isn't quite there when it comes to macro expansion.

Demo

Given the following schema:

// schema.rs
diesel::table! {
    todos (id) {
        id -> Int4,
        text -> Text,
        completed -> Bool,
    }
}

We run:

cargo dsync -i schema.rs -o models

Now we have everything we need!

use models::todos;

async fn demo(db: Connection) {
  let created_todo = todos::create(&mut db, todos::CreateTodo {
    text: "Create a demo",
    completed: false,
  }).await?;
  
  let todos_list = todos::paginate(&mut db, 1, 10).await?;
  
  let updated_todo = todos::update(&mut db, created_todo.id, UpdateTodo {
    text: created_todo.text,
    completed: true,
  }).await?;
}

For a complete example, see test/simple_schema/schema.rs which generates all the code in test/simple_schema/models.

Usage

  1. Add this crate:

    cargo add dsync
  2. Create a new binary in your project which uses the crate (for example, bin/dsync.rs)

    use std::{collections::HashMap, path::PathBuf};
    use dsync::{GenerationConfig, TableOptions};
    
    pub fn main() {
        let dir = env!("CARGO_MANIFEST_DIR");
    
        dsync::generate_files(
            PathBuf::from_iter([dir, "src/schema.rs"]), 
            PathBuf::from_iter([dir, "src/models"]), 
            GenerationConfig { /* ... your generation options ... */ }
        );
    }
  3. Create a Cargo.toml binary entry:

    [[bin]]
    name = "dsync"
    path = "bin/dsync.rs"
  4. Execute!

cargo run --bin dsync

Protip: to use cargo dsync, create an alias in .cargo/config:

[alias]
dsync="run --bin dsync"

Pre-built binary

Setting up a custom binary allows you to completely customize the generation; however, if complete customization isn't necessary, you can install the CLI directly (you'll have to make sure you keep it up-to-date by running this periodically):

cargo install dsync 

CLI Usage

  • -i: input argument: path to schema file
  • -o: output argument: path to directory where generated code should be written
  • -c: connection type (for example: diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>)
  • -g: (optional) 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 (see https://github.com/Wulf/tsync)
  • note: the CLI has fail-safes to prevent accidental file overwriting
dsync -i src/schema.rs -o src/models

Docs

See dsync --help for more information.

Feel free to open tickets for support or feature requests.

Development/Testing

Use ./test/test_all.sh to run tests. After running the test, there should be no unexpected changes to files in ./test (use git status and git diff to see if there were any changes).

License

This tool is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE, LICENSE-MIT, and COPYRIGHT for details.

Comments
  • Fixes issues with the belongs_to syntax when using associations

    Fixes issues with the belongs_to syntax when using associations

    Hello! I was having some trouble with the generated code when using associations on the belongs_to syntax. This PR solves the syntax pattern problem. There is a another issue that I should mention is that when the struct is generated it's using the singular pattern and on the belongs_to syntax wasn't. I fixed that too, but I suggest we use another strategy to provide some better guarantee on the naming pattern!

    opened by jean-santos 2
  • Bump indoc from 1.0.7 to 2.0.0

    Bump indoc from 1.0.7 to 2.0.0

    Bumps indoc from 1.0.7 to 2.0.0.

    Release notes

    Sourced from indoc's releases.

    2.0.0

    • Change handling of final newline at zero levels of indentation (#55)
    • Add concatdoc! macro (#56)
    • Raise oldest supported rustc to 1.56

    1.0.9

    • Fix parsing of some edge cases involving angle brackets in writedoc's expr argument (#54)

    1.0.8

    • Documentation improvements
    Commits
    • bbbec14 Release 2.0.0
    • 24a804e Add concatdoc docs
    • 476b937 Delete paths from .cargo/config
    • b5fb2dc Merge pull request #57 from dtolnay/fromstr
    • 623d666 Replace TokenStream::from_str with Literal::from_str
    • 28d6d25 Switch to 2021 edition
    • 46d38c0 Merge pull request #56 from dtolnay/concat
    • 4fec8a9 Add concatdoc macro
    • 1f70529 Merge pull request #55 from dtolnay/trailing
    • 31694b5 Preserve last newline even if not indented
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies rust 
    opened by dependabot[bot] 1
  • Bump proc-macro2 from 1.0.47 to 1.0.50

    Bump proc-macro2 from 1.0.47 to 1.0.50

    Bumps proc-macro2 from 1.0.47 to 1.0.50.

    Release notes

    Sourced from proc-macro2's releases.

    1.0.50

    • Implement Hash for proc_macro2::LineColumn (#362)

    1.0.49

    • Opt out of -Zrustdoc-scrape-examples on docs.rs for now

    1.0.48

    • Documentation improvements
    Commits
    • 94c7519 Release 1.0.50
    • f01da43 Merge pull request #362 from dtolnay/hashlinecolumn
    • d4c564b Implement Hash for LineColumn
    • 92a0295 Merge pull request #361 from dtolnay/linecolumn
    • a4be982 Deduplicate implementations of LineColumn
    • 9924b79 Prevent actions duplication on noop merge commits
    • 37e89e1 Sync license text with rust-lang repos
    • 8779f4c Update ui test suite to nightly-2022-12-30
    • 293705d Release 1.0.49
    • 6b9ee3d Opt out -Zrustdoc-scrape-examples on docs.rs
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies rust 
    opened by dependabot[bot] 1
  • Bump anyhow from 1.0.64 to 1.0.68

    Bump anyhow from 1.0.64 to 1.0.68

    Bumps anyhow from 1.0.64 to 1.0.68.

    Release notes

    Sourced from anyhow's releases.

    1.0.68

    • Opt out of -Zrustdoc-scrape-examples on docs.rs for now

    1.0.67

    • Improve the backtrace captured when context() is used on an Option (#280)

    1.0.66

    • Reduce unhelpful backtrace frames in backtraces captured during a context call (#279)

    1.0.65

    • impl Provider for anyhow::Error
    Commits
    • 867763b Release 1.0.68
    • c0a87d0 Opt out -Zrustdoc-scrape-examples on docs.rs
    • 1cc707b Release 1.0.67
    • 613b261 Update build status badge
    • 0f922d7 Disable backtrace CI on Rust 1.50
    • acecd9b Update ui test suite to nightly-2022-12-15
    • 0bac51f Time out workflows after 45 minutes
    • 60e8800 Fix renamed let_underscore_drop lint
    • 8d1c734 Update ui test suite to nightly-2022-11-16
    • 451651b Update ui test suite to nightly-2022-11-11
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies rust 
    opened by dependabot[bot] 1
  • Bump indoc from 1.0.7 to 1.0.8

    Bump indoc from 1.0.7 to 1.0.8

    Bumps indoc from 1.0.7 to 1.0.8.

    Release notes

    Sourced from indoc's releases.

    1.0.8

    • Documentation improvements
    Commits
    • 31daf63 Release 1.0.8
    • f1f1076 Update build status badge
    • e11839a Time out workflows after 45 minutes
    • 5f964a8 Raise minimum tested toolchain to rust 1.56
    • 4c9287a Remove default package.readme metadata from Cargo.toml
    • e1657ed GitHub Workflows security hardening
    • 59770fe Revert "Avoid cargo 1.45–1.50 in GitHub Actions"
    • defd69a Avoid cargo 1.45–1.50 in GitHub Actions
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies rust 
    opened by dependabot[bot] 1
  • Bump anyhow from 1.0.64 to 1.0.69

    Bump anyhow from 1.0.64 to 1.0.69

    Bumps anyhow from 1.0.64 to 1.0.69.

    Release notes

    Sourced from anyhow's releases.

    1.0.69

    • Documentation improvements

    1.0.68

    • Opt out of -Zrustdoc-scrape-examples on docs.rs for now

    1.0.67

    • Improve the backtrace captured when context() is used on an Option (#280)

    1.0.66

    • Reduce unhelpful backtrace frames in backtraces captured during a context call (#279)

    1.0.65

    • impl Provider for anyhow::Error
    Commits
    • 58377ab Release 1.0.69
    • f65b087 Merge pull request #295 from dtolnay/docrepr
    • 10370e9 Hide repr attribute from documentation
    • cf2adb4 Raise minimum toolchain for the backtrace feature to 1.60
    • 0a45d76 Prevent actions duplication on noop merge commits
    • 3d91f13 Sync license text with rust-lang repos
    • ed1327f Ignore redundant_clone lint on test testing clone
    • 867763b Release 1.0.68
    • c0a87d0 Opt out -Zrustdoc-scrape-examples on docs.rs
    • 1cc707b Release 1.0.67
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies rust 
    opened by dependabot[bot] 0
  • Bump actions/cache from 3.2.3 to 3.2.4 in /.github/workflows

    Bump actions/cache from 3.2.3 to 3.2.4 in /.github/workflows

    Bumps actions/cache from 3.2.3 to 3.2.4.

    Release notes

    Sourced from actions/cache's releases.

    v3.2.4

    What's Changed

    New Contributors

    Full Changelog: https://github.com/actions/cache/compare/v3...v3.2.4

    Changelog

    Sourced from actions/cache's changelog.

    3.2.3

    • Support cross os caching on Windows as an opt-in feature.
    • Fix issue with symlink restoration on Windows for cross-os caches.

    3.2.4

    • Added option to fail job on cache miss.
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 0
  • Bump structopt from 0.3.23 to 0.3.26

    Bump structopt from 0.3.23 to 0.3.26

    ⚠️ Dependabot is rebasing this PR ⚠️

    Rebasing might not happen immediately, so don't worry if this takes some time.

    Note: if you make any changes to this PR yourself, they will take precedence over the rebase.


    Bumps structopt from 0.3.23 to 0.3.26.

    Changelog

    Sourced from structopt's changelog.

    v0.3.25 (2021-10-18)

    • Fix duplication of aliases in subcommands #504

    v0.3.25 (2021-10-18)

    • No changes
    Commits
    • 97e92a3 v0.3.26
    • 2bdd6b4 Clarification on maintenance since clap v3 is out
    • 2736281 Upgrade heck
    • 358cccf [docs] Add output to all examples
    • 4c1a8fc Link to the clap API in the documentation that says all clap methods can be used
    • ffd4772 Typo
    • da1fff8 v0.3.25
    • e83b0fc Merge branch 'master' of github.com:TeXitoi/structopt
    • 6dc2963 v0.4.17
    • ddb51cb Fix duplication of aliases in subcommands
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies rust 
    opened by dependabot[bot] 0
  • Bump syn from 1.0.103 to 1.0.107

    Bump syn from 1.0.103 to 1.0.107

    ⚠️ Dependabot is rebasing this PR ⚠️

    Rebasing might not happen immediately, so don't worry if this takes some time.

    Note: if you make any changes to this PR yourself, they will take precedence over the rebase.


    Bumps syn from 1.0.103 to 1.0.107.

    Release notes

    Sourced from syn's releases.

    1.0.107

    • Opt out of -Zrustdoc-scrape-examples on docs.rs for now

    1.0.106

    • Documentation improvements

    1.0.105

    • Improve parse errors related to dyn and impl type syntax (#1245)

    1.0.104

    • Add PathArguments::is_none()
    Commits
    • 4168f6b Release 1.0.107
    • d8690f2 Opt out -Zrustdoc-scrape-examples on docs.rs
    • 5306cde Release 1.0.106
    • 6db337c Update build status badge
    • 876a605 Merge pull request #1251 from dtolnay/instaloop
    • 65e0e42 Fix invalid use of insta snapshot inside a loop
    • 1d09024 Update test suite to nightly-2022-12-03
    • 998e863 Release 1.0.105
    • 02e2a21 Merge pull request #1247 from dtolnay/punctdrop
    • 9113ad0 Help infer may_dangle on type parameter of Punctuated iterator Drop impls
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies rust 
    opened by dependabot[bot] 0
  • Bump actions/cache from 3.2.4 to 3.2.5 in /.github/workflows

    Bump actions/cache from 3.2.4 to 3.2.5 in /.github/workflows

    Bumps actions/cache from 3.2.4 to 3.2.5.

    Release notes

    Sourced from actions/cache's releases.

    v3.2.5

    What's Changed

    New Contributors

    Full Changelog: https://github.com/actions/cache/compare/v3...v3.2.5

    Changelog

    Sourced from actions/cache's changelog.

    3.2.4

    • Added option to fail job on cache miss.

    3.2.5

    • Added fix to prevent from setting MYSYS environment variable globally.
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 0
  • Bump proc-macro2 from 1.0.47 to 1.0.51

    Bump proc-macro2 from 1.0.47 to 1.0.51

    Bumps proc-macro2 from 1.0.47 to 1.0.51.

    Release notes

    Sourced from proc-macro2's releases.

    1.0.51

    • Implement rustc's limit on the number of # used for delimiting a raw string literal: 255 (#364)

    1.0.50

    • Implement Hash for proc_macro2::LineColumn (#362)

    1.0.49

    • Opt out of -Zrustdoc-scrape-examples on docs.rs for now

    1.0.48

    • Documentation improvements
    Commits
    • bc369f0 Release 1.0.51
    • ec804f1 Merge pull request #364 from dtolnay/hashes
    • dffd53c Reduce max hash in raw strings to 255
    • f0a3490 Add raw string literal test cases
    • 3b90e7d Ignore items_after_statements pedantic clippy lint
    • bce0e5f Consistently use Self in the return of From impls
    • 3915aee Speed up cargo fuzz CI job
    • 94c7519 Release 1.0.50
    • f01da43 Merge pull request #362 from dtolnay/hashlinecolumn
    • d4c564b Implement Hash for LineColumn
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies rust 
    opened by dependabot[bot] 0
  • Add support for

    Add support for "unsigned" numeric fields

    Hi, I just gave this project a try to generate DB models for an existing database. The database uses unsigned integers on may columns. Those get typed (for example) as i32 where it should be u32.

    I came accross https://github.com/Wulf/dsync/blob/12979e00998635291ecaf721cf6bc4282d9808ee/src/parser.rs (but there is no panic, or message visible when running dsync.

    The resulting problem is, that all models fail to derive Insertable and AsChangeset.

    trait bound `i32: diesel::Expression` is not satisfied
    

    For example this table

    diesel::table! {
        aliases (id) {
            id -> Unsigned<Integer>,
            aliasname -> Varchar,
            mainname -> Varchar,
        }
    }
    

    yields with dsync:

    #[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Identifiable)]
    #[diesel(table_name=aliases, primary_key(id))]
    pub struct Aliase {
        pub id: i32,
        pub aliasname: String,
        pub mainname: String,
    }
    

    And with https://github.com/abbychau/diesel_cli_ext (where it works):

    #[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Identifiable)]
    #[diesel(table_name = aliases)]
    pub struct Aliase {
        pub id: u32,
        pub aliasname: String,
        pub mainname: String,
    }
    
    opened by longsleep 0
  • Use a Trait to organize functions

    Use a Trait to organize functions

    Hey, one of the creators of lemmy here, this looks like a really interesting project that could help us. We have a lot of tables, and generating a lot of the simpler Crud-type functions in code would make this really useful.

    Instead of pub struct UpdateTodo and exporting that, I highly recommend creating a trait. Here's what we do in our code:

    pub trait Crud {
      type Form;
      type IdType; // We use diesel-newtypes to make sure all the Ids are unit structs, to make sure people aren't using a `PostId` when they should be using a `CommentId` for example... using `i32` can be dangerous.
      fn create(conn: &mut Connection, form: &Self::Form) -> Result<Self, Error>
        where Self: Sized;
      fn read(conn: &mut Connection, id: Self::IdType) -> Result<Self, Error> 
      ...
    

    Then your generated code would be:

    impl Crud for XXX {
      type Form = XXXForm;
      fn read(...
    

    And people could easily import Crud to get all the functions.

    opened by dessalines 6
Owner
Haris
Haris
Static-checked parsing of regexes into structs

Statically-checked regex parsing into structs. This avoids common regex pitfalls like Off by one capture indexes Trying to get nonexistent captures De

Andrew Baxter 4 Dec 18, 2022
Generate SUMMARY.md files based on your book's file structure

mdbook-autosummary Generate a SUMMARY.md for your mdBook based on your folder structure! Warning The implementation is hacky and has several limitatio

Hyper 3 Sep 30, 2023
A query-building & utility crate for SurrealDB and its SQL querying language that aims to be simple

Surreal simple querybuilder A simple query-builder for the Surreal Query Language, for SurrealDB. Aims at being simple to use and not too verbose firs

Thibault H 11 Dec 30, 2022
A library for extracting #[no_mangle] pub extern "C" functions (https://docs.rust-embedded.org/book/interoperability/rust-with-c.html#no_mangle)

A library for extracting #[no_mangle] pub extern "C" functions In order to expose a function with C binary interface for interoperability with other p

Dmitrii - Demenev 0 Feb 17, 2022
A Rust crate providing utility functions and macros.

介绍 此库提供四类功能:异常处理、http post收发对象、格式转换、语法糖。 在 Cargo.toml 里添加如下依赖项 [dependencies.xuanmi_base_support] git = "https://github.com/taiyi-research-institute/x

null 17 Mar 22, 2023
Functions for mapping plaintexts to a u64 while preserving sort order

ore_encoding.rs This is a companion package to ore.rs that can generate and manipulate u64 plaintexts before they are encrypted by ore.rs. Being able

CipherStash 2 Dec 14, 2022
proc-macro to help with using surrealdb's custom functions

SurrealDB Functions This is a proc-macro crate that given a path to a .surql file or a folder of .surql files, will parse DEFINE FUNCTION fn::s inside

Aly 5 Jul 30, 2023
Generate voxel block meshes in Rust.

block-mesh Fast algorithms for generating voxel block meshes. Two algorithms are included: visible_block_faces: very fast but suboptimal meshes greedy

Duncan 89 Dec 24, 2022
A Matrix bot which can generate "This Week in X" like blog posts

hebbot A Matrix bot which can help to generate periodic / recurrent summary blog posts (also known as "This Week in X"). The bot was inspired by twim-

Häcker Felix 43 Dec 17, 2022
This crate allows to generate a flat binary with the memory representation of an ELF.

flatelf Library This crate allows to generate a flat binary with the memory representation of an ELF. It also allows to generate a FLATELF with the fo

Roi Martin 3 Sep 29, 2022
A procedural macro to generate a new function implementation for your struct.

Impl New ?? A procedural macro to generate a new function implementation for your struct. ?? Add to your project Add this to your Cargo.toml: [depende

Mohammed Alotaibi 4 Sep 8, 2023
This is a lightweight audio-video player built in Rust using FFmpeg libraries. It demonstrates the usage of FFmpeg with Rust to play back video files.

FFmpeg Rust Video Player This is a lightweight audio-video player built in Rust using FFmpeg libraries. It demonstrates the usage of FFmpeg with Rust

Jenin Sutradhar 3 Apr 10, 2024
Rust command-line tool to encrypt and decrypt files or directories with age

Bottle A Rust command-line tool that can compress and encrypt (and decrypt and extract) files or directories using age, gzip, and tar. Bottle has no c

Sam Schlinkert 1 Aug 1, 2022
CLI program written in Rust to anonymize DICOM files

dicom-anonymizer CLI program written in Rust to anonymize DICOM files anonymizer 0.1.0 Domenic Melcher USAGE: anonymizer [OPTIONS] <FILE> ARGS:

Domenic Melcher 2 May 30, 2022
A simple path traversal checker made with Rust. Useful for APIs that serve dynamic files.

Path trav A simple path traversal checker made with Rust. Useful for APIs that serve dynamic files. Note: this is a security tool. If you see somethin

Gátomo 3 Nov 21, 2022
Rust library for concurrent data access, using memory-mapped files, zero-copy deserialization, and wait-free synchronization.

mmap-sync mmap-sync is a Rust crate designed to manage high-performance, concurrent data access between a single writer process and multiple reader pr

Cloudflare 97 Jun 26, 2023
A benchmark of Rust/serde deserializers on configuration files

This program compares the time some serde deserializers take to deserialize some string into a configuration-like struct deriving Deserialize. The ben

Denys Séguret 4 Oct 30, 2023
Create archives of files within Garry's Mod

gm_zip Create archives of files within Garry's Mod. Note: The scope of this module only works accross the gmod installation files e.g from GarrysMod/g

Earu 9 Oct 25, 2022
A tool and library to losslessly join multiple .mp4 files shot with same camera and settings

mp4-merge A tool and library to losslessly join multiple .mp4 files shot with same camera and settings. This is useful to merge multiple files that ar

Gyroflow 7 Jan 2, 2023