Documentation

PostgrestRequestBuilder
in package
Uses FilterOperators

PostgREST request builder.

Class for dynamically building PostgREST requests.

Table of Contents

Properties

$filters  : array<string|int, string>
$body  : string|null
$headers  : array<string, string>
$helper  : Helper
$method  : string
$schemaName  : string
$tableName  : string

Methods

__construct()  : mixed
Create a new PostgREST request builder.
count()  : PostgrestRequestBuilder
Count the result range.
delete()  : PostgrestRequestBuilder
Delete from the table.
filterRaw()  : PostgrestRequestBuilder
Raw filter function for tables.
filterRawColumn()  : PostgrestRequestBuilder
Raw filter function for columns.
getHeader()  : string|null
Get header value by name.
getRequestData()  : array<int, mixed>
Get data from class which is needed to run the request
insert()  : PostgrestRequestBuilder
Insert data into the table.
limit()  : PostgrestRequestBuilder
Set the limit for the results.
offset()  : PostgrestRequestBuilder
Set the offset for the results.
orderBy()  : PostgrestRequestBuilder
Order results by the given columns.
select()  : PostgrestRequestBuilder
Set the columns to select from the table.
setHeader()  : PostgrestRequestBuilder
Set specific header.
update()  : PostgrestRequestBuilder
Update the table.
upsert()  : PostgrestRequestBuilder
Insert data into the table, or resolve conflict if rows already exists.
_insert()  : PostgrestRequestBuilder
Underlying function which backs insert() and upsert().
appendPreferHeader()  : void
Append the Prefer header.
encodeData()  : void
Encode the given data in the given format.
setDuplicateResolution()  : void
Set the duplicate resolution.
setMissingAsDefault()  : void
Set the missing columns to their default values.
setReturnFormat()  : void
Set the return format.

Properties

Methods

__construct()

Create a new PostgREST request builder.

public final __construct(string $schemaName, string $tableName) : mixed
Parameters
$schemaName : string

The schema name to use for the request.

$tableName : string

The table name to use for the request.

count()

Count the result range.

public count(CountType $countType) : PostgrestRequestBuilder
Parameters
$countType : CountType

The type of count to perform.

Tags
link
https://postgrest.org/en/stable/references/api/tables_views.html#exact-count
link
https://postgrest.org/en/stable/references/api/tables_views.html#planned-count
link
https://postgrest.org/en/stable/references/api/tables_views.html#estimated-count
Return values
PostgrestRequestBuilder

The request builder.

filterRawColumn()

Raw filter function for columns.

public filterRawColumn(string $columnName, string $operator, string $value) : PostgrestRequestBuilder
Parameters
$columnName : string

The name of the column.

$operator : string

The operator to use.

$value : string

The value to use.

Return values
PostgrestRequestBuilder

The PostgrestRequestBuilder instance.

getHeader()

Get header value by name.

public getHeader(string $name) : string|null
Parameters
$name : string

The name of the header.

Return values
string|null

The value of the header, or null if it does not exist.

getRequestData()

Get data from class which is needed to run the request

public getRequestData() : array<int, mixed>
Return values
array<int, mixed>

insert()

Insert data into the table.

public insert(array<string, mixed>|array<string|int, array<string, mixed>> $data[, array<string|int, string> $columns = [] ][, bool $missingAsDefault = false ][, DataFormat $dataFormat = DataFormat::JSON ][, ReturnFormat $returnFormat = ReturnFormat::NONE ]) : PostgrestRequestBuilder
Parameters
$data : array<string, mixed>|array<string|int, array<string, mixed>>

The data to insert.

$columns : array<string|int, string> = []

Which columns to insert

$missingAsDefault : bool = false

Whether to use the default value for missing columns.

$dataFormat : DataFormat = DataFormat::JSON

The format in which the data will be sent.

$returnFormat : ReturnFormat = ReturnFormat::NONE

The format in which the response will be returned.

Tags
throws
NotUnifiedValuesException

If the columns are not of the same type.

link
https://postgrest.org/en/stable/references/api/tables_views.html#insert
Return values
PostgrestRequestBuilder

The request builder.

update()

Update the table.

public update(array<string, mixed> $data[, ReturnFormat $returnFormat = ReturnFormat::NONE ]) : PostgrestRequestBuilder
Parameters
$data : array<string, mixed>

Key-value pairs (Column + Value).

$returnFormat : ReturnFormat = ReturnFormat::NONE

The format in which the response will be returned.

Tags
throws
DataEncodingException

If the data could not be encoded as JSON.

link
https://postgrest.org/en/stable/references/api/tables_views.html#update
Return values
PostgrestRequestBuilder

The request builder.

upsert()

Insert data into the table, or resolve conflict if rows already exists.

public upsert(array<string, mixed>|array<string|int, array<string, mixed>> $data[, DataFormat $dataFormat = DataFormat::JSON ][, ReturnFormat $returnFormat = ReturnFormat::NONE ][, DuplicateResolution $duplicateResolution = DuplicateResolution::MERGE ][, array<string|int, string> $onConflict = [] ]) : PostgrestRequestBuilder
Parameters
$data : array<string, mixed>|array<string|int, array<string, mixed>>

The data to insert.

$dataFormat : DataFormat = DataFormat::JSON

The format in which the data will be sent.

$returnFormat : ReturnFormat = ReturnFormat::NONE

The format in which the response will be returned.

$duplicateResolution : DuplicateResolution = DuplicateResolution::MERGE

The resolution to use for duplicate rows.

$onConflict : array<string|int, string> = []

The columns to use for conflict resolution.

Tags
throws
FilterLogicException

If the duplicate resolution is not set.

throws
NotUnifiedValuesException

If the onConflict columns are not of the same type.

link
https://postgrest.org/en/stable/references/api/tables_views.html#upsert
Return values
PostgrestRequestBuilder

The request builder.

_insert()

Underlying function which backs insert() and upsert().

private _insert(array<string|int, array<string, mixed>> $data[, bool $missingAsDefault = false ][, DataFormat $dataFormat = DataFormat::JSON ][, ReturnFormat $returnFormat = ReturnFormat::NONE ][, DuplicateResolution $duplicateResolution = DuplicateResolution::NONE ]) : PostgrestRequestBuilder
Parameters
$data : array<string|int, array<string, mixed>>

The data to insert.

$missingAsDefault : bool = false

Whether to use the default value for missing columns.

$dataFormat : DataFormat = DataFormat::JSON

The format in which the data will be sent.

$returnFormat : ReturnFormat = ReturnFormat::NONE

The format in which the response will be returned.

$duplicateResolution : DuplicateResolution = DuplicateResolution::NONE

The resolution to use for duplicate rows.

Tags
throws
DataEncodingException

If the data could not be encoded as JSON or the DataFormat chosen is not supported.

Return values
PostgrestRequestBuilder

The request builder.

appendPreferHeader()

Append the Prefer header.

private appendPreferHeader(string $preferHeader) : void
Parameters
$preferHeader : string

The Prefer header.

encodeData()

Encode the given data in the given format.

private encodeData(array<string|int, array<string, mixed>> $data, DataFormat $dataFormat) : void
Parameters
$data : array<string|int, array<string, mixed>>

The data to encode.

$dataFormat : DataFormat

The format in which to encode the data.

Tags
throws
DataEncodingException

If the data could not be encoded as JSON.

setMissingAsDefault()

Set the missing columns to their default values.

private setMissingAsDefault() : void

        
On this page

Search results