Skip to content

Commit

Permalink
generic cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
koskimas committed Jan 7, 2022
1 parent bab8d5b commit 2d420ed
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/dialect/database-introspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ColumnDataType } from '../operation-node/data-type-node.js'
*/
export interface DatabaseIntrospector {
/**
* Get the database metadata such as the names of the tables and columns.
* Get the database metadata such as table and column names.
*/
getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>
}
Expand Down
2 changes: 1 addition & 1 deletion src/dialect/dialect-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface DialectAdapter {

/**
* This method is used to acquire a lock for the migrations so that
* it's not possible for two migration processes to run in parallel.
* it's not possible for two migration operations to run in parallel.
*
* Most dialects have explicit locks that can be used, like advisory locks
* in PostgreSQL and the get_lock function in MySQL.
Expand Down
4 changes: 2 additions & 2 deletions src/dialect/dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export interface Dialect {
createAdapter(): DialectAdapter

/**
* Creates a database introspector that can be used to get the database metadata
* such as the tables and columns that exist in the database.
* Creates a database introspector that can be used to get database metadata
* such as the table names and column names of those tables.
*
* `db` never has any plugins installed. It's created using
* {@link Kysely.withoutPlugins}.
Expand Down
10 changes: 6 additions & 4 deletions src/kysely.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ export class Kysely<DB> extends QueryCreator<DB> {
constructor(args: KyselyConfig)
constructor(args: KyselyProps)
constructor(args: KyselyConfig | KyselyProps) {
let superProps: QueryCreatorProps;
let props: KyselyProps;
let superProps: QueryCreatorProps
let props: KyselyProps

if (isKyselyProps(args)) {
superProps = { executor: args.executor, parseContext: args.parseContext }
props = { ...args }
Expand Down Expand Up @@ -102,8 +103,9 @@ export class Kysely<DB> extends QueryCreator<DB> {
parseContext,
}
}
super(superProps);
this.#props = freeze(props);

super(superProps)
this.#props = freeze(props)
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/parser/join-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { AnyColumn, AnyColumnWithTable } from '../util/type-utils.js'
import {
TableExpression,
parseTableExpression,
ExtractAliasFromTableExpression,
TableExpressionDatabase,
TableExpressionTables,
} from './table-parser.js'
import { parseReferenceFilter } from './filter-parser.js'
import { JoinBuilder } from '../query-builder/join-builder.js'
Expand All @@ -17,18 +17,18 @@ export type JoinReferenceExpression<DB, TB extends keyof DB, TE> =
export type JoinCallbackExpression<DB, TB extends keyof DB, TE> = (
join: JoinBuilder<
TableExpressionDatabase<DB, TE>,
TB | ExtractAliasFromTableExpression<DB, TE>
TableExpressionTables<DB, TB, TE>
>
) => JoinBuilder<any, any>

type AnyJoinColumn<DB, TB extends keyof DB, TE> = AnyColumn<
TableExpressionDatabase<DB, TE>,
TB | ExtractAliasFromTableExpression<DB, TE>
TableExpressionTables<DB, TB, TE>
>

type AnyJoinColumnWithTable<DB, TB extends keyof DB, TE> = AnyColumnWithTable<
TableExpressionDatabase<DB, TE>,
TB | ExtractAliasFromTableExpression<DB, TE>
TableExpressionTables<DB, TB, TE>
>

export function parseJoin(
Expand Down
6 changes: 3 additions & 3 deletions src/query-builder/join-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ export interface JoinInterface<DB, TB extends keyof DB> {
* and "pet"."name" = $1
* ```
*
* You can join a subquery by providing a function as the first
* argument:
* You can join a subquery by providing a select query (or a callback)
* as the first argument:
*
* ```ts
* await db.selectFrom('person')
* .innerJoin(
* (qb) => qb.selectFrom('pet')
* qb.selectFrom('pet')
* .select(['owner_id', 'name'])
* .where('name', '=', 'Doggo')
* .as('doggos'),
Expand Down
41 changes: 21 additions & 20 deletions test/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ async function testConditionalJoinWhere(db: Kysely<Database>) {
async function testJoin(db: Kysely<Database>) {
const r1 = await db
.selectFrom('person')
.innerJoin('movie', 'movie.id', 'person.id')
.innerJoin('pet', 'pet.owner_id', 'person.id')
.selectAll()
.execute()

Expand All @@ -444,47 +444,48 @@ async function testJoin(db: Kysely<Database>) {
gender: 'male' | 'female' | 'other'
modified_at: Date

stars: number
name: string
species: 'cat' | 'dog'
owner_id: number
}[]
>(r1)

const r2 = await db
.selectFrom('person')
.innerJoin('movie as m', (join) => join.onRef('m.id', '=', 'person.id'))
.where('m.stars', '>', 2)
.selectAll('m')
.innerJoin('pet as p', (join) => join.onRef('p.owner_id', '=', 'person.id'))
.where('p.species', 'in', ['cat'])
.selectAll('p')
.execute()

expectType<{ id: string; stars: number }[]>(r2)
expectType<Selectable<Pet>[]>(r2)
expectType<
{ id: string; name: string; species: 'cat' | 'dog'; owner_id: number }[]
>(r2)

const r3 = await db
.selectFrom('person')
.innerJoin(
(qb) =>
qb
.selectFrom('movie')
.select(['movie.id', 'movie.stars as rating'])
.as('m'),
'm.id',
db.selectFrom('pet').select(['pet.id', 'pet.owner_id as owner']).as('p'),
'p.owner',
'person.id'
)
.where('m.rating', '>', 2)
.selectAll('m')
.where('p.owner', '>', 2)
.selectAll('p')
.execute()

expectType<{ id: string; rating: number }[]>(r3)
expectType<{ id: string; owner: number }[]>(r3)

const r4 = await db
.selectFrom('person')
.innerJoin(
(qb) => qb.selectFrom('movie').selectAll('movie').as('m'),
(join) => join.onRef('m.id', '=', 'person.id')
(qb) => qb.selectFrom('pet').selectAll('pet').as('p'),
(join) => join.onRef('p.owner_id', '=', 'person.id')
)
.where('m.stars', '>', 2)
.selectAll('m')
.where('p.owner_id', '>', 2)
.selectAll('p')
.execute()

expectType<{ id: string; stars: number }[]>(r4)
expectType<Selectable<Pet>[]>(r4)

const r5 = await db
.selectFrom('person')
Expand Down

0 comments on commit 2d420ed

Please sign in to comment.