dylex / postgresql-typed

Haskell PostgreSQL library with compile-time type inference
http://hackage.haskell.org/package/postgresql-typed
Other
84 stars 12 forks source link

Change getQueryString to take PGTypeEnv instead of PGConnection #20

Closed stoeffel closed 4 years ago

stoeffel commented 4 years ago

We have a need for using getQueryString, but we don't have access to a PGConnection. I don't have full context on how the internals of postgresql-typed works, but I think it's actually not necessary for the function. This would be awesome for our usecase, though. Does this change make sense to you? Is there something you'd like me to adjust?

dylex commented 4 years ago

I went back and forth on this. I decided it would be safer to have there in case it becomes more important at some point for encoding literals (e.g., version difference), but if this is important for your use case I suppose I'm fine getting rid of it. I could also imagine having a undefinedConnection :: PGConnection for use with it, though that does feel a bit messy. @jwoudenberg any thoughts, since you requested this?

dylex commented 4 years ago

I guess we could also just make it take a PGTypeEnv and then it's up to you what to pass. Maybe that's the best option.

jwoudenberg commented 4 years ago

Full disclosure: Stoeffel and I work on the same team :). Your original change was super useful, and having a simple function to turn a query into a string prompted further use cases, that made us wonder if we could do without the connection string. It's not exactly a blocker because, as you said, we could pass in undefined, but yeah, feels messy.

I guess we could also just make it take a PGTypeEnv and then it's up to you what to pass. Maybe that's the best option.

I really like this!

stoeffel commented 4 years ago

I guess we could also just make it take a PGTypeEnv and then it's up to you what to pass. Maybe that's the best option.

Yes, I was actually thinking about that initially as well, but thought that it's not really used. I can make that change to the PR if you'd like me to.

dylex commented 4 years ago

Sure, thanks, I'll happily merge the PGTypeEnv version if you want to do that.

stoeffel commented 4 years ago

@dylex I've made the change. Thanks for your responsiveness!

dylex commented 4 years ago

Thanks! I'll try to get a new release out in the next few days. (Trying to decide on some unrelated switches to vector first.)

stoeffel commented 4 years ago

@dylex In case your interested, this is why we wanted this change. https://dev.to/noredink/type-safe-mysql-queries-via-postgres-5cnk

dylex commented 4 years ago

@stoeffel Cool, thanks for the link. I think I saw a talk from you guys at the Compose conference earlier this year. I know I owe you a release, too -- hopefully that's not blocking anything.

stoeffel commented 4 years ago

nope not blocking at all. we just use the commit hash. that was probably Richard Feldman :-) maybe we'll see us at some conf as well.