Giter VIP home page Giter VIP logo

marquee's Introduction

Marquee Database Layer

Overview

Marquee is a free multi-database abstraction layer and ORM. Its purpose is to allow for universal code patterns while making use of intelligent data sources. Whether you choose to store your data in Redis, MySQL, or even a CSV - 99% of your PHP code remains the same.

Database Support

  • Redis: Testing
  • MySQL: Alpha / Testing
  • SQLite: Planned
  • MSSQL: Planned
  • CSV: Planned
  • JSON: Planned
  • PostgreSQL: Planned
  • Azure Cosmos DB: Planned

About the Author

My name is Charles Pellens. I am a self-taught software engineer from Michigan. I am passionate about simplifying the web development process through automation and innovation. I have a nack for creating clean, semantic APIs. I believe that code verbosity should not be dependent solely on comments. This project allows for expressive code by making use of simple, understandable, and predictable method and class names while maintaining flexible functionality. I hope you find that my work enables you to quickly get up and going with your next project.

https://charlespellens.me/ | [email protected]

Disclaimer: Not Production Ready

While I am very proud of the progress on this project, please do not use it for any mission critical work at this point. This is a work in progress and I invite you to play around with it or make it your own.

Quick Start / Example

<?php

include 'vendor/autoload.php';

/**
 * Library Use Statements
 */
use Marquee\Core\Connection\MySQLConnection;
use Marquee\Data\Entity;
use Marquee\Exception\Exception;
use Marquee\Schema\Property;

/**
 * PHP Core Use Statements
 */
use \Generator;

/**
 * Define a sample entity with two string properties:
 * - username
 * - password
 */
class User extends Entity
{
    public function getUsername(): string
    {
        return $this->username;
    }

    public static function Properties(): Generator
    {
        yield Property::string('username')->unique();
        yield Property::string('password');
    }
}

$db = new MySQLConnection(MySQLConnection::CreateDsn(DB_HOST, DB_PORT, DB_PASSWORD, DB_USERNAME));
$db->selectDb(DB_NAME);

if ($db->tryConnect($e)) {
    try {
        /**
         * Build the user table if it doesn't already exist in the schema
         */
        $table = User::BuildTable($db);
        if (!$table->exists()) {
            $table->create();
            echo 'Created user table', '<br>';
        }

        /**
         * Query all users
         */
        $userCount = 0;
        $users     = $db->query(User::class)->limit(10)->get();

        echo '<ul>';
        while ($user = $users->next()) {
            echo '<li>', $user, '</li>';
            $userCount++;
        }
        echo '</ul>';

        /**
         * If we have less than 10 users, insert a new one.
         */
        if ($userCount < 10) {
            $insert = $db->query(User::class)->create([
                'username' => 'Test ' . uniqid(),
                'password' => password_hash('test password', PASSWORD_ARGON2I)
            ]);

            if ($user = $insert->next()) {
                echo 'Created test user';
            }
        } else {
            /**
             * Start over if we have 10 users
             */
            $db->query(User::class)->truncate()->next();
            echo 'Deleted all users';
        }
    } catch (Exception $e) {
        echo 'Error: ', $e->getMessage();
    } finally {
        $db->disconnect();
    }
} else {
    exit($e->getMessage());
}

marquee's People

Contributors

cpellens avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.