Skip to content

Commit

Permalink
fix a bunch of untyped sql snippets in API doc examples
Browse files Browse the repository at this point in the history
  • Loading branch information
koskimas committed Mar 23, 2024
1 parent 58ba4ae commit 64a56f9
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/expression/expression-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 404,7 @@ export interface ExpressionBuilder<DB, TB extends keyof DB> {
*
* ```ts
* db.update('pet').set((eb) => ({
* name: sql`concat(${eb.ref('pet.name')}, ${suffix})`
* name: sql<string>`concat(${eb.ref('pet.name')}, ${suffix})`
* }))
* ```
*
Expand Down
2 changes: 1 addition & 1 deletion src/query-builder/function-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 124,7 @@ export interface FunctionModule<DB, TB extends keyof DB> {
* ```ts
* db.selectFrom('person')
* .selectAll('person')
* .where(sql`upper(first_name)`, '=', 'JENNIFER')
* .where(sql<string>`upper(first_name)`, '=', 'JENNIFER')
* ```
*/
<O, RE extends ReferenceExpression<DB, TB> = ReferenceExpression<DB, TB>>(
Expand Down
4 changes: 2 additions & 2 deletions src/query-builder/insert-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 193,7 @@ export class InsertQueryBuilder<DB, TB extends keyof DB, O>
* .insertInto('person')
* .values(({ ref, selectFrom, fn }) => ({
* first_name: 'Jennifer',
* last_name: sql`concat(${ani}, ${ston})`,
* last_name: sql<string>`>concat(${ani}, ${ston})`,
* middle_name: ref('first_name'),
* age: selectFrom('person')
* .select(fn.avg<number>('age').as('avg_age')),
Expand Down Expand Up @@ -496,7 496,7 @@ export class InsertQueryBuilder<DB, TB extends keyof DB, O>
* species: 'cat',
* })
* .onConflict((oc) => oc
* .expression(sql`lower(name)`)
* .expression(sql<string>`lower(name)`)
* .doUpdateSet({ species: 'hamster' })
* )
* .execute()
Expand Down
10 changes: 5 additions & 5 deletions src/query-builder/select-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 912,7 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O>
* .limit(1)
* )
* .orderBy(
* sql`concat(first_name, last_name)`
* sql<string>`concat(first_name, last_name)`
* )
* .execute()
* ```
Expand Down Expand Up @@ -981,7 981,7 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O>
* .selectFrom('person')
* .select([
* 'first_name',
* sql`max(id)`.as('max_id')
* sql<string>`max(id)`.as('max_id')
* ])
* .groupBy('first_name')
* .execute()
Expand All @@ -1005,7 1005,7 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O>
* .select([
* 'first_name',
* 'last_name',
* sql`max(id)`.as('max_id')
* sql<string>`max(id)`.as('max_id')
* ])
* .groupBy([
* 'first_name',
Expand Down Expand Up @@ -1033,10 1033,10 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O>
* .select([
* 'first_name',
* 'last_name',
* sql`max(id)`.as('max_id')
* sql<string>`max(id)`.as('max_id')
* ])
* .groupBy([
* sql`concat(first_name, last_name)`,
* sql<string>`concat(first_name, last_name)`,
* (qb) => qb.selectFrom('pet').select('id').limit(1)
* ])
* .execute()
Expand Down
4 changes: 2 additions & 2 deletions src/query-builder/update-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 561,7 @@ export class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyof DB, O>
* .set('first_name', 'Foo')
* // As always, both arguments can be arbitrary expressions or
* // callbacks that give you access to an expression builder:
* .set(sql`address['postalCode']`, (eb) => eb.val('61710))
* .set(sql<string>`address['postalCode']`, (eb) => eb.val('61710))
* .where('id', '=', '1')
* .executeTakeFirst()
* ```
Expand Down Expand Up @@ -602,7 602,7 @@ export class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyof DB, O>
* first_name: selectFrom('person').select('first_name').limit(1),
* middle_name: ref('first_name'),
* age: eb('age', ' ', 1),
* last_name: sql`${'Ani'} || ${'ston'}`,
* last_name: sql<string>`${'Ani'} || ${'ston'}`,
* }))
* .where('id', '=', 1)
* .executeTakeFirst()
Expand Down
2 changes: 1 addition & 1 deletion src/query-builder/where-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 270,7 @@ export interface WhereInterface<DB, TB extends keyof DB> {
* .selectFrom('person')
* .selectAll()
* .where(
* sql`coalesce(first_name, last_name)`,
* sql<string>`coalesce(first_name, last_name)`,
* 'like',
* '%' name '%',
* )
Expand Down
10 changes: 5 additions & 5 deletions src/raw-builder/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 43,12 @@ export interface Sql {
* // method to give it an alias.
* sql<string>`concat(first_name, ' ', last_name)`.as('full_name')
* )
* .where(sql`birthdate between ${date1} and ${date2}`)
* .where(sql<boolean>`birthdate between ${date1} and ${date2}`)
* // Here we assume we have list of nicknames for the person
* // (a list of strings) and we use the PostgreSQL `@>` operator
* // to test if all of them are valid nicknames for the user.
* .where('nicknames', '@>', sql`ARRAY[${sql.join(nicknames)}]`)
* .orderBy(sql`concat(first_name, ' ', last_name)`)
* .where('nicknames', '@>', sql<string[]>`ARRAY[${sql.join(nicknames)}]`)
* .orderBy(sql<string>`concat(first_name, ' ', last_name)`)
* .execute()
* ```
*
Expand All @@ -73,7 73,7 @@ export interface Sql {
*
* ```ts
* const petName = db.selectFrom('pet').select('name').limit(1)
* const fullName = sql`concat(first_name, ' ', last_name)`
* const fullName = sql<string>`concat(first_name, ' ', last_name)`
*
* sql`
* select ${fullName} as full_name, ${petName} as pet_name
Expand Down Expand Up @@ -323,7 323,7 @@ export interface Sql {
* return db
* .selectFrom('person')
* .selectAll()
* .where('nicknames', '@>', sql`ARRAY[${sql.join(nicknames)}]`)
* .where('nicknames', '@>', sql<string[]>`ARRAY[${sql.join(nicknames)}]`)
* .execute()
* }
* ```
Expand Down
2 changes: 1 addition & 1 deletion src/schema/alter-table-add-index-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 121,7 @@ export class AlterTableAddIndexBuilder
* await db.schema
* .alterTable('person')
* .addIndex('person_first_name_index')
* .expression(sql`(first_name < 'Sami')`)
* .expression(sql<boolean>`(first_name < 'Sami')`)
* .execute()
* ```
*
Expand Down

0 comments on commit 64a56f9

Please sign in to comment.