Initial commit - Event Planner application
This commit is contained in:
53
node_modules/kysely/dist/esm/schema/alter-column-builder.d.ts
generated
vendored
Normal file
53
node_modules/kysely/dist/esm/schema/alter-column-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
import { AlterColumnNode } from '../operation-node/alter-column-node.js';
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import { type DataTypeExpression } from '../parser/data-type-parser.js';
|
||||
import { type DefaultValueExpression } from '../parser/default-value-parser.js';
|
||||
export declare class AlterColumnBuilder {
|
||||
#private;
|
||||
constructor(column: string);
|
||||
setDataType(dataType: DataTypeExpression): AlteredColumnBuilder;
|
||||
setDefault(value: DefaultValueExpression): AlteredColumnBuilder;
|
||||
dropDefault(): AlteredColumnBuilder;
|
||||
setNotNull(): AlteredColumnBuilder;
|
||||
dropNotNull(): AlteredColumnBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
}
|
||||
/**
|
||||
* Allows us to force consumers to do exactly one alteration to a column.
|
||||
*
|
||||
* One cannot do no alterations:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* // .execute() // Property 'execute' does not exist on type 'AlteredColumnBuilder'.
|
||||
* ```
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* // .alterColumn('age', (ac) => ac) // Type 'AlterColumnBuilder' is not assignable to type 'AlteredColumnBuilder'.
|
||||
* // .execute()
|
||||
* ```
|
||||
*
|
||||
* One cannot do multiple alterations:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* // .alterColumn('age', (ac) => ac.dropNotNull().setNotNull()) // Property 'setNotNull' does not exist on type 'AlteredColumnBuilder'.
|
||||
* // .execute()
|
||||
* ```
|
||||
*
|
||||
* Which would now throw a compilation error, instead of a runtime error.
|
||||
*/
|
||||
export declare class AlteredColumnBuilder implements OperationNodeSource {
|
||||
#private;
|
||||
constructor(alterColumnNode: AlterColumnNode);
|
||||
toOperationNode(): AlterColumnNode;
|
||||
}
|
||||
export type AlterColumnBuilderCallback = (builder: AlterColumnBuilder) => AlteredColumnBuilder;
|
||||
70
node_modules/kysely/dist/esm/schema/alter-column-builder.js
generated
vendored
Normal file
70
node_modules/kysely/dist/esm/schema/alter-column-builder.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
/// <reference types="./alter-column-builder.d.ts" />
|
||||
import { AlterColumnNode } from '../operation-node/alter-column-node.js';
|
||||
import { parseDataTypeExpression, } from '../parser/data-type-parser.js';
|
||||
import { parseDefaultValueExpression, } from '../parser/default-value-parser.js';
|
||||
export class AlterColumnBuilder {
|
||||
#column;
|
||||
constructor(column) {
|
||||
this.#column = column;
|
||||
}
|
||||
setDataType(dataType) {
|
||||
return new AlteredColumnBuilder(AlterColumnNode.create(this.#column, 'dataType', parseDataTypeExpression(dataType)));
|
||||
}
|
||||
setDefault(value) {
|
||||
return new AlteredColumnBuilder(AlterColumnNode.create(this.#column, 'setDefault', parseDefaultValueExpression(value)));
|
||||
}
|
||||
dropDefault() {
|
||||
return new AlteredColumnBuilder(AlterColumnNode.create(this.#column, 'dropDefault', true));
|
||||
}
|
||||
setNotNull() {
|
||||
return new AlteredColumnBuilder(AlterColumnNode.create(this.#column, 'setNotNull', true));
|
||||
}
|
||||
dropNotNull() {
|
||||
return new AlteredColumnBuilder(AlterColumnNode.create(this.#column, 'dropNotNull', true));
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Allows us to force consumers to do exactly one alteration to a column.
|
||||
*
|
||||
* One cannot do no alterations:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* // .execute() // Property 'execute' does not exist on type 'AlteredColumnBuilder'.
|
||||
* ```
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* // .alterColumn('age', (ac) => ac) // Type 'AlterColumnBuilder' is not assignable to type 'AlteredColumnBuilder'.
|
||||
* // .execute()
|
||||
* ```
|
||||
*
|
||||
* One cannot do multiple alterations:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* // .alterColumn('age', (ac) => ac.dropNotNull().setNotNull()) // Property 'setNotNull' does not exist on type 'AlteredColumnBuilder'.
|
||||
* // .execute()
|
||||
* ```
|
||||
*
|
||||
* Which would now throw a compilation error, instead of a runtime error.
|
||||
*/
|
||||
export class AlteredColumnBuilder {
|
||||
#alterColumnNode;
|
||||
constructor(alterColumnNode) {
|
||||
this.#alterColumnNode = alterColumnNode;
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#alterColumnNode;
|
||||
}
|
||||
}
|
||||
32
node_modules/kysely/dist/esm/schema/alter-table-add-foreign-key-constraint-builder.d.ts
generated
vendored
Normal file
32
node_modules/kysely/dist/esm/schema/alter-table-add-foreign-key-constraint-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import { AlterTableNode } from '../operation-node/alter-table-node.js';
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { OnModifyForeignAction } from '../operation-node/references-node.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
import type { ForeignKeyConstraintBuilder, ForeignKeyConstraintBuilderInterface } from './foreign-key-constraint-builder.js';
|
||||
export declare class AlterTableAddForeignKeyConstraintBuilder implements ForeignKeyConstraintBuilderInterface<AlterTableAddForeignKeyConstraintBuilder>, OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: AlterTableAddForeignKeyConstraintBuilderProps);
|
||||
onDelete(onDelete: OnModifyForeignAction): AlterTableAddForeignKeyConstraintBuilder;
|
||||
onUpdate(onUpdate: OnModifyForeignAction): AlterTableAddForeignKeyConstraintBuilder;
|
||||
deferrable(): AlterTableAddForeignKeyConstraintBuilder;
|
||||
notDeferrable(): AlterTableAddForeignKeyConstraintBuilder;
|
||||
initiallyDeferred(): AlterTableAddForeignKeyConstraintBuilder;
|
||||
initiallyImmediate(): AlterTableAddForeignKeyConstraintBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): AlterTableNode;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface AlterTableAddForeignKeyConstraintBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: AlterTableNode;
|
||||
readonly constraintBuilder: ForeignKeyConstraintBuilder;
|
||||
}
|
||||
64
node_modules/kysely/dist/esm/schema/alter-table-add-foreign-key-constraint-builder.js
generated
vendored
Normal file
64
node_modules/kysely/dist/esm/schema/alter-table-add-foreign-key-constraint-builder.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
/// <reference types="./alter-table-add-foreign-key-constraint-builder.d.ts" />
|
||||
import { AddConstraintNode } from '../operation-node/add-constraint-node.js';
|
||||
import { AlterTableNode } from '../operation-node/alter-table-node.js';
|
||||
import { freeze } from '../util/object-utils.js';
|
||||
export class AlterTableAddForeignKeyConstraintBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
onDelete(onDelete) {
|
||||
return new AlterTableAddForeignKeyConstraintBuilder({
|
||||
...this.#props,
|
||||
constraintBuilder: this.#props.constraintBuilder.onDelete(onDelete),
|
||||
});
|
||||
}
|
||||
onUpdate(onUpdate) {
|
||||
return new AlterTableAddForeignKeyConstraintBuilder({
|
||||
...this.#props,
|
||||
constraintBuilder: this.#props.constraintBuilder.onUpdate(onUpdate),
|
||||
});
|
||||
}
|
||||
deferrable() {
|
||||
return new AlterTableAddForeignKeyConstraintBuilder({
|
||||
...this.#props,
|
||||
constraintBuilder: this.#props.constraintBuilder.deferrable(),
|
||||
});
|
||||
}
|
||||
notDeferrable() {
|
||||
return new AlterTableAddForeignKeyConstraintBuilder({
|
||||
...this.#props,
|
||||
constraintBuilder: this.#props.constraintBuilder.notDeferrable(),
|
||||
});
|
||||
}
|
||||
initiallyDeferred() {
|
||||
return new AlterTableAddForeignKeyConstraintBuilder({
|
||||
...this.#props,
|
||||
constraintBuilder: this.#props.constraintBuilder.initiallyDeferred(),
|
||||
});
|
||||
}
|
||||
initiallyImmediate() {
|
||||
return new AlterTableAddForeignKeyConstraintBuilder({
|
||||
...this.#props,
|
||||
constraintBuilder: this.#props.constraintBuilder.initiallyImmediate(),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
addConstraint: AddConstraintNode.create(this.#props.constraintBuilder.toOperationNode()),
|
||||
}), this.#props.queryId);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
138
node_modules/kysely/dist/esm/schema/alter-table-add-index-builder.d.ts
generated
vendored
Normal file
138
node_modules/kysely/dist/esm/schema/alter-table-add-index-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
import type { Expression } from '../expression/expression.js';
|
||||
import { AlterTableNode } from '../operation-node/alter-table-node.js';
|
||||
import type { IndexType } from '../operation-node/create-index-node.js';
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import { type OrderedColumnName } from '../parser/reference-parser.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
export declare class AlterTableAddIndexBuilder implements OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: AlterTableAddIndexBuilderProps);
|
||||
/**
|
||||
* Makes the index unique.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* .addIndex('person_first_name_index')
|
||||
* .unique()
|
||||
* .column('email')
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* alter table `person` add unique index `person_first_name_index` (`email`)
|
||||
* ```
|
||||
*/
|
||||
unique(): AlterTableAddIndexBuilder;
|
||||
/**
|
||||
* Adds a column to the index.
|
||||
*
|
||||
* Also see {@link columns} for adding multiple columns at once or {@link expression}
|
||||
* for specifying an arbitrary expression.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* .addIndex('person_first_name_and_age_index')
|
||||
* .column('first_name')
|
||||
* .column('age desc')
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* alter table `person` add index `person_first_name_and_age_index` (`first_name`, `age` desc)
|
||||
* ```
|
||||
*/
|
||||
column<CL extends string>(column: OrderedColumnName<CL>): AlterTableAddIndexBuilder;
|
||||
/**
|
||||
* Specifies a list of columns for the index.
|
||||
*
|
||||
* Also see {@link column} for adding a single column or {@link expression} for
|
||||
* specifying an arbitrary expression.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* .addIndex('person_first_name_and_age_index')
|
||||
* .columns(['first_name', 'age desc'])
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* alter table `person` add index `person_first_name_and_age_index` (`first_name`, `age` desc)
|
||||
* ```
|
||||
*/
|
||||
columns<CL extends string>(columns: OrderedColumnName<CL>[]): AlterTableAddIndexBuilder;
|
||||
/**
|
||||
* Specifies an arbitrary expression for the index.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* .addIndex('person_first_name_index')
|
||||
* .expression(sql<boolean>`(first_name < 'Sami')`)
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* alter table `person` add index `person_first_name_index` ((first_name < 'Sami'))
|
||||
* ```
|
||||
*/
|
||||
expression(expression: Expression<any>): AlterTableAddIndexBuilder;
|
||||
/**
|
||||
* Specifies the index type.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* .addIndex('person_first_name_index')
|
||||
* .column('first_name')
|
||||
* .using('hash')
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* alter table `person` add index `person_first_name_index` (`first_name`) using hash
|
||||
* ```
|
||||
*/
|
||||
using(indexType: IndexType): AlterTableAddIndexBuilder;
|
||||
using(indexType: string): AlterTableAddIndexBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): AlterTableNode;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface AlterTableAddIndexBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: AlterTableNode;
|
||||
}
|
||||
162
node_modules/kysely/dist/esm/schema/alter-table-add-index-builder.js
generated
vendored
Normal file
162
node_modules/kysely/dist/esm/schema/alter-table-add-index-builder.js
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
/// <reference types="./alter-table-add-index-builder.d.ts" />
|
||||
import { AddIndexNode } from '../operation-node/add-index-node.js';
|
||||
import { AlterTableNode } from '../operation-node/alter-table-node.js';
|
||||
import { RawNode } from '../operation-node/raw-node.js';
|
||||
import { parseOrderedColumnName, } from '../parser/reference-parser.js';
|
||||
import { freeze } from '../util/object-utils.js';
|
||||
export class AlterTableAddIndexBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
/**
|
||||
* Makes the index unique.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* .addIndex('person_first_name_index')
|
||||
* .unique()
|
||||
* .column('email')
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* alter table `person` add unique index `person_first_name_index` (`email`)
|
||||
* ```
|
||||
*/
|
||||
unique() {
|
||||
return new AlterTableAddIndexBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
addIndex: AddIndexNode.cloneWith(this.#props.node.addIndex, {
|
||||
unique: true,
|
||||
}),
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adds a column to the index.
|
||||
*
|
||||
* Also see {@link columns} for adding multiple columns at once or {@link expression}
|
||||
* for specifying an arbitrary expression.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* .addIndex('person_first_name_and_age_index')
|
||||
* .column('first_name')
|
||||
* .column('age desc')
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* alter table `person` add index `person_first_name_and_age_index` (`first_name`, `age` desc)
|
||||
* ```
|
||||
*/
|
||||
column(column) {
|
||||
return new AlterTableAddIndexBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
addIndex: AddIndexNode.cloneWithColumns(this.#props.node.addIndex, [
|
||||
parseOrderedColumnName(column),
|
||||
]),
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Specifies a list of columns for the index.
|
||||
*
|
||||
* Also see {@link column} for adding a single column or {@link expression} for
|
||||
* specifying an arbitrary expression.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* .addIndex('person_first_name_and_age_index')
|
||||
* .columns(['first_name', 'age desc'])
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* alter table `person` add index `person_first_name_and_age_index` (`first_name`, `age` desc)
|
||||
* ```
|
||||
*/
|
||||
columns(columns) {
|
||||
return new AlterTableAddIndexBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
addIndex: AddIndexNode.cloneWithColumns(this.#props.node.addIndex, columns.map(parseOrderedColumnName)),
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Specifies an arbitrary expression for the index.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* .addIndex('person_first_name_index')
|
||||
* .expression(sql<boolean>`(first_name < 'Sami')`)
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* alter table `person` add index `person_first_name_index` ((first_name < 'Sami'))
|
||||
* ```
|
||||
*/
|
||||
expression(expression) {
|
||||
return new AlterTableAddIndexBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
addIndex: AddIndexNode.cloneWithColumns(this.#props.node.addIndex, [
|
||||
expression.toOperationNode(),
|
||||
]),
|
||||
}),
|
||||
});
|
||||
}
|
||||
using(indexType) {
|
||||
return new AlterTableAddIndexBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
addIndex: AddIndexNode.cloneWith(this.#props.node.addIndex, {
|
||||
using: RawNode.createWithSql(indexType),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
148
node_modules/kysely/dist/esm/schema/alter-table-builder.d.ts
generated
vendored
Normal file
148
node_modules/kysely/dist/esm/schema/alter-table-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
import { AlterTableNode } from '../operation-node/alter-table-node.js';
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import { type ColumnDefinitionBuilderCallback } from './column-definition-builder.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import { type DataTypeExpression } from '../parser/data-type-parser.js';
|
||||
import { type ForeignKeyConstraintBuilderCallback } from './foreign-key-constraint-builder.js';
|
||||
import type { Expression } from '../expression/expression.js';
|
||||
import { type AlterColumnBuilderCallback } from './alter-column-builder.js';
|
||||
import { AlterTableExecutor } from './alter-table-executor.js';
|
||||
import { AlterTableAddForeignKeyConstraintBuilder } from './alter-table-add-foreign-key-constraint-builder.js';
|
||||
import { AlterTableDropConstraintBuilder } from './alter-table-drop-constraint-builder.js';
|
||||
import { AlterTableAddIndexBuilder } from './alter-table-add-index-builder.js';
|
||||
import { type UniqueConstraintNodeBuilderCallback } from './unique-constraint-builder.js';
|
||||
import { type PrimaryKeyConstraintBuilderCallback } from './primary-key-constraint-builder.js';
|
||||
import { type CheckConstraintBuilderCallback } from './check-constraint-builder.js';
|
||||
/**
|
||||
* This builder can be used to create a `alter table` query.
|
||||
*/
|
||||
export declare class AlterTableBuilder implements ColumnAlteringInterface {
|
||||
#private;
|
||||
constructor(props: AlterTableBuilderProps);
|
||||
renameTo(newTableName: string): AlterTableExecutor;
|
||||
setSchema(newSchema: string): AlterTableExecutor;
|
||||
alterColumn(column: string, alteration: AlterColumnBuilderCallback): AlterTableColumnAlteringBuilder;
|
||||
dropColumn(column: string): AlterTableColumnAlteringBuilder;
|
||||
renameColumn(column: string, newColumn: string): AlterTableColumnAlteringBuilder;
|
||||
/**
|
||||
* See {@link CreateTableBuilder.addColumn}
|
||||
*/
|
||||
addColumn(columnName: string, dataType: DataTypeExpression, build?: ColumnDefinitionBuilderCallback): AlterTableColumnAlteringBuilder;
|
||||
/**
|
||||
* Creates an `alter table modify column` query. The `modify column` statement
|
||||
* is only implemeted by MySQL and oracle AFAIK. On other databases you
|
||||
* should use the `alterColumn` method.
|
||||
*/
|
||||
modifyColumn(columnName: string, dataType: DataTypeExpression, build?: ColumnDefinitionBuilderCallback): AlterTableColumnAlteringBuilder;
|
||||
/**
|
||||
* See {@link CreateTableBuilder.addUniqueConstraint}
|
||||
*/
|
||||
addUniqueConstraint(constraintName: string, columns: string[], build?: UniqueConstraintNodeBuilderCallback): AlterTableExecutor;
|
||||
/**
|
||||
* See {@link CreateTableBuilder.addCheckConstraint}
|
||||
*/
|
||||
addCheckConstraint(constraintName: string, checkExpression: Expression<any>, build?: CheckConstraintBuilderCallback): AlterTableExecutor;
|
||||
/**
|
||||
* See {@link CreateTableBuilder.addForeignKeyConstraint}
|
||||
*
|
||||
* Unlike {@link CreateTableBuilder.addForeignKeyConstraint} this method returns
|
||||
* the constraint builder and doesn't take a callback as the last argument. This
|
||||
* is because you can only add one column per `ALTER TABLE` query.
|
||||
*/
|
||||
addForeignKeyConstraint(constraintName: string, columns: string[], targetTable: string, targetColumns: string[], build?: ForeignKeyConstraintBuilderCallback): AlterTableAddForeignKeyConstraintBuilder;
|
||||
/**
|
||||
* See {@link CreateTableBuilder.addPrimaryKeyConstraint}
|
||||
*/
|
||||
addPrimaryKeyConstraint(constraintName: string, columns: string[], build?: PrimaryKeyConstraintBuilderCallback): AlterTableExecutor;
|
||||
dropConstraint(constraintName: string): AlterTableDropConstraintBuilder;
|
||||
renameConstraint(oldName: string, newName: string): AlterTableDropConstraintBuilder;
|
||||
/**
|
||||
* This can be used to add index to table.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* db.schema.alterTable('person')
|
||||
* .addIndex('person_email_index')
|
||||
* .column('email')
|
||||
* .unique()
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* alter table `person` add unique index `person_email_index` (`email`)
|
||||
* ```
|
||||
*/
|
||||
addIndex(indexName: string): AlterTableAddIndexBuilder;
|
||||
/**
|
||||
* This can be used to drop index from table.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* db.schema.alterTable('person')
|
||||
* .dropIndex('person_email_index')
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* alter table `person` drop index `test_first_name_index`
|
||||
* ```
|
||||
*/
|
||||
dropIndex(indexName: string): AlterTableExecutor;
|
||||
/**
|
||||
* Calls the given function passing `this` as the only argument.
|
||||
*
|
||||
* See {@link CreateTableBuilder.$call}
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
}
|
||||
export interface AlterTableBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: AlterTableNode;
|
||||
}
|
||||
export interface ColumnAlteringInterface {
|
||||
alterColumn(column: string, alteration: AlterColumnBuilderCallback): ColumnAlteringInterface;
|
||||
dropColumn(column: string): ColumnAlteringInterface;
|
||||
renameColumn(column: string, newColumn: string): ColumnAlteringInterface;
|
||||
/**
|
||||
* See {@link CreateTableBuilder.addColumn}
|
||||
*/
|
||||
addColumn(columnName: string, dataType: DataTypeExpression, build?: ColumnDefinitionBuilderCallback): ColumnAlteringInterface;
|
||||
/**
|
||||
* Creates an `alter table modify column` query. The `modify column` statement
|
||||
* is only implemeted by MySQL and oracle AFAIK. On other databases you
|
||||
* should use the `alterColumn` method.
|
||||
*/
|
||||
modifyColumn(columnName: string, dataType: DataTypeExpression, build: ColumnDefinitionBuilderCallback): ColumnAlteringInterface;
|
||||
}
|
||||
export declare class AlterTableColumnAlteringBuilder implements ColumnAlteringInterface, OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: AlterTableColumnAlteringBuilderProps);
|
||||
alterColumn(column: string, alteration: AlterColumnBuilderCallback): AlterTableColumnAlteringBuilder;
|
||||
dropColumn(column: string): AlterTableColumnAlteringBuilder;
|
||||
renameColumn(column: string, newColumn: string): AlterTableColumnAlteringBuilder;
|
||||
/**
|
||||
* See {@link CreateTableBuilder.addColumn}
|
||||
*/
|
||||
addColumn(columnName: string, dataType: DataTypeExpression, build?: ColumnDefinitionBuilderCallback): AlterTableColumnAlteringBuilder;
|
||||
/**
|
||||
* Creates an `alter table modify column` query. The `modify column` statement
|
||||
* is only implemeted by MySQL and oracle AFAIK. On other databases you
|
||||
* should use the `alterColumn` method.
|
||||
*/
|
||||
modifyColumn(columnName: string, dataType: DataTypeExpression, build?: ColumnDefinitionBuilderCallback): AlterTableColumnAlteringBuilder;
|
||||
toOperationNode(): AlterTableNode;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface AlterTableColumnAlteringBuilderProps extends AlterTableBuilderProps {
|
||||
}
|
||||
263
node_modules/kysely/dist/esm/schema/alter-table-builder.js
generated
vendored
Normal file
263
node_modules/kysely/dist/esm/schema/alter-table-builder.js
generated
vendored
Normal file
@@ -0,0 +1,263 @@
|
||||
/// <reference types="./alter-table-builder.d.ts" />
|
||||
import { AddColumnNode } from '../operation-node/add-column-node.js';
|
||||
import { AlterTableNode } from '../operation-node/alter-table-node.js';
|
||||
import { ColumnDefinitionNode } from '../operation-node/column-definition-node.js';
|
||||
import { DropColumnNode } from '../operation-node/drop-column-node.js';
|
||||
import { IdentifierNode } from '../operation-node/identifier-node.js';
|
||||
import { RenameColumnNode } from '../operation-node/rename-column-node.js';
|
||||
import { freeze, noop } from '../util/object-utils.js';
|
||||
import { ColumnDefinitionBuilder, } from './column-definition-builder.js';
|
||||
import { ModifyColumnNode } from '../operation-node/modify-column-node.js';
|
||||
import { parseDataTypeExpression, } from '../parser/data-type-parser.js';
|
||||
import { ForeignKeyConstraintBuilder, } from './foreign-key-constraint-builder.js';
|
||||
import { AddConstraintNode } from '../operation-node/add-constraint-node.js';
|
||||
import { UniqueConstraintNode } from '../operation-node/unique-constraint-node.js';
|
||||
import { CheckConstraintNode } from '../operation-node/check-constraint-node.js';
|
||||
import { ForeignKeyConstraintNode } from '../operation-node/foreign-key-constraint-node.js';
|
||||
import { ColumnNode } from '../operation-node/column-node.js';
|
||||
import { parseTable } from '../parser/table-parser.js';
|
||||
import { DropConstraintNode } from '../operation-node/drop-constraint-node.js';
|
||||
import { AlterColumnBuilder, } from './alter-column-builder.js';
|
||||
import { AlterTableExecutor } from './alter-table-executor.js';
|
||||
import { AlterTableAddForeignKeyConstraintBuilder } from './alter-table-add-foreign-key-constraint-builder.js';
|
||||
import { AlterTableDropConstraintBuilder } from './alter-table-drop-constraint-builder.js';
|
||||
import { PrimaryKeyConstraintNode } from '../operation-node/primary-key-constraint-node.js';
|
||||
import { DropIndexNode } from '../operation-node/drop-index-node.js';
|
||||
import { AddIndexNode } from '../operation-node/add-index-node.js';
|
||||
import { AlterTableAddIndexBuilder } from './alter-table-add-index-builder.js';
|
||||
import { UniqueConstraintNodeBuilder, } from './unique-constraint-builder.js';
|
||||
import { PrimaryKeyConstraintBuilder, } from './primary-key-constraint-builder.js';
|
||||
import { CheckConstraintBuilder, } from './check-constraint-builder.js';
|
||||
import { RenameConstraintNode } from '../operation-node/rename-constraint-node.js';
|
||||
/**
|
||||
* This builder can be used to create a `alter table` query.
|
||||
*/
|
||||
export class AlterTableBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
renameTo(newTableName) {
|
||||
return new AlterTableExecutor({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
renameTo: parseTable(newTableName),
|
||||
}),
|
||||
});
|
||||
}
|
||||
setSchema(newSchema) {
|
||||
return new AlterTableExecutor({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
setSchema: IdentifierNode.create(newSchema),
|
||||
}),
|
||||
});
|
||||
}
|
||||
alterColumn(column, alteration) {
|
||||
const builder = alteration(new AlterColumnBuilder(column));
|
||||
return new AlterTableColumnAlteringBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithColumnAlteration(this.#props.node, builder.toOperationNode()),
|
||||
});
|
||||
}
|
||||
dropColumn(column) {
|
||||
return new AlterTableColumnAlteringBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithColumnAlteration(this.#props.node, DropColumnNode.create(column)),
|
||||
});
|
||||
}
|
||||
renameColumn(column, newColumn) {
|
||||
return new AlterTableColumnAlteringBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithColumnAlteration(this.#props.node, RenameColumnNode.create(column, newColumn)),
|
||||
});
|
||||
}
|
||||
addColumn(columnName, dataType, build = noop) {
|
||||
const builder = build(new ColumnDefinitionBuilder(ColumnDefinitionNode.create(columnName, parseDataTypeExpression(dataType))));
|
||||
return new AlterTableColumnAlteringBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithColumnAlteration(this.#props.node, AddColumnNode.create(builder.toOperationNode())),
|
||||
});
|
||||
}
|
||||
modifyColumn(columnName, dataType, build = noop) {
|
||||
const builder = build(new ColumnDefinitionBuilder(ColumnDefinitionNode.create(columnName, parseDataTypeExpression(dataType))));
|
||||
return new AlterTableColumnAlteringBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithColumnAlteration(this.#props.node, ModifyColumnNode.create(builder.toOperationNode())),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* See {@link CreateTableBuilder.addUniqueConstraint}
|
||||
*/
|
||||
addUniqueConstraint(constraintName, columns, build = noop) {
|
||||
const uniqueConstraintBuilder = build(new UniqueConstraintNodeBuilder(UniqueConstraintNode.create(columns, constraintName)));
|
||||
return new AlterTableExecutor({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
addConstraint: AddConstraintNode.create(uniqueConstraintBuilder.toOperationNode()),
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* See {@link CreateTableBuilder.addCheckConstraint}
|
||||
*/
|
||||
addCheckConstraint(constraintName, checkExpression, build = noop) {
|
||||
const constraintBuilder = build(new CheckConstraintBuilder(CheckConstraintNode.create(checkExpression.toOperationNode(), constraintName)));
|
||||
return new AlterTableExecutor({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
addConstraint: AddConstraintNode.create(constraintBuilder.toOperationNode()),
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* See {@link CreateTableBuilder.addForeignKeyConstraint}
|
||||
*
|
||||
* Unlike {@link CreateTableBuilder.addForeignKeyConstraint} this method returns
|
||||
* the constraint builder and doesn't take a callback as the last argument. This
|
||||
* is because you can only add one column per `ALTER TABLE` query.
|
||||
*/
|
||||
addForeignKeyConstraint(constraintName, columns, targetTable, targetColumns, build = noop) {
|
||||
const constraintBuilder = build(new ForeignKeyConstraintBuilder(ForeignKeyConstraintNode.create(columns.map(ColumnNode.create), parseTable(targetTable), targetColumns.map(ColumnNode.create), constraintName)));
|
||||
return new AlterTableAddForeignKeyConstraintBuilder({
|
||||
...this.#props,
|
||||
constraintBuilder,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* See {@link CreateTableBuilder.addPrimaryKeyConstraint}
|
||||
*/
|
||||
addPrimaryKeyConstraint(constraintName, columns, build = noop) {
|
||||
const constraintBuilder = build(new PrimaryKeyConstraintBuilder(PrimaryKeyConstraintNode.create(columns, constraintName)));
|
||||
return new AlterTableExecutor({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
addConstraint: AddConstraintNode.create(constraintBuilder.toOperationNode()),
|
||||
}),
|
||||
});
|
||||
}
|
||||
dropConstraint(constraintName) {
|
||||
return new AlterTableDropConstraintBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
dropConstraint: DropConstraintNode.create(constraintName),
|
||||
}),
|
||||
});
|
||||
}
|
||||
renameConstraint(oldName, newName) {
|
||||
return new AlterTableDropConstraintBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
renameConstraint: RenameConstraintNode.create(oldName, newName),
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* This can be used to add index to table.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* db.schema.alterTable('person')
|
||||
* .addIndex('person_email_index')
|
||||
* .column('email')
|
||||
* .unique()
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* alter table `person` add unique index `person_email_index` (`email`)
|
||||
* ```
|
||||
*/
|
||||
addIndex(indexName) {
|
||||
return new AlterTableAddIndexBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
addIndex: AddIndexNode.create(indexName),
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* This can be used to drop index from table.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* db.schema.alterTable('person')
|
||||
* .dropIndex('person_email_index')
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* alter table `person` drop index `test_first_name_index`
|
||||
* ```
|
||||
*/
|
||||
dropIndex(indexName) {
|
||||
return new AlterTableExecutor({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
dropIndex: DropIndexNode.create(indexName),
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Calls the given function passing `this` as the only argument.
|
||||
*
|
||||
* See {@link CreateTableBuilder.$call}
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
}
|
||||
export class AlterTableColumnAlteringBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
alterColumn(column, alteration) {
|
||||
const builder = alteration(new AlterColumnBuilder(column));
|
||||
return new AlterTableColumnAlteringBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithColumnAlteration(this.#props.node, builder.toOperationNode()),
|
||||
});
|
||||
}
|
||||
dropColumn(column) {
|
||||
return new AlterTableColumnAlteringBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithColumnAlteration(this.#props.node, DropColumnNode.create(column)),
|
||||
});
|
||||
}
|
||||
renameColumn(column, newColumn) {
|
||||
return new AlterTableColumnAlteringBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithColumnAlteration(this.#props.node, RenameColumnNode.create(column, newColumn)),
|
||||
});
|
||||
}
|
||||
addColumn(columnName, dataType, build = noop) {
|
||||
const builder = build(new ColumnDefinitionBuilder(ColumnDefinitionNode.create(columnName, parseDataTypeExpression(dataType))));
|
||||
return new AlterTableColumnAlteringBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithColumnAlteration(this.#props.node, AddColumnNode.create(builder.toOperationNode())),
|
||||
});
|
||||
}
|
||||
modifyColumn(columnName, dataType, build = noop) {
|
||||
const builder = build(new ColumnDefinitionBuilder(ColumnDefinitionNode.create(columnName, parseDataTypeExpression(dataType))));
|
||||
return new AlterTableColumnAlteringBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithColumnAlteration(this.#props.node, ModifyColumnNode.create(builder.toOperationNode())),
|
||||
});
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
26
node_modules/kysely/dist/esm/schema/alter-table-drop-constraint-builder.d.ts
generated
vendored
Normal file
26
node_modules/kysely/dist/esm/schema/alter-table-drop-constraint-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import { AlterTableNode } from '../operation-node/alter-table-node.js';
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
export declare class AlterTableDropConstraintBuilder implements OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: AlterTableDropConstraintBuilderProps);
|
||||
ifExists(): AlterTableDropConstraintBuilder;
|
||||
cascade(): AlterTableDropConstraintBuilder;
|
||||
restrict(): AlterTableDropConstraintBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): AlterTableNode;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface AlterTableDropConstraintBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: AlterTableNode;
|
||||
}
|
||||
56
node_modules/kysely/dist/esm/schema/alter-table-drop-constraint-builder.js
generated
vendored
Normal file
56
node_modules/kysely/dist/esm/schema/alter-table-drop-constraint-builder.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
/// <reference types="./alter-table-drop-constraint-builder.d.ts" />
|
||||
import { AlterTableNode } from '../operation-node/alter-table-node.js';
|
||||
import { DropConstraintNode } from '../operation-node/drop-constraint-node.js';
|
||||
import { freeze } from '../util/object-utils.js';
|
||||
export class AlterTableDropConstraintBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
ifExists() {
|
||||
return new AlterTableDropConstraintBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
dropConstraint: DropConstraintNode.cloneWith(this.#props.node.dropConstraint, {
|
||||
ifExists: true,
|
||||
}),
|
||||
}),
|
||||
});
|
||||
}
|
||||
cascade() {
|
||||
return new AlterTableDropConstraintBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
dropConstraint: DropConstraintNode.cloneWith(this.#props.node.dropConstraint, {
|
||||
modifier: 'cascade',
|
||||
}),
|
||||
}),
|
||||
});
|
||||
}
|
||||
restrict() {
|
||||
return new AlterTableDropConstraintBuilder({
|
||||
...this.#props,
|
||||
node: AlterTableNode.cloneWithTableProps(this.#props.node, {
|
||||
dropConstraint: DropConstraintNode.cloneWith(this.#props.node.dropConstraint, {
|
||||
modifier: 'restrict',
|
||||
}),
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
18
node_modules/kysely/dist/esm/schema/alter-table-executor.d.ts
generated
vendored
Normal file
18
node_modules/kysely/dist/esm/schema/alter-table-executor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { AlterTableNode } from '../operation-node/alter-table-node.js';
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
export declare class AlterTableExecutor implements OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: AlterTableExecutorProps);
|
||||
toOperationNode(): AlterTableNode;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface AlterTableExecutorProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: AlterTableNode;
|
||||
}
|
||||
17
node_modules/kysely/dist/esm/schema/alter-table-executor.js
generated
vendored
Normal file
17
node_modules/kysely/dist/esm/schema/alter-table-executor.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/// <reference types="./alter-table-executor.d.ts" />
|
||||
import { freeze } from '../util/object-utils.js';
|
||||
export class AlterTableExecutor {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
13
node_modules/kysely/dist/esm/schema/check-constraint-builder.d.ts
generated
vendored
Normal file
13
node_modules/kysely/dist/esm/schema/check-constraint-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { CheckConstraintNode } from '../operation-node/check-constraint-node.js';
|
||||
export declare class CheckConstraintBuilder implements OperationNodeSource {
|
||||
#private;
|
||||
constructor(node: CheckConstraintNode);
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): CheckConstraintNode;
|
||||
}
|
||||
export type CheckConstraintBuilderCallback = (builder: CheckConstraintBuilder) => CheckConstraintBuilder;
|
||||
17
node_modules/kysely/dist/esm/schema/check-constraint-builder.js
generated
vendored
Normal file
17
node_modules/kysely/dist/esm/schema/check-constraint-builder.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/// <reference types="./check-constraint-builder.d.ts" />
|
||||
export class CheckConstraintBuilder {
|
||||
#node;
|
||||
constructor(node) {
|
||||
this.#node = node;
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#node;
|
||||
}
|
||||
}
|
||||
514
node_modules/kysely/dist/esm/schema/column-definition-builder.d.ts
generated
vendored
Normal file
514
node_modules/kysely/dist/esm/schema/column-definition-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,514 @@
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import { type OnModifyForeignAction } from '../operation-node/references-node.js';
|
||||
import { ColumnDefinitionNode } from '../operation-node/column-definition-node.js';
|
||||
import { type DefaultValueExpression } from '../parser/default-value-parser.js';
|
||||
import type { Expression } from '../expression/expression.js';
|
||||
export declare class ColumnDefinitionBuilder implements OperationNodeSource {
|
||||
#private;
|
||||
constructor(node: ColumnDefinitionNode);
|
||||
/**
|
||||
* Adds `auto_increment` or `autoincrement` to the column definition
|
||||
* depending on the dialect.
|
||||
*
|
||||
* Some dialects like PostgreSQL don't support this. On PostgreSQL
|
||||
* you can use the `serial` or `bigserial` data type instead.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.autoIncrement().primaryKey())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `id` integer primary key auto_increment
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
autoIncrement(): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Makes the column an identity column.
|
||||
*
|
||||
* This only works on some dialects like MS SQL Server (MSSQL).
|
||||
*
|
||||
* For PostgreSQL's `generated always as identity` use {@link generatedAlwaysAsIdentity}.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.identity().primaryKey())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MSSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table "person" (
|
||||
* "id" integer identity primary key
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
identity(): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Makes the column the primary key.
|
||||
*
|
||||
* If you want to specify a composite primary key use the
|
||||
* {@link CreateTableBuilder.addPrimaryKeyConstraint} method.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `id` integer primary key
|
||||
* )
|
||||
*/
|
||||
primaryKey(): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Adds a foreign key constraint for the column.
|
||||
*
|
||||
* If your database engine doesn't support foreign key constraints in the
|
||||
* column definition (like MySQL 5) you need to call the table level
|
||||
* {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn('owner_id', 'integer', (col) => col.references('person.id'))
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table "pet" (
|
||||
* "owner_id" integer references "person" ("id")
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
references(ref: string): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Adds an `on delete` constraint for the foreign key column.
|
||||
*
|
||||
* If your database engine doesn't support foreign key constraints in the
|
||||
* column definition (like MySQL 5) you need to call the table level
|
||||
* {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn(
|
||||
* 'owner_id',
|
||||
* 'integer',
|
||||
* (col) => col.references('person.id').onDelete('cascade')
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table "pet" (
|
||||
* "owner_id" integer references "person" ("id") on delete cascade
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
onDelete(onDelete: OnModifyForeignAction): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Adds an `on update` constraint for the foreign key column.
|
||||
*
|
||||
* If your database engine doesn't support foreign key constraints in the
|
||||
* column definition (like MySQL 5) you need to call the table level
|
||||
* {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn(
|
||||
* 'owner_id',
|
||||
* 'integer',
|
||||
* (col) => col.references('person.id').onUpdate('cascade')
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table "pet" (
|
||||
* "owner_id" integer references "person" ("id") on update cascade
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
onUpdate(onUpdate: OnModifyForeignAction): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Adds a unique constraint for the column.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('email', 'varchar(255)', col => col.unique())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `email` varchar(255) unique
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
unique(): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Adds a `not null` constraint for the column.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('first_name', 'varchar(255)', col => col.notNull())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `first_name` varchar(255) not null
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
notNull(): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Adds a `unsigned` modifier for the column.
|
||||
*
|
||||
* This only works on some dialects like MySQL.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('age', 'integer', col => col.unsigned())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `age` integer unsigned
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
unsigned(): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Adds a default value constraint for the column.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn('number_of_legs', 'integer', (col) => col.defaultTo(4))
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `pet` (
|
||||
* `number_of_legs` integer default 4
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* Values passed to `defaultTo` are interpreted as value literals by default. You can define
|
||||
* an arbitrary SQL expression using the {@link sql} template tag:
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn(
|
||||
* 'created_at',
|
||||
* 'timestamp',
|
||||
* (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`)
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `pet` (
|
||||
* `created_at` timestamp default CURRENT_TIMESTAMP
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
defaultTo(value: DefaultValueExpression): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Adds a check constraint for the column.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn('number_of_legs', 'integer', (col) =>
|
||||
* col.check(sql`number_of_legs < 5`)
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `pet` (
|
||||
* `number_of_legs` integer check (number_of_legs < 5)
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
check(expression: Expression<any>): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Makes the column a generated column using a `generated always as` statement.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('full_name', 'varchar(255)',
|
||||
* (col) => col.generatedAlwaysAs(sql`concat(first_name, ' ', last_name)`)
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `full_name` varchar(255) generated always as (concat(first_name, ' ', last_name))
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
generatedAlwaysAs(expression: Expression<any>): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Adds the `generated always as identity` specifier.
|
||||
*
|
||||
* This only works on some dialects like PostgreSQL.
|
||||
*
|
||||
* For MS SQL Server (MSSQL)'s identity column use {@link identity}.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.generatedAlwaysAsIdentity().primaryKey())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table "person" (
|
||||
* "id" integer generated always as identity primary key
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
generatedAlwaysAsIdentity(): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Adds the `generated by default as identity` specifier on supported dialects.
|
||||
*
|
||||
* This only works on some dialects like PostgreSQL.
|
||||
*
|
||||
* For MS SQL Server (MSSQL)'s identity column use {@link identity}.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.generatedByDefaultAsIdentity().primaryKey())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table "person" (
|
||||
* "id" integer generated by default as identity primary key
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
generatedByDefaultAsIdentity(): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Makes a generated column stored instead of virtual. This method can only
|
||||
* be used with {@link generatedAlwaysAs}
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('full_name', 'varchar(255)', (col) => col
|
||||
* .generatedAlwaysAs(sql`concat(first_name, ' ', last_name)`)
|
||||
* .stored()
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `full_name` varchar(255) generated always as (concat(first_name, ' ', last_name)) stored
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
stored(): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* This can be used to add any additional SQL right after the column's data type.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey())
|
||||
* .addColumn(
|
||||
* 'first_name',
|
||||
* 'varchar(36)',
|
||||
* (col) => col.modifyFront(sql`collate utf8mb4_general_ci`).notNull()
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `id` integer primary key,
|
||||
* `first_name` varchar(36) collate utf8mb4_general_ci not null
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
modifyFront(modifier: Expression<any>): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Adds `nulls not distinct` specifier.
|
||||
* Should be used with `unique` constraint.
|
||||
*
|
||||
* This only works on some dialects like PostgreSQL.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey())
|
||||
* .addColumn('first_name', 'varchar(30)', col => col.unique().nullsNotDistinct())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table "person" (
|
||||
* "id" integer primary key,
|
||||
* "first_name" varchar(30) unique nulls not distinct
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
nullsNotDistinct(): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Adds `if not exists` specifier. This only works for PostgreSQL.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* .addColumn('email', 'varchar(255)', col => col.unique().ifNotExists())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* alter table "person" add column if not exists "email" varchar(255) unique
|
||||
* ```
|
||||
*/
|
||||
ifNotExists(): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* This can be used to add any additional SQL to the end of the column definition.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey())
|
||||
* .addColumn(
|
||||
* 'age',
|
||||
* 'integer',
|
||||
* col => col.unsigned()
|
||||
* .notNull()
|
||||
* .modifyEnd(sql`comment ${sql.lit('it is not polite to ask a woman her age')}`)
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `id` integer primary key,
|
||||
* `age` integer unsigned not null comment 'it is not polite to ask a woman her age'
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
modifyEnd(modifier: Expression<any>): ColumnDefinitionBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): ColumnDefinitionNode;
|
||||
}
|
||||
export type ColumnDefinitionBuilderCallback = (builder: ColumnDefinitionBuilder) => ColumnDefinitionBuilder;
|
||||
597
node_modules/kysely/dist/esm/schema/column-definition-builder.js
generated
vendored
Normal file
597
node_modules/kysely/dist/esm/schema/column-definition-builder.js
generated
vendored
Normal file
@@ -0,0 +1,597 @@
|
||||
/// <reference types="./column-definition-builder.d.ts" />
|
||||
import { CheckConstraintNode } from '../operation-node/check-constraint-node.js';
|
||||
import { ReferencesNode, } from '../operation-node/references-node.js';
|
||||
import { SelectAllNode } from '../operation-node/select-all-node.js';
|
||||
import { parseStringReference } from '../parser/reference-parser.js';
|
||||
import { ColumnDefinitionNode } from '../operation-node/column-definition-node.js';
|
||||
import { parseDefaultValueExpression, } from '../parser/default-value-parser.js';
|
||||
import { GeneratedNode } from '../operation-node/generated-node.js';
|
||||
import { DefaultValueNode } from '../operation-node/default-value-node.js';
|
||||
import { parseOnModifyForeignAction } from '../parser/on-modify-action-parser.js';
|
||||
export class ColumnDefinitionBuilder {
|
||||
#node;
|
||||
constructor(node) {
|
||||
this.#node = node;
|
||||
}
|
||||
/**
|
||||
* Adds `auto_increment` or `autoincrement` to the column definition
|
||||
* depending on the dialect.
|
||||
*
|
||||
* Some dialects like PostgreSQL don't support this. On PostgreSQL
|
||||
* you can use the `serial` or `bigserial` data type instead.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.autoIncrement().primaryKey())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `id` integer primary key auto_increment
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
autoIncrement() {
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, { autoIncrement: true }));
|
||||
}
|
||||
/**
|
||||
* Makes the column an identity column.
|
||||
*
|
||||
* This only works on some dialects like MS SQL Server (MSSQL).
|
||||
*
|
||||
* For PostgreSQL's `generated always as identity` use {@link generatedAlwaysAsIdentity}.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.identity().primaryKey())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MSSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table "person" (
|
||||
* "id" integer identity primary key
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
identity() {
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, { identity: true }));
|
||||
}
|
||||
/**
|
||||
* Makes the column the primary key.
|
||||
*
|
||||
* If you want to specify a composite primary key use the
|
||||
* {@link CreateTableBuilder.addPrimaryKeyConstraint} method.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `id` integer primary key
|
||||
* )
|
||||
*/
|
||||
primaryKey() {
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, { primaryKey: true }));
|
||||
}
|
||||
/**
|
||||
* Adds a foreign key constraint for the column.
|
||||
*
|
||||
* If your database engine doesn't support foreign key constraints in the
|
||||
* column definition (like MySQL 5) you need to call the table level
|
||||
* {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn('owner_id', 'integer', (col) => col.references('person.id'))
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table "pet" (
|
||||
* "owner_id" integer references "person" ("id")
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
references(ref) {
|
||||
const references = parseStringReference(ref);
|
||||
if (!references.table || SelectAllNode.is(references.column)) {
|
||||
throw new Error(`invalid call references('${ref}'). The reference must have format table.column or schema.table.column`);
|
||||
}
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, {
|
||||
references: ReferencesNode.create(references.table, [
|
||||
references.column,
|
||||
]),
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Adds an `on delete` constraint for the foreign key column.
|
||||
*
|
||||
* If your database engine doesn't support foreign key constraints in the
|
||||
* column definition (like MySQL 5) you need to call the table level
|
||||
* {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn(
|
||||
* 'owner_id',
|
||||
* 'integer',
|
||||
* (col) => col.references('person.id').onDelete('cascade')
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table "pet" (
|
||||
* "owner_id" integer references "person" ("id") on delete cascade
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
onDelete(onDelete) {
|
||||
if (!this.#node.references) {
|
||||
throw new Error('on delete constraint can only be added for foreign keys');
|
||||
}
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, {
|
||||
references: ReferencesNode.cloneWithOnDelete(this.#node.references, parseOnModifyForeignAction(onDelete)),
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Adds an `on update` constraint for the foreign key column.
|
||||
*
|
||||
* If your database engine doesn't support foreign key constraints in the
|
||||
* column definition (like MySQL 5) you need to call the table level
|
||||
* {@link CreateTableBuilder.addForeignKeyConstraint} method instead.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn(
|
||||
* 'owner_id',
|
||||
* 'integer',
|
||||
* (col) => col.references('person.id').onUpdate('cascade')
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table "pet" (
|
||||
* "owner_id" integer references "person" ("id") on update cascade
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
onUpdate(onUpdate) {
|
||||
if (!this.#node.references) {
|
||||
throw new Error('on update constraint can only be added for foreign keys');
|
||||
}
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, {
|
||||
references: ReferencesNode.cloneWithOnUpdate(this.#node.references, parseOnModifyForeignAction(onUpdate)),
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Adds a unique constraint for the column.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('email', 'varchar(255)', col => col.unique())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `email` varchar(255) unique
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
unique() {
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, { unique: true }));
|
||||
}
|
||||
/**
|
||||
* Adds a `not null` constraint for the column.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('first_name', 'varchar(255)', col => col.notNull())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `first_name` varchar(255) not null
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
notNull() {
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, { notNull: true }));
|
||||
}
|
||||
/**
|
||||
* Adds a `unsigned` modifier for the column.
|
||||
*
|
||||
* This only works on some dialects like MySQL.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('age', 'integer', col => col.unsigned())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `age` integer unsigned
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
unsigned() {
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, { unsigned: true }));
|
||||
}
|
||||
/**
|
||||
* Adds a default value constraint for the column.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn('number_of_legs', 'integer', (col) => col.defaultTo(4))
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `pet` (
|
||||
* `number_of_legs` integer default 4
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* Values passed to `defaultTo` are interpreted as value literals by default. You can define
|
||||
* an arbitrary SQL expression using the {@link sql} template tag:
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn(
|
||||
* 'created_at',
|
||||
* 'timestamp',
|
||||
* (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`)
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `pet` (
|
||||
* `created_at` timestamp default CURRENT_TIMESTAMP
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
defaultTo(value) {
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, {
|
||||
defaultTo: DefaultValueNode.create(parseDefaultValueExpression(value)),
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Adds a check constraint for the column.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn('number_of_legs', 'integer', (col) =>
|
||||
* col.check(sql`number_of_legs < 5`)
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `pet` (
|
||||
* `number_of_legs` integer check (number_of_legs < 5)
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
check(expression) {
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, {
|
||||
check: CheckConstraintNode.create(expression.toOperationNode()),
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Makes the column a generated column using a `generated always as` statement.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('full_name', 'varchar(255)',
|
||||
* (col) => col.generatedAlwaysAs(sql`concat(first_name, ' ', last_name)`)
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `full_name` varchar(255) generated always as (concat(first_name, ' ', last_name))
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
generatedAlwaysAs(expression) {
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, {
|
||||
generated: GeneratedNode.createWithExpression(expression.toOperationNode()),
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Adds the `generated always as identity` specifier.
|
||||
*
|
||||
* This only works on some dialects like PostgreSQL.
|
||||
*
|
||||
* For MS SQL Server (MSSQL)'s identity column use {@link identity}.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.generatedAlwaysAsIdentity().primaryKey())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table "person" (
|
||||
* "id" integer generated always as identity primary key
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
generatedAlwaysAsIdentity() {
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, {
|
||||
generated: GeneratedNode.create({ identity: true, always: true }),
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Adds the `generated by default as identity` specifier on supported dialects.
|
||||
*
|
||||
* This only works on some dialects like PostgreSQL.
|
||||
*
|
||||
* For MS SQL Server (MSSQL)'s identity column use {@link identity}.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.generatedByDefaultAsIdentity().primaryKey())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table "person" (
|
||||
* "id" integer generated by default as identity primary key
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
generatedByDefaultAsIdentity() {
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, {
|
||||
generated: GeneratedNode.create({ identity: true, byDefault: true }),
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Makes a generated column stored instead of virtual. This method can only
|
||||
* be used with {@link generatedAlwaysAs}
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('full_name', 'varchar(255)', (col) => col
|
||||
* .generatedAlwaysAs(sql`concat(first_name, ' ', last_name)`)
|
||||
* .stored()
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `full_name` varchar(255) generated always as (concat(first_name, ' ', last_name)) stored
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
stored() {
|
||||
if (!this.#node.generated) {
|
||||
throw new Error('stored() can only be called after generatedAlwaysAs');
|
||||
}
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, {
|
||||
generated: GeneratedNode.cloneWith(this.#node.generated, {
|
||||
stored: true,
|
||||
}),
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* This can be used to add any additional SQL right after the column's data type.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey())
|
||||
* .addColumn(
|
||||
* 'first_name',
|
||||
* 'varchar(36)',
|
||||
* (col) => col.modifyFront(sql`collate utf8mb4_general_ci`).notNull()
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `id` integer primary key,
|
||||
* `first_name` varchar(36) collate utf8mb4_general_ci not null
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
modifyFront(modifier) {
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWithFrontModifier(this.#node, modifier.toOperationNode()));
|
||||
}
|
||||
/**
|
||||
* Adds `nulls not distinct` specifier.
|
||||
* Should be used with `unique` constraint.
|
||||
*
|
||||
* This only works on some dialects like PostgreSQL.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey())
|
||||
* .addColumn('first_name', 'varchar(30)', col => col.unique().nullsNotDistinct())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table "person" (
|
||||
* "id" integer primary key,
|
||||
* "first_name" varchar(30) unique nulls not distinct
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
nullsNotDistinct() {
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, { nullsNotDistinct: true }));
|
||||
}
|
||||
/**
|
||||
* Adds `if not exists` specifier. This only works for PostgreSQL.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* .addColumn('email', 'varchar(255)', col => col.unique().ifNotExists())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* alter table "person" add column if not exists "email" varchar(255) unique
|
||||
* ```
|
||||
*/
|
||||
ifNotExists() {
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWith(this.#node, { ifNotExists: true }));
|
||||
}
|
||||
/**
|
||||
* This can be used to add any additional SQL to the end of the column definition.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey())
|
||||
* .addColumn(
|
||||
* 'age',
|
||||
* 'integer',
|
||||
* col => col.unsigned()
|
||||
* .notNull()
|
||||
* .modifyEnd(sql`comment ${sql.lit('it is not polite to ask a woman her age')}`)
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `id` integer primary key,
|
||||
* `age` integer unsigned not null comment 'it is not polite to ask a woman her age'
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
modifyEnd(modifier) {
|
||||
return new ColumnDefinitionBuilder(ColumnDefinitionNode.cloneWithEndModifier(this.#node, modifier.toOperationNode()));
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#node;
|
||||
}
|
||||
}
|
||||
173
node_modules/kysely/dist/esm/schema/create-index-builder.d.ts
generated
vendored
Normal file
173
node_modules/kysely/dist/esm/schema/create-index-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
import { CreateIndexNode, type IndexType } from '../operation-node/create-index-node.js';
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import { type ExtractColumnNameFromOrderedColumnName, type OrderedColumnName } from '../parser/reference-parser.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
import type { Expression } from '../expression/expression.js';
|
||||
import { type ComparisonOperatorExpression } from '../parser/binary-operation-parser.js';
|
||||
import type { ExpressionBuilder } from '../expression/expression-builder.js';
|
||||
import type { ShallowRecord, SqlBool } from '../util/type-utils.js';
|
||||
export declare class CreateIndexBuilder<C = never> implements OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: CreateIndexBuilderProps);
|
||||
/**
|
||||
* Adds the "if not exists" modifier.
|
||||
*
|
||||
* If the index already exists, no error is thrown if this method has been called.
|
||||
*/
|
||||
ifNotExists(): CreateIndexBuilder<C>;
|
||||
/**
|
||||
* Makes the index unique.
|
||||
*/
|
||||
unique(): CreateIndexBuilder<C>;
|
||||
/**
|
||||
* Adds `nulls not distinct` specifier to index.
|
||||
* This only works on some dialects like PostgreSQL.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* db.schema.createIndex('person_first_name_index')
|
||||
* .on('person')
|
||||
* .column('first_name')
|
||||
* .nullsNotDistinct()
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create index "person_first_name_index"
|
||||
* on "test" ("first_name")
|
||||
* nulls not distinct;
|
||||
* ```
|
||||
*/
|
||||
nullsNotDistinct(): CreateIndexBuilder<C>;
|
||||
/**
|
||||
* Specifies the table for the index.
|
||||
*/
|
||||
on(table: string): CreateIndexBuilder<C>;
|
||||
/**
|
||||
* Adds a column to the index.
|
||||
*
|
||||
* Also see {@link columns} for adding multiple columns at once or {@link expression}
|
||||
* for specifying an arbitrary expression.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createIndex('person_first_name_and_age_index')
|
||||
* .on('person')
|
||||
* .column('first_name')
|
||||
* .column('age desc')
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create index "person_first_name_and_age_index" on "person" ("first_name", "age" desc)
|
||||
* ```
|
||||
*/
|
||||
column<CL extends string>(column: OrderedColumnName<CL>): CreateIndexBuilder<C | ExtractColumnNameFromOrderedColumnName<CL>>;
|
||||
/**
|
||||
* Specifies a list of columns for the index.
|
||||
*
|
||||
* Also see {@link column} for adding a single column or {@link expression} for
|
||||
* specifying an arbitrary expression.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createIndex('person_first_name_and_age_index')
|
||||
* .on('person')
|
||||
* .columns(['first_name', 'age desc'])
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create index "person_first_name_and_age_index" on "person" ("first_name", "age" desc)
|
||||
* ```
|
||||
*/
|
||||
columns<CL extends string>(columns: OrderedColumnName<CL>[]): CreateIndexBuilder<C | ExtractColumnNameFromOrderedColumnName<CL>>;
|
||||
/**
|
||||
* Specifies an arbitrary expression for the index.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createIndex('person_first_name_index')
|
||||
* .on('person')
|
||||
* .expression(sql`first_name COLLATE "fi_FI"`)
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create index "person_first_name_index" on "person" (first_name COLLATE "fi_FI")
|
||||
* ```
|
||||
*/
|
||||
expression(expression: Expression<any>): CreateIndexBuilder<C>;
|
||||
/**
|
||||
* Specifies the index type.
|
||||
*/
|
||||
using(indexType: IndexType): CreateIndexBuilder<C>;
|
||||
using(indexType: string): CreateIndexBuilder<C>;
|
||||
/**
|
||||
* Adds a where clause to the query. This Effectively turns the index partial.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createIndex('orders_unbilled_index')
|
||||
* .on('orders')
|
||||
* .column('order_nr')
|
||||
* .where(sql.ref('billed'), 'is not', true)
|
||||
* .where('order_nr', 'like', '123%')
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create index "orders_unbilled_index" on "orders" ("order_nr") where "billed" is not true and "order_nr" like '123%'
|
||||
* ```
|
||||
*
|
||||
* Column names specified in {@link column} or {@link columns} are known at compile-time
|
||||
* and can be referred to in the current query and context.
|
||||
*
|
||||
* Sometimes you may want to refer to columns that exist in the table but are not
|
||||
* part of the current index. In that case you can refer to them using {@link sql}
|
||||
* expressions.
|
||||
*
|
||||
* Parameters are always sent as literals due to database restrictions.
|
||||
*/
|
||||
where(lhs: C | Expression<any>, op: ComparisonOperatorExpression, rhs: unknown): CreateIndexBuilder<C>;
|
||||
where(factory: (qb: ExpressionBuilder<ShallowRecord<string, ShallowRecord<C & string, any>>, string>) => Expression<SqlBool>): CreateIndexBuilder<C>;
|
||||
where(expression: Expression<SqlBool>): CreateIndexBuilder<C>;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): CreateIndexNode;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface CreateIndexBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: CreateIndexNode;
|
||||
}
|
||||
199
node_modules/kysely/dist/esm/schema/create-index-builder.js
generated
vendored
Normal file
199
node_modules/kysely/dist/esm/schema/create-index-builder.js
generated
vendored
Normal file
@@ -0,0 +1,199 @@
|
||||
/// <reference types="./create-index-builder.d.ts" />
|
||||
import { CreateIndexNode, } from '../operation-node/create-index-node.js';
|
||||
import { RawNode } from '../operation-node/raw-node.js';
|
||||
import { parseOrderedColumnName, } from '../parser/reference-parser.js';
|
||||
import { parseTable } from '../parser/table-parser.js';
|
||||
import { freeze } from '../util/object-utils.js';
|
||||
import { parseValueBinaryOperationOrExpression, } from '../parser/binary-operation-parser.js';
|
||||
import { QueryNode } from '../operation-node/query-node.js';
|
||||
import { ImmediateValueTransformer } from '../plugin/immediate-value/immediate-value-transformer.js';
|
||||
export class CreateIndexBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
/**
|
||||
* Adds the "if not exists" modifier.
|
||||
*
|
||||
* If the index already exists, no error is thrown if this method has been called.
|
||||
*/
|
||||
ifNotExists() {
|
||||
return new CreateIndexBuilder({
|
||||
...this.#props,
|
||||
node: CreateIndexNode.cloneWith(this.#props.node, {
|
||||
ifNotExists: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Makes the index unique.
|
||||
*/
|
||||
unique() {
|
||||
return new CreateIndexBuilder({
|
||||
...this.#props,
|
||||
node: CreateIndexNode.cloneWith(this.#props.node, {
|
||||
unique: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adds `nulls not distinct` specifier to index.
|
||||
* This only works on some dialects like PostgreSQL.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* db.schema.createIndex('person_first_name_index')
|
||||
* .on('person')
|
||||
* .column('first_name')
|
||||
* .nullsNotDistinct()
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create index "person_first_name_index"
|
||||
* on "test" ("first_name")
|
||||
* nulls not distinct;
|
||||
* ```
|
||||
*/
|
||||
nullsNotDistinct() {
|
||||
return new CreateIndexBuilder({
|
||||
...this.#props,
|
||||
node: CreateIndexNode.cloneWith(this.#props.node, {
|
||||
nullsNotDistinct: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Specifies the table for the index.
|
||||
*/
|
||||
on(table) {
|
||||
return new CreateIndexBuilder({
|
||||
...this.#props,
|
||||
node: CreateIndexNode.cloneWith(this.#props.node, {
|
||||
table: parseTable(table),
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adds a column to the index.
|
||||
*
|
||||
* Also see {@link columns} for adding multiple columns at once or {@link expression}
|
||||
* for specifying an arbitrary expression.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createIndex('person_first_name_and_age_index')
|
||||
* .on('person')
|
||||
* .column('first_name')
|
||||
* .column('age desc')
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create index "person_first_name_and_age_index" on "person" ("first_name", "age" desc)
|
||||
* ```
|
||||
*/
|
||||
column(column) {
|
||||
return new CreateIndexBuilder({
|
||||
...this.#props,
|
||||
node: CreateIndexNode.cloneWithColumns(this.#props.node, [
|
||||
parseOrderedColumnName(column),
|
||||
]),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Specifies a list of columns for the index.
|
||||
*
|
||||
* Also see {@link column} for adding a single column or {@link expression} for
|
||||
* specifying an arbitrary expression.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createIndex('person_first_name_and_age_index')
|
||||
* .on('person')
|
||||
* .columns(['first_name', 'age desc'])
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create index "person_first_name_and_age_index" on "person" ("first_name", "age" desc)
|
||||
* ```
|
||||
*/
|
||||
columns(columns) {
|
||||
return new CreateIndexBuilder({
|
||||
...this.#props,
|
||||
node: CreateIndexNode.cloneWithColumns(this.#props.node, columns.map(parseOrderedColumnName)),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Specifies an arbitrary expression for the index.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createIndex('person_first_name_index')
|
||||
* .on('person')
|
||||
* .expression(sql`first_name COLLATE "fi_FI"`)
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create index "person_first_name_index" on "person" (first_name COLLATE "fi_FI")
|
||||
* ```
|
||||
*/
|
||||
expression(expression) {
|
||||
return new CreateIndexBuilder({
|
||||
...this.#props,
|
||||
node: CreateIndexNode.cloneWithColumns(this.#props.node, [
|
||||
expression.toOperationNode(),
|
||||
]),
|
||||
});
|
||||
}
|
||||
using(indexType) {
|
||||
return new CreateIndexBuilder({
|
||||
...this.#props,
|
||||
node: CreateIndexNode.cloneWith(this.#props.node, {
|
||||
using: RawNode.createWithSql(indexType),
|
||||
}),
|
||||
});
|
||||
}
|
||||
where(...args) {
|
||||
const transformer = new ImmediateValueTransformer();
|
||||
return new CreateIndexBuilder({
|
||||
...this.#props,
|
||||
node: QueryNode.cloneWithWhere(this.#props.node, transformer.transformNode(parseValueBinaryOperationOrExpression(args), this.#props.queryId)),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
24
node_modules/kysely/dist/esm/schema/create-schema-builder.d.ts
generated
vendored
Normal file
24
node_modules/kysely/dist/esm/schema/create-schema-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { CreateSchemaNode } from '../operation-node/create-schema-node.js';
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
export declare class CreateSchemaBuilder implements OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: CreateSchemaBuilderProps);
|
||||
ifNotExists(): CreateSchemaBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): CreateSchemaNode;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface CreateSchemaBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: CreateSchemaNode;
|
||||
}
|
||||
31
node_modules/kysely/dist/esm/schema/create-schema-builder.js
generated
vendored
Normal file
31
node_modules/kysely/dist/esm/schema/create-schema-builder.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/// <reference types="./create-schema-builder.d.ts" />
|
||||
import { CreateSchemaNode } from '../operation-node/create-schema-node.js';
|
||||
import { freeze } from '../util/object-utils.js';
|
||||
export class CreateSchemaBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
ifNotExists() {
|
||||
return new CreateSchemaBuilder({
|
||||
...this.#props,
|
||||
node: CreateSchemaNode.cloneWith(this.#props.node, { ifNotExists: true }),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
331
node_modules/kysely/dist/esm/schema/create-table-builder.d.ts
generated
vendored
Normal file
331
node_modules/kysely/dist/esm/schema/create-table-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,331 @@
|
||||
import { CreateTableNode, type OnCommitAction } from '../operation-node/create-table-node.js';
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import { ColumnDefinitionBuilder } from './column-definition-builder.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
import { type ForeignKeyConstraintBuilderCallback } from './foreign-key-constraint-builder.js';
|
||||
import { type DataTypeExpression } from '../parser/data-type-parser.js';
|
||||
import type { Expression } from '../expression/expression.js';
|
||||
import { type UniqueConstraintNodeBuilderCallback } from './unique-constraint-builder.js';
|
||||
import { type PrimaryKeyConstraintBuilderCallback } from './primary-key-constraint-builder.js';
|
||||
import { type CheckConstraintBuilderCallback } from './check-constraint-builder.js';
|
||||
/**
|
||||
* This builder can be used to create a `create table` query.
|
||||
*/
|
||||
export declare class CreateTableBuilder<TB extends string, C extends string = never> implements OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: CreateTableBuilderProps);
|
||||
/**
|
||||
* Adds the "temporary" modifier.
|
||||
*
|
||||
* Use this to create a temporary table.
|
||||
*/
|
||||
temporary(): CreateTableBuilder<TB, C>;
|
||||
/**
|
||||
* Adds an "on commit" statement.
|
||||
*
|
||||
* This can be used in conjunction with temporary tables on supported databases
|
||||
* like PostgreSQL.
|
||||
*/
|
||||
onCommit(onCommit: OnCommitAction): CreateTableBuilder<TB, C>;
|
||||
/**
|
||||
* Adds the "if not exists" modifier.
|
||||
*
|
||||
* If the table already exists, no error is thrown if this method has been called.
|
||||
*/
|
||||
ifNotExists(): CreateTableBuilder<TB, C>;
|
||||
/**
|
||||
* Adds a column to the table.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', (col) => col.autoIncrement().primaryKey())
|
||||
* .addColumn('first_name', 'varchar(50)', (col) => col.notNull())
|
||||
* .addColumn('last_name', 'varchar(255)')
|
||||
* .addColumn('bank_balance', 'numeric(8, 2)')
|
||||
* // You can specify any data type using the `sql` tag if the types
|
||||
* // don't include it.
|
||||
* .addColumn('data', sql`any_type_here`)
|
||||
* .addColumn('parent_id', 'integer', (col) =>
|
||||
* col.references('person.id').onDelete('cascade')
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* With this method, it's once again good to remember that Kysely just builds the
|
||||
* query and doesn't provide the same API for all databases. For example, some
|
||||
* databases like older MySQL don't support the `references` statement in the
|
||||
* column definition. Instead foreign key constraints need to be defined in the
|
||||
* `create table` query. See the next example:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', (col) => col.primaryKey())
|
||||
* .addColumn('parent_id', 'integer')
|
||||
* .addForeignKeyConstraint(
|
||||
* 'person_parent_id_fk',
|
||||
* ['parent_id'],
|
||||
* 'person',
|
||||
* ['id'],
|
||||
* (cb) => cb.onDelete('cascade')
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* Another good example is that PostgreSQL doesn't support the `auto_increment`
|
||||
* keyword and you need to define an autoincrementing column for example using
|
||||
* `serial`:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'serial', (col) => col.primaryKey())
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
addColumn<CN extends string>(columnName: CN, dataType: DataTypeExpression, build?: ColumnBuilderCallback): CreateTableBuilder<TB, C | CN>;
|
||||
/**
|
||||
* Adds a primary key constraint for one or more columns.
|
||||
*
|
||||
* The constraint name can be anything you want, but it must be unique
|
||||
* across the whole database.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('first_name', 'varchar(64)')
|
||||
* .addColumn('last_name', 'varchar(64)')
|
||||
* .addPrimaryKeyConstraint('primary_key', ['first_name', 'last_name'])
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
addPrimaryKeyConstraint(constraintName: string, columns: C[], build?: PrimaryKeyConstraintBuilderCallback): CreateTableBuilder<TB, C>;
|
||||
/**
|
||||
* Adds a unique constraint for one or more columns.
|
||||
*
|
||||
* The constraint name can be anything you want, but it must be unique
|
||||
* across the whole database.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('first_name', 'varchar(64)')
|
||||
* .addColumn('last_name', 'varchar(64)')
|
||||
* .addUniqueConstraint(
|
||||
* 'first_name_last_name_unique',
|
||||
* ['first_name', 'last_name']
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* In dialects such as PostgreSQL you can specify `nulls not distinct` as follows:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('first_name', 'varchar(64)')
|
||||
* .addColumn('last_name', 'varchar(64)')
|
||||
* .addUniqueConstraint(
|
||||
* 'first_name_last_name_unique',
|
||||
* ['first_name', 'last_name'],
|
||||
* (cb) => cb.nullsNotDistinct()
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
addUniqueConstraint(constraintName: string, columns: C[], build?: UniqueConstraintNodeBuilderCallback): CreateTableBuilder<TB, C>;
|
||||
/**
|
||||
* Adds a check constraint.
|
||||
*
|
||||
* The constraint name can be anything you want, but it must be unique
|
||||
* across the whole database.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('animal')
|
||||
* .addColumn('number_of_legs', 'integer')
|
||||
* .addCheckConstraint('check_legs', sql`number_of_legs < 5`)
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
addCheckConstraint(constraintName: string, checkExpression: Expression<any>, build?: CheckConstraintBuilderCallback): CreateTableBuilder<TB, C>;
|
||||
/**
|
||||
* Adds a foreign key constraint.
|
||||
*
|
||||
* The constraint name can be anything you want, but it must be unique
|
||||
* across the whole database.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn('owner_id', 'integer')
|
||||
* .addForeignKeyConstraint(
|
||||
* 'owner_id_foreign',
|
||||
* ['owner_id'],
|
||||
* 'person',
|
||||
* ['id'],
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* Add constraint for multiple columns:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn('owner_id1', 'integer')
|
||||
* .addColumn('owner_id2', 'integer')
|
||||
* .addForeignKeyConstraint(
|
||||
* 'owner_id_foreign',
|
||||
* ['owner_id1', 'owner_id2'],
|
||||
* 'person',
|
||||
* ['id1', 'id2'],
|
||||
* (cb) => cb.onDelete('cascade')
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
addForeignKeyConstraint(constraintName: string, columns: C[], targetTable: string, targetColumns: string[], build?: ForeignKeyConstraintBuilderCallback): CreateTableBuilder<TB, C>;
|
||||
/**
|
||||
* This can be used to add any additional SQL to the front of the query __after__ the `create` keyword.
|
||||
*
|
||||
* Also see {@link temporary}.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .modifyFront(sql`global temporary`)
|
||||
* .addColumn('id', 'integer', col => col.primaryKey())
|
||||
* .addColumn('first_name', 'varchar(64)', col => col.notNull())
|
||||
* .addColumn('last_name', 'varchar(64)', col => col.notNull())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (Postgres):
|
||||
*
|
||||
* ```sql
|
||||
* create global temporary table "person" (
|
||||
* "id" integer primary key,
|
||||
* "first_name" varchar(64) not null,
|
||||
* "last_name" varchar(64) not null
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
modifyFront(modifier: Expression<any>): CreateTableBuilder<TB, C>;
|
||||
/**
|
||||
* This can be used to add any additional SQL to the end of the query.
|
||||
*
|
||||
* Also see {@link onCommit}.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey())
|
||||
* .addColumn('first_name', 'varchar(64)', col => col.notNull())
|
||||
* .addColumn('last_name', 'varchar(64)', col => col.notNull())
|
||||
* .modifyEnd(sql`collate utf8_unicode_ci`)
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `id` integer primary key,
|
||||
* `first_name` varchar(64) not null,
|
||||
* `last_name` varchar(64) not null
|
||||
* ) collate utf8_unicode_ci
|
||||
* ```
|
||||
*/
|
||||
modifyEnd(modifier: Expression<any>): CreateTableBuilder<TB, C>;
|
||||
/**
|
||||
* Allows to create table from `select` query.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('copy')
|
||||
* .temporary()
|
||||
* .as(db.selectFrom('person').select(['first_name', 'last_name']))
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create temporary table "copy" as
|
||||
* select "first_name", "last_name" from "person"
|
||||
* ```
|
||||
*/
|
||||
as(expression: Expression<unknown>): CreateTableBuilder<TB, C>;
|
||||
/**
|
||||
* Calls the given function passing `this` as the only argument.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('test')
|
||||
* .$call((builder) => builder.addColumn('id', 'integer'))
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* This is useful for creating reusable functions that can be called with a builder.
|
||||
*
|
||||
* ```ts
|
||||
* import { type CreateTableBuilder, sql } from 'kysely'
|
||||
*
|
||||
* const addDefaultColumns = (ctb: CreateTableBuilder<any, any>) => {
|
||||
* return ctb
|
||||
* .addColumn('id', 'integer', (col) => col.notNull())
|
||||
* .addColumn('created_at', 'date', (col) =>
|
||||
* col.notNull().defaultTo(sql`now()`)
|
||||
* )
|
||||
* .addColumn('updated_at', 'date', (col) =>
|
||||
* col.notNull().defaultTo(sql`now()`)
|
||||
* )
|
||||
* }
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('test')
|
||||
* .$call(addDefaultColumns)
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): CreateTableNode;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface CreateTableBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: CreateTableNode;
|
||||
}
|
||||
export type ColumnBuilderCallback = (builder: ColumnDefinitionBuilder) => ColumnDefinitionBuilder;
|
||||
408
node_modules/kysely/dist/esm/schema/create-table-builder.js
generated
vendored
Normal file
408
node_modules/kysely/dist/esm/schema/create-table-builder.js
generated
vendored
Normal file
@@ -0,0 +1,408 @@
|
||||
/// <reference types="./create-table-builder.d.ts" />
|
||||
import { ColumnDefinitionNode } from '../operation-node/column-definition-node.js';
|
||||
import { CreateTableNode, } from '../operation-node/create-table-node.js';
|
||||
import { ColumnDefinitionBuilder } from './column-definition-builder.js';
|
||||
import { freeze, noop } from '../util/object-utils.js';
|
||||
import { ForeignKeyConstraintNode } from '../operation-node/foreign-key-constraint-node.js';
|
||||
import { ColumnNode } from '../operation-node/column-node.js';
|
||||
import { ForeignKeyConstraintBuilder, } from './foreign-key-constraint-builder.js';
|
||||
import { parseDataTypeExpression, } from '../parser/data-type-parser.js';
|
||||
import { PrimaryKeyConstraintNode } from '../operation-node/primary-key-constraint-node.js';
|
||||
import { UniqueConstraintNode } from '../operation-node/unique-constraint-node.js';
|
||||
import { CheckConstraintNode } from '../operation-node/check-constraint-node.js';
|
||||
import { parseTable } from '../parser/table-parser.js';
|
||||
import { parseOnCommitAction } from '../parser/on-commit-action-parse.js';
|
||||
import { UniqueConstraintNodeBuilder, } from './unique-constraint-builder.js';
|
||||
import { parseExpression } from '../parser/expression-parser.js';
|
||||
import { PrimaryKeyConstraintBuilder, } from './primary-key-constraint-builder.js';
|
||||
import { CheckConstraintBuilder, } from './check-constraint-builder.js';
|
||||
/**
|
||||
* This builder can be used to create a `create table` query.
|
||||
*/
|
||||
export class CreateTableBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
/**
|
||||
* Adds the "temporary" modifier.
|
||||
*
|
||||
* Use this to create a temporary table.
|
||||
*/
|
||||
temporary() {
|
||||
return new CreateTableBuilder({
|
||||
...this.#props,
|
||||
node: CreateTableNode.cloneWith(this.#props.node, {
|
||||
temporary: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adds an "on commit" statement.
|
||||
*
|
||||
* This can be used in conjunction with temporary tables on supported databases
|
||||
* like PostgreSQL.
|
||||
*/
|
||||
onCommit(onCommit) {
|
||||
return new CreateTableBuilder({
|
||||
...this.#props,
|
||||
node: CreateTableNode.cloneWith(this.#props.node, {
|
||||
onCommit: parseOnCommitAction(onCommit),
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adds the "if not exists" modifier.
|
||||
*
|
||||
* If the table already exists, no error is thrown if this method has been called.
|
||||
*/
|
||||
ifNotExists() {
|
||||
return new CreateTableBuilder({
|
||||
...this.#props,
|
||||
node: CreateTableNode.cloneWith(this.#props.node, {
|
||||
ifNotExists: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adds a column to the table.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', (col) => col.autoIncrement().primaryKey())
|
||||
* .addColumn('first_name', 'varchar(50)', (col) => col.notNull())
|
||||
* .addColumn('last_name', 'varchar(255)')
|
||||
* .addColumn('bank_balance', 'numeric(8, 2)')
|
||||
* // You can specify any data type using the `sql` tag if the types
|
||||
* // don't include it.
|
||||
* .addColumn('data', sql`any_type_here`)
|
||||
* .addColumn('parent_id', 'integer', (col) =>
|
||||
* col.references('person.id').onDelete('cascade')
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* With this method, it's once again good to remember that Kysely just builds the
|
||||
* query and doesn't provide the same API for all databases. For example, some
|
||||
* databases like older MySQL don't support the `references` statement in the
|
||||
* column definition. Instead foreign key constraints need to be defined in the
|
||||
* `create table` query. See the next example:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', (col) => col.primaryKey())
|
||||
* .addColumn('parent_id', 'integer')
|
||||
* .addForeignKeyConstraint(
|
||||
* 'person_parent_id_fk',
|
||||
* ['parent_id'],
|
||||
* 'person',
|
||||
* ['id'],
|
||||
* (cb) => cb.onDelete('cascade')
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* Another good example is that PostgreSQL doesn't support the `auto_increment`
|
||||
* keyword and you need to define an autoincrementing column for example using
|
||||
* `serial`:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'serial', (col) => col.primaryKey())
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
addColumn(columnName, dataType, build = noop) {
|
||||
const columnBuilder = build(new ColumnDefinitionBuilder(ColumnDefinitionNode.create(columnName, parseDataTypeExpression(dataType))));
|
||||
return new CreateTableBuilder({
|
||||
...this.#props,
|
||||
node: CreateTableNode.cloneWithColumn(this.#props.node, columnBuilder.toOperationNode()),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adds a primary key constraint for one or more columns.
|
||||
*
|
||||
* The constraint name can be anything you want, but it must be unique
|
||||
* across the whole database.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('first_name', 'varchar(64)')
|
||||
* .addColumn('last_name', 'varchar(64)')
|
||||
* .addPrimaryKeyConstraint('primary_key', ['first_name', 'last_name'])
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
addPrimaryKeyConstraint(constraintName, columns, build = noop) {
|
||||
const constraintBuilder = build(new PrimaryKeyConstraintBuilder(PrimaryKeyConstraintNode.create(columns, constraintName)));
|
||||
return new CreateTableBuilder({
|
||||
...this.#props,
|
||||
node: CreateTableNode.cloneWithConstraint(this.#props.node, constraintBuilder.toOperationNode()),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adds a unique constraint for one or more columns.
|
||||
*
|
||||
* The constraint name can be anything you want, but it must be unique
|
||||
* across the whole database.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('first_name', 'varchar(64)')
|
||||
* .addColumn('last_name', 'varchar(64)')
|
||||
* .addUniqueConstraint(
|
||||
* 'first_name_last_name_unique',
|
||||
* ['first_name', 'last_name']
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* In dialects such as PostgreSQL you can specify `nulls not distinct` as follows:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('first_name', 'varchar(64)')
|
||||
* .addColumn('last_name', 'varchar(64)')
|
||||
* .addUniqueConstraint(
|
||||
* 'first_name_last_name_unique',
|
||||
* ['first_name', 'last_name'],
|
||||
* (cb) => cb.nullsNotDistinct()
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
addUniqueConstraint(constraintName, columns, build = noop) {
|
||||
const uniqueConstraintBuilder = build(new UniqueConstraintNodeBuilder(UniqueConstraintNode.create(columns, constraintName)));
|
||||
return new CreateTableBuilder({
|
||||
...this.#props,
|
||||
node: CreateTableNode.cloneWithConstraint(this.#props.node, uniqueConstraintBuilder.toOperationNode()),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adds a check constraint.
|
||||
*
|
||||
* The constraint name can be anything you want, but it must be unique
|
||||
* across the whole database.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('animal')
|
||||
* .addColumn('number_of_legs', 'integer')
|
||||
* .addCheckConstraint('check_legs', sql`number_of_legs < 5`)
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
addCheckConstraint(constraintName, checkExpression, build = noop) {
|
||||
const constraintBuilder = build(new CheckConstraintBuilder(CheckConstraintNode.create(checkExpression.toOperationNode(), constraintName)));
|
||||
return new CreateTableBuilder({
|
||||
...this.#props,
|
||||
node: CreateTableNode.cloneWithConstraint(this.#props.node, constraintBuilder.toOperationNode()),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adds a foreign key constraint.
|
||||
*
|
||||
* The constraint name can be anything you want, but it must be unique
|
||||
* across the whole database.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn('owner_id', 'integer')
|
||||
* .addForeignKeyConstraint(
|
||||
* 'owner_id_foreign',
|
||||
* ['owner_id'],
|
||||
* 'person',
|
||||
* ['id'],
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* Add constraint for multiple columns:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn('owner_id1', 'integer')
|
||||
* .addColumn('owner_id2', 'integer')
|
||||
* .addForeignKeyConstraint(
|
||||
* 'owner_id_foreign',
|
||||
* ['owner_id1', 'owner_id2'],
|
||||
* 'person',
|
||||
* ['id1', 'id2'],
|
||||
* (cb) => cb.onDelete('cascade')
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
addForeignKeyConstraint(constraintName, columns, targetTable, targetColumns, build = noop) {
|
||||
const builder = build(new ForeignKeyConstraintBuilder(ForeignKeyConstraintNode.create(columns.map(ColumnNode.create), parseTable(targetTable), targetColumns.map(ColumnNode.create), constraintName)));
|
||||
return new CreateTableBuilder({
|
||||
...this.#props,
|
||||
node: CreateTableNode.cloneWithConstraint(this.#props.node, builder.toOperationNode()),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* This can be used to add any additional SQL to the front of the query __after__ the `create` keyword.
|
||||
*
|
||||
* Also see {@link temporary}.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .modifyFront(sql`global temporary`)
|
||||
* .addColumn('id', 'integer', col => col.primaryKey())
|
||||
* .addColumn('first_name', 'varchar(64)', col => col.notNull())
|
||||
* .addColumn('last_name', 'varchar(64)', col => col.notNull())
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (Postgres):
|
||||
*
|
||||
* ```sql
|
||||
* create global temporary table "person" (
|
||||
* "id" integer primary key,
|
||||
* "first_name" varchar(64) not null,
|
||||
* "last_name" varchar(64) not null
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
modifyFront(modifier) {
|
||||
return new CreateTableBuilder({
|
||||
...this.#props,
|
||||
node: CreateTableNode.cloneWithFrontModifier(this.#props.node, modifier.toOperationNode()),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* This can be used to add any additional SQL to the end of the query.
|
||||
*
|
||||
* Also see {@link onCommit}.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey())
|
||||
* .addColumn('first_name', 'varchar(64)', col => col.notNull())
|
||||
* .addColumn('last_name', 'varchar(64)', col => col.notNull())
|
||||
* .modifyEnd(sql`collate utf8_unicode_ci`)
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (MySQL):
|
||||
*
|
||||
* ```sql
|
||||
* create table `person` (
|
||||
* `id` integer primary key,
|
||||
* `first_name` varchar(64) not null,
|
||||
* `last_name` varchar(64) not null
|
||||
* ) collate utf8_unicode_ci
|
||||
* ```
|
||||
*/
|
||||
modifyEnd(modifier) {
|
||||
return new CreateTableBuilder({
|
||||
...this.#props,
|
||||
node: CreateTableNode.cloneWithEndModifier(this.#props.node, modifier.toOperationNode()),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Allows to create table from `select` query.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('copy')
|
||||
* .temporary()
|
||||
* .as(db.selectFrom('person').select(['first_name', 'last_name']))
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create temporary table "copy" as
|
||||
* select "first_name", "last_name" from "person"
|
||||
* ```
|
||||
*/
|
||||
as(expression) {
|
||||
return new CreateTableBuilder({
|
||||
...this.#props,
|
||||
node: CreateTableNode.cloneWith(this.#props.node, {
|
||||
selectQuery: parseExpression(expression),
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Calls the given function passing `this` as the only argument.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('test')
|
||||
* .$call((builder) => builder.addColumn('id', 'integer'))
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* This is useful for creating reusable functions that can be called with a builder.
|
||||
*
|
||||
* ```ts
|
||||
* import { type CreateTableBuilder, sql } from 'kysely'
|
||||
*
|
||||
* const addDefaultColumns = (ctb: CreateTableBuilder<any, any>) => {
|
||||
* return ctb
|
||||
* .addColumn('id', 'integer', (col) => col.notNull())
|
||||
* .addColumn('created_at', 'date', (col) =>
|
||||
* col.notNull().defaultTo(sql`now()`)
|
||||
* )
|
||||
* .addColumn('updated_at', 'date', (col) =>
|
||||
* col.notNull().defaultTo(sql`now()`)
|
||||
* )
|
||||
* }
|
||||
*
|
||||
* await db.schema
|
||||
* .createTable('test')
|
||||
* .$call(addDefaultColumns)
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
33
node_modules/kysely/dist/esm/schema/create-type-builder.d.ts
generated
vendored
Normal file
33
node_modules/kysely/dist/esm/schema/create-type-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
import { CreateTypeNode } from '../operation-node/create-type-node.js';
|
||||
export declare class CreateTypeBuilder implements OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: CreateTypeBuilderProps);
|
||||
toOperationNode(): CreateTypeNode;
|
||||
/**
|
||||
* Creates an anum type.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* db.schema.createType('species').asEnum(['cat', 'dog', 'frog'])
|
||||
* ```
|
||||
*/
|
||||
asEnum(values: readonly string[]): CreateTypeBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface CreateTypeBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: CreateTypeNode;
|
||||
}
|
||||
40
node_modules/kysely/dist/esm/schema/create-type-builder.js
generated
vendored
Normal file
40
node_modules/kysely/dist/esm/schema/create-type-builder.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/// <reference types="./create-type-builder.d.ts" />
|
||||
import { freeze } from '../util/object-utils.js';
|
||||
import { CreateTypeNode } from '../operation-node/create-type-node.js';
|
||||
export class CreateTypeBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
||||
}
|
||||
/**
|
||||
* Creates an anum type.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* db.schema.createType('species').asEnum(['cat', 'dog', 'frog'])
|
||||
* ```
|
||||
*/
|
||||
asEnum(values) {
|
||||
return new CreateTypeBuilder({
|
||||
...this.#props,
|
||||
node: CreateTypeNode.cloneWithEnum(this.#props.node, values),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
48
node_modules/kysely/dist/esm/schema/create-view-builder.d.ts
generated
vendored
Normal file
48
node_modules/kysely/dist/esm/schema/create-view-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
import { CreateViewNode } from '../operation-node/create-view-node.js';
|
||||
import type { RawBuilder } from '../raw-builder/raw-builder.js';
|
||||
import type { SelectQueryBuilder } from '../query-builder/select-query-builder.js';
|
||||
export declare class CreateViewBuilder implements OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: CreateViewBuilderProps);
|
||||
/**
|
||||
* Adds the "temporary" modifier.
|
||||
*
|
||||
* Use this to create a temporary view.
|
||||
*/
|
||||
temporary(): CreateViewBuilder;
|
||||
materialized(): CreateViewBuilder;
|
||||
/**
|
||||
* Only implemented on some dialects like SQLite. On most dialects, use {@link orReplace}.
|
||||
*/
|
||||
ifNotExists(): CreateViewBuilder;
|
||||
orReplace(): CreateViewBuilder;
|
||||
columns(columns: string[]): CreateViewBuilder;
|
||||
/**
|
||||
* Sets the select query or a `values` statement that creates the view.
|
||||
*
|
||||
* WARNING!
|
||||
* Some dialects don't support parameterized queries in DDL statements and therefore
|
||||
* the query or raw {@link sql } expression passed here is interpolated into a single
|
||||
* string opening an SQL injection vulnerability. DO NOT pass unchecked user input
|
||||
* into the query or raw expression passed to this method!
|
||||
*/
|
||||
as(query: SelectQueryBuilder<any, any, any> | RawBuilder<any>): CreateViewBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): CreateViewNode;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface CreateViewBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: CreateViewNode;
|
||||
}
|
||||
95
node_modules/kysely/dist/esm/schema/create-view-builder.js
generated
vendored
Normal file
95
node_modules/kysely/dist/esm/schema/create-view-builder.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/// <reference types="./create-view-builder.d.ts" />
|
||||
import { freeze } from '../util/object-utils.js';
|
||||
import { CreateViewNode } from '../operation-node/create-view-node.js';
|
||||
import { parseColumnName } from '../parser/reference-parser.js';
|
||||
import { ImmediateValuePlugin } from '../plugin/immediate-value/immediate-value-plugin.js';
|
||||
export class CreateViewBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
/**
|
||||
* Adds the "temporary" modifier.
|
||||
*
|
||||
* Use this to create a temporary view.
|
||||
*/
|
||||
temporary() {
|
||||
return new CreateViewBuilder({
|
||||
...this.#props,
|
||||
node: CreateViewNode.cloneWith(this.#props.node, {
|
||||
temporary: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
materialized() {
|
||||
return new CreateViewBuilder({
|
||||
...this.#props,
|
||||
node: CreateViewNode.cloneWith(this.#props.node, {
|
||||
materialized: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Only implemented on some dialects like SQLite. On most dialects, use {@link orReplace}.
|
||||
*/
|
||||
ifNotExists() {
|
||||
return new CreateViewBuilder({
|
||||
...this.#props,
|
||||
node: CreateViewNode.cloneWith(this.#props.node, {
|
||||
ifNotExists: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
orReplace() {
|
||||
return new CreateViewBuilder({
|
||||
...this.#props,
|
||||
node: CreateViewNode.cloneWith(this.#props.node, {
|
||||
orReplace: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
columns(columns) {
|
||||
return new CreateViewBuilder({
|
||||
...this.#props,
|
||||
node: CreateViewNode.cloneWith(this.#props.node, {
|
||||
columns: columns.map(parseColumnName),
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Sets the select query or a `values` statement that creates the view.
|
||||
*
|
||||
* WARNING!
|
||||
* Some dialects don't support parameterized queries in DDL statements and therefore
|
||||
* the query or raw {@link sql } expression passed here is interpolated into a single
|
||||
* string opening an SQL injection vulnerability. DO NOT pass unchecked user input
|
||||
* into the query or raw expression passed to this method!
|
||||
*/
|
||||
as(query) {
|
||||
const queryNode = query
|
||||
.withPlugin(new ImmediateValuePlugin())
|
||||
.toOperationNode();
|
||||
return new CreateViewBuilder({
|
||||
...this.#props,
|
||||
node: CreateViewNode.cloneWith(this.#props.node, {
|
||||
as: queryNode,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
30
node_modules/kysely/dist/esm/schema/drop-index-builder.d.ts
generated
vendored
Normal file
30
node_modules/kysely/dist/esm/schema/drop-index-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { DropIndexNode } from '../operation-node/drop-index-node.js';
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
export declare class DropIndexBuilder implements OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: DropIndexBuilderProps);
|
||||
/**
|
||||
* Specifies the table the index was created for. This is not needed
|
||||
* in all dialects.
|
||||
*/
|
||||
on(table: string): DropIndexBuilder;
|
||||
ifExists(): DropIndexBuilder;
|
||||
cascade(): DropIndexBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): DropIndexNode;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface DropIndexBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: DropIndexNode;
|
||||
}
|
||||
54
node_modules/kysely/dist/esm/schema/drop-index-builder.js
generated
vendored
Normal file
54
node_modules/kysely/dist/esm/schema/drop-index-builder.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
/// <reference types="./drop-index-builder.d.ts" />
|
||||
import { DropIndexNode } from '../operation-node/drop-index-node.js';
|
||||
import { parseTable } from '../parser/table-parser.js';
|
||||
import { freeze } from '../util/object-utils.js';
|
||||
export class DropIndexBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
/**
|
||||
* Specifies the table the index was created for. This is not needed
|
||||
* in all dialects.
|
||||
*/
|
||||
on(table) {
|
||||
return new DropIndexBuilder({
|
||||
...this.#props,
|
||||
node: DropIndexNode.cloneWith(this.#props.node, {
|
||||
table: parseTable(table),
|
||||
}),
|
||||
});
|
||||
}
|
||||
ifExists() {
|
||||
return new DropIndexBuilder({
|
||||
...this.#props,
|
||||
node: DropIndexNode.cloneWith(this.#props.node, {
|
||||
ifExists: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
cascade() {
|
||||
return new DropIndexBuilder({
|
||||
...this.#props,
|
||||
node: DropIndexNode.cloneWith(this.#props.node, {
|
||||
cascade: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
25
node_modules/kysely/dist/esm/schema/drop-schema-builder.d.ts
generated
vendored
Normal file
25
node_modules/kysely/dist/esm/schema/drop-schema-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { DropSchemaNode } from '../operation-node/drop-schema-node.js';
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
export declare class DropSchemaBuilder implements OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: DropSchemaBuilderProps);
|
||||
ifExists(): DropSchemaBuilder;
|
||||
cascade(): DropSchemaBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): DropSchemaNode;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface DropSchemaBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: DropSchemaNode;
|
||||
}
|
||||
41
node_modules/kysely/dist/esm/schema/drop-schema-builder.js
generated
vendored
Normal file
41
node_modules/kysely/dist/esm/schema/drop-schema-builder.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
/// <reference types="./drop-schema-builder.d.ts" />
|
||||
import { DropSchemaNode } from '../operation-node/drop-schema-node.js';
|
||||
import { freeze } from '../util/object-utils.js';
|
||||
export class DropSchemaBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
ifExists() {
|
||||
return new DropSchemaBuilder({
|
||||
...this.#props,
|
||||
node: DropSchemaNode.cloneWith(this.#props.node, {
|
||||
ifExists: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
cascade() {
|
||||
return new DropSchemaBuilder({
|
||||
...this.#props,
|
||||
node: DropSchemaNode.cloneWith(this.#props.node, {
|
||||
cascade: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
25
node_modules/kysely/dist/esm/schema/drop-table-builder.d.ts
generated
vendored
Normal file
25
node_modules/kysely/dist/esm/schema/drop-table-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { DropTableNode } from '../operation-node/drop-table-node.js';
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
export declare class DropTableBuilder implements OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: DropTableBuilderProps);
|
||||
ifExists(): DropTableBuilder;
|
||||
cascade(): DropTableBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): DropTableNode;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface DropTableBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: DropTableNode;
|
||||
}
|
||||
41
node_modules/kysely/dist/esm/schema/drop-table-builder.js
generated
vendored
Normal file
41
node_modules/kysely/dist/esm/schema/drop-table-builder.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
/// <reference types="./drop-table-builder.d.ts" />
|
||||
import { DropTableNode } from '../operation-node/drop-table-node.js';
|
||||
import { freeze } from '../util/object-utils.js';
|
||||
export class DropTableBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
ifExists() {
|
||||
return new DropTableBuilder({
|
||||
...this.#props,
|
||||
node: DropTableNode.cloneWith(this.#props.node, {
|
||||
ifExists: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
cascade() {
|
||||
return new DropTableBuilder({
|
||||
...this.#props,
|
||||
node: DropTableNode.cloneWith(this.#props.node, {
|
||||
cascade: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
24
node_modules/kysely/dist/esm/schema/drop-type-builder.d.ts
generated
vendored
Normal file
24
node_modules/kysely/dist/esm/schema/drop-type-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { DropTypeNode } from '../operation-node/drop-type-node.js';
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
export declare class DropTypeBuilder implements OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: DropTypeBuilderProps);
|
||||
ifExists(): DropTypeBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): DropTypeNode;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface DropTypeBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: DropTypeNode;
|
||||
}
|
||||
33
node_modules/kysely/dist/esm/schema/drop-type-builder.js
generated
vendored
Normal file
33
node_modules/kysely/dist/esm/schema/drop-type-builder.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/// <reference types="./drop-type-builder.d.ts" />
|
||||
import { DropTypeNode } from '../operation-node/drop-type-node.js';
|
||||
import { freeze } from '../util/object-utils.js';
|
||||
export class DropTypeBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
ifExists() {
|
||||
return new DropTypeBuilder({
|
||||
...this.#props,
|
||||
node: DropTypeNode.cloneWith(this.#props.node, {
|
||||
ifExists: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
26
node_modules/kysely/dist/esm/schema/drop-view-builder.d.ts
generated
vendored
Normal file
26
node_modules/kysely/dist/esm/schema/drop-view-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
import { DropViewNode } from '../operation-node/drop-view-node.js';
|
||||
export declare class DropViewBuilder implements OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: DropViewBuilderProps);
|
||||
materialized(): DropViewBuilder;
|
||||
ifExists(): DropViewBuilder;
|
||||
cascade(): DropViewBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): DropViewNode;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface DropViewBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: DropViewNode;
|
||||
}
|
||||
49
node_modules/kysely/dist/esm/schema/drop-view-builder.js
generated
vendored
Normal file
49
node_modules/kysely/dist/esm/schema/drop-view-builder.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/// <reference types="./drop-view-builder.d.ts" />
|
||||
import { freeze } from '../util/object-utils.js';
|
||||
import { DropViewNode } from '../operation-node/drop-view-node.js';
|
||||
export class DropViewBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
materialized() {
|
||||
return new DropViewBuilder({
|
||||
...this.#props,
|
||||
node: DropViewNode.cloneWith(this.#props.node, {
|
||||
materialized: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
ifExists() {
|
||||
return new DropViewBuilder({
|
||||
...this.#props,
|
||||
node: DropViewNode.cloneWith(this.#props.node, {
|
||||
ifExists: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
cascade() {
|
||||
return new DropViewBuilder({
|
||||
...this.#props,
|
||||
node: DropViewNode.cloneWith(this.#props.node, {
|
||||
cascade: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
28
node_modules/kysely/dist/esm/schema/foreign-key-constraint-builder.d.ts
generated
vendored
Normal file
28
node_modules/kysely/dist/esm/schema/foreign-key-constraint-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import { ForeignKeyConstraintNode } from '../operation-node/foreign-key-constraint-node.js';
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { OnModifyForeignAction } from '../operation-node/references-node.js';
|
||||
export interface ForeignKeyConstraintBuilderInterface<R> {
|
||||
onDelete(onDelete: OnModifyForeignAction): R;
|
||||
onUpdate(onUpdate: OnModifyForeignAction): R;
|
||||
deferrable(): R;
|
||||
notDeferrable(): R;
|
||||
initiallyDeferred(): R;
|
||||
initiallyImmediate(): R;
|
||||
}
|
||||
export declare class ForeignKeyConstraintBuilder implements ForeignKeyConstraintBuilderInterface<ForeignKeyConstraintBuilder>, OperationNodeSource {
|
||||
#private;
|
||||
constructor(node: ForeignKeyConstraintNode);
|
||||
onDelete(onDelete: OnModifyForeignAction): ForeignKeyConstraintBuilder;
|
||||
onUpdate(onUpdate: OnModifyForeignAction): ForeignKeyConstraintBuilder;
|
||||
deferrable(): ForeignKeyConstraintBuilder;
|
||||
notDeferrable(): ForeignKeyConstraintBuilder;
|
||||
initiallyDeferred(): ForeignKeyConstraintBuilder;
|
||||
initiallyImmediate(): ForeignKeyConstraintBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): ForeignKeyConstraintNode;
|
||||
}
|
||||
export type ForeignKeyConstraintBuilderCallback = (builder: ForeignKeyConstraintBuilder) => ForeignKeyConstraintBuilder;
|
||||
45
node_modules/kysely/dist/esm/schema/foreign-key-constraint-builder.js
generated
vendored
Normal file
45
node_modules/kysely/dist/esm/schema/foreign-key-constraint-builder.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/// <reference types="./foreign-key-constraint-builder.d.ts" />
|
||||
import { ForeignKeyConstraintNode } from '../operation-node/foreign-key-constraint-node.js';
|
||||
import { parseOnModifyForeignAction } from '../parser/on-modify-action-parser.js';
|
||||
export class ForeignKeyConstraintBuilder {
|
||||
#node;
|
||||
constructor(node) {
|
||||
this.#node = node;
|
||||
}
|
||||
onDelete(onDelete) {
|
||||
return new ForeignKeyConstraintBuilder(ForeignKeyConstraintNode.cloneWith(this.#node, {
|
||||
onDelete: parseOnModifyForeignAction(onDelete),
|
||||
}));
|
||||
}
|
||||
onUpdate(onUpdate) {
|
||||
return new ForeignKeyConstraintBuilder(ForeignKeyConstraintNode.cloneWith(this.#node, {
|
||||
onUpdate: parseOnModifyForeignAction(onUpdate),
|
||||
}));
|
||||
}
|
||||
deferrable() {
|
||||
return new ForeignKeyConstraintBuilder(ForeignKeyConstraintNode.cloneWith(this.#node, { deferrable: true }));
|
||||
}
|
||||
notDeferrable() {
|
||||
return new ForeignKeyConstraintBuilder(ForeignKeyConstraintNode.cloneWith(this.#node, { deferrable: false }));
|
||||
}
|
||||
initiallyDeferred() {
|
||||
return new ForeignKeyConstraintBuilder(ForeignKeyConstraintNode.cloneWith(this.#node, {
|
||||
initiallyDeferred: true,
|
||||
}));
|
||||
}
|
||||
initiallyImmediate() {
|
||||
return new ForeignKeyConstraintBuilder(ForeignKeyConstraintNode.cloneWith(this.#node, {
|
||||
initiallyDeferred: false,
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#node;
|
||||
}
|
||||
}
|
||||
17
node_modules/kysely/dist/esm/schema/primary-key-constraint-builder.d.ts
generated
vendored
Normal file
17
node_modules/kysely/dist/esm/schema/primary-key-constraint-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import { PrimaryKeyConstraintNode } from '../operation-node/primary-key-constraint-node.js';
|
||||
export declare class PrimaryKeyConstraintBuilder implements OperationNodeSource {
|
||||
#private;
|
||||
constructor(node: PrimaryKeyConstraintNode);
|
||||
deferrable(): PrimaryKeyConstraintBuilder;
|
||||
notDeferrable(): PrimaryKeyConstraintBuilder;
|
||||
initiallyDeferred(): PrimaryKeyConstraintBuilder;
|
||||
initiallyImmediate(): PrimaryKeyConstraintBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): PrimaryKeyConstraintNode;
|
||||
}
|
||||
export type PrimaryKeyConstraintBuilderCallback = (builder: PrimaryKeyConstraintBuilder) => PrimaryKeyConstraintBuilder;
|
||||
34
node_modules/kysely/dist/esm/schema/primary-key-constraint-builder.js
generated
vendored
Normal file
34
node_modules/kysely/dist/esm/schema/primary-key-constraint-builder.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
/// <reference types="./primary-key-constraint-builder.d.ts" />
|
||||
import { PrimaryKeyConstraintNode } from '../operation-node/primary-key-constraint-node.js';
|
||||
export class PrimaryKeyConstraintBuilder {
|
||||
#node;
|
||||
constructor(node) {
|
||||
this.#node = node;
|
||||
}
|
||||
deferrable() {
|
||||
return new PrimaryKeyConstraintBuilder(PrimaryKeyConstraintNode.cloneWith(this.#node, { deferrable: true }));
|
||||
}
|
||||
notDeferrable() {
|
||||
return new PrimaryKeyConstraintBuilder(PrimaryKeyConstraintNode.cloneWith(this.#node, { deferrable: false }));
|
||||
}
|
||||
initiallyDeferred() {
|
||||
return new PrimaryKeyConstraintBuilder(PrimaryKeyConstraintNode.cloneWith(this.#node, {
|
||||
initiallyDeferred: true,
|
||||
}));
|
||||
}
|
||||
initiallyImmediate() {
|
||||
return new PrimaryKeyConstraintBuilder(PrimaryKeyConstraintNode.cloneWith(this.#node, {
|
||||
initiallyDeferred: false,
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#node;
|
||||
}
|
||||
}
|
||||
47
node_modules/kysely/dist/esm/schema/refresh-materialized-view-builder.d.ts
generated
vendored
Normal file
47
node_modules/kysely/dist/esm/schema/refresh-materialized-view-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { Compilable } from '../util/compilable.js';
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
import { RefreshMaterializedViewNode } from '../operation-node/refresh-materialized-view-node.js';
|
||||
export declare class RefreshMaterializedViewBuilder implements OperationNodeSource, Compilable {
|
||||
#private;
|
||||
constructor(props: RefreshMaterializedViewBuilderProps);
|
||||
/**
|
||||
* Adds the "concurrently" modifier.
|
||||
*
|
||||
* Use this to refresh the view without locking out concurrent selects on the materialized view.
|
||||
*
|
||||
* WARNING!
|
||||
* This cannot be used with the "with no data" modifier.
|
||||
*/
|
||||
concurrently(): RefreshMaterializedViewBuilder;
|
||||
/**
|
||||
* Adds the "with data" modifier.
|
||||
*
|
||||
* If specified (or defaults) the backing query is executed to provide the new data, and the materialized view is left in a scannable state
|
||||
*/
|
||||
withData(): RefreshMaterializedViewBuilder;
|
||||
/**
|
||||
* Adds the "with no data" modifier.
|
||||
*
|
||||
* If specified, no new data is generated and the materialized view is left in an unscannable state.
|
||||
*
|
||||
* WARNING!
|
||||
* This cannot be used with the "concurrently" modifier.
|
||||
*/
|
||||
withNoData(): RefreshMaterializedViewBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): RefreshMaterializedViewNode;
|
||||
compile(): CompiledQuery;
|
||||
execute(): Promise<void>;
|
||||
}
|
||||
export interface RefreshMaterializedViewBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly executor: QueryExecutor;
|
||||
readonly node: RefreshMaterializedViewNode;
|
||||
}
|
||||
72
node_modules/kysely/dist/esm/schema/refresh-materialized-view-builder.js
generated
vendored
Normal file
72
node_modules/kysely/dist/esm/schema/refresh-materialized-view-builder.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/// <reference types="./refresh-materialized-view-builder.d.ts" />
|
||||
import { freeze } from '../util/object-utils.js';
|
||||
import { RefreshMaterializedViewNode } from '../operation-node/refresh-materialized-view-node.js';
|
||||
export class RefreshMaterializedViewBuilder {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = freeze(props);
|
||||
}
|
||||
/**
|
||||
* Adds the "concurrently" modifier.
|
||||
*
|
||||
* Use this to refresh the view without locking out concurrent selects on the materialized view.
|
||||
*
|
||||
* WARNING!
|
||||
* This cannot be used with the "with no data" modifier.
|
||||
*/
|
||||
concurrently() {
|
||||
return new RefreshMaterializedViewBuilder({
|
||||
...this.#props,
|
||||
node: RefreshMaterializedViewNode.cloneWith(this.#props.node, {
|
||||
concurrently: true,
|
||||
withNoData: false,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adds the "with data" modifier.
|
||||
*
|
||||
* If specified (or defaults) the backing query is executed to provide the new data, and the materialized view is left in a scannable state
|
||||
*/
|
||||
withData() {
|
||||
return new RefreshMaterializedViewBuilder({
|
||||
...this.#props,
|
||||
node: RefreshMaterializedViewNode.cloneWith(this.#props.node, {
|
||||
withNoData: false,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adds the "with no data" modifier.
|
||||
*
|
||||
* If specified, no new data is generated and the materialized view is left in an unscannable state.
|
||||
*
|
||||
* WARNING!
|
||||
* This cannot be used with the "concurrently" modifier.
|
||||
*/
|
||||
withNoData() {
|
||||
return new RefreshMaterializedViewBuilder({
|
||||
...this.#props,
|
||||
node: RefreshMaterializedViewNode.cloneWith(this.#props.node, {
|
||||
withNoData: true,
|
||||
concurrently: false,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId);
|
||||
}
|
||||
compile() {
|
||||
return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
|
||||
}
|
||||
async execute() {
|
||||
await this.#props.executor.executeQuery(this.compile());
|
||||
}
|
||||
}
|
||||
230
node_modules/kysely/dist/esm/schema/schema.d.ts
generated
vendored
Normal file
230
node_modules/kysely/dist/esm/schema/schema.d.ts
generated
vendored
Normal file
@@ -0,0 +1,230 @@
|
||||
import type { QueryExecutor } from '../query-executor/query-executor.js';
|
||||
import { AlterTableBuilder } from './alter-table-builder.js';
|
||||
import { CreateIndexBuilder } from './create-index-builder.js';
|
||||
import { CreateSchemaBuilder } from './create-schema-builder.js';
|
||||
import { CreateTableBuilder } from './create-table-builder.js';
|
||||
import { DropIndexBuilder } from './drop-index-builder.js';
|
||||
import { DropSchemaBuilder } from './drop-schema-builder.js';
|
||||
import { DropTableBuilder } from './drop-table-builder.js';
|
||||
import { CreateViewBuilder } from './create-view-builder.js';
|
||||
import { DropViewBuilder } from './drop-view-builder.js';
|
||||
import type { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
||||
import { CreateTypeBuilder } from './create-type-builder.js';
|
||||
import { DropTypeBuilder } from './drop-type-builder.js';
|
||||
import { RefreshMaterializedViewBuilder } from './refresh-materialized-view-builder.js';
|
||||
/**
|
||||
* Provides methods for building database schema.
|
||||
*/
|
||||
export declare class SchemaModule {
|
||||
#private;
|
||||
constructor(executor: QueryExecutor);
|
||||
/**
|
||||
* Create a new table.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* This example creates a new table with columns `id`, `first_name`,
|
||||
* `last_name` and `gender`:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
|
||||
* .addColumn('first_name', 'varchar', col => col.notNull())
|
||||
* .addColumn('last_name', 'varchar', col => col.notNull())
|
||||
* .addColumn('gender', 'varchar')
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* This example creates a table with a foreign key. Not all database
|
||||
* engines support column-level foreign key constraint definitions.
|
||||
* For example if you are using MySQL 5.X see the next example after
|
||||
* this one.
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
|
||||
* .addColumn('owner_id', 'integer', col => col
|
||||
* .references('person.id')
|
||||
* .onDelete('cascade')
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* This example adds a foreign key constraint for a columns just
|
||||
* like the previous example, but using a table-level statement.
|
||||
* On MySQL 5.X you need to define foreign key constraints like
|
||||
* this:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
|
||||
* .addColumn('owner_id', 'integer')
|
||||
* .addForeignKeyConstraint(
|
||||
* 'pet_owner_id_foreign', ['owner_id'], 'person', ['id'],
|
||||
* (constraint) => constraint.onDelete('cascade')
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
createTable<TB extends string>(table: TB): CreateTableBuilder<TB, never>;
|
||||
/**
|
||||
* Drop a table.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .dropTable('person')
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
dropTable(table: string): DropTableBuilder;
|
||||
/**
|
||||
* Create a new index.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createIndex('person_full_name_unique_index')
|
||||
* .on('person')
|
||||
* .columns(['first_name', 'last_name'])
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
createIndex(indexName: string): CreateIndexBuilder;
|
||||
/**
|
||||
* Drop an index.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .dropIndex('person_full_name_unique_index')
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
dropIndex(indexName: string): DropIndexBuilder;
|
||||
/**
|
||||
* Create a new schema.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createSchema('some_schema')
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
createSchema(schema: string): CreateSchemaBuilder;
|
||||
/**
|
||||
* Drop a schema.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .dropSchema('some_schema')
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
dropSchema(schema: string): DropSchemaBuilder;
|
||||
/**
|
||||
* Alter a table.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* .alterColumn('first_name', (ac) => ac.setDataType('text'))
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
alterTable(table: string): AlterTableBuilder;
|
||||
/**
|
||||
* Create a new view.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createView('dogs')
|
||||
* .orReplace()
|
||||
* .as(db.selectFrom('pet').selectAll().where('species', '=', 'dog'))
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
createView(viewName: string): CreateViewBuilder;
|
||||
/**
|
||||
* Refresh a materialized view.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .refreshMaterializedView('my_view')
|
||||
* .concurrently()
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
refreshMaterializedView(viewName: string): RefreshMaterializedViewBuilder;
|
||||
/**
|
||||
* Drop a view.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .dropView('dogs')
|
||||
* .ifExists()
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
dropView(viewName: string): DropViewBuilder;
|
||||
/**
|
||||
* Create a new type.
|
||||
*
|
||||
* Only some dialects like PostgreSQL have user-defined types.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createType('species')
|
||||
* .asEnum(['dog', 'cat', 'frog'])
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
createType(typeName: string): CreateTypeBuilder;
|
||||
/**
|
||||
* Drop a type.
|
||||
*
|
||||
* Only some dialects like PostgreSQL have user-defined types.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .dropType('species')
|
||||
* .ifExists()
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
dropType(typeName: string): DropTypeBuilder;
|
||||
/**
|
||||
* Returns a copy of this schema module with the given plugin installed.
|
||||
*/
|
||||
withPlugin(plugin: KyselyPlugin): SchemaModule;
|
||||
/**
|
||||
* Returns a copy of this schema module without any plugins.
|
||||
*/
|
||||
withoutPlugins(): SchemaModule;
|
||||
/**
|
||||
* See {@link QueryCreator.withSchema}
|
||||
*/
|
||||
withSchema(schema: string): SchemaModule;
|
||||
}
|
||||
325
node_modules/kysely/dist/esm/schema/schema.js
generated
vendored
Normal file
325
node_modules/kysely/dist/esm/schema/schema.js
generated
vendored
Normal file
@@ -0,0 +1,325 @@
|
||||
/// <reference types="./schema.d.ts" />
|
||||
import { AlterTableNode } from '../operation-node/alter-table-node.js';
|
||||
import { CreateIndexNode } from '../operation-node/create-index-node.js';
|
||||
import { CreateSchemaNode } from '../operation-node/create-schema-node.js';
|
||||
import { CreateTableNode } from '../operation-node/create-table-node.js';
|
||||
import { DropIndexNode } from '../operation-node/drop-index-node.js';
|
||||
import { DropSchemaNode } from '../operation-node/drop-schema-node.js';
|
||||
import { DropTableNode } from '../operation-node/drop-table-node.js';
|
||||
import { parseTable } from '../parser/table-parser.js';
|
||||
import { AlterTableBuilder } from './alter-table-builder.js';
|
||||
import { CreateIndexBuilder } from './create-index-builder.js';
|
||||
import { CreateSchemaBuilder } from './create-schema-builder.js';
|
||||
import { CreateTableBuilder } from './create-table-builder.js';
|
||||
import { DropIndexBuilder } from './drop-index-builder.js';
|
||||
import { DropSchemaBuilder } from './drop-schema-builder.js';
|
||||
import { DropTableBuilder } from './drop-table-builder.js';
|
||||
import { createQueryId } from '../util/query-id.js';
|
||||
import { WithSchemaPlugin } from '../plugin/with-schema/with-schema-plugin.js';
|
||||
import { CreateViewBuilder } from './create-view-builder.js';
|
||||
import { CreateViewNode } from '../operation-node/create-view-node.js';
|
||||
import { DropViewBuilder } from './drop-view-builder.js';
|
||||
import { DropViewNode } from '../operation-node/drop-view-node.js';
|
||||
import { CreateTypeBuilder } from './create-type-builder.js';
|
||||
import { DropTypeBuilder } from './drop-type-builder.js';
|
||||
import { CreateTypeNode } from '../operation-node/create-type-node.js';
|
||||
import { DropTypeNode } from '../operation-node/drop-type-node.js';
|
||||
import { parseSchemableIdentifier } from '../parser/identifier-parser.js';
|
||||
import { RefreshMaterializedViewBuilder } from './refresh-materialized-view-builder.js';
|
||||
import { RefreshMaterializedViewNode } from '../operation-node/refresh-materialized-view-node.js';
|
||||
/**
|
||||
* Provides methods for building database schema.
|
||||
*/
|
||||
export class SchemaModule {
|
||||
#executor;
|
||||
constructor(executor) {
|
||||
this.#executor = executor;
|
||||
}
|
||||
/**
|
||||
* Create a new table.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* This example creates a new table with columns `id`, `first_name`,
|
||||
* `last_name` and `gender`:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('person')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
|
||||
* .addColumn('first_name', 'varchar', col => col.notNull())
|
||||
* .addColumn('last_name', 'varchar', col => col.notNull())
|
||||
* .addColumn('gender', 'varchar')
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* This example creates a table with a foreign key. Not all database
|
||||
* engines support column-level foreign key constraint definitions.
|
||||
* For example if you are using MySQL 5.X see the next example after
|
||||
* this one.
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
|
||||
* .addColumn('owner_id', 'integer', col => col
|
||||
* .references('person.id')
|
||||
* .onDelete('cascade')
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* This example adds a foreign key constraint for a columns just
|
||||
* like the previous example, but using a table-level statement.
|
||||
* On MySQL 5.X you need to define foreign key constraints like
|
||||
* this:
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createTable('pet')
|
||||
* .addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
|
||||
* .addColumn('owner_id', 'integer')
|
||||
* .addForeignKeyConstraint(
|
||||
* 'pet_owner_id_foreign', ['owner_id'], 'person', ['id'],
|
||||
* (constraint) => constraint.onDelete('cascade')
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
createTable(table) {
|
||||
return new CreateTableBuilder({
|
||||
queryId: createQueryId(),
|
||||
executor: this.#executor,
|
||||
node: CreateTableNode.create(parseTable(table)),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Drop a table.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .dropTable('person')
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
dropTable(table) {
|
||||
return new DropTableBuilder({
|
||||
queryId: createQueryId(),
|
||||
executor: this.#executor,
|
||||
node: DropTableNode.create(parseTable(table)),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Create a new index.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createIndex('person_full_name_unique_index')
|
||||
* .on('person')
|
||||
* .columns(['first_name', 'last_name'])
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
createIndex(indexName) {
|
||||
return new CreateIndexBuilder({
|
||||
queryId: createQueryId(),
|
||||
executor: this.#executor,
|
||||
node: CreateIndexNode.create(indexName),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Drop an index.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .dropIndex('person_full_name_unique_index')
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
dropIndex(indexName) {
|
||||
return new DropIndexBuilder({
|
||||
queryId: createQueryId(),
|
||||
executor: this.#executor,
|
||||
node: DropIndexNode.create(indexName),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Create a new schema.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createSchema('some_schema')
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
createSchema(schema) {
|
||||
return new CreateSchemaBuilder({
|
||||
queryId: createQueryId(),
|
||||
executor: this.#executor,
|
||||
node: CreateSchemaNode.create(schema),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Drop a schema.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .dropSchema('some_schema')
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
dropSchema(schema) {
|
||||
return new DropSchemaBuilder({
|
||||
queryId: createQueryId(),
|
||||
executor: this.#executor,
|
||||
node: DropSchemaNode.create(schema),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Alter a table.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .alterTable('person')
|
||||
* .alterColumn('first_name', (ac) => ac.setDataType('text'))
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
alterTable(table) {
|
||||
return new AlterTableBuilder({
|
||||
queryId: createQueryId(),
|
||||
executor: this.#executor,
|
||||
node: AlterTableNode.create(parseTable(table)),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Create a new view.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createView('dogs')
|
||||
* .orReplace()
|
||||
* .as(db.selectFrom('pet').selectAll().where('species', '=', 'dog'))
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
createView(viewName) {
|
||||
return new CreateViewBuilder({
|
||||
queryId: createQueryId(),
|
||||
executor: this.#executor,
|
||||
node: CreateViewNode.create(viewName),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Refresh a materialized view.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .refreshMaterializedView('my_view')
|
||||
* .concurrently()
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
refreshMaterializedView(viewName) {
|
||||
return new RefreshMaterializedViewBuilder({
|
||||
queryId: createQueryId(),
|
||||
executor: this.#executor,
|
||||
node: RefreshMaterializedViewNode.create(viewName),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Drop a view.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .dropView('dogs')
|
||||
* .ifExists()
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
dropView(viewName) {
|
||||
return new DropViewBuilder({
|
||||
queryId: createQueryId(),
|
||||
executor: this.#executor,
|
||||
node: DropViewNode.create(viewName),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Create a new type.
|
||||
*
|
||||
* Only some dialects like PostgreSQL have user-defined types.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .createType('species')
|
||||
* .asEnum(['dog', 'cat', 'frog'])
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
createType(typeName) {
|
||||
return new CreateTypeBuilder({
|
||||
queryId: createQueryId(),
|
||||
executor: this.#executor,
|
||||
node: CreateTypeNode.create(parseSchemableIdentifier(typeName)),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Drop a type.
|
||||
*
|
||||
* Only some dialects like PostgreSQL have user-defined types.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* await db.schema
|
||||
* .dropType('species')
|
||||
* .ifExists()
|
||||
* .execute()
|
||||
* ```
|
||||
*/
|
||||
dropType(typeName) {
|
||||
return new DropTypeBuilder({
|
||||
queryId: createQueryId(),
|
||||
executor: this.#executor,
|
||||
node: DropTypeNode.create(parseSchemableIdentifier(typeName)),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Returns a copy of this schema module with the given plugin installed.
|
||||
*/
|
||||
withPlugin(plugin) {
|
||||
return new SchemaModule(this.#executor.withPlugin(plugin));
|
||||
}
|
||||
/**
|
||||
* Returns a copy of this schema module without any plugins.
|
||||
*/
|
||||
withoutPlugins() {
|
||||
return new SchemaModule(this.#executor.withoutPlugins());
|
||||
}
|
||||
/**
|
||||
* See {@link QueryCreator.withSchema}
|
||||
*/
|
||||
withSchema(schema) {
|
||||
return new SchemaModule(this.#executor.withPluginAtFront(new WithSchemaPlugin(schema)));
|
||||
}
|
||||
}
|
||||
23
node_modules/kysely/dist/esm/schema/unique-constraint-builder.d.ts
generated
vendored
Normal file
23
node_modules/kysely/dist/esm/schema/unique-constraint-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import { UniqueConstraintNode } from '../operation-node/unique-constraint-node.js';
|
||||
export declare class UniqueConstraintNodeBuilder implements OperationNodeSource {
|
||||
#private;
|
||||
constructor(node: UniqueConstraintNode);
|
||||
/**
|
||||
* Adds `nulls not distinct` to the unique constraint definition
|
||||
*
|
||||
* Supported by PostgreSQL dialect only
|
||||
*/
|
||||
nullsNotDistinct(): UniqueConstraintNodeBuilder;
|
||||
deferrable(): UniqueConstraintNodeBuilder;
|
||||
notDeferrable(): UniqueConstraintNodeBuilder;
|
||||
initiallyDeferred(): UniqueConstraintNodeBuilder;
|
||||
initiallyImmediate(): UniqueConstraintNodeBuilder;
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call<T>(func: (qb: this) => T): T;
|
||||
toOperationNode(): UniqueConstraintNode;
|
||||
}
|
||||
export type UniqueConstraintNodeBuilderCallback = (builder: UniqueConstraintNodeBuilder) => UniqueConstraintNodeBuilder;
|
||||
42
node_modules/kysely/dist/esm/schema/unique-constraint-builder.js
generated
vendored
Normal file
42
node_modules/kysely/dist/esm/schema/unique-constraint-builder.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/// <reference types="./unique-constraint-builder.d.ts" />
|
||||
import { UniqueConstraintNode } from '../operation-node/unique-constraint-node.js';
|
||||
export class UniqueConstraintNodeBuilder {
|
||||
#node;
|
||||
constructor(node) {
|
||||
this.#node = node;
|
||||
}
|
||||
/**
|
||||
* Adds `nulls not distinct` to the unique constraint definition
|
||||
*
|
||||
* Supported by PostgreSQL dialect only
|
||||
*/
|
||||
nullsNotDistinct() {
|
||||
return new UniqueConstraintNodeBuilder(UniqueConstraintNode.cloneWith(this.#node, { nullsNotDistinct: true }));
|
||||
}
|
||||
deferrable() {
|
||||
return new UniqueConstraintNodeBuilder(UniqueConstraintNode.cloneWith(this.#node, { deferrable: true }));
|
||||
}
|
||||
notDeferrable() {
|
||||
return new UniqueConstraintNodeBuilder(UniqueConstraintNode.cloneWith(this.#node, { deferrable: false }));
|
||||
}
|
||||
initiallyDeferred() {
|
||||
return new UniqueConstraintNodeBuilder(UniqueConstraintNode.cloneWith(this.#node, {
|
||||
initiallyDeferred: true,
|
||||
}));
|
||||
}
|
||||
initiallyImmediate() {
|
||||
return new UniqueConstraintNodeBuilder(UniqueConstraintNode.cloneWith(this.#node, {
|
||||
initiallyDeferred: false,
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Simply calls the provided function passing `this` as the only argument. `$call` returns
|
||||
* what the provided function returns.
|
||||
*/
|
||||
$call(func) {
|
||||
return func(this);
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#node;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user