Class: Sequel::SQLite::Dataset

Inherits:
Dataset show all
Defined in:
lib/sequel/adapters/sqlite.rb

Constant Summary collapse

EXPLAIN =
'EXPLAIN %s'.freeze

Constants inherited from Dataset

Dataset::NOTIMPL_MSG, Dataset::STOCK_TRANSFORMS

Constants included from Dataset::Convenience

Dataset::Convenience::COMMA_SEPARATOR, Dataset::Convenience::MAGIC_METHODS, Dataset::Convenience::MUTATION_RE, Dataset::Convenience::NAKED_HASH

Constants included from Dataset::SQL

Dataset::SQL::ALIASED_REGEXP, Dataset::SQL::AND_SEPARATOR, Dataset::SQL::COMMA_SEPARATOR, Dataset::SQL::DATE_FORMAT, Dataset::SQL::FALSE, Dataset::SQL::JOIN_TYPES, Dataset::SQL::NULL, Dataset::SQL::QUALIFIED_REGEXP, Dataset::SQL::QUESTION_MARK, Dataset::SQL::STOCK_COUNT_OPTS, Dataset::SQL::TIMESTAMP_FORMAT, Dataset::SQL::TRUE, Dataset::SQL::WILDCARD

Constants included from Dataset::Sequelizer

Dataset::Sequelizer::JOIN_AND, Dataset::Sequelizer::JOIN_COMMA

Instance Attribute Summary

Attributes inherited from Dataset

#db, #opts

Attributes included from Dataset::Convenience

#current_page, #page_count, #page_size, #pagination_record_count

Instance Method Summary collapse

Methods inherited from Dataset

#<<, #clone_merge, #columns, dataset_classes, #each, #extend_with_destroy, inherited, #initialize, #model_classes, #naked, #polymorphic_key, #remove_row_proc, #set, #set_model, #set_options, #set_row_proc, #transform, #transform_load, #transform_save, #update_each_method

Methods included from Dataset::Convenience

#[], #[]=, #avg, #create_or_replace_view, #create_view, #current_page_record_count, #current_page_record_range, #each_hash, #empty?, #first, #group_and_count, #interval, #last, #magic_method_missing, #map, #max, #method_missing, #min, #multi_insert, #next_page, #page_range, #paginate, #prev_page, #print, #query, #range, #set_pagination_info, #single_record, #single_value, #sum, #to_csv, #to_hash

Methods included from Dataset::SQL

#and, #column_list, #count, #delete_sql, #except, #exclude, #exists, #expression_list, #filter, #from, #full_outer_join, #group, #having, #inner_join, #insert_multiple, #intersect, #invert_order, #join_expr, #join_table, #left_outer_join, #limit, #or, #order, #qualified_column_name, #quote_column_ref, #reverse_order, #right_outer_join, #select, #select_sql, #source_list, #to_table_reference, #union, #uniq, #update_sql, #where

Methods included from Dataset::Sequelizer

#call_expr, #compare_expr, #eval_expr, #ext_expr, #fcall_expr, #iter_expr, #match_expr, #proc_to_sql, #pt_expr, #replace_dvars, #unfold_each_expr, #value_to_parse_tree, #vcall_expr

Methods included from Enumerable

#send_each

Constructor Details

This class inherits a constructor from Sequel::Dataset

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Sequel::Dataset::Convenience

Instance Method Details

#array_tuples_fetch_rows(sql, &block) ⇒ Object



155
156
157
158
159
160
# File 'lib/sequel/adapters/sqlite.rb', line 155

def array_tuples_fetch_rows(sql, &block)
  @db.execute_select(sql) do |result|
    @columns = result.columns.map {|c| c.to_sym}
    result.each {|r| r.keys = @columns; block[r]}
  end
end

#delete(opts = nil) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/sequel/adapters/sqlite.rb', line 170

def delete(opts = nil)
  # check if no filter is specified
  unless (opts && opts[:where]) || @opts[:where]
    @db.transaction do
      unfiltered_count = count
      @db.execute delete_sql(opts)
      unfiltered_count
    end
  else
    @db.execute delete_sql(opts)
  end
end

#explainObject



185
186
187
188
189
# File 'lib/sequel/adapters/sqlite.rb', line 185

def explain
  res = []
  @db.result_set(EXPLAIN % select_sql(opts), nil) {|r| res << r}
  res
end

#fetch_rows(sql, &block) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/sequel/adapters/sqlite.rb', line 143

def fetch_rows(sql, &block)
  @db.execute_select(sql) do |result|
    @columns = result.columns.map {|c| c.to_sym}
    column_count = @columns.size
    result.each do |values|
      row = {}
      column_count.times {|i| row[@columns[i]] = values[i]}
      block.call(row)
    end
  end
end

#insert(*values) ⇒ Object



162
163
164
# File 'lib/sequel/adapters/sqlite.rb', line 162

def insert(*values)
  @db.execute_insert insert_sql(*values)
end

#insert_sql(*values) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/sequel/adapters/sqlite.rb', line 135

def insert_sql(*values)
  if (values.size == 1) && values.first.is_a?(Sequel::Dataset)
    "INSERT INTO #{@opts[:from]} #{values.first.sql};"
  else
    super(*values)
  end
end

#literal(v) ⇒ Object



126
127
128
129
130
131
132
133
# File 'lib/sequel/adapters/sqlite.rb', line 126

def literal(v)
  case v
  when Time
    literal(v.iso8601)
  else
    super
  end
end

#update(*args, &block) ⇒ Object



166
167
168
# File 'lib/sequel/adapters/sqlite.rb', line 166

def update(*args, &block)
  @db.execute update_sql(*args, &block)
end