rafaelwendel / phpsupabase

PHP Client to use Supabase
MIT License
187 stars 17 forks source link

Where 2 conditions for a field (e.g. date) #29

Closed paulgotea closed 3 months ago

paulgotea commented 11 months ago

I am trying to make a query and get the data based on created_at field for a specific date interval.

How can I add to conditions for one field?

Currently I have this;

    $query = [
      'select' => 'created_at',
      'from'   => 'usersData',
      'where' =>
      [
        'created_at' => 'gte.' . $this->start_date . 'T00:00:00',
      ],

But I want to add this as well:

'created_at' => 'lt.' . $this->end_date . 'T23:59:59',

Thanks!

rafaelwendel commented 11 months ago

Hi @paulgotea

To be able to get data by date range, I recommend using the QueryBuilder class.

$query = $service->initializeQueryBuilder();
$result = $query->select("created_at")
                    ->from('usersData')
                    ->where('created_at', 'gte.' . $this->start_date . 'T00:00:00')
                    ->where('created_at', 'lt.' . $this->end_date. 'T23:59:59')
                    ->execute()
                    ->getResult();

I hope you can resolve this.

If you have any problems, I am available to try to help you.

=)