-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
tomolimo
Contributor
|
||
* 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.
Sorry, something went wrong.
trasher
Author
Collaborator
|
||
* 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 | ||
--------------- | ||
|
@@ -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.
Sorry, something went wrong. |
||
|
||
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.
Sorry, something went wrong. |
||
* ``orderby``: first argument is the field name, second is the order, ``ASC`` or ``DESC`` | ||
This comment has been minimized.
Sorry, something went wrong. |
||
* ``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.
Sorry, something went wrong. |
||
|
||
$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(); |
MySQL and MariaDB are the same, right?