hgourvest / node-firebird

Pure javascript and asynchronous Firebird client for Node.js.
Mozilla Public License 2.0
252 stars 124 forks source link

Listen for Firebird events #28

Open claytonaalves opened 10 years ago

claytonaalves commented 10 years ago

Is there a way to listen for Firebird events ?

petersirka commented 9 years ago

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.

mariuz commented 9 years ago

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/

claytonaalves commented 9 years ago

Yes. That's what I meant.

jacobalberty commented 8 years ago

This is definitely a much needed feature.

pabloruan0710 commented 7 years ago

somebody works with firebird events ? in php has ibase_set_event_handler

mreis1 commented 7 years ago

+1

sdnetwork commented 7 years ago

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')
    })
})
claytonaalves commented 7 years ago

Working as expected. Good work.

pabloruan0710 commented 7 years ago

@sdnetwork have limit for registerEvent ?

sdnetwork commented 7 years ago

i dont't know why ?

pabloruan0710 commented 7 years ago

Just a question!

beletot commented 6 years ago

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 ?

claytonaalves commented 6 years ago

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

pabloruan0710 commented 6 years ago

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

slachtar commented 4 years ago

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

lukaas25 commented 3 years ago

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

mreis1 commented 3 years ago

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

lukaas25 commented 3 years ago

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

balenaultra commented 3 years ago

@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?

lukaas25 commented 3 years ago

@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) }) })

balenaultra commented 3 years ago

console.log(name,count)

which package? hgourvest or sdnetwork ?

lukaas25 commented 3 years ago

@balenaultra sdnetwork package

cesarramirez1912 commented 3 years ago

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

lukaas25 commented 3 years ago

@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

mreis1 commented 3 years ago

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 ?

eduardochiletto commented 2 years ago

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

mreis1 commented 2 years ago

@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.