Skip to content

Commit

Permalink
correcao de class
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Morais authored and Bruno Morais committed Nov 26, 2023
1 parent b519500 commit 3764641
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 28 deletions.
22 changes: 22 additions & 0 deletions example/ExampleDao.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use BMorais\Database\Crud;
use BMorais\Database\CrudBuilder;

class ExampleDao extends CrudBuilder {


public function __construct()
{
$this->setTable("EXAMPLE");
$this->setClassModel("exampleModel");
}

public function findName(): array {
$this->selectBuilder()
->where("NOME=?",["Joao"])
->orderBy("NOME")
->executeQuery()
->fetchArrayAssoc();
}
}
41 changes: 13 additions & 28 deletions src/CrudBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @subpackage class
* @access protected
*/
abstract class CrudBuilder
abstract class CrudBuilder extends Crud
{
use DatalayerTrait;

Expand Down Expand Up @@ -45,7 +45,7 @@ abstract class CrudBuilder
* @param array $paramns
* @return $this
*/
protected function select(string $fields = "*", array $paramns = []): CrudBuilder
public function selectBuilder(string $fields = "*", array $paramns = []): self
{
try {
$query = "SELECT {$fields} FROM {$this->getTable()}";
Expand All @@ -63,7 +63,7 @@ protected function select(string $fields = "*", array $paramns = []): CrudBuilde
* @param array $paramns
* @return $this
*/
protected function insert(string $fields, array $paramns): self
protected function insertBuilder(string $fields, array $paramns): self
{
try {
$numparams = '';
Expand All @@ -84,7 +84,7 @@ protected function insert(string $fields, array $paramns): self
* @param array $paramns
* @return $this
*/
protected function update(string $fields, array $paramns): self
protected function updateBuilder(string $fields, array $paramns): self
{
try {
$fields_T = '';
Expand All @@ -107,7 +107,7 @@ protected function update(string $fields, array $paramns): self
* @param array $paramns
* @return $this
*/
protected function delete(): self
protected function deleteBuilder(): self
{
try {
$query = "DELETE FROM {$this->getTable()}";
Expand Down Expand Up @@ -183,6 +183,7 @@ protected function orWhere(string $condition, array $paramns = []): self

/**
* @param string $parameter
* @param $order
* @return $this
*/
protected function orderBy(string $parameter, $order = null): self
Expand All @@ -196,6 +197,11 @@ protected function orderBy(string $parameter, $order = null): self
}
}

/**
* @param string $parameter
* @param $order
* @return $this
*/
protected function addOrderBy(string $parameter, $order = null): self
{
try {
Expand Down Expand Up @@ -371,7 +377,7 @@ protected function executeQuery(): self
/**
* @return void
*/
protected function debug()
protected function debug(): void
{
try {
echo $this->query . '<pre>' . print_r($this->params) . '</pre>';
Expand All @@ -381,27 +387,6 @@ protected function debug()
}
}

/**
* @return false|string
*/
protected function lastInsertId(): ?string
{
try {
return $this->lastId();
} catch (\PDOException $e) {
$this->setError($e);
}
}

/**
* @param $params
* @return self
*/
protected function setParameter($params): self
{
$this->params = array_merge($this->params, $params);
return $this;
}

/**
* @param string $query
Expand All @@ -420,7 +405,7 @@ private function add(string $query, string $type, array $params = []): void
}

if (!empty($params))
$this->params = array_merge($this->params, $params);
$this->setParameter($params);
} catch (\PDOException $e) {
$this->setError($e);
}
Expand Down
19 changes: 19 additions & 0 deletions src/DatalayerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,25 @@ protected function getPrepare(): PDOStatement
return $this->prepare;
}

/**
* @param $params
* @return self
*/
protected function setParameter($params): self
{
$this->params = array_merge($this->params, $params);
return $this;
}

/**
* @param $params
* @return array
*/
protected function getParameter(): array
{
return $this->params;
}

protected function getResult(): array
{
return $this->resultArray;
Expand Down

0 comments on commit 3764641

Please sign in to comment.