Class: Lotus::Model::Adapters::Sql::Command Private

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/model/adapters/sql/command.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.

Execute a command for the given query.

See Also:

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(query) ⇒ Command

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 command

Parameters:

Since:

  • 0.1.0



18
19
20
# File 'lib/lotus/model/adapters/sql/command.rb', line 18

def initialize(query)
  @collection = query.scoped
end

Instance Method Details

#create(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.

Parameters:

  • entity (Object)

    the entity to persist

Returns:

  • the primary key of the just created record.

See Also:

Since:

  • 0.1.0



32
33
34
# File 'lib/lotus/model/adapters/sql/command.rb', line 32

def create(entity)
  @collection.insert(entity)
end

#deleteObject Also known as: clear

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.

Deletes all the records for the current query.

It’s used to delete a single record or an entire database table.



57
58
59
# File 'lib/lotus/model/adapters/sql/command.rb', line 57

def delete
  @collection.delete
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 corresponding record for the given entity.

Parameters:

  • entity (Object)

    the entity to persist

See Also:

Since:

  • 0.1.0



44
45
46
# File 'lib/lotus/model/adapters/sql/command.rb', line 44

def update(entity)
  @collection.update(entity)
end