neo4j / neo4j-javascript-driver

Neo4j Bolt driver for JavaScript
https://neo4j.com/docs/javascript-manual/current/
Apache License 2.0
853 stars 148 forks source link

Introduce `resultTransformer.first` #1200

Closed bigmontz closed 3 months ago

bigmontz commented 3 months ago

⚠️ This API is released as preview. This function enables fetching only the first record in the Result. If any other record is present, it will be discarded and network optimization might be applied.

Examples:

// using in the execute query
const maybeFirstRecord = await driver.executeQuery('MATCH (p:Person{ age: $age }) RETURN p.name as name', { age: 25 }, {
    database: 'neo4j,
    resultTransformer: neo4j.resultTransformers.first()
})
// using in other a result

const maybeFirstRecord = await session.executeRead(tx => {
    // do not `await` or `resolve` the result before send it to the transformer
    const result = tx.run('MATCH (p:Person{ age: $age }) RETURN p.name as name', { age: 25 })
    return  neo4j.resultTransformers.first()(result)
})

⚠️ This API is released as preview.