meltdown/database

v1.0.2 2018-05-28 22:53 UTC

README

A simple database component, with QueryBuiler, Model. Highly inspired by Eloquent by Laravel.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

You have to be at least PHP >=7.1.

Installing

You can you directly from github or using composer

With composer

composer require meltdown/database

Directly from github

git clone https://github.com/Dersaun/database.git

Connecting to database

<?php

use Meltdown\Database\Manager\Manager;

//Instante a new Manager to connect to database
$manager = new Manager();

//Connection to database
$manager->connectToDatabase([
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'mock',
    'username'  => 'root',
    'password'  => 'toor',
    'charset'   => 'utf8',
    'collation' => utf8_unicode_ci,
    'prefix'    => '',
    'options'   =>  [
        PDO::ATTR_PERSISTENT => true,
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
    ],
]);

//Make the connection available
$manager->makeGlobal();

Using the QueryBuilder

<?php

use Meltdown\Database\Manager\Manager as QBuilder;

$posts = QBuilder::table('posts')
                  ->where('post_id' '!=', 25)
                  ->get() // returns Meltdown\Database\Collection\Collection

$comments = QBuilder::table('comments')
                    ->join('posts', 'comments.post_id', '=', 'posts.post_id')
                    ->select('comments.comment', 'posts.*')
                    ->orderBy('posts.post_id')
                    ->get();

Using Models

<?php

use Meltdown\Database\Domain\Model;

class Post extends Model
{

}

class Comment extends Model
{
  /**
  * A comment belongs to one post.
  */
  public function post()
  {
    return $this->belongsTo('Post', 'post_id');
  }
}

$posts = new Post();

$posts = $posts->all();

$comments = new Comment();

$comments = $coment->post();

End with an example of getting some data out of the system or using it for a little demo

Running the tests

Explain how to run the automated tests for this system

Break down into end to end tests

Explain what these tests test and why

Give an example

And coding style tests

Explain what these tests test and why

Give an example

Deployment

Add additional notes about how to deploy this on a live system

Built With

  • Dropwizard - The web framework used
  • Maven - Dependency Management
  • ROME - Used to generate RSS Feeds

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Hat tip to anyone whose code was used
  • Inspiration
  • etc