Module: E621::CsvImportable

Extended by:
T::Sig
Included in:
Artist, BulkUpdateRequest, Pool, Post, PostReplacement, PostVersion, Tag, TagAlias, TagImplication, WikiPage
Defined in:
lib/e621/csv_importable.rb

Instance Method Summary collapse

Instance Method Details

#import_from_csv(csv_path, truncate: false, recreate_indexes: false, chunk_bytes: 1 << 20) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/e621/csv_importable.rb', line 45

def import_from_csv(csv_path, truncate: false, recreate_indexes: false, chunk_bytes: 1 << 20)
  model = T.unsafe(self)
  indexes = recreate_indexes ? secondary_index_definitions : {}

  model.connection.execute("TRUNCATE #{model.quoted_table_name}") if truncate
  indexes.each_key { |name| model.connection.execute("DROP INDEX IF EXISTS #{name}") }

  count = copy_csv(csv_path, chunk_bytes: chunk_bytes)

  indexes.each_value { |ddl| model.connection.execute(ddl) }
  self.row_count = count
  count
end

#row_countObject



9
10
11
# File 'lib/e621/csv_importable.rb', line 9

def row_count
  E621::RowCount[T.unsafe(self).table_name.split(".").last]
end

#row_count=(count) ⇒ Object



14
15
16
# File 'lib/e621/csv_importable.rb', line 14

def row_count=(count)
  E621::RowCount.set(T.unsafe(self).table_name.split(".").last, count)
end