Package Data | |
---|---|
Maintainer Username: | Ronster |
Maintainer Contact: | ronsterdj@gmail.com (Ronnie Visser) |
Package Create Date: | 2017-07-12 |
Package Last Update: | 2017-07-12 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-01 15:02:10 |
Package Statistics | |
---|---|
Total Downloads: | 2,324 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This is a clone from yurykabanov/laravel-postgres-ext and has Laravel 5.4 support.
This project was inspired by features PostgreSQL supports and Laravel does not. Unfortunately, such features are not accepted in official repository (like this one) and developers are told to use raw queries that is completely wrong solution in my opinion.
composer require ronnievisser/laravel-postgres-ext
to install this package.Illuminate\Database\DatabaseServiceProvider::class
to RonnieVisser\Database\DatabaseServiceProvider::class
.RonnieVisser\Database\Eloquent\Model
instead of Illuminate\Database\Eloquent\Model
.UPSERT (INSERT ON CONFLICT UPDATE) is supported by PostgreSQL since version 9.5 and can be performed by calling
Model::upsert($arrayOfAttibutes, $uniqueField)
Like original insert method, upsert can manage multiple records.
PostgreSQL supports several index types: btree, hash, gist, spgist, gin, and brin (as for version 9.5) and other index-related features (for example, index can be created concurrently, i.e. without table locking). This package supports creation of all currently supported indexing methods.
Indexes can be created using the same syntax as original one:
$table->index('column_name');
but it now accepts additional parameters:
$table->index('column_name', 'index_name', $methodName, $arrayOfOptions);
where $methodName
is one of methods listed before and $arrayOfOptions
is array with different options (like concurrency and uniqueness).
Examples:
// CREATE INDEX CONCURRENTLY ... USING GIST ...
$table->index('column_name', 'index_name', 'gist', [ 'concurrently' => true ]);
// CREATE UNIQUE INDEX ... USING BTREE ...
$table->index('column_name', 'index_name', 'gin', [ 'unique' => true ]);
Note, that there's two ways of making column unique: using constraint and index (more information). Laravel uses constraint to make column unique, this behavior stays the same for $table->unique()
but you can also create unique index using $table->index($col, $index, $method, [ 'unique' => true ])
.
PostgreSQL supports views (since version 9.1) and materialized views (since version 9.3). These can be created using DB::statement()
but it's more convenient to use some aliases to manage them.
Views can be created using following statements:
// create non-materialized view using specified select statement
Schema::createView('some_view', 'select 1 as some_value');
// create materialized view using specified select statement
Schema::createView('some_view', 'select 1 as some_value', true);
and dropped:
// create non-materialized view using specified select statement
Schema::dropView('some_view');
So far it doesn't support some query builders since view's select statement could be (and usually is) very complicated.
Laravel claims that it does support jsonb type and jsonb operators like ?
, ?|
and ?&
. But it is impossible to use them in queries since they are treated as parameters in prepared statements. This package automatically wraps these operators in appropriate functions (Note that ?|
also used for other types -- this behavior is not supported at this moment).
Available group by expressions described in official documentation.
// GROUP BY GROUPING SETS ((brand), (size), ())
DB::table('some_table')->groupByGroupingSets('brand', 'size', null);
// GROUP BY ROLLUP (e1, e2, e3)
DB::table('some_table')->groupByRollup('e1', 'e2', 'e3');
// GROUP BY CUBE (e1, e2, e3)
DB::table('some_table')->groupByCube('e1', 'e2', 'e3');