Skip to content

Commit 1607444

Browse files
authored
Merge pull request #51 from GiGainfosystems/fix/make_alias_syntax_configurable
Make alias syntax configurable
2 parents 8eabd3e + f72f513 commit 1607444

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = [
55
"Daniel Buse <[email protected]>",
66
]
77
name = "diesel-oci"
8-
version = "0.2.0"
8+
version = "0.2.1"
99
license = "MIT OR Apache-2.0"
1010
description = "A oci database adapter for diesel"
1111
readme = "README.md"
@@ -52,3 +52,6 @@ chrono = ["chrono-time", "diesel/chrono"]
5252
r2d2 = ["diesel/r2d2"]
5353
dynamic-schema = ["diesel-dynamic-schema"]
5454
gst = []
55+
56+
[patch.crates-io]
57+
diesel = { git = "https://github.com/weiznich/diesel", rev = "e632a7ca4fa12b76d7638392aeaff7522f57adef" }

src/oracle/backend.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ impl SqlDialect for Oracle {
3939
type ConcatClause = sql_dialect::concat_clause::ConcatWithPipesClause;
4040
type ArrayComparison = sql_dialect::array_comparison::AnsiSqlArrayComparison;
4141
type SelectStatementSyntax = sql_dialect::select_statement_syntax::AnsiSqlSelectStatement;
42+
type AliasSyntax = OracleAliasSyntax;
4243
}
4344

4445
pub struct OracleStyleBatchInsert;
4546
pub struct OracleReturningClause;
4647
pub struct OracleDualForEmptySelectClause;
4748
pub struct OracleExistsSyntax;
49+
pub struct OracleAliasSyntax;

src/oracle/query_builder/alias.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,17 @@ where
5454
out.push_identifier(&self.alias)
5555
}
5656
}
57+
58+
impl<S> QueryFragment<Oracle, crate::oracle::backend::OracleAliasSyntax>
59+
for diesel::query_source::Alias<S>
60+
where
61+
S: diesel::query_source::AliasSource,
62+
S::Target: QueryFragment<Oracle>,
63+
{
64+
fn walk_ast<'b>(&'b self, mut pass: AstPass<'_, 'b, Oracle>) -> QueryResult<()> {
65+
self.source.target().walk_ast(pass.reborrow())?;
66+
pass.push_sql(" ");
67+
pass.push_identifier(S::NAME)?;
68+
Ok(())
69+
}
70+
}

src/test/mod.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,5 +2394,43 @@ fn batch_insert_1() {
23942394
assert_eq!(res[1].big, Some(-3));
23952395
}
23962396

2397+
#[test]
2398+
fn alias() {
2399+
let mut conn = init_testing();
2400+
create_gst_types_table(&mut conn);
2401+
2402+
::diesel::insert_into(gst_types::table)
2403+
.values(Newgst_types::new(
2404+
Some(1),
2405+
Some(2),
2406+
Some(3),
2407+
Some(4),
2408+
Some("foo".into()),
2409+
Some(b"bar".to_vec()),
2410+
Some(1.23),
2411+
Some(3.14),
2412+
Some("bac".into()),
2413+
))
2414+
.execute(&mut conn)
2415+
.unwrap();
2416+
2417+
let test_alias = diesel::alias!(gst_types as test_alias);
2418+
let res = test_alias
2419+
.filter(test_alias.field(gst_types::big).eq(1))
2420+
.load::<GSTTypes>(&mut conn)
2421+
.unwrap();
2422+
2423+
assert_eq!(res.len(), 1);
2424+
assert_eq!(res[0].big, Some(1));
2425+
assert_eq!(res[0].big2, Some(2));
2426+
assert_eq!(res[0].small, Some(3));
2427+
assert_eq!(res[0].normal, Some(4));
2428+
assert_eq!(res[0].text, Some("foo".to_owned()));
2429+
assert_eq!(res[0].byte, Some(b"bar".to_vec()));
2430+
assert_eq!(res[0].d, Some(1.23));
2431+
assert_eq!(res[0].r, Some(3.14));
2432+
assert_eq!(res[0].v, Some("bac".to_owned()));
2433+
}
2434+
23972435
#[cfg(feature = "dynamic-schema")]
23982436
mod dynamic_select;

0 commit comments

Comments
 (0)