lpsmith / postgresql-simple

Mid-level client library for accessing PostgreSQL from Haskell
Other
206 stars 71 forks source link

Useful exports #138

Closed s9gf4ult closed 9 years ago

lpsmith commented 9 years ago

The constructors patch I'm 100% fine with.

The additional helper functions I'm a bit more leery of, not because I think it's a bad idea, but because I want to change the way that postgresql-simple performs escaping, and I'm not enthusiastic about extending that part of the API at the present time. See #120 and #127 for example.

s9gf4ult commented 9 years ago

Ok. As I understand from #127 pure string escaping not being implemented soon.

I just implemented the quasiquoter you wanted in #120 here https://bitbucket.org/3ai/pgsimple/src/e217ee4adf29a9c76cfa68c0d09799e1de74c56e/src/PGSimple/TH/SqlExp.hs?at=master

It works like

let subquery = [sqlExp| SELECT field, field2 FROM table where name = #{name}|]
pgQueryB [sqlExp| SELECT * FROM (^{buquery}) WHERE field = #{fieldValue}|] 

It supports two ways of interpolating:

  1. ^{sqlBuilder} which requires sqlBuilder to be an instance of ToSqlBuilder. This is equivalent of mappend on SqlBuilder
  2. #{value} which requires value to be an instance of ToField. This is equvalent of current interpolation of Query with ? sign inside.

The returning value of this quasiquoter is https://bitbucket.org/3ai/pgsimple/src/e217ee4adf29a9c76cfa68c0d09799e1de74c56e/src/PGSimple/SqlBuilder.hs?at=master

newtype SqlBuilder =
    SqlBuilder
    { sqlBuild :: Connection -> IO Builder }
    deriving (Typeable, Generic)

instance Monoid SqlBuilder ...

As you can see, this is reader of Connection which builds blaze builder just because of string escaping, which requires Connection and is IO action.

We are using pgsimple which is a bundle of quick and dirty helpers on top of postgresql-simple. It includes not just quasiquoter but some sort of primitive ORM also.

I think we will develop pgsimple and many parts of it (PgMonadT and selExp at least) should be in postgresql-simple. It is easier to make a correcting release of postgresql-simple to make pgsimple compilable and later (maybe 0.5 release?) merge some features of pgsimple to potgresql-simple. Because they should be merged.

There is also some work to be done with pgsimple itself.

Now, what about exports of escapeStringConn and its friends:

s9gf4ult commented 9 years ago

Hello again. I have updated this patch, string escaping functions are moved to Internal module. Action building is also moved to Internal. So public modules export same as before (except added error constructors).

We are almost ready to release our https://bitbucket.org/3ai/pgsimple/src/5b728877a93179a8e8180c88db0eb1be7b3f7672?at=feature/monadic and this patch required for.

Take a look what it can in documentation https://bitbucket.org/3ai/pgsimple/src/5b728877a93179a8e8180c88db0eb1be7b3f7672/src/PGSimple/TH/SqlExp.hs?at=feature%2Fmonadic

lpsmith commented 9 years ago

I just released 0.4.10.0, thanks!

s9gf4ult commented 9 years ago

Wow, so fast!