3
3
namespace YlsIdeas \CockroachDb ;
4
4
5
5
use Illuminate \Database \ConnectionInterface ;
6
- use Illuminate \Database \Grammar ;
6
+ use Illuminate \Database \Grammar as BaseGrammar ;
7
7
use Illuminate \Database \PDO \PostgresDriver ;
8
8
use Illuminate \Database \PostgresConnection ;
9
- use Illuminate \Database \Schema \PostgresSchemaState ;
10
9
use Illuminate \Filesystem \Filesystem ;
11
- use YlsIdeas \CockroachDb \Builder \CockroachDbBuilder ;
12
- use YlsIdeas \CockroachDb \Processor \CockroachDbProcessor ;
10
+ use YlsIdeas \CockroachDb \Builder \CockroachDbBuilder as DbBuilder ;
11
+ use YlsIdeas \CockroachDb \Processor \CockroachDbProcessor as DbProcessor ;
13
12
use YlsIdeas \CockroachDb \Query \CockroachGrammar as QueryGrammar ;
14
13
use YlsIdeas \CockroachDb \Schema \CockroachGrammar as SchemaGrammar ;
14
+ use YlsIdeas \CockroachDb \Schema \CockroachSchemaState as SchemaState ;
15
15
16
16
class CockroachDbConnection extends PostgresConnection implements ConnectionInterface
17
17
{
18
18
/**
19
19
* Get the default query grammar instance.
20
20
*
21
- * @return Grammar
21
+ * @return BaseGrammar
22
22
*/
23
- protected function getDefaultQueryGrammar ()
23
+ protected function getDefaultQueryGrammar (): BaseGrammar
24
24
{
25
- return $ this ->withTablePrefix (new QueryGrammar ());
25
+ return $ this ->withTablePrefix ($ this -> setConnection ( new QueryGrammar () ));
26
26
}
27
27
28
28
/**
29
29
* Get a schema builder instance for the connection.
30
30
*
31
- * @return \Illuminate\Database\Schema\PostgresBuilder
31
+ * @return DbBuilder
32
32
*/
33
- public function getSchemaBuilder ()
33
+ public function getSchemaBuilder (): DbBuilder
34
34
{
35
35
if ($ this ->schemaGrammar === null ) {
36
36
$ this ->useDefaultSchemaGrammar ();
37
37
}
38
38
39
- return new CockroachDbBuilder ($ this );
39
+ return new DbBuilder ($ this );
40
40
}
41
41
42
42
/**
43
43
* Get the default schema grammar instance.
44
44
*
45
- * @return Grammar
45
+ * @return BaseGrammar
46
46
*/
47
- protected function getDefaultSchemaGrammar (): Grammar
47
+ protected function getDefaultSchemaGrammar (): BaseGrammar
48
48
{
49
- return $ this ->withTablePrefix (new SchemaGrammar ());
49
+ return $ this ->withTablePrefix ($ this -> setConnection ( new SchemaGrammar () ));
50
50
}
51
51
52
52
/**
53
53
* Get the schema state for the connection.
54
- *
55
- * @param \Illuminate\Filesystem\Filesystem|null $files
56
- * @param callable|null $processFactory
57
- * @return \Illuminate\Database\Schema\PostgresSchemaState
54
+ * @return SchemaState
55
+ * @phpstan-ignore-next-line base class has fixed type that we can't correct
58
56
*/
59
- public function getSchemaState (Filesystem $ files = null , callable $ processFactory = null ): PostgresSchemaState
57
+ public function getSchemaState (Filesystem $ files = null , callable $ processFactory = null )
60
58
{
61
- return new PostgresSchemaState ($ this , $ files , $ processFactory );
59
+ return new SchemaState ($ this , $ files , $ processFactory );
62
60
}
63
61
64
62
/**
65
63
* Get the default post processor instance.
66
64
*
67
- * @return CockroachDbProcessor
65
+ * @return DbProcessor
68
66
*/
69
- protected function getDefaultPostProcessor (): CockroachDbProcessor
67
+ protected function getDefaultPostProcessor (): DbProcessor
70
68
{
71
- return new CockroachDbProcessor ();
69
+ return new DbProcessor ();
72
70
}
73
71
74
72
/**
@@ -80,4 +78,16 @@ protected function getDoctrineDriver()
80
78
{
81
79
return new PostgresDriver ();
82
80
}
81
+
82
+ /**
83
+ * Required to set the connection. This isn't compatible with older Laravel versions
84
+ */
85
+ protected function setConnection (BaseGrammar $ grammar ): BaseGrammar
86
+ {
87
+ if (method_exists ($ grammar , 'setConnection ' )) {
88
+ return $ grammar ->setConnection ($ this );
89
+ }
90
+
91
+ return $ grammar ;
92
+ }
83
93
}
0 commit comments