Giter Club home page Giter Club logo

laravel-json-query-builder's Issues

Builder query execution error in Laravel 8.x

DB : MariaDb
Leavel : 8.x

Issue in query syntax created by "JsonQuery" will give column and table name in double quote which is not supported but mysql and MariaDB as well.

public $builder;
    public function __construct()
    {
        $this->builder = app(Builder::class);
        $this->builder->setModel(new User());
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
     */
    public function index(Request $request)
    {
        $input = [
            'search' => [
                'first_name' => '=Simeon',
            ],
        ];
        $jsonQuery = new JsonQuery( $this->builder , $input);
        $jsonQuery->search();
        dd($this->builder->get());
        return UserResource::collection($users);
    }

Error

Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '"users" where ((("first_name" in (?))))' at line 1 (SQL: select * from "users" where ((("first_name" in ("Simeon"))))) in file /var/www/api/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 692

mysql accept this type of syntax

SQL: select * from `users` where (((`first_name` in ("Simeon"))))

Respect Model Connection

Hi,

currently the package supports only the default connection set up in the .env file, but in my case i have to use multiple connections, which are set up in the $connection var in the corresponding model.

Could you update those methods to support it.

   public function getModelColumns(): array
    {
        $table = $this->model->getTable();
        $connection = $this->model->getConnection();

        if (Cache::has(self::CACHE_PREFIX . $table)) {
            return Cache::get(self::CACHE_PREFIX . $table);
        }

        $columns = $connection->getSchemaBuilder()->getColumnListing($table);
        $modelColumns = [];

        $this->registerEnumTypeForDoctrine($connection);

        try {
            foreach ($columns as $column) {
                $modelColumns[$column] = $connection->getSchemaBuilder()->getColumnType($table, $column);
            }
        } catch (Exception $e) {
            // leave model columns as an empty array and cache it.
        }

        Cache::put(self::CACHE_PREFIX . $table, $modelColumns, self::CACHE_TTL);

        return $modelColumns;
    }

    /**
     * Having 'enum' in table definition will throw Doctrine error because it is not defined in their types.
     * Registering it manually.
     */
    protected function registerEnumTypeForDoctrine($connection): void
    {

        if (!class_exists('Doctrine\DBAL\Driver\AbstractSQLiteDriver')) {
            return;
        }

        $connection
            ->getDoctrineSchemaManager()
            ->getDatabasePlatform()
            ->registerDoctrineTypeMapping('enum', 'string');
    }

how i can make a not exists expression with a subquery

Hi!

Please tell me how I can create the following expression

select *
from `users`
where `channel_id` = 81
  and (not exists (select *
                     from `user_variables`
                     where `users`.`id` = `user_variables`.`user_id`
                       and `id` in ('489')
                       and `value` = 123
          ))

For one field, I can use the construction
!relation.column

But I need not_exists by subquery

Thanks for your attention :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.