Data Model Generation for PostgreSQL

DinGo is a simple Go code generator that is useful to produce Microservice applications starting from the database schema.


PostgreSQL supported

As I showed in the previous post DinGo produces code reading the database schema and its first version supported only the MySQL database, but now after a not so short and unfortunately not continuous work, finally the PostgreSQL database has been supported.

The current release (2.0.beta) contains all the templates and producers for providing microservices that can operate on Postgres. This DinGo release is still in beta because it requires a few tests and there are also some limitations. Postgres array types are not supported and I don't know if they will be in the future.

Reading the Information Schema

PostgreSQL offers two methods for retrieving meta-data about the table's schema using the system catalogs (pg_class, pg_user, pg_view, ...) or querying the information_schema (available since Postgres 7.4).
DinGo has adopted the second method retrieving all the tables meta-data querying the information_schema. This approach is very similar to that used with MySQL, queries on the PostgreSQL information_schema require only few changes starting from the previous ones.


Updated configuration file

DinGo configuration file requires some additional parameters to connect Postgres. This is an example of configuration 

{
    "Hostname": "localhost", 
    "Port": "5432",
    "DatabaseType": "Postgres", 
    "DatabaseName": "Customers", 
    "Username": "postgres", 
    "Password": "mypassword",
    "BasePackage": "github.com/maxzerbini/prjtestPostgres",
    "OutputPath": "$GOPATH/src/github.com/maxzerbini/prjtestPostgres",
    "ExcludedEntities": [],
    "Entities": [],
    "SkipDaoGeneration": false,
    "SkipBizGeneration": false,
    "SkipServiceGeneration": false,
    "ForcePluralResourceName": true,
    "PostgresSchema": "public"
}


The new property DatabaseType can now assume one of the two values "MySQL" or "Postgres" and the PostgresSchema property is used for querying the Information_Schema and get the meta-data of the selected set of tables.

Commenti

Post popolari in questo blog

OAuth 2.0 Server & Authorization Middleware for Gin-Gonic

From the database schema to RESTful API with DinGo

Go text and HTML templates