Class: TableQuery::QuerySchema

Inherits:
Object
  • Object
show all
Defined in:
lib/table-query/query-schema.rb

Overview

QuerySchema defines query’s input and output field relation.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ QuerySchema

Create a query schema object.

Parameters:

  • name (Symbol)

    query name



34
35
36
37
38
39
40
# File 'lib/table-query/query-schema.rb', line 34

def initialize(name)
  @name = name
  @inputs = []
  @outputs = []
  @values = []
  @table = nil
end

Instance Attribute Details

#inputsArray<Field> (readonly)

input field list

Returns:



20
21
22
# File 'lib/table-query/query-schema.rb', line 20

def inputs
  @inputs
end

#nameSymbol (readonly)

query name

Returns:

  • (Symbol)


16
17
18
# File 'lib/table-query/query-schema.rb', line 16

def name
  @name
end

#outputsArray<Field> (readonly)

output field list

Returns:



24
25
26
# File 'lib/table-query/query-schema.rb', line 24

def outputs
  @outputs
end

#valuesArray<Field> (readonly)

preset value list

Returns:



28
29
30
# File 'lib/table-query/query-schema.rb', line 28

def values
  @values
end

Class Method Details

.define(name, &b) ⇒ QuerySchema

Define a new query schema.

Parameters:

  • name (Symbol)

    query name

Returns:



10
11
12
# File 'lib/table-query/query-schema.rb', line 10

def self.define(name, &b)
  new(name).tap {|x| x.instance_eval(&b)}
end

Instance Method Details

#input(name, options = {}) ⇒ void

This method returns an undefined value.

Define an input field.

Parameters:

  • name (Symbol)

    field name

  • options (Hash) (defaults to: {})

    input options



49
50
51
# File 'lib/table-query/query-schema.rb', line 49

def input(name, options={})
  @inputs << Field.new(name, nil, nil, nil, options)
end

#output(name, options = {}) ⇒ void

This method returns an undefined value.

Define an output field.

Parameters:

  • name (Symbol)

    field name

  • options (Hash) (defaults to: {})

    output options



60
61
62
# File 'lib/table-query/query-schema.rb', line 60

def output(name, options={})
  @outputs << Field.new(name, nil, nil, nil, options)
end

#set_table(table) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Set target table for query.

Parameters:

  • table (Table)

    query target table



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/table-query/query-schema.rb', line 83

def set_table(table)
  @table = table
  @table.table_schema.fields.each do |field|
    (@inputs + @outputs + @values).each do |item|
      if field.name == item.name
        item.pos = field.pos
        item.type = @table.types[field.type]
      end
    end
  end
end

#value(name, val, options = {}) ⇒ void

This method returns an undefined value.

Define pre set value of the query.

Parameters:

  • name (Symbol)

    field name

  • val (Object)

    table data

  • options (Hash) (defaults to: {})

    value options



73
74
75
# File 'lib/table-query/query-schema.rb', line 73

def value(name, val, options={})
  @values << Field.new(name, nil, nil, val, options)
end