A simple object-relational mapping library built using PHP.

Overview

infinite-simple-orm

licence licence

A simple object-relational mapping library built using PHP.

Note

This project is intended only for experimental purposes, and in fact, the library is under development. It is not recommended for any usage on a production code.

Installation

Simply download this repository from github. Use composer to install dependencies.

composer install

Usage

  • Configure MySQL (MariaDB) database.
  • Import the database configuration provided in ./db folder to give a quick try
  • Edit pdoConnection.php, in root folder, change
    • host name,
    • user name and password as shown below, or pass your own PDO instance.
  • This ORM currently works only with a single database.
class pdoConnection  {

    private $username = "YOUR_USER_NAME"; // change this to your username
    private $password = "YOUR_DATABASE_PASSWORD";    // change this to your password
    private $dsn = "mysql:host=HOST;dbname=test_data_mapper"; // change HOST to your hostname
  • Use Postman or similar software to hit test.php, and the database query results will be shown in response.

Database Configuration

  • Find the database configuration in ./config/entity_definition.json file.

  • configure entity_definition.json as needed, using guide given below.

{

  "product": {
        "id": {
            "name" : "id",
            "primary" : true
        },
        "_assoc" : {
            "product_sku" : {
                "target" : "product_sku",
                "refer" : "product_id",
                "inverse" : "id",
                "type" : "OneToMany"
            }
        }
        
    },
  • Entity Name is used as the database table name by default. To explicitly set the database table name,
// 'product' is used as table name by default

"product": {

        "__table_name" : "product_table"
        //if __table_name is explicitly defined, it will be used as the table name of entity
        
        // attributes 
},
  • Entity attributes are described in the following formats :
{
    "entity_attribute" : "table_column"
    
    Or
    
    "entity_attribute" : {
                       "name" : "column_name"
                       //if explicitly defined, name will be used as the column name
    }
}
  • Primary keys can be defined like this, (multiple attributes can be defined as primary - composite keys)
{
    "entity_attribute_2" : {"primary" : TRUE}
}
  • Auto_Incremented values
"product" : {
     
       "entity_attribute" : {"autoIncrement" : TRUE}
     
}
  • Define Entity's Associations, if any,
{

 "entity_attribute" : "table_column",
 
  "_assoc" : {
                "associated_entity_name" : {
                    "target" : "associated entity_name",
                    "refer" : "referred attribute of associated entity", // how the entity joins the other entity
                    "inverse" : "PARENT ENTITY'S CORRESPONDING ATTRIBUTE (FOREIGN KEY OR PRIMARY KEY)"
                    "type" : "OneToMany"
                 }
   }
}

Obtain EntityManager

$connection->connection() ]); ">
$connection = new pdoConnection();

$entityManager = new EntityManager ((object) [
    "connection" => $connection->connection()
]);

Fetch data from database

  • To fetch data from the database, obtain an $EntityManager instance, call get(entity_name)
$data = $EntityManager->get('entity_name')->go();

or 

// get data by a key

//@return array 
$data = $EntityManager->get('entity_name',['entity_attrib' => 'some_value', 'entity_attrib_2' => 'some_other_value'])->go();

//invoke go() to get the data;

Inserting data to database

  • Once you retrieve an entity from database, EntityManager keeps track of it. If something has been changed, EntityManager takes care of changed properties and updates the database, once you save.

    • From last example, to change a property in the Entity and save,
save($data_one); //go() executes the query and do the insertion $entityManager->go(); ">
$data = $EntityManager->get('entity_name',['entity_attrib' => 'some_value', 'entity_attrib_2' => 'some_other_value'])->go();
$data_one = $data[0];

$data_one->some_attribute = "just_changed";
$entityManager->save($data_one);

//go() executes the query and do the insertion 
$entityManager->go();
"test_010", "product_name" => "test_product", "img_url" => "some_url"]; //no need to set all properties of entity manually, all the available properties for entities will be set from the object we pass $entityManager->save($product,$props); $entityManager->go(); //invoke go() to save the data; ">
//get an EntityResult instance
$product = $entityManager->entity("product");

// inserting values
$props = (object) ["id" => "test_010", "product_name" => "test_product", "img_url" => "some_url"];

//no need to set all properties of entity manually, all the available properties for entities will be set from the object we pass

$entityManager->save($product,$props); 
$entityManager->go();

//invoke go() to save the data;

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

You might also like...
AWS Cognito package using the AWS SDK for PHP/Laravel
AWS Cognito package using the AWS SDK for PHP/Laravel

Laravel Package to manage Web and API authentication with AWS Cognito AWS Cognito package using the AWS SDK for PHP This package provides a simple way

PHP REST API without using any frameworks. Contains all CRUD operations.
PHP REST API without using any frameworks. Contains all CRUD operations.

PHP REST API without any framework and CRUD operations 🖐 Hi there, this is a simple REST API built in PHP without using any frameworks. This is built

Generates OpenApi specification for Laravel, Lumen or Dingo using a configuration array and cebe/php-openapi

OpenApi Generator for Laravel, Lumen and Dingo. About The openapi-gen package provides a convenient way to create OpenApi specifications for Laravel,

EXPERIMENTAL plugin extending WPGraphQL to support querying (Gutenberg) Blocks as data, using Server Side Block registries to map Blocks to the GraphQL Schema.

WPGraphQL Block Editor This is an experimental plugin to work toward compatiblity between the WordPress Gutenberg Block Editor and WPGraphQL, based on

Zoho CRM API SDK is a wrapper to Zoho CRM APIs. By using this sdk, user can build the application with ease

Archival Notice: This SDK is archived. You can continue to use it, but no new features or support requests will be accepted. For the new version, refe

Using waifu2x api from DeepAI - ye UPSCALE YOUR WAIFUUUU

php-waifu2x-api Using waifu2x api from DeepAI - ye UPSCALE YOUR WAIFUUUU Usage You must fill your api key from DeepAI $API_KEY = "YOUR_API_KEY_HEREEEE

OpenAPI(v3) Validators for Symfony http-foundation, using `league/openapi-psr7-validator` and `symfony/psr-http-message-bridge`.

openapi-http-foundation-validator OpenAPI(v3) Validators for Symfony http-foundation, using league/openapi-psr7-validator and symfony/psr-http-message

Laravel api tool kit is a set of tools that will help you to build a fast and well-organized API using laravel best practices.
Laravel api tool kit is a set of tools that will help you to build a fast and well-organized API using laravel best practices.

Laravel API tool kit and best API practices Laravel api tool kit is a set of tools that will help you to build a fast and well-organized API using lar

This project lists all the mandatory steps I recommend to build a Website using Symfony, Twig, Doctrine.
This project lists all the mandatory steps I recommend to build a Website using Symfony, Twig, Doctrine.

{% raw %} -- keep this for Jekyll to fully bypass this documents, because of the Twig tags. Symfony Website Checklist 📑 Summary~~~~ Elevator pitch P

Owner
Maleesha Gimshan
Full stack web developer
Maleesha Gimshan
An object oriented PHP wrapper for the Livepeer API

Livepeer PHP An object oriented PHP wrapper for the Livepeer API Requirements PHP >= 7.4 A PSR-17 implementation A PSR-18 implementation Install Via C

Owen Voke 2 Nov 23, 2021
This PHP library will help you to work with your Pinterest account without using any API account credentials.

Pinterest Bot for PHP A PHP library to help you work with your Pinterest account without API credentials. The Pinterest API is painful: receiving an a

Sergey Zhuk 414 Nov 21, 2022
PHP library/SDK for Crypto APIs 2.0 using Guzzle version 7

cryptoapis/sdk-guzzle7 Crypto APIs 2.0 is a complex and innovative infrastructure layer that radically simplifies the development of any Blockchain an

Crypto APIs 3 Oct 21, 2022
An easy to use Fractal wrapper built for Laravel and Lumen applications

An easy to use Fractal wrapper built for Laravel and Lumen applications The package provides a nice and easy wrapper around Fractal for use in your La

Spatie 1.8k Dec 30, 2022
This project was built to connect WHMCS with GridPane.com's API service so we can create sites within WHMCS.

GridPane Server Module for WHMCS This project was built to connect WHMCS with GridPane.com's API service so we can create sites within WHMCS. Discliam

null 10 Sep 2, 2021
An SDK built to facilitate application development for Facebook Ads API.

Facebook Business SDK for PHP Introduction The Facebook Business SDK is a one-stop shop to help our partners better serve their businesses. Partners a

Meta 719 Dec 28, 2022
A Symfony bundle that provides #StandWithUkraine banner and has some built-in features to block access to your resource for Russian-speaking users.

StandWithUkraineBundle На русском? Смотри README.ru.md This bundle provides a built-in StandWithUkraine banner for your Symfony application and has so

Victor Bocharsky 10 Nov 12, 2022
A simple way of authenticating your RESTful APIs with API keys using Laravel

ApiGuard This package is no longer maintained This package is no longer maintained as Laravel already has a similar feature built-in since Laravel 5.8

Chris Bautista 691 Nov 29, 2022
Simple utility and class library for generating php classes from a wsdl file.

wsdl2phpgenerator Simple WSDL to PHP classes converter. Takes a WSDL file and outputs class files ready to use. Uses the MIT license. Announcement: We

null 802 Dec 10, 2022
API for Symbiota using the Lumen PHP PHP Micro-Framework By Laravel

symbiota-api API for Symbiota using the Lumen PHP PHP Micro-Framework By Laravel Laravel Lumen Official Documentation Documentation for the Lumen fram

Biodiversity Knowledge Integration Center 2 Jan 3, 2022