Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoded values as Params? #48

Open
0x777 opened this issue Jun 13, 2016 · 7 comments
Open

Encoded values as Params? #48

0x777 opened this issue Jun 13, 2016 · 7 comments

Comments

@0x777
Copy link

0x777 commented Jun 13, 2016

list :: Params [(LibPQ.Oid, Maybe ByteString)]

It is useful when dealing with dynamically generated queries.

@nikita-volkov
Copy link
Owner

I agree this might be useful to some.

However I'd rather go with the following:

raw :: Value (LibPQ.Oid, Maybe ByteString)

Then the definition of your list function becomes just contramany raw.

I won't promise to implement that soon, though. A PR would be welcome.

@0x777
Copy link
Author

0x777 commented Jun 13, 2016

If we go with raw, what does it mean to use functions like arrayValue on raw?

@nikita-volkov
Copy link
Owner

Right. Actually it seems like our both variants are impossible. What we can do is something more like this:

-- | Given an OID and an according array OID
-- produces an encoder of raw bytes.
raw :: Oid -> Oid -> Value (Maybe ByteString)

@0x777
Copy link
Author

0x777 commented Jun 13, 2016

How about this?

rawList :: Params [(LibPQ.Oid, Maybe ByteString)]
rawList = Params (Params.Params $ Op encoder)
  where
    encoder = DList.fromList . map (fmap const)

@0x777
Copy link
Author

0x777 commented Jun 13, 2016

Or rather

rawList :: Params [(LibPQ.Oid, Bool -> Maybe ByteString)]
rawList = Params (Params.Params $ Op DList.fromList)

@nikita-volkov
Copy link
Owner

Oh, right! This you can do.

Can you describe your use-case though? Maybe we could find something better than exporting such a low-level functionality.

@0x777
Copy link
Author

0x777 commented Jun 13, 2016

I work on a compiler which converts a JSON based query language to SQL. In a nutshell,

exec :: DatabaseSchema -> JSONQuery -> IO (Either Error Aeson.Value)

So, given a query, a Postgres prepared statement is generated, and with the DatabaseSchema, the arguments to this statement are converted to binary format (using encoders from postgresql-binary). This statement is then executed with a thin wrapper written on top of postgresql-libpq.

I would like to replace this wrapper with hasql. The starting point would be to use the statement function. By the time this function is used, the arguments to the prepared statement are already converted to postgres's binary format. Hence, the requirement for the Params [(LibPQ.Oid, Maybe ByteString)] encoder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants