Table of Contents

Interface IPostgrestTable<TModel>

Namespace
Supabase.Postgrest.Interfaces
Assembly
Supabase.Postgrest.dll

Client interface for Postgrest

public interface IPostgrestTable<TModel> : IGettableHeaders where TModel : BaseModel, new()

Type Parameters

TModel
Inherited Members

Properties

BaseUrl

API Base Url for subsequent calls.

string BaseUrl { get; }

Property Value

string

TableName

Name of the Table parsed by the Model.

string TableName { get; }

Property Value

string

Methods

And(List<IPostgrestQueryFilter>)

Adds an AND Filter to the current query args.

IPostgrestTable<TModel> And(List<IPostgrestQueryFilter> filters)

Parameters

filters List<IPostgrestQueryFilter>

Returns

IPostgrestTable<TModel>

Clear()

Clears currently defined query values.

void Clear()

Columns(Expression<Func<TModel, object[]>>)

By using the columns query parameter it’s possible to specify the payload keys that will be inserted and ignore the rest of the payload.

The rest of the JSON keys will be ignored. Using this also has the side-effect of being more efficient for Bulk Insert since PostgREST will not process the JSON and it’ll send it directly to PostgreSQL.

See: https://postgrest.org/en/stable/api.html#specifying-columns

IPostgrestTable<TModel> Columns(Expression<Func<TModel, object[]>> predicate)

Parameters

predicate Expression<Func<TModel, object[]>>

Returns

IPostgrestTable<TModel>

Columns(string[])

By using the columns query parameter it’s possible to specify the payload keys that will be inserted and ignore the rest of the payload.

The rest of the JSON keys will be ignored. Using this also has the side-effect of being more efficient for Bulk Insert since PostgREST will not process the JSON and it’ll send it directly to PostgreSQL.

See: https://postgrest.org/en/stable/api.html#specifying-columns

IPostgrestTable<TModel> Columns(string[] columns)

Parameters

columns string[]

Returns

IPostgrestTable<TModel>

Count(CountType, CancellationToken)

Returns ONLY a count from the specified query.

See: https://postgrest.org/en/v7.0.0/api.html?highlight=count

Task<int> Count(Constants.CountType type, CancellationToken cancellationToken = default)

Parameters

type Constants.CountType

The kind of count.

cancellationToken CancellationToken

Returns

Task<int>

Delete(QueryOptions?, CancellationToken)

Executes a delete request using the defined query params on the current instance.

Task Delete(QueryOptions? options = null, CancellationToken cancellationToken = default)

Parameters

options QueryOptions
cancellationToken CancellationToken

Returns

Task

Delete(TModel, QueryOptions?, CancellationToken)

Executes a delete request using the model's primary key as the filter for the request.

Task<ModeledResponse<TModel>> Delete(TModel model, QueryOptions? options = null, CancellationToken cancellationToken = default)

Parameters

model TModel
options QueryOptions
cancellationToken CancellationToken

Returns

Task<ModeledResponse<TModel>>

Filter<TCriterion>(Expression<Func<TModel, object>>, Operator, TCriterion?)

Add a filter to a query request using a predicate to select column.

IPostgrestTable<TModel> Filter<TCriterion>(Expression<Func<TModel, object>> predicate, Constants.Operator op, TCriterion? criterion)

Parameters

predicate Expression<Func<TModel, object>>

Expects a columns from the Model to be returned

op Constants.Operator

Operation to perform.

criterion TCriterion

Value to filter with, must be a string, List<object>, Dictionary<string, object>, FullTextSearchConfig, or Range

Returns

IPostgrestTable<TModel>

Type Parameters

TCriterion

Exceptions

ArgumentException

Filter<TCriterion>(string, Operator, TCriterion?)

Add a Filter to a query request

IPostgrestTable<TModel> Filter<TCriterion>(string columnName, Constants.Operator op, TCriterion? criterion)

Parameters

columnName string

Column Name in Table.

op Constants.Operator

Operation to perform.

criterion TCriterion

Value to filter with, must be a string, List<object>, Dictionary<string, object>, FullTextSearchConfig, or Range

Returns

IPostgrestTable<TModel>

Type Parameters

TCriterion

GenerateUrl()

Generates the encoded URL with defined query parameters that will be sent to the Postgrest API.

string GenerateUrl()

Returns

string

Get(CancellationToken)

Executes the query using the defined filters on the current instance.

Task<ModeledResponse<TModel>> Get(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<ModeledResponse<TModel>>

Insert(ICollection<TModel>, QueryOptions?, CancellationToken)

Executes a BULK INSERT query using the defined query params on the current instance.

Task<ModeledResponse<TModel>> Insert(ICollection<TModel> models, QueryOptions? options = null, CancellationToken cancellationToken = default)

Parameters

models ICollection<TModel>
options QueryOptions
cancellationToken CancellationToken

Returns

Task<ModeledResponse<TModel>>

A typed model response from the database.

Insert(TModel, QueryOptions?, CancellationToken)

Executes an INSERT query using the defined query params on the current instance.

Task<ModeledResponse<TModel>> Insert(TModel model, QueryOptions? options = null, CancellationToken cancellationToken = default)

Parameters

model TModel
options QueryOptions
cancellationToken CancellationToken

Returns

Task<ModeledResponse<TModel>>

A typed model response from the database.

Limit(int, string?)

Sets a limit with an optional foreign table reference.

IPostgrestTable<TModel> Limit(int limit, string? foreignTableName = null)

Parameters

limit int
foreignTableName string

Returns

IPostgrestTable<TModel>

Match(Dictionary<string, string>)

Finds all rows whose columns match the specified query object.

IPostgrestTable<TModel> Match(Dictionary<string, string> query)

Parameters

query Dictionary<string, string>

The object to filter with, with column names as keys mapped to their filter values.

Returns

IPostgrestTable<TModel>

Match(TModel)

Fills in query parameters based on a given model's primary key(s).

IPostgrestTable<TModel> Match(TModel model)

Parameters

model TModel

A model with a primary key column

Returns

IPostgrestTable<TModel>

Not(IPostgrestQueryFilter)

Adds a NOT filter to the current query args.

IPostgrestTable<TModel> Not(IPostgrestQueryFilter filter)

Parameters

filter IPostgrestQueryFilter

Returns

IPostgrestTable<TModel>

Not(Expression<Func<TModel, object>>, Operator, Dictionary<string, object>)

Adds a NOT filter to the current query args.

IPostgrestTable<TModel> Not(Expression<Func<TModel, object>> predicate, Constants.Operator op, Dictionary<string, object> criteria)

Parameters

predicate Expression<Func<TModel, object>>

Expects a column from the model to be returned.

op Constants.Operator
criteria Dictionary<string, object>

Returns

IPostgrestTable<TModel>

Not(string, Operator, Dictionary<string, object>)

Adds a NOT filter to the current query args.

IPostgrestTable<TModel> Not(string columnName, Constants.Operator op, Dictionary<string, object> criteria)

Parameters

columnName string
op Constants.Operator
criteria Dictionary<string, object>

Returns

IPostgrestTable<TModel>

Not<TCriterion>(Expression<Func<TModel, object>>, Operator, List<TCriterion>)

Adds a NOT filter to the current query args. Allows queries like:

await client.Table<User>().Not("status", Operators.In, new List<string> {"AWAY", "OFFLINE"}).Get();
IPostgrestTable<TModel> Not<TCriterion>(Expression<Func<TModel, object>> predicate, Constants.Operator op, List<TCriterion> criteria)

Parameters

predicate Expression<Func<TModel, object>>

Expects a column from the model to be returned.

op Constants.Operator
criteria List<TCriterion>

Returns

IPostgrestTable<TModel>

Type Parameters

TCriterion

Not<TCriterion>(Expression<Func<TModel, object>>, Operator, TCriterion?)

Adds a NOT filter to the current query args.

Allows queries like:

await client.Table<User>().Not("status", Operators.Equal, "OFFLINE").Get();
IPostgrestTable<TModel> Not<TCriterion>(Expression<Func<TModel, object>> predicate, Constants.Operator op, TCriterion? criterion)

Parameters

predicate Expression<Func<TModel, object>>

Expects a column from the model to be returned.

op Constants.Operator
criterion TCriterion

Returns

IPostgrestTable<TModel>

Type Parameters

TCriterion

Not<TCriterion>(string, Operator, List<TCriterion>)

Adds a NOT filter to the current query args. Allows queries like:

await client.Table<User>().Not("status", Operators.In, new List<string> {"AWAY", "OFFLINE"}).Get();
IPostgrestTable<TModel> Not<TCriterion>(string columnName, Constants.Operator op, List<TCriterion> criteria)

Parameters

columnName string
op Constants.Operator
criteria List<TCriterion>

Returns

IPostgrestTable<TModel>

Type Parameters

TCriterion

Not<TCriterion>(string, Operator, TCriterion?)

Adds a NOT filter to the current query args.

Allows queries like:

await client.Table<User>().Not("status", Operators.Equal, "OFFLINE").Get();
IPostgrestTable<TModel> Not<TCriterion>(string columnName, Constants.Operator op, TCriterion? criterion)

Parameters

columnName string
op Constants.Operator
criterion TCriterion

Returns

IPostgrestTable<TModel>

Type Parameters

TCriterion

Offset(int, string?)

Sets an offset with an optional foreign table reference.

IPostgrestTable<TModel> Offset(int offset, string? foreignTableName = null)

Parameters

offset int
foreignTableName string

Returns

IPostgrestTable<TModel>

OnConflict(Expression<Func<TModel, object>>)

Set an onConflict query parameter for UPSERTing on a column that has a UNIQUE constraint using a linq predicate.

IPostgrestTable<TModel> OnConflict(Expression<Func<TModel, object>> predicate)

Parameters

predicate Expression<Func<TModel, object>>

Expects a column from the model to be returned.

Returns

IPostgrestTable<TModel>

OnConflict(string)

By specifying the onConflict query parameter, you can make UPSERT work on a column(s) that has a UNIQUE constraint.

IPostgrestTable<TModel> OnConflict(string columnName)

Parameters

columnName string

Returns

IPostgrestTable<TModel>

Or(List<IPostgrestQueryFilter>)

Adds a OR Filter to the current query args.

IPostgrestTable<TModel> Or(List<IPostgrestQueryFilter> filters)

Parameters

filters List<IPostgrestQueryFilter>

Returns

IPostgrestTable<TModel>

Order(Expression<Func<TModel, object>>, Ordering, NullPosition)

Adds an ordering to the current query args using a predicate function.

NOTE: If multiple orderings are required, chain this function with another call to Order(Expression{Func{T,object}},Ordering,NullPosition) .

IPostgrestTable<TModel> Order(Expression<Func<TModel, object>> predicate, Constants.Ordering ordering, Constants.NullPosition nullPosition = NullPosition.First)

Parameters

predicate Expression<Func<TModel, object>>
ordering Constants.Ordering

Expects a columns from the Model to be returned

nullPosition Constants.NullPosition

Returns

IPostgrestTable<TModel>

Order(string, Ordering, NullPosition)

Adds an ordering to the current query args.

NOTE: If multiple orderings are required, chain this function with another call to Order(Expression{Func{T,object}},Ordering,NullPosition) .

IPostgrestTable<TModel> Order(string column, Constants.Ordering ordering, Constants.NullPosition nullPosition = NullPosition.First)

Parameters

column string

Column Name

ordering Constants.Ordering
nullPosition Constants.NullPosition

Returns

IPostgrestTable<TModel>

Order(string, string, Ordering, NullPosition)

Adds an ordering to the current query args.

NOTE: If multiple orderings are required, chain this function with another call to Order(Expression{Func{T,object}},Ordering,NullPosition) .

IPostgrestTable<TModel> Order(string foreignTable, string column, Constants.Ordering ordering, Constants.NullPosition nullPosition = NullPosition.First)

Parameters

foreignTable string
column string
ordering Constants.Ordering
nullPosition Constants.NullPosition

Returns

IPostgrestTable<TModel>

Range(int)

Sets a FROM range, similar to a StartAt query.

IPostgrestTable<TModel> Range(int from)

Parameters

from int

Returns

IPostgrestTable<TModel>

Range(int, int)

Sets a bounded range to the current query.

IPostgrestTable<TModel> Range(int from, int to)

Parameters

from int
to int

Returns

IPostgrestTable<TModel>

Select(Expression<Func<TModel, object[]>>)

Select columns using a predicate function.

For example: Table<Movie>().Select(x => new[] { x.Id, x.Name, x.CreatedAt }).Get();

IPostgrestTable<TModel> Select(Expression<Func<TModel, object[]>> predicate)

Parameters

predicate Expression<Func<TModel, object[]>>

Expects an array of columns from the Model to be returned.

Returns

IPostgrestTable<TModel>

Select(string)

Select columns for query.

IPostgrestTable<TModel> Select(string columnQuery)

Parameters

columnQuery string

Returns

IPostgrestTable<TModel>

Set(Expression<Func<TModel, KeyValuePair<object, object?>>>)

Specifies a KeyValuePair to be updated. Should be combined with filters/where clauses.

Can be called multiple times to set multiple values.

IPostgrestTable<TModel> Set(Expression<Func<TModel, KeyValuePair<object, object?>>> keyValuePairExpression)

Parameters

keyValuePairExpression Expression<Func<TModel, KeyValuePair<object, object>>>

Returns

IPostgrestTable<TModel>

Exceptions

ArgumentException

Set(Expression<Func<TModel, object>>, object?)

Specifies a key and value to be updated. Should be combined with filters/where clauses.

Can be called multiple times to set multiple values.

IPostgrestTable<TModel> Set(Expression<Func<TModel, object>> keySelector, object? value)

Parameters

keySelector Expression<Func<TModel, object>>
value object

Returns

IPostgrestTable<TModel>

Single(CancellationToken)

Executes a query that expects to have a single object returned, rather than returning list of models it will return a single model.

Task<TModel?> Single(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<TModel>

Update(QueryOptions?, CancellationToken)

Calls an Update function after Set has been called.

Task<ModeledResponse<TModel>> Update(QueryOptions? options = null, CancellationToken cancellationToken = default)

Parameters

options QueryOptions
cancellationToken CancellationToken

Returns

Task<ModeledResponse<TModel>>

Exceptions

ArgumentException

Update(TModel, QueryOptions?, CancellationToken)

Executes an UPDATE query using the defined query params on the current instance.

Task<ModeledResponse<TModel>> Update(TModel model, QueryOptions? options = null, CancellationToken cancellationToken = default)

Parameters

model TModel
options QueryOptions
cancellationToken CancellationToken

Returns

Task<ModeledResponse<TModel>>

A typed response from the database.

Upsert(ICollection<TModel>, QueryOptions?, CancellationToken)

Executes an UPSERT query using the defined query params on the current instance.

By default the new record is returned. Set QueryOptions.ReturnType to Minimal if you don't need this value. By specifying the QueryOptions.OnConflict parameter, you can make UPSERT work on a column(s) that has a UNIQUE constraint. QueryOptions.DuplicateResolution.IgnoreDuplicates Specifies if duplicate rows should be ignored and not inserted.

Task<ModeledResponse<TModel>> Upsert(ICollection<TModel> model, QueryOptions? options = null, CancellationToken cancellationToken = default)

Parameters

model ICollection<TModel>
options QueryOptions
cancellationToken CancellationToken

Returns

Task<ModeledResponse<TModel>>

Upsert(TModel, QueryOptions?, CancellationToken)

Executes an UPSERT query using the defined query params on the current instance.

By default the new record is returned. Set QueryOptions.ReturnType to Minimal if you don't need this value. By specifying the QueryOptions.OnConflict parameter, you can make UPSERT work on a column(s) that has a UNIQUE constraint. QueryOptions.DuplicateResolution.IgnoreDuplicates Specifies if duplicate rows should be ignored and not inserted.

Task<ModeledResponse<TModel>> Upsert(TModel model, QueryOptions? options = null, CancellationToken cancellationToken = default)

Parameters

model TModel
options QueryOptions
cancellationToken CancellationToken

Returns

Task<ModeledResponse<TModel>>

Where(Expression<Func<TModel, bool>>)

Filter a query based on a predicate function.

Note: Chaining multiple Where(Expression<Func<TModel, bool>>) calls will be parsed as an "AND" query.

Examples: Table<Movie>().Where(x => x.Name == "Top Gun").Get(); Table<Movie>().Where(x => x.Name == "Top Gun" || x.Name == "Mad Max").Get(); Table<Movie>().Where(x => x.Name.Contains("Gun")).Get(); Table<Movie>().Where(x => x.CreatedAt <= new DateTime(2022, 08, 21)).Get(); Table<Movie>().Where(x => x.Id > 5 && x.Name.Contains("Max")).Get();

IPostgrestTable<TModel> Where(Expression<Func<TModel, bool>> predicate)

Parameters

predicate Expression<Func<TModel, bool>>

Returns

IPostgrestTable<TModel>