Module: LunaPark::Extensions::Repositories::Postgres::Read
- Defined in:
- lib/luna_park/extensions/repositories/postgres/read.rb
Instance Method Summary collapse
- #all(**scope) ⇒ Object
- #count(**scope) ⇒ Object
- #find(pk_value, **scope) ⇒ Object
- #find!(pk_value, **scope) ⇒ Object
- #first(**scope) ⇒ Object
- #last(**scope) ⇒ Object
- #lock(pk_value) ⇒ Object
- #lock!(pk_value) ⇒ Object
- #transaction(&block) ⇒ Object
Instance Method Details
#all(**scope) ⇒ Object
32 33 34 |
# File 'lib/luna_park/extensions/repositories/postgres/read.rb', line 32 def all(**scope) read_all(scoped(**scope).order { created_at.desc }) end |
#count(**scope) ⇒ Object
28 29 30 |
# File 'lib/luna_park/extensions/repositories/postgres/read.rb', line 28 def count(**scope) scoped(**scope).count end |
#find(pk_value, **scope) ⇒ Object
24 25 26 |
# File 'lib/luna_park/extensions/repositories/postgres/read.rb', line 24 def find(pk_value, **scope) read_one scoped(**scope).where(primary_key => pk_value) end |
#find!(pk_value, **scope) ⇒ Object
20 21 22 |
# File 'lib/luna_park/extensions/repositories/postgres/read.rb', line 20 def find!(pk_value, **scope) found! find(pk_value, **scope), not_found_by: pk_value end |
#first(**scope) ⇒ Object
36 37 38 |
# File 'lib/luna_park/extensions/repositories/postgres/read.rb', line 36 def first(**scope) read_one scoped(**scope).order(:created_at).first end |
#last(**scope) ⇒ Object
40 41 42 |
# File 'lib/luna_park/extensions/repositories/postgres/read.rb', line 40 def last(**scope) read_one scoped(**scope).order(:created_at).last end |
#lock(pk_value) ⇒ Object
12 13 14 |
# File 'lib/luna_park/extensions/repositories/postgres/read.rb', line 12 def lock(pk_value) transaction { yield find pk_value, for_update: true } end |
#lock!(pk_value) ⇒ Object
8 9 10 |
# File 'lib/luna_park/extensions/repositories/postgres/read.rb', line 8 def lock!(pk_value) transaction { yield find! pk_value, for_update: true } end |
#transaction(&block) ⇒ Object
16 17 18 |
# File 'lib/luna_park/extensions/repositories/postgres/read.rb', line 16 def transaction(&block) dataset.transaction(&block) end |