CANYON-SQL

A full written in Rust ORM for multiple databases.

Canyon-SQL is a high level abstraction for working with multiple databases concurrently. Is build on top of the async language features to provide a high speed, high performant library to handling data access for consumers.

Early stage disclaimer

The library it's still on a early stage state. Any contrib via fork + PR it's really appreciated. Currently we are involved in a really active development on the project.

Full documentation resources

There is a work-in-progress web page, build with mdBook containing the official documentation. Here is where you will find all the technical documentation for Canyon-SQL. You can read it by clicking this link

Most important features

Supported databases

Canyon-SQL currently has support for work with the following databases:

Every crate listed above is an async based crate, in line with the guidelines of the Canyon-SQL design.

There are plans for include more databases engines.

Better by example

Let's take a look to see how the Canyon code looks like!

The classical SELECT * FROM {table_name}

```rust let findallresult: Result, Box> = League::find_all().await;

// Connection doesn't return an error assert!(findallresult.isok()); // We retrieved elements from the League table assert!(!findallresult.unwrap().isempty()); ```

Performing a search over the primary key column

```rust let findbypkresult: Result, Box> = League::findby_pk(&1).await;

assert!(findbypkresult.asref().unwrap().is_some());

let someleague = findbypkresult.unwrap().unwrap(); asserteq!(someleague.id, 1); asserteq!(someleague.extid, 100695891328981122i64); asserteq!(someleague.slug, "european-masters"); asserteq!(someleague.name, "European Masters"); asserteq!(someleague.region, "EUROPE"); asserteq!( someleague.imageurl, "http://static.lolesports.com/leagues/EMBug_Outline1.png" ); ```

Note the leading reference on the find_by_pk(...) parameter. This associated function receives an &dyn QueryParameter<'_> as argument, not a value.

Building more complex queries

For exemplify the capabilities of Canyon, we will use SelectQueryBuilder<T>, which implements the QueryBuilder<T> trait for build a more complex where, filteing data and joining tables.

rust let mut select_with_joins = LeagueTournament::select_query(); select_with_joins .inner_join("tournament", "league.id", "tournament.league_id") .left_join("team", "tournament.id", "player.tournament_id") .r#where(LeagueFieldValue::id(&7), Comp::Gt) .and(LeagueFieldValue::name(&"KOREA"), Comp::Eq) .and_values_in(LeagueField::name, &["LCK", "STRANGER THINGS"]); // NOTE: We don't have in the docker the generated relationships // with the joins, so for now, we are just going to check that the // generated SQL by the SelectQueryBuilder<T> is the spected assert_eq!( select_with_joins.read_sql(), "SELECT * FROM league INNER JOIN tournament ON league.id = tournament.league_id LEFT JOIN team ON tournament.id = player.tournament_id WHERE id > $1 AND name = $2 AND name IN ($2, $3) " )

Note: For now, when you use joins, you will need to create a new model with the columns in both tables (in case that you desire the data in such columns), but just follows the habitual process with the CanyonMapper. It will try to retrieve the data for every field declared. If you don't declare a field that is in the open clause, in this case (*), that field won't be retrieved. No problem. But if you have fields that aren't map able with some column in the database, the program will panic.

More examples

If you want to see more examples, you can take a look into the tests folder, at the root of this repository. Every available database operation is tested there, so you can use it to find the usage of the described operations in the documentation mentioned above

Contributing to CANYON-SQL

First of all, thanks for take in consideration help us with the project. You can take a look to our templated guide.

But, to summarize:

What about the tests?

Typically in Canyon, isolated unit tests are written as doc-tests, and the integration ones are under the folder ./tests

If you want to run the tests (because this is the first thing that you want to do after fork the repo), a couple of things have to be considered before.