Skip to content

Commit

Permalink
fixes #258
Browse files Browse the repository at this point in the history
  • Loading branch information
koskimas committed Dec 27, 2022
1 parent 22cac0e commit cc25cdf
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 83 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kysely",
"version": "0.23.0",
"version": "0.23.1",
"description": "Type safe SQL query builder",
"repository": {
"type": "git",
Expand Down
11 changes: 7 additions & 4 deletions src/schema/alter-table-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ export class AlterTableBuilder implements ColumnAlteringInterface {

export interface AlterTableBuilderProps {
readonly queryId: QueryId
readonly node: AlterTableNode
readonly executor: QueryExecutor
readonly node: AlterTableNode
}

export class AlterTableExecutor implements OperationNodeSource, Compilable {
Expand Down Expand Up @@ -306,7 +306,7 @@ export class AlterTableColumnAlteringBuilder
readonly #props: AlterTableColumnAlteringBuilderProps

constructor(props: AlterTableColumnAlteringBuilderProps) {
this.#props = props
this.#props = freeze(props)
}

alterColumn(
Expand Down Expand Up @@ -396,12 +396,15 @@ export class AlterTableColumnAlteringBuilder
}

toOperationNode(): AlterTableNode {
return this.#props.node
return this.#props.executor.transformQuery(
this.#props.node,
this.#props.queryId
)
}

compile(): CompiledQuery {
return this.#props.executor.compileQuery(
this.#props.node,
this.toOperationNode(),
this.#props.queryId
)
}
Expand Down
16 changes: 8 additions & 8 deletions src/schema/create-index-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class CreateIndexBuilder implements OperationNodeSource, Compilable {
unique(): CreateIndexBuilder {
return new CreateIndexBuilder({
...this.#props,
createIndexNode: CreateIndexNode.cloneWith(this.#props.createIndexNode, {
node: CreateIndexNode.cloneWith(this.#props.node, {
unique: true,
}),
})
Expand All @@ -40,7 +40,7 @@ export class CreateIndexBuilder implements OperationNodeSource, Compilable {
on(table: string): CreateIndexBuilder {
return new CreateIndexBuilder({
...this.#props,
createIndexNode: CreateIndexNode.cloneWith(this.#props.createIndexNode, {
node: CreateIndexNode.cloneWith(this.#props.node, {
table: parseTable(table),
}),
})
Expand All @@ -54,7 +54,7 @@ export class CreateIndexBuilder implements OperationNodeSource, Compilable {
column(column: string): CreateIndexBuilder {
return new CreateIndexBuilder({
...this.#props,
createIndexNode: CreateIndexNode.cloneWith(this.#props.createIndexNode, {
node: CreateIndexNode.cloneWith(this.#props.node, {
expression: parseColumnName(column),
}),
})
Expand All @@ -68,7 +68,7 @@ export class CreateIndexBuilder implements OperationNodeSource, Compilable {
columns(columns: string[]): CreateIndexBuilder {
return new CreateIndexBuilder({
...this.#props,
createIndexNode: CreateIndexNode.cloneWith(this.#props.createIndexNode, {
node: CreateIndexNode.cloneWith(this.#props.node, {
expression: ListNode.create(columns.map(parseColumnName)),
}),
})
Expand All @@ -92,7 +92,7 @@ export class CreateIndexBuilder implements OperationNodeSource, Compilable {
expression(expression: Expression<any>): CreateIndexBuilder {
return new CreateIndexBuilder({
...this.#props,
createIndexNode: CreateIndexNode.cloneWith(this.#props.createIndexNode, {
node: CreateIndexNode.cloneWith(this.#props.node, {
expression: expression.toOperationNode(),
}),
})
Expand All @@ -106,15 +106,15 @@ export class CreateIndexBuilder implements OperationNodeSource, Compilable {
using(indexType: string): CreateIndexBuilder {
return new CreateIndexBuilder({
...this.#props,
createIndexNode: CreateIndexNode.cloneWith(this.#props.createIndexNode, {
node: CreateIndexNode.cloneWith(this.#props.node, {
using: RawNode.createWithSql(indexType),
}),
})
}

toOperationNode(): CreateIndexNode {
return this.#props.executor.transformQuery(
this.#props.createIndexNode,
this.#props.node,
this.#props.queryId
)
}
Expand All @@ -139,5 +139,5 @@ preventAwait(
export interface CreateIndexBuilderProps {
readonly queryId: QueryId
readonly executor: QueryExecutor
readonly createIndexNode: CreateIndexNode
readonly node: CreateIndexNode
}
9 changes: 3 additions & 6 deletions src/schema/create-schema-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ export class CreateSchemaBuilder implements OperationNodeSource, Compilable {
ifNotExists(): CreateSchemaBuilder {
return new CreateSchemaBuilder({
...this.#props,
createSchemaNode: CreateSchemaNode.cloneWith(
this.#props.createSchemaNode,
{ ifNotExists: true }
),
node: CreateSchemaNode.cloneWith(this.#props.node, { ifNotExists: true }),
})
}

toOperationNode(): CreateSchemaNode {
return this.#props.executor.transformQuery(
this.#props.createSchemaNode,
this.#props.node,
this.#props.queryId
)
}
Expand All @@ -51,5 +48,5 @@ preventAwait(
export interface CreateSchemaBuilderProps {
readonly queryId: QueryId
readonly executor: QueryExecutor
readonly createSchemaNode: CreateSchemaNode
readonly node: CreateSchemaNode
}
38 changes: 19 additions & 19 deletions src/schema/create-table-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class CreateTableBuilder<TB extends string, C extends string = never>
temporary(): CreateTableBuilder<TB, C> {
return new CreateTableBuilder({
...this.#props,
createTableNode: CreateTableNode.cloneWith(this.#props.createTableNode, {
node: CreateTableNode.cloneWith(this.#props.node, {
temporary: true,
}),
})
Expand All @@ -60,7 +60,7 @@ export class CreateTableBuilder<TB extends string, C extends string = never>
onCommit(onCommit: OnCommitAction): CreateTableBuilder<TB, C> {
return new CreateTableBuilder({
...this.#props,
createTableNode: CreateTableNode.cloneWith(this.#props.createTableNode, {
node: CreateTableNode.cloneWith(this.#props.node, {
onCommit: parseOnCommitAction(onCommit),
}),
})
Expand All @@ -74,7 +74,7 @@ export class CreateTableBuilder<TB extends string, C extends string = never>
ifNotExists(): CreateTableBuilder<TB, C> {
return new CreateTableBuilder({
...this.#props,
createTableNode: CreateTableNode.cloneWith(this.#props.createTableNode, {
node: CreateTableNode.cloneWith(this.#props.node, {
ifNotExists: true,
}),
})
Expand Down Expand Up @@ -140,8 +140,8 @@ export class CreateTableBuilder<TB extends string, C extends string = never>

return new CreateTableBuilder({
...this.#props,
createTableNode: CreateTableNode.cloneWithColumn(
this.#props.createTableNode,
node: CreateTableNode.cloneWithColumn(
this.#props.node,
columnBuilder.toOperationNode()
),
})
Expand All @@ -165,8 +165,8 @@ export class CreateTableBuilder<TB extends string, C extends string = never>
): CreateTableBuilder<TB, C> {
return new CreateTableBuilder({
...this.#props,
createTableNode: CreateTableNode.cloneWithConstraint(
this.#props.createTableNode,
node: CreateTableNode.cloneWithConstraint(
this.#props.node,
PrimaryConstraintNode.create(columns, constraintName)
),
})
Expand All @@ -190,8 +190,8 @@ export class CreateTableBuilder<TB extends string, C extends string = never>
): CreateTableBuilder<TB, C> {
return new CreateTableBuilder({
...this.#props,
createTableNode: CreateTableNode.cloneWithConstraint(
this.#props.createTableNode,
node: CreateTableNode.cloneWithConstraint(
this.#props.node,
UniqueConstraintNode.create(columns, constraintName)
),
})
Expand All @@ -217,8 +217,8 @@ export class CreateTableBuilder<TB extends string, C extends string = never>
): CreateTableBuilder<TB, C> {
return new CreateTableBuilder({
...this.#props,
createTableNode: CreateTableNode.cloneWithConstraint(
this.#props.createTableNode,
node: CreateTableNode.cloneWithConstraint(
this.#props.node,
CheckConstraintNode.create(
checkExpression.toOperationNode(),
constraintName
Expand Down Expand Up @@ -276,8 +276,8 @@ export class CreateTableBuilder<TB extends string, C extends string = never>

return new CreateTableBuilder({
...this.#props,
createTableNode: CreateTableNode.cloneWithConstraint(
this.#props.createTableNode,
node: CreateTableNode.cloneWithConstraint(
this.#props.node,
builder.toOperationNode()
),
})
Expand Down Expand Up @@ -312,8 +312,8 @@ export class CreateTableBuilder<TB extends string, C extends string = never>
modifyFront(modifier: Expression<any>): CreateTableBuilder<TB, C> {
return new CreateTableBuilder({
...this.#props,
createTableNode: CreateTableNode.cloneWithFrontModifier(
this.#props.createTableNode,
node: CreateTableNode.cloneWithFrontModifier(
this.#props.node,
modifier.toOperationNode()
),
})
Expand Down Expand Up @@ -348,8 +348,8 @@ export class CreateTableBuilder<TB extends string, C extends string = never>
modifyEnd(modifier: Expression<any>): CreateTableBuilder<TB, C> {
return new CreateTableBuilder({
...this.#props,
createTableNode: CreateTableNode.cloneWithEndModifier(
this.#props.createTableNode,
node: CreateTableNode.cloneWithEndModifier(
this.#props.node,
modifier.toOperationNode()
),
})
Expand Down Expand Up @@ -393,7 +393,7 @@ export class CreateTableBuilder<TB extends string, C extends string = never>

toOperationNode(): CreateTableNode {
return this.#props.executor.transformQuery(
this.#props.createTableNode,
this.#props.node,
this.#props.queryId
)
}
Expand All @@ -418,7 +418,7 @@ preventAwait(
export interface CreateTableBuilderProps {
readonly queryId: QueryId
readonly executor: QueryExecutor
readonly createTableNode: CreateTableNode
readonly node: CreateTableNode
}

export type ColumnBuilderCallback = (
Expand Down
9 changes: 3 additions & 6 deletions src/schema/create-type-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class CreateTypeBuilder implements OperationNodeSource, Compilable {

toOperationNode(): CreateTypeNode {
return this.#props.executor.transformQuery(
this.#props.createTypeNode,
this.#props.node,
this.#props.queryId
)
}
Expand All @@ -33,10 +33,7 @@ export class CreateTypeBuilder implements OperationNodeSource, Compilable {
asEnum(values: string[]): CreateTypeBuilder {
return new CreateTypeBuilder({
...this.#props,
createTypeNode: CreateTypeNode.cloneWithEnum(
this.#props.createTypeNode,
values
),
node: CreateTypeNode.cloneWithEnum(this.#props.node, values),
})
}

Expand All @@ -60,5 +57,5 @@ preventAwait(
export interface CreateTypeBuilderProps {
readonly queryId: QueryId
readonly executor: QueryExecutor
readonly createTypeNode: CreateTypeNode
readonly node: CreateTypeNode
}
16 changes: 8 additions & 8 deletions src/schema/create-view-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class CreateViewBuilder implements OperationNodeSource, Compilable {
temporary(): CreateViewBuilder {
return new CreateViewBuilder({
...this.#props,
createViewNode: CreateViewNode.cloneWith(this.#props.createViewNode, {
node: CreateViewNode.cloneWith(this.#props.node, {
temporary: true,
}),
})
Expand All @@ -35,7 +35,7 @@ export class CreateViewBuilder implements OperationNodeSource, Compilable {
materialized(): CreateViewBuilder {
return new CreateViewBuilder({
...this.#props,
createViewNode: CreateViewNode.cloneWith(this.#props.createViewNode, {
node: CreateViewNode.cloneWith(this.#props.node, {
materialized: true,
}),
})
Expand All @@ -47,7 +47,7 @@ export class CreateViewBuilder implements OperationNodeSource, Compilable {
ifNotExists(): CreateViewBuilder {
return new CreateViewBuilder({
...this.#props,
createViewNode: CreateViewNode.cloneWith(this.#props.createViewNode, {
node: CreateViewNode.cloneWith(this.#props.node, {
ifNotExists: true,
}),
})
Expand All @@ -56,7 +56,7 @@ export class CreateViewBuilder implements OperationNodeSource, Compilable {
orReplace(): CreateViewBuilder {
return new CreateViewBuilder({
...this.#props,
createViewNode: CreateViewNode.cloneWith(this.#props.createViewNode, {
node: CreateViewNode.cloneWith(this.#props.node, {
orReplace: true,
}),
})
Expand All @@ -65,7 +65,7 @@ export class CreateViewBuilder implements OperationNodeSource, Compilable {
columns(columns: string[]): CreateViewBuilder {
return new CreateViewBuilder({
...this.#props,
createViewNode: CreateViewNode.cloneWith(this.#props.createViewNode, {
node: CreateViewNode.cloneWith(this.#props.node, {
columns: columns.map(parseColumnName),
}),
})
Expand All @@ -87,15 +87,15 @@ export class CreateViewBuilder implements OperationNodeSource, Compilable {

return new CreateViewBuilder({
...this.#props,
createViewNode: CreateViewNode.cloneWith(this.#props.createViewNode, {
node: CreateViewNode.cloneWith(this.#props.node, {
as: queryNode,
}),
})
}

toOperationNode(): CreateViewNode {
return this.#props.executor.transformQuery(
this.#props.createViewNode,
this.#props.node,
this.#props.queryId
)
}
Expand All @@ -120,5 +120,5 @@ preventAwait(
export interface CreateViewBuilderProps {
readonly queryId: QueryId
readonly executor: QueryExecutor
readonly createViewNode: CreateViewNode
readonly node: CreateViewNode
}
Loading

0 comments on commit cc25cdf

Please sign in to comment.