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

[Database] Initial commit logic #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions packages/database/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/tests export-ignore
/phpunit.xml.dist export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
2 changes: 2 additions & 0 deletions packages/database/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/
composer.lock
7 changes: 7 additions & 0 deletions packages/database/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CHANGELOG
=========

2.0
===

* First release
29 changes: 29 additions & 0 deletions packages/database/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2022, Divine Niiquaye Ibok
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
92 changes: 92 additions & 0 deletions packages/database/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<div align="center">

# The Poakium Database

[![Latest Version](https://img.shields.io/packagist/v/biurad/database.svg?style=flat-square)](https://packagist.org/packages/biurad/database)
[![Software License](https://img.shields.io/badge/License-BSD--3-brightgreen.svg?style=flat-square)](LICENSE)
[![Workflow Status](https://img.shields.io/github/workflow/status/biurad/php-git-scm/build?style=flat-square)](https://github.com/biurad/php-database/actions)
[![Code Maintainability](https://img.shields.io/codeclimate/maintainability/biurad/php-database?style=flat-square)](https://codeclimate.com/github/biurad/php-database)
[![Coverage Status](https://img.shields.io/codecov/c/github/biurad/php-database?style=flat-square)](https://codecov.io/gh/biurad/php-git-scm)
[![Quality Score](https://img.shields.io/scrutinizer/g/biurad/php-database.svg?style=flat-square)](https://scrutinizer-ci.com/g/biurad/php-database)

</div>

---

A Blazing fast database abstraction layer (DBAL) with object–relational mapping(ORM) support PHP[1] library for working with PHP Data Objects(PDO) databases. It is a simple, easy to use, and powerful tool for querying data into databases.

## 📦 Installation

PHP[1] 8.0 or newer and SQL Server (2008 R2 or higher), MySQL (5.7 or higher), Postgres (12.12 or higher) and Oracle (12.1 or higher) are required. The recommended way to install, is by using [Composer][2]. Simply run:

```bash
$ composer require biurad/database
```

## 📍 Quick Start

Here is an example of how to use the library:

A plain PDO example of this:

```php
$stmt = $pdo->prepare("SELECT * FROM myTable WHERE name = ?");
$stmt->bindParam(1, $name, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->get_result();
$products=[];

while($row = $result->fetch_assoc()) $product[] = $row;
$stmt->close();
```

Turns into this using query builder:

```php
$products = $connection->getQueryBuilder()
->select()
->from('myTable')
->where('name', '=', $name)
->fetchList();

// or
$products = $pdo->fetchList("SELECT * FROM myTable WHERE name = ?", $name);
```

or using the query builder with the ORM:

```php
$products = $connection->getQueryBuilder()
->select()
->from(Entity\Product::class)
->where('name', '=', $name)
->fetchList();

// or
$products = $connection->getRepository(ProductRepository::class)
->findBy(['name' => $name]);
```

## 📓 Documentation

In-depth documentation on how to use this library can be found at [docs.biurad.com][3]. It is also recommended to browse through unit tests in the [tests](./tests/) directory.

## 🙌 Sponsors

If this library made it into your project, or you interested in supporting us, please consider [donating][4] to support future development.

## 👥 Credits & Acknowledgements

- [Divine Niiquaye Ibok][5] is the author this library.
- [All Contributors][6] who contributed to this project.

## 📄 License

Poakium Database is completely free and released under the [BSD 3 License](LICENSE).

[1]: https://php.net
[2]: https://getcomposer.org
[3]: https://docs.biurad.com/poakium/database
[4]: https://biurad.com/sponsor
[5]: https://github.com/divineniiquaye
[6]: https://github.com/biurad/php-database/contributors
33 changes: 33 additions & 0 deletions packages/database/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "biurad/database",
"type": "library",
"description": "Library for SQL querying data into databases (any database supported by PDO)",
"keywords": ["database", "query", "repository", "library", "php"],
"license": "BSD-3-Clause",
"authors": [
{
"name": "Niiquaye Divine Ibok",
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"preferred-install": "dist",
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"require": {
"php": "^8.0",
"ext-pdo": "*"
},
"autoload": {
"psr-4": {
"Biurad\\Database\\": "src/"
}
},
"suggest": {
"psr/log": "Required to use loggers for reporting of execution"
}
}
26 changes: 26 additions & 0 deletions packages/database/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true"
>
<php>
<ini name="error_reporting" value="-1" />
</php>

<testsuites>
<testsuite name="Poakium Database Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>
</phpunit>