Skip to content

Commit

Permalink
Merge pull request #100 from KumbiaPHP/dev
Browse files Browse the repository at this point in the history
V0.5.3
  • Loading branch information
joanhey authored May 14, 2020
2 parents aa4dbc7 + eaae813 commit 8e41cce
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 10 deletions.
4 changes: 2 additions & 2 deletions BaseRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
/**
* Base del ORM ActiveRecord.
*/
class BaseRecord
abstract class BaseRecord
{

public const VERSION = '0.5.2';
public const VERSION = '0.5.3';

/**
* Database por defecto usa default.
Expand Down
16 changes: 8 additions & 8 deletions LiteRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
/**
* Implementación de patrón ActiveRecord sin ayudantes de consultas SQL.
*/
class LiteRecord extends BaseRecord
abstract class LiteRecord extends BaseRecord
{
/**
* Obtener objeto por clave primaria, $var = Modelo($id).
*
* @param string $id valor para clave primaria
* @return self
* @return self|false
*/
public function __invoke($id): self
public function __invoke($id)
{
return self::get($id);
}
Expand All @@ -40,7 +40,7 @@ public function __invoke($id): self
*
* @param string $callback
*
* @return bool
* @return null|false
*/
protected function callback(string $callback)
{
Expand Down Expand Up @@ -105,7 +105,7 @@ public function update(array $data = []): bool
if ($this->callback('_beforeUpdate') === \false) {
return \false;
}
$this->hasPK();
//$this->hasPK();
$values = [];
$sql = QueryGenerator::update($this, $values);
//var_dump($values);var_dump($sql);die;
Expand Down Expand Up @@ -176,9 +176,9 @@ public static function delete($pk): bool
* @param string $pk valor para clave primaria
* @param string $fields campos que se desean obtener separados por coma
*
* @return self
* @return self|false
*/
public static function get($pk, $fields = '*'): self
public static function get($pk, $fields = '*')
{
$sql = "SELECT $fields FROM ".static::getSource().' WHERE '.static::$pk.' = ?';

Expand Down Expand Up @@ -208,7 +208,7 @@ public static function all(string $sql = '', array $values = []): array
* @param string $sql
* @param array $values
*
* @return static
* @return static|false
*/
public static function first(string $sql, array $values = [])//: static in php 8
{
Expand Down
34 changes: 34 additions & 0 deletions Query/sqlite_last_insert_id.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* KumbiaPHP web & app Framework.
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://wiki.kumbiaphp.com/Licencia
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@kumbiaphp.com so we can send you a copy immediately.
*
* @category Kumbia
*
* @copyright 2005 - 2020 Kumbia Team (http://www.kumbiaphp.com)
* @license http://wiki.kumbiaphp.com/Licencia New BSD License
*/
namespace Kumbia\ActiveRecord\Query;

/**
* Obtiene el último id generado en sqlite.
*
* @param \PDO $dbh conexion pdo
* @param string $pk campo clave primaria
* @param string $table nombre de tabla
* @param string $schema esquema
* @return string
*/
function sqlite_last_insert_id(\PDO $dbh, $pk, $table, $schema = \null)
{
return $dbh->lastInsertId();
}
34 changes: 34 additions & 0 deletions Query/sqlite_limit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* KumbiaPHP web & app Framework.
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://wiki.kumbiaphp.com/Licencia
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@kumbiaphp.com so we can send you a copy immediately.
*
* @category Kumbia
*
* @copyright 2005 - 2020 Kumbia Team (http://www.kumbiaphp.com)
* @license http://wiki.kumbiaphp.com/Licencia New BSD License
*/

namespace Kumbia\ActiveRecord\Query;

/**
* Adiciona limit y offset a la consulta sql en sqlite.
*
* @param string $sql consulta select
* @param int $limit valor limit
* @param int $offset valor offset
* @return string
*/
function sqlite_limit($sql, int $limit, int $offset = 0)
{
return $sql." LIMIT $offset, $limit";
}

0 comments on commit 8e41cce

Please sign in to comment.