\JSONDB\Database
Class Database
Summary
Properties |
$server |
$database |
$table |
$username |
$password |
$queryIsPrepared |
$queryIsExecuted |
$queryString |
$parsedQuery |
$queryResults |
$cache |
$queryParser |
$config |
$benchmark |
Constants |
No constants |
Properties
$server
$server : string
Description | The path to databases directories |
Type | string |
$database
$database : string
Description | The name of the currently used database |
Type | string |
$table
$table : string
Description | The name of the currently used table |
Type | string |
$username
$username : string
Description | The currently logged in username |
Type | string |
$password
$password : string
Description | The currently logged in user password |
Type | string |
$queryIsPrepared
$queryIsPrepared : boolean
Description | The query is prepared? |
Type | boolean |
$queryIsExecuted
$queryIsExecuted : boolean
Description | The query is executed? |
Type | boolean |
$queryString
$queryString : string
Description | The query |
Type | string |
$parsedQuery
$parsedQuery : array
Description | The parsed query |
Type | array |
$queryResults
$queryResults : array
Description | Stores results of the select() query |
Type | array |
$cache
$cache : \JSONDB\Cache
Description | Cache manager |
Type | \JSONDB\Cache |
$queryParser
$queryParser : \JSONDB\QueryParser
Description | Query parser |
Type | \JSONDB\QueryParser |
$config
$config : \JSONDB\Configuration
Description | Configuration manager |
Type | \JSONDB\Configuration |
$benchmark
$benchmark : \JSONDB\Benchmark
Description | Benchmark |
Type | \JSONDB\Benchmark |
Methods
__construct()
__construct(string $server, string $username, string $password, string $database = NULL )
Database __constructor.
Parameters
string | $server |
The name of the server to connect to |
string | $username |
The username used to connect to the server |
string | $password |
The password used for the given username |
string | $database |
The name of the database to use with the current connection |
Throws
setDatabase()
setDatabase(string $database) : \JSONDB\Database
Changes the currently used database.
Parameters
string | $database |
The name of the database |
Throws
Returns
setTable()
get(string $table) : \JSONDB\Database
Change the currently used table.
Parameters
string | $table |
The name of the table |
Throws
Returns
queryString()
queryString() : string
Returns the last query.
Returns
string
getServer()
getServer() : string
Returns the name of the currently used server.
Returns
string
getDatabase()
getDatabase() : string
Returns the name of the currently used database.
Returns
string
getTable()
getTable() : string
Returns the name of the currently used table.
Returns
string
benchmark()
benchmark() : \JSONDB\Benchmark
Returns the current benchmark instance.
Returns
createDatabase()
createDatabase(string $name) : \JSONDB\Database
Creates a new database in the current server.
Parameters
string | $name |
The name of the new database |
Throws
Returns
disconnect()
disconnect()
Disconnects from the database.
createTable()
createTable(string $name, array $prototype) : \JSONDB\Database
Creates a new table in the current database.
Parameters
string | $name |
The name of the new table |
array | $prototype |
The prototype of the table. An array of field names => fields properties pairs. Learn more here |
Throws
Returns
query()
query(string $query) : mixed
Sends a JQL query to the current database.
Parameters
string | $query |
The JQL query |
Throws
Returns
mixed
prepare()
prepare(string $query) : \JSONDB\PreparedQueryStatement
Sends a prepared JQL query.
Parameters
string | $query |
The prepared JQL query |
Throws
Returns
getTableData()
getTableData(string $path = NULL) : array
Returns table's data.
Parameters
string|null | $path |
The path of the table |
Returns
array
queryIsPrepared()
queryIsPrepared() : boolean
Checks if the current query is a prepared query.
Returns
boolean
queryIsExecuted()
queryIsExecuted() : boolean
Checks if the current query is already executed.
Returns
boolean
_getDatabasePath()
_getDatabasePath(string $database = NULL) : string
Gets the path to a database.
Parameters
string | $database |
The name of the database |
Returns
string
_getTablePath()
_getTablePath(string|null $table = NULL) : array
Returns the path to a table.
Parameters
string | $table |
The name of the table |
Returns
string
_getTableContent()
_getTableContent(string|null $table = NULL) : array
Returns a table's content.
Parameters
string|null | $table |
The name of the table |
Returns
array
_parseValue()
_parseValue(mixed $value, array $properties) : string|float|integer|array|boolean|null
Parses a JQL query value.
Parameters
mixed | $value |
The value to parse |
array | $properties |
The properties to use when parsing value |
Throws
Returns
_select()
_select(array $data) : \JSONDB\QueryResult
The JQL select() query.
Parameters
array | $data |
The table's data to use |
Throws
Returns
_insert()
_insert(array $data) : boolean
The JQL insert() query.
Parameters
array | $data |
The table's data to use |
Throws
Returns
boolean
_replace()
_replace(array $data) : boolean
The JQL replace() query.
Parameters
array | $data |
The table's data to use |
Throws
Returns
boolean
_delete()
_delete(array $data) : boolean
The JQL delete() query.
Parameters
array | $data |
The table's data to use |
Throws
Returns
boolean
_update()
_update(array $data) : boolean
The JQL update() query.
Parameters
array | $data |
The table's data to use |
Throws
Returns
boolean
_truncate()
_truncate(array $data) : boolean
The JQL truncate() query.
Parameters
array | $data |
The table's data to use |
Throws
Returns
boolean
_count()
_count(array $data) : \JSONDB\QueryResult
The JQL count() query.
Parameters
array | $data |
The table's data to use |
Throws
Returns
_filter()
_filter(array $data, array $filters) : array
Iterates over each values of $data
and test them using conditions if $filters
.
If a value in $data
don't pass
any conditions in $filters
it will be removed.
Parameters
array | $data |
The table's data to iterate over |
array | $filters |
Conditions used to remove data which don't pass them |
Throws
Returns
array
_execute()
_execute() : mixed
Executes a query and returns the result.
Throws
Returns
mixed
_getLastValidRowID()
_getLastValidRowID(array $data, boolean $min = TRUE) : integer
Returns the last valid row ID of a table.
Parameters
array | $data |
The table's data to use |
boolean | $min |
Used to check if we have to return the minimal or the maximal valid row ID |
Returns
integer