Menu

Working with Data Stores Log in to Edit

LongStone

Working with Data Stores

JCORE provides a data service layer that is able to interact with multiple data stores and multiple types of data stores from RDBMS to NoSQL through a single data API with a standard "CRUD" interface as well as an option for "raw" interaction. The data API instantiates data base connector classes as defined through a common interface, see: class [sequence] diagram example.

In the MySQL example the connector class is instantiated as needed based on the configuration settings in CONFIG/SERVICE/DATA.ini. See [DATA CONFIGURATION] for more details.

Data operations are performed through 1 of 5 methods of the global DATA_API object: create, retrieve, update, delete, raw. Each of the first 4 operations will return extended data from the query (depending on the DBMS) i.e. the insert id in the case of MySQL with a "create" operation or any errors if they occur.

The data API does not abstract queries or the query language in any capacity. I the case of RDBMS data stores use POS, native "Plain Old SQL" of the data store.

Getting Data

$result = $GLOBALS["DATA_API"]->retrieve(
    $DSN='Data Store Name',                 see: [DATA CONFIGURATION]
    $query,                                 a query string
    $args=array(                            *extended arguments * 
        'returnArray' => true
    )
);

Extended Arguments

Was provisioned to keep the function signature small and allow for secondary operations like write through cache. Setting the value returnArray to true will automatically transform the result set into an array.

Data Access Methods

Create
returnArray === TRUE

returns the following values in the result array from a "create" operation

$resultArray["INSERT_ID"]       = mysql_insert_id($connection);
$resultArray["AFFECTED_ROWS"]   = mysql_affected_rows($connection);
$resultArray["INFO"]            = mysql_info($connection);
Retrieve
returnArray === TRUE

if TRUE the result is returned as a PHP array

Update
returnArray === TRUE

returns the following values in the result array from a "update" operation

$resultArray["AFFECTED_ROWS"]   = mysql_affected_rows($connection);
$resultArray["INFO"]            = mysql_info($connection);
Delete
returnArray === TRUE

returns the following values in the result array from a "delete" operation

$resultArray["AFFECTED_ROWS"]   = mysql_affected_rows($connection);
$resultArray["INFO"]            = mysql_info($connection)
Raw
extended args are ignored

returns the raw result of the query


Related

Wiki: DATA CONFIGURATION
Wiki: Quick Start Guide

Discussion

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.