Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test and fix mapping of mysql and postgres native types #538

Merged
merged 15 commits into from Mar 11, 2020

Conversation

tomhoule
Copy link
Contributor

@tomhoule tomhoule commented Feb 26, 2020

This is a first PR. I will test more in follow-ups.

@tomhoule tomhoule force-pushed the query-engine/test-database-types-support branch 3 times, most recently from 05a1608 to e35e764 Compare February 27, 2020 13:49
@tomhoule tomhoule added this to the Preview 23 milestone Feb 27, 2020
@tomhoule tomhoule force-pushed the query-engine/test-database-types-support branch 3 times, most recently from 1388b6c to 41c636b Compare March 2, 2020 13:04
@janpio janpio modified the milestones: Preview 23, Preview 24 Mar 3, 2020
@tomhoule tomhoule force-pushed the query-engine/test-database-types-support branch 4 times, most recently from 6fc0279 to 2128ed1 Compare March 6, 2020 14:44
@tomhoule tomhoule changed the title [WIP] Test mapping of mysql native types [WIP] Test and fix mapping of mysql and postgres native types Mar 6, 2020
@tomhoule tomhoule force-pushed the query-engine/test-database-types-support branch from b6a4b08 to dc12321 Compare March 9, 2020 10:55
@tomhoule tomhoule changed the title [WIP] Test and fix mapping of mysql and postgres native types Test and fix mapping of mysql and postgres native types Mar 9, 2020
@tomhoule tomhoule force-pushed the query-engine/test-database-types-support branch 7 times, most recently from 411a83c to 6b29c05 Compare March 10, 2020 14:13
@tomhoule tomhoule force-pushed the query-engine/test-database-types-support branch from cb18d43 to 9d4c7f9 Compare March 10, 2020 15:52
@@ -15,6 +15,9 @@ impl<'a> From<ParameterizedValue<'a>> for PrismaValue {
ParameterizedValue::Uuid(uuid) => PrismaValue::Uuid(uuid),
ParameterizedValue::DateTime(dt) => PrismaValue::DateTime(dt),
ParameterizedValue::Char(c) => PrismaValue::String(c.to_string()),
ParameterizedValue::Bytes(bytes) => PrismaValue::String(
String::from_utf8(bytes.into_owned()).expect("PrismaValue::String from ParameterizedValue::Bytes"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next PR will test this (and things like non-utf8 encodings) to make sure we return good errors.

@tomhoule tomhoule marked this pull request as ready for review March 11, 2020 08:37
@tomhoule tomhoule requested review from pimeys and do4gr March 11, 2020 08:37
@@ -136,7 +136,9 @@ pub fn row_value_to_prisma_value(
ParameterizedValue::Integer(i) => {
PrismaValue::Float(Decimal::from_f64(i as f64).expect("f64 was not a Decimal."))
}
ParameterizedValue::Text(s) => PrismaValue::Float(s.parse().unwrap()),
ParameterizedValue::Text(_) | ParameterizedValue::Bytes(_) => {
PrismaValue::Float(p_value.as_str().unwrap().parse().unwrap())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A necessary "Yo dawg! I heard you like unwrapping" meme...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, missed that one - we can probably do better error handling there.

Copy link
Member

@do4gr do4gr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.


// We assume the bytes are stored as a big endian signed integer, because that is what
// mysql does if you enter a numeric value for a bits column.
fn interpret_bytes_as_i64(bytes: &[u8]) -> i64 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked already in slack. This makes me a bit worried due to this not being obvious in the type level that we're only talking about MySQL. I'm worried that somebody can without knowing write code that returns bytes from Quaint that are not from MySQL and we run this code and do some crazy wrong stuff.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm not proposing or asking any changes, just writing down here that I'm a bit uncomfortable with this :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would be nice to have a way to specialize things depending on the specific database we're working with in the sql query connector. That way we could do this, but only on mysql. This hack may go away when we expand the type system.

@@ -33,6 +33,7 @@ impl ToSqlRow for ResultRow {
fn to_sql_row<'b>(self, idents: &[(TypeIdentifier, FieldArity)]) -> crate::Result<SqlRow> {
let mut row = SqlRow::default();
let row_width = idents.len();
row.values.reserve(row_width);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. What is the difference between this and then implementing with_capacity to SqlRow and using it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's the same.

query-engine/prisma/src/tests/type_mappings/test_api.rs Outdated Show resolved Hide resolved
query-engine/prisma/src/tests/type_mappings/test_api.rs Outdated Show resolved Hide resolved
@tomhoule tomhoule merged commit ab4ecca into master Mar 11, 2020
@tomhoule tomhoule deleted the query-engine/test-database-types-support branch March 11, 2020 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants