imarc/devour
最新稳定版本:3.3.1
Composer 安装命令:
composer require imarc/devour
包简介
An SQL database synchronizer
README 文档
README
$sync = new Devour\Synchronizer(); $table = new Devour\Mapping('events'); $table->addKey('id') $table->setSource('evmas'); $table->setParam('tracker_limit', date('Y-m-d', strtotime('-1 year'))); $table->addJoin('vendor', 'firm', ['vendor = firm.id']); $table->addField('id', 'evmas.control'); $table->addFilter('highlights', 'evmas.majordesc'); $table->addWhere("exclude_from_catalog != 'Y'"); $table->addWhere("end_date >= '{{ tracker_limit }}'"); $sync->addTable($table); $sync->run('events')
CSV Source Imports
Use Devour\Importer for file workflows. It extends Synchronizer, uses a single database connection for both source and destination, and stages file data in the destination database through a pluggable file driver.
$sync = new Devour\Importer($database); $mapping = new Devour\Mapping('placeholder', 'events', 'id'); $mapping ->setFileConfig('csv', [ 'path' => '/path/to/events.csv', 'header' => true, 'delimiter' => ',', 'enclosure' => '"', 'escape' => '\\', 'alias' => 'csvsrc' ]) ->addField('id', 'csvsrc.id') ->addField('title', 'csvsrc.title') ->addField('start_date', 'csvsrc.start_date') ->addWhere('csvsrc.id IS NOT NULL') ; $sync->addMapping($mapping); $sync->runWithDriver(new Devour\CsvDriver(), ['events']);
Example with explicit columns definitions:
$mapping->setFileConfig('csv', [ 'path' => '/path/to/events.csv', 'header' => true, 'alias' => 'csvsrc', 'columns' => [ 'id' => 'integer', 'title' => 'text', 'start_date' => 'date', 'price' => 'numeric(10,2)' ] ]);
Example .jin mapping for CSV imports (recommended persistent = true):
[devour.map] target = events key = id source = csvsrc persistent = true fields = { "id" : "csvsrc.id", "title" : "csvsrc.title", "start_date" : "csvsrc.start_date" } [&.csv] path = env('EVENTS_CSV', '/path/to/events.csv') header = true delimiter = "," enclosure = "\"" escape = "\\" alias = "csvsrc"
Custom file drivers can implement Devour\FileDriver and be passed to Devour\Importer::runWithDriver() in place of Devour\CsvDriver.
Notes:
- CSV data is materialized into a temporary staging table on the destination database before synchronization.
Importeraccepts a generic file driver at runtime viarunWithDriver(FileDriver $driver, ...);CsvDriveris the default implementation for CSV imports.Mappingis file-driver agnostic; provide file settings withsetFileConfig('<type>', [...]).- For CSV imports, you can optionally pass
columnsinsetFileConfig('csv', ...)to control temporary table column definitions. - CSV mapping joins execute on the destination database, so join targets must be destination-accessible tables.
- IMPORTANT: set CSV mappings as persistent (
setPersistent(true)in PHP orpersistent = truein.jin) if you need to preserve existing destination rows not present in the CSV.- If
persistentis not set, normal sync delete behavior can remove destination rows that do not appear in the current CSV import.
- If
统计信息
- 总下载量: 8.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-01