Class: Observ::JsonQueryable::JsonQuery
- Inherits:
-
Object
- Object
- Observ::JsonQueryable::JsonQuery
- Defined in:
- app/models/concerns/observ/json_queryable.rb
Overview
Internal class that generates database-specific SQL for JSON queries.
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
-
#extract_sql ⇒ Object
Returns SQL fragment for extracting the JSON value.
-
#initialize(connection, table_name, column, path) ⇒ JsonQuery
constructor
A new instance of JsonQuery.
-
#to_sql ⇒ Object
Returns SQL fragment for WHERE clause comparison (with placeholder).
Constructor Details
#initialize(connection, table_name, column, path) ⇒ JsonQuery
Returns a new instance of JsonQuery.
68 69 70 71 72 73 |
# File 'app/models/concerns/observ/json_queryable.rb', line 68 def initialize(connection, table_name, column, path) @connection = connection @table_name = table_name @column = column.to_s @path = path.to_s end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
66 67 68 |
# File 'app/models/concerns/observ/json_queryable.rb', line 66 def column @column end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
66 67 68 |
# File 'app/models/concerns/observ/json_queryable.rb', line 66 def connection @connection end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
66 67 68 |
# File 'app/models/concerns/observ/json_queryable.rb', line 66 def path @path end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
66 67 68 |
# File 'app/models/concerns/observ/json_queryable.rb', line 66 def table_name @table_name end |
Instance Method Details
#extract_sql ⇒ Object
Returns SQL fragment for extracting the JSON value
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/models/concerns/observ/json_queryable.rb', line 81 def extract_sql case adapter_name when /postgresql/i postgresql_extract when /sqlite/i sqlite_extract when /mysql|mariadb/i mysql_extract else # Fallback for unknown adapters - try PostgreSQL syntax postgresql_extract end end |
#to_sql ⇒ Object
Returns SQL fragment for WHERE clause comparison (with placeholder)
76 77 78 |
# File 'app/models/concerns/observ/json_queryable.rb', line 76 def to_sql "#{extract_sql} = ?" end |