Skip to content

Commit

Permalink
Merge pull request #2 from martin-georgiev/feature/better-support-of-…
Browse files Browse the repository at this point in the history
…text-arrays

Better support of PostgreSQL text array type
  • Loading branch information
martin-georgiev authored Mar 2, 2017
2 parents 1687bd5 + c015a70 commit 9e23d7f
Show file tree
Hide file tree
Showing 42 changed files with 197 additions and 46 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ php:
- '7.1'
- hhvm
- nightly
install: composer install
install: composer install
script:
- vendor/bin/phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/**
* Abstract handling of PostgreSql array data types
* @see http://www.postgresql.org/docs/9.4/static/arrays.html
* @see https://www.postgresql.org/docs/9.4/static/arrays.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion src/MartinGeorgiev/Doctrine/DBAL/Types/BigIntArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql BIGINT[] data type
* @see http://www.postgresql.org/docs/9.4/static/arrays.html
* @see https://www.postgresql.org/docs/9.4/static/arrays.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion src/MartinGeorgiev/Doctrine/DBAL/Types/IntegerArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql INTEGER[] data type
* @see http://www.postgresql.org/docs/9.4/static/arrays.html
* @see https://www.postgresql.org/docs/9.4/static/arrays.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion src/MartinGeorgiev/Doctrine/DBAL/Types/Jsonb.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/**
* Implementation of PostgreSql JSONB data type
* @see http://www.postgresql.org/docs/9.4/static/datatype-json.html
* @see https://www.postgresql.org/docs/9.4/static/datatype-json.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion src/MartinGeorgiev/Doctrine/DBAL/Types/JsonbArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql JSONB[] data type
* @see http://www.postgresql.org/docs/9.4/static/arrays.html
* @see https://www.postgresql.org/docs/9.4/static/arrays.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion src/MartinGeorgiev/Doctrine/DBAL/Types/SmallIntArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql SMALLINT[] data type
* @see http://www.postgresql.org/docs/9.4/static/arrays.html
* @see https://www.postgresql.org/docs/9.4/static/arrays.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
15 changes: 8 additions & 7 deletions src/MartinGeorgiev/Doctrine/DBAL/Types/TextArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace MartinGeorgiev\Doctrine\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use MartinGeorgiev\Utils\DataStructure;

/**
* Implementation of PostgreSql TEXT[] data type
* @see http://www.postgresql.org/docs/9.4/static/arrays.html
* @see https://www.postgresql.org/docs/9.4/static/arrays.html
*
* @since 0.6
* @author Martin Georgiev <[email protected]>
Expand All @@ -24,7 +25,7 @@ class TextArray extends AbstractType
* @param mixed $value The value to convert.
* @param AbstractPlatform $platform The currently used database platform.
*
* @return string The database representation of the value.
* @return null|string The database representation of the value.
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
Expand All @@ -38,7 +39,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
/**
* @param array $phpTextArray
*
* @return string
* @return bool|string
*/
protected function transformToPostgresTextArray($phpTextArray)
{
Expand All @@ -48,7 +49,7 @@ protected function transformToPostgresTextArray($phpTextArray)
if (empty($phpTextArray)) {
return '{}';
}
return '{"' . join('","', $phpTextArray) . '"}';
return DataStructure::transformPHPArrayToPostgresTextArray($phpTextArray);
}

/**
Expand All @@ -57,7 +58,7 @@ protected function transformToPostgresTextArray($phpTextArray)
* @param string $value The value to convert.
* @param AbstractPlatform $platform The currently used database platform.
*
* @return array The PHP representation of the value.
* @return null|array The PHP representation of the value.
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
Expand All @@ -78,7 +79,7 @@ protected function transformFromPostgresTextArray($postgresValue)
if ($postgresValue === '{}') {
return [];
}
$trimmedPostgresValue = mb_substr($postgresValue, 2, -2);
return explode('","', $trimmedPostgresValue);

return DataStructure::transformPostgresTextArrayToPHPArray($postgresValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql ALL()
* @see http://www.postgresql.org/docs/9.4/static/functions-subquery.html#FUNCTIONS-SUBQUERY-ALL
* @see https://www.postgresql.org/docs/9.4/static/functions-subquery.html#FUNCTIONS-SUBQUERY-ALL
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql ANY()
* @see http://www.postgresql.org/docs/9.4/static/functions-subquery.html#FUNCTIONS-SUBQUERY-ANY-SOME
* @see https://www.postgresql.org/docs/9.4/static/functions-subquery.html#FUNCTIONS-SUBQUERY-ANY-SOME
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql ARRAY[]
* @see http://www.postgresql.org/docs/9.4/static/arrays.html
* @see https://www.postgresql.org/docs/9.4/static/arrays.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql ARRAY_APPEND()
* @see http://www.postgresql.org/docs/9.4/static/functions-array.html
* @see https://www.postgresql.org/docs/9.4/static/functions-array.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql check if two arrays have elements in common (using &&)
* @see http://www.postgresql.org/docs/9.4/static/functions-array.html
* @see https://www.postgresql.org/docs/9.4/static/functions-array.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql CARDINALITY()
* @see http://www.postgresql.org/docs/9.4/static/functions-array.html
* @see https://www.postgresql.org/docs/9.4/static/functions-array.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql ARRAY_CAT()
* @see http://www.postgresql.org/docs/9.4/static/functions-array.html
* @see https://www.postgresql.org/docs/9.4/static/functions-array.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql ARRAY_PREPEND()
* @see http://www.postgresql.org/docs/9.4/static/functions-array.html
* @see https://www.postgresql.org/docs/9.4/static/functions-array.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql ARRAY_REMOVE()
* @see http://www.postgresql.org/docs/9.4/static/functions-array.html
* @see https://www.postgresql.org/docs/9.4/static/functions-array.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql ARRAY_REPLACE()
* @see http://www.postgresql.org/docs/9.4/static/functions-array.html
* @see https://www.postgresql.org/docs/9.4/static/functions-array.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql ARRAY_TO_STRING()
* @see http://www.postgresql.org/docs/9.4/static/functions-array.html
* @see https://www.postgresql.org/docs/9.4/static/functions-array.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql check if left side contains right side (using @>)
* @see http://www.postgresql.org/docs/9.4/static/functions-array.html
* @see https://www.postgresql.org/docs/9.4/static/functions-array.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* Implementation of PostgreSql GREATEST()
* @see http://www.postgresql.org/docs/9.4/static/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
* @see https://www.postgresql.org/docs/9.4/static/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
*
* @since 0.7
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql STRING_TO_ARRAY()
* @see http://www.postgresql.org/docs/9.4/static/functions-array.html
* @see https://www.postgresql.org/docs/9.4/static/functions-array.html
*
* @since 0.4
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql check if left side is contained by right side (using <@)
* @see http://www.postgresql.org/docs/9.4/static/functions-array.html
* @see https://www.postgresql.org/docs/9.4/static/functions-array.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql json field retrival, filtered by key (using ->)
* @see http://www.postgresql.org/docs/9.4/static/functions-json.html
* @see https://www.postgresql.org/docs/9.4/static/functions-json.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql json field retrival as integer, filtered by key (using ->> and type casting to BIGINT)
* @see http://www.postgresql.org/docs/9.4/static/functions-json.html
* @see https://www.postgresql.org/docs/9.4/static/functions-json.html
*
* @since 0.3
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql json field retrival as text, filtered by key (using ->>)
* @see http://www.postgresql.org/docs/9.4/static/functions-json.html
* @see https://www.postgresql.org/docs/9.4/static/functions-json.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql json object retrival, filtered by specific path (using #>)
* @see http://www.postgresql.org/docs/9.4/static/functions-json.html
* @see https://www.postgresql.org/docs/9.4/static/functions-json.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql json object retrival as text, filtered by specific path (using #>>)
* @see http://www.postgresql.org/docs/9.4/static/functions-json.html
* @see https://www.postgresql.org/docs/9.4/static/functions-json.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql JSONB_ARRAY_ELEMENTS()
* @see http://www.postgresql.org/docs/9.4/static/functions-json.html
* @see https://www.postgresql.org/docs/9.4/static/functions-json.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql JSONB_ARRAY_ELEMENTS_TEXT()
* @see http://www.postgresql.org/docs/9.4/static/functions-json.html
* @see https://www.postgresql.org/docs/9.4/static/functions-json.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql JSONB_ARRAY_LENGTH()
* @see http://www.postgresql.org/docs/9.4/static/functions-json.html
* @see https://www.postgresql.org/docs/9.4/static/functions-json.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql JSONB_EACH()
* @see http://www.postgresql.org/docs/9.4/static/functions-json.html
* @see https://www.postgresql.org/docs/9.4/static/functions-json.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql JSONB_EACH_TEXT()
* @see http://www.postgresql.org/docs/9.4/static/functions-json.html
* @see https://www.postgresql.org/docs/9.4/static/functions-json.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql JSONB_EXISTS()
* @see http://www.postgresql.org/docs/9.4/static/functions-json.html
* @see https://www.postgresql.org/docs/9.4/static/functions-json.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql JSONB_OBJECT_KEYS()
* @see http://www.postgresql.org/docs/9.4/static/functions-json.html
* @see https://www.postgresql.org/docs/9.4/static/functions-json.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql LEAST()
* @see http://www.postgresql.org/docs/9.4/static/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
* @see https://www.postgresql.org/docs/9.4/static/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
*
* @since 0.7
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql STRING_TO_ARRAY()
* @see http://www.postgresql.org/docs/9.4/static/functions-array.html
* @see https://www.postgresql.org/docs/9.4/static/functions-array.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Implementation of PostgreSql TO_TSQUERY()
* @see http://www.postgresql.org/docs/9.4/static/textsearch-controls.html
* @see https://www.postgresql.org/docs/9.4/static/textsearch-controls.html
*
* @since 0.1
* @author Martin Georgiev <[email protected]>
Expand Down
Loading

0 comments on commit 9e23d7f

Please sign in to comment.