Class: Query

Inherits:
Object
  • Object
show all
Defined in:
lib/eno.rb

Instance Method Summary collapse

Constructor Details

#initialize(**ctx, &block) ⇒ Query

Returns a new instance of Query.



370
371
372
373
# File 'lib/eno.rb', line 370

def initialize(**ctx, &block)
  @ctx = ctx
  @block = block
end

Instance Method Details

#as(sym) ⇒ Object



380
381
382
# File 'lib/eno.rb', line 380

def as(sym)
  Alias.new(self, sym)
end

#mutate(&block) ⇒ Object



392
393
394
395
396
397
398
# File 'lib/eno.rb', line 392

def mutate(&block)
  old_block = @block
  Query.new(@ctx) {
    instance_eval(&old_block)
    instance_eval(&block)
  }
end

#to_sql(**ctx) ⇒ Object



375
376
377
378
# File 'lib/eno.rb', line 375

def to_sql(**ctx)
  r = SQL.new(@ctx.merge(ctx))
  r.to_sql(&@block)
end

#where(&block) ⇒ Object



384
385
386
387
388
389
390
# File 'lib/eno.rb', line 384

def where(&block)
  old_block = @block
  Query.new(@ctx) {
    instance_eval(&old_block)
    where instance_eval(&block)
  }
end