LogoLogo
6.4.0
6.4.0
  • Introduction
  • What's New?
  • Installation & Usage
  • Migration Guide
  • Contributing & Filing Issues
  • Contributors
  • Query Builder
    • Return Format
    • Interception Points
    • Retrieving Results
    • Aggregates
    • Selects
    • From
    • Joins
    • Where Clauses
    • Conditionals
    • Ordering, Grouping & Limit
    • Unions
    • Common Table Expressions (i.e. CTEs)
    • Inserts
    • Updates
    • Deletes
    • New Query
    • Clone
  • Schema Builder
    • Overview
    • Create
    • Columns
    • Column Modifiers
    • Column Constraints
    • Creating Table Constraints
    • Alter
    • Drop
Powered by GitBook
On this page

Was this helpful?

Edit on Git
Export as PDF
  1. Query Builder

New Query

A query builder is a stateful, transient object. That means that if you want to execute two different queries, you need two separate instances of QueryBuilder.

// This will cause you pain and grief...

var user = query.from( "users" )
  .where( "username", rc.username )
  .first();

var posts = query.from( "posts" ).get();
// This will error because `username` is not a column in `posts`.

An easy way to get a new query builder is to use the newQuery method available on the builder.

// This will cause you pain and grief...

var user = query.from( "users" )
  .where( "username", rc.username )
  .first();

var posts = query.newQuery().from( "posts" ).get();
// This will work as we expect it to.

The newQuery method will keep the current grammar, return format, and utils attached to the called query builder.

PreviousDeletesNextClone

Last updated 6 years ago

Was this helpful?