umpirsky/extraload

强大的ETL库。

0.1.0 2016-03-12 17:11 UTC

README

symfony upgrade fixertwig gettext extractorwisdomcentipedepermissions handlerextraloadgravatarlocurrocountry listtransliterator

Extraload Build Status Scrutinizer Code Quality

强大的ETL库。

示例

将CSV数据导出到控制台

输入数据为csv格式

"99921-58-10-7", "Divine Comedy", "Dante Alighieri"
"9971-5-0210-0", "A Tale of Two Cities", "Charles Dickens"
"960-425-059-0", "The Lord of the Rings", "J. R. R. Tolkien"
"80-902734-1-6", "And Then There Were None", "Agatha Christie"

使用

(new DefaultPipeline(
    new CsvExtractor(
        new \SplFileObject('books.csv')
    ),
    new NoopTransformer(),
    new ConsoleLoader(
        new Table(new ConsoleOutput())
    )
))->process();

可以将其作为表格导出到控制台

+---------------+--------------------------+------------------+
| 99921-58-10-7 | Divine Comedy            | Dante Alighieri  |
| 9971-5-0210-0 | A Tale of Two Cities     | Charles Dickens  |
| 960-425-059-0 | The Lord of the Rings    | J. R. R. Tolkien |
| 80-902734-1-6 | And Then There Were None | Agatha Christie  |
+---------------+--------------------------+------------------+

在这个示例中使用了 NoopTransformer,但可以应用各种转换。还可以使用 TransformerChain 链接转换器。

将Doctrine查询导出到控制台

首先确保将固定数据加载到数据库中--本例使用MySQL

mysql> source /home/standard/projects/Extraload/fixtures/mysql/books.sql

所以以下代码

(new DefaultPipeline(
    new QueryExtractor($conn, 'SELECT * FROM books'),
    new NoopTransformer(),
    new ConsoleLoader(
        new Table($output = new ConsoleOutput())
    )
))->process();

将结果导出到控制台

+---------------+--------------------------+------------------+
| 99921-58-10-7 | Divine Comedy            | Dante Alighieri  |
| 9781847493583 | La Vita Nuova            | Dante Alighieri  |
| 9971-5-0210-0 | A Tale of Two Cities     | Charles Dickens  |
| 960-425-059-0 | The Lord of the Rings    | J. R. R. Tolkien |
| 80-902734-1-6 | And Then There Were None | Agatha Christie  |
+---------------+--------------------------+------------------+

将Doctrine预查询导出到控制台

以下代码

// ...

$sql = "SELECT * FROM books WHERE author = :author";
$values = [
    [
        'parameter' => ':author',
        'value' => 'Dante Alighieri',
        'data_type' => PDO::PARAM_STR // optional
    ]
];

(new DefaultPipeline(
    new QueryExtractor($conn, $sql, $values),
    new NoopTransformer(),
    new ConsoleLoader(
        new Table($output = new ConsoleOutput())
    )
))->process();

将结果导出到控制台

+---------------+---------------+-----------------+
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
| 9781847493583 | La Vita Nuova | Dante Alighieri |
+---------------+---------------+-----------------+

将Doctrine查询导出到表格

以下代码

// ...

(new DefaultPipeline(
    new QueryExtractor($conn, 'SELECT * FROM books'),
    new NoopTransformer(),
    new DbalLoader($conn, 'my_books')
))->process();

将结果导出到 my_books

mysql> select * from my_books;
+----------------+--------------------------+----------------------------+
| isbn           | title                    | author                     |
+----------------+--------------------------+----------------------------+
| 9781503262140  | Faust                    | Johann Wolfgang von Goethe |
| 978-0156949606 | The Waves                | Virgina Woolf              |
| 99921-58-10-7  | Divine Comedy            | Dante Alighieri            |
| 9781847493583  | La Vita Nuova            | Dante Alighieri            |
| 9971-5-0210-0  | A Tale of Two Cities     | Charles Dickens            |
| 960-425-059-0  | The Lord of the Rings    | J. R. R. Tolkien           |
| 80-902734-1-6  | And Then There Were None | Agatha Christie            |
+----------------+--------------------------+----------------------------+
7 rows in set (0.00 sec)

查看更多 示例

2. 灵感来源

php-etlpetl 的启发。