tomjaguarpaw / haskell-opaleye

Other
602 stars 115 forks source link

add showSqlTypeWithSchema for types in a schema #589

Closed stevemao closed 5 months ago

stevemao commented 5 months ago
tomjaguarpaw commented 5 months ago

If you want a schema I don't understand why you can't just do showSqlType = "\"foo\".\"bar\"".

stevemao commented 5 months ago

I can, but other APIs such as enumMapperWithSchema has a spot for schema. This is to make it consistent with these APIs.

tomjaguarpaw commented 5 months ago

I see. Then in that case I think showSqlTypeWithSchema wants just to be a function

showSqlTypeWithSchema :: (String, String) -> String
showSqlTypeWithSchema (schema, type_) =
  render (doubleQuotes (text schema) <> text "." <> doubleQuotes (text type_))

that you use like

instance IsSqlType Whatever where
  showSqlType = showSqlTypeWithSchema ("schema", "type_name")

Making it a class method means that all instances have to implement it, which is not what we want because not all type names have a schema.

stevemao commented 5 months ago

Happy with a function to make it simple. But I have some questions

showSqlTypeWithSchema seems to be quite generic. Maybe we can call it sqlTypeWithSchema?

Making it a class method means that all instances have to implement it, which is not what we want because not all type names have a schema.

Not really? the instance can choose to implement either method {-# MINIMAL showSqlType | showSqlTypeWithSchema #-}

tomjaguarpaw commented 5 months ago

Making it a class method means that all instances have to implement it, which is not what we want because not all type names have a schema.

Not really? the instance can choose to implement either method {-# MINIMAL showSqlType | showSqlTypeWithSchema #-}

But what if an instance choose not to implement it but then a user calls it on that instance? Run time crash, presumably.

stevemao commented 5 months ago

Ok, definitely not ideal even though it's an internal module

tomjaguarpaw commented 5 months ago

Thanks, I tweaked this and merged it in https://github.com/tomjaguarpaw/haskell-opaleye/commit/f012b275608e5109f913be61260cdbdf6149d088

tomjaguarpaw commented 5 months ago

Released as https://hackage.haskell.org/package/opaleye-0.10.3.0