{"action":"created","issue":{"url":"https://api.github.com/repos/BaseXdb/basex/issues/1082","labels_url":"https://api.github.com/repos/BaseXdb/basex/issues/1082/labels{/name}","comments_url":"https://api.github.com/repos/BaseXdb/basex/issues/1082/comments","events_url":"https://api.github.com/repos/BaseXdb/basex/issues/1082/events","html_url":"https://github.com/BaseXdb/basex/issues/1082","id":58254425,"number":1082,"title":"Database Triggers","user":{"login":"ChristianGruen","id":196589,"avatar_url":"https://avatars.githubusercontent.com/u/196589?v=3","gravatar_id":"","url":"https://api.github.com/users/ChristianGruen","html_url":"https://github.com/ChristianGruen","followers_url":"https://api.github.com/users/ChristianGruen/followers","following_url":"https://api.github.com/users/ChristianGruen/following{/other_user}","gists_url":"https://api.github.com/users/ChristianGruen/gists{/gist_id}","starred_url":"https://api.github.com/users/ChristianGruen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChristianGruen/subscriptions","organizations_url":"https://api.github.com/users/ChristianGruen/orgs","repos_url":"https://api.github.com/users/ChristianGruen/repos","events_url":"https://api.github.com/users/ChristianGruen/events{/privacy}","received_events_url":"https://api.github.com/users/ChristianGruen/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/BaseXdb/basex/labels/feature","name":"feature","color":"f06040"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-02-19T19:15:50Z","updated_at":"2015-05-26T13:13:57Z","closed_at":null,"body":"Allow definition of database triggers to react on changes in a database (creations, updates, deletions).\r\n\r\nOpen questions:\r\n\r\n1. What is the smallest observable unit? A Resource? Arbitrary XML nodes?\r\n2. Is it sufficient to work with affected resource paths, or do we also want to cache and return updated nodes?\r\n3. How are triggers defined? As independent XQuery expressions?\r\n4. How are errors treated that occur during trigger execution?\r\n  * Will the original transaction return an error?\r\n  * Will another transaction be triggered?\r\n  * Will it only be remembered in the database log files?\r\n5. If we remove the current database event architecture, do we still want to inform clients on changes, or do we use something else like web sockets?\r\n\r\n**Database Commands:**\r\n\r\n```\r\nOPEN db\r\nTRIGGER INSTALL trigger.xq delete\r\nTRIGGER DELETE trigger.xq\r\nTRIGGER LIST\r\n```\r\n\r\n**XQuery:**\r\n\r\n```xquery\r\nlet $db := 'db'\r\nlet $code := 'push-it.xq'\r\nlet $operation := 'delete'\r\nreturn trigger:install($db, $code, $operation)\r\n```\r\n\r\n**Trigger Query (trigger.xq):**\r\n\r\n```xquery\r\ndeclare variable $db as xs:string external;\r\ndeclare variable $resources as xs:string* external;\r\ndeclare variable $operation as xs:string external;\r\nadmin:write-log(\r\n  \"Operation: \" || $operation ||\r\n  \", Database: \" || $db\r\n  \", Resources: \" || count($resources)\r\n)\r\n```\r\n\r\nFeedback is welcome!"},"comment":{"url":"https://api.github.com/repos/BaseXdb/basex/issues/comments/105521239","html_url":"https://github.com/BaseXdb/basex/issues/1082#issuecomment-105521239","issue_url":"https://api.github.com/repos/BaseXdb/basex/issues/1082","id":105521239,"user":{"login":"dirkk","id":327759,"avatar_url":"https://avatars.githubusercontent.com/u/327759?v=3","gravatar_id":"","url":"https://api.github.com/users/dirkk","html_url":"https://github.com/dirkk","followers_url":"https://api.github.com/users/dirkk/followers","following_url":"https://api.github.com/users/dirkk/following{/other_user}","gists_url":"https://api.github.com/users/dirkk/gists{/gist_id}","starred_url":"https://api.github.com/users/dirkk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dirkk/subscriptions","organizations_url":"https://api.github.com/users/dirkk/orgs","repos_url":"https://api.github.com/users/dirkk/repos","events_url":"https://api.github.com/users/dirkk/events{/privacy}","received_events_url":"https://api.github.com/users/dirkk/received_events","type":"User","site_admin":false},"created_at":"2015-05-26T13:13:57Z","updated_at":"2015-05-26T13:13:57Z","body":"One of the reasons why I don't particularly liked the old event architecture is that such a loosely coupled integration is in my opinion not a job for a database system or query processor. What you can already do is to use some 3rd party tool like a message queue (ZeroMQ, ...), which could trigger such events and could get notified.\r\nGiven that such tools already exist, are highly performant and can be used to achieve the same effect (and much more) I personally would not re-add such an event trigger."}}