Class: Observ::JsonQueryable::JsonQuery

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/observ/json_queryable.rb

Overview

Internal class that generates database-specific SQL for JSON queries.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#columnObject (readonly)

Returns the value of attribute column.



66
67
68
# File 'app/models/concerns/observ/json_queryable.rb', line 66

def column
  @column
end

#connectionObject (readonly)

Returns the value of attribute connection.



66
67
68
# File 'app/models/concerns/observ/json_queryable.rb', line 66

def connection
  @connection
end

#pathObject (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_nameObject (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_sqlObject

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_sqlObject

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