Skip to content

Commit ada9048

Browse files
authored
Merge pull request #32 from zerodaycode/development
Merge last changes from development to main
2 parents 33b971b + fbf494c commit ada9048

31 files changed

Lines changed: 192 additions & 105 deletions

.github/workflows/code-coverage.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
name: Linux CI && Code Coverage
1+
name: Linux CI
22

33
on:
44
push:
5+
branches: 'development'
56
tags:
67
- 'v[0-9]+.[0-9]+.[0-9]+'
78
- 'v[0-9]+.[0-9]+.[0-9]+rc[0-9]+'
@@ -43,6 +44,7 @@ jobs:
4344

4445
- name: Run tests
4546
run: |
47+
cargo test initialize_sql_server_docker_instance -p tests --all-features --no-fail-fast -- --show-output --nocapture --include-ignored
4648
cargo test --all-features --no-fail-fast --target=x86_64-unknown-linux-gnu -- --show-output --test-threads=1
4749
4850
- name: Waking up docker

.github/workflows/code-quality.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
strategy:
4646
fail-fast: false
4747
matrix:
48-
crate: [canyon_connection, canyon_crud, canyon_macros, canyon_observer, canyon_observer, canyon_sql]
48+
crate: [canyon_connection, canyon_crud, canyon_macros, canyon_observer, canyon_sql]
4949
steps:
5050
- uses: actions/checkout@v3
5151

.github/workflows/continuous-integration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Continuous Integration
22

33
on:
44
push:
5-
branches: 'main'
5+
branches: '*'
66
pull_request:
7-
branches: 'main'
7+
branches: '*'
88

99
env:
1010
CARGO_TERM_COLOR: always

CONTRIBUTING.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Contributing to CONTRIBUTING.md
1+
# Contributing to Canyon-SQL
22

3-
First off, thanks for taking the time to contribute!
3+
First off, thanks for taking the time to contribute!
44

55
All types of contributions are encouraged and valued. See the [Table of Contents](#table-of-contents) for different ways to help and details about how this project handles them. Please make sure to read the relevant section before making your contribution. It will make it a lot easier for us maintainers and smooth out the experience for all involved. The community looks forward to your contributions.
66

@@ -24,15 +24,13 @@ All types of contributions are encouraged and valued. See the [Table of Contents
2424
- [Commit Messages](#commit-messages)
2525
- [Join The Project Team](#join-the-project-team)
2626

27-
2827
## Code of Conduct
2928

3029
This project and everyone participating in it is governed by the
3130
[CONTRIBUTING.md Code of Conduct](blob/master/CODE_OF_CONDUCT.md).
3231
By participating, you are expected to uphold this code. Please report unacceptable behavior
3332
to <>.
3433

35-
3634
## I Have a Question
3735

3836
> If you want to ask a question, we assume that you have read the available [Documentation](https://github.com/zerodaycode/canyon-book).
@@ -47,16 +45,14 @@ If you then still feel the need to ask a question and need clarification, we rec
4745

4846
We will then take care of the issue as soon as possible.
4947

50-
51-
5248
## I Want To Contribute
5349

54-
> ### Legal Notice
50+
### Legal Notice
51+
5552
> When contributing to this project, you must agree that you have authored 100% of the content, that you have the necessary rights to the content and that the content you contribute may be provided under the project license.
5653
5754
### Reporting Bugs
5855

59-
6056
#### Before Submitting a Bug Report
6157

6258
A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible.
@@ -72,12 +68,10 @@ A good bug report shouldn't leave others needing to chase you up for more inform
7268
- Possibly your input and the output
7369
- Can you reliably reproduce the issue? And can you also reproduce it with older versions?
7470

75-
7671
#### How Do I Submit a Good Bug Report?
7772

7873
> You must never report security related issues, vulnerabilities or bugs including sensitive information to the issue tracker, or elsewhere in public. Instead sensitive bugs must be sent by email to <>.
7974
80-
8175
We use GitHub issues to track bugs and errors. If you run into an issue with the project:
8276

8377
- Open an [Issue](/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
@@ -93,7 +87,7 @@ Once it's filed:
9387

9488
### Suggesting Enhancements
9589

96-
If you want to suggest an enhacement or new feature for the project, please [open a new issue](/issues) describing what you desire to improve, and, potentially, how you plan to contribute to the project.
90+
If you want to suggest an enhancement or new feature for the project, please [open a new issue](/issues) describing what you desire to improve, and, potentially, how you plan to contribute to the project.
9791

9892
#### Before Submitting an Enhancement
9993

@@ -112,6 +106,6 @@ Enhancement suggestions are tracked as [GitHub issues](/issues).
112106
- You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux.
113107
- **Explain why this enhancement would be useful** to most CONTRIBUTING.md users. You may also want to point out the other projects that solved it better and which could serve as inspiration.
114108

115-
116109
## Attribution
110+
117111
This guide is based on the **contributing.md**. [Make your own](https://contributing.md/)!

README.md

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
**A full written in `Rust` ORM for multiple databases.**
44

5-
- [![Linux CI](https://github.com/zerodaycode/Canyon-SQL/actions/workflows/code-coverage.yml/badge.svg)](https://github.com/zerodaycode/Canyon-SQL/actions/workflows/code-coverage.yml)
5+
- ![crates.io](https://img.shields.io/crates/v/canyon_sql.svg)
66
- [![Code Coverage Measure](https://zerodaycode.github.io/Canyon-SQL/badges/flat.svg)](https://zerodaycode.github.io/Canyon-SQL)
7+
- [![Linux CI](https://github.com/zerodaycode/Canyon-SQL/actions/workflows/code-coverage.yml/badge.svg)](https://github.com/zerodaycode/Canyon-SQL/actions/workflows/code-coverage.yml)
78
- [![Tests on macOS](https://github.com/zerodaycode/Canyon-SQL/actions/workflows/macos-tests.yml/badge.svg)](https://github.com/zerodaycode/Canyon-SQL/actions/workflows/macos-tests.yml)
89
- [![Tests on Windows](https://github.com/zerodaycode/Canyon-SQL/actions/workflows/windows-tests.yml/badge.svg)](https://github.com/zerodaycode/Canyon-SQL/actions/workflows/windows-tests.yml)
910

@@ -27,8 +28,8 @@ You can read it [by clicking this link](https://zerodaycode.github.io/canyon-boo
2728
- Use of multiple datasources. You can query multiple databases at the same time, even different ones!. This means that you will be able to query concurrently
2829
a `PostgreSQL` database and an `SqlServer` one in the same project.
2930
- Is macro based. With a few annotations and a configuration file, you are ready to write your data access.
30-
- Allows **migrations**. `Canyon-SQL` comes with a *god-mode* that will manage every table on your database for you. You can modify in `Canyon` code your tables internally, altering columns, setting up constraints...
31-
Also, in the future, we have plans to allow you to manipulate the whole server, like creating databases, altering configurations... everything, but in a programatically approach with `Canyon`!
31+
- Allows **migrations**. `Canyon-SQL` comes with a *god-mode* that will manage every table on your database for you. You can modify in `Canyon` code your tables internally, altering columns, setting up constraints...
32+
Also, in the future, we have plans to allow you to manipulate the whole server, like creating databases, altering configurations... everything, but in a programmatically approach with `Canyon`!
3233

3334
## Supported databases
3435

@@ -40,3 +41,93 @@ Also, in the future, we have plans to allow you to manipulate the whole server,
4041
Every crate listed above is an `async` based crate, in line with the guidelines of the `Canyon-SQL` design.
4142

4243
There are plans for include more databases engines.
44+
45+
## Better by example
46+
47+
Let's take a look to see how the `Canyon` code looks like!
48+
49+
### The classical SELECT * FROM {table_name}
50+
51+
```rust
52+
let find_all_result: Result<Vec<League>, Box<dyn Error + Send + Sync>> = League::find_all().await;
53+
54+
// Connection doesn't return an error
55+
assert!(find_all_result.is_ok());
56+
// We retrieved elements from the League table
57+
assert!(!find_all_result.unwrap().is_empty());
58+
```
59+
60+
### Performing a search over the primary key column
61+
62+
```rust
63+
let find_by_pk_result: Result<Option<League>, Box<dyn Error + Send + Sync>> = League::find_by_pk(&1).await;
64+
65+
assert!(find_by_pk_result.as_ref().unwrap().is_some());
66+
67+
let some_league = find_by_pk_result.unwrap().unwrap();
68+
assert_eq!(some_league.id, 1);
69+
assert_eq!(some_league.ext_id, 100695891328981122_i64);
70+
assert_eq!(some_league.slug, "european-masters");
71+
assert_eq!(some_league.name, "European Masters");
72+
assert_eq!(some_league.region, "EUROPE");
73+
assert_eq!(
74+
some_league.image_url,
75+
"http://static.lolesports.com/leagues/EM_Bug_Outline1.png"
76+
);
77+
```
78+
79+
Note the leading reference on the `find_by_pk(...)` parameter. This associated function receives an `&dyn QueryParameter<'_>` as argument, not a value.
80+
81+
### Building more complex queries
82+
83+
For exemplify the capabilities of `Canyon`, we will use `SelectQueryBuilder<T>`, which implements the `QueryBuilder<T>` trait
84+
for build a more complex where, filteing data and joining tables.
85+
86+
```rust
87+
let mut select_with_joins = LeagueTournament::select_query();
88+
select_with_joins
89+
.inner_join("tournament", "league.id", "tournament.league_id")
90+
.left_join("team", "tournament.id", "player.tournament_id")
91+
.r#where(LeagueFieldValue::id(&7), Comp::Gt)
92+
.and(LeagueFieldValue::name(&"KOREA"), Comp::Eq)
93+
.and_values_in(LeagueField::name, &["LCK", "STRANGER THINGS"]);
94+
// NOTE: We don't have in the docker the generated relationships
95+
// with the joins, so for now, we are just going to check that the
96+
// generated SQL by the SelectQueryBuilder<T> is the spected
97+
assert_eq!(
98+
select_with_joins.read_sql(),
99+
"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) "
100+
)
101+
```
102+
103+
> 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.
104+
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
105+
able with some column in the database, the program will panic.
106+
107+
## More examples
108+
109+
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
110+
111+
## Contributing to CANYON-SQL
112+
113+
First of all, thanks for take in consideration help us with the project.
114+
You can take a look to our [templated guide]((./CONTRIBUTING.md)).
115+
116+
But, to summarize:
117+
118+
- Take a look at the already opened issues, to see if already exists of it's someone already taking care about solving it. Even tho, you can enter to participate and explain your point of view, or even help to accomplish the task
119+
- Make a fork of `Canyon-SQL`
120+
- If you opened an issue, create a branch from the base branch of the repo (that's the default), and point it to your fork
121+
- After complete your changes, open a `PR` to the default branch. Fill the template provided in the best way you're able to do it
122+
- Wait for the approval. In most of cases, a test over the feature will be required before approve your changes
123+
124+
## What about the tests?
125+
126+
Typically in `Canyon`, isolated unit tests are written as doc-tests, and the integration ones are under the folder `./tests`
127+
128+
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.
129+
130+
- You will need Docker installed in the target machine
131+
- If you have Docker, and `Canyon-SQL` cloned of forked, you can run our docker-compose file `(docker/docker-compose.yml)`, which will initialize a `PostgreSQL` database and will put content on it to make the tests able to work.
132+
- Finally, some tests runs against `MSSQL`. We didn't found a nice way of inserting data directly when the Docker wakes up, but instead, we run a very special test located at `tests/crud/mod.rs`, that is named `initialize_sql_server_docker_instance`. When you run this one, initial data will be inserted into the tables that are created when this test run.
133+
(If you know a better way of doing this, please, open a issue to let us know it, and improve this process!)

canyon_connection/src/canyon_database_connector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl DatabaseConnection {
6161

6262
tokio::spawn(async move {
6363
if let Err(e) = new_connection.await {
64-
eprintln!("An error occured while trying to connect to the PostgreSQL database: {e}");
64+
eprintln!("An error occurred while trying to connect to the PostgreSQL database: {e}");
6565
}
6666
});
6767

@@ -96,7 +96,7 @@ impl DatabaseConnection {
9696
// TcpStream to connect to the server.
9797
let tcp = TcpStream::connect(config.get_addr())
9898
.await
99-
.expect("Error instanciating the SqlServer TCP Stream");
99+
.expect("Error instantiating the SqlServer TCP Stream");
100100

101101
// We'll disable the Nagle algorithm. Buffering is handled
102102
// internally with a `Sink`.

canyon_connection/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ lazy_static! {
4040
/// in the configuration file.
4141
///
4242
/// This avoids Canyon to create a new connection to the database on every query, potentially avoiding bottlenecks
43-
/// derivated from the instanciation of that new conn every time.
43+
/// derivated from the instantiation of that new conn every time.
4444
///
4545
/// Note: We noticed with the integration tests that the [`tokio_postgres`] crate (PostgreSQL) is able to work in an async environment
4646
/// with a new connection per query without no problem, but the [`tiberius`] crate (MSSQL) sufferes a lot when it has continuous

canyon_crud/src/bounds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ where
4545
/// and convert it to a tuple struct formed by the column name as an String,
4646
/// and the dynamic value of the [`QueryParameter<'_>`] trait object contained
4747
/// inside the variant requested,
48-
/// enabling a convertion of that value into something
48+
/// enabling a conversion of that value into something
4949
/// that can be part of an SQL query.
5050
///
5151
///
@@ -229,7 +229,7 @@ pub trait QueryParameter<'a>: std::fmt::Debug + Sync + Send {
229229
/// This implementation is necessary because of the generic amplitude
230230
/// of the arguments of the [`Transaction::query`], that should work with
231231
/// a collection of [`QueryParameter<'a>`], in order to allow a workflow
232-
/// that is not dependant of the specific type of the argument that holds
232+
/// that is not dependent of the specific type of the argument that holds
233233
/// the query parameters of the database connectors
234234
impl<'a> IntoSql<'a> for &'a dyn QueryParameter<'a> {
235235
fn into_sql(self) -> ColumnData<'a> {

canyon_crud/src/crud.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ mod sqlserver_query_launcher {
210210
where
211211
Z: AsRef<[&'a dyn QueryParameter<'a>]> + Sync + Send + 'a,
212212
{
213-
// Re-generate de insert statement to adecuate it to the SQL SERVER syntax to retrieve the PK value(s) after insert
213+
// Re-generate de insert statement to adequate it to the SQL SERVER syntax to retrieve the PK value(s) after insert
214214
if stmt.contains("RETURNING") {
215215
let c = stmt.clone();
216216
let temp = c

canyon_crud/src/query_elements/operators.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ pub enum Comp {
99
Eq,
1010
/// Operator "!=" not equals
1111
Neq,
12-
/// Operator ">" greather than value
12+
/// Operator ">" greater than value
1313
Gt,
14-
/// Operator ">=" greather or equals than value
14+
/// Operator ">=" greater or equals than value
1515
GtEq,
1616
/// Operator "<" less than value
1717
Lt,

0 commit comments

Comments
 (0)