Skip to content

Latest commit

 

History

History
152 lines (117 loc) · 8.71 KB

Database-Table-Config.md

File metadata and controls

152 lines (117 loc) · 8.71 KB

'Table' object (entity-driven)

The Table object identifies an existing database Table (or View) and defines its code-generation characteristics.

The columns for the table (or view) are inferred from the database schema definition. The IncludeColumns and ExcludeColumns provide a shorthand to include or exclude selected columns from all the StoredProcedure children. A table can be defined more that once to enable different column configurations as required.

In addition to the primary Stored Procedures generation, the following types of artefacts can also be generated:


Example

A YAML example is as follows:

tables:
- { name: Table, schema: Test, create: true, update: true, upsert: true, delete: true, merge: true, udt: true, getAll: true, getAllOrderBy: [ Name Des ], excludeColumns: [ Other ], permission: TestSec,
    storedProcedures: [
      { name: GetByArgs, type: GetColl, excludeColumns: [ Count ],
        parameters: [
          { name: Name, nullable: true, operator: LIKE },
          { name: MinCount, operator: GE, column: Count },
          { name: MaxCount, operator: LE, column: Count, nullable: true }
        ]
      },
      { name: Get, type: Get, withHints: NOLOCK,
        execute: [
          { statement: EXEC Demo.Before, location: Before },
          { statement: EXEC Demo.After }
        ]
      },
      { name: Update, type: Update }
    ]
  }

Property categories

The Table object supports a number of properties that control the generated code output. These properties are separated into a series of logical categories.

Category Description
Key Provides the key configuration.
Columns Provides the Columns configuration.
CodeGen Provides the Code Generation configuration.
EntityFramework Provides the Entity Framework (EF) model configuration.
UDT Provides the User Defined Table and Table-Valued Parameter configuration.
Auth Provides the Authorization configuration.
Infer Provides the special Column Name inference configuration.
Collections Provides related child (hierarchical) configuration.

The properties with a bold name are those that are more typically used (considered more important).


Key

Provides the key configuration.

Property Description
name The name of the Table in the database. [Mandatory]
schema The name of the Schema where the Table is defined in the database.
† Defaults to CodeGeneration.Schema.
alias The Schema.Table alias name.
† Will automatically default where not specified.

Columns

Provides the Columns configuration.

Property Description
includeColumns The list of Column names to be included in the underlying generated output.
† Where not specified this indicates that all Columns are to be included.
excludeColumns The list of Column names to be excluded from the underlying generated output.
† Where not specified this indicates no Columns are to be excluded.
aliasColumns The list of Column and Alias pairs (split by a ^ lookup character) to enable column aliasing/renaming.
† Each alias value should be formatted as Column + ^ + Alias; e.g. PCODE^ProductCode.

CodeGen

Provides the Code Generation configuration. These primarily provide a shorthand to create the standard Get, GetAll, Create, Update, Upsert, Delete and Merge.

Property Description
get Indicates whether a Get stored procedure is to be automatically generated where not otherwise explicitly specified.
getAll Indicates whether a GetAll stored procedure is to be automatically generated where not otherwise explicitly specified.
† The GetAllOrderBy is used to specify the GetAll query sort order.
getAllOrderBy The list of Column names (including sort order ASC/DESC literal) to be used as the GetAll query sort order.
† This relates to the GetAll selection.
create Indicates whether a Create stored procedure is to be automatically generated where not otherwise explicitly specified.
update Indicates whether a Update stored procedure is to be automatically generated where not otherwise explicitly specified.
upsert Indicates whether a Upsert stored procedure is to be automatically generated where not otherwise explicitly specified.
delete Indicates whether a Delete stored procedure is to be automatically generated where not otherwise explicitly specified.
merge Indicates whether a Merge (insert/update/delete of Udt list) stored procedure is to be automatically generated where not otherwise explicitly specified.
† This will also require a Udt (SQL User Defined Table) and Tvp (.NET Table-Valued Parameter) to function.

EntityFramework

Provides the Entity Framework (EF) model configuration.

Property Description
efModel Indicates whether an Entity Framework .NET (C#) model is to be generated.
† Defaults to CodeGeneration.EfModel.
efModelName The .NET (C#) EntityFramework (EF) model name.
† Defaults to Name applying the CodeGeneration.AutoDotNetRename.

UDT

Provides the User Defined Table and Table-Valued Parameter configuration.

Property Description
udt Indicates whether a User Defined Table (UDT) type should be created.
udtExcludeColumns The list of Column names to be excluded from the User Defined Table (UDT).
† Where not specified this indicates that no Columns are to be excluded.
tvp The name of the .NET entity associated with the Udt so that it can be expressed (created) as a Table-Valued Parameter for usage within the corresponding DbMapper.

Auth

Provides the Authorization configuration.

Property Description
permission The permission (prefix) to be used for security permission checking (suffix defaults to Read, Write or Delete and can be overridden in the underlying stored procedure).
orgUnitImmutable Indicates whether the OrgUnitId column is considered immutable, in that it can not be changed once set.
† Defaults to CodeGeneration.OrgUnitImmutable. This is only applicable for stored procedures.

Infer

Provides the special Column Name inference configuration.

Property Description
columnNameIsDeleted The column name for the IsDeleted capability.
† Defaults to CodeGeneration.IsDeleted.
columnNameTenantId The column name for the TenantId capability.
† Defaults to CodeGeneration.TenantId.
columnNameOrgUnitId The column name for the OrgUnitId capability.
† Defaults to CodeGeneration.OrgUnitId.
columnNameRowVersion The column name for the RowVersion capability.
† Defaults to CodeGeneration.RowVersion.
columnNameCreatedBy The column name for the CreatedBy capability.
† Defaults to CodeGeneration.CreatedBy.
columnNameCreatedDate The column name for the CreatedDate capability.
† Defaults to CodeGeneration.CreatedDate.
columnNameUpdatedBy The column name for the UpdatedBy capability.
† Defaults to CodeGeneration.UpdatedBy.
columnNameUpdatedDate The column name for the UpdatedDate capability.
† Defaults to CodeGeneration.UpdatedDate.
columnNameDeletedBy The column name for the DeletedBy capability.
† Defaults to CodeGeneration.UpdatedBy.
columnNameDeletedDate The column name for the DeletedDate capability.
† Defaults to CodeGeneration.UpdatedDate.

Collections

Provides related child (hierarchical) configuration.

Property Description
storedProcedures The corresponding StoredProcedure collection.

A StoredProcedure object defines the stored procedure code-generation characteristics.
relationships The corresponding Relationship collection.

A Relationship object defines an Entity Frameworrk (EF) relationship between parent and child tables.