百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

active_importer

> 数据库
开源

定义导入器,将表格数据从电子表格或 CSV 文件加载到任何类似 ActiveRecord 的 ORM 中。

329 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

定义导入器,将表格数据从电子表格或 CSV 文件加载到任何类似 ActiveRecord 的 ORM 中。

ActiveImporter

ARCHIVED

Define importers that load tabular data from spreadsheets or CSV files into any ActiveRecord-like ORM.

Installation

Add this line to your application's Gemfile:

gem 'active_importer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_importer

Usage

Define classes that you instruct on how to import data into data models.

ruby
class EmployeeImporter < ActiveImporter::Base
  imports Employee

  column 'First name', :first_name
  column 'Last name', :last_name
  column 'Department', :department do |department_name|
    Department.find_by(name: department_name)
  end
end

The importer defines what data model it imports data into, and how columns in the data source map to fields in the model. Also, by providing a block, the source value can be processed before being stored, as shown with the 'Department' column in the example above.

Once defined, importers can be invoked to import a given data file.

ruby
EmployeeImporter.import('/path/to/file.xls')

The data file is expected to contain columns with titles corresponding to the columns declared. Any extra columns are ignored. Any errors while processing the data file does not interrupt the whole process. Instead, errors are notified via some callbacks defined in the importer (see below).

Documentation

For mote detailed information about the different aspects of importing data with active_importer, refer to the following sections in the wiki.

Getting started

  • Understanding how spreadsheets are parsed
  • Mapping columns to attributes

Diving in

  • Custom data processing
  • Helper methods
  • File extension and supported formats
  • Passing custom parameters
  • Events and callbacks
  • Selecting the model instance to import into (Update instead of create)
  • Error handling
  • Selecting the sheet to get data from
  • Skipping rows

Advanced features

  • Aborting the import process
  • Transactional importers

Contributing

Contributions are welcome! Take a look at our contributions guide for details.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyactiverecordcsv-filesdata-importimporter

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库