Class: Sequel::Dataset

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

Instance Method Summary collapse

Instance Method Details

#async_allObject



116
117
118
119
120
121
122
123
124
125
# File 'lib/sequel/async.rb', line 116

def async_all
  async_fetch_rows(sql, :all) do |rows|
    if row_proc = @row_proc
      yield(rows.map{|r| row_proc.call(r) })
    else
      yield(rows)
    end
  end
  nil
end

#async_count(&cb) ⇒ Object



127
128
129
130
131
132
133
134
135
136
# File 'lib/sequel/async.rb', line 127

def async_count &cb
  if options_overlap(COUNT_FROM_SELF_OPTS)
    from_self.async_count(&cb)
  else
    clone(STOCK_COUNT_OPTS).async_each{|r|
      yield r.is_a?(Hash) ? r.values.first.to_i : r.values.values.first.to_i
    }
  end
  nil
end

#async_delete(&cb) ⇒ Object



68
69
70
71
# File 'lib/sequel/async.rb', line 68

def async_delete &cb
  EventedMysql.execute delete_sql, &cb
  nil
end

#async_eachObject



105
106
107
108
109
110
111
112
113
114
# File 'lib/sequel/async.rb', line 105

def async_each
  async_fetch_rows(select_sql, :each) do |r|
    if row_proc = @row_proc
      yield row_proc.call(r)
    else
      yield r
    end
  end
  nil
end

#async_fetch_rows(sql, iter = :each) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/sequel/async.rb', line 83

def async_fetch_rows sql, iter = :each
  EventedMysql.raw(sql) do |m|
    r = m.result

    i = -1
    cols = r.fetch_fields.map{|f| [output_identifier(f.name), Sequel::MySQL::MYSQL_TYPES[f.type], i+=1]}
    @columns = cols.map{|c| c.first}
    rows = []
    while row = r.fetch_row
      h = {}
      cols.each{|n, p, i| v = row[i]; h[n] = (v && p) ? p.call(v) : v}
      if iter == :each
        yield h
      else
        rows << h
      end
    end
    yield rows if iter == :all
  end
  nil
end

#async_insert(*args, &cb) ⇒ Object



53
54
55
56
# File 'lib/sequel/async.rb', line 53

def async_insert *args, &cb
  EventedMysql.insert insert_sql(*args), &cb
  nil
end

#async_insert_ignore(*args, &cb) ⇒ Object



58
59
60
61
# File 'lib/sequel/async.rb', line 58

def async_insert_ignore *args, &cb
  EventedMysql.insert insert_ignore.insert_sql(*args), &cb
  nil
end

#async_multi_insert(*args, &cb) ⇒ Object



73
74
75
76
# File 'lib/sequel/async.rb', line 73

def async_multi_insert *args, &cb
  EventedMysql.execute multi_insert_sql(*args).first, &cb
  nil
end

#async_multi_insert_ignore(*args, &cb) ⇒ Object



78
79
80
81
# File 'lib/sequel/async.rb', line 78

def async_multi_insert_ignore *args, &cb
  EventedMysql.execute insert_ignore.multi_insert_sql(*args).first, &cb
  nil
end

#async_update(*args, &cb) ⇒ Object



63
64
65
66
# File 'lib/sequel/async.rb', line 63

def async_update *args, &cb
  EventedMysql.update update_sql(*args), &cb
  nil
end