On this page

Querying

Read rows from tables and views with GET requests or the SDK.

#Select all columns

const { data, error } = await stitchdb.from('todos').select('*')

#Select some columns

const { data } = await stitchdb.from('todos').select('id, task')

Fetch related rows through foreign keys by naming the related table in select. Rename with alias:column, and add !inner to keep only rows that have a match:

const { data } = await stitchdb.from('todos').select('id, task, owner:profiles(username)')
const { data: mine } = await stitchdb.from('todos').select('id, profiles!inner(username)').eq('profiles.username', 'ada')

#One row

JavaScript
const { data } = await stitchdb.from('todos').select('*').eq('id', 1).single()      // error unless exactly one row
const { data: maybe } = await stitchdb.from('todos').select('*').eq('id', 1).maybeSingle() // null when none

#Count rows

const { count } = await stitchdb.from('todos').select('*', { count: 'exact', head: true })

count: 'planned' or 'estimated' are faster on large tables.

#Other formats

JavaScript
const { data: csv } = await stitchdb.from('todos').select('*').csv()
const { data: plan } = await stitchdb.from('todos').select('*').explain()

Each response returns at most your plan's rows per API request; page through larger results (see Filtering and pagination).