sqlite icon indicating copy to clipboard operation
sqlite copied to clipboard

Modify hooks?

Open nkev opened this issue 7 years ago • 3 comments

This is very cool, thank you for sharing. One thing I would love to see are event hooks where I can register my custom function to be called after all INSERT, UPDATE and DELETE operations. Is that possible?

nkev avatar Apr 04 '18 00:04 nkev

This would be a wrapper for sqlite_preupdate_hook? Yes I think that's a good feature.

crawshaw avatar Apr 05 '18 16:04 crawshaw

If you look at the mxk driver, he allows setting hooks on commit, rollback, update, but also on busy.

https://github.com/mxk/go-sqlite/

You can see how he does it. He exports his go functions that accept a pointer to his Conn struct.

https://github.com/mxk/go-sqlite/blob/master/sqlite3/util.go#L357-L375

When I forked his driver, I ended up removing them, because they break a fundamental rule in go. You cannot pass a go pointer to a go pointer to C.

The way I've decided that you have to do it is by passing an integer index as your function data, and having a global go function handler that can take that index and find the proper callback in a map, like this:

https://github.com/golang/go/wiki/cgo#function-variables

bvinc avatar Aug 07 '18 14:08 bvinc

I may take a pass at implementing this. I have implemented a similar kind of registry for avoiding passing illegal go pointers to C.

AdamSLevy avatar Dec 10 '19 21:12 AdamSLevy