https://github.com/inkflow59/sqlgenix
A PHP library that let you build easily your SQL queries to build your dynamics websites easier, enabling performance and efficiency for your interactions with your databases
https://github.com/inkflow59/sqlgenix
composer php-library php8 sql
Last synced: 4 months ago
JSON representation
A PHP library that let you build easily your SQL queries to build your dynamics websites easier, enabling performance and efficiency for your interactions with your databases
- Host: GitHub
- URL: https://github.com/inkflow59/sqlgenix
- Owner: Inkflow59
- License: mit
- Created: 2024-12-13T15:01:58.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-19T19:37:58.000Z (over 1 year ago)
- Last Synced: 2025-03-28T23:11:17.449Z (over 1 year ago)
- Topics: composer, php-library, php8, sql
- Language: PHP
- Homepage: https://sqlgenix.vercel.app
- Size: 1.32 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SQLGenix ๐
## Supercharge Your Database Interactions
SQLGenix is your go-to SQL query generator that takes the pain out of database operations. Say goodbye to manual SQL writing and hello to elegant, chainable methods that make database interactions a breeze. Perfect for both rapid application development and sophisticated database management tasks.
## Table of Contents
- [Key Features](#key-features)
- [Quick Start](#quick-start)
- [Installation](#installation)
- [Usage Examples](#usage-examples)
- [Create New Records](#create-new-records)
- [Fetch Data](#fetch-data)
- [Update Records](#update-records)
- [Remove Data](#remove-data)
- [Requirements](#requirements)
- [Testing](#testing)
- [Contributing](#contributing)
- [License](#license)
- [Get in Touch](#get-in-touch)
## โจ Key Features
- ๐ฏ **Smart Query Generation** - Build complex SQL queries with simple, intuitive methods
- ๐ **Full CRUD Support** - Handle SELECT, INSERT, UPDATE, and DELETE operations effortlessly
- ๐ **Multi-Database Support** - Works seamlessly with MySQL, PostgreSQL, SQLite, and more
- ๐ก๏ธ **Robust Error Handling** - Graceful exception management keeps your application stable
- โก **Lightning Fast** - Optimized for performance without sacrificing flexibility
- ๐ **Pagination Support** - Built-in LIMIT, OFFSET, and page-based pagination
- ๐ **Query Caching** - Intelligent caching system for improved performance
- ๐ **UNION Operations** - Combine multiple queries with UNION and UNION ALL
- ๐ฆ **Bulk Operations** - Efficient batch INSERT, UPDATE, and DELETE operations
- ๐ **Advanced Joins** - Support for INNER, LEFT, RIGHT joins with complex conditions
- ๐๏ธ **Database Adapters** - Adapter pattern for database-specific optimizations
## ๐ Quick Start
### Installation
Get started with Composer:
```bash
composer require sqlgenix/sqlgenix
```
Or clone the repository manually:
```bash
git clone https://github.com/Inkflow59/SQLGenix.git
cd SQLGenix
composer install
```
### ๐ Usage Examples
#### Create New Records
```php
require 'src/SQLInsert.php';
$db = new Database();
$insert = new SQLInsert($db);
$insert->into('users')
->set(['name', 'email'], ['John Doe', 'john@example.com'])
->execute();
```
#### Fetch Data
```php
require 'src/SQLSelect.php';
$db = new Database();
$select = new SQLSelect($db);
$result = $select->select(['name', 'email'])
->from('users')
->where('email = "john@example.com"')
->execute();
```
#### Update Records
```php
require 'src/SQLUpdate.php';
$db = new Database();
$update = new SQLUpdate($db);
$update->table('users')
->set('name', 'Jane Doe')
->where('email = "john@example.com"')
->execute();
```
#### Remove Data
```php
require 'src/SQLDelete.php';
$db = new Database();
$delete = new SQLDelete($db);
$delete->from('users')
->where('email = "john@example.com"')
->execute();
```
#### Pagination
```php
require 'src/SQLSelect.php';
$db = new Database();
$select = new SQLSelect($db);
$result = $select->select(['*'])
->from('users')
->where('status = "active"')
->orderBy(['created_at'], 'DESC')
->paginate(2, 20) // Page 2, 20 per page
->execute();
```
#### Query Caching
```php
require 'src/QueryCache.php';
require 'src/SQLSelect.php';
$cache = new QueryCache(100, 3600); // 100 items, 1 hour TTL
$db = new Database();
$select = new SQLSelect($db, $cache);
$result = $select->select(['*'])
->from('users')
->where('active = 1')
->execute(); // Cached automatically
```
#### UNION Operations
```php
require 'src/SQLSelect.php';
$db = new Database();
$activeUsers = new SQLSelect($db);
$activeUsers->select(['name', 'email'])->from('active_users');
$inactiveUsers = new SQLSelect($db);
$inactiveUsers->select(['name', 'email'])->from('inactive_users');
$allUsers = new SQLSelect($db);
$result = $allUsers->select(['name', 'email'])
->from('current_users')
->union($activeUsers)
->unionAll($inactiveUsers)
->execute();
```
#### Bulk Operations
```php
require 'src/BulkOperations.php';
$db = new Database();
$bulk = new BulkOperations($db);
// Bulk insert 1000 records
$data = []; // Your data array
$result = $bulk->bulkInsert('users', ['name', 'email'], $data);
echo "Inserted: " . $result['inserted_rows'] . " rows";
```
#### Multi-Database Support
```php
require 'src/DatabaseAdapterFactory.php';
require 'src/UniversalSQLSelect.php';
// Create MySQL adapter
$mysqlAdapter = DatabaseAdapterFactory::createMySQL([
'host' => 'localhost',
'database' => 'myapp',
'username' => 'user',
'password' => 'pass'
]);
// Create PostgreSQL adapter
$postgresAdapter = DatabaseAdapterFactory::createPostgreSQL([
'host' => 'localhost',
'database' => 'myapp',
'username' => 'user',
'password' => 'pass'
]);
// Same query works on both databases
$mysqlQuery = new UniversalSQLSelect($mysqlAdapter);
$postgresQuery = new UniversalSQLSelect($postgresAdapter);
$result = $mysqlQuery->select(['*'])->from('users')->execute();
```
## โ๏ธ Requirements
- PHP 7.0+
- Any major SQL database (MySQL, PostgreSQL, SQLite)
- Composer for dependency management
## ๐งช Testing
Run the test suite with:
```bash
composer test
```
## ๐ค Contributing
We love contributions! Here's how you can help:
1. Fork the repo
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## ๐ License
SQLGenix is MIT licensed. See the [LICENSE](LICENSE) file for details.
## ๐ฌ Get in Touch
Questions or suggestions? [Drop me a line](mailto:tomcucherosset@hotmail.fr)
---
Made with โค๏ธ by SQLGenix Team