Skip to content

Commit 76022de

Browse files
committed
draft
1 parent 7799b20 commit 76022de

10 files changed

+154
-39
lines changed

.sqlx/query-07a6c51ee278a56a95e947d1f334277c85ed788706d6f7c124eae06871feba87.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

.sqlx/query-1798fb8c66823e371b0306d1cefbf5923d1d6f9d6992535049cdfb0d7b2843bf.json

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-946d756b9e0821ef66916722e44ef249429458b2ef54e46bce72f76a1ef63753.json

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-ea76fbbc69c1941fe6baba8969b04ad3cf07b7ccd4f2b3b10e7eed32346b3855.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqlx-exasol-impl/src/column.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{borrow::Cow, fmt::Display};
22

3-
use serde::{Deserialize, Deserializer, Serialize};
3+
use serde::{Deserialize, Deserializer, Serialize, Serializer};
44
use sqlx_core::{column::Column, database::Database, ext::ustr::UStr};
55

66
use crate::{database::Exasol, type_info::ExaTypeInfo};
@@ -13,6 +13,7 @@ pub struct ExaColumn {
1313
pub(crate) ordinal: usize,
1414
#[serde(deserialize_with = "ExaColumn::lowercase_name")]
1515
pub(crate) name: UStr,
16+
#[serde(serialize_with = "ExaColumn::flatten_datatype")]
1617
pub(crate) data_type: ExaTypeInfo,
1718
}
1819

@@ -34,6 +35,36 @@ impl ExaColumn {
3435
.map(|c| c.0.to_lowercase())
3536
.map(From::from)
3637
}
38+
39+
/// Serialization helper so that offline query files are generated correctly, as that's
40+
/// the only place where the entire [`ExaColumn`] gets serialized.
41+
fn flatten_datatype<S>(type_info: &ExaTypeInfo, serializer: S) -> Result<S::Ok, S::Error>
42+
where
43+
S: Serializer,
44+
{
45+
type_info.data_type.serialize(serializer)
46+
}
47+
}
48+
49+
#[test]
50+
fn test_column_serde() {
51+
let column_str = r#" {
52+
"ordinal": 0,
53+
"name": "user_id!",
54+
"dataType": {
55+
"type": "DECIMAL",
56+
"precision": 18,
57+
"scale": 0
58+
}
59+
}"#;
60+
61+
let column: ExaColumn = serde_json::from_str(column_str).unwrap();
62+
println!("{column:?}");
63+
64+
let new_column_str = serde_json::to_string(&column).unwrap();
65+
66+
let column: ExaColumn = serde_json::from_str(&new_column_str).unwrap();
67+
println!("{column:?}");
3768
}
3869

3970
impl Display for ExaColumn {

sqlx-exasol-impl/src/type_checking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl_type_checking!(
3737
i128,
3838
f32,
3939
f64,
40-
String,
40+
String | &str,
4141

4242
// External types
4343
#[cfg(feature = "uuid")]

sqlx-exasol-impl/src/type_info.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use sqlx_core::type_info::TypeInfo;
1111
// Note that the [`DataTypeName`] is automatically constructed from the provided [`ExaDataType`].
1212
#[derive(Debug, Clone, Copy, Deserialize)]
1313
#[serde(from = "ExaDataType")]
14-
#[serde(rename_all = "camelCase")]
1514
pub struct ExaTypeInfo {
1615
pub(crate) name: DataTypeName,
1716
pub(crate) data_type: ExaDataType,

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,6 @@ pub mod any {
239239
pub use sqlx_exasol_macros;
240240
#[cfg(feature = "macros")]
241241
mod macros;
242+
243+
// TODO:
244+
// -

tests/compile_time.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,43 @@
33
//! cargo run -p sqlx-exasol-cli prepare -- --features runtime-tokio --tests
44
//! ```
55
6-
#[sqlx_exasol::test]
7-
async fn test_query(
6+
#[sqlx_exasol::test(migrations = "tests/migrations")]
7+
#[ignore]
8+
async fn test_compile_time_queries(
89
mut conn: sqlx::pool::PoolConnection<sqlx_exasol::Exasol>,
910
) -> anyhow::Result<()> {
10-
let x: Option<String> = sqlx_exasol::query_scalar!("SELECT dummy FROM DUAL")
11-
.fetch_one(&mut *conn)
11+
struct User {
12+
user_id: u64,
13+
username: String,
14+
}
15+
16+
let username = "test";
17+
18+
sqlx_exasol::query!("INSERT INTO users (username) VALUES(?);", username)
19+
.execute(&mut *conn)
1220
.await?;
1321

22+
let user_id: u64 = sqlx_exasol::query_scalar!(
23+
r#"SELECT user_id as "user_id!" FROM users WHERE username = ?"#,
24+
username
25+
)
26+
.fetch_one(&mut *conn)
27+
.await?;
28+
29+
let user = sqlx_exasol::query_as!(
30+
User,
31+
r#"SELECT user_id as "user_id!", username as "username!" FROM users WHERE user_id = ?"#,
32+
user_id
33+
)
34+
.fetch_one(&mut *conn)
35+
.await?;
36+
37+
assert_eq!(user.user_id, user_id);
38+
assert_eq!(user.username, username);
39+
40+
loop {
41+
sqlx_exasol::__rt::sleep(std::time::Duration::from_secs(10)).await;
42+
}
43+
1444
Ok(())
1545
}

tests/migrations/2_post.sql

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,4 @@ CREATE TABLE post
88

99
-- Not meant to do anything, but just test that query separation
1010
-- in migrations is done properly.
11-
-- We include the semicolon in the where clause because we test based on that.
12-
-- NOTE: Putting a semicolon in a comment such as this one will cause the migration
13-
-- to fail, because Exasol accepts a statement that is just a comment, but the
14-
-- second part of the comment, after the semicolon, will always fail.
15-
DELETE FROM post WHERE ';' = ';'
16-
;
17-
18-
11+
DELETE FROM post WHERE ';' = ';';

0 commit comments

Comments
 (0)