diff --git a/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Integration/AvroTest.php b/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Integration/AvroTest.php index af2a2d7f9..884750502 100644 --- a/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Integration/AvroTest.php +++ b/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Integration/AvroTest.php @@ -12,6 +12,7 @@ use function Flow\ETL\DSL\float_entry; use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\ignore; use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\json_entry; use function Flow\ETL\DSL\json_object_entry; @@ -331,7 +332,7 @@ public function test_writing_twice_to_the_same_location_with_ignore_mode() : voi }, \range(1, 100)) ) )) - ->mode(SaveMode::Ignore) + ->saveMode(ignore()) ->write(to_avro($path)) ->run(); diff --git a/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVLoaderTest.php b/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVLoaderTest.php index 07d32a218..d0b38612c 100644 --- a/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVLoaderTest.php +++ b/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVLoaderTest.php @@ -7,9 +7,9 @@ use function Flow\ETL\Adapter\CSV\to_csv; use function Flow\ETL\DSL\array_entry; use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\overwrite; use function Flow\ETL\DSL\str_entry; use Flow\ETL\Filesystem\Path; -use Flow\ETL\Filesystem\SaveMode; use Flow\ETL\Flow; use Flow\ETL\Row; use Flow\ETL\Rows; @@ -207,7 +207,7 @@ public function test_loading_overwrite_csv() : void Row::create(int_entry('id', 3), str_entry('name', 'Dawid')), ) ) - ->mode(SaveMode::Overwrite) + ->saveMode(overwrite()) ->load(to_csv($path)) ->run(); diff --git a/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JsonLoaderTest.php b/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JsonLoaderTest.php index e1018be20..77e2b08b3 100644 --- a/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JsonLoaderTest.php +++ b/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JsonLoaderTest.php @@ -7,7 +7,9 @@ use function Flow\ETL\Adapter\Json\from_json; use function Flow\ETL\Adapter\Json\to_json; use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\exception_if_exists; use function Flow\ETL\DSL\from_array; +use function Flow\ETL\DSL\ignore; use function Flow\ETL\DSL\ref; use Flow\ETL\Adapter\JSON\JsonLoader; use Flow\ETL\Config; @@ -259,7 +261,7 @@ public function test_save_mode_throw_exception_on_partitioned_rows() : void ['id' => 5, 'partition' => 'b'], ])) ->partitionBy(ref('partition')) - ->mode(SaveMode::ExceptionIfExists) + ->saveMode(exception_if_exists()) ->write(to_json($path)) ->run(); @@ -291,7 +293,7 @@ public function test_save_with_ignore_mode() : void ['id' => 2], ['id' => 3], ])) - ->mode(SaveMode::Ignore) + ->saveMode(ignore()) ->write(to_json($path)) ->run(); diff --git a/src/core/etl/src/Flow/ETL/DSL/functions.php b/src/core/etl/src/Flow/ETL/DSL/functions.php index 5f41fecc7..b023c5f2f 100644 --- a/src/core/etl/src/Flow/ETL/DSL/functions.php +++ b/src/core/etl/src/Flow/ETL/DSL/functions.php @@ -11,6 +11,7 @@ use Flow\ETL\ErrorHandler\SkipRows; use Flow\ETL\ErrorHandler\ThrowError; use Flow\ETL\Extractor; +use Flow\ETL\Filesystem\SaveMode; use Flow\ETL\Filesystem\Stream\Mode; use Flow\ETL\Flow; use Flow\ETL\FlowContext; @@ -988,3 +989,23 @@ function config_builder() : ConfigBuilder { return new ConfigBuilder(); } + +function overwrite() : SaveMode +{ + return SaveMode::Overwrite; +} + +function ignore() : SaveMode +{ + return SaveMode::Ignore; +} + +function exception_if_exists() : SaveMode +{ + return SaveMode::ExceptionIfExists; +} + +function append() : SaveMode +{ + return SaveMode::Append; +} diff --git a/src/core/etl/src/Flow/ETL/DataFrame.php b/src/core/etl/src/Flow/ETL/DataFrame.php index a1b2bc2bb..234a28e21 100644 --- a/src/core/etl/src/Flow/ETL/DataFrame.php +++ b/src/core/etl/src/Flow/ETL/DataFrame.php @@ -744,6 +744,16 @@ public function run(?callable $callback = null) : void } } + /** + * Alias for DataFrame::mode. + * + * @lazy + */ + public function saveMode(SaveMode $mode) : self + { + return $this->mode($mode); + } + /** * @lazy * Keep only given entries.