Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c8467ef
Corrected the code coverage workflow. Updated the CHANGELOG.md
TheRustifyer Apr 13, 2023
aee3e23
#feature - Created two new cfg properties, for split the code per sup…
TheRustifyer Apr 14, 2023
2812902
#fix - Small doc typos and reordering trait impl members
TheRustifyer Apr 14, 2023
f49f5d6
#wip - Rewriting with conditinal compilation. Reworking the workspace
TheRustifyer Apr 14, 2023
5723243
WIP - Introducing CanyonRows
TheRustifyer Apr 15, 2023
32e611a
WIP - Whole rework of the workspace, more cfg's
TheRustifyer Apr 16, 2023
41843a4
#wip - Addressing the issues of the CanyonMemory module to the new so…
TheRustifyer Apr 17, 2023
ad9e1ea
#wip - Addressing the issues of the Handler module to the new source …
TheRustifyer Apr 18, 2023
6d9c663
#wip - Reaching the goal of the conditional compilation by database c…
TheRustifyer Apr 18, 2023
c0b0dd7
First compilable version since the rework for the conditional compila…
TheRustifyer Apr 18, 2023
2a7d64f
Setting up the missing parts for msssql databases
TheRustifyer Apr 18, 2023
e09557d
Adecuating the doc-tests to the conditional compilation
TheRustifyer Apr 18, 2023
5d99d49
Applying format with rustfmt
TheRustifyer Apr 18, 2023
f6c4408
Discarded the integrated auth cfg feature flag, it will be included d…
TheRustifyer Apr 18, 2023
c7893e3
Addressing issues on the macros with the new code structure - [select…
TheRustifyer Apr 19, 2023
b576757
Addressing issues on the macros with the new code structure - [insert…
TheRustifyer Apr 19, 2023
8558c98
WIP - Reworked the way of how we was thinking about our features. Try…
TheRustifyer Apr 19, 2023
51b97d5
Moved the IT to initialize MSSQL databases to its own crate
TheRustifyer Apr 20, 2023
cc9a3ef
A bunch of major changes to stabilize the new conditional APIs into t…
TheRustifyer Apr 20, 2023
f77aa14
All the APIs stabilized for making use of the conditional compilation…
TheRustifyer Apr 20, 2023
8a3decf
Setting up a better version for looking for the Canyon configuration …
TheRustifyer Apr 20, 2023
a6049a1
v0.3.0
TheRustifyer Apr 20, 2023
9735fd4
No IT for Windows and MacOS targets
TheRustifyer Apr 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
rustup override set nightly

- name: Make the USER own the working directory. Installing `gssapi` headers
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
sudo chown -R $USER:$USER ${{ github.workspace }}
sudo apt -y install gcc libgssapi-krb5-2 libkrb5-dev libsasl2-modules-gssapi-mit
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
strategy:
fail-fast: false
matrix:
crate: [canyon_connection, canyon_crud, canyon_macros, canyon_observer, canyon_sql]
crate: [canyon_connection, canyon_crud, canyon_macros, canyon_observer]
steps:
- uses: actions/checkout@v3

Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ jobs:

- name: Run only UNIT tests for Windows
if: ${{ matrix.os == 'windows-latest' }}
run: cargo test --verbose --workspace --target=x86_64-pc-windows-msvc --exclude tests --all-features --no-fail-fast -- --show-output
run: |
cargo test --verbose --workspace --lib --target=x86_64-pc-windows-msvc --all-features --no-fail-fast -- --show-output
cargo test --verbose --workspace --doc --target=x86_64-pc-windows-msvc --all-features --no-fail-fast -- --show-output

- name: Run only UNIT tests for MacOS
if: ${{ matrix.os == 'MacOS-latest' }}
run: cargo test --verbose --workspace --exclude tests --all-features --no-fail-fast -- --show-output
run: |
cargo test --verbose --workspace --lib --all-features --no-fail-fast -- --show-output
cargo test --verbose --workspace --doc --all-features --no-fail-fast -- --show-output
26 changes: 25 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,31 @@ Year format is defined as: `YYYY-m-d`

## [Unreleased]

- Solved a bug in the canyon_entity proc macro that was wiring the incorrect user table name in the migrations
## [0.2.0] - 2023 - 04 - 13

### Feature

- Enabled conditional compilation for the database dependencies of the project.
This caused a major rework in the codebase, but none of the client APIs has been affected.
Now, Canyon-SQL comes with two features, ["postgres", "mssql"].
There's no default features enabled for the project.

## [0.2.0] - 2023 - 04 - 13

### Feature [BREAKING CHANGES]

- The configuration file has been reworked, by providing a whole category dedicated
to the authentication against the database server.
- We removed the database type property, since the database type can be inferred by
the new mandatory auth property
- Included support for the `MSSQL` integrated authentication via the cfg feature `mssql-integrated-auth`

## [0.1.2] - 2023 - 03 - 28

### Update

- Implemented bool types for QueryParameters<'_>.
- Minimal performance improvements

## [0.1.1] - 2023 - 03 - 20

Expand Down
61 changes: 57 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,65 @@
# This is the root Cargo.toml file that serves as manager for the workspace of the project
[package]
name = "canyon_sql"
version.workspace = true
edition.workspace = true

[workspace]
members = [
"canyon_sql",
"canyon_connection",
"canyon_crud",
"canyon_observer",
"canyon_macros",
"canyon_crud",
"canyon_connection",

"tests"
]

[dependencies]
# Project crates
canyon_connection = { workspace = true, path = "canyon_connection" }
canyon_crud = { workspace = true, path = "canyon_crud" }
canyon_observer = { workspace = true, path = "canyon_observer" }
canyon_macros = { workspace = true, path = "canyon_macros" }

# To be marked as opt deps
tokio-postgres = { workspace = true, optional = true }
tiberius = { workspace = true, optional = true }

[workspace.dependencies]
canyon_crud = { version = "0.3.0", path = "canyon_crud" }
canyon_connection = { version = "0.3.0", path = "canyon_connection" }
canyon_observer = { version = "0.3.0", path = "canyon_observer" }
canyon_macros = { version = "0.3.0", path = "canyon_macros" }

tokio = { version = "1.27.0", features = ["full"] }
tokio-util = { version = "0.7.4", features = ["compat"] }
tokio-postgres = { version = "0.7.2", features = ["with-chrono-0_4"] }
tiberius = { version = "0.12.1", features = ["tds73", "chrono", "integrated-auth-gssapi"] }

chrono = { version = "0.4", features = ["serde"] } # Just from TP better?
serde = { version = "1.0.138", features = ["derive"] }

futures = "0.3.25"
indexmap = "1.9.1"
async-std = "1.12.0"
lazy_static = "1.4.0"
toml = "0.7.3"
async-trait = "0.1.68"
walkdir = "2.3.3"
regex = "1.5"

quote = "1.0.9"
proc-macro2 = "1.0.27"

[workspace.package]
version = "0.3.0"
edition = "2021"
authors = ["Alex Vergara<[email protected]>, Gonzalo Busto<[email protected]>"]
documentation = "https://zerodaycode.github.io/canyon-book/"
homepage = "https://github.com/zerodaycode/Canyon-SQL"
readme = "README.md"
license = "MIT"
description = "A Rust ORM and QueryBuilder"

[features]
postgres = ["tokio-postgres", "canyon_connection/postgres", "canyon_crud/postgres", "canyon_observer/postgres", "canyon_macros/postgres"]
mssql = ["tiberius", "canyon_connection/mssql", "canyon_crud/mssql", "canyon_observer/mssql", "canyon_macros/mssql"]
2 changes: 1 addition & 1 deletion bash_aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ alias SqlServerInitializationLinux='cargo test initialize_sql_server_docker_inst


# Publish Canyon-SQL to the registry with its dependencies
alias PublishCanyon='cargo publish -p canyon_connection && cargo publish -p canyon_crud && cargo publish -p canyon_observer && cargo publish -p canyon_macros && cargo publish -p canyon_sql'
alias PublishCanyon='cargo publish -p canyon_connection && cargo publish -p canyon_crud && cargo publish -p canyon_observer && cargo publish -p canyon_macros && cargo publish -p canyon_sql_root'

# Collects the code coverage for the project (tests must run before this)
alias CcEnvVars='export CARGO_INCREMENTAL=0
Expand Down
41 changes: 21 additions & 20 deletions canyon_connection/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
[package]
name = "canyon_connection"
version = "0.2.0"
edition = "2021"
documentation = "https://zerodaycode.github.io/canyon-book/"
homepage = "https://github.com/zerodaycode/Canyon-SQL"
readme = "../README.md"
license = "MIT"
description = "A Rust ORM and QueryBuilder"

version.workspace = true
edition.workspace = true
authors.workspace = true
documentation.workspace = true
homepage.workspace = true
readme.workspace = true
license.workspace = true
description.workspace = true

[dependencies]
tokio = { version = "1.21.2", features = ["full"] }
tokio-util = { version = "0.7.4", features = ["compat"] }
tokio-postgres = { version = "0.7.2", features = ["with-chrono-0_4"] }
futures = "0.3.25"
indexmap = "1.9.1"
tokio = { workspace = true }
tokio-util = { workspace = true }

tiberius = { version = "0.12.1", features = ["tds73", "chrono", "integrated-auth-gssapi"] }
async-std = { version = "1.12.0" }
tokio-postgres = { workspace = true, optional = true }
tiberius = { workspace = true, optional = true }

lazy_static = "1.4.0"
futures = { workspace = true }
indexmap = { workspace = true }
lazy_static = { workspace = true }
toml = { workspace = true }
serde = { workspace = true }
async-std = { workspace = true, optional = true }
walkdir = { workspace = true }

serde = { version = "1.0.138", features = ["derive"] }
toml = "0.7.3"

[features]
mssql-integrated-auth = []

postgres = ["tokio-postgres"]
mssql = ["tiberius", "async-std"]
114 changes: 80 additions & 34 deletions canyon_connection/src/canyon_database_connector.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
use async_std::net::TcpStream;

use serde::Deserialize;

#[cfg(feature = "mssql")]
use async_std::net::TcpStream;
#[cfg(feature = "mssql")]
use tiberius::{AuthMethod, Config};
#[cfg(feature = "postgres")]
use tokio_postgres::{Client, NoTls};

use crate::datasources::DatasourceConfig;

/// Represents the current supported databases by Canyon
#[derive(Deserialize, Debug, Eq, PartialEq, Clone, Copy, Default)]
#[derive(Deserialize, Debug, Eq, PartialEq, Clone, Copy)]
pub enum DatabaseType {
#[default]
#[serde(alias = "postgres", alias = "postgresql")]
#[cfg(feature = "postgres")]
PostgreSql,
#[serde(alias = "sqlserver", alias = "mssql")]
#[cfg(feature = "mssql")]
SqlServer,
}

/// A connection with a `PostgreSQL` database
#[cfg(feature = "postgres")]
pub struct PostgreSqlConnection {
pub client: Client,
// pub connection: Connection<Socket, NoTlsStream>, // TODO Hold it, or not to hold it... that's the question!
}

/// A connection with a `SqlServer` database
#[cfg(feature = "mssql")]
pub struct SqlServerConnection {
pub client: &'static mut tiberius::Client<TcpStream>,
}
Expand All @@ -32,7 +38,9 @@ pub struct SqlServerConnection {
/// process them and generates a pool of 1 to 1 database connection for
/// every datasource defined.
pub enum DatabaseConnection {
#[cfg(feature = "postgres")]
Postgres(PostgreSqlConnection),
#[cfg(feature = "mssql")]
SqlServer(SqlServerConnection),
}

Expand All @@ -44,13 +52,15 @@ impl DatabaseConnection {
datasource: &DatasourceConfig,
) -> Result<DatabaseConnection, Box<(dyn std::error::Error + Send + Sync + 'static)>> {
match datasource.get_db_type() {
#[cfg(feature = "postgres")]
DatabaseType::PostgreSql => {
let (username, password) = match &datasource.auth {
crate::datasources::Auth::Postgres(postgres_auth) => match postgres_auth {
crate::datasources::PostgresAuth::Basic { username, password } => {
(username.as_str(), password.as_str())
}
},
#[cfg(feature = "mssql")]
crate::datasources::Auth::SqlServer(_) => {
panic!("Found SqlServer auth configuration for a PostgreSQL datasource")
}
Expand Down Expand Up @@ -79,6 +89,7 @@ impl DatabaseConnection {
// connection: new_connection,
}))
}
#[cfg(feature = "mssql")]
DatabaseType::SqlServer => {
let mut config = Config::new();

Expand All @@ -88,14 +99,14 @@ impl DatabaseConnection {

// Using SQL Server authentication.
config.authentication(match &datasource.auth {
#[cfg(feature = "postgres")]
crate::datasources::Auth::Postgres(_) => {
panic!("Found PostgreSQL auth configuration for a SqlServer database")
}
crate::datasources::Auth::SqlServer(sql_server_auth) => match sql_server_auth {
crate::datasources::SqlServerAuth::Basic { username, password } => {
AuthMethod::sql_server(username, password)
}
#[cfg(feature = "mssql-integrated-auth")]
crate::datasources::SqlServerAuth::Integrated => AuthMethod::Integrated,
},
});
Expand Down Expand Up @@ -128,19 +139,21 @@ impl DatabaseConnection {
}
}

pub fn postgres_connection(&self) -> Option<&PostgreSqlConnection> {
if let DatabaseConnection::Postgres(conn) = self {
Some(conn)
} else {
None
#[cfg(feature = "postgres")]
pub fn postgres_connection(&self) -> &PostgreSqlConnection {
match self {
DatabaseConnection::Postgres(conn) => conn,
#[cfg(all(feature = "postgres", feature = "mssql"))]
_ => panic!(),
}
}

pub fn sqlserver_connection(&mut self) -> Option<&mut SqlServerConnection> {
if let DatabaseConnection::SqlServer(conn) = self {
Some(conn)
} else {
None
#[cfg(feature = "mssql")]
pub fn sqlserver_connection(&mut self) -> &mut SqlServerConnection {
match self {
DatabaseConnection::SqlServer(conn) => conn,
#[cfg(all(feature = "postgres", feature = "mssql"))]
_ => panic!(),
}
}
}
Expand All @@ -150,27 +163,60 @@ mod database_connection_handler {
use super::*;
use crate::CanyonSqlConfig;

const CONFIG_FILE_MOCK_ALT: &str = r#"
[canyon_sql]
datasources = [
{name = 'PostgresDS', auth = { postgresql = { basic = { username = "postgres", password = "postgres" } } }, properties.host = 'localhost', properties.db_name = 'triforce', properties.migrations='enabled' },
{name = 'SqlServerDS', auth = { sqlserver = { basic = { username = "sa", password = "SqlServer-10" } } }, properties.host = '192.168.0.250.1', properties.port = 3340, properties.db_name = 'triforce2', properties.migrations='disabled' }
]
"#;

/// Tests the behaviour of the `DatabaseType::from_datasource(...)`
#[test]
fn check_from_datasource() {
let config: CanyonSqlConfig = toml::from_str(CONFIG_FILE_MOCK_ALT)
.expect("A failure happened retrieving the [canyon_sql] section");

assert_eq!(
config.canyon_sql.datasources[0].get_db_type(),
DatabaseType::PostgreSql
);
assert_eq!(
config.canyon_sql.datasources[1].get_db_type(),
DatabaseType::SqlServer
);
#[cfg(all(feature = "postgres", feature = "mssql"))]
{
const CONFIG_FILE_MOCK_ALT_ALL: &str = r#"
[canyon_sql]
datasources = [
{name = 'PostgresDS', auth = { postgresql = { basic = { username = "postgres", password = "postgres" } } }, properties.host = 'localhost', properties.db_name = 'triforce', properties.migrations='enabled' },
{name = 'SqlServerDS', auth = { sqlserver = { basic = { username = "sa", password = "SqlServer-10" } } }, properties.host = '192.168.0.250.1', properties.port = 3340, properties.db_name = 'triforce2', properties.migrations='disabled' }
]
"#;
let config: CanyonSqlConfig = toml::from_str(CONFIG_FILE_MOCK_ALT_ALL)
.expect("A failure happened retrieving the [canyon_sql] section");
assert_eq!(
config.canyon_sql.datasources[0].get_db_type(),
DatabaseType::PostgreSql
);
assert_eq!(
config.canyon_sql.datasources[1].get_db_type(),
DatabaseType::SqlServer
);
}

#[cfg(feature = "postgres")]
{
const CONFIG_FILE_MOCK_ALT_PG: &str = r#"
[canyon_sql]
datasources = [
{name = 'PostgresDS', auth = { postgresql = { basic = { username = "postgres", password = "postgres" } } }, properties.host = 'localhost', properties.db_name = 'triforce', properties.migrations='enabled' },
]
"#;
let config: CanyonSqlConfig = toml::from_str(CONFIG_FILE_MOCK_ALT_PG)
.expect("A failure happened retrieving the [canyon_sql] section");
assert_eq!(
config.canyon_sql.datasources[0].get_db_type(),
DatabaseType::PostgreSql
);
}

#[cfg(feature = "mssql")]
{
const CONFIG_FILE_MOCK_ALT_MSSQL: &str = r#"
[canyon_sql]
datasources = [
{name = 'SqlServerDS', auth = { sqlserver = { basic = { username = "sa", password = "SqlServer-10" } } }, properties.host = '192.168.0.250.1', properties.port = 3340, properties.db_name = 'triforce2', properties.migrations='disabled' }
]
"#;
let config: CanyonSqlConfig = toml::from_str(CONFIG_FILE_MOCK_ALT_MSSQL)
.expect("A failure happened retrieving the [canyon_sql] section");
assert_eq!(
config.canyon_sql.datasources[0].get_db_type(),
DatabaseType::SqlServer
);
}
}
}
Loading