Plugin Application Data

Plugin Application Data in DbFace

!!! Tip Data Source Plugin only works on On-premises installation or Enterprise Plan.

If your data does not store in databases or even there is no data store. DbFace also works for your case with Data Source Plugin.

Write Data Source Plugin

Each data source plugin requires 2 entry files: plugin.setup.php and API.php
You can get the Sample Data Source plugin from: https://github.com/jsding/dbface-plugins

plugin.setup.php

<?php
return array(
  'id'              => 'sample_plugin',
  'author'          => 'DbFace',
  'author_url'      => 'https://www.dbface.com/',
  'name'            => 'Sample Data Source Plugin',
  'description'     => 'Sample data source plugin that help you build DbFace plugin that make your application work with DbFace. <a href="https://github.com/jsding/dbface-plugins">https://github.com/jsding/dbface-plugins</a>',
  'version'         => '0.9.0',
  'namespace'       => 'Plugin\Datasource\Sample'
);
NameRequiredDescription
idYesPlugin ID (unique)
authorNoPlugin author
author_urlNoPlugin author website
nameYesThe plugin name
descriptionYesThe plugin description
versionYesThe plugin version
namespaceYesThe plugin php calss namespace

API.php

!!! warning “Please Note” The API class namespace must be the namespace value in plugin.setup.php.

<?php
// Must match the namespace value in plugin.setup.php
namespace Plugin\Datasource\Sample;
/**
 * Apache Log Analytics Plugin for DbFace - by DbFace
 *
 * @package		plugins/datasources/apache-log
 * @author		DbFace 
 * @copyright	Copyright (c) 2017 DbFace, Inc.
 * @link		https://www.dbface.com
 * @since		Version 1.0
 */
class API {
  private $database;
  
  /**
	 * accept data source configuration
	 *
   * 
	 * @return array schemas array
	 */
  public function setup($config = array()) {
    $this->database = $config['database'];
  }
  
  /**
	 * get schemas of this data source
	 *
   * 
	 * @return array schemas array
	 */
  public function get_schemas() {
    // TODO: do your business and get the schemas finally
    return array(
      'sample_view1' => array(
        'fields' => array(
          'id' => array('type'=> 'integer', 'pk'=>1),
          'comment' => array('type'=> 'string')
        )
      )
    );
  }
  
  /**
	 * get datas of this specific schema
	 *
	 * @return array datas of the schema
	 */
  public function get_datas($schema) {
    // TODO: do your business and finally get the resultset for $schema
    $result = array(
      array('id'=>0, 'comment'=>'this is string1'),
      array('id'=>1, 'comment'=>'this is string2'),
      array('id'=>2, 'comment'=>'this is string3'),
      array('id'=>3, 'comment'=>'this is string4')
    );
    return $result;
  }
}

Method NameParameterDescription
setup$configPass the database configuration
get_schemasvoidReturn all the views
get_datas$shemaReturn all json data of the specific schema

Use Data Source Plugin

Once you finished your data source plugin, place all the files in plugins/datasources folder, DbFace will scan all the subfolders and list all the available plugins in the Plugin category. All data source plugins

Now, we can make a new connection that use the plugin. Use the data source plugin

FieldDescription
Database TypeThe data source plugin name
NameThe name that identify the connection
Database NameInternal name that will pass to plugin

Click “Submit” button, DbFace will create a new connection that use your data source plugin. Use the data source plugin

Click the “Sync” button to run the plugin.

!!! warning “Please Note” Do not forget to click “Sync” button to let DbFace know the data source changes.

Now, you can use the data source to create report applications just like MySQL or any other database connections in DbFace.


Last modified December 28, 2020: change the ticket (c5eeadc)