y0lk/sqldumper

SQL 导出工具

0.2.2 2023-08-23 16:03 UTC

This package is auto-updated.

Last update: 2024-09-23 18:31:46 UTC


README

Latest Stable Version Build Status Code Coverage Scrutinizer Code Quality License Total Downloads

SQLDumper 是一个用于轻松创建定制 SQL 导出的小型库。

安装

通过 Composer

$ composer require y0lk/sqldumper

用法

概念是您可以选择表并为每个表设置某些 "导出参数",这样您可以快速链式调用多个函数来创建定制导出。

use Y0lk\SQLDumper\SQLDumper;

//Init the dumper with your DB info
$dumper = new SQLDumper('localhost', 'dbname', 'root', '');

//Set all tables to dump without data and without DROP statement
$dumper->allTables()
	->withData(false)
	->withDrop(false);

//Set table1 to dump with data
$dumper->table('table1')
	->withData(true);

//Set table2 and table3 to dump without structure (data only), and table3 with where condition
$dumper->listTables([
		'table2',
		'table3'
	])
	->withStructure(false)
	->table('table3')
		->where('id=2 OR foo="bar"');

//This will group DROP statements and put them at the beginning of the dump
$dumper->groupDrops(true);

//This will group INSERT statements and put them at the end of the dump
$dumper->groupInserts(true);

$dumper->save('dump.sql');

导出器选项

groupDrops(bool $group)

当设置为 TRUE 时,这将分组 DROP 语句并将它们放在导出的开始处

groupInserts(bool $group)

当设置为 TRUE 时,这将分组 INSERT 语句并将它们放在导出的末尾

表选择

有 3 种基本方法来选择表。当选择一个或多个表时,它们将作为 TableDumper 对象返回,您可以在这些对象上设置导出选项。

allTables()

选择 DB 中的所有表

table(string|Table $table)

通过表名(字符串)或表对象选择

listTables(array $listTables)

通过表名列表(字符串)或表对象选择

表选项

这是每个 TableDumper 可用的方法列表

withStructure(bool $withStructure)

是否导出表的 CREATE 结构

withData(bool $withData)

是否导出表数据(INSERT 语句)

withDrop(bool $withDrop)

是否包含 DROP 语句(在 CREATE 之前)

where(string $where_string)

WHERE 查询字符串作为常规 SQL

输出

dump(resource $stream)

这是主要的导出函数,将导出输出到流中。

save(string $filename)

将导出保存到文件

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件