https://github.com/effectra/sql-query
Effectra/SqlQuery is a powerful database manipulation package for PHP.
https://github.com/effectra/sql-query
manupulation mysql php sql sql-query sqlite syntax
Last synced: 28 days ago
JSON representation
Effectra/SqlQuery is a powerful database manipulation package for PHP.
- Host: GitHub
- URL: https://github.com/effectra/sql-query
- Owner: effectra
- Created: 2023-06-18T23:20:41.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-11T20:54:46.000Z (over 2 years ago)
- Last Synced: 2024-12-29T16:34:06.399Z (over 1 year ago)
- Topics: manupulation, mysql, php, sql, sql-query, sqlite, syntax
- Language: PHP
- Homepage:
- Size: 151 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Effectra SqlQuery
Effectra/SqlQuery is a powerful database manipulation package for PHP.
## Installation
You can install this package via Composer. Run the following command:
```bash
composer require effectra/sql-query
```
## Usage
### Query Example
```php
use Effectra\SqlQuery\Query;
// Select statement
$query = Query::select('users')->columns(['id','email','password'])->where(['id' => 9841]);
// Print the SQL query
echo $query;
//output
// SELECT id, email, password FROM users WHERE id = 9841
```
### Table Example
```php
use Effectra\SqlQuery\Table;
use Effectra\SqlQuery\Charset;
use Effectra\SqlQuery\Driver;
use Effectra\SqlQuery\Engine;
Query::driver(Driver::MySQL);
Query::createTable('users', function (Table $table) {
$table->autoIncrement();
$table->username()->unique();
$table->email()->unique();
$table->timestamps();
})->engine(Engine::MYSQL_InnoDB)->charset(Charset::MySQL_utf8mb4);
```
output:
```sql
CREATE TABLE users (
id BIGINT NOT NULL AUTO_INCREMENT ,
username VARCHAR (50) NOT NULL UNIQUE CHECK (username REGEXP '^[a-zA-Z0-9_]+$'),
email VARCHAR (255) NOT NULL UNIQUE CHECK (email REGEXP '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'),
created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ,
updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4_0900_ai_ci
```
## License
This package is open-source and available under the [MIT License](https://opensource.org/licenses/MIT).