|
Description | | Author |
This package can generate database creation SQL queries from JSON.
It takes a file in JSYN format (JSON) and parses it to extract a list of commands for database creation.
The main class can generate SQL queries for creating or modifying database structures like databases, tables, views, indexes, trigger, functions, stored procedures, etc..
The generated SQL is compatible with several databases like MySQL, SQLite, Microsoft SQL server, etc.. Innovation Award
May 2016
Number 7
Prize: SourceGuarding PHP encoder tool |
Every SQL database driven application needs to update the database schema once in a while to support new features.
This class can perform that process of generating SQL for database updates with elegance, as it allows developers to define database schema additions in a JSON based file format, so it can work with different types of databases.
Since the format is based in JSON it can be used eventually by similar packages written in other languages.
Not only it supports the creation and modification of databases, tables and indexes, but it also supports triggers, views, stored procedures and functions.
Manuel Lemos |
| |
|
|
Innovation award
Nominee: 7x
Winner: 1x |
|
Scripd
A robust SQL Generator. Parses database structures defined in json based on a custom jsyn file format and generates corresponding sql queries.
Class Features
- A json like file format to define database structure
- Support for multiple sql vendors / dialects
- Compatible with PHP 5.0+
- Support for UTF-8 content and 8bit, base64, binary, and quoted-printable encodings
- Much More!
Why you might need it
This project was birthed as a result of the need to give users an opportunity to create
their own custom database structure in a PHP Application.
I wanted users to be able to modify database structures while there is support for multiple db vendors such as mysql, sqlite and sql server.
This library offers the ability to create database structures in a json-like format and generate sql compatible with several database vendors.
It is also very easy to use and integrate into your php based projects
License
This software is distributed under the MIT license. Please read LICENSE for information on the
software availability and distribution.
Installation & loading
Scripd is available via Composer/Packagist, so just add this line to your composer.json
file:
"samshal/scripd": "~1.0"
or
composer require samshal/scripd
A Simple Example
JSON DB Structure (structure.json)
{
":database":{
":crud-action":"create",
"name":"dbname",
":table":[
{
":crud-action":"create",
"name":"students",
"columns":[
{
"name":"id",
"data-type":"int",
"primary-key":true
},
{
"name":"first_name",
"data-type":"varchar(20)",
"default":"'samuel'"
},
{
"name":"last_name",
"data-type":"varchar(20)"
},
{
"name":"class",
"data-type":"varchar(10)"
}
]
}
]
}
}
PHP (index.php)
<?php
require 'vendor/autoload.php';
$jsonDBStructure = new Samshal\Scripd\JsonDbStructure('./structure.json', 'mysql');
$jsonDBStructure->parseStructure();
$sql = $jsonDBStructure->getGeneratedSql();
echo $sql;