Module: Cyrel::Functions
- Defined in:
- lib/cyrel/functions.rb
Overview
Provides helper methods for creating Cypher function call expressions.
Constant Summary collapse
- ASTERISK =
Represents the Cypher ‘*’ literal, often used in count(*). We use a specific object to differentiate it from a string literal “*”.
Object.new
Class Method Summary collapse
- .avg(expression, distinct: false) ⇒ Object
-
.coalesce(*expressions) ⇒ Object
Returns the first non-null expression.
- .collect(expression, distinct: false) ⇒ Object
-
.count(expression, distinct: false) ⇒ Object
Because apparently, COUNT(*) isn’t obvious enough.
-
.element_id(node_variable) ⇒ Object
deprecated
Deprecated.
Use #node_id instead for adapter-aware ID handling
-
.id(node_variable) ⇒ Object
deprecated
Deprecated.
Use #node_id instead for adapter-aware ID handling
-
.labels(node_variable) ⇒ Object
Retrieves labels from a node.
- .max(expression) ⇒ Object
- .min(expression) ⇒ Object
-
.node_id(node_variable) ⇒ Object
Adapter-aware node ID function Generates a placeholder that will be replaced by the correct ID function at execution time based on the database adapter (Neo4j vs Memgraph) Because databases can’t agree on how to name their ID functions, we’ll just pretend they’re all the same and fix it later.
- .properties(variable) ⇒ Object
-
.size(expression) ⇒ Object
— List Functions — Add common list functions like size(), keys(), range(), etc.
-
.sum(expression, distinct: false) ⇒ Object
— Aggregation Functions —.
- .timestamp ⇒ Object
- .to_boolean(expression) ⇒ Object
- .to_float(expression) ⇒ Object
-
.to_integer(expression) ⇒ Object
Converts a thing into an integer.
- .to_string(expression) ⇒ Object
- .type(relationship_variable) ⇒ Object
Class Method Details
.avg(expression, distinct: false) ⇒ Object
100 101 102 |
# File 'lib/cyrel/functions.rb', line 100 def avg(expression, distinct: false) Expression::FunctionCall.new(:avg, expression, distinct: distinct) end |
.coalesce(*expressions) ⇒ Object
Returns the first non-null expression. The Cypher equivalent of settling.
68 69 70 |
# File 'lib/cyrel/functions.rb', line 68 def coalesce(*expressions) Expression::FunctionCall.new(:coalesce, expressions) end |
.collect(expression, distinct: false) ⇒ Object
112 113 114 |
# File 'lib/cyrel/functions.rb', line 112 def collect(expression, distinct: false) Expression::FunctionCall.new(:collect, expression, distinct: distinct) end |
.count(expression, distinct: false) ⇒ Object
Because apparently, COUNT(*) isn’t obvious enough. Handles the ‘give me everything and make it snappy’ use case.
42 43 44 45 46 47 48 49 50 |
# File 'lib/cyrel/functions.rb', line 42 def count(expression, distinct: false) # Handle count(*) specifically expr_arg = case expression when :* then ASTERISK when Symbol, String then Clause::Return::RawIdentifier.new(expression.to_s) # Convert symbol/string to RawIdentifier else expression # Assume it's already an Expression object (like PropertyAccess) end Expression::FunctionCall.new(:count, expr_arg, distinct: distinct) end |
.element_id(node_variable) ⇒ Object
Use #node_id instead for adapter-aware ID handling
Use elementId() instead of deprecated id()
22 23 24 |
# File 'lib/cyrel/functions.rb', line 22 def element_id(node_variable) Expression::FunctionCall.new(:elementId, Clause::Return::RawIdentifier.new(node_variable.to_s)) end |
.id(node_variable) ⇒ Object
Use #node_id instead for adapter-aware ID handling
27 28 29 |
# File 'lib/cyrel/functions.rb', line 27 def id(node_variable) Expression::FunctionCall.new(:id, Clause::Return::RawIdentifier.new(node_variable.to_s)) end |
.labels(node_variable) ⇒ Object
Retrieves labels from a node. You could also just… ask the node. But noooo. Instead, we call a function and pretend we’re not slowly dying inside.
54 55 56 |
# File 'lib/cyrel/functions.rb', line 54 def labels(node_variable) Expression::FunctionCall.new(:labels, node_variable) end |
.max(expression) ⇒ Object
108 109 110 |
# File 'lib/cyrel/functions.rb', line 108 def max(expression) Expression::FunctionCall.new(:max, expression) end |
.min(expression) ⇒ Object
104 105 106 |
# File 'lib/cyrel/functions.rb', line 104 def min(expression) Expression::FunctionCall.new(:min, expression) end |
.node_id(node_variable) ⇒ Object
Adapter-aware node ID function Generates a placeholder that will be replaced by the correct ID function at execution time based on the database adapter (Neo4j vs Memgraph) Because databases can’t agree on how to name their ID functions, we’ll just pretend they’re all the same and fix it later
36 37 38 |
# File 'lib/cyrel/functions.rb', line 36 def node_id(node_variable) Expression::FunctionCall.new(:__NODE_ID__, Clause::Return::RawIdentifier.new(node_variable.to_s)) end |
.properties(variable) ⇒ Object
62 63 64 |
# File 'lib/cyrel/functions.rb', line 62 def properties(variable) Expression::FunctionCall.new(:properties, variable) end |
.size(expression) ⇒ Object
— List Functions — Add common list functions like size(), keys(), range(), etc. as needed
119 120 121 |
# File 'lib/cyrel/functions.rb', line 119 def size(expression) Expression::FunctionCall.new(:size, expression) end |
.sum(expression, distinct: false) ⇒ Object
— Aggregation Functions —
96 97 98 |
# File 'lib/cyrel/functions.rb', line 96 def sum(expression, distinct: false) Expression::FunctionCall.new(:sum, expression, distinct: distinct) end |
.timestamp ⇒ Object
72 73 74 |
# File 'lib/cyrel/functions.rb', line 72 def Expression::FunctionCall.new(:timestamp) end |
.to_boolean(expression) ⇒ Object
90 91 92 |
# File 'lib/cyrel/functions.rb', line 90 def to_boolean(expression) Expression::FunctionCall.new(:toBoolean, expression) end |
.to_float(expression) ⇒ Object
86 87 88 |
# File 'lib/cyrel/functions.rb', line 86 def to_float(expression) Expression::FunctionCall.new(:toFloat, expression) end |
.to_integer(expression) ⇒ Object
Converts a thing into an integer. Great for when your data is having an identity crisis and just wants to be whole again.
82 83 84 |
# File 'lib/cyrel/functions.rb', line 82 def to_integer(expression) Expression::FunctionCall.new(:toInteger, expression) end |
.to_string(expression) ⇒ Object
76 77 78 |
# File 'lib/cyrel/functions.rb', line 76 def to_string(expression) Expression::FunctionCall.new(:toString, expression) end |
.type(relationship_variable) ⇒ Object
58 59 60 |
# File 'lib/cyrel/functions.rb', line 58 def type(relationship_variable) Expression::FunctionCall.new(:type, relationship_variable) end |