C++ Trigger Framework

Started by Shmuel Kamenskyabout 4 years ago5 messageshackers
Jump to latest
#1Shmuel Kamensky
shmuelkamensky@gmail.com

Hello all, this is my first time posting here (I first posted on the IRC
but didn't get any response), so let me know if there's a different
procedure for asking questions.

I'm interested in creating a Postgres extension that would enable
developers to write triggers in (modern) C++. Does anyone know if there is
already some sort of translation wrapper between the native Postgres C
API's and C++? Or if there's already a project that allows for writing
triggers in C++ with ease?
I see that https://github.com/clkao/plv8js-clkao/blob/master/plv8_type.cc
does implement an abstraction of sorts, but it's specific to v8 types and
is not genericized as a way of interacting with Postgres C API's from C++
from *an*y C++ code.

Can you imagine any potential technical challenges I may encounter (e.g.
massaging postgres' custom allocator to work with C++'s new and delete
operators, or unresolvable compiler incompatibilities)?

Thanks for any input :-)

#2Nathan Bossart
nathandbossart@gmail.com
In reply to: Shmuel Kamensky (#1)
Re: C++ Trigger Framework

On Tue, Feb 22, 2022 at 04:02:39PM +0200, Shmuel Kamensky wrote:

I'm interested in creating a Postgres extension that would enable
developers to write triggers in (modern) C++. Does anyone know if there is
already some sort of translation wrapper between the native Postgres C
API's and C++? Or if there's already a project that allows for writing
triggers in C++ with ease?
I see that https://github.com/clkao/plv8js-clkao/blob/master/plv8_type.cc
does implement an abstraction of sorts, but it's specific to v8 types and
is not genericized as a way of interacting with Postgres C API's from C++
from *an*y C++ code.

Can you imagine any potential technical challenges I may encounter (e.g.
massaging postgres' custom allocator to work with C++'s new and delete
operators, or unresolvable compiler incompatibilities)?

This might answer your questions:

https://www.postgresql.org/docs/devel/xfunc-c.html#EXTEND-CPP

--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

#3Shmuel Kamensky
shmuelkamensky@gmail.com
In reply to: Nathan Bossart (#2)
Re: C++ Trigger Framework

Hi Nathan,

Thanks for the reply. I did indeed read that document and it's a great
place to get started. But it doesn't quite answer my questions. Do you
personally have experience writing software in C++ that interacts with
Postgres?

On Tue, Feb 22, 2022, 23:07 Nathan Bossart <nathandbossart@gmail.com> wrote:

Show quoted text

On Tue, Feb 22, 2022 at 04:02:39PM +0200, Shmuel Kamensky wrote:

I'm interested in creating a Postgres extension that would enable
developers to write triggers in (modern) C++. Does anyone know if there

is

already some sort of translation wrapper between the native Postgres C
API's and C++? Or if there's already a project that allows for writing
triggers in C++ with ease?
I see that

https://github.com/clkao/plv8js-clkao/blob/master/plv8_type.cc

does implement an abstraction of sorts, but it's specific to v8 types and
is not genericized as a way of interacting with Postgres C API's from C++
from *an*y C++ code.

Can you imagine any potential technical challenges I may encounter (e.g.
massaging postgres' custom allocator to work with C++'s new and delete
operators, or unresolvable compiler incompatibilities)?

This might answer your questions:

https://www.postgresql.org/docs/devel/xfunc-c.html#EXTEND-CPP

--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

#4Bruce Momjian
bruce@momjian.us
In reply to: Shmuel Kamensky (#3)
Re: C++ Trigger Framework

On Tue, Feb 22, 2022 at 11:33:05PM +0200, Shmuel Kamensky wrote:

Hi Nathan,

Thanks for the reply. I did indeed read that document and it's a great place to
get started. But it doesn't quite answer my questions. Do you personally have
experience writing software in C++ that interacts with Postgres?

As far as I know, it should just work like C. I know you can compile
the backend server using a C++ compiler because we get bug reports when
we break it.

--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com

If only the physical world exists, free will is an illusion.

#5Shmuel Kamensky
shmuelkamensky@gmail.com
In reply to: Bruce Momjian (#4)
Re: C++ Trigger Framework

OK, great thank you, Buce! I'll check back in with any interesting results
when I have something running (probably in a few months to a year since I
don't yet know C++ very well :-)).