prisma / quaint

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

PostgreSQL - Could not convert value to IpAddr #416

Open carlos-rian opened 2 years ago

carlos-rian commented 2 years ago

Description

I ran a query_raw where the PostgreSQL column is of type CIDR or MacAddr but I got this error.

This message is in the src/ast/values.rs file, line 788.

Value in column: 192.168.100.128/25 and 08:00:2b:01:02:03

Error

CIDR Error querying the database: error deserializing column 24: cannot convert between the Rust type core::option::Option<std::net::ip::IpAddr> and the Postgres type cidr

MacAddr has the same problem Column type 'macaddr' could not be deserialized from the database.

Simponic commented 2 years ago

I'm also running into these issues trying to create the following models:

model Network {
  id                       Int    @id @default(autoincrement())
  subnet                   String @unique @db.Inet

  @@index([subnet(ops: InetOps)], type: Gist)
}

model AP {
  id            Int                    @id @default(autoincrement())
  macAddr       Unsupported("macaddr")
}

Now, I know absolutely nothing about Rust, but from the given error I found https://doc.rust-lang.org/std/net/struct.AddrParseError.html which led me on a hunt. Could it be from attempting to parse it with std::net::IpAddr, which does not support subnets? https://github.com/prisma/quaint/blob/657a56a38f6d61533ecbc71935eff61fbcf6af54/src/connector/postgres/conversion.rs#L489-L494

I'm sorry in advance if this is completely wrong, just trying to add some traffic onto this issue with my very limited knowledge since this fix is important to me.