JsonSQL
class JsonSQL
This class allows you to store and retrieve data from files in JSON format using SQL standard.
- The data are described by a json schema in compliance with the spécifications of http://json-schema.org
This schema can be generated on this site: http://jsonschema.net
The API is very similar to PDO
The JSON schema is saved in a file whose name is in the form
.schema.json - The data is saved in a file whose name is in the form
.json
Properties
static private array | $_instance | List of class instances. | |
private Engine | $engine | The JsonSQL engine attached to this instance |
Methods
Represents a connection between PHP and a json database in memory.
Returns a pointer to the json schema object
Returns a ArrayIterator on the rows of the table $name
Executes an SQL statement in a single function call, returning the result set (if any) returned by the statement as a Statement object.
Executes an SQL statement in a single function call, returning the number of rows affected by the statement.
Quotes a string for use in a query.
Returns the ID of the last inserted row.
Initiates a transaction.
Commits a transaction.
Rolls back the current transaction, as initiated by beginTransaction().
Checks if inside a transaction.
Appends a row to a table
Deletes a table row
Replaces a table row by another
Creates a table in the database
Deletes all rows from a table
Drops a table
Renames a table
Adds a column in a table of the database
Renames a column
Drops a column
Changes the type of a column
Changes whether a column is marked to allow null values or to reject null values
Set or remove the default value for a column.
Set or remove primary key for a column.
Set or remove autoincrement for a column.
Set or remove the title of a table.
Set or remove the description of a table.
Set or remove the title of a column.
Set or remove the description of a column.
Saves the current database and/or its schema on the file system
Details
at line 72
private
__construct()
Represents a connection between PHP and a json database in memory.
at line 86
static JsonSQL
open(string $name, boolean $create = false)
Open a json database
at line 104
static JsonSQL
create(string $name)
Creates a json database then open it
at line 118
Engine
getEngine()
Returns the JsonSQL engine attached to this instance
at line 128
object
schema()
Returns a pointer to the json schema object
at line 139
ArrayIterator
table(string $name)
Returns a ArrayIterator on the rows of the table $name
at line 150
Statement
prepare(string $sql)
Prepares a statement for execution and returns a statement object
at line 168
Statement
query(string $sql)
Executes an SQL statement in a single function call, returning the result set (if any) returned by the statement as a Statement object.
at line 184
int
exec(string $sql)
Executes an SQL statement in a single function call, returning the number of rows affected by the statement.
at line 197
string
quote(string $string, int $type = \PDO::PARAM_STR)
Quotes a string for use in a query.
at line 207
string
lastInsertId()
Returns the ID of the last inserted row.
at line 217
bool
beginTransaction()
Initiates a transaction.
at line 227
bool
commit()
Commits a transaction.
at line 237
bool
rollBack()
Rolls back the current transaction, as initiated by beginTransaction().
at line 247
bool
inTransaction()
Checks if inside a transaction.
at line 260
void
insert(string $table, array $row)
Appends a row to a table
at line 272
void
delete(string $table, int $index)
Deletes a table row
at line 286
void
replace(string $table, int $index, object $row)
Replaces a table row by another
at line 302
void
createTable(string $table, object $columns, array $required, array $foreignkeys, bool $ifnotexists = false)
Creates a table in the database
at line 314
void
truncate(string $table)
Deletes all rows from a table
at line 327
void
dropTable(string $table, bool $ifexists = false)
Drops a table
at line 340
void
renameTable(string $table, string $newname)
Renames a table
at line 355
void
addColumn(string $table, string $column, object $columnDef, array $required = array())
Adds a column in a table of the database
at line 369
void
renameColumn(string $table, string $column, string $newname)
Renames a column
at line 383
void
dropColumn(string $table, string $column, bool $ifexists = false)
Drops a column
at line 399
void
setColumnType(string $table, string $column, string $type, string $format = '', string $datatype = '')
Changes the type of a column
at line 413
void
setNotNull(string $table, string $column, bool $allownull = false)
Changes whether a column is marked to allow null values or to reject null values
at line 427
void
setDefault(string $table, string $column, string|bool $default = false)
Set or remove the default value for a column.
at line 441
void
setPrimaryKey(string $table, string $column, bool $remove = false)
Set or remove primary key for a column.
at line 455
void
setAutoincrement(string $table, string $column, bool $remove = false)
Set or remove autoincrement for a column.
at line 468
void
setTableTitle(string $table, string|bool $title = false)
Set or remove the title of a table.
at line 481
void
setTableDescription(string $table, string|bool $description = false)
Set or remove the description of a table.
at line 495
void
setColumnTitle(string $table, string $column, string|bool $title = false)
Set or remove the title of a column.
at line 509
void
setColumnDescription(string $table, string $column, string|bool $description = false)
Set or remove the description of a column.
at line 520
void
save()
Saves the current database and/or its schema on the file system