Skip to content

Database Notification Improvements #1008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 27 commits into from

Conversation

bigmontz
Copy link
Contributor

@bigmontz bigmontz commented Oct 19, 2022

Cypher are improving the notifications that are produced by query execution by making it configurable what level of notifications can be returned and adding additional information to notifications.

Usage:

const neo4j from 'neo4j-driver'

// Configuring at the driver level
const driver = neo4j.driver(<ADDRESS>, <TOKEN>, { 
    notificationFilters: [ neo4j.notificationFilter.WARNING.ALL ]
})

// Configuring a the session level
const session = driver.session({
    database: 'neo4j',
    notificationFilters: [ 
       neo4j.notificationFilter.WARNING.ALL,
       neo4j.notificationFilter.INFORMANTION.QUERY
    ]
})

// Configuring using plain string.
const session = driver.session({
    database: 'neo4j',
    notificationFilters: [ 
       'WARNING.ALL',
       'INFORMANTION.QUERY'
    ]
})


const { summary }  = await session.executeWrite(tx => tx.run(<QUERY>, <PARAMS>))

// Reading notifications
for (const notification of summary.notifications) {
     switch(notification.severityLevel) {
          case neo4j.notificationSeverityLevel.INFORMATION: // or simply 'INFORMATION'
              console.info(`[${notification.category}] ${notification.title} - ${notification.description}`)
              break
          case neo4j.notificationSeverityLevel.WARNING: // or simply 'WARNING'
              console.warn(`[${notification.category}]${notification.title} - ${notification.description}`)
              break
          case neo4j.notificationSeverityLevel.UNKNOWN: // or simply 'UNKNOWN'
          default:
              // the raw info came from the server could be found at notification.rawSeverityLevel
              console.log(`[${notification.category}]${notification.title} - ${notification.description}`)
              break
     }
}

More details in the methods documentation and type signature.

@bigmontz bigmontz marked this pull request as ready for review November 4, 2022 14:20
@robsdedude robsdedude self-requested a review November 7, 2022 11:29
if (notificationFilters != null) {
const error = newError(
'Driver is connected to the database that does not support user notification filters. ' +
'Please upgrade to neo4j 5.3.0 or later in order to use this functionality. ' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not yet clear if this feature will make it into 5.3 or later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will hold this comment/pr until we have the functionality merged in the server and we know which version it will be part of.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 just make sure to not forget to update the parts of the PR that mention the version (also some doc comments).

@@ -216,7 +216,9 @@ class SessionConfig {
* // using default server configuration
* const sessionWithSeverDefaultNotifications = driver.session({ database:'neo4j', notificationFilters: neo4j.notificationFilter.serverDefault() })
* // EQUIVALENT TO: const sessionWithSeverDefaultNotifications = driver.session({ database:'neo4j', notificationFilters: ["SERVER_DEFAULT"] })
* // OR SIMPLY: const sessionWithSeverDefaultNotifications = driver.session({ database:'neo4j' })
*
* // using default configured in the connection/driver configuration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* // using default configured in the connection/driver configuration
* // using whatever filters were configured for the {@link Driver} (default behavior)

@bigmontz
Copy link
Contributor Author

Replaced by #1064

@bigmontz bigmontz closed this Mar 16, 2023
@bigmontz bigmontz deleted the 5.x-notifications branch March 16, 2023 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants