LogoLogo
12.1.0
12.1.0
  • Introduction
  • What's New?
  • Installation & Usage
  • Migration Guide
  • Contributing & Filing Issues
  • Query Builder
    • Getting a New Query
    • Building Queries
      • Selects
      • From
      • For
      • Joins
      • Wheres
      • Order By
      • Group By and Having
      • Limit, Offset, and Pagination
      • Locks
      • Unions
      • Common Table Expressions (i.e. CTEs)
      • Raw Expressions
      • When / Conditionals
      • Query Parameters and Bindings
    • Executing Queries
      • Retrieving Results
      • Aggregates
      • Inserts, Updates, and Deletes
    • Options and Utilities
      • Query Options and Utilities
      • Clone and Reset
      • Return Format
      • Column Formatter
      • Interception Points
    • Debugging
      • sqlCommenter
  • Schema Builder
    • Overview
    • Creating Tables and Views
    • Columns
    • Column Modifiers
    • Column Constraints
    • Creating Table Constraints
    • Altering Tables and Views
    • Dropping Tables and Views
    • Debugging
  • External Links
    • API Docs
    • Source Code
    • Issue Tracker
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
Export as PDF
  1. Query Builder
  2. Building Queries

For

This section only applies to SQL Server Grammars.

In SQL Server, FOR clauses are how you can return JSON or XML directly from your query.

In qb, only raw expressions are accepted via the forRaw method.

forRaw

Name
Type
Required
Default
Description

expression

string

true

The raw sql for the FOR clause.

QueryBuilder
query
    .select( [ "id", "name" ] )
    .from( "users" )
    .forRaw( "JSON AUTO" );
SQL Server
SELECT [id], [name]
FROM [users]
FOR JSON AUTO

PreviousFromNextJoins

Was this helpful?