singlestore-labs / singlestoredb-laravel-driver

The official SingleStore Laravel driver.
https://github.com/singlestore-labs/singlestore-laravel-driver
Apache License 2.0
224 stars 22 forks source link

Add support for CTEs with laravel-cte #64

Closed heychazza closed 1 year ago

heychazza commented 1 year ago

Hi folks,

Any chance of being able to add support for the https://github.com/staudenmeir/laravel-cte package, as currently it gives the following error:

BadMethodCallException : Call to undefined method SingleStore\Laravel\Query\Builder::withExpression()

I'd happily donate in return as I want to avoid raw queries.

Thanks

heychazza commented 1 year ago

Also CC @staudenmeir in case you may know any "magic" to get it working

staudenmeir commented 1 year ago

Hi @heychazza, Maybe you can reuse an existing implementation from my package. Is SingleStore closer to PostgreSQL or MySQL? Are table names etc. quoted with double quotes or backticks?

heychazza commented 1 year ago

Hi @heychazza, Maybe you can reuse an existing implementation from my package. Is SingleStore closer to PostgreSQL or MySQL? Are table names etc. quoted with double quotes or backticks?

Hey pal, I believe backticks work fine, I know in this driver they have their own builder.

I assume you’d just need to combine their builder with your extra methods.

AdalbertMemSQL commented 1 year ago

Hi @heychazza Thanks for reaching out. I created an internal ticket to investigate this question.

AdalbertMemSQL commented 1 year ago

SingleStore is closer to MySQL in terms of syntax, so there is a sense of trying to use laravel-cte with the MySQL driver.

heychazza commented 1 year ago

SingleStore is closer to MySQL in terms of syntax, so there is a sense of trying to use laravel-cte with the MySQL driver.

Yeah I agree, I think the laravel-cte driver would just need to add singlestore as a driver and point to MySQL perhaps, I'm not sure

AdalbertMemSQL commented 1 year ago

Ideally, it should reuse grammar from this connector.

For example, to have something like this

namespace Staudenmeir\LaravelCte\Query\Grammars;

use SingleStore\Laravel\Query\Grammar as Base;
use Staudenmeir\LaravelCte\Query\Grammars\Traits\CompilesSingleStoreExpressions;

class SingleStoreGrammar extends Base
{
    use CompilesSingleStoreExpressions;
}

But as a first implementation - just pointing to MySQL is a good start.

AdalbertMemSQL commented 1 year ago

@heychazza @staudenmeir I created a PR that adds support of the SingleStore https://github.com/staudenmeir/laravel-cte/pull/48

heychazza commented 1 year ago

@heychazza @staudenmeir I created a PR that adds support of the SingleStore staudenmeir/laravel-cte#48

This is actually superb, you’ve added tests and everything. 10/10 - SingleStore have a phenomenal team member 👏

AdalbertMemSQL commented 1 year ago

Thanks to @staudenmeir Now this driver should work well with laravel-cte.