Skip to content

Latest commit

 

History

History
503 lines (418 loc) · 8.07 KB

01-usage.md

File metadata and controls

503 lines (418 loc) · 8.07 KB

Using UDMS

Installation

olive-cms/udms is available on Packagist (olive-cms/udms) and as such installable via Composer.

composer require olive-cms/udms

If you do not use Composer, you can grab the code from GitHub, and use any PSR-0 compatible autoloader (e.g. the Symfony2 ClassLoader component) to load Monolog classes.

Core Concepts

Coming soon!

Get udms

// load autoload
require_once '/path/to/vendor/autoload.php';
use Olive\UDMS\Core as udms;

// create a udms
$udms = new udms('/path/to/vendor/', '/path/to/database/dir');

Addons

Get available addons

$list = $udms->getAddonsList();
/* output array
 * example:
  Array
  (
      [0] => MySQL
      [1] => MongoDB
      [2] => Json
  )
 */

Set addon

Set you Selection addon

// output void
$udms->setAddon('json');

App Model

Set App Model

$udms->setAppModel(
  [
    'school' // database name
    => [
      'student' // table name
      => [
        'id' // column name
        => [
          'type' => 'int',
          'index' => 'primary',
          'auto' => [
              'start' => 93000000,
              'add' => 43
          ]
        ],
        'fullname' => [
          'type' => 'text',
          '__udms_config'
          => [
            'mysql_mysql' => [
              'charset' => [
                  'utf8' => 'utf8_persian_ci'
              ]
            ]
          ]
        ]
      ]
    ]
  ]
);
// output void

Render

Render App model for Your selection addon:

/*
 * important: first set addon and next render!
 * output void
 */
$udms->render();

Databases method

Available Database Rule

Some addons (example mysql) with some config, Does not allow for Create Database. this method for test available create database.

// output Boolean
if($udms->availableDatabaseRule()) {
  // available
} else {
  // not available
}

Create Database

// output void
$udms->createDatabase('school',
  [] // config
);

Exists Database

Check exists Database

// output Boolean
if($udms->existsDatabase('school')) {
  // exists
} else {
  // not exists
}

Drop Database

/*
 * Warning: delete databse dir in udms chache dir
 * output void
 */
$udms->dropDatabase('school');

Rename Database

// output void
$udms->renameDatabase('school', 'to');

List Databases

$list = $udms->listDatabases();
/* output array
 * example:
  Array
  (
      [0] => school
  )
 */

Tables method

Available Table Rule

Check available table rule

// output Boolean
if($udms->school->availableTableRule()) {
  // available
} else {
  // not available
}

Create Table

// output void
$udms->school->createTable('studnet',
  [] // config
);

Exists Table

Check exist table

// output Boolean
if($udms->school->existsTable('studnet')) {
  // exists
} else {
  // not exists
}

Drop Table

// output void
$udms->school->dropTable('studnet');

Rename Table

/*
 * Notice: rename database dir in udms cache dir
 * output void
 */
$udms->school->renameTable('studnet', 'to');

Clean Table

// output void
$udms->school->cleanTable('studnet');

List Tables

$list = $udms->school->listTables();
/* output array
 * example:
  Array
  (
      [0] => class
      [1] => students
      [2] => teacher
  )
 */

Columns method

Available Column Rule

Check available columns rule

// output Boolean
if($udms->school->availableColumnRule()) {
  // available
} else {
  // not available
}

Create Column

// output void
$udms->school->student->createColumn('studnet',
  [] // config
);
/**
 * config available:
 * @param type -> [int, text]
 * @param length -> (0==ultimate)
 * @param index -> [primary]
 * @param auto -> [start => int, add => int]
 * @param __udms_rel -> [table => column]
 */
/*
# example 1:
$udms->school->classes->createColumn('id',
  [
    'type' => 'int',
    'lenght' => 8,
    'index' => 'primary',
    'auto' => [
      'start' => 1000000,
      'add' => 367
    ]
  ]
);

# example 2:

$udms->school->classes->createColumn('t_id',
  [
    '__udms_rel' => [
      'teacher' => 'id'
    ]
  ]
);
 */

Exists Column

Check exists column

// output Boolean
if($udms->school->student->existsColumn('studnet')) {
  // exists
} else {
  // not exists
}

Drop Column

// output void
$udms->school->student->dropColumn('studnet');

List Columns

$list = $udms->school->student->listColumns();
/* output array
 * example:
  Array
  (
      [0] => id
      [1] => first_name
      [2] => last_name
  )
 */

Data methods

Insert

$uid = $udms->school->student->insert(
  [
    'fname' => 'mehdi',
    'lname' => 'hosseinzade'
  ]
);
/* output String
 * string "c4ca4238a0b923820dcc509a6f75849b"
 */

Update

// output void
$udms->school->student->update($uid,
  [
    'fname' => 'arshen'
  ]
);

Delete

// output void
$udms->school->student->delete($uid);

Find

$list_1 = $udms->school->student->find(
  [
    'id' => [
      '<' => 9400000,
      '>' => 9200000
    ],
    'lname' => [
      'match' => '/(zade)+/'
    ]
  ],
  // options
  [
    'relation' => false,
    'sort' => [
      'name' => SORT_DESC
    ]
  ]
);
/* output array
 * example
 Array
 (
     [0] => Array
         (
             [fname] => mehdi
             [lname] => hosseinzade
             [id] => 93000000
             [__udms_id] => 529d1ff34a86af52e136858a8e7efc40
         )
 )
 */

Get

alias find method without filter

$list_1 = $udms->school->student->get(
  [
    'relation' => false,
    'sort' => [
      'lname' => SORT_ASC
    ],
    'limit' => 5
  ]
);
/* output array
 * example:
 Array
 (
     [0] => Array
         (
             [fname] => alireza
             [lname] => aghaeipour
             [id] => 93000172
             [__udms_id] => 92277596d3fe0baaf6814caaa2f9fb17
         )

     [1] => Array
         (
             [fname] => mehdi
             [lname] => hosseinzade
             [id] => 93000000
             [__udms_id] => 529d1ff34a86af52e136858a8e7efc40
         )

     [2] => Array
         (
             [fname] => abolfazl
             [lname] => nazerpanah
             [id] => 93000129
             [__udms_id] => 390aa37bf6aabfa8af16bb729f02d207
         )

     [3] => Array
         (
             [fname] => mehrzad
             [lname] => poureghbal
             [id] => 93000043
             [__udms_id] => 64df99136dc56fc4ba306a1fffe75231
         )

     [4] => Array
         (
             [fname] => mohammad
             [lname] => rezaei
             [id] => 93000086
             [__udms_id] => 1fa3d2ab103b82e368c534f87720f8e2
         )
 )
 */