Class: Perpetuity::Postgres::QueryAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/perpetuity/postgres/query_attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ QueryAttribute

Returns a new instance of QueryAttribute.



9
10
11
# File 'lib/perpetuity/postgres/query_attribute.rb', line 9

def initialize name
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/perpetuity/postgres/query_attribute.rb', line 7

def name
  @name
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/perpetuity/postgres/query_attribute.rb', line 33

def any?
  QueryExpression.new count, :>, 0
end

#countObject



29
30
31
# File 'lib/perpetuity/postgres/query_attribute.rb', line 29

def count
  SQLFunction.new('json_array_length', self)
end

#idObject



41
42
43
# File 'lib/perpetuity/postgres/query_attribute.rb', line 41

def id
  QueryAttribute.new "#{name}->'__metadata__'->>'id'"
end

#in(collection) ⇒ Object



21
22
23
# File 'lib/perpetuity/postgres/query_attribute.rb', line 21

def in collection
  QueryExpression.new self, :in, collection
end

#nil?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/perpetuity/postgres/query_attribute.rb', line 25

def nil?
  QueryExpression.new self, :==, nil
end

#none?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/perpetuity/postgres/query_attribute.rb', line 37

def none?
  QueryExpression.new count, :==, 0
end

#to_dbObject



49
50
51
# File 'lib/perpetuity/postgres/query_attribute.rb', line 49

def to_db
  (self != nil).to_db
end

#to_sObject



45
46
47
# File 'lib/perpetuity/postgres/query_attribute.rb', line 45

def to_s
  name.to_s
end