-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nette/dibi driver support #462
Comments
Hi Jakub, great to see people interessting in adding support for new db apis. to add a new api to phpstan-dba you need 2 things:
I would suggest doing these 2 things in separate PRs. starting with 1) which is the easier step. feel free to open a PR with your attemps, so I can give you more concrete hints |
Well 1) seems easy (I already kind of did that when I added those methods in services in the neon file) when I was testing, afaik the it would be this 🐞 jakubvojacek@~/Sites/phpstan-dba $ git diff
diff --git a/config/dba.neon b/config/dba.neon
index 2542a3d..250bdda 100644
--- a/config/dba.neon
+++ b/config/dba.neon
@@ -49,6 +49,7 @@ services:
- 'mysqli::execute_query#0'
- 'Doctrine\DBAL\Connection::query#0' # deprecated in doctrine
- 'Doctrine\DBAL\Connection::exec#0' # deprecated in doctrine
+ - 'Dibi\Connection::query#0'
-
class: staabm\PHPStanDba\Rules\SyntaxErrorInQueryFunctionRule
@@ -89,3 +90,4 @@ services:
- 'mysqli::execute_query#0'
- 'Doctrine\DBAL\Connection::query#0' # deprecated in doctrine
- 'Doctrine\DBAL\Connection::exec#0' # deprecated in doctrine
+ - 'Dibi\Connection::query#0' but its hard for me to say that I didnt miss anything since I cannot test it properly without 2). I will try looking at the samples that you sent and in case I manage somehow to make it work, I will open the PRs Thanks again |
nevermind my previous post. The problem with $connection->query('...')->fetchAll();
$connection->query('...')->fetchSingle();
$connection->query('...')->fetchAssoc('xxx'); and to write support for that does not seem as easy. But dibi also supports $connection->fetchAll();
$connection->fetchSingle();
$connection->fetchAssoc(); which returns the desired results already. in that case 1) would be something like 🐞 jakubvojacek@~/Sites/phpstan-dba $ git diff
diff --git a/config/dba.neon b/config/dba.neon
index 2542a3d..f15bcae 100644
--- a/config/dba.neon
+++ b/config/dba.neon
@@ -49,6 +49,11 @@ services:
- 'mysqli::execute_query#0'
- 'Doctrine\DBAL\Connection::query#0' # deprecated in doctrine
- 'Doctrine\DBAL\Connection::exec#0' # deprecated in doctrine
+ - 'Dibi\Connection::fetch#0'
+ - 'Dibi\Connection::fetchSingle#0'
+ - 'Dibi\Connection::fetchAssoc#0'
+ - 'Dibi\Connection::fetchAll#0'
+ - 'Dibi\Connection::fetchPairs#0'
-
class: staabm\PHPStanDba\Rules\SyntaxErrorInQueryFunctionRule
@@ -89,3 +94,8 @@ services:
- 'mysqli::execute_query#0'
- 'Doctrine\DBAL\Connection::query#0' # deprecated in doctrine
- 'Doctrine\DBAL\Connection::exec#0' # deprecated in doctrine
+ - 'Dibi\Connection::fetch#0'
+ - 'Dibi\Connection::fetchSingle#0'
+ - 'Dibi\Connection::fetchAssoc#0'
+ - 'Dibi\Connection::fetchAll#0'
+ - 'Dibi\Connection::fetchPairs#0'
🐞 jakubvojacek@~/Sites/phpstan-dba $ and then I'd have to create rules for each of those methods, something like final class DibiConnectionFetchDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
{
public function getClass(): string
{
return \Dibi\Connection::class;
}
public function isMethodSupported(MethodReflection $methodReflection): bool
{
return \in_array(strtolower($methodReflection->getName()), ['fetch'], true);
}
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
{
// some logic that will return the type of the single column (via something like inferType) that the user selected (nullable because the query might return zero rows)
}
} right? Please excuse my "stupidness", I've never contributed to phpstan before so it might take some time before I'm up to speed. |
I am getting somewhat close to finishing stage two (will have to write some tests) but I got the feeling you won't like some parts of that :) but works like a charm so far |
great news.
thats totally fine. I am looking forward to it. |
Just a thought. You could implement namespace Dibi
class Connection
{
/**
* @template args
* @param args $args
* @return Result<args, Dibi\Row::class>
*/
public function query(mixed ...$args): Result {}
}
/**
* @template args
* @template rowType
*/
class Result
{
/**
* @return self<args, $class>
*/
public function setRowClass(?string $class): self {}
} Having the template on the |
Hello
I tried modifying phpstan-dba to add support to either https://github.com/dg/dibi or https://github.com/nette/database (both are very very similar in terms of methods, almost interchangeable).
The syntax is mainly
i tried copying stuff from mysqli/pdo driver but they are different, they execute the query in 2 steps (prepare, execute) while dibi/nette does that in one method that accepts N-parameters.
Could you please guide me a bit how to add basic support for this?
Thanks a lot
Jakub
The text was updated successfully, but these errors were encountered: