2017 © Pedro Peláez
 

library minifast-orm

A little ORM, very simple to use and ultra fast

image

itechcydia/minifast-orm

A little ORM, very simple to use and ultra fast

  • Monday, July 16, 2018
  • by iTechCydia
  • Repository
  • 2 Watchers
  • 2 Stars
  • 15 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

MiniFast ORM

MiniFast ORM is a very little Object-Relational Mapping system. It will be usefull for little web projects where you don't want to spend all your time writting SQL queries., (*1)

Documentation

First of all

You need to create a .xml file containing your databse scheme. All supported types and the syntax will be available soon. Example:, (*2)

<?xml version="1.0" encoding="UTF-8"?>
<database name="main">
    <table name="user">
        <column name="id" type="int" primaryKey="true" autoIncrement="true"/>
        <column name="pseudo" type="varchar" size="50"/>
        <column name="email" type="varchar" size="139"/>
        <column name="password" type="varchar" size="128"/>
        <column name="admin" type="boolean" default="0"/>
        <column name="image" type="text"/>
        <column name="newsletter" type="boolean" default="true"/>
        <column name="email_public" type="boolean" default="true"/>
    </table>
    <table name="category">
        <column name="id" type="int" primaryKey="true" autoIncrement="true"/>
        <column name="name" type="varchar" size="20"/>
    </table>
    <table name="topic">
        <column name="id" type="int" primaryKey="true" autoIncrement="true"/>
        <column name="category" type="int" required="true"/>
        <foreign-key foreign-table="category">
            <reference local="category" foreign="id"/>
        </foreign-key>
    </table>
</database>

Install

Install MiniFast with Composer by adding it to the composer.json file:, (*3)

{
    "require": {
        "minifast/minifast-orm": "^1"
    }
}

There is an installer included in MiniFast that will create classes for you based on your xml schema. Assuming you are in your website root directory, execute it like this:, (*4)

$ php vendor/minifast/minifast-orm/init.php /path/to/schema.xml

There will be no input if there is no error., (*5)

How to use

After running the installer, an autoloader has been created. Set up the MySQL host, user and password (defaults are localhost, root and root) in vendor/itechcydia/minifast-orm/src/minifast/Base.php and vendor/itechcydia/minifast-orm/src/minifast/BaseQuery.php __construct() methods., (*6)

An autoload.php file has been created by Composer and you need to include it in order to use MiniFast. Assuming you have the same schema.xml than the one above, you will find some examples below:, (*7)

INSERT

<?php
$user = new User();
$user
    ->setPseudo('iTechCydia')
    ->setEmail('email@server.com')
    ->setPassword(hash('whirlpool', 'theUserSecretPassword'))
    ->setDate(time())
    ->save();

This will create the SQL query and execute it., (*8)

SELECT

Select 10 users starting after the third., (*9)

<?php
$user = new UserQuery::create()
    ->limit(10)
    ->offset(3)
    ->findAll();

Only the user 23., (*10)

<?php
$user = new UserQuery::create()
    ->findPK(23);

Users 23, 24 and 25., (*11)

<?php
$user = new UserQuery::create()
    ->findPKs([23, 24, 25]);

User where pseudo is iTechCydia., (*12)

<?php
$user = new UserQuery::create()
    ->findByPseudo('iTechCydia')
    ->find();

UPDATE

Update user 23 and set newsletter to true, email_public to false and email to email2@server.com., (*13)

<?php
$user = UserQuery::create()
    ->filterById(23)
    ->setNewsletter(true)
    ->setEmailPublic(false)
    ->setEmail('email2@server.com')
    ->save(); // Don't forget to save!

DELETE

Delete all from user table (you need to set the first parameter to true to avoid any mistake), (*14)

<?php
$user = UserQuery::create()
    ->delete(true);

Delete specific users using filters, (*15)

$user = UserQuery::create()
    ->filterByNewsletter(false) // bad users :p
    ->delete();

The Versions

16/07 2018

dev-master

9999999-dev

A little ORM, very simple to use and ultra fast

  Sources   Download

MIT

The Requires

  • php ^7.0

 

16/07 2018

v1.0

1.0.0.0

A little ORM, very simple to use and ultra fast

  Sources   Download

MIT

The Requires

  • php ^7.0

 

06/07 2018

v1.0-beta.3

1.0.0.0-beta3

A little ORM, very simple to use and ultra fast

  Sources   Download

MIT

The Requires

  • php ^7.0

 

01/07 2018

v1.0-beta.2

1.0.0.0-beta2

A little ORM, very simple to use and ultra fast

  Sources   Download

MIT

The Requires

  • php ^7.0