Skip to content

Commit

Permalink
update site examples
Browse files Browse the repository at this point in the history
  • Loading branch information
koskimas committed Jun 8, 2023
1 parent 7ea9f31 commit e552c00
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 28 deletions.
18 changes: 0 additions & 18 deletions site/docs/examples/SELECT/0020-a-single-colum-with-table.mdx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const aSingleColumWithTable = `const persons = await db
export const columnWithATable = `const persons = await db
.selectFrom(['person', 'pet'])
.select('person.id')
.execute()`
18 changes: 18 additions & 0 deletions site/docs/examples/SELECT/0020-column-with-a-table.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: 'Column with a table'
---

# Column with a table

Select a single column and specify a table:

import {
Playground,
exampleSetup,
} from '../../../src/components/Playground'

import {
columnWithATable
} from './0020-column-with-a-table'

<Playground code={columnWithATable} setupCode={exampleSetup} />
2 changes: 1 addition & 1 deletion site/docs/examples/SELECT/0040-aliases.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: 'Aliases'

# Aliases

Aliased selections:
You can provide an alias for the selections by appending `as the_alias` to the selection.

import {
Playground,
Expand Down
2 changes: 1 addition & 1 deletion site/docs/examples/SELECT/0050-complex-selections.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: 'Complex selections'

# Complex selections

You can also select arbitrary expression including subqueries and raw sql snippets.
You can select arbitrary expression including subqueries and raw sql snippets.
When you do that, you need to give a name for the selections using the `as` method:

import {
Expand Down
4 changes: 4 additions & 0 deletions site/docs/examples/SELECT/0090-all-columns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const allColumns = `const persons = await db
.selectFrom('person')
.selectAll()
.execute()`
18 changes: 18 additions & 0 deletions site/docs/examples/SELECT/0090-all-columns.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: 'All columns'
---

# All columns

The `selectAll` method generates `SELECT *`:

import {
Playground,
exampleSetup,
} from '../../../src/components/Playground'

import {
allColumns
} from './0090-all-columns'

<Playground code={allColumns} setupCode={exampleSetup} />
4 changes: 4 additions & 0 deletions site/docs/examples/SELECT/0100-all-columns-of-a-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const allColumnsOfATable = `const persons = await db
.selectFrom('person')
.selectAll('person')
.execute()`
18 changes: 18 additions & 0 deletions site/docs/examples/SELECT/0100-all-columns-of-a-table.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: 'All columns of a table'
---

# All columns of a table

Select all columns of a table:

import {
Playground,
exampleSetup,
} from '../../../src/components/Playground'

import {
allColumnsOfATable
} from './0100-all-columns-of-a-table'

<Playground code={allColumnsOfATable} setupCode={exampleSetup} />
14 changes: 14 additions & 0 deletions site/docs/examples/WHERE/0030-or-where.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const orWhere = `const persons = await db
.selectFrom('person')
.selectAll()
.where(({ or, and, cmpr }) => or([
and([
cmpr('first_name', '=', 'Jennifer'),
cmpr('last_name', '=', 'Aniston')
]),
and([
cmpr('first_name', '=', 'Sylvester'),
cmpr('last_name', '=', 'Stallone')
])
]))
.execute()`
18 changes: 18 additions & 0 deletions site/docs/examples/WHERE/0030-or-where.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: 'OR where'
---

# OR where

To combine conditions using `OR`, you can use the expression builder:

import {
Playground,
exampleSetup,
} from '../../../src/components/Playground'

import {
orWhere
} from './0030-or-where'

<Playground code={orWhere} setupCode={exampleSetup} />
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ import {

import {
conditionalWhereCalls
} from './0030-conditional-where-calls'
} from './0040-conditional-where-calls'

<Playground code={conditionalWhereCalls} setupCode={exampleSetup} />
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ import {

import {
complexWhereClause
} from './0040-complex-where-clause'
} from './0050-complex-where-clause'

<Playground code={complexWhereClause} setupCode={exampleSetup} />
12 changes: 9 additions & 3 deletions src/query-builder/select-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export class SelectQueryBuilder<DB, TB extends keyof DB, O>
* select "id" from "person" where "first_name" = $1
* ```
*
* <!-- siteExample("select", "A single colum with table", 20) -->
* <!-- siteExample("select", "Column with a table", 20) -->
*
* Select a single column and specify a table:
*
Expand Down Expand Up @@ -410,7 +410,7 @@ export class SelectQueryBuilder<DB, TB extends keyof DB, O>
*
* <!-- siteExample("select", "Aliases", 40) -->
*
* Aliased selections:
* You can provide an alias for the selections by appending `as the_alias` to the selection.
*
* ```ts
* const persons = await db
Expand All @@ -433,7 +433,7 @@ export class SelectQueryBuilder<DB, TB extends keyof DB, O>
*
* <!-- siteExample("select", "Complex selections", 50) -->
*
* You can also select arbitrary expression including subqueries and raw sql snippets.
* You can select arbitrary expression including subqueries and raw sql snippets.
* When you do that, you need to give a name for the selections using the `as` method:
*
* ```ts
Expand Down Expand Up @@ -748,6 +748,10 @@ export class SelectQueryBuilder<DB, TB extends keyof DB, O>
*
* ### Examples
*
* <!-- siteExample("select", "All columns", 90) -->
*
* The `selectAll` method generates `SELECT *`:
*
* ```ts
* const persons = await db
* .selectFrom('person')
Expand All @@ -761,6 +765,8 @@ export class SelectQueryBuilder<DB, TB extends keyof DB, O>
* select * from "person"
* ```
*
* <!-- siteExample("select", "All columns of a table", 100) -->
*
* Select all columns of a table:
*
* ```ts
Expand Down
37 changes: 35 additions & 2 deletions src/query-builder/where-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,40 @@ export interface WhereInterface<DB, TB extends keyof DB> {
* select * from "person" where "id" in ($1, $2, $3)
* ```
*
* <!-- siteExample("where", "Conditional where calls", 30) -->
* <!-- siteExample("where", "OR where", 30) -->
*
* To combine conditions using `OR`, you can use the expression builder:
*
* ```ts
* const persons = await db
* .selectFrom('person')
* .selectAll()
* .where(({ or, and, cmpr }) => or([
* and([
* cmpr('first_name', '=', 'Jennifer'),
* cmpr('last_name', '=', 'Aniston')
* ]),
* and([
* cmpr('first_name', '=', 'Sylvester'),
* cmpr('last_name', '=', 'Stallone')
* ])
* ]))
* .execute()
* ```
*
* The generated SQL (PostgreSQL):
*
* ```sql
* select *
* from "person"
* where (
* ("first_name" = $1 AND "last_name" = $2)
* OR
* ("first_name" = $3 AND "last_name" = $4)
* )
* ```
*
* <!-- siteExample("where", "Conditional where calls", 40) -->
*
* You can add expressions conditionally like this:
*
Expand Down Expand Up @@ -137,7 +170,7 @@ export interface WhereInterface<DB, TB extends keyof DB> {
* select * from "person" where "id" in ($1, $2, $3)
* ```
*
* <!-- siteExample("where", "Complex where clause", 40) -->
* <!-- siteExample("where", "Complex where clause", 50) -->
*
* For complex `where` expressions you can pass in a single callback and
* use the `ExpressionBuilder` to build your expression:
Expand Down

0 comments on commit e552c00

Please sign in to comment.