Version: 4.3

Class: SchemaGenerator

Hierarchy

  • SchemaGenerator

Constructors

constructor

+ new SchemaGenerator(em: SqlEntityManager): SchemaGenerator

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

Parameters:

NameType
emSqlEntityManager

Returns: SchemaGenerator

Properties

config

Private Readonly config: Configuration<IDatabaseDriver<Connection>> = this.em.config

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


connection

Private Readonly connection: AbstractSqlConnection = this.driver.getConnection()

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


driver

Private Readonly driver: AbstractSqlDriver<AbstractSqlConnection> = this.em.getDriver()

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


em

Private Readonly em: SqlEntityManager

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


helper

Private Readonly helper: SchemaHelper = this.platform.getSchemaHelper()!

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


knex

Private Readonly knex: any = this.connection.getKnex()

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


metadata

Private Readonly metadata: MetadataStorage = this.em.getMetadata()

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


platform

Private Readonly platform: AbstractSqlPlatform = this.driver.getPlatform()

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

Methods

computeColumnDifference

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

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

Parameters:

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

Returns: void


computeTableDifference

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

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

Parameters:

NameType
metaEntityMetadata
tableDatabaseTable
safeboolean

Returns: TableDifference


configureColumn

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

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

Type parameters:

Name
T

Parameters:

NameTypeDefault value
metaEntityMetadata<T>-
propEntityProperty<T>-
colColumnBuilder-
columnNamestring-
pkPropEntityProperty<T>prop
alter?IsSame-

Returns: ColumnBuilder


createDatabase

createDatabase(name: string): Promise<void>

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

creates new database and connects to it

Parameters:

NameType
namestring

Returns: Promise<void>


createForeignKey

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

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

Parameters:

NameType
tableTableBuilder
metaEntityMetadata
propEntityProperty
createdColumnsstring[]
diff?IsSame

Returns: void


createForeignKeyReference

PrivatecreateForeignKeyReference(table: TableBuilder, prop: EntityProperty): void

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

Parameters:

NameType
tableTableBuilder
propEntityProperty

Returns: void


createForeignKeys

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

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

Parameters:

NameTypeDefault value
tableTableBuilder-
metaEntityMetadata-
props?EntityProperty[]-
createdColumnsstring[][]

Returns: void


createIndex

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

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

Parameters:

NameType
tableCreateTableBuilder
metaEntityMetadata
index{ name?: string | boolean ; properties: string | string[] ; type?: string }
uniqueboolean

Returns: void


createSchema

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

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

Parameters:

NameTypeDefault value
wrapbooleantrue

Returns: Promise<void>


createSimpleTableColumn

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

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

Parameters:

NameType
tableTableBuilder
metaEntityMetadata
propEntityProperty
alter?IsSame

Returns: ColumnBuilder


createTable

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

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

Parameters:

NameType
metaEntityMetadata
createdColumnsstring[]

Returns: SchemaBuilder


createTableColumn

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

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

Parameters:

NameType
tableTableBuilder
metaEntityMetadata
propEntityProperty
alter?IsSame

Returns: ColumnBuilder[]


dropDatabase

dropDatabase(name: string): Promise<void>

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

Parameters:

NameType
namestring

Returns: Promise<void>


dropSchema

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

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

Parameters:

NameTypeDefault value
wrapbooleantrue
dropMigrationsTablebooleanfalse
dropDbbooleanfalse

Returns: Promise<void>


dropTable

PrivatedropTable(name: string): SchemaBuilder

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

Parameters:

NameType
namestring

Returns: SchemaBuilder


dropTableColumn

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

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

Parameters:

NameType
tableTableBuilder
columnColumn

Returns: void


dump

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

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

Parameters:

NameTypeDefault value
builderSchemaBuilder-
appendstring"

" |

Returns: string


ensureDatabase

ensureDatabase(): Promise<void>

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

Returns: Promise<void>


execute

execute(sql: string): Promise<void>

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

Parameters:

NameType
sqlstring

Returns: Promise<void>


findIndexDifference

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

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

Parameters:

NameType
metaEntityMetadata
tableDatabaseTable
removeColumn[]

Returns: object

NameType
addIndexIndexDef[]
dropIndexIndexDef[]

findRenamedColumns

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

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

Parameters:

NameType
createEntityProperty[]
removeColumn[]

Returns: { from: Column ; to: EntityProperty }[]


generate

generate(): Promise<string>

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

Returns: Promise<string>


getCreateSchemaSQL

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

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

Parameters:

NameTypeDefault value
wrapbooleantrue

Returns: Promise<string>


getDropSchemaSQL

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

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

Parameters:

NameTypeDefault value
wrapbooleantrue
dropMigrationsTablebooleanfalse

Returns: Promise<string>


getIndexName

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

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

Type parameters:

Name
T

Parameters:

NameType
metaEntityMetadata<T>
propEntityProperty<T>
type"unique" | "index"
columnNamesstring[]

Returns: string


getOrderedMetadata

PrivategetOrderedMetadata(): EntityMetadata[]

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

Returns: EntityMetadata[]


getUpdateSchemaSQL

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

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

Parameters:

NameTypeDefault value
wrapbooleantrue
safebooleanfalse
dropTablesbooleantrue

Returns: Promise<string>


getUpdateTableFKsSQL

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

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

Parameters:

NameType
metaEntityMetadata
schemaDatabaseSchema
createdColumnsstring[]

Returns: string


getUpdateTableIndexesSQL

PrivategetUpdateTableIndexesSQL(meta: EntityMetadata, schema: DatabaseSchema): string

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

Parameters:

NameType
metaEntityMetadata
schemaDatabaseSchema

Returns: string


getUpdateTableSQL

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

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

Parameters:

NameType
metaEntityMetadata
schemaDatabaseSchema
safeboolean
createdColumnsstring[]

Returns: string


shouldHaveColumn

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

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

Parameters:

NameTypeDefault value
metaEntityMetadata-
propEntityProperty-
updatebooleanfalse

Returns: boolean


updateSchema

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

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

Parameters:

NameTypeDefault value
wrapbooleantrue
safebooleanfalse
dropTablesbooleantrue

Returns: Promise<void>


updateTable

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

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

Parameters:

NameType
metaEntityMetadata
tableDatabaseTable
safeboolean
createdColumnsstring[]

Returns: SchemaBuilder[]


updateTableColumn

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

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

Parameters:

NameType
tableTableBuilder
metaEntityMetadata
propEntityProperty
columnColumn
diffIsSame
createdColumnsstring[]

Returns: void


wrapSchema

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

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

Parameters:

NameTypeDefault value
sqlstring-
wrapbooleantrue

Returns: Promise<string>

Last updated on by Martin Adámek