Coder Social home page Coder Social logo

lulo's Introduction

lulo

A minimal ORM for PHP inspired by Django.

What's this?

This is a small and easy to use ORM based on Django's ORM API for PHP.

Requirements

PHP 5.4 and dependencies installed by composer (AdoDB and Twig template system).

Installation

lulo has been uploaded to packagist.org can be easilly installed with composer:

composer require intelligenia/lulo

Documentation

Local configuration

Create a configuration.local.php in your web server with the structure defined in configuration.local.example.php.

This file must contain access credential to your database as seen in the example:

function get_db_settings(){
    $db_settings = [
        "server" => "<DB SERVER>",
        "user" => "<DB USER>",
        "password" => "<DB PASSWORD>",
        "database" => "<DATABASE>"
    ];
    return $db_settings;
}

This local configuration file will be loaded automatically from configuration.php and will be used to access database.

API

Extended documents:

Examples

There is a test module gives you several examples of using Lulo and its query system.

/**
 * Example user class for a social-network-like system.
 * @author Diego J. Romero López at intelligenia.
 * */
class User extends \lulo\models\LuloModel{
	
	/** Model table */
	const TABLE_NAME = "user";
	
	/** Class name*/
	const CLASS_NAME = __CLASS__;
	
	/**
	 * Metainformation of the class
	 * */
	public static $META = [
		// Description of the model
		"model_description" => "Test user",
		// Verbose name
		"verbose_name" => "test user",
		// Verbose name (plural)
		"verbose_name_plural" => "test users",
		// Gender of the verbose name
		"gender" => "m",
		// Order in lists (["field1"=>"ASC|DESC", "field2"=>"ASC|DESC", ...])
		"order" => ["username"=>"ASC"]
	];
	
	/**
	 * Model attributes
	 * */
	protected static $ATTRIBUTES = [
		// Primary key
		"stack"=>["type"=>"string", "default"=>TEST_STACK, "verbose_name"=>"User dependant stack", "auto"=>true],
		"id" => ["type"=>"int", "verbose_name"=>"Identificador único del usuario", "auto"=>true],
		
        	// Proper user fields
		"first_name" => ["type"=>"string", "verbose_name"=>"Name", "access"=>"rw"],
		"last_name" => ["type"=>"string", "verbose_name"=>"Family name"],
		"email" => ["type"=>"string", "subtype"=>"email", "verbose_name"=>"E-Mail"],
		"phone" => ["type"=>"string", "subtype"=>"phone", "verbose_name"=>"User telepohone number", "null"=>true, "default"=>null],
		"username" => ["type"=>"string", "subtype"=>"username", "verbose_name"=>"Username"],
		"sha1_password" => ["type"=>"string", "verbose_name"=>"Password"],
		
        	// Photograph of the user. Stored as a blob in database
		"main_photo" => ["type"=>"blob", "verbose_name"=>"User photo", "null"=>true, "default"=>null],
		"main_photo_mimetype" => ["type"=>"string", "verbose_name"=>"Mimetype of main_photo", "default" =>"application/octet-stream"],
		"main_photo_filename" => ["type"=>"string", "verbose_name"=>"Filename of main_photo", "null"=>true, "default"=>null],
		
        	// Datetime fields
		"last_update_datetime" => ["type"=>"string", "subtype"=>"datetime", "verbose_name"=>"Last update of this object", "auto"=>true],
		"creation_datetime" => ["type"=>"string", "subtype"=>"datetime", "verbose_name"=>"Creation datetime of this object", "auto"=>true],
	];
	
	
	/** Primary key */
	protected static $PK_ATTRIBUTES = ["stack", "id"];
	
	
	/**
	 * Related models.
	 * */
	protected static $RELATED_MODELS = ["Tag", "Photo", "Post"];
	
	
	/** Relationships */
	protected static $RELATIONSHIPS = [
	
	];
}
User::init();

Extending Lulo

Adding new DBMS SQL templates

Add a new folder in sql_templates with the name that will identify your DBMS (mssql2012, for example).

Overwrite the queries you need. Lulo template system will first load the templates you specify here and if it doesn't find the template, it will try to load it from the _default folder.

TODO

  • Allow models to dynamically change of table. It can be done by reimplementing getTableName method.
  • End translation of code to English.
  • Translate documents to English.
  • Reimplement Collection to use RecordSet.
  • Script for table creation from model. Manager class in management namespace allows creation and deletion of model tables.
  • Migrations.

License

MIT License.

Authors

  • Lulo and Lulo query created by the team leader and main developer of this project: Diego J. Romero López at intelligenia ([email protected])
  • DB abstraction layer created by several members of intelligenia team. Reviewed and extended by Gerardo Fernandez Rodríguez.
  • QueryResult was done with Gerardo Fernandez Rodríguez.
  • Several bugfixes and tests in MSSQL done by Francisco Morales.
  • Minor translation fixes done by Brian Holsters

lulo's People

Contributors

brian-holsters avatar diegojromerolopez avatar moralesgea avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

lulo's Issues

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.