Skip to content

Commit 0bb6ac0

Browse files
Merge pull request #1 from defenestrator/addPostGresGrammar
Add post gres grammar
2 parents ef1b302 + 9e8c6f7 commit 0bb6ac0

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

src/Connection/PostgresConnection.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Dyrynda\Database\Connection;
4+
5+
use Dyrynda\Database\Schema\Grammars\PostgresGrammar;
6+
use Illuminate\Database\PostgresConnection as BasePostgresConnection;
7+
8+
class PostgresConnection extends BasePostgresConnection
9+
{
10+
/**
11+
* Get the default schema grammar instance.
12+
*
13+
* @return \Illuminate\Database\Grammar
14+
*/
15+
protected function getDefaultSchemaGrammar()
16+
{
17+
return $this->withTablePrefix(new PostgresGrammar);
18+
}
19+
}

src/LaravelEfficientUuidServiceProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Database\Schema\Blueprint;
88
use Dyrynda\Database\Connection\MySqlConnection;
99
use Dyrynda\Database\Connection\SQLiteConnection;
10+
use Dyrynda\Database\Connection\PostgresConnection;
1011

1112
class LaravelEfficientUuidServiceProvider extends ServiceProvider
1213
{
@@ -31,6 +32,10 @@ public function register()
3132
return new MySqlConnection($connection, $database, $prefix, $config);
3233
});
3334

35+
Connection::resolverFor('postgres', function ($connection, $database, $prefix, $config) {
36+
return new PostgresConnection($connection, $database, $prefix, $config);
37+
});
38+
3439
Connection::resolverFor('sqlite', function ($connection, $database, $prefix, $config) {
3540
return new SQLiteConnection($connection, $database, $prefix, $config);
3641
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Dyrynda\Database\Schema\Grammars;
4+
5+
use Illuminate\Support\Fluent;
6+
use Illuminate\Database\Schema\Grammars\PostgresGrammar as BasePostgresGrammar;
7+
8+
class PostgresGrammar extends BasePostgresGrammar
9+
{
10+
/**
11+
* Create the column definition for a UUID type.
12+
*
13+
* @param \Illuminate\Support\Fluent $column
14+
*
15+
* @return string
16+
*/
17+
protected function typeEfficientUuid(Fluent $column)
18+
{
19+
return 'bytea';
20+
}
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Mockery as m;
6+
use Illuminate\Database\Connection;
7+
use Illuminate\Database\Schema\Blueprint;
8+
use Dyrynda\Database\Schema\Grammars\PostgresGrammar;
9+
10+
class DatabasePostgresSchemaGrammarTest extends TestCase
11+
{
12+
public function tearDown(): void
13+
{
14+
m::close();
15+
}
16+
17+
public function testAddingUuid()
18+
{
19+
$blueprint = new Blueprint('users', function ($table) {
20+
$table->uuid('foo');
21+
$table->efficientUuid('bar');
22+
});
23+
24+
$connection = m::mock(Connection::class);
25+
26+
$this->assertEquals(
27+
['alter table "users" add column "foo" uuid not null, add column "bar" bytea not null'],
28+
$blueprint->toSql($connection, new PostgresGrammar)
29+
);
30+
}
31+
}

0 commit comments

Comments
 (0)