-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CrateDB bulk operations: Add support for improved DML efficiency
https://crate.io/docs/crate/reference/en/latest/interfaces/http.html#bulk-operations - In order to use the bulk operations interface, a `PDOStatement` needs to be prepared using the `bulkMode` option, like `->prepare($sql, ["bulkMode" => true])`. - The interface of `BulkResponse` has been made compatible with `Collection`, specifically wrt. the `getRows()` method, in order to return data from the driver without needing other proprietary methods. - In order to propagate the non-standard bulk response shape back, the user has to select the `PDO::FETCH_NUM` fetch style. - Documentation: Add two example programs about insert operations
- Loading branch information
Showing
15 changed files
with
679 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/* | ||
* Basic example demonstrating how to connect to CrateDB using PHP PDO. | ||
* | ||
* Prerequisites: | ||
* | ||
* docker run --rm -it --publish=4200:4200 crate | ||
* | ||
* Synopsis: | ||
* | ||
* php examples/insert_basic.php | ||
*/ | ||
include("./vendor/autoload.php"); | ||
|
||
error_reporting(E_ALL ^ E_DEPRECATED); | ||
|
||
// Connect to CrateDB. | ||
use Crate\PDO\PDO; | ||
$connection = new PDO("crate:localhost:4200", "crate"); | ||
|
||
// Create database table. | ||
$connection->exec("DROP TABLE IF EXISTS test_table;"); | ||
$connection->exec("CREATE TABLE test_table (id INTEGER, name STRING, int_type INTEGER);"); | ||
|
||
// Run insert operation. | ||
$statement = $connection->prepare('INSERT INTO test_table (id, name, int_type) VALUES (?, ?, ?)'); | ||
$statement->execute([5, 'foo', 1]); | ||
$statement->execute([6, 'bar', 2]); | ||
|
||
// Evaluate response. | ||
print("Total count: {$statement->rowCount()}\n"); | ||
$response = $statement->fetchAll(PDO::FETCH_NUM); | ||
print_r($response); | ||
|
||
// Disconnect from database. | ||
// https://www.php.net/manual/en/pdo.connections.php | ||
// https://stackoverflow.com/questions/18277233/pdo-closing-connection | ||
$statement = null; | ||
$connection = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/* | ||
* Example demonstrating how to use CrateDB's bulk operations interface for | ||
* inserting large amounts of data efficiently, using PHP PDO. | ||
* | ||
* Prerequisites: | ||
* | ||
* docker run --rm -it --publish=4200:4200 crate | ||
* | ||
* Synopsis: | ||
* | ||
* php examples/insert_bulk.php | ||
*/ | ||
include("./vendor/autoload.php"); | ||
|
||
error_reporting(E_ALL ^ E_DEPRECATED); | ||
|
||
// Connect to CrateDB. | ||
use Crate\PDO\PDO; | ||
$connection = new PDO("crate:localhost:4200", "crate"); | ||
|
||
// Create database table. | ||
$connection->exec("DROP TABLE IF EXISTS test_table;"); | ||
$connection->exec("CREATE TABLE test_table (id INTEGER, name STRING, int_type INTEGER);"); | ||
|
||
// Run insert operation. | ||
$parameters = [[5, 'foo', 1], [6, 'bar', 2], [7, 'foo', 3], [8, 'bar', 4]]; | ||
$statement = $connection->prepare( | ||
'INSERT INTO test_table (id, name, int_type) VALUES (?, ?, ?)', | ||
array("bulkMode" => true)); | ||
$statement->execute($parameters); | ||
|
||
// Evaluate response. | ||
// MUST use `PDO::FETCH_NUM` for returning bulk operation responses. | ||
print("Total count: {$statement->rowCount()}\n"); | ||
$response = $statement->fetchAll(PDO::FETCH_NUM); | ||
print_r($response); | ||
|
||
// Disconnect from database. | ||
// https://www.php.net/manual/en/pdo.connections.php | ||
// https://stackoverflow.com/questions/18277233/pdo-closing-connection | ||
$statement = null; | ||
$connection = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.