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

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

Overview

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

Constant Summary collapse

FUNCTIONS =
{
  char_length: "LENGTH", greatest: "MAX", least: "MIN",
  now: nil, date_trunc: nil, rand: "RANDOM",
  bit_and: nil, bit_or: nil, bit_xor: nil,
  localtime: nil, localtimestamp: nil,
}.freeze

Instance Method Summary collapse

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.



29
30
31
32
33
# File 'lib/active_record/refined/dialect/sqlite.rb', line 29

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

#check_lateral(model) ⇒ Object

Raises:

  • (NotImplementedError)


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

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

#datetime_precision_supported?Boolean

Returns:

  • (Boolean)


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

def datetime_precision_supported? = false

#extract_supported?Boolean

Returns:

  • (Boolean)


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

def extract_supported? = false

#json_aggregate_name(kind) ⇒ Object



46
47
48
# File 'lib/active_record/refined/dialect/sqlite.rb', line 46

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

#json_argument(value, _model) ⇒ Object



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

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

#json_keys(document, model) ⇒ Object



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

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

#quantifiers_supported?Boolean

Returns:

  • (Boolean)


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

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.



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

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