-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Float type missing & json wrongfully treated as string
- Loading branch information
1 parent
bef8c3e
commit ac14c2e
Showing
3 changed files
with
31 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -910,7 +910,7 @@ extern "SQL" { | |
/// # fn run_test() -> QueryResult<()> { | ||
/// # use diesel::dsl::{sql, json_quote}; | ||
/// # use serde_json::{json, Value}; | ||
/// # use diesel::sql_types::{Text, Integer, Nullable}; | ||
/// # use diesel::sql_types::{Text, Json, Integer, Nullable}; | ||
/// # let connection = &mut establish_connection(); | ||
/// | ||
/// let version = diesel::select(sql::<Text>("sqlite_version();")) | ||
|
@@ -928,25 +928,41 @@ extern "SQL" { | |
/// println!("SQLite version is too old, skipping the test."); | ||
/// return Ok(()); | ||
/// } | ||
/// let test_value = 42; | ||
/// let result = diesel::select(json_quote::<Integer, _>(test_value)) | ||
/// let result = diesel::select(json_quote::<Integer, _>(42)) | ||
/// .get_result::<Option<String>>(connection)?; | ||
/// | ||
/// assert_eq!(Some("42".to_string()), result); | ||
/// | ||
/// let result = diesel::select(json_quote::<Text, _>("verdant")) | ||
/// .get_result::<Option<String>>(connection)?; | ||
/// assert_eq!(Some("\"verdant\"".to_string()), result); | ||
/// | ||
/// let result = diesel::select(json_quote::<Text, _>("[1]")) | ||
/// .get_result::<Option<String>>(connection)?; | ||
/// assert_eq!(Some("\"[1]\"".to_string()), result); | ||
/// | ||
/// let result = diesel::select(json_quote::<Nullable<Text>, _>(None::<&str>)) | ||
/// .get_result::<Option<String>>(connection)?; | ||
/// assert_eq!(Some("null".to_string()), result); | ||
/// | ||
// COMENT---------------------------------------- | ||
This comment has been minimized.
Sorry, something went wrong. |
||
// BELOW NONE WORKING TESTS, JSON and FLOAT TYPES | ||
// DATATYPE FOR FLOAT NEEDED & JSON IS TREATED AS TEXT | ||
// let result = diesel::select(json_quote::<Json, _>(json!([1]))) | ||
// .get_result::<Option<String>>(connection)?; | ||
// assert_eq!(Some("[1]".to_string()), result); | ||
// | ||
// let result = diesel::select(json_quote::<Integer, _>(3.14159)) | ||
// .get_result::<Option<String>>(connection)?; | ||
// | ||
// assert_eq!(Some("3.14159".to_string()), result); | ||
// COMENT---------------------------------------- | ||
/// | ||
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
#[sql_name = "json_quote"] | ||
#[cfg(feature = "sqlite")] | ||
fn json_quote<J: MaybeNullableValue<Integer> + MaybeNullableValue<Text>>( // Have to add Supoprt for Real/Floates, how? Existing Datatype? | ||
fn json_quote<J: MaybeNullableValue<Json> + MaybeNullableValue<Integer> + MaybeNullableValue<Text>>( // Have to add Supoprt for Real/Floates, how? Existing Datatype? | ||
This comment has been minimized.
Sorry, something went wrong.
JakobKlocker
Author
|
||
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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -517,6 +517,7 @@ fn sqlite_functions() -> _ { | |
json_type(sqlite_extras::json), | ||
json_type_with_path(sqlite_extras::json, sqlite_extras::text), | ||
json_quote(sqlite_extras::text), | ||
json_quote(sqlite_extras::json), | ||
json_quote(sqlite_extras::id), | ||
This comment has been minimized.
Sorry, something went wrong.
JakobKlocker
Author
|
||
) | ||
} | ||
|
Both tests below fail, the first one because the Json seems to be handled as a Text and the second one because I can't find a Value for Real/Float