Skip to content

Commit

Permalink
1.34.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecc committed Apr 27, 2020
1 parent e95d1f0 commit d1e7778
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 18 deletions.
65 changes: 63 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ where
### Run an unprepared query

```php
$sql="CREATE TABLE `product` (
$sql='CREATE TABLE `product` (
`idproduct` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NULL,
PRIMARY KEY (`idproduct`));";
PRIMARY KEY (`idproduct`));';
$pdoOne->runRawQuery($sql);
```

Expand Down Expand Up @@ -1283,6 +1283,64 @@ $dao->render();


## Code generation.

There are several ways to generate a Repository code, it is possible to generate a code using the CLI, the GUI or using the next code:

```php
$pdo=new PdoOne('mysql','127.0.0.1','root','abc.123','sakila');
$pdo->connect();
$table=$pdo->generateCodeClass('Tablename','repo'); // where Tablename is the name of the table to analyze. it must exsits.
echo $clase;
```

The code generated looks like this one

```php
class TableNameRepo extends _BasePdoOneRepo
{
// ....
}
```

### Using the Repository class.

For started, you must set an instance of the PdoOne

You could do it by creating a function called pdOne

```php
function pdoOne() {
$pdo=new PdoOne('mysql','127.0.0.1','root','abc.123','sakila');
$pdo->connect();
}
```

Or creating a global variable called $pdoOne

```php
$pdoOne=new PdoOne('mysql','127.0.0.1','root','abc.123','sakila');
$pdoOne->connect();
```

Or injecting the instance into the class

```php
$pdo=new PdoOne('mysql','127.0.0.1','root','abc.123','sakila');
$pdo->connect();
TableNameRepo::setPdoOne($pdo);
```

### Queries

```php
$data=TableNameRepo::toList(); // select * from tablerepo
$data=TableNameRepo::first($pk); // select * from tablerepo where pk=$pk (it always returns 1 or zero values)
$data=TableNameRepo::where('a1=?',['i',$value])::toList(); // select * from tablerepo where a1=$value
```





## Benchmark (mysql, estimated)
Expand Down Expand Up @@ -1317,6 +1375,9 @@ In a nutshell:
* Every minor version means that it adds a new functionality i.e. 1.5 -> 1.6 (new methods)
* Every decimal version means that it patches/fixes/refactoring a previous functionality i.e. 1.5.0 -> 1.5.1 (fix)

* 1.34.1 2020-04-27
* _BasePdoOneRepo 2.2.1 fixed.

* 1.34 2020-04-27
* _BasePdoOneRepo 2.2 now it allows load relation many by one.
* sniffer is removed. Using Php Inspections ​(EA Extended)​
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "eftec/pdoone",
"description": "Procedural PDO Data access class in a single Class",
"version": "1.34",
"version": "1.34.1",
"type": "library",
"keywords": [
"dao",
Expand Down
4 changes: 2 additions & 2 deletions lib/PdoOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
* @package eftec
* @author Jorge Castro Castillo
* @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne
* @version 1.34 2020-04-27
* @version 1.34.1 2020-04-27
*/
class PdoOne
{

const VERSION = '1.33';
const VERSION = '1.34.1';

const NULL = PHP_INT_MAX;

Expand Down
32 changes: 19 additions & 13 deletions lib/_BasePdoOneRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ public static function buildSelect($prefixTable='',$prefix='') {
$keys=array_keys(static::getDef());
$keyRel=static::getDefFK(false);
$cols='';
if(strpos(static::class,'\\')) { // we assume that every repo class lives in the same namespace.
$ns=explode('\\',static::class,2);
$ns=$ns[0].'\\';
} else {
$ns='';
}
foreach($keys as $key=>$value) {
$cols.=self::getPdoOne()->addDelimiter($prefixTable)
.".{$value} as ".self::getPdoOne()->addDelimiter($prefix.$value). ',';
Expand All @@ -210,7 +216,7 @@ public static function buildSelect($prefixTable='',$prefix='') {
$table = $value['reftable'];
$colLocal = self::getPdoOne()->addDelimiter($prefixTable . '.' . $key);

$class = $table . 'Repo';
$class = $ns.$table . 'Repo';
//$tableAlias=$prefixTable.':'.$table.':'.$key;

//$tableAlias2=$prefixTable.':'.$key;
Expand Down Expand Up @@ -258,31 +264,31 @@ public static function transform($inputRow) {
if(strpos($col,':')!==false) {
$arr=explode(':',$col);
$c=count($arr);
$k0='/'.$arr[1];
$k1='/'.$arr[1];
switch ($c) {
case 2:
$row[$k0][$arr[1]] = $value;
$row[$k1] = $value;
break;
case 3:
$row[$k0][$arr[1]][$arr[2]] = $value;
$row[$k1][$arr[2]] = $value;
break;
case 4:
$k2=$k0.'/'.$arr[2];
if(!isset($row[$k0][$arr[1]][$k2])) {
$row[$k0][$arr[1]][$k2]=[];
$k2=$k1.'/'.$arr[2];
if(!isset($row[$k1][$k2])) {
$row[$k1][$arr[1]][$k2]=[];
}
$row[$k0][$arr[1]][$k2][$arr[3]] = $value;
$row[$k1][$k2][$arr[3]] = $value;
break;
case 5:
$row[$k0][$arr[1]][$arr[2]][$arr[3]][$arr[4]]= $value;
$row[$k1][$arr[2]][$arr[3]][$arr[4]]= $value;
break;
case 6:
$k2=$k0.'/'.$arr[2];
$k2=$k1.'/'.$arr[2];
$k4=$k2.'/'.$arr[4];
if(!isset($row[$k0][$arr[1]][$k2][$arr[3]][$k4])) {
$row[$k0][$arr[1]][$k2][$arr[3]][$k4]=[];
if(!isset($row[$k1][$k2][$arr[3]][$k4])) {
$row[$k1][$k2][$arr[3]][$k4]=[];
}
$row[$k0][$arr[1]][$k2][$arr[3]][$k4][$arr[5]] = $value;
$row[$k1][$k2][$arr[3]][$k4][$arr[5]] = $value;
break;
}

Expand Down

0 comments on commit d1e7778

Please sign in to comment.