Skip to content

Commit

Permalink
Remove preventAwait (#1160)
Browse files Browse the repository at this point in the history
Related #748
  • Loading branch information
wirekang authored and igalklebanov committed Oct 3, 2024
1 parent 650ce08 commit a84367a
Show file tree
Hide file tree
Showing 38 changed files with 28 additions and 257 deletions.
11 changes: 0 additions & 11 deletions src/kysely.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
TransactionSettings,
TRANSACTION_ISOLATION_LEVELS,
} from './driver/driver.js'
import { preventAwait } from './util/prevent-await.js'
import {
createFunctionModule,
FunctionModule,
Expand Down Expand Up @@ -526,11 +525,6 @@ export class ConnectionBuilder<DB> {

interface ConnectionBuilderProps extends KyselyProps {}

preventAwait(
ConnectionBuilder,
"don't await ConnectionBuilder instances directly. To execute the query you need to call the `execute` method",
)

export class TransactionBuilder<DB> {
readonly #props: TransactionBuilderProps

Expand Down Expand Up @@ -579,11 +573,6 @@ interface TransactionBuilderProps extends KyselyProps {
readonly isolationLevel?: IsolationLevel
}

preventAwait(
TransactionBuilder,
"don't await TransactionBuilder instances directly. To execute the transaction you need to call the `execute` method",
)

function validateTransactionSettings(settings: TransactionSettings): void {
if (
settings.isolationLevel &&
Expand Down
7 changes: 5 additions & 2 deletions src/operation-node/operation-node-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ export class OperationNodeTransformer {
DropConstraintNode: this.transformDropConstraint.bind(this),
ForeignKeyConstraintNode: this.transformForeignKeyConstraint.bind(this),
CreateViewNode: this.transformCreateView.bind(this),
RefreshMaterializedViewNode: this.transformRefreshMaterializedView.bind(this),
RefreshMaterializedViewNode:
this.transformRefreshMaterializedView.bind(this),
DropViewNode: this.transformDropView.bind(this),
GeneratedNode: this.transformGenerated.bind(this),
DefaultValueNode: this.transformDefaultValue.bind(this),
Expand Down Expand Up @@ -798,7 +799,9 @@ export class OperationNodeTransformer {
})
}

protected transformRefreshMaterializedView(node: RefreshMaterializedViewNode): RefreshMaterializedViewNode {
protected transformRefreshMaterializedView(
node: RefreshMaterializedViewNode,
): RefreshMaterializedViewNode {
return requireAllProps<RefreshMaterializedViewNode>({
kind: 'RefreshMaterializedViewNode',
name: this.transformNode(node.name),
Expand Down
4 changes: 3 additions & 1 deletion src/operation-node/operation-node-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ export abstract class OperationNodeVisitor {
protected abstract visitPrimitiveValueList(node: PrimitiveValueListNode): void
protected abstract visitOperator(node: OperatorNode): void
protected abstract visitCreateView(node: CreateViewNode): void
protected abstract visitRefreshMaterializedView(node: RefreshMaterializedViewNode): void
protected abstract visitRefreshMaterializedView(
node: RefreshMaterializedViewNode,
): void
protected abstract visitDropView(node: DropViewNode): void
protected abstract visitGenerated(node: GeneratedNode): void
protected abstract visitDefaultValue(node: DefaultValueNode): void
Expand Down
6 changes: 0 additions & 6 deletions src/query-builder/aggregate-function-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { freeze } from '../util/object-utils.js'
import { AggregateFunctionNode } from '../operation-node/aggregate-function-node.js'
import { AliasNode } from '../operation-node/alias-node.js'
import { IdentifierNode } from '../operation-node/identifier-node.js'
import { preventAwait } from '../util/prevent-await.js'
import { OverBuilder } from './over-builder.js'
import { createOverBuilder } from '../parser/parse-utils.js'
import {
Expand Down Expand Up @@ -344,11 +343,6 @@ export class AggregateFunctionBuilder<DB, TB extends keyof DB, O = unknown>
}
}

preventAwait(
AggregateFunctionBuilder,
"don't await AggregateFunctionBuilder instances. They are never executed directly and are always just a part of a query.",
)

/**
* {@link AggregateFunctionBuilder} with an alias. The result of calling {@link AggregateFunctionBuilder.as}.
*/
Expand Down
6 changes: 0 additions & 6 deletions src/query-builder/cte-builder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { OperationNodeSource } from '../operation-node/operation-node-source.js'
import { CommonTableExpressionNode } from '../operation-node/common-table-expression-node.js'
import { preventAwait } from '../util/prevent-await.js'
import { freeze } from '../util/object-utils.js'

export class CTEBuilder<N extends string> implements OperationNodeSource {
Expand Down Expand Up @@ -39,11 +38,6 @@ export class CTEBuilder<N extends string> implements OperationNodeSource {
}
}

preventAwait(
CTEBuilder,
"don't await CTEBuilder instances. They are never executed directly and are always just a part of a query.",
)

interface CTEBuilderProps {
readonly node: CommonTableExpressionNode
}
Expand Down
6 changes: 0 additions & 6 deletions src/query-builder/delete-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
SimplifySingleResult,
SqlBool,
} from '../util/type-utils.js'
import { preventAwait } from '../util/prevent-await.js'
import { Compilable } from '../util/compilable.js'
import { QueryExecutor } from '../query-executor/query-executor.js'
import { QueryId } from '../util/query-id.js'
Expand Down Expand Up @@ -1153,11 +1152,6 @@ export class DeleteQueryBuilder<DB, TB extends keyof DB, O>
}
}

preventAwait(
DeleteQueryBuilder,
"don't await DeleteQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.",
)

export interface DeleteQueryBuilderProps {
readonly queryId: QueryId
readonly queryNode: DeleteQueryNode
Expand Down
6 changes: 0 additions & 6 deletions src/query-builder/insert-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
UpdateObjectExpression,
parseUpdateObjectExpression,
} from '../parser/update-set-parser.js'
import { preventAwait } from '../util/prevent-await.js'
import { Compilable } from '../util/compilable.js'
import { QueryExecutor } from '../query-executor/query-executor.js'
import { QueryId } from '../util/query-id.js'
Expand Down Expand Up @@ -1076,11 +1075,6 @@ export class InsertQueryBuilder<DB, TB extends keyof DB, O>
}
}

preventAwait(
InsertQueryBuilder,
"don't await InsertQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.",
)

export interface InsertQueryBuilderProps {
readonly queryId: QueryId
readonly queryNode: InsertQueryNode
Expand Down
6 changes: 0 additions & 6 deletions src/query-builder/join-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { ExpressionOrFactory } from '../parser/expression-parser.js'
import { ReferenceExpression } from '../parser/reference-parser.js'
import { freeze } from '../util/object-utils.js'
import { preventAwait } from '../util/prevent-await.js'
import { SqlBool } from '../util/type-utils.js'

export class JoinBuilder<DB, TB extends keyof DB>
Expand Down Expand Up @@ -92,11 +91,6 @@ export class JoinBuilder<DB, TB extends keyof DB>
}
}

preventAwait(
JoinBuilder,
"don't await JoinBuilder instances. They are never executed directly and are always just a part of a query.",
)

export interface JoinBuilderProps {
readonly joinNode: JoinNode
}
21 changes: 0 additions & 21 deletions src/query-builder/merge-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { NOOP_QUERY_EXECUTOR } from '../query-executor/noop-query-executor.js'
import { QueryExecutor } from '../query-executor/query-executor.js'
import { Compilable } from '../util/compilable.js'
import { freeze } from '../util/object-utils.js'
import { preventAwait } from '../util/prevent-await.js'
import { QueryId } from '../util/query-id.js'
import {
ShallowRecord,
Expand Down Expand Up @@ -262,11 +261,6 @@ export class MergeQueryBuilder<DB, TT extends keyof DB, O>
}
}

preventAwait(
MergeQueryBuilder,
"don't await MergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.",
)

export interface MergeQueryBuilderProps {
readonly queryId: QueryId
readonly queryNode: MergeQueryNode
Expand Down Expand Up @@ -833,11 +827,6 @@ export class WheneableMergeQueryBuilder<
}
}

preventAwait(
WheneableMergeQueryBuilder,
"don't await WheneableMergeQueryBuilder instances directly. To execute the query you need to call `execute`.",
)

export class MatchedThenableMergeQueryBuilder<
DB,
TT extends keyof DB,
Expand Down Expand Up @@ -1034,11 +1023,6 @@ export class MatchedThenableMergeQueryBuilder<
}
}

preventAwait(
MatchedThenableMergeQueryBuilder,
"don't await MatchedThenableMergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.",
)

export class NotMatchedThenableMergeQueryBuilder<
DB,
TT extends keyof DB,
Expand Down Expand Up @@ -1145,11 +1129,6 @@ export class NotMatchedThenableMergeQueryBuilder<
}
}

preventAwait(
NotMatchedThenableMergeQueryBuilder,
"don't await NotMatchedThenableMergeQueryBuilder instances directly. To execute the query you need to call `execute` when available.",
)

export type ExtractWheneableMergeQueryBuilder<
DB,
TT extends keyof DB,
Expand Down
13 changes: 0 additions & 13 deletions src/query-builder/on-conflict-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
} from '../parser/update-set-parser.js'
import { Updateable } from '../util/column-type.js'
import { freeze } from '../util/object-utils.js'
import { preventAwait } from '../util/prevent-await.js'
import { AnyColumn, SqlBool } from '../util/type-utils.js'
import { WhereInterface } from './where-interface.js'

Expand Down Expand Up @@ -251,8 +250,6 @@ export interface OnConflictBuilderProps {
readonly onConflictNode: OnConflictNode
}

preventAwait(OnConflictBuilder, "don't await OnConflictBuilder instances.")

export type OnConflictDatabase<DB, TB extends keyof DB> = {
[K in keyof DB | 'excluded']: Updateable<K extends keyof DB ? DB[K] : DB[TB]>
}
Expand All @@ -273,11 +270,6 @@ export class OnConflictDoNothingBuilder<DB, TB extends keyof DB>
}
}

preventAwait(
OnConflictDoNothingBuilder,
"don't await OnConflictDoNothingBuilder instances.",
)

export class OnConflictUpdateBuilder<DB, TB extends keyof DB>
implements WhereInterface<DB, TB>, OperationNodeSource
{
Expand Down Expand Up @@ -358,8 +350,3 @@ export class OnConflictUpdateBuilder<DB, TB extends keyof DB>
return this.#props.onConflictNode
}
}

preventAwait(
OnConflictUpdateBuilder,
"don't await OnConflictUpdateBuilder instances.",
)
6 changes: 0 additions & 6 deletions src/query-builder/over-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
} from '../parser/partition-by-parser.js'
import { StringReference } from '../parser/reference-parser.js'
import { freeze } from '../util/object-utils.js'
import { preventAwait } from '../util/prevent-await.js'

export class OverBuilder<DB, TB extends keyof DB>
implements OperationNodeSource
Expand Down Expand Up @@ -107,11 +106,6 @@ export class OverBuilder<DB, TB extends keyof DB>
}
}

preventAwait(
OverBuilder,
"don't await OverBuilder instances. They are never executed directly and are always just a part of a query.",
)

export interface OverBuilderProps {
readonly overNode: OverNode
}
11 changes: 0 additions & 11 deletions src/query-builder/select-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import {
UndirectedOrderByExpression,
parseOrderBy,
} from '../parser/order-by-parser.js'
import { preventAwait } from '../util/prevent-await.js'
import { LimitNode } from '../operation-node/limit-node.js'
import { OffsetNode } from '../operation-node/offset-node.js'
import { Compilable } from '../util/compilable.js'
Expand Down Expand Up @@ -2487,11 +2486,6 @@ class SelectQueryBuilderImpl<DB, TB extends keyof DB, O>
}
}

preventAwait(
SelectQueryBuilderImpl,
"don't await SelectQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.",
)

export function createSelectQueryBuilder<DB, TB extends keyof DB, O>(
props: SelectQueryBuilderProps,
): SelectQueryBuilder<DB, TB, O> {
Expand Down Expand Up @@ -2549,11 +2543,6 @@ class AliasedSelectQueryBuilderImpl<
}
}

preventAwait(
AliasedSelectQueryBuilderImpl,
"don't await AliasedSelectQueryBuilder instances directly. AliasedSelectQueryBuilder should never be executed directly since it's always a part of another query.",
)

export type SelectQueryBuilderWithInnerJoin<
DB,
TB extends keyof DB,
Expand Down
6 changes: 0 additions & 6 deletions src/query-builder/update-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import {
ExtractUpdateTypeFromReferenceExpression,
parseUpdate,
} from '../parser/update-set-parser.js'
import { preventAwait } from '../util/prevent-await.js'
import { Compilable } from '../util/compilable.js'
import { QueryExecutor } from '../query-executor/query-executor.js'
import { QueryId } from '../util/query-id.js'
Expand Down Expand Up @@ -1151,11 +1150,6 @@ export class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyof DB, O>
}
}

preventAwait(
UpdateQueryBuilder,
"don't await UpdateQueryBuilder instances directly. To execute the query you need to call `execute` or `executeTakeFirst`.",
)

export interface UpdateQueryBuilderProps {
readonly queryId: QueryId
readonly queryNode: UpdateQueryNode
Expand Down
10 changes: 7 additions & 3 deletions src/query-compiler/default-query-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,9 @@ export class DefaultQueryCompiler

if (node.joins) {
if (!node.from) {
throw new Error("Joins in an update query are only supported as a part of a PostgreSQL 'update set from join' query. If you want to create a MySQL 'update join set' query, see https://kysely.dev/docs/examples/update/my-sql-joins")
throw new Error(
"Joins in an update query are only supported as a part of a PostgreSQL 'update set from join' query. If you want to create a MySQL 'update join set' query, see https://kysely.dev/docs/examples/update/my-sql-joins",
)
}

this.append(' ')
Expand Down Expand Up @@ -1254,8 +1256,10 @@ export class DefaultQueryCompiler
this.visitNode(node.as)
}
}

protected override visitRefreshMaterializedView(node: RefreshMaterializedViewNode): void {

protected override visitRefreshMaterializedView(
node: RefreshMaterializedViewNode,
): void {
this.append('refresh materialized view ')

if (node.concurrently) {
Expand Down
11 changes: 0 additions & 11 deletions src/raw-builder/raw-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { QueryResult } from '../driver/database-connection.js'
import { AliasNode } from '../operation-node/alias-node.js'
import { RawNode } from '../operation-node/raw-node.js'
import { CompiledQuery } from '../query-compiler/compiled-query.js'
import { preventAwait } from '../util/prevent-await.js'
import { QueryExecutor } from '../query-executor/query-executor.js'
import { freeze } from '../util/object-utils.js'
import { KyselyPlugin } from '../plugin/kysely-plugin.js'
Expand Down Expand Up @@ -221,11 +220,6 @@ export function createRawBuilder<O>(props: RawBuilderProps): RawBuilder<O> {
return new RawBuilderImpl(props)
}

preventAwait(
RawBuilderImpl,
"don't await RawBuilder instances directly. To execute the query you need to call `execute`",
)

/**
* {@link RawBuilder} with an alias. The result of calling {@link RawBuilder.as}.
*/
Expand Down Expand Up @@ -266,8 +260,3 @@ class AliasedRawBuilderImpl<O = unknown, A extends string = never>
)
}
}

preventAwait(
AliasedRawBuilderImpl,
"don't await AliasedRawBuilder instances directly. AliasedRawBuilder should never be executed directly since it's always a part of another query.",
)
Loading

0 comments on commit a84367a

Please sign in to comment.