From 0c2b55b1ec375cef4b14ab0a0c6739cf5a4dddc1 Mon Sep 17 00:00:00 2001 From: Joao Gilberto Magalhaes Date: Wed, 22 Jan 2025 15:01:12 -0600 Subject: [PATCH 1/3] Make insert more understandable --- README.md | 1 + src/InsertQuery.php | 37 +++++++++++++++++-------------------- src/Repository.php | 2 +- tests/InsertQueryTest.php | 12 ++++++------ tests/RepositoryTest.php | 6 +++--- 5 files changed, 28 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 59f74cd..d29bccf 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,7 @@ $result = $repository->getByQuery($query); ## Advanced Topics * [Active Record](docs/active-record.md) +* [Auto Discovering Relationship](docs/auto-discovering-relationship.md) * [The Literal Object](docs/the-literal-object.md) * [Soft Delete](docs/softdelete.md) * [Caching the Results](docs/cache.md) diff --git a/src/InsertQuery.php b/src/InsertQuery.php index c107c66..908a771 100644 --- a/src/InsertQuery.php +++ b/src/InsertQuery.php @@ -10,17 +10,17 @@ class InsertQuery extends Updatable { - protected array $fields = []; + protected array $values = []; - public static function getInstance(string $table = null, array $fields = []): self + public static function getInstance(string $table = null, array $fieldsAndValues = []): self { $query = new InsertQuery(); if (!is_null($table)) { $query->table($table); } - foreach ($fields as $field => $value) { - $query->field($field, $value); + foreach ($fieldsAndValues as $field => $value) { + $query->set($field, $value); } return $query; @@ -28,28 +28,30 @@ public static function getInstance(string $table = null, array $fields = []): se /** * Fields to be used for the INSERT + * * Example: - * $query->fields(['name', 'price']); + * $query->set('name', 'price'); * * @param string $field * @param int|float|bool|string|LiteralInterface|null $value * @return $this */ - public function field(string $field, int|float|bool|string|LiteralInterface|null $value): self + public function set(string $field, int|float|bool|string|LiteralInterface|null $value): self { - $this->fields[$field] = $value; + $this->values[$field] = $value; return $this; } /** * Fields to be used for the INSERT - * Example: + * Use this method to add the fields will be prepared for the INSERT - same query, but with different values, executed multiple times + * Example: * $query->fields(['name', 'price']); * * @param array $fields * @return $this */ - public function fields(array $fields): static + public function defineFields(array $fields): static { // swap the key and value of the $fields array and set null as value $fields = array_flip($fields); @@ -57,16 +59,11 @@ public function fields(array $fields): static return null; }, $fields); - $this->fields = array_merge($this->fields, $fields); + $this->values = array_merge($this->values, $fields); return $this; } - protected function getFields(): string - { - return ' ' . implode(', ', $this->fields) . ' '; - } - /** * @param DbFunctionsInterface|null $dbHelper * @return SqlObject @@ -74,11 +71,11 @@ protected function getFields(): string */ public function build(DbFunctionsInterface $dbHelper = null): SqlObject { - if (empty($this->fields)) { + if (empty($this->values)) { throw new OrmInvalidFieldsException('You must specify the fields for insert'); } - $fieldsStr = array_keys($this->fields); + $fieldsStr = array_keys($this->values); // get the fields from the first element only if (!is_null($dbHelper)) { $fieldsStr = $dbHelper->delimiterField($fieldsStr); } @@ -92,9 +89,9 @@ public function build(DbFunctionsInterface $dbHelper = null): SqlObject . $tableStr . '( ' . implode(', ', $fieldsStr) . ' ) ' . ' values ' - . '( :' . implode(', :', array_keys($this->fields)) . ' ) '; + . '( :' . implode(', :', array_keys($this->values)) . ' ) '; - $params = $this->fields; + $params = $this->values; $sql = ORMHelper::processLiteral($sql, $params); return new SqlObject($sql, $params, SqlObjectEnum::INSERT); } @@ -106,7 +103,7 @@ public function build(DbFunctionsInterface $dbHelper = null): SqlObject public function convert(?DbFunctionsInterface $dbDriver = null): QueryBuilderInterface { $query = Query::getInstance() - ->fields(array_keys($this->fields)) + ->fields(array_keys($this->values)) ->table($this->table); foreach ($this->where as $item) { diff --git a/src/Repository.php b/src/Repository.php index 6d10df9..909530b 100644 --- a/src/Repository.php +++ b/src/Repository.php @@ -395,7 +395,7 @@ function ($propName, $targetName, $value) use ($mapper, $instance) { $position = 0; foreach ($keyGen as $value) { $array[$pkList[$position]] = $value; - $updatable->field($this->mapper->getPrimaryKey()[$position++], $value); + $updatable->set($this->mapper->getPrimaryKey()[$position++], $value); } $keyReturned = $this->insert($updatable, $keyGen); if (count($pkList) == 1 && !empty($keyReturned)) { diff --git a/tests/InsertQueryTest.php b/tests/InsertQueryTest.php index 2422354..2fe199d 100644 --- a/tests/InsertQueryTest.php +++ b/tests/InsertQueryTest.php @@ -29,9 +29,9 @@ public function testInsert() { $this->object->table('test'); - $this->object->field('fld1', 'A'); - $this->object->field('fld2', 'B'); - $this->object->field('fld3', 'C'); + $this->object->set('fld1', 'A'); + $this->object->set('fld2', 'B'); + $this->object->set('fld3', 'C'); $sqlObject = $this->object->build(); $this->assertEquals( @@ -54,9 +54,9 @@ public function testQueryUpdatable() $this->object->convert()->build() ); - $this->object->field('fld1', 'A'); - $this->object->field('fld2', 'B'); - $this->object->field('fld3', 'C'); + $this->object->set('fld1', 'A'); + $this->object->set('fld2', 'B'); + $this->object->set('fld3', 'C'); $this->assertEquals( new SqlObject('SELECT fld1, fld2, fld3 FROM test'), diff --git a/tests/RepositoryTest.php b/tests/RepositoryTest.php index 55e92c5..be72fcc 100644 --- a/tests/RepositoryTest.php +++ b/tests/RepositoryTest.php @@ -433,7 +433,7 @@ public function testInsertBuildAndExecute() $insertQuery = InsertQuery::getInstance() ->table('users') - ->fields([ + ->defineFields([ 'name', 'createdate' ]); @@ -451,8 +451,8 @@ public function testInsertBuildAndExecute2() $insertQuery = InsertQuery::getInstance() ->table('users') - ->field('name', 'inserted name') - ->field('createdate', '2024-09-03') + ->set('name', 'inserted name') + ->set('createdate', '2024-09-03') ; $insertQuery->buildAndExecute($this->repository->getDbDriver()); From a532c1dcbdc124f4dd373b4ca73bba943b07a066 Mon Sep 17 00:00:00 2001 From: Joao Gilberto Magalhaes Date: Wed, 22 Jan 2025 21:17:40 -0600 Subject: [PATCH 2/3] Added InsertBulkQuery.php --- docs/updating-the-database.md | 69 ++++++++++++++++++- src/InsertBulkQuery.php | 109 ++++++++++++++++++++++++++++++ src/InsertMultipleQuery.php | 101 --------------------------- src/InsertSelectQuery.php | 5 +- tests/InsertBulkQueryTest.php | 74 ++++++++++++++++++++ tests/InsertMultipleQueryTest.php | 87 ------------------------ tests/RepositoryTest.php | 17 +++-- 7 files changed, 262 insertions(+), 200 deletions(-) create mode 100644 src/InsertBulkQuery.php delete mode 100644 src/InsertMultipleQuery.php create mode 100644 tests/InsertBulkQueryTest.php delete mode 100644 tests/InsertMultipleQueryTest.php diff --git a/docs/updating-the-database.md b/docs/updating-the-database.md index 3cb8ffa..4f1a3ba 100644 --- a/docs/updating-the-database.md +++ b/docs/updating-the-database.md @@ -3,6 +3,8 @@ Once you have defined the model, (see [Getting Started](getting-started-model.md)) you can start to interact with the database and doing queries, updates, and deletes. +## Update + Update a single record is simple as: ```php @@ -14,7 +16,9 @@ $repository->save($users); This code will update the record with the ID 10 and set the name to "New name". -The idea is to insert a new record. If you don't set the ID, the library will assume that you are inserting a new record. +## Insert + +If you don't set the ID, the library will assume that you are inserting a new record. ```php name = "New name"; $repository->save($users); ``` -## Advanced Cases +## Using the UpdateQuery (Special Cases) In some cases you need to update multiples records at once. See an example: @@ -37,4 +41,63 @@ $updateQuery->set('fld3', 'C'); $updateQuery->where('fld1 > :id', ['id' => 10]); ``` -This code will update the table `test` and set the fields `fld1`, `fld2`, and `fld3` to `A`, `B`, and `C` respectively where the `fld1` is greater than 10. \ No newline at end of file +This code will update the table `test` and set the fields `fld1`, `fld2`, and `fld3` to `A`, `B`, and `C` +respectively where the `fld1` is greater than 10. + +## Insert records with InsertQuery + +You can insert records using the `InsertQuery` object. See an example: + +```php +table('test'); +$insertQuery->set('fld1', 'A'); +$insertQuery->set('fld2', 'B'); +$insertQuery->set('fld3', 'C'); +``` + +## Insert records from another select + +You can insert records from another select using the `InsertSelectQuery` object. See an example: + +```php +table('table2'); +$query->field('fldA'); +$query->field('fldB'); +$query->field('fldC'); +$query->where('fldA = :valueA', ['valueA' => 1]); + +// Define the insert select query +$insertSelectQuery = new \ByJG\MicroOrm\InsertSelectQuery(); +$insertSelectQuery->table('test'); +$insertSelectQuery->fields(['fld1', 'fld2', 'fld3']); +$insertSelectQuery->fromQuery($query); // The query to select the records +``` + +## Insert records in batch + +You can insert records in batch using the `InsertBulkQuery` object. See an example: + +```php +values(['fld1' => 'A', 'fld2' => 'B']); +$insertBulk->values(['fld1' => 'D', 'fld2' => 'E']); +$insertBulk->values(['fld1' => 'G', 'fld2' => 'H']); +``` + +## Delete records + +You can delete records using the `DeleteQuery` object. See an example: + +```php +table('test'); +$deleteQuery->where('fld1 = :value', ['value' => 'A']); +``` diff --git a/src/InsertBulkQuery.php b/src/InsertBulkQuery.php new file mode 100644 index 0000000..412d1e9 --- /dev/null +++ b/src/InsertBulkQuery.php @@ -0,0 +1,109 @@ +table($table); + + foreach ($fieldNames as $fieldname) { + $this->fields[$fieldname] = []; + } + } + + + public static function getInstance(string $table, array $fieldNames): static + { + return new InsertBulkQuery($table, $fieldNames); + } + + /** + * @throws OrmInvalidFieldsException + */ + public function values(array $values, bool $allowNonMatchFields = true): static + { + if (array_diff(array_keys($this->fields), array_keys($values))) { + throw new OrmInvalidFieldsException('The provided values do not match the expected fields'); + } + + if (!$allowNonMatchFields && array_diff(array_keys($values), array_keys($this->fields))) { + throw new OrmInvalidFieldsException('The provided values contain more fields than expected'); + } + + foreach (array_keys($this->fields) as $field) { + $this->fields[$field][] = $values[$field]; + } + + return $this; + } + + /** + * @param DbFunctionsInterface|null $dbHelper + * @return SqlObject + * @throws OrmInvalidFieldsException + */ + public function build(DbFunctionsInterface $dbHelper = null): SqlObject + { + if (empty($this->fields)) { + throw new OrmInvalidFieldsException('You must specify the fields for insert'); + } + + $tableStr = $this->table; + if (!is_null($dbHelper)) { + $tableStr = $dbHelper->delimiterTable($tableStr); + } + + // Extract column names + $columns = array_keys($this->fields); + + // Get the number of rows + $rowCount = count(current($this->fields)); + + // Initialize placeholders and parameters + $placeholders = []; + $params = []; + + // Build placeholders and populate $params + for ($i = 0; $i < $rowCount; $i++) { + $rowPlaceholders = []; + foreach ($columns as $j => $col) { + $paramKey = "p{$i}_$j"; // Generate the parameter key + $rowPlaceholders[] = ":$paramKey"; // Add to row placeholders + $params[$paramKey] = $this->fields[$col][$i]; // Map parameter key to value + } + $placeholders[] = '(' . implode(', ', $rowPlaceholders) . ')'; // Add row placeholders to query + } + + if (!is_null($dbHelper)) { + $columns = $dbHelper->delimiterField($columns); + } + + // Construct the final SQL query + $sql = sprintf( + "INSERT INTO %s (%s) VALUES %s", + $tableStr, + implode(', ', $columns), + implode(', ', $placeholders) + ); + + return new SqlObject(ORMHelper::processLiteral($sql), $params); + } + + public function convert(?DbFunctionsInterface $dbDriver = null): QueryBuilderInterface + { + throw new InvalidArgumentException('It is not possible to convert an InsertBulkQuery to a Query'); + } +} diff --git a/src/InsertMultipleQuery.php b/src/InsertMultipleQuery.php deleted file mode 100644 index 664127d..0000000 --- a/src/InsertMultipleQuery.php +++ /dev/null @@ -1,101 +0,0 @@ -table($table); - } - - $query->fields($fields); - - return $query; - } - - public function fields(array $fields): static - { - $this->fields = $fields; - $this->row = []; - return $this; - } - - public function addRow(array $row): static - { - if (count($this->fields) !== count($row)) { - throw new \InvalidArgumentException('The row must have the same number of fields'); - } - - $rowToAdd = []; - foreach ($this->fields as $field) { - if (!array_key_exists($field, $row)) { - throw new \InvalidArgumentException("The field '$field' must be in the row"); - } - $rowToAdd[$field] = $row[$field]; - } - - $this->row[] = $rowToAdd; - - return $this; - } - - /** - * @param DbFunctionsInterface|null $dbHelper - * @return SqlObject - * @throws OrmInvalidFieldsException - */ - public function build(DbFunctionsInterface $dbHelper = null): SqlObject - { - if (empty($this->fields)) { - throw new OrmInvalidFieldsException('You must specify the fields for insert'); - } - - $fieldsStr = $this->fields; - if (!is_null($dbHelper)) { - $fieldsStr = $dbHelper->delimiterField($fieldsStr); - } - - $tableStr = $this->table; - if (!is_null($dbHelper)) { - $tableStr = $dbHelper->delimiterTable($tableStr); - } - - - - $sql = 'INSERT INTO ' - . $tableStr - . ' ( ' . implode(', ', $fieldsStr) . ' ) ' - . ' values '; - - $params = []; - $rowNum = 1; - foreach ($this->row as $row) { - $paramRow = []; - foreach ($row as $key => $value) { - $paramRow[$key . $rowNum] = $value; - } - $sql .= ' ( :' . implode(', :', array_keys($paramRow)) . ' ),'; - $params = array_merge($params, $paramRow); - $rowNum++; - } - - $sql = ORMHelper::processLiteral(trim($sql, ","), $params); - - return new SqlObject($sql, $params); - } - - public function convert(?DbFunctionsInterface $dbDriver = null): QueryBuilderInterface - { - throw new \InvalidArgumentException('It is not possible to convert an InsertMultipleQuery to a Query'); - } -} diff --git a/src/InsertSelectQuery.php b/src/InsertSelectQuery.php index 515f9f9..c5c0fba 100644 --- a/src/InsertSelectQuery.php +++ b/src/InsertSelectQuery.php @@ -3,9 +3,9 @@ namespace ByJG\MicroOrm; use ByJG\AnyDataset\Db\DbFunctionsInterface; -use ByJG\MicroOrm\Exception\InvalidArgumentException; use ByJG\MicroOrm\Exception\OrmInvalidFieldsException; use ByJG\MicroOrm\Interface\QueryBuilderInterface; +use InvalidArgumentException; class InsertSelectQuery extends Updatable { @@ -51,7 +51,6 @@ public function fromSqlObject(SqlObject $sqlObject): static /** * @param DbFunctionsInterface|null $dbHelper * @return SqlObject - * @throws InvalidArgumentException * @throws OrmInvalidFieldsException */ public function build(DbFunctionsInterface $dbHelper = null): SqlObject @@ -91,6 +90,6 @@ public function build(DbFunctionsInterface $dbHelper = null): SqlObject public function convert(?DbFunctionsInterface $dbDriver = null): QueryBuilderInterface { - throw new \InvalidArgumentException('It is not possible to convert an InsertMultipleQuery to a Query'); + throw new InvalidArgumentException('It is not possible to convert an InsertSelectQuery to a Query'); } } diff --git a/tests/InsertBulkQueryTest.php b/tests/InsertBulkQueryTest.php new file mode 100644 index 0000000..bce4fee --- /dev/null +++ b/tests/InsertBulkQueryTest.php @@ -0,0 +1,74 @@ +values(['fld1' => 'A', 'fld2' => 'B']); + $insertBulk->values(['fld1' => 'D', 'fld2' => 'E']); + $insertBulk->values(['fld1' => 'G', 'fld2' => 'H']); + + $sqlObject = $insertBulk->build(); + + $this->assertEquals('INSERT INTO test (fld1, fld2) VALUES (:p0_0, :p0_1), (:p1_0, :p1_1), (:p2_0, :p2_1)', $sqlObject->getSql()); + $this->assertEquals([ + 'p0_0' => 'A', + 'p0_1' => 'B', + 'p1_0' => 'D', + 'p1_1' => 'E', + 'p2_0' => 'G', + 'p2_1' => 'H', + ], $sqlObject->getParameters()); + } + + public function testInsertDifferentOrder() + { + $insertBulk = new InsertBulkQuery('test', ['fld1', 'fld2', 'fld3']); + $insertBulk->values(['fld2' => 'B', 'fld1' => 'A', 'fld3' => 'C']); + $insertBulk->values(['fld3' => 'F', 'fld1' => 'D', 'fld2' => 'E', 'fld4' => 'X']); + $insertBulk->values(['fld2' => 'H', 'fld3' => 'I', 'fld1' => 'G']); + + $sqlObject = $insertBulk->build(); + + $this->assertEquals('INSERT INTO test (fld1, fld2, fld3) VALUES (:p0_0, :p0_1, :p0_2), (:p1_0, :p1_1, :p1_2), (:p2_0, :p2_1, :p2_2)', $sqlObject->getSql()); + $this->assertEquals([ + 'p0_0' => 'A', + 'p0_1' => 'B', + 'p0_2' => 'C', + 'p1_0' => 'D', + 'p1_1' => 'E', + 'p1_2' => 'F', + 'p2_0' => 'G', + 'p2_1' => 'H', + 'p2_2' => 'I', + ], $sqlObject->getParameters()); + } + + public function testWrongFieldsValuesCount() + { + $this->expectExceptionMessage('The provided values do not match the expected fields'); + $insertBulk = new InsertBulkQuery('test', ['fld1', 'fld2', 'fld3']); + $insertBulk->values(['fld1' => 'A', 'fld2' => 'B']); + } + + public function testWrongFieldsValuesCount2() + { + $this->expectExceptionMessage('The provided values do not match the expected fields'); + $insertBulk = new InsertBulkQuery('test', ['fld1', 'fld2', 'fld3']); + $insertBulk->values(['fld1' => 'A', 'fld2' => 'B', 'fld4' => 'C']); + } + + public function testWrongValuesFieldsCount() + { + $this->expectExceptionMessage('The provided values contain more fields than expected'); + $insertBulk = new InsertBulkQuery('test', ['fld1', 'fld2', 'fld3']); + $insertBulk->values(['fld1' => 'A', 'fld2' => 'B', 'fld3' => 'C', 'fld4' => 'D'], allowNonMatchFields: false); + } + +} diff --git a/tests/InsertMultipleQueryTest.php b/tests/InsertMultipleQueryTest.php deleted file mode 100644 index 465cdf8..0000000 --- a/tests/InsertMultipleQueryTest.php +++ /dev/null @@ -1,87 +0,0 @@ -object = new InsertMultipleQuery(); - } - - protected function tearDown(): void - { - $this->object = null; - } - - public function testInsert() - { - $this->object->table('test'); - $this->object->fields(['fld1', 'fld2', 'fld3']); - - $this->object->addRow(['fld1' => 'A', 'fld2' => 'B', 'fld3' => 'C']); - $this->object->addRow(['fld1' => 'D', 'fld2' => 'E', 'fld3' => 'F']); - - $sqlObject = $this->object->build(); - - $this->assertEquals('INSERT INTO test ( fld1, fld2, fld3 ) values ( :fld11, :fld21, :fld31 ), ( :fld12, :fld22, :fld32 )', $sqlObject->getSql()); - $this->assertEquals([ - 'fld11' => 'A', - 'fld21' => 'B', - 'fld31' => 'C', - 'fld12' => 'D', - 'fld22' => 'E', - 'fld32' => 'F', - ], $sqlObject->getParameters()); - } - - public function testInsertStatic() - { - $query = InsertMultipleQuery::getInstance('test', ['fld1', 'fld2', 'fld3']); - - $query->addRow(['fld1' => 'A', 'fld2' => 'B', 'fld3' => 'C']); - $query->addRow(['fld1' => 'D', 'fld2' => 'E', 'fld3' => 'F']); - - $params = []; - $sqlObject = $query->build(); - - $this->assertEquals('INSERT INTO test ( fld1, fld2, fld3 ) values ( :fld11, :fld21, :fld31 ), ( :fld12, :fld22, :fld32 )', $sqlObject->getSql()); - $this->assertEquals([ - 'fld11' => 'A', - 'fld21' => 'B', - 'fld31' => 'C', - 'fld12' => 'D', - 'fld22' => 'E', - 'fld32' => 'F', - ], $sqlObject->getParameters()); - } - - public function testInsertError() - { - $query = InsertMultipleQuery::getInstance('test', ['fld1', 'fld2', 'fld3']); - - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('The row must have the same number of fields'); - - $query->addRow(['fld1' => 'A', 'fld2' => 'B']); - } - - public function testInsertError2() - { - $query = InsertMultipleQuery::getInstance('test', ['fld1', 'fld2', 'fld3']); - - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage("The field 'fld3' must be in the row"); - - $query->addRow(['fld1' => 'A', 'fld2' => 'B', 'nonexistent' => 'C']); - } - -} diff --git a/tests/RepositoryTest.php b/tests/RepositoryTest.php index be72fcc..627d825 100644 --- a/tests/RepositoryTest.php +++ b/tests/RepositoryTest.php @@ -14,6 +14,7 @@ use ByJG\MicroOrm\Exception\OrmInvalidFieldsException; use ByJG\MicroOrm\Exception\RepositoryReadOnlyException; use ByJG\MicroOrm\FieldMapping; +use ByJG\MicroOrm\InsertBulkQuery; use ByJG\MicroOrm\InsertQuery; use ByJG\MicroOrm\Interface\ObserverProcessorInterface; use ByJG\MicroOrm\Literal\Literal; @@ -76,9 +77,11 @@ public function setUp(): void name varchar(45), createdate datetime);' ); - $this->dbDriver->execute("insert into users (name, createdate) values ('John Doe', '2017-01-02')"); - $this->dbDriver->execute("insert into users (name, createdate) values ('Jane Doe', '2017-01-04')"); - $this->dbDriver->execute("insert into users (name, createdate) values ('JG', '1974-01-26')"); + $insertBulk = InsertBulkQuery::getInstance('users', ['name', 'createdate']); + $insertBulk->values(['name' => 'John Doe', 'createdate' => '2017-01-02']); + $insertBulk->values(['name' => 'Jane Doe', 'createdate' => '2017-01-04']); + $insertBulk->values(['name' => 'JG', 'createdate' => '1974-01-26']); + $insertBulk->buildAndExecute($this->dbDriver); $this->userMapper = new Mapper(Users::class, 'users', 'Id'); @@ -90,9 +93,11 @@ public function setUp(): void updated_at datetime, deleted_at datetime);' ); - $this->dbDriver->execute("insert into info (iduser, property) values (1, 30.4)"); - $this->dbDriver->execute("insert into info (iduser, property) values (1, 1250.96)"); - $this->dbDriver->execute("insert into info (iduser, property) values (3, '3.5')"); + $insertMultiple = InsertBulkQuery::getInstance('info', ['iduser', 'property']); + $insertMultiple->values(['iduser' => 1, 'property' => 30.4]); + $insertMultiple->values(['iduser' => 1, 'property' => 1250.96]); + $insertMultiple->values(['iduser' => 3, 'property' => 3.5]); + $insertMultiple->buildAndExecute($this->dbDriver); $this->infoMapper = new Mapper(Info::class, 'info', 'id'); $this->infoMapper->addFieldMapping(FieldMapping::create('value')->withFieldName('property')); From b5b939b97974468bc2f4bbc8c57f3f27faba15a2 Mon Sep 17 00:00:00 2001 From: Joao Gilberto Magalhaes Date: Thu, 23 Jan 2025 10:03:33 -0600 Subject: [PATCH 3/3] Fix InsertBulkQuery.php --- src/InsertBulkQuery.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/InsertBulkQuery.php b/src/InsertBulkQuery.php index 412d1e9..cd5f865 100644 --- a/src/InsertBulkQuery.php +++ b/src/InsertBulkQuery.php @@ -99,7 +99,8 @@ public function build(DbFunctionsInterface $dbHelper = null): SqlObject implode(', ', $placeholders) ); - return new SqlObject(ORMHelper::processLiteral($sql), $params); + $sql = ORMHelper::processLiteral($sql, $params); + return new SqlObject($sql, $params); } public function convert(?DbFunctionsInterface $dbDriver = null): QueryBuilderInterface