Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gabrieljmj/lousql
In-development. For MySQL.
https://github.com/gabrieljmj/lousql
Last synced: about 2 months ago
JSON representation
In-development. For MySQL.
- Host: GitHub
- URL: https://github.com/gabrieljmj/lousql
- Owner: gabrieljmj
- License: other
- Created: 2015-04-11T04:37:09.000Z (almost 10 years ago)
- Default Branch: develop
- Last Pushed: 2015-04-15T01:42:11.000Z (over 9 years ago)
- Last Synced: 2023-08-05T17:52:36.817Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 344 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Lousql
=======
In-development.## Usage example
Creating table
```php
use Gabrieljmj\Lousql\Builder\Builder;$pdo = new PDO('mysql:host=localhost;dbname=mydb', 'root', '');
$builder = new Builder();
$table =
$buiilder
->createTable('users')
->ifNotExists()
->id
->integer(11)
->notNull()
->autoIncrement()
->done()
->name
->varchar(50)
->notNull()
->done()
->created_at
->timestamp()
->asDefault('CURRENT_TIMESTAMP')
->done();$pdo->exec($table);
$hasError = (int) $pdo->errorInfo()[0] === 0 ? false : true;if ($hasError) {
throw new \Exception($pdo->errorInfo()[2]);
}
```
Dropping table
```php
$drop =
$builder
->dropTable('users')
->ifExists();$pdo->exec($drop);
```
More than one
```php
$buiilder
->createTable('users')
->ifNotExists()
->id
->integer(11)
->notNull()
->autoIncrement()
->done()
->name
->varchar(50)
->notNull()
->done()
->created_at
->timestamp()
->asDefault('CURRENT_TIMESTAMP')
->done()
->done()
->dropTable('posts')
->ifExists();$queries = array_map(function ($query) {
return (string) $query;
}, $builder->getQueries());$pdo->exec(implode("\n", $queries));
```