Skip to content

Commit

Permalink
Normal Int passed test of no-op, have to figure out Floates and add p…
Browse files Browse the repository at this point in the history
…ropper tests for jsons/text
  • Loading branch information
JakobKlocker committed Mar 7, 2025
1 parent 707dc76 commit bef8c3e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
20 changes: 13 additions & 7 deletions diesel/src/sqlite/expression/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,19 +928,25 @@ extern "SQL" {
/// println!("SQLite version is too old, skipping the test.");
/// return Ok(());
/// }
/// let test_value = 3.14159
///
/// let result = diesel::select(json_quote::<Integer, _>(test_value)
/// let test_value = 42;
/// let result = diesel::select(json_quote::<Integer, _>(test_value))
/// .get_result::<Option<String>>(connection)?;
///
/// assert_eq!(Some(test_value), result);
/// assert_eq!(Some("42".to_string()), result);
///
/// # Ok(())
/// # }
/// ```
#[sql_name = "json_quote"]
#[cfg(feature = "sqlite")]
fn json_quote<J: MaybeNullableValue<Integer> + MaybeNullableValue<Text>>(
j: J,
) -> JsonOrNullableJson;
fn json_quote<J: MaybeNullableValue<Integer> + MaybeNullableValue<Text>>( // Have to add Supoprt for Real/Floates, how? Existing Datatype?
j: J
) -> Nullable<Text>;
}
// double test case
// let test_value = 3.14159;
// let result = diesel::select(json_quote::<Integer, _>(test_value))
// .get_result::<Option<String>>(connection)?;
//
// assert_eq!(Some("3.14159".to_string()), result);

6 changes: 6 additions & 0 deletions diesel/src/sqlite/expression/helper_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ pub type json_type<E> = super::functions::json_type<SqlTypeOf<E>, E>;
#[allow(non_camel_case_types)]
#[cfg(feature = "sqlite")]
pub type json_type_with_path<J, P> = super::functions::json_type_with_path<SqlTypeOf<J>, J, P>;

/// Return type of [`json_type(json)`](super::functions::json_type())
#[allow(non_camel_case_types)]
#[cfg(feature = "sqlite")]
pub type json_quote<J> = super::functions::json_quote<SqlTypeOf<J>, J>;

2 changes: 2 additions & 0 deletions diesel_derives/tests/auto_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ fn sqlite_functions() -> _ {
json_valid(sqlite_extras::json),
json_type(sqlite_extras::json),
json_type_with_path(sqlite_extras::json, sqlite_extras::text),
json_quote(sqlite_extras::text),
json_quote(sqlite_extras::id),
)
}

Expand Down

0 comments on commit bef8c3e

Please sign in to comment.