Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pgsql encoder #21

Open
wants to merge 28 commits into
base: pgsql-encoder
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
15bdcb8
removed dynColSqlMaria function, simply json_encode($attributes) in e…
Jan 27, 2017
a6c08b1
runned tests for pg and updated results in pgsql1.txt
Feb 2, 2017
8922cc1
some cleanup
Feb 3, 2017
49b6dce
modified test fixtures to not set id and let pg handle it through ser…
Feb 3, 2017
415c110
modified test fixtures to not set id and let pg handle it through ser…
Feb 3, 2017
270b23c
altered pgsql encoder to create attribute the way that seems proper
Feb 4, 2017
90791cd
altered pgsql encoder to create attribute the way that seems proper, …
Feb 4, 2017
1cc09c4
fixed error of $type declared as a const
Feb 5, 2017
54f9b57
fixed error of $type declared as a const
Feb 5, 2017
e0c56b3
altered encoderInterface no reason to set $type default in interface …
Feb 5, 2017
b07f8bd
altered encoderInterface no reason to set $type default in interface …
Feb 6, 2017
4583cd6
altered encoderInterface no reason to set $type default in interface …
Feb 6, 2017
bec2b6e
updated test results
Feb 6, 2017
99d1880
updated test file
Feb 6, 2017
7742a49
updated test file altered pgencoder to use jsonb_extract_path_text wh…
Feb 10, 2017
b9ebbc6
updated test file altered pgencoder to use jsonb_extract_path_text wh…
Feb 10, 2017
0799cbb
added numeric and text types to daq, modifies pgsqlencoder to accept …
Feb 11, 2017
d5e4267
added numeric and text types to daq, modifies pgsqlencoder to accept …
Feb 11, 2017
e3e3f37
reformatted the code to comply with psr2 standards altered encoder to…
gvasilopulos Feb 11, 2017
817f1b8
created distinct regexp for postgres
gvasilopulos Feb 12, 2017
5fc39ea
added exception for not supported jsonb dbtypes under postgres
gvasilopulos Feb 12, 2017
aed81d9
bugfixes, updated test file to be "closer" to the original dynamicrec…
gvasilopulos Feb 12, 2017
7cdeb47
reformated sources to psr2 standard
gvasilopulos Feb 12, 2017
3cd8844
added boolean type
gvasilopulos Feb 13, 2017
6cd0565
added boolean type
gvasilopulos Feb 13, 2017
e4003a9
removed unused files
gvasilopulos Feb 13, 2017
31f5f7b
added test for complex json stucture, added fixtures for complex json
gvasilopulos Feb 20, 2017
768895d
added test for complex json stucture, added fixtures for complex json
gvasilopulos Feb 20, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
/cache
/vendor
jssearch.index.js
errors.txt
errors.txt
/tests/arraysubset.php
/tests/unit/FixErrorTests.php
/tests/unit/DynamicActiveRecordTestPgJson11.php
24 changes: 19 additions & 5 deletions DynamicActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @copyright Copyright (c) 2015 Spinitron LLC
* @license http://opensource.org/licenses/ISC
*/

namespace spinitron\dynamicAr;

use Yii;
Expand Down Expand Up @@ -46,6 +45,7 @@
*/
class DynamicActiveQuery extends ActiveQuery
{

/**
* @var string name of the DynamicActiveRecord's column storing serialized dynamic attributes
*/
Expand Down Expand Up @@ -103,7 +103,7 @@ public function prepare($builder)
if (empty($this->_dynamicColumn)) {
/** @var string $modelClass */
throw new \yii\base\InvalidConfigException(
$modelClass . '::dynamicColumn() must return an attribute name'
$modelClass . '::dynamicColumn() must return an attribute name'
);
}

Expand Down Expand Up @@ -211,17 +211,31 @@ public function createCommand($db = null)
$type = !empty($matches[3]) ? $matches[3] : 'CHAR';
return $encoder->dynamicAttributeExpression($matches[2], $type);
};

$pattern = <<<'REGEXP'
$driver = $db->getDriverName();
$patternmaria = <<<'REGEXP'
% (`?) \(! \s*?
( [a-z_\x7f-\xff][a-z0-9_\x7f-\xff]* (?: \. [^.|\s]+)* )
(?: \| (binary (?:\(\d+\))? | char (?:\(\d+\))? | time (?:\(\d+\))? | datetime (?:\(\d+\))? | date
| decimal (?:\(\d\d?(?:,\d\d?)?\))? | double (?:\(\d\d?,\d\d?\))?
| int(eger)? | (?:un)? signed (?:\s+int(eger)?)?) )?
\s*? !\) \1 %ix
REGEXP;
$patternpostgres = <<<'REGEXP'
% (`?) \(! \s*?
( [a-z_\x7f-\xff][a-z0-9_\x7f-\xff]* (?: \. [^.|\s]+)* )
(?: \| (char (?:\(\d+\))? | numeric | jsonb | text | boolean
| NUMERIC | JSONB | TEXT | BOOLEAN ?) )?
\s*? !\) \1 %ix
REGEXP;
if ($driver == 'mysql' || $driver == 'mysqli') {
$pattern = $patternmaria;
} else if ($driver == 'pgsql') {
$pattern = $patternpostgres;
} else {
throw new \yii\base\NotSupportedException("DynamicActiveRecord does not support '$driver' DBMS.");
}
$sql = preg_replace_callback($pattern, $callback, $sql);

// print_r($sql);
return $db->createCommand($sql, $params);
}

Expand Down
6 changes: 3 additions & 3 deletions DynamicActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ public function getAttribute($name)
return null;
}
$ref = &$ref[$key];
}

return $ref;
}
return $ref;
}

/**
Expand Down
Loading