Skip to content

Commit

Permalink
Formatting, reword, typos
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Sep 30, 2016
1 parent c0d71f1 commit e1c322e
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions source/specifications/lessql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,31 @@ Introduction
Several database engines
------------------------

We want be able to use GLPI with databases:
We want be able to use GLPI with following databases:

* MySQL
* MariaDB
* MySQL/MariaDB

This comment has been minimized.

Copy link
@trasher

trasher Sep 30, 2016

Author Collaborator

MySQL and MariaDB are the same, right?

This comment has been minimized.

Copy link
@tomolimo

tomolimo Sep 30, 2016

Contributor

Yes and no.
You can replace mysql by mariadb but not the reverse. And they have some behaviors that are different. Ex: an Optimize will lock innodb tables on mariadb but not on recent mysql.

* Postgresql
* sqlite

To do that, we will use a lightweight ORM: LessQL (http://lessql.net/)
* SQLite

To achieve that, we will use a lightweight ORM: `LessQL <http://lessql.net/>`_.

Performances
------------

To have better performances, we will do only simple queries (never use joins).


Main changes in database
------------------------

The database structure must be changed:

* table names from *plurial* to *singular*
* foreignkey from *plurial* to *singular*
* all boolean like is_deleted must be in type *boolean* instead *integer*
* table names from *plural* to *singular*

This comment has been minimized.

Copy link
@trasher

trasher Sep 30, 2016

Author Collaborator

Is this changed really required? Well, changes will be huge, but if we can limit a bit... :)

This comment has been minimized.

Copy link
@ddurieux

ddurieux Sep 30, 2016

Contributor

lessql use it and foreignkey is often used like this

* foreignkey from *plural* to *singular*
* all boolean like ``is_deleted`` must be in type *boolean* instead of *integer*
* foreignkeys with action:
* *update* => *NO_ACTION*
* *delete* => *SET NULL* , not use *CASCADE* because we will not be able to manage logs of delete items



* *update* => ``NO_ACTION``
* *delete* => ``SET NULL``, do not use ``CASCADE`` because we will not be able to manage logs of delete items

Use abstraction
---------------
Expand All @@ -46,26 +41,26 @@ In case we want use another ORM later, we will define an abstraction layer::

glpi code <-> abstraction class <-> use LessQL functions

Create a class: ``CommonDB``

This comment has been minimized.

Copy link
@trasher

trasher Sep 30, 2016

Author Collaborator

To respect CS, CommonDb, no?


Create a class: *CommonDB*

with functions:

* *table*: define the table to do query, so create the query
* *select*: list of fields to select, so add select to the query (if this not called, will get all fields), id is always implicit, so not need ad it
* *where*: first arg is the field, second is what to search (if string it's = 'your string', if array it's IN ('str', 'str')), third is '' or 'not'
* *orderby*: first arg is the field name, second 'ASC' or 'DESC'
* *limit*: first arg is count, second the offset
* *count*: get number of elements found
* *fetch*: get only first element
* *fetchall*: get all elements
with functions:

For example query all computers with id + name have is_deleted = false::
* ``table``: define the table to do query, so create the query
* ``select``: list of fields to select, so add select to the query (if this not called, will get all fields), id is always implicit, so not need ad it
* ``where``: first argument is the field, second is what to search (if string is *your string*, this will query for ``IN ('your', 'string')``), third is ``''`` or ``'not'``

This comment has been minimized.

Copy link
@trasher

trasher Sep 30, 2016

Author Collaborator

I've changed here because it seems incorrect to me...

* ``orderby``: first argument is the field name, second is the order, ``ASC`` or ``DESC``

This comment has been minimized.

Copy link
@trasher

trasher Sep 30, 2016

Author Collaborator

CS: orderBy

* ``limit``: first argument is count, second the offset
* ``count``: get number of elements found
* ``fetch``: get only first element
* ``fetchall``: get all elements

This comment has been minimized.

Copy link
@trasher

trasher Sep 30, 2016

Author Collaborator

CS: fetchAll


$cDB = new CommonDB();
$cDB->table('glpi_computer');
$cDB->select('name');
$cDB->where('is_deleted', true);
$my_computers = $cDB->fetchall();
For example query *all computers with id and name having is_deleted equals to true*:

.. code-block:: php
<?php
$cDB = new CommonDB();
$cDB->table('glpi_computer');
$cDB->select('name');
$cDB->where('is_deleted', true);
$my_computers = $cDB->fetchall();

0 comments on commit e1c322e

Please sign in to comment.