Skip to main content

RelationalSchemaBuilder

@webda/sql-schema


Class: RelationalSchemaBuilder

Defined in: packages/sql-schema/src/builder.ts:110

Builds the RelationalSchemaPlan of the models of a store from their compiled metadata

Pure: no database, no logging (warnings are returned in the plan), same input same plan. Rules:

  • one table per model hierarchy (single-table inheritance, __type discriminator), unless tables names one
  • one typed column per stored field (Schemas.Stored), NOT NULL when required
  • ModelParent / ModelLink: a column (one per key part for a composite key) with a foreign key, ON DELETE CASCADE for a parent, NO ACTION for a link (until the delete policies of #798)
  • ModelLinksSimpleArray / ModelLinksArray / ModelLinksMap: a junction table <table>_<attribute>
  • ModelRelated / ModelsMapped: no storage
  • foreign keys only between models of the plan: a reference to another model gets a column and an index

Constructors​

Constructor​

new RelationalSchemaBuilder(options?): RelationalSchemaBuilder

Defined in: packages/sql-schema/src/builder.ts:116

Parameters​

options?​

RelationalSchemaOptions = {}

the builder options

Returns​

RelationalSchemaBuilder

Methods​

build()​

build(models): RelationalSchemaPlan

Defined in: packages/sql-schema/src/builder.ts:131

Build the plan

Parameters​

models​

Iterable<SchemaModelMetadata>

the models handled by the store, subclasses included

Returns​

RelationalSchemaPlan

the plan

Throws​

SchemaBuildError when the models cannot share their tables (primary keys or column types differ)