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
$filters
protected
array<string|int, string>
$filters
$body
private
string|null
$body
$headers
private
array<string, string>
$headers
$helper
private
Helper
$helper
$method
private
string
$method
$schemaName
private
string
$schemaName
$tableName
private
string
$tableName
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
Return values
PostgrestRequestBuilder —The request builder.
delete()
Delete from the table.
public
delete([ReturnFormat $returnFormat = ReturnFormat::NONE ]) : PostgrestRequestBuilder
Parameters
- $returnFormat : ReturnFormat = ReturnFormat::NONE
-
The format in which the response will be returned.
Tags
Return values
PostgrestRequestBuilder —The request builder.
filterRaw()
Raw filter function for tables.
public
filterRaw(string $filter) : PostgrestRequestBuilder
Parameters
- $filter : string
-
The filter to use.
Return values
PostgrestRequestBuilder —The PostgrestRequestBuilder instance.
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
Return values
PostgrestRequestBuilder —The request builder.
limit()
Set the limit for the results.
public
limit(int $limit) : PostgrestRequestBuilder
Parameters
- $limit : int
-
The limit.
Tags
Return values
PostgrestRequestBuilder —The request builder.
offset()
Set the offset for the results.
public
offset(int $offset) : PostgrestRequestBuilder
Parameters
- $offset : int
-
The offset.
Tags
Return values
PostgrestRequestBuilder —The request builder.
orderBy()
Order results by the given columns.
public
orderBy(OrderColumn ...$columns) : PostgrestRequestBuilder
Parameters
- $columns : OrderColumn
-
The columns by which to order.
Tags
Return values
PostgrestRequestBuilder —The request builder.
select()
Set the columns to select from the table.
public
select(string ...$columns) : PostgrestRequestBuilder
Parameters
- $columns : string
-
The columns to select.
Tags
Return values
PostgrestRequestBuilder —The request builder.
setHeader()
Set specific header.
public
setHeader(string $name, string $value) : PostgrestRequestBuilder
Parameters
- $name : string
-
The name of the header.
- $value : string
-
The value of the header.
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
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
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
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
setDuplicateResolution()
Set the duplicate resolution.
private
setDuplicateResolution(DuplicateResolution $duplicateResolution) : void
Parameters
- $duplicateResolution : DuplicateResolution
-
The duplicate resolution.
setMissingAsDefault()
Set the missing columns to their default values.
private
setMissingAsDefault() : void
setReturnFormat()
Set the return format.
private
setReturnFormat(ReturnFormat $returnFormat) : void
Parameters
- $returnFormat : ReturnFormat
-
The return format.