DataStore

DataStore

DataStore

DataStore Helper is the DevLess internal API for working with data related to services. To use the DataStore class import it by inserting use App\Helpers\DataStore; at the very top of the php file, right after the <?php tag. Now you can use it to interact with the database.

Query Records

To get all records:

DataStore::service('serviceName', 'tableName')->queryData();

You may pass in query parameters. eg: The size parameter gets a given number of results:

DataStore::service('serviceName', 'tableName')->size(7)->queryData();

Available query parameters include :

Add Records

To add data to a given table by passing it in as an array of values.

DataStore::service('serviceName', 'tableName')->addData([['firstName'=>'edmond','lastName'=>'Mensah']])

You may also make double entries

DataStore::service('serviceName', 'tableName')->addData([
  ['firstName'=>'edmond','lastName'=>'Mensah'],
  ['firstName'=>'charles','lastName'=>'Feggerson']
])

Update Records

To update records you need the record id.

$data = ['firstName'=>'james'];
DataStore::service('serviceName', 'tableName')->where($id, $value)->update($data)

The $id parameter should be a string identifier.

Delete tables or records

To delete records from the table:

DataStore('serviceName', 'tableName')->where($id, $value)->delete();

To truncate a table:

DataStore('serviceName', 'tableName')->truncate()

To drop table:

DataStore('serviceName', 'tableName')->drop()

Instance Info

You may also get all info about the DevLess instance using the DataStore from within your application.

 $instance = DataStore::instanceInfo();

 $user = $instance['admin'];
 $app  = $instance['app'];

 var_dump($user, $app)

Dump

DevLess also provides a key/value store. This could be used to store user configuration settings or any data not part of the service but relates to the current instance only

 use App\Helpers\DataStore;

 //stores the current time `time()` under the key created_on
 DataStore::setDump('created_on', time());

 //gets the value under the created_on key
 $data = DataStore::getDump('created_on');
 var_dump($data);

 //updates the created_on key to the new current time()
 DataStore::updateDump('created_on', time());

 $data = DataStore::getDump('created_on');
 var_dump($data);

 //removes the entire key/value created_on
 DataStore::destroyDump('created_on');

Last updated