2017 © Pedro Peláez
 

library rdb

Simple relational database layer that abstracts SQL script to more usual persistence functions. It still provides a selectSQL function for more advanced and customized queries.

image

tdw/rdb

Simple relational database layer that abstracts SQL script to more usual persistence functions. It still provides a selectSQL function for more advanced and customized queries.

  • Saturday, February 24, 2018
  • by tiago.desenvolvedorweb
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

RDB - Relational Database

Simple relational database layer that abstracts SQL script to more usual persistence functions. It still provides a selectSQL function for more advanced and customized queries., (*1)

Build Status, (*2)

Requirements

PHP: >=7.0, (*3)

Install

$ composer require tdw/rdb

Usage

require autoload

<?php

$config = [
    'db_driver' => 'mysql',
    'db_host' => 'localhost',
    'db_port' => '3306',
    'db_name' => 'blog',
    'db_user' => 'root',
    'db_pass' => 'root'
];

$rdb = new \Tdw\RDB\Wrapper($config);
$database = $rdb->getDatabase();
<?php

try {    
    //select
    $select = $database->select('posts');
    /**@var \Tdw\RDB\Result\Select $result*/
    $result = $select->execute();
    print_r($result->fetchAll());    
} catch (Tdw\RDB\Exception\StatementExecuteException $e) {
    die($e->getPrevious());
}
<?php

try {    
    //insert
    $insert = $database->insert(
        'posts',
        ['title'=>'Post title','description'=>'Post desc']
    );
    /**@var \Tdw\RDB\Result\Insert $result*/
    $result = $insert->execute();
    print_r($result->lastInsertId());    
} catch (Tdw\RDB\Exception\StatementExecuteException $e) {
    die($e->getPrevious());
}
<?php

try {    
    //update
    $update = $database->update(
        'posts',
        ['title'=>'Post title','description'=>'Post desc'],
        ['id' => 1]
    );
    /**@var \Tdw\RDB\Result\Update $result*/
    $result = $update->execute();
    print_r($result->rowCount());    
} catch (Tdw\RDB\Exception\StatementExecuteException $e) {
    die($e->getPrevious());
}
<?php

try {    
    //delete
    $delete = $database->delete('posts', ['id' => 1]);
    /**@var \Tdw\RDB\Result\Delete $result*/
    $result = $delete->execute();
    print_r($result->rowCount());    
} catch (Tdw\RDB\Exception\StatementExecuteException $e) {
    die($e->getPrevious());
}

Tdw\RDB\Database

->select(string $table, array $columns = ['*'])
->insert(string $table, array $parameters)
->update(string $table, array $parameters, array $conditions)
->delete(string $table, array $conditions)
->selectSQL(string $sql, array $parameters = [])
->beginTransaction()
->commit()
->rollBack()

Statement Class

Tdw\RDB\Statement\Select
Tdw\RDB\Statement\Insert
Tdw\RDB\Statement\Update
Tdw\RDB\Statement\Delete, (*4)

Statement Method

Used only in Tdw\RDB\Statement\Select, (*5)

->columns(array $columns)
->join(
  string $childTable,
  string $foreignKeyChild,
  string $operator,
  string $primaryKeyParent
)
->where(string $column, string $operator, $value)
->orWhere(string $column, string $operator, $value)
->between(string $column, $valueOne, $valueTwo)
->notBetween(string $column, $valueOne, $valueTwo)
->orBetween(string $column, $valueOne, $valueTwo)
->orNotBetween(string $column, $valueOne, $valueTwo)
->in(string $column, array $subSet)
->notIn(string $column, array $subSet)
->orIn(string $column, array $subSet)
->orNotIn(string $column, array $subSet)
->like(string $column, string $value)
->orLike(string $column, string $value)
->notLike(string $column, string $value)
->orNotLike(string $column, string $value)
->null(string $column)
->orNull(string $column)
->notNull(string $column)
->orNotNull(string $column)
->orderBy(string $columns, $designator = 'ASC')
->limit(int $count, int $offset = 0)

Used all statement, (*6)

->execute(): //respective result
->parameters(): array

Result Class

Tdw\RDB\Result\Select
Tdw\RDB\Result\Insert
Tdw\RDB\Result\Update
Tdw\RDB\Result\Delete, (*7)

Result Method

Used only in Tdw\Result\Select, (*8)

->fetchAll(): \Tdw\RDB\Contract\Collection
->fetch(): \Tdw\RDB\Contract\Item

Used only in Tdw\Result\Insert, (*9)

->lastInsertId(string $name = null)

Used all result, (*10)

->rowCount()

Collection Method

->get($key);
->all(): array;
->isEmpty(): bool;
->contains($value): bool;
->keys(): array;
->values(): array;
->shift();
->pop();
->push($value);
->prepend($value);
->remove($key);
->search($value);
->sort(\Closure $callback);
->each(\Closure $callback);
->filter(\Closure $callback): Collection;
->map(\Closure $callback): Collection;
->add($key, $value): Collection;
->clear();

Contributing

Add new features., (*11)

License

The Tdw RDB is open-sourced software licensed under the MIT license., (*12)

The Versions

24/02 2018

dev-master

9999999-dev

Simple relational database layer that abstracts SQL script to more usual persistence functions. It still provides a selectSQL function for more advanced and customized queries.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Tiago Lopes

24/02 2018

1.0.6

1.0.6.0

Simple relational database layer that abstracts SQL script to more usual persistence functions. It still provides a selectSQL function for more advanced and customized queries.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Tiago Lopes

24/02 2018

1.0.5

1.0.5.0

Simple relational database layer that abstracts SQL script to more usual persistence functions. It still provides a selectSQL function for more advanced and customized queries.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Tiago Lopes

01/02 2018

1.0.4

1.0.4.0

Simple relational database layer that abstracts SQL script to more usual persistence functions. It still provides a selectSQL function for more advanced and customized queries.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Tiago Lopes

21/01 2018

1.0.3

1.0.3.0

Simple relational database layer that abstracts SQL script to more usual persistence functions. It still provides a selectSQL function for more advanced and customized queries.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Tiago Lopes

20/01 2018

1.0.2

1.0.2.0

Simple relational database layer that abstracts SQL script to more usual persistence functions. It still provides a selectSQL function for more advanced and customized queries.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Tiago Lopes

11/01 2018

1.0.1

1.0.1.0

Simple relational database layer that abstracts SQL script to more usual persistence functions. It still provides a selectSQL function for more advanced and customized queries.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Tiago Lopes

29/09 2017

1.0.0

1.0.0.0

  Sources   Download

The Requires

  • php >=7.1

 

The Development Requires

by Tiago Lopes

29/09 2017

0.9.9

0.9.9.0

  Sources   Download

The Requires

  • php >=7.1

 

The Development Requires

by Tiago Lopes

29/09 2017

0.9.8

0.9.8.0

  Sources   Download

The Requires

  • php >=7.1

 

The Development Requires

by Tiago Lopes