class SQLToJSONConverter

This class allows the conversion of a SQL database to a json-schema.org compliant JSON database

Properties

private array $parameters
private array $types
private string $databasesDir
private SimpleXMLElement $datasources
private int $maxId

Methods

void
__construct(array $fparameters, string $databasesDir)

Constructor of class SQLToJSONConverter

array
convert(SimpleXMLElement $datasource)

Transfers the schema and data from a data source into an array for conversion to JSON

getDatabase(SimpleXMLElement $datasource, bool $withDbName = true)

Returns a Database object for the database of a data source

array|string|bool|null
tableInfos(Database $database, string $table)

Returns the information on a table

array
getData(Database $database, string $table, array $schema, array $required)

Returns all the rows of a table of a SQL database

string
guessType(string $value, string $priorType = '')

Guess the type of the value of a choice item

string|bool|int|float
castValue(string $value, string $type)

Casts a value according to its type.

Details

at line 155
void __construct(array $fparameters, string $databasesDir)

Constructor of class SQLToJSONConverter

Parameters

array $fparameters The database parameters
string $databasesDir The G6K databases directory

Return Value

void

at line 169
array convert(SimpleXMLElement $datasource)

Transfers the schema and data from a data source into an array for conversion to JSON

Parameters

SimpleXMLElement $datasource The datasource definition extracted from DataSources.xml

Return Value

array The result array

at line 299
protected Database getDatabase(SimpleXMLElement $datasource, bool $withDbName = true)

Returns a Database object for the database of a data source

Parameters

SimpleXMLElement $datasource The datasource definition extracted from DataSources.xml
bool $withDbName (default: true) if false, the name of the database will not be inserted in the dsn string.

Return Value

Database The Database object

at line 314
protected array|string|bool|null tableInfos(Database $database, string $table)

Returns the information on a table

Parameters

Database $database The unified access interface to the database
string $table The name of the table

Return Value

array|string|bool|null The information on the table

at line 351
protected array getData(Database $database, string $table, array $schema, array $required)

Returns all the rows of a table of a SQL database

Parameters

Database $database The unified access interface to the database
string $table The name of the table
array $schema &$schema The list of columns in the table and their properties
array $required &$required The list of required columns

Return Value

array The rows of the table

at line 407
protected string guessType(string $value, string $priorType = '')

Guess the type of the value of a choice item

Parameters

string $value The value
string $priorType (default: '') The harmonized type of the prior items of the choice

Return Value

string The type of the value

at line 444
protected string|bool|int|float castValue(string $value, string $type)

Casts a value according to its type.

Parameters

string $value The value to be casted
string $type The type of the value.

Return Value

string|bool|int|float The casted value