JavaScript: Fetch data

Examples

Getting your data

const \{ data, error \} = await supabase
  .from('cities')
  .select()

Selecting specific columns

const \{ data, error \} = await supabase
  .from('cities')
  .select('name')

Query foreign tables

const \{ data, error \} = await supabase
  .from('countries')
  .select(`
    name,
    cities (
      name
    )
  `)

Query the same foreign table multiple times

const \{ data, error \} = await supabase
  .from('products')
  .select(`
    id,
    supplier:supplier_id ( name ),
    purchaser:purchaser_id ( name )
  `)

Filtering with inner joins

const \{ data, error \} = await supabase
  .from('messages')
  .select('*, users!inner(*)')
  .eq('users.username', 'Jane')

Querying with count option

const \{ data, error, count \} = await supabase
  .from('cities')
  .select('name', \{ count: 'exact' \}) // if you don't want to return any rows, you can use \{ count: 'exact', head: true \}

Querying JSON data

const \{ data, error \} = await supabase
  .from('users')
  .select(`
    id, name,
    address->street
  `)
  .eq('address->postcode', 90210)

Return data as CSV

const \{ data, error \} = await supabase
  .from('users')
  .select()
  .csv()

Aborting requests in-flight

const ac = new AbortController()
supabase
  .from('very_big_table')
  .select()
  .abortSignal(ac.signal)
  .then(console.log)
ac.abort()
// \{
//   error: \{
//     message: 'FetchError: The user aborted a request.',
//     details: '',
//     hint: '',
//     code: ''
//   \},
//   data: null,
//   body: null,
//   count: null,
//   status: 400,
//   statusText: 'Bad Request'
// \}