ishifoev/laravel-extended-grammars
最新稳定版本:1.0.1
Composer 安装命令:
composer require ishifoev/laravel-extended-grammars
包简介
Extends Laravel's database grammars with advanced SQL helpers like insertOrUpdateUsing().
README 文档
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
🪪 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
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-17