EzDbCodeGen 1.1.77

This complete and self contained code generation utility will install in a sub directory EzDbCodeGen of a target project.  From this path, you can run a powershell script that will generate code based on the connection string.  Each template is a handlebars template that has tags that specify where you would like to output the generated code and if there is a vs project that you wish to update with the file list (old VS project formats only).

There is a newer version of this package available.
See the version list below for details.

Requires NuGet 3.3.0 or higher.

Install-Package EzDbCodeGen -Version 1.1.77
dotnet add package EzDbCodeGen --version 1.1.77
<PackageReference Include="EzDbCodeGen" Version="1.1.77" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EzDbCodeGen --version 1.1.77
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EzDbCodeGen, 1.1.77"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install EzDbCodeGen as a Cake Addin
#addin nuget:?package=EzDbCodeGen&version=1.1.77

// Install EzDbCodeGen as a Cake Tool
#tool nuget:?package=EzDbCodeGen&version=1.1.77
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

ez-db-codegen-core

Easy code generation based on a database schema given by EZDbSchema. The template language this application uses is HandleBars.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system. This nuget package will dump the published cli package for code generation and a powershell script to run it. The nuget package will dump everything you need for code generation into the project you have selected under the EzDbCodeGen folder.

Prerequisites

  • [DotNetCore 3.1+] (https://www.microsoft.com/net/learn/get-started) - You will get everything you need except the sdk! please download the latest version of this before trying to run the powershell script
  • You will need MSSQL with some database installed. If you need a sample database, feel free to look for the World Wide Importers samples.

NOTE: If you have not set your powershell execution remote policy first, you will need to do this as noted in Powershell Execution Policy

  • Open the powershell command prompt in administrator mode and type: Set-ExecutionPolicy RemoteSigned

Using this project:

Lets go through a test run of how to use this before we get into the nitty gritty:

From NuGet (or use the nuget package manager)
  1. Install-Package EzDbCodeGen - it will create a folder in EzDbCodeGen.NuGet.TestTarget called EzDbCodeGen. This will contain a subdirectoy called appbin that contains a portable deployment of a portable dotnet core 2.2 console application. The nuget package will use your project name name to create an application specific version of an config file and powershell script file that you can use to generate your code. Subsequent updates to the nuget package will not touch the application specific files. There will also be a Templates directory, here is where you will place your handle bars templates. The powershell script, if passed a path, will execute each .hbs template in this path.
  2. Update the connection string in ezdbcodegen.ps1 with the database you wish to create your templates on
  3. right click on ezdbcodegen.ps1 and select "Open with PowerShell ISE" (because for whatever reason, the direct executer just hangs for me)
  4. Click the green right arrow to run the script. You should see a powershell window come up with the script running, EzDbCodeGen/Generated should have the results of both of the templates execution

Deployment

This project was design to be hosted and distributed with nuget.com.

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

Many thanks to the following projects that have helped in this project

  • EzDBSchema
  • McMaster.Extensions.CommandLineUtils

HandleBar Custom Functions

  • {{ ContextAsJson }} - Will dump the current context as a JSON file on the rendered file, useful for debugging
  • {{ Prefix $p1 }} - Will append a string to the beginning of the string passed through $p1
  • {{ ExtractTableName $p1 }} - Used the extract the table name from a schema.table object name format
  • {{ ExtractSchemaName $p1 }} - Used the extract the schema name from a schema.table object name format
  • {{ ToSingular $p1 }} - Will change $p1 to a singular word
  • {{ Comma }} - Will output a comma
  • {{ ToPlural }} - Will change $p1 to a plural word
  • {{ ToNetType $p1 }} - Assuming that the string is a sql type, it will return the corresponding .net type with a ? if the property is nullable
  • {{ ToCodeFriendly $p1 }} - Will write a string removing code unfriendly characters
  • {{ PropertyNameSuffix $p1 }} - Will output a code friendly string
  • {{ ToJsType }} - Assuming that the string is a sql type, it will return the corresponding javascript type appending "| null" if it is nullable
  • {{ AsFormattedName $p1 }} - Strips ID, UID, or id from $p1
  • {{ ToSnakeCase $p1 }} - Will turn $p1 into snake case
  • {{ ToSingularSnakeCase $p1 }} - Will turn $p1 into snake case singular
  • {{ ToTitleCaseSafeFileName $p1 }} - Will turn $p1 into Title case and safe for a file name (excellent for the <FILE/> clause )
  • {{ ToCsObjectName $p1 }} - Will convert $p1 to a string sutable for C# Code name
  • {{ StringFormat $p1, $p2 }} - Versitile string function that lets you apply 1 or more formatting tasks on $p1, $p2 can cantain one more of 'lower,upper,snake,title,pascal,trim,plural,single,nettype,jstype', performed in order
  • {{ EntityCustomAttribute $p1 }} - Upeer stirng and replacing "US_" to ""
  • {{ IfPropertyExists $p1 }} - Will search the parent context to see of the entity name exists, will only write the code after to {{/IfPropertyExists}} if true
  • {{ isRelationshipCount $p1 $p2 }} - $p1 should be a comparison op >, =, ==, <, !=, <>, $p2 should be the number compared to will only write the code after to {{/isRelationshipCount}} if true
  • {{ isRelationshipTypeOf $p1}} - Should be called when the context is a Relationship or RelaitonshipList, $p1 can = OneToMany, ZeroOrOneToMany, ZeroOrOneToManyOnly, ManyToOne, ManyToZeroOrOne, ManyToZeroOrOneOnly, OneToOne, OneToZeroOrOne, OneToZeroOrOneOnly, ZeroOrOneToOne, ZeroOrOneToOneOnly
  • {{ ToTargetEntityAlias }} - Should be called when the context is a Relationship or RelaitonshipList, will return the Alias of what this entity is related to
  • {{ ToUniqueColumnName $p1 }} - Will attempt to figured out a unique column name if one of the same name exists
  • {{ ifPropertyCustomAttributeCond $p1 $p2 $p3}} - Tests the value of a particular custom attribute of a propery, if true will write code from tag to {{/ifPropertyCustomAttributeCond}} or {{else}}. if false, it will write from {{else}} to {{/ifPropertyCustomAttributeCond}} $p1 = attribute name $p2 = should be a comparison op >, =, ==, <, !=, <> $p3 = value to compare
  • {{ isNotInList $p1 $p2 \[$p3\]...\[$pn\] }} - Will return true if $p1 does not exist in $p2(+), will write from tag isNotInList to {{/isNotInList}} or {{else}} of it doesnt exist, if it does, it will write from {{else}} to {{/isNotInList}}
  • `{{ ifNot $p1 }} - if $p1 is false, this will write all code between this tag and {{/ifNot}} or {{else}}, if true, code to be writtent will be {{else}} to {{/ifNot}}
  • {{ ifCond $p1 \[$p2\] \[$p3\]}} - This function requirs 1 argument or 3 arguments if there is only $p1, then $p1 should be a boolean, otherwise $p1 = 1value to compare $p2 = should be a comparison op >, =, ==, <, !=, <> $p3 = value to if the result of the 3 operators is true, it will write from this tag to {{else}} or {{/ifCond}}, if false then code from {{else}} to {{/ifCond}} will be written

ez-db-codegen-core

Easy code generation based on a database schema given by EZDbSchema. The template language this application uses is HandleBars.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system. This nuget package will dump the published cli package for code generation and a powershell script to run it. The nuget package will dump everything you need for code generation into the project you have selected under the EzDbCodeGen folder.

Prerequisites

  • [DotNetCore 3.1+] (https://www.microsoft.com/net/learn/get-started) - You will get everything you need except the sdk! please download the latest version of this before trying to run the powershell script
  • You will need MSSQL with some database installed. If you need a sample database, feel free to look for the World Wide Importers samples.

NOTE: If you have not set your powershell execution remote policy first, you will need to do this as noted in Powershell Execution Policy

  • Open the powershell command prompt in administrator mode and type: Set-ExecutionPolicy RemoteSigned

Using this project:

Lets go through a test run of how to use this before we get into the nitty gritty:

From NuGet (or use the nuget package manager)
  1. Install-Package EzDbCodeGen - it will create a folder in EzDbCodeGen.NuGet.TestTarget called EzDbCodeGen. This will contain a subdirectoy called appbin that contains a portable deployment of a portable dotnet core 2.2 console application. The nuget package will use your project name name to create an application specific version of an config file and powershell script file that you can use to generate your code. Subsequent updates to the nuget package will not touch the application specific files. There will also be a Templates directory, here is where you will place your handle bars templates. The powershell script, if passed a path, will execute each .hbs template in this path.
  2. Update the connection string in ezdbcodegen.ps1 with the database you wish to create your templates on
  3. right click on ezdbcodegen.ps1 and select "Open with PowerShell ISE" (because for whatever reason, the direct executer just hangs for me)
  4. Click the green right arrow to run the script. You should see a powershell window come up with the script running, EzDbCodeGen/Generated should have the results of both of the templates execution

Deployment

This project was design to be hosted and distributed with nuget.com.

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

Many thanks to the following projects that have helped in this project

  • EzDBSchema
  • McMaster.Extensions.CommandLineUtils

HandleBar Custom Functions

  • {{ ContextAsJson }} - Will dump the current context as a JSON file on the rendered file, useful for debugging
  • {{ Prefix $p1 }} - Will append a string to the beginning of the string passed through $p1
  • {{ ExtractTableName $p1 }} - Used the extract the table name from a schema.table object name format
  • {{ ExtractSchemaName $p1 }} - Used the extract the schema name from a schema.table object name format
  • {{ ToSingular $p1 }} - Will change $p1 to a singular word
  • {{ Comma }} - Will output a comma
  • {{ ToPlural }} - Will change $p1 to a plural word
  • {{ ToNetType $p1 }} - Assuming that the string is a sql type, it will return the corresponding .net type with a ? if the property is nullable
  • {{ ToCodeFriendly $p1 }} - Will write a string removing code unfriendly characters
  • {{ PropertyNameSuffix $p1 }} - Will output a code friendly string
  • {{ ToJsType }} - Assuming that the string is a sql type, it will return the corresponding javascript type appending "| null" if it is nullable
  • {{ AsFormattedName $p1 }} - Strips ID, UID, or id from $p1
  • {{ ToSnakeCase $p1 }} - Will turn $p1 into snake case
  • {{ ToSingularSnakeCase $p1 }} - Will turn $p1 into snake case singular
  • {{ ToTitleCaseSafeFileName $p1 }} - Will turn $p1 into Title case and safe for a file name (excellent for the <FILE/> clause )
  • {{ ToCsObjectName $p1 }} - Will convert $p1 to a string sutable for C# Code name
  • {{ StringFormat $p1, $p2 }} - Versitile string function that lets you apply 1 or more formatting tasks on $p1, $p2 can cantain one more of 'lower,upper,snake,title,pascal,trim,plural,single,nettype,jstype', performed in order
  • {{ EntityCustomAttribute $p1 }} - Upeer stirng and replacing "US_" to ""
  • {{ IfPropertyExists $p1 }} - Will search the parent context to see of the entity name exists, will only write the code after to {{/IfPropertyExists}} if true
  • {{ isRelationshipCount $p1 $p2 }} - $p1 should be a comparison op >, =, ==, <, !=, <>, $p2 should be the number compared to will only write the code after to {{/isRelationshipCount}} if true
  • {{ isRelationshipTypeOf $p1}} - Should be called when the context is a Relationship or RelaitonshipList, $p1 can = OneToMany, ZeroOrOneToMany, ZeroOrOneToManyOnly, ManyToOne, ManyToZeroOrOne, ManyToZeroOrOneOnly, OneToOne, OneToZeroOrOne, OneToZeroOrOneOnly, ZeroOrOneToOne, ZeroOrOneToOneOnly
  • {{ ToTargetEntityAlias }} - Should be called when the context is a Relationship or RelaitonshipList, will return the Alias of what this entity is related to
  • {{ ToUniqueColumnName $p1 }} - Will attempt to figured out a unique column name if one of the same name exists
  • {{ ifPropertyCustomAttributeCond $p1 $p2 $p3}} - Tests the value of a particular custom attribute of a propery, if true will write code from tag to {{/ifPropertyCustomAttributeCond}} or {{else}}. if false, it will write from {{else}} to {{/ifPropertyCustomAttributeCond}} $p1 = attribute name $p2 = should be a comparison op >, =, ==, <, !=, <> $p3 = value to compare
  • {{ isNotInList $p1 $p2 \[$p3\]...\[$pn\] }} - Will return true if $p1 does not exist in $p2(+), will write from tag isNotInList to {{/isNotInList}} or {{else}} of it doesnt exist, if it does, it will write from {{else}} to {{/isNotInList}}
  • `{{ ifNot $p1 }} - if $p1 is false, this will write all code between this tag and {{/ifNot}} or {{else}}, if true, code to be writtent will be {{else}} to {{/ifNot}}
  • {{ ifCond $p1 \[$p2\] \[$p3\]}} - This function requirs 1 argument or 3 arguments if there is only $p1, then $p1 should be a boolean, otherwise $p1 = 1value to compare $p2 = should be a comparison op >, =, ==, <, !=, <> $p3 = value to if the result of the 3 operators is true, it will write from this tag to {{else}} or {{/ifCond}}, if false then code from {{else}} to {{/ifCond}} will be written

Release Notes

Upgraded to DotNetCore 3.1
Database and Entity objects now contain 'Misc' and allows for any key value pair to be realized in the object model
Database.ColumnNameFilters is an array that allows wild card specification of filtering out column names globally
Vastly improved nuget module updates (cleans and backs up files in the target EzDbCodeGen Path)

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.2.18 2,104 5/13/2020
1.1.87 325 12/26/2019
1.1.82 254 12/23/2019
1.1.77 240 12/21/2019
1.1.51 290 8/30/2019
1.1.46 421 6/6/2019
1.1.34 293 6/6/2019
1.1.24 461 2/22/2019
1.1.22 685 9/28/2018
1.1.20 491 9/19/2018
1.1.10 549 8/24/2018
1.1.9 546 8/21/2018
1.1.5 511 8/1/2018
1.1.3 516 7/30/2018
1.1.2 495 7/27/2018
1.1.0 502 7/20/2018