node-firebird icon indicating copy to clipboard operation
node-firebird copied to clipboard

Listen for Firebird events

Open claytonaalves opened this issue 12 years ago • 31 comments

Is there a way to listen for Firebird events ?

claytonaalves avatar Aug 20 '13 17:08 claytonaalves

New version v0.2.0 supports events:

Firebird.attach(options, function(err, db) {

    if (err)
        throw err;

    db.on('row', function(row, index, isObject) {
        // index === Number
        // isObject === is row object or array?
    });

    db.on('result', function(result) {
        // result === Array
    });

    db.on('attach', function() {

    });

    db.on('detach', function(isPoolConnection) {
        // isPoolConnection == Boolean
    });

    db.on('reconnect', function() {

    });

    db.on('error', function(err) {

    });

    db.on('transaction', function(isolation) {
        // isolation === Number
    });

    db.on('commit', function() {

    });

    db.on('rollback', function() {

    });

    db.detach();
});

Thanks.

petersirka avatar Oct 14 '14 17:10 petersirka

I think he asks for Firebird internal events http://www.janus-software.com/fbmanual/manual.php?book=php&topic=49 http://mikejustin.wordpress.com/2012/11/06/firebird-database-events-and-message-oriented-middleware/ One example from the C++ node driver http://www.king-foo.be/2011/07/catch-firebird-events-with-node-js/

mariuz avatar Oct 15 '14 13:10 mariuz

Yes. That's what I meant.

claytonaalves avatar Oct 15 '14 18:10 claytonaalves

This is definitely a much needed feature.

jacobalberty avatar Feb 09 '16 04:02 jacobalberty

somebody works with firebird events ? in php has ibase_set_event_handler

pabloruan0710 avatar Nov 10 '16 18:11 pabloruan0710

+1

mreis1 avatar Jan 27 '17 09:01 mreis1

good news it's done you can try on https://github.com/sdnetwork/node-firebird

db.attachEvent( function (err, evtmgr) {
    if (err)
        return console.log('Error : ', err);

    evtmgr.on('post_event', function (name, count) {
        console.log("rec event", name, count);           
    })

    evtmgr.registerEvent(["evt1", "evt2"], function (err) {
        console.log('ready to receive evt1 and evt2')
    })

    evtmgr.unregisterEvent(["evt1"], function (err) {
         console.log('remove evt1, after that you only receive evt2')
    })
})

sdnetwork avatar Mar 20 '17 17:03 sdnetwork

Working as expected. Good work.

claytonaalves avatar Mar 21 '17 11:03 claytonaalves

@sdnetwork have limit for registerEvent ?

pabloruan0710 avatar Mar 21 '17 14:03 pabloruan0710

i dont't know why ?

sdnetwork avatar Mar 21 '17 21:03 sdnetwork

Just a question!

pabloruan0710 avatar Mar 21 '17 21:03 pabloruan0710

Hello, I would try to use the post_event option in firebird but can't find the function attachEvent. Is she still available in the last version of node-firebird ?

beletot avatar Jul 06 '17 12:07 beletot

@beletot Use the forked version from @sdnetwork ... @hgourvest hasn't merged the feature yet.

claytonaalves avatar Jul 07 '17 11:07 claytonaalves

Hi, yours have problem with events lost attach and not but received post_event after long time?

pabloruan0710 avatar Oct 31 '17 13:10 pabloruan0710

Hello, could someone tell me please, if the listening to firebird's post events feature implemented.

slachtar avatar Apr 08 '20 04:04 slachtar

Hi @sdnetwork, i'm use the node-firebird and the need to listen for events arises, when using flamerobin I see that the events are generated, but I cannot hear on the node. Is there any way to help me? Thank you very much. I'm Brazilian, sorry for my English

lukaas25 avatar Jul 05 '20 02:07 lukaas25

@slachtar @lukaas25 No but there are other nodejs libraries that give you that possibility

mreis1 avatar Jul 05 '20 15:07 mreis1

@slachtar thanks for the return, but I managed to monitor the events, this package helped a lot

lukaas25 avatar Jul 06 '20 13:07 lukaas25

@slachtar thanks for the return, but I managed to monitor the events, this package helped a lot

How do you do that? Using hgourvest package or sdnetwork?

balenaultra avatar Apr 29 '21 16:04 balenaultra

@balenaultra I did like this: Firebird.attach(options, async function(err, db) { if (err){ return console.log("error",err) }else{ db.attachEvent( function (err, evtmgr) { if (err) return console.log('Error : ', err);
evtmgr.registerEvent(["even_name"], function (error) {
if(error){ return error; } }) evtmgr.on('event_name', async function(name,count){ console.log(name,count) }) })

lukaas25 avatar May 01 '21 18:05 lukaas25

console.log(name,count)

which package? hgourvest or sdnetwork ?

balenaultra avatar May 03 '21 18:05 balenaultra

@balenaultra sdnetwork package

lukaas25 avatar May 04 '21 01:05 lukaas25

@lukaas25 voce quer pegar um evento tipo uma trigger? conseguiu? tambem estou querendo e nao estou conseguindo

cesarramirez1912 avatar May 11 '21 15:05 cesarramirez1912

@lukaas25 voce quer pegar um evento tipo uma trigger? conseguiu? tambem estou querendo e nao estou conseguindo

Isso, eu estou visualizando os eventos do banco, consegui sim, pelo código acima esta funcionando, usa o pacote do sdnetwork que vais conseguir

lukaas25 avatar May 14 '21 02:05 lukaas25

This was already mentioned but let's make it clear. hgourvest/node-firebird doesn't provide a way to capture events emitted through firebird's POST_EVENT (https://www.firebirdsql.org/file/documentation/papers_presentations/Power_Firebird_events.pdf).

Although, a fork of this project was created by sdnetwork and it's available here: https://github.com/sdnetwork/node-firebird

The method that allows to list for events is not documented in the project's readme.md file but you can see the implementation here: https://github.com/sdnetwork/node-firebird/blob/master/lib/index.js#L1778

In order to use that method you must install the sdnetwork library. Then, in order to import firebird you need to var Firebird = require('node-firebird-dev')

Then you will be able to use the implementation suggested by @lukaas25 above https://github.com/hgourvest/node-firebird/issues/28#issuecomment-830673752

Firebird.attach(options, async function(err, db) {
	if (err) {
		return console.log("error", err)
	} else {
		db.attachEvent(function(err, evtmgr) {
			if (err)
				return console.log('Error : ', err);

                         // Start listening for fb events here. In this case, this will fire if we call "POST_EVENT 'event_name'" from a trigger or from a stored procedure. 

			evtmgr.registerEvent(["event_name"], function(error) {
				if (error) {
					return error;
				}
			})

			evtmgr.on('event_name', async function(name, count) {
				console.log(name, count)
			})
		})
	}
})

Note: sdnetwork is not receiving any updates for a while now.

Still think it would be a great add to the project if we could bring sdnetwork attachEvent feature to this project. Don't you agree?

@hgourvest @mariuz ?

mreis1 avatar May 14 '21 08:05 mreis1

I think he asks for Firebird internal events http://www.janus-software.com/fbmanual/manual.php?book=php&topic=49 http://mikejustin.wordpress.com/2012/11/06/firebird-database-events-and-message-oriented-middleware/ One example from the C++ node driver http://www.king-foo.be/2011/07/catch-firebird-events-with-node-js/

TypeError: db.registerEvent is not a function

eduardochiletto avatar Jul 14 '21 22:07 eduardochiletto

@eduardochiletto as I said previously, you can't call registerEvent in node-firebird. You will have to install a fork (node-firebird-dev) created from this project to have such feature.

mreis1 avatar Jul 15 '21 07:07 mreis1