Module: ActiveRecord::Refined::Dialect::MysqlishJsonFunctions
- Included in:
- MysqlCompat, Sqlite
- Defined in:
- lib/active_record/refined/dialect/mysqlish_json_functions.rb
Overview
The JSON editing and building functions MySQL and SQLite spell alike: JSON_SET and JSON_REMOVE over a $ path, and JSON_ARRAY and JSON_OBJECT with each key alternating with its value. The spellings are MySQL's, which SQLite's json1 took over, and standard in neither sense of the word -- SQL:2016 gives JSON_OBJECT a KEY k VALUE v syntax and has no editing functions at all -- so they live here as a family likeness for the two to include, not in the base as a default for everyone.
Instance Method Summary collapse
- #json_build(kind, keys, args, _model) ⇒ Object
- #json_remove(document, dollar_paths, _steps, _model) ⇒ Object
- #json_set(document, _steps, dollar_path, value, expression, model) ⇒ Object
Instance Method Details
#json_build(kind, keys, args, _model) ⇒ Object
28 29 30 31 32 |
# File 'lib/active_record/refined/dialect/mysqlish_json_functions.rb', line 28 def json_build(kind, keys, args, _model) Arel::Nodes::NamedFunction.new( kind == :array ? "JSON_ARRAY" : "JSON_OBJECT", json_build_body(kind, keys, args)) end |
#json_remove(document, dollar_paths, _steps, _model) ⇒ Object
22 23 24 25 26 |
# File 'lib/active_record/refined/dialect/mysqlish_json_functions.rb', line 22 def json_remove(document, dollar_paths, _steps, _model) Arel::Nodes::NamedFunction.new( "JSON_REMOVE", [document, *dollar_paths.map { |path| Arel::Nodes.build_quoted(path) }]) end |
#json_set(document, _steps, dollar_path, value, expression, model) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/active_record/refined/dialect/mysqlish_json_functions.rb', line 15 def json_set(document, _steps, dollar_path, value, expression, model) Arel::Nodes::NamedFunction.new( "JSON_SET", [document, Arel::Nodes.build_quoted(dollar_path), json_set_value(value, expression, model)]) end |