ishifoev / laravel-extended-grammars
Extends Laravel's database grammars with advanced SQL helpers like insertOrUpdateUsing().
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/ishifoev/laravel-extended-grammars
Requires
- php: ^8.1|^8.2|^8.3
- illuminate/database: ^10.0|^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.0
- mockery/mockery: ^1.6
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^10.0
- vimeo/psalm: ^6.0
README
๐งฉ Extends Laravel's database grammars with advanced SQL helpers like
insertOrUpdateUsing()
for MySQL, PostgreSQL, and SQLite.
๐ Installation
composer require ishifoev/laravel-extended-grammars
๐ง Example: Query Builder
DB::table('users')->insertOrUpdateUsing( ['id', 'name', 'email'], // columns to insert DB::table('imports')->select('id', 'name', 'email'), // source data ['name', 'email'] // columns to update if duplicate );
Generated SQL (MySQL):
INSERT INTO users (id, name, email) SELECT id, name, email FROM imports ON DUPLICATE KEY UPDATE name = VALUES(name), email = VALUES(email);
PostgreSQL:
INSERT INTO users (id, name, email) SELECT id, name, email FROM imports ON CONFLICT (id) DO UPDATE SET name = EXCLUDED.name, email = EXCLUDED.email;
SQLite
INSERT INTO users (id, name, email) SELECT id, name, email FROM imports ON CONFLICT(id) DO UPDATE SET name = excluded.name, email = excluded.email;
๐งฉ Example: Eloquent Model
use App\Models\User; User::insertOrUpdateUsing( ['id', 'name', 'email'], DB::table('imports')->select('id', 'name', 'email'), ['name', 'email'] );
Supported
Database | Status | Laravel Versions |
---|---|---|
MySQL | โ Full support | 10, 11, 12 |
PostgreSQL | โ Full support | 10, 11, 12 |
SQLite | โ Full support | 10, 11, 12 |
๐งช Testing
Install dependencies:
composer install
Run all checks:
composer test
composer lint
composer analyze
Or run via Docker:
docker-compose run --rm test
๐งฐ Composer Scripts
Command | Description |
---|---|
composer test |
Run PHPUnit tests |
composer lint |
Check code style via Laravel Pint |
composer analyze |
Run static analysis via Psalm |
๐งฑ Project Structure
src/ โโโ Concerns/SupportsInsertOrUpdateUsing.php โโโ Contracts/InsertOrUpdateGrammarInterface.php โโโ Factories/GrammarFactory.php โโโ Grammars/ โ โโโ MySqlGrammar.php โ โโโ PostgresGrammar.php โ โโโ SQLiteGrammar.php โโโ Providers/ExtendedGrammarsServiceProvider.php tests/ โโโ MySqlGrammarTest.php โโโ PostgresGrammarTest.php โโโ SQLiteGrammarTest.php
๐งโ๐ป Author
Ismoil Shifoev
Senior Laravel Developer
๐ง ismoil.shifoev94@gmail.com
๐ชช License
Licensed under the MIT License
Copyright (c) 2025 Ismoil Shifoev
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
๐ท๏ธ Version History
v1.0.0 (Initial Release)
Added MySQL/PostgreSQL/SQLite support
Added insertOrUpdateUsing() for models and Query Builder
Added unit tests and static analysis
Added Laravel Pint and Psalm integration
Laravel 10, 11, 12 compatible