Thanks for your interest in contributing to sql-composer! We very much look forward to your suggestions, bug reports, and pull requests.
Have a look at our issue tracker. If you can't find an issue (open or closed) describing your problem (or a very similar one) there, please open a new issue with the following details:
- Which versions of Rust and sql-composer are you using?
- Which feature flags are you using?
- What are you trying to accomplish?
- What is the full error you are seeing?
- How can we reproduce this?
- Please quote as much of your code as needed to reproduce (best link to a public repository or Gist)
- Please post as much of your database schema as is relevant to your error
Thank you! We'll try to respond as quickly as possible.
If you can't find an issue (open or closed) describing your idea on our issue tracker, open an issue. Adding answers to the following questions in your description is +1:
- What do you want to do, and how do you expect sql-composer to support you with that?
- How might this be added to sql-composer?
- What are possible alternatives?
- Are there any disadvantages?
Thank you! We'll try to respond as quickly as possible.
-
Install Rust using rustup, which allows you to easily switch between Rust versions. sql-composer currently supports Rust Stable, Nightly, Rust Beta.
-
Install the system libraries needed to interface with the database systems you wish to use.
These are the same as when compiling sql-composer. It's generally a good idea to install all drivers so you can run all tests locally.
-
Clone this repository and open it in your favorite editor.
-
Local override of database ports or passwords
If you wish to change the local database ports, override PG_DATABASE_PORT and MYSQL_DATABASE_PORT via environment variables or edit the values in the
.env
file.Use MYSQL_DATABASE_PASS and PG_DATABASE_PASS to override the default passwords. If the containers have already been run, changing the password will not affect the container. Shut down the container and delete the db/* files to clear the old password values.
# delete database storage files to force re-initialization of database sudo rm -rf db/*
-
Use docker-compose to launch containers with databases for testing.
docker-compose up
will download and run containers for mysql and postgresql. The internal database ports (3306 or 5432) will be forwarded to ports on the host as determined by MYSQL_DATABASE_PORT and PG_DATABASE_PORT environment variables. Default port values are defined in the.env
file in the root of the crate.The containers will be named
sql_composer_mysql
andsql_composer_postgres
. Each will have an empty database namedsql_composer
owned by userrunner
The containers will run in the foreground until interrupted with
ctrl-c
.docker-compose up # launch both postgresql and mysql docker-compose up mysql # launch only mysql docker-compose up postgresql # launch only postgresql
db storage files will be cached in the
./db/
directory. These files can be deleted to force the database to re-initialize on the next run ofdocker-compose up
-
Now, try running the test suite to confirm everything works for you locally by executing
cargo test
. (Initially, this will take a while to compile everything.) Each database is hidden behind a feature flag.Run a test against all the databases with the
--all-features
flagIndividual features are not supported at the top level workspace, they can only be enabled when building within the subprojects. See: rust-lang/cargo#4942
The features are listed in the
[features]
section ofCargo.toml
of the individual projects.- dbd-mysql
- dbd-rusqlite
- dbd-postgres
- composer-serde (for sql-composer only)
cargo test # run non-db and sqlite tests only cargo test --all-features # compile for all dbs and run all tests. # individual features are only supported in the sub-projects # sql-composer: (cd sql-composer && cargo test --features dbd-mysql) # compile for mysql and run mysql tests. (cd sql-composer && cargo test --features dbd-postgres) # compile for postgresql and run postgresql tests. (cd sql-composer && cargo test --features dbd-rusqlite) # compile for rusqlite and run rusqlite tests. (cd sql-composer && cargo test --features composer-serde) # compile for serde and run serde tests. # multiple features are passed as single quoted string of space separated features (cd sql-composer && cargo test --features "composer-serde dbd-mysql") # compile for serde and mysql # sql-composer-cli: (cd sql-composer-cli && cargo test --features dbd-mysql) # compile for mysql and run mysql tests. (cd sql-composer-cli && cargo test --features dbd-postgres) # compile for postgresql and run postgresql tests. (cd sql-composer-cli && cargo test --features dbd-rusqlite) # compile for rusqlite and run rusqlite tests.
We follow the Rust Style Guide, enforced using rustfmt. To run rustfmt tests locally:
-
Use rustup to set rust toolchain to the version specified in the rust-toolchain file.
-
Install the rustfmt and clippy by running
rustup component add rustfmt-preview rustup component add clippy-preview
-
Run clippy using cargo from the root of your sql-composer repo.
cargo clippy
Each PR needs to compile without warning.
-
Run rustfmt using cargo from the root of your sql-composer repo.
To see changes that need to be made, run
cargo fmt --all -- --check
If all code is properly formatted (e.g. if you have not made any changes), this should run without error or output. If your code needs to be reformatted, you will see a diff between your code and properly formatted code. If you see code here that you didn't make any changes to then you are probably running the wrong version of rustfmt. Once you are ready to apply the formatting changes, run
cargo fmt --all
You won't see any output, but all your files will be corrected.
You can also use rustfmt to make corrections or highlight issues in your editor. Check out their README for details.