Class PostgrestQuery

java.lang.Object
com.codename1.cloud.supabase.PostgrestQuery

public class PostgrestQuery extends Object

A PostgREST query or write on one table, built with chained calls and sent by execute().

Filters apply to selects, updates and deletes. Values are sent as text; PostgREST converts them to the column type.

Supabase supabase = new Supabase("https://xyzcompany.supabase.co", "public-anon-key");
Map<String, Object> row = new HashMap<String, Object>();
row.put("name", "Denmark");
supabase.from("countries").insert(row).returning(true).execute();
supabase.from("countries").delete().eq("name", "Atlantis").execute();
  • Method Details

    • select

      public PostgrestQuery select(String columns)

      Chooses the columns to return, * by default. Embedded resources work too: id,name,cities(name).

      Parameters
      • columns: the column list
      Returns

      this query

    • eq

      public PostgrestQuery eq(String column, Object value)

      Column equals value.

      Parameters
      • column: the column

      • value: the value

      Returns

      this query

    • neq

      public PostgrestQuery neq(String column, Object value)

      Column does not equal value.

      Parameters
      • column: the column

      • value: the value

      Returns

      this query

    • gt

      public PostgrestQuery gt(String column, Object value)

      Column is greater than value.

      Parameters
      • column: the column

      • value: the value

      Returns

      this query

    • gte

      public PostgrestQuery gte(String column, Object value)

      Column is greater than or equal to value.

      Parameters
      • column: the column

      • value: the value

      Returns

      this query

    • lt

      public PostgrestQuery lt(String column, Object value)

      Column is less than value.

      Parameters
      • column: the column

      • value: the value

      Returns

      this query

    • lte

      public PostgrestQuery lte(String column, Object value)

      Column is less than or equal to value.

      Parameters
      • column: the column

      • value: the value

      Returns

      this query

    • like

      public PostgrestQuery like(String column, String pattern)

      Case sensitive pattern match. Use * or % as the wildcard.

      Parameters
      • column: the column

      • pattern: the pattern

      Returns

      this query

    • ilike

      public PostgrestQuery ilike(String column, String pattern)

      Case insensitive pattern match.

      Parameters
      • column: the column

      • pattern: the pattern

      Returns

      this query

    • is

      public PostgrestQuery is(String column, String value)

      Column IS a value: null, true or false.

      Parameters
      • column: the column

      • value: null, true or false

      Returns

      this query

    • in

      public PostgrestQuery in(String column, Object... values)

      Column is one of the values. Values with commas, quotes or parentheses are quoted.

      Parameters
      • column: the column

      • values: the values

      Returns

      this query

    • order

      public PostgrestQuery order(String column, boolean ascending)

      Sorts by a column. Call again for secondary sorts.

      Parameters
      • column: the column

      • ascending: the direction

      Returns

      this query

    • limit

      public PostgrestQuery limit(int count)

      Returns at most count rows.

      Parameters
      • count: the row limit
      Returns

      this query

    • range

      public PostgrestQuery range(int from, int to)

      Returns rows from to to, both inclusive and zero based.

      Parameters
      • from: the first row

      • to: the last row

      Returns

      this query

    • insert

      public PostgrestQuery insert(Object rows)

      Inserts a row (Map) or rows (List of maps).

      Parameters
      • rows: a map or a list of maps
      Returns

      this query

    • upsert

      public PostgrestQuery upsert(Object rows, String onConflictColumns)

      Inserts rows or merges them into existing rows with the same key.

      Parameters
      • rows: a map or a list of maps

      • onConflictColumns: the unique columns to match on, or null for the primary key

      Returns

      this query

    • update

      public PostgrestQuery update(Map<String,Object> values)

      Updates the rows that match the filters.

      Parameters
      • values: the columns to change
      Returns

      this query

    • delete

      public PostgrestQuery delete()

      Deletes the rows that match the filters.

      Returns

      this query

    • returning

      public PostgrestQuery returning(boolean returning)

      Asks a write to return the affected rows. Off by default.

      Parameters
      • returning: true to return the rows
      Returns

      this query

    • getMethod

      public String getMethod()

      The HTTP method execute() sends.

      Returns

      the method

    • buildUrl

      public String buildUrl()

      The request URL execute() sends, query string included.

      Returns

      the URL

    • buildHeaders

      public Map<String,String> buildHeaders()

      The request headers execute() adds to the auth headers.

      Returns

      the headers

    • execute

      public AsyncResource<List<Map<String,Object>>> execute()

      Sends the request.

      Returns

      the rows; empty for a write without returning(true)