Skip to content

Commit

Permalink
Merge pull request #878 from neo4jrb/pretty_cypher
Browse files Browse the repository at this point in the history
Support outputting pretty cypher queries
  • Loading branch information
cheerfulstoic committed Jul 28, 2015
2 parents d1db024 + eae4c11 commit 173e26c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Metrics/AbcSize:
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 208
Max: 211

# Offense count: 768
# Configuration parameters: AllowURI, URISchemes.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Added ability to view `model_class` from `Association` class for `rails_admin` Neo4j adapter
- QueryProxy `where` will now look for declared properties matching hash keys. When found, it will send the value through that property's type converter if the type matches the property's unconverted state.
- Improved handling of unpersisted nodes with associations. You can now use `<<` to create associations between unpersisted nodes. A `save` will cascade through unpersisted objects, creating nodes and rels along the way. See https://github.com/neo4jrb/neo4j/pull/871
- Support formatted cypher queries for easy reading by humans via the `pretty_logged_cypher_queries` configuration variable
- On `QueryProxy` objects you can now use an `:id` key in `where` and `find_by` methods to refer to the property from `id_property` (`uuid` by default)

## [5.0.8] - 2015-07-26
Expand Down
5 changes: 5 additions & 0 deletions docs/Configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ Configuration
**Default:** ``nil`` (or ``Rails.logger`` in Rails)

A Ruby ``Logger`` object which is used to log Cypher queries (`info` level is used)

**pretty_logged_cypher_queries**
**Default:** ``nil``

If true, format outputted queries with newlines and colors to be more easily readable by humans
8 changes: 6 additions & 2 deletions lib/neo4j/active_node/query/query_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ def scoping
alias_method :order_by, :order

# Cypher string for the QueryProxy's query. This will not include params. For the full output, see <tt>to_cypher_with_params</tt>.
def to_cypher
query.to_cypher
def to_cypher(*args)
query.to_cypher(*args)
end

def print_cypher
query.print_cypher
end

# Returns a string of the cypher query with return objects and params
Expand Down
2 changes: 2 additions & 0 deletions lib/neo4j/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def open_neo4j_session(options)
def register_neo4j_cypher_logging
return if @neo4j_cypher_logging_registered

Neo4j::Core::Query.pretty_cypher = Neo4j::Config[:pretty_logged_cypher_queries]

Neo4j::Server::CypherSession.log_with do |message|
(Neo4j::Config[:logger] || Rails.logger).info message
end
Expand Down

0 comments on commit 173e26c

Please sign in to comment.