Apstory.Scaffold.App follows an MSSQL database-first approach to generate CRUD stored procedures and related C# code.
It adopts a convention-over-configuration methodology, reducing complexity when running the application.
When running regen on a table, the following SQL procedures will be generated:
DelHrd– Hard delete from the table.DelSft– Soft delete (marks row asIsActive = false).GetByTableNameIds– Fetches rows based on a list of supplied IDs.GetById– Fetches a record based on the primary key.GetByIds– Fetches records based on foreign keys.GetByIdsPaging– Fetches a paginated set of rows.InsUpd– Inserts or updates an entry in the table.
Common/ProjectName.Common.ServiceCollectionExtension/Gen/AddGeneratedRepositoriesServiceCollectionExtension.cs- Registers repositories with SQL connection strings.
Common/ProjectName.Common.ServiceCollectionExtension/Gen/AddGeneratedServicesServiceCollectionExtension.cs- Registers services.
Dal/ProjectName.Dal.Dapper/Gen/TableNameRepository.Gen.cs- Contains Dapper methods to interact with the SQL database.
Dal/ProjectName.Dal.Interface/Gen/ITableNameRepository.Gen.cs- Repository interface.
Domain/ProjectName.Domain/Gen/TableNameService.Gen.cs- Service layer that interacts with the repository.
Domain/ProjectName.Domain/Gen/TableNameService.Foreign.Gen.cs- Extends the service layer with additional methods for handling foreign key relationships (depth of 1).
Domain/ProjectName.Domain.Interface/Gen/ITableNameService.Gen.cs- Interface for the service layer.
Domain/ProjectName.Domain.Interface/Gen/ITableNameService.Foreign.Gen.cs- Interface for the foreign key service layer.
Model/ProjectName.Model/Gen/TableName.Gen.cs- Represents the database table as a model, including foreign key relationships.
To install or update the tool globally use the following command:
dotnet tool update Apstory.Scaffold.App --global
Running Apstory.Scaffold.App will search for a .sqlproj file, extract the namespace for the entire project, and begin watching for any .sql file changes.
By default, running the application without parameters will make it run in the background, continuously watching for file changes.
The .sqlproj file used can be overridden using the -sqlproject parameter.
-
-sqlproject <path>
Overrides the SQL project path instead of letting the application search for it. -
-namespace <name>
Overrides the namespace for scaffolded code instead of fetching it from the.sqlproj. -
-regen <params>
Executes immediate regeneration of files.- When no parameters are supplied, it regenerates all found schemas.
- You can specify:
- A schema:
dbo - A table:
dbo.tablename - A procedure:
dbo.zgen_procname
- A schema:
- Multiple entities can be specified using
;, e.g.:-regen dbo;dbo.Customer;dbo.zgen_GetOrders
-
-sqlpush <params>
Pushes changes to the database.- When left empty, it detects Git changes.
- You can specify:
- A table:
dbo.tablename(Limited functionality - Will only push new tables, not any updates made to an existing table) - A procedure:
dbo.zgen_procname
- A table:
- Requires the
-sqldestinationswitch.- Specifies the database connection string for pushing changes.
- Note: Only initial table creation can be pushed, no table updates are pushed.
- Multiple entities can be specified using
;, e.g.:-sqlpush dbo.Customer;dbo.zgen_InsertOrder
-
-delete
Deletes and removes associated scaffolded code.- When left empty, it deletes all scaffolded code.
- You can specify:
- A schema:
dboTo delete all scaffolded code within a schema. - A table:
dbo.tablenameto delete the table and all scaffolded sql stored procedures - A procedure:
dbo.zgen_procname
- A schema:
-
-tsdalfolderScaffolds a SQLite repository based on a typescript model- Requires the
-tsmodelswitch to point to a specific typescript model.
- Requires the