I am working on Google big queries and I wanted to know that either I can use laravel query builder to get data from google big query service?
I was working on the same thing and trying to figure out the solution for that I user laravel 5 query builder and then I get an idea if we get the query from query builder and get bindings from query builder then we can easily use that query directory for the google bigquery
Let me explain with the code below.
$users = DB::table('users')
->where('id','=','3');
Now i will use the function that will return me mysql query.
$sql = $users->toSql(); //this will return the sql query from query builder.
The output of above statement will be like this
select * from users where id = ?
Now I have another function that will give me the binding of that query.
$bindings = $users->getBindings(); //this statement will return me 3
After that if we want complete mysql query with binding then we have another function to do that.
public function getSqlWithBinding($sql,$bindDataArr){
foreach($bindDataArr as $binding)
{
$value = is_numeric($binding) ? $binding : "'".$binding."'";
$sql = preg_replace('/\?/', $value, $sql, 1);
}
return $sql;
}
Just pass both $sql = $users->toSql();
and $bindings = $users->getBindings();
in parameter to the above function and get the complete query like below.
select * from users where id = 3
Now that sql query you can use for you google bigquery
without any confusion.
You can't. The query builder is meant for database protocols. Currently, Laravel supports four databases:
MySQL
PostgreSQL
SQLite
SQL Server
BigQuery instead is provided as a service, and has it's own SDK. You need to add the to composer.json the BigQuery Cloud package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With