Skip to content

Add sql.describe() #98

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

Closed
wants to merge 1 commit into from
Closed

Add sql.describe() #98

wants to merge 1 commit into from

Conversation

akheron
Copy link
Contributor

@akheron akheron commented Aug 1, 2020

Hi! I'm the author of sqltyper, a tool for automatically creating TypeScript typings for PosgreSQL queries.

One of the things sqltyper does is calling Postgres to describe the input parameters and output columns of a statement. Currently I'm using node-postgres, which doesn't support describing statements. So I've added the support and have an in-tree copy of node-postgres. There's an open PR, but it doesn't seem to move forward.

I would like to use this library for its speed and simplicity instead. Adding support for describing statements didn't require much code, which is nice!

Let me know what you think.

@akheron akheron force-pushed the describe branch 2 times, most recently from e465335 to 1477727 Compare August 19, 2020 15:09
@akheron
Copy link
Contributor Author

akheron commented Aug 19, 2020

Moved describe to addTypes to make it available in sql.begin. Fixed conflicts.

@TobiasNickel
Copy link

@porsager i think this is pretty cool, but should the PR go to version 2.?

@porsager
Copy link
Owner

Oh man, I'm sorry I haven't had time to look at this, haven't read through it until now.. I think it would a great addition. Your PR looks good, but what do you think about making the API like this:

sql`...`.describe()

That way it's in line with .stream(), .cursor() etc.

@akheron
Copy link
Contributor Author

akheron commented Dec 15, 2020

Rebased and fixed conflicts 👍

@akheron
Copy link
Contributor Author

akheron commented Dec 15, 2020

The reason I added it as sql.describe() is that you're not really supposed to use query parameters. If your query requires parameters, you should use $1, $2, etc. directly, so that the query is natively understood by postrges and it can return the type information for $1, $2, etc. In this sense, sql.describe() is closer to sql.file() in my opinion.

@porsager
Copy link
Owner

@akheron Sorry this has been hanging so long. I've finally found some time for Postgres.js again.. I'd still like if we could have it as sql``.describe() since the query sent is converted to $1, $2 ... anyway. This let's you use .describe with either sql``, sql.unsafe() and sql.file.

@porsager porsager mentioned this pull request Jan 11, 2022
Merged
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

Successfully merging this pull request may close these issues.

3 participants