Class: AuctionFunCore::Repos::StaffContext::StaffRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/auction_fun_core/repos/staff_context/staff_repository.rb

Overview

SQL repository for staffs.

Instance Method Summary collapse

Instance Method Details

#allArray<ROM::Struct::Staff>, []

Returns all staffs in database.

Returns:

  • (Array<ROM::Struct::Staff>, [])


15
16
17
# File 'lib/auction_fun_core/repos/staff_context/staff_repository.rb', line 15

def all
  staffs.to_a
end

#by_id(id) ⇒ ROM::Struct::Staff?

Search staff in database by primary key.

Parameters:

  • id (Integer)

    Staff ID

Returns:

  • (ROM::Struct::Staff, nil)


35
36
37
# File 'lib/auction_fun_core/repos/staff_context/staff_repository.rb', line 35

def by_id(id)
  staffs.by_pk(id).one
end

#by_id!(id) ⇒ ROM::Struct::Auction

Search staffs in database by primary key.

Parameters:

  • id (Integer)

    Staff ID

Returns:

  • (ROM::Struct::Auction)

Raises:

  • (ROM::TupleCountMismatchError)

    if not found on database



43
44
45
# File 'lib/auction_fun_core/repos/staff_context/staff_repository.rb', line 43

def by_id!(id)
  staffs.by_pk(id).one!
end

#by_login(login) ⇒ ROM::Struct::Staff?

Search staff in database by email of phone keys.

Parameters:

  • login (String)

    Staff email or phone

Returns:

  • (ROM::Struct::Staff, nil)


50
51
52
# File 'lib/auction_fun_core/repos/staff_context/staff_repository.rb', line 50

def ()
  staffs.where(Sequel[email: ] | Sequel[phone: ]).one
end

#countInteger

Returns the total number of staffs in database.

Returns:

  • (Integer)


21
22
23
# File 'lib/auction_fun_core/repos/staff_context/staff_repository.rb', line 21

def count
  staffs.count
end

#exists?(conditions) ⇒ true, false

Checks if it returns any staff given one or more conditions.

Parameters:

  • conditions (Hash)

    DSL Dataset

Returns:

  • (true)

    when some staff is returned from the given condition.

  • (false)

    when no staff is returned from the given condition.



58
59
60
# File 'lib/auction_fun_core/repos/staff_context/staff_repository.rb', line 58

def exists?(conditions)
  staffs.exist?(conditions)
end

#query(conditions) ⇒ AuctionFunCore::Relations::Staffs

Mount SQL conditions in query for search in database.

Parameters:

  • conditions (Hash)

    DSL Dataset

Returns:



28
29
30
# File 'lib/auction_fun_core/repos/staff_context/staff_repository.rb', line 28

def query(conditions)
  staffs.where(conditions)
end