#1 2020-02-12 11:10:33

msgendodoc@gmail.com
Member
Registered: 2018-01-28
Posts: 15

Can Mormot write a Pascal class in code based on a database table?

Hi,

I am new to MORMOT and understand that extending the TSQLRecord class one can build a class in Pascal code which can then automate database table design and creation, JSON transport and much more.  This is very powerful. 

But I already have a Firebird 3 database schema with 34 tables which already defines my domain information structure very well. 

I need now to make Pascal classes which replicate this same database structure, and connect to and from the database, and then also allow JSON transport for a client - server multi-tier product. 

As I already have the database structure designed, is it possible in MORMOT to read this Firebird database schema and then automatically create the Pascal classes, presumably using TSQLRecord?  This seems to be the reverse of the automation of the database from the Pascal classes usually done in MORMOT. 

Please advise

Thanks

Martin

Last edited by msgendodoc@gmail.com (2020-02-12 11:11:42)

Offline

#2 2020-02-12 11:42:05

xalo
Member
Registered: 2016-09-22
Posts: 32

Re: Can Mormot write a Pascal class in code based on a database table?

IIRC there's no automatic procedure to do this task. But IMHO it's not much work to do with 34 tables->classes and you can adapt, map, improve, etc... some classes to fit ORM. It was for me a good point to read first ORM is not Database

Offline

#3 2020-02-12 12:09:43

msgendodoc@gmail.com
Member
Registered: 2018-01-28
Posts: 15

Re: Can Mormot write a Pascal class in code based on a database table?

Thanks for the link.   OK, so DB to Pascal class is not the done thing.   Focus on the classes, you say.   Shame as my DB Schema really reflects my domain and work flow. 

I did already write a Pascal procedure to iterate each field in each database table and automatically generate the Pascal code for a class for each table.  And I thought that was pretty neat, when it worked and compiled too!!

So I might still use that procedure to create class templates from the database tables and then further work on the automatically generated code to make the classes mORMot compatible.

Offline

#4 2020-02-12 12:36:13

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: Can Mormot write a Pascal class in code based on a database table?

SynDB Explorer (in folder SQLite3\Samples)  generates the class code for you.

Take a look.

Offline

Board footer

Powered by FluxBB