Search code examples
delphistored-proceduresfirebirdmormot

How to use database stored procedures on mORMot?


I'm implementing an application using mORMot with Delphi from an existing client-server app that is using a Firebird database with a lot of stored procedures dealing with updating some tables and querying very complicated data. It would take too long to reimplement and move everything from the database to the application side.

I have no idea what to do. Anyone, please help to guide me on how to use - call Firebird stored procedures on mORMot. (It would be great if there is an example.)


Solution

  • Stored procedures are great to access the database directly, but they are a nightmare for modern design. So there is no direct/native way of running stored procedures in mORMot, because it doesn't make sense with an ORM design, and modern SOA/Microservices/DDD architecture.

    What you could do with mORMot and your existing project is for instance:

    • Create a first layer of reusable "business/model" services using several interfaces - your own "logic toolbox";

    • Let the implementation classes of those interfaces call the existing stored procedures using your existing FireBird access library;

    • Publish the "business/model" layer services using another set of public REST endpoints, using mORMot interface based services, and fined REST interfaces with simple DTOs;

    • Let the new forms of your client app switch from RAD into this n-Tier/REST design, calling this new mORMot interface based services if possible;

    • Consider writing some new client code, maybe from a JavaScript REST/JSON client (you may use a third-party company for that);

    • Take a look at the mORMot Web MVC layer - php-like feature of the framework - which may help writing some dynamic web pages from your existing "business/model" layer;

    • Consider using the mORMot ORM for new tables and new data, perhaps switching to a MicroService architecture with its own SQLite3 persistence layer (or still Firebird is you really want, but you could switch using the ORM);

    • Benefit for a lot of cross-cutting features of the framework, like logging, pdf or JSON processing.

    Take a look at the documentation FAQ, and ask in the mORMot/Synopse forum.

    Check for instance: