libpg_query icon indicating copy to clipboard operation
libpg_query copied to clipboard

Expose frame options

Open autarch opened this issue 5 years ago • 4 comments

The frameOptions field shows up in a couple different structs. It's currently defined as an int in the struct_defs.json file, but it's really a set of bitmasks. It'd be nice if these were exposed in some form or other. I'm not sure exactly where the data should go, though. Maybe this needs a new file in srcdata for such things?

autarch avatar Nov 22 '20 17:11 autarch

There are a few other similar cases that I've noticed, including AclMode and cursor options, CURSOR_OPT_*.

autarch avatar Nov 22 '20 17:11 autarch

@autarch Thats a good point - but I'm not sure how to expose that information either (we could certainly extract it from the source). If you are at the C layer (i.e. writing C code yourself) you could potentially access the C defines, so its mostly a question of how to solve this in a higher-level language wrapper.

To help me prioritize this, can you describe your use case for libpg_query a bit more?

lfittl avatar Feb 20 '21 12:02 lfittl

I'm using the JSON files to generate Rust structs for a Rust program that uses libpg_query via libpg_query-sys. The latter is a very thin Rust wrapper around libpg_query that returns parse results as JSON. I turn those JSON results into actual structs.

You can see an example of the generated code at https://github.com/houseabsolute/pg-pretty/blob/master/parser/src/ast.rs. For now I've just made my own FrameOptions enum manually in https://github.com/houseabsolute/pg-pretty/blob/master/parser/src/flags.rs, but if I had the relevant JSON data I'm sure I could generate this as well, which would be preferable.

Just FYI, the program I'm writing is a pretty printer for Postges SQL (and hopefully PL/pgSQL in the future).

autarch avatar Feb 21 '21 01:02 autarch

@autarch Makes sense, thanks for sharing!

I'll keep in mind how we can address this in the future. For now I'm fully focused on finally getting the Postgres 13 parser release out, but this would certainly be a change worth making after that (but can't make any promises at this point when I'll get to it).

lfittl avatar Feb 21 '21 01:02 lfittl