Class: Lotus::Model::Adapters::Sql::Collection Private

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/lotus/model/adapters/sql/collection.rb

Overview

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

Maps a SQL database table and perfoms manipulations on it.

Instance Method Summary collapse

Constructor Details

#initialize(dataset, mapped_collection) ⇒ Lotus::Model::Adapters::Sql::Collection

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.

Initialize a collection

Parameters:

Since:

  • 0.1.0



27
28
29
30
# File 'lib/lotus/model/adapters/sql/collection.rb', line 27

def initialize(dataset, mapped_collection)
  super(dataset)
  @mapped_collection = mapped_collection
end

Instance Method Details

#exclude(*args) ⇒ Lotus::Model::Adapters::Sql::Collection

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.

Filters the current scope with an ‘exclude` directive.

Parameters:

  • args (Array)

    the array of arguments

Returns:

See Also:

Since:

  • 0.1.0



43
44
45
# File 'lib/lotus/model/adapters/sql/collection.rb', line 43

def exclude(*args)
  Collection.new(super, @mapped_collection)
end

#group(*args) ⇒ Lotus::Model::Adapters::Sql::Collection

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.

Filters the current scope with a ‘group` directive.

Parameters:

  • args (Array)

    the array of arguments

Returns:

See Also:

Since:

  • 0.5.0



172
173
174
# File 'lib/lotus/model/adapters/sql/collection.rb', line 172

def group(*args)
  Collection.new(super, @mapped_collection)
end

#identitySymbol

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.

Name of the identity column in database

Returns:

  • (Symbol)

    the identity name

Since:

  • 0.5.0



259
260
261
# File 'lib/lotus/model/adapters/sql/collection.rb', line 259

def identity
  @mapped_collection.identity
end

#insert(entity) ⇒ Object

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.

Creates a record for the given entity and assigns an id.

Parameters:

  • entity (Object)

    the entity to persist

Returns:

  • the primary key of the created record

See Also:

Since:

  • 0.1.0



57
58
59
60
61
62
# File 'lib/lotus/model/adapters/sql/collection.rb', line 57

def insert(entity)
  serialized_entity            = _serialize(entity)
  serialized_entity[identity] = super(serialized_entity)

  _deserialize(serialized_entity)
end

#join_table(*args) ⇒ Lotus::Model::Adapters::Sql::Collection

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.

Use join table for current scope



239
240
241
# File 'lib/lotus/model/adapters/sql/collection.rb', line 239

def join_table(*args)
  Collection.new(super, @mapped_collection)
end

#limit(*args) ⇒ Lotus::Model::Adapters::Sql::Collection

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.

Filters the current scope with a ‘limit` directive.

Parameters:

  • args (Array)

    the array of arguments

Returns:

See Also:

Since:

  • 0.1.0



75
76
77
# File 'lib/lotus/model/adapters/sql/collection.rb', line 75

def limit(*args)
  Collection.new(super, @mapped_collection)
end

#offset(*args) ⇒ Lotus::Model::Adapters::Sql::Collection

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.

Filters the current scope with an ‘offset` directive.

Parameters:

  • args (Array)

    the array of arguments

Returns:

See Also:

Since:

  • 0.1.0



90
91
92
# File 'lib/lotus/model/adapters/sql/collection.rb', line 90

def offset(*args)
  Collection.new(super, @mapped_collection)
end

#or(*args) ⇒ Lotus::Model::Adapters::Sql::Collection

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.

Filters the current scope with an ‘or` directive.

Parameters:

  • args (Array)

    the array of arguments

Returns:

See Also:

Since:

  • 0.1.0



105
106
107
# File 'lib/lotus/model/adapters/sql/collection.rb', line 105

def or(*args)
  Collection.new(super, @mapped_collection)
end

#order(*args) ⇒ Lotus::Model::Adapters::Sql::Collection

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.

Filters the current scope with an ‘order` directive.

Parameters:

  • args (Array)

    the array of arguments

Returns:

See Also:

Since:

  • 0.1.0



120
121
122
# File 'lib/lotus/model/adapters/sql/collection.rb', line 120

def order(*args)
  Collection.new(super, @mapped_collection)
end

#order_more(*args) ⇒ Lotus::Model::Adapters::Sql::Collection

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.

Filters the current scope with an ‘order` directive.

Parameters:

  • args (Array)

    the array of arguments

Returns:

See Also:

Since:

  • 0.1.0



135
136
137
# File 'lib/lotus/model/adapters/sql/collection.rb', line 135

def order_more(*args)
  Collection.new(super, @mapped_collection)
end

#select(*args) ⇒ Object

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.

Since:

  • 0.1.0



151
152
153
# File 'lib/lotus/model/adapters/sql/collection.rb', line 151

def select(*args)
  Collection.new(super, @mapped_collection)
end

#select_allLotus::Model::Adapters::Sql::Collection

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.

Select all attributes for current scope



226
227
228
# File 'lib/lotus/model/adapters/sql/collection.rb', line 226

def select_all
  Collection.new(super(table_name), @mapped_collection)
end

#table_nameString

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.

Return table name mapped collection

Returns:

  • (String)

    table name

Since:

  • 0.5.0



249
250
251
# File 'lib/lotus/model/adapters/sql/collection.rb', line 249

def table_name
  @mapped_collection.name
end

#to_aArray

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.

Resolves self by fetching the records from the database and translating them into entities.

Returns:

  • (Array)

    the result of the query

Since:

  • 0.1.0



213
214
215
# File 'lib/lotus/model/adapters/sql/collection.rb', line 213

def to_a
  @mapped_collection.deserialize(self)
end

#update(entity) ⇒ Object

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.

Updates the record corresponding to the given entity.

Parameters:

  • entity (Object)

    the entity to persist

See Also:

Since:

  • 0.1.0



199
200
201
202
203
204
# File 'lib/lotus/model/adapters/sql/collection.rb', line 199

def update(entity)
  serialized_entity = _serialize(entity)
  super(serialized_entity)

  _deserialize(serialized_entity)
end

#where(*args) ⇒ Lotus::Model::Adapters::Sql::Collection

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.

Filters the current scope with a ‘where` directive.

Parameters:

  • args (Array)

    the array of arguments

Returns:

See Also:

Since:

  • 0.1.0



187
188
189
# File 'lib/lotus/model/adapters/sql/collection.rb', line 187

def where(*args)
  Collection.new(super, @mapped_collection)
end