prisma / quaint

SQL Query AST and Visitor for Rust
Apache License 2.0
583 stars 62 forks source link

Prevent decimal/float conversions where unstable. Allow casting of expressions. #292

Open pimeys opened 3 years ago

pimeys commented 3 years ago

Part of: https://github.com/prisma/prisma/issues/6902

sumeetattree commented 3 years ago

@pimeys This looks great! Just what I have been looking for to add query support to enum types. Anything I can do to help fast track this PR?

sumeetattree commented 3 years ago

@pimeys Slight correction in postgres visitor (Not sure about other databases), the custom type name should be double quoted.

let comparison = "kind".equals(value.cast_as("UserKind"));

The query output is:

SELECT    
  "public"."users".*    
FROM    
  "public"."users"    
WHERE    
  "kind" = ($1) :: UserKind # I know crazy type name, but sometimes external databases have stuff like this

UserKind will actually be converted to userkind by postgres. To avoid this the type must be quoted. "\"UserKind\"". The CastType::Custom should automatically quote the typenames.

pimeys commented 3 years ago

This whole issue is on hold now due to not having time in any team and if we merge this, we'll break our main product (it needs to get the corresponding PR finished and merged)...

sumeetattree commented 3 years ago

Ah, understood. Thanks, I'll try something at my end.