asseco-voice / laravel-json-query-builder Goto Github PK
View Code? Open in Web Editor NEWBuilding Eloquent queries from JSON
License: MIT License
Building Eloquent queries from JSON
License: MIT License
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"))))
PHP 8.1 / Laravel 9 support?
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');
}
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 :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.