Class: ActiveRecord::Refined::Dialect::Sqlite

Inherits:
Dialect
  • Object
show all
Includes:
MysqlishJsonFunctions
Defined in:
lib/active_record/refined/dialect/sqlite.rb

Overview

SQLite: the fewest of the extras, and a JSON path through its own operators.

Instance Method Summary collapse

Methods included from MysqlishJsonFunctions

#json_build, #json_remove, #json_set

Instance Method Details

#add_interval(date, amount, unit, subtract, date_only) ⇒ Object

A date is moved by a modifier to date() or datetime(), '+3 day'; the unit's own name reads there, singular. datetime() answers with a time of day whatever it is given, so a date column, as the node tells one, goes through date() and stays a date.



33
34
35
36
37
# File 'lib/active_record/refined/dialect/sqlite.rb', line 33

def add_interval(date, amount, unit, subtract, date_only)
  modifier = format("%+d %s", subtract ? -amount : amount, unit)
  Arel::Nodes::NamedFunction.new(
    date_only ? "date" : "datetime", [date, Arel::Nodes.build_quoted(modifier)])
end

#bitwise_operators_supported?Boolean



22
# File 'lib/active_record/refined/dialect/sqlite.rb', line 22

def bitwise_operators_supported? = true

#check_lateral(model) ⇒ Object

Raises:

  • (NotImplementedError)


24
25
26
27
# File 'lib/active_record/refined/dialect/sqlite.rb', line 24

def check_lateral(model)
  raise NotImplementedError,
    "a lateral join has no equivalent on #{model.connection_db_config.adapter}"
end

#datetime_precision_supported?Boolean



19
# File 'lib/active_record/refined/dialect/sqlite.rb', line 19

def datetime_precision_supported? = false

#excluded(column, _model) ⇒ Object



69
70
71
# File 'lib/active_record/refined/dialect/sqlite.rb', line 69

def excluded(column, _model)
  AST::Column.new(:excluded, column)
end

#extract_supported?Boolean



20
# File 'lib/active_record/refined/dialect/sqlite.rb', line 20

def extract_supported? = false

#json_aggregate_name(kind) ⇒ Object



65
66
67
# File 'lib/active_record/refined/dialect/sqlite.rb', line 65

def json_aggregate_name(kind)
  kind == :arrayagg ? "json_group_array" : "json_group_object"
end

#json_argument(value, _model) ⇒ Object



60
61
62
63
# File 'lib/active_record/refined/dialect/sqlite.rb', line 60

def json_argument(value, _model)
  Arel::Nodes::NamedFunction.new(
    "json", [Arel::Nodes.build_quoted(JSON.generate(value))])
end

#json_has_key(document, _name, path, _model) ⇒ Object

json_type at the path answers NULL where nothing stands there.



50
51
52
# File 'lib/active_record/refined/dialect/sqlite.rb', line 50

def json_has_key(document, _name, path, _model)
  Arel::Nodes::NamedFunction.new("json_type", [document, path]).not_eq(nil)
end

#json_keys(document, model) ⇒ Object



54
55
56
57
58
# File 'lib/active_record/refined/dialect/sqlite.rb', line 54

def json_keys(document, model)
  sql = compile(document, model)
  Arel.sql("CASE WHEN json_type(#{sql}) = 'object' " \
           "THEN (SELECT json_group_array(key) FROM json_each(#{sql})) END")
end

#json_path(document, dollar_path, _steps, json_value, _model) ⇒ Object

-> keeps the value's type where ->> gives text, so dig_text casts to text only to make the comparison portable.



41
42
43
44
45
46
47
# File 'lib/active_record/refined/dialect/sqlite.rb', line 41

def json_path(document, dollar_path, _steps, json_value, _model)
  extracted = Arel::Nodes::InfixOperation.new(
    json_value ? :"->" : :"->>", document, Arel::Nodes.build_quoted(dollar_path))
  return extracted if json_value
  Arel::Nodes::NamedFunction.new(
    "CAST", [Arel::Nodes::As.new(extracted, Arel::Nodes::SqlLiteral.new("text"))])
end

#quantifiers_supported?Boolean



21
# File 'lib/active_record/refined/dialect/sqlite.rb', line 21

def quantifiers_supported? = false

#string_agg(operand, separator, orders, _string, model) ⇒ Object

group_concat, with the ORDER BY inside the call from 3.44 on.



74
75
76
# File 'lib/active_record/refined/dialect/sqlite.rb', line 74

def string_agg(operand, separator, orders, _string, model)
  string_agg_call("group_concat", operand, separator, orders, model)
end