Skip to main content
Version: 4.5

Class: SchemaGenerator#

knex.SchemaGenerator

Constructors#

constructor#

+ new SchemaGenerator(em: EntityManager<AbstractSqlDriver<AbstractSqlConnection>>): SchemaGenerator

Parameters:#

NameType
emEntityManager<AbstractSqlDriver<AbstractSqlConnection>>

Returns: SchemaGenerator

Defined in: packages/knex/src/schema/SchemaGenerator.ts:16

Properties#

config#

Private Readonly config: Configuration<IDatabaseDriver<Connection>>

Defined in: packages/knex/src/schema/SchemaGenerator.ts:10


connection#

Private Readonly connection: AbstractSqlConnection

Defined in: packages/knex/src/schema/SchemaGenerator.ts:15


driver#

Private Readonly driver: AbstractSqlDriver<AbstractSqlConnection>

Defined in: packages/knex/src/schema/SchemaGenerator.ts:11


helper#

Private Readonly helper: SchemaHelper

Defined in: packages/knex/src/schema/SchemaGenerator.ts:14


knex#

Private Readonly knex: Knex<any, unknown[]>

Defined in: packages/knex/src/schema/SchemaGenerator.ts:16


metadata#

Private Readonly metadata: MetadataStorage

Defined in: packages/knex/src/schema/SchemaGenerator.ts:12


platform#

Private Readonly platform: AbstractSqlPlatform

Defined in: packages/knex/src/schema/SchemaGenerator.ts:13

Methods#

computeColumnDifference#

PrivatecomputeColumnDifference(table: DatabaseTable, prop: EntityProperty<any>, create: EntityProperty<any>[], update: { column: Column ; diff: IsSame ; prop: EntityProperty<any> }[], joinColumn?: string, idx?: number): void

Parameters:#

NameTypeDefault value
tableDatabaseTable-
propEntityProperty<any>-
createEntityProperty<any>[]-
update{ column: Column ; diff: IsSame ; prop: EntityProperty<any> }[]-
joinColumn?string-
idxnumber0

Returns: void

Defined in: packages/knex/src/schema/SchemaGenerator.ts:314


computeTableDifference#

PrivatecomputeTableDifference(meta: EntityMetadata<any>, table: DatabaseTable, safe: boolean): TableDifference

Parameters:#

NameType
metaEntityMetadata<any>
tableDatabaseTable
safeboolean

Returns: TableDifference

Defined in: packages/knex/src/schema/SchemaGenerator.ts:292


configureColumn#

PrivateconfigureColumn<T>(meta: EntityMetadata<T>, prop: EntityProperty<T>, col: ColumnBuilder, columnName: string, pkProp?: EntityProperty<T>, alter?: IsSame): ColumnBuilder

Type parameters:#

Name
T

Parameters:#

NameType
metaEntityMetadata<T>
propEntityProperty<T>
colColumnBuilder
columnNamestring
pkPropEntityProperty<T>
alter?IsSame

Returns: ColumnBuilder

Defined in: packages/knex/src/schema/SchemaGenerator.ts:435


createDatabase#

createDatabase(name: string): Promise<void>

creates new database and connects to it

Parameters:#

NameType
namestring

Returns: Promise<void>

Defined in: packages/knex/src/schema/SchemaGenerator.ts:134


createForeignKey#

PrivatecreateForeignKey(table: TableBuilder, meta: EntityMetadata<any>, prop: EntityProperty<any>, createdColumns: string[], diff?: IsSame): void

Parameters:#

NameType
tableTableBuilder
metaEntityMetadata<any>
propEntityProperty<any>
createdColumnsstring[]
diff?IsSame

Returns: void

Defined in: packages/knex/src/schema/SchemaGenerator.ts:474


createForeignKeyReference#

PrivatecreateForeignKeyReference(table: TableBuilder, prop: EntityProperty<any>, meta: EntityMetadata<any>): void

Parameters:#

NameType
tableTableBuilder
propEntityProperty<any>
metaEntityMetadata<any>

Returns: void

Defined in: packages/knex/src/schema/SchemaGenerator.ts:493


createForeignKeys#

PrivatecreateForeignKeys(table: TableBuilder, meta: EntityMetadata<any>, props?: EntityProperty<any>[], createdColumns?: string[]): void

Parameters:#

NameType
tableTableBuilder
metaEntityMetadata<any>
props?EntityProperty<any>[]
createdColumnsstring[]

Returns: void

Defined in: packages/knex/src/schema/SchemaGenerator.ts:467


createIndex#

PrivatecreateIndex(table: CreateTableBuilder, meta: EntityMetadata<any>, index: { name?: string | boolean ; properties: string | string[] ; type?: string }, unique: boolean): void

Parameters:#

NameType
tableCreateTableBuilder
metaEntityMetadata<any>
indexobject
index.name?string | boolean
index.propertiesstring | string[]
index.type?string
uniqueboolean

Returns: void

Defined in: packages/knex/src/schema/SchemaGenerator.ts:250


createSchema#

createSchema(wrap?: boolean): Promise<void>

Parameters:#

NameTypeDefault value
wrapbooleantrue

Returns: Promise<void>

Defined in: packages/knex/src/schema/SchemaGenerator.ts:29


createSimpleTableColumn#

PrivatecreateSimpleTableColumn(table: TableBuilder, meta: EntityMetadata<any>, prop: EntityProperty<any>, alter?: IsSame): ColumnBuilder

Parameters:#

NameType
tableTableBuilder
metaEntityMetadata<any>
propEntityProperty<any>
alter?IsSame

Returns: ColumnBuilder

Defined in: packages/knex/src/schema/SchemaGenerator.ts:383


createTable#

PrivatecreateTable(meta: EntityMetadata<any>, createdColumns: string[]): SchemaBuilder

Parameters:#

NameType
metaEntityMetadata<any>
createdColumnsstring[]

Returns: SchemaBuilder

Defined in: packages/knex/src/schema/SchemaGenerator.ts:228


createTableColumn#

PrivatecreateTableColumn(table: TableBuilder, meta: EntityMetadata<any>, prop: EntityProperty<any>, alter?: IsSame): ColumnBuilder[]

Parameters:#

NameType
tableTableBuilder
metaEntityMetadata<any>
propEntityProperty<any>
alter?IsSame

Returns: ColumnBuilder[]

Defined in: packages/knex/src/schema/SchemaGenerator.ts:370


dropDatabase#

dropDatabase(name: string): Promise<void>

Parameters:#

NameType
namestring

Returns: Promise<void>

Defined in: packages/knex/src/schema/SchemaGenerator.ts:140


dropSchema#

dropSchema(wrap?: boolean, dropMigrationsTable?: boolean, dropDb?: boolean): Promise<void>

Parameters:#

NameTypeDefault value
wrapbooleantrue
dropMigrationsTablebooleanfalse
dropDbbooleanfalse

Returns: Promise<void>

Defined in: packages/knex/src/schema/SchemaGenerator.ts:69


dropTable#

PrivatedropTable(name: string, schema?: string): SchemaBuilder

Parameters:#

NameType
namestring
schema?string

Returns: SchemaBuilder

Defined in: packages/knex/src/schema/SchemaGenerator.ts:336


dropTableColumn#

PrivatedropTableColumn(table: TableBuilder, column: Column): void

Parameters:#

NameType
tableTableBuilder
columnColumn

Returns: void

Defined in: packages/knex/src/schema/SchemaGenerator.ts:419


dump#

Privatedump(builder: SchemaBuilder, append?: string): string

Parameters:#

NameTypeDefault value
builderSchemaBuilder-
appendstring'\n\n'

Returns: string

Defined in: packages/knex/src/schema/SchemaGenerator.ts:615


ensureDatabase#

ensureDatabase(): Promise<void>

Returns: Promise<void>

Defined in: packages/knex/src/schema/SchemaGenerator.ts:35


execute#

execute(sql: string): Promise<void>

Parameters:#

NameType
sqlstring

Returns: Promise<void>

Defined in: packages/knex/src/schema/SchemaGenerator.ts:146


findIndexDifference#

PrivatefindIndexDifference(meta: EntityMetadata<any>, table: DatabaseTable, remove: Column[]): object

Parameters:#

NameType
metaEntityMetadata<any>
tableDatabaseTable
removeColumn[]

Returns: object

NameType
addIndexIndexDef[]
dropIndexIndexDef[]

Defined in: packages/knex/src/schema/SchemaGenerator.ts:538


findRenamedColumns#

PrivatefindRenamedColumns(create: EntityProperty<any>[], remove: Column[]): { from: Column ; to: EntityProperty<any> }[]

Parameters:#

NameType
createEntityProperty<any>[]
removeColumn[]

Returns: { from: Column ; to: EntityProperty<any> }[]

Defined in: packages/knex/src/schema/SchemaGenerator.ts:508


generate#

generate(): Promise<string>

Returns: Promise<string>

Defined in: packages/knex/src/schema/SchemaGenerator.ts:20


getCreateSchemaSQL#

getCreateSchemaSQL(wrap?: boolean): Promise<string>

Parameters:#

NameTypeDefault value
wrapbooleantrue

Returns: Promise<string>

Defined in: packages/knex/src/schema/SchemaGenerator.ts:46


getDropSchemaSQL#

getDropSchemaSQL(wrap?: boolean, dropMigrationsTable?: boolean): Promise<string>

Parameters:#

NameTypeDefault value
wrapbooleantrue
dropMigrationsTablebooleanfalse

Returns: Promise<string>

Defined in: packages/knex/src/schema/SchemaGenerator.ts:79


getIndexName#

PrivategetIndexName<T>(meta: EntityMetadata<T>, prop: EntityProperty<T>, type: index | unique, columnNames: string[]): string

Type parameters:#

Name
T

Parameters:#

NameType
metaEntityMetadata<T>
propEntityProperty<T>
typeindex | unique
columnNamesstring[]

Returns: string

Defined in: packages/knex/src/schema/SchemaGenerator.ts:457


getOrderedMetadata#

PrivategetOrderedMetadata(): EntityMetadata<any>[]

Returns: EntityMetadata<any>[]

Defined in: packages/knex/src/schema/SchemaGenerator.ts:595


getUpdateSchemaSQL#

getUpdateSchemaSQL(wrap?: boolean, safe?: boolean, dropTables?: boolean): Promise<string>

Parameters:#

NameTypeDefault value
wrapbooleantrue
safebooleanfalse
dropTablesbooleantrue

Returns: Promise<string>

Defined in: packages/knex/src/schema/SchemaGenerator.ts:99


getUpdateTableFKsSQL#

PrivategetUpdateTableFKsSQL(meta: EntityMetadata<any>, schema: DatabaseSchema, createdColumns: string[]): string

Parameters:#

NameType
metaEntityMetadata<any>
schemaDatabaseSchema
createdColumnsstring[]

Returns: string

Defined in: packages/knex/src/schema/SchemaGenerator.ts:164


getUpdateTableIndexesSQL#

PrivategetUpdateTableIndexesSQL(meta: EntityMetadata<any>, schema: DatabaseSchema): string

Parameters:#

NameType
metaEntityMetadata<any>
schemaDatabaseSchema

Returns: string

Defined in: packages/knex/src/schema/SchemaGenerator.ts:180


getUpdateTableSQL#

PrivategetUpdateTableSQL(meta: EntityMetadata<any>, schema: DatabaseSchema, safe: boolean, createdColumns: string[]): string

Parameters:#

NameType
metaEntityMetadata<any>
schemaDatabaseSchema
safeboolean
createdColumnsstring[]

Returns: string

Defined in: packages/knex/src/schema/SchemaGenerator.ts:154


shouldHaveColumn#

PrivateshouldHaveColumn(meta: EntityMetadata<any>, prop: EntityProperty<any>, update?: boolean): boolean

Parameters:#

NameTypeDefault value
metaEntityMetadata<any>-
propEntityProperty<any>-
updatebooleanfalse

Returns: boolean

Defined in: packages/knex/src/schema/SchemaGenerator.ts:347


updateSchema#

updateSchema(wrap?: boolean, safe?: boolean, dropTables?: boolean): Promise<void>

Parameters:#

NameTypeDefault value
wrapbooleantrue
safebooleanfalse
dropTablesbooleantrue

Returns: Promise<void>

Defined in: packages/knex/src/schema/SchemaGenerator.ts:94


updateTable#

PrivateupdateTable(meta: EntityMetadata<any>, table: DatabaseTable, safe: boolean, createdColumns: string[]): SchemaBuilder[]

Parameters:#

NameType
metaEntityMetadata<any>
tableDatabaseTable
safeboolean
createdColumnsstring[]

Returns: SchemaBuilder[]

Defined in: packages/knex/src/schema/SchemaGenerator.ts:261


updateTableColumn#

PrivateupdateTableColumn(table: TableBuilder, meta: EntityMetadata<any>, prop: EntityProperty<any>, column: Column, diff: IsSame, createdColumns: string[]): void

Parameters:#

NameType
tableTableBuilder
metaEntityMetadata<any>
propEntityProperty<any>
columnColumn
diffIsSame
createdColumnsstring[]

Returns: void

Defined in: packages/knex/src/schema/SchemaGenerator.ts:401


wrapSchema#

PrivatewrapSchema(sql: string, wrap?: boolean): Promise<string>

Parameters:#

NameTypeDefault value
sqlstring-
wrapbooleantrue

Returns: Promise<string>

Defined in: packages/knex/src/schema/SchemaGenerator.ts:216

Last updated on by Renovate Bot