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

1.0.1 2025-10-17 06:50 UTC

This package is auto-updated.

Last update: 2025-10-17 06:54:25 UTC


README

Packagist Version Packagist Downloads License

๐Ÿงฉ 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