22
22
23
23
class PgSQLConnection extends AbstractConnection
24
24
{
25
- /**
26
- * @var PostgreSQL
27
- */
28
- protected $ connection ;
25
+ protected PostgreSQL $ connection ;
29
26
30
27
protected array $ config = [
31
28
'driver ' => 'pgsql ' ,
@@ -104,7 +101,7 @@ public function execute(string $query, array $bindings = []): int
104
101
105
102
public function exec (string $ sql ): int
106
103
{
107
- return $ this ->execute ($ sql, [] );
104
+ return $ this ->execute ($ sql );
108
105
}
109
106
110
107
public function query (string $ query , array $ bindings = []): array
@@ -128,24 +125,31 @@ public function fetch(string $query, array $bindings = [])
128
125
129
126
public function call (string $ method , array $ argument = [])
130
127
{
131
- switch ($ method ) {
132
- case 'beginTransaction ' :
133
- return $ this ->connection ->query ('BEGIN ' );
134
- case 'rollBack ' :
135
- return $ this ->connection ->query ('ROLLBACK ' );
136
- case 'commit ' :
137
- return $ this ->connection ->query ('COMMIT ' );
138
- }
139
-
140
- return $ this ->connection ->{$ method }(...$ argument );
128
+ return match ($ method ) {
129
+ 'beginTransaction ' => $ this ->connection ->query ('BEGIN ' ),
130
+ 'rollBack ' => $ this ->connection ->query ('ROLLBACK ' ),
131
+ 'commit ' => $ this ->connection ->query ('COMMIT ' ),
132
+ default => $ this ->connection ->{$ method }(...$ argument ),
133
+ };
141
134
}
142
135
143
136
public function run (Closure $ closure )
144
137
{
145
138
return $ closure ->call ($ this , $ this ->connection );
146
139
}
147
140
148
- public function str_replace_once ($ needle , $ replace , $ haystack )
141
+ /**
142
+ * @param string $needle
143
+ * @param string $replace
144
+ * @param string $haystack
145
+ * @deprecated ,using `strReplaceOnce` instead
146
+ */
147
+ public function str_replace_once ($ needle , $ replace , $ haystack ): array |string
148
+ {
149
+ return $ this ->strReplaceOnce ($ needle , $ replace , $ haystack );
150
+ }
151
+
152
+ public function strReplaceOnce (string $ needle , string $ replace , string $ haystack ): array |string
149
153
{
150
154
// Looks for the first occurence of $needle in $haystack
151
155
// and replaces it with $replace.
@@ -162,7 +166,7 @@ protected function prepare(string $query): PostgreSQLStatement
162
166
{
163
167
$ num = 1 ;
164
168
while (strpos ($ query , '? ' )) {
165
- $ query = $ this ->str_replace_once ('? ' , '$ ' . $ num ++, $ query );
169
+ $ query = $ this ->strReplaceOnce ('? ' , '$ ' . $ num ++, $ query );
166
170
}
167
171
168
172
$ statement = $ this ->connection ->prepare ($ query );
0 commit comments