2 – senCille MVC: The Database & Stub.

The senCille MVC framework will start with a desktop application and the first thing we need is a Database with a lot of relationships and well know data.  After a little searching the internet, we found a script to create the well know Northwind Database.

Northwind has been part of MS-SQL Server since the very first versions. Currently, this sample database is not deployed with the product, but you can download it from Microsoft’s help site.

Next image is in a database diagram in A4 size which and can be downloaded, with the right button, as you know and printed if needed for reference.

Northwind

As said, this database was initially developed for MS-SQL Server. We are going to deploy a little Stub program to create the database and deploy it to the correct location, and after that, fill it with a good set of Data for our samples. But, as we don’t want limit the use of the application to MS-SQL Server, our first version is going to be for the Firebird embedded edition.

You can download a copy of the repository, (get a clone in git language), from the next repository.

Bitbucket

https://bitbucket.org/juanc_cilleruelo/sencillemvc

Remember that the Branch described in this post is called scStub.

If you select master, you will see the projects latest version, not in the version described here.

folder structure

The folder structure is simple. We have four folders. The Bin folder is the destination of the compiled project. When we build and deploy the project, we only use content from this folder. Inside the Bin folder, another bin folder holds all the necessary files to run FireBird Embedded databases. Including the required FireBird content is a courtesy to make this project easier to use and not require separate downloading and configuration.

The dcus folder is a throw away for all precompiled units. We want to maintain it in a separate folder to minimize complexity in the bin folder, but it is important.

The scFramework is the folder which will to hold the files of the framework. All the files in this folder will be common to all the projects we create. The name all of source files will be part of the namespace senCille.

Finally, the scStub folder is the first application project and is to be dedicated to managing of the Data.  We want to have a good base of examples that can be initialized at any time, and before of each unit test execution. This application creates the Database with the example Data used by the programs. This program shall be maintained along with rest of code. This foundation will help assure us the framework and programs are achieving  their targets.

Inside scStub, the program code is not very complicated. It includes a good example of the use of Delegates in Delphi (events), that if you understand, will be a good introduction to the manner of reaching Event handlers of each component of our Views through a Controller.

scFramework folderThis folder holds the first four files of our framework.

DBController is one of the base fundamental classes in our framework. Its simplicity should not confuse us. This class is used to connect with the physical database. In next version of the project we are going to modify it to allow connection to other types of databases, like MS-SQL Server, Oracle, Interbase, etc. For now, it will connect only with Firebird Embedded.

DBController encapsulates the connection to the database. Every time we create a Controller we are going to assign this DBController to it. When the Controller creates its corresponding Model class, it will use this object to establish the connection. This will allow us to assure that we only have one active connection all the time (very important in mobile apps working with IBLite or IBTogo databases), but this will assure too that, if we change the database of the project, this won’t have an impact on the controllers, because the DBController hides the physical Details of the connection.

In this first project, scStub, you can see a basic use of DBController.

SQLConnect.pas contains a nice helper class that will allow us to create Querys on the fly in our program. These queries are clean and in many cases independent of the Connection. In theory, the use of this class shall be restricted to the Model Layer.

Tools.pas is a library to place all the little tools that this framework will need. I think that this is an elegant form of mandating all the code inside classes.

Finally, DBRows.pas is the parent class of all the Row classes of our applications. This is not part of this first project, but is available to get a gimps of the framework to come.

When the Model communicates with the Controller and vice-versa, or when a Controller communicates with other Controllers, there are a lot of circumstances in which we need to pass the data of a Row in the Database. TDBRow descendant classes are the representation of a  DBRow in this situation.

But, this is part of a future post.

In the next post we will see how to create these classes.

 

Juan Carlos Cilleruelo

Randy Sill (Editor/Collaborator)

One thought on “2 – senCille MVC: The Database & Stub.

  1. senCille MVC: The Database & Stub. – senCille

Leave a comment