Outerbase SDK
  • Outerbase SDK
  • Get Started
    • Overview
    • Playground
  • Introspection
    • Overview
    • Universal data language
    • Connect a data source
    • Generate models
      • Limit table scope
    • Remote queries
  • Query Builder
    • Overview
    • Select
      • Single table
      • Multiple tables
      • Where clauses
      • Join tables
      • Limit & Offset
      • Order By
    • Insert
    • Update
    • Delete
    • Returning
    • Operators
    • .toString()
    • .asClass()
    • .query()
    • .queryRaw()
  • Data Sources
    • Overview
    • Outerbase
    • Cloudflare D1
    • Neon
Powered by GitBook
On this page
  • Basic query
  • Schema
  • Specifying columns
  • Requesting all columns
  1. Query Builder
  2. Select

Single table

Fetching data from your database via the query builder has a lot of similarities to writing plain SQL.

Basic query

To get data from a single table in the most simple way you can just call for the specified columns from a table using the selectFrom function chain, followed by the .query() to execute the network call.

const { data, error } = await db
    .selectFrom([
        {
            table: 'table_name',
            columns: ['column_name']
        }
    ])
    .query()

Schema

For more complex database structures you may need to specify the schema of the table you're trying to reference if it's not in the public schema.

NOTE: If the table is in the public schema, or the database does not support schemas then the schema field is not required.

const { data, error } = await db
    .selectFrom([
        {
            schema: 'custom_schema',
            table: 'table_name',
            columns: ['column_name'],
        }
    ])
    .query()

Specifying columns

To request specific columns, just specify them in an array for each particular table you're accessing.

const { data, error } = await db
    .selectFrom([
        {
            schema: 'custom_schema',
            table: 'table_name',
            columns: ['id', 'first_name', 'last_name'],
        }
    ])
    .query()

Requesting all columns

Similar to SQL, if you want to request all columns from a table you can use the * character to indicate all columns.

const { data, error } = await db
    .selectFrom([
        {
            schema: 'custom_schema',
            table: 'table_name',
            columns: ['*'],
        }
    ])
    .query()
PreviousSelectNextMultiple tables

Last updated 11 months ago