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
TableName
Name of the Table parsed by the Model.
string TableName { get; }
Property Value
Methods
And(List<IPostgrestQueryFilter>)
Adds an AND Filter to the current query args.
IPostgrestTable<TModel> And(List<IPostgrestQueryFilter> filters)
Parameters
filtersList<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
predicateExpression<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
columnsstring[]
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
typeConstants.CountTypeThe kind of count.
cancellationTokenCancellationToken
Returns
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
optionsQueryOptionscancellationTokenCancellationToken
Returns
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
modelTModeloptionsQueryOptionscancellationTokenCancellationToken
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
predicateExpression<Func<TModel, object>>Expects a columns from the Model to be returned
opConstants.OperatorOperation to perform.
criterionTCriterionValue to filter with, must be a
string,List<object>,Dictionary<string, object>,FullTextSearchConfig, orRange
Returns
- IPostgrestTable<TModel>
Type Parameters
TCriterion
Exceptions
Filter<TCriterion>(string, Operator, TCriterion?)
Add a Filter to a query request
IPostgrestTable<TModel> Filter<TCriterion>(string columnName, Constants.Operator op, TCriterion? criterion)
Parameters
columnNamestringColumn Name in Table.
opConstants.OperatorOperation to perform.
criterionTCriterionValue to filter with, must be a
string,List<object>,Dictionary<string, object>,FullTextSearchConfig, orRange
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
Get(CancellationToken)
Executes the query using the defined filters on the current instance.
Task<ModeledResponse<TModel>> Get(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
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
modelsICollection<TModel>optionsQueryOptionscancellationTokenCancellationToken
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
modelTModeloptionsQueryOptionscancellationTokenCancellationToken
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
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
queryDictionary<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
modelTModelA 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
filterIPostgrestQueryFilter
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
predicateExpression<Func<TModel, object>>Expects a column from the model to be returned.
opConstants.OperatorcriteriaDictionary<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
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
predicateExpression<Func<TModel, object>>Expects a column from the model to be returned.
opConstants.OperatorcriteriaList<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
predicateExpression<Func<TModel, object>>Expects a column from the model to be returned.
opConstants.OperatorcriterionTCriterion
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
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
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
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
predicateExpression<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
columnNamestring
Returns
- IPostgrestTable<TModel>
Or(List<IPostgrestQueryFilter>)
Adds a OR Filter to the current query args.
IPostgrestTable<TModel> Or(List<IPostgrestQueryFilter> filters)
Parameters
filtersList<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
IPostgrestTable<TModel> Order(Expression<Func<TModel, object>> predicate, Constants.Ordering ordering, Constants.NullPosition nullPosition = NullPosition.First)
Parameters
predicateExpression<Func<TModel, object>>orderingConstants.OrderingExpects a columns from the Model to be returned
nullPositionConstants.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
IPostgrestTable<TModel> Order(string column, Constants.Ordering ordering, Constants.NullPosition nullPosition = NullPosition.First)
Parameters
columnstringColumn Name
orderingConstants.OrderingnullPositionConstants.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
IPostgrestTable<TModel> Order(string foreignTable, string column, Constants.Ordering ordering, Constants.NullPosition nullPosition = NullPosition.First)
Parameters
Returns
- IPostgrestTable<TModel>
Range(int)
Sets a FROM range, similar to a StartAt query.
IPostgrestTable<TModel> Range(int from)
Parameters
fromint
Returns
- IPostgrestTable<TModel>
Range(int, int)
Sets a bounded range to the current query.
IPostgrestTable<TModel> Range(int from, int to)
Parameters
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
predicateExpression<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
columnQuerystring
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
keyValuePairExpressionExpression<Func<TModel, KeyValuePair<object, object>>>
Returns
- IPostgrestTable<TModel>
Exceptions
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
keySelectorExpression<Func<TModel, object>>valueobject
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
cancellationTokenCancellationToken
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
optionsQueryOptionscancellationTokenCancellationToken
Returns
- Task<ModeledResponse<TModel>>
Exceptions
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
modelTModeloptionsQueryOptionscancellationTokenCancellationToken
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
modelICollection<TModel>optionsQueryOptionscancellationTokenCancellationToken
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
modelTModeloptionsQueryOptionscancellationTokenCancellationToken
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
predicateExpression<Func<TModel, bool>>
Returns
- IPostgrestTable<TModel>