Skip to content

TranQuangTienSA/generator-jhipster-db-helper

 
 

Repository files navigation

generator-jhipster-db-helper

NPM version Build Status Dependency Status Join the chat at https://gitter.im/generator-jhipster-db-helper/Lobby

This JHipster module makes mapping on an existing database easier. If you're not aware of the difficulties of using an existing database with JHipster, read this

quick start

Step one : Answer questions after creating or regenerating an entity

the questions this module will ask for a given entity 'Book'

Step two : Let our module do all the necessary modifications (see here some of them)

the modifications this module will do in the JPA file for a given entity

Step three : Profit

Check this application to see all the modifications our module do or check our notes for details.

New feature or supporting a new set up

We've made as easy as possible to contribute to our project, come and join the fun !

To contribute to this project, please read the contributing section.

Introduction

This is a JHipster module, meant to be used in a JHipster application.

It enables the user to input values corresponding to its existing database and inject them at the right places in the pertinent files automatically. Without this module, you would have to modify each value by hand. Count all your tables and your fields, sum everything, multiply by 2 or more (depending on the relationships) and this is the number of modifications this module will spare you.

Usage

Generate an application with yo jhipster, run our module with yo jhipster-db-helper and you're done. Our module will run as a post app/entity hook and you'll have to answer its questions.

Furthermore, you can use the option --force from Entity generator when generating an entity, provided that you have a configuration file including our module fields for this entity. Our module will interpret the option and look for values into the corresponding entity configuration file rather than from user input.

So the following will work :

$ cat .jhipster/Developer.json
{
    "fluentMethods": true,
    "relationships": [
        {
            "relationshipName": "beverage",
            "dbhRelationshipId": "beverage_id",
            "otherEntityName": "beverage",
            "relationshipType": "many-to-one",
            "otherEntityField": "name"
        },
        {
            "relationshipName": "bug",
            "dbhRelationshipId": "bugs_id",
            "otherEntityName": "bug",
            "relationshipType": "many-to-many",
            "otherEntityField": "analysis",
            "ownerSide": true,
            "otherEntityRelationshipName": "developer"
        },
        {
            "relationshipName": "mug",
            "otherEntityName": "mug",
            "relationshipType": "one-to-one",
            "ownerSide": false,
            "otherEntityRelationshipName": "developer"
        }
    ],
    "fields": [
        {
            "fieldName": "firstname",
            "dbhColumnName": "DB_Firstname",
            "fieldType": "String"
        },
        {
            "fieldName": "lastname",
            "dbhColumnName": "DB_Lastname",
            "fieldType": "String"
        },
        {
            "fieldName": "birthdate",
            "dbhColumnName": "DB_Birthdate",
            "fieldType": "LocalDate"
        }
    ],
    "changelogDate": "20170619101554",
    "dto": "no",
    "service": "no",
    "entityTableName": "DB_Developer",
    "pagination": "no",
    "dbhIdName": "DB_ID"
}
$ yo jhipster:entity Developer --force

Don't mind the field "dbhRelationshipId". It's there so we can successfully match some values after regeneration.

Installation

Prerequisites

As this is a JHipster module, we expect you have JHipster and its related tools already installed:

Create a new JHipster app and choose a SQL database.

With Yarn

To install this module: yarn global add generator-jhipster-db-helper

To update this module: yarn global upgrade generator-jhipster-db-helper

With NPM

To install this module: npm install -g generator-jhipster-db-helper

To update this module: npm update -g generator-jhipster-db-helper

What this module does

In a new app, run yo jhipster-db-helper.

This changes the naming convention to a more flexible one, registers itself as a post app hook and registers a 'fix-entity' sub-generator as a post-entity hook.

After creating or regenerating an entity (yo jhipster:entity MyEntity), there will be two more questions :

  • What is the table name for this entity ? (default)
  • What column name do you want for the field "fieldName" ? (default)

The former is asked once, the latter once for each field. It stores your answer in the entity configuration file (.jhipster/Entity.json) and makes the necessary replacements in both ORM and changelog files.

Planned features :

  • Import your database schema into JHipster. At the moment, you must create each entity yourself. We plan to make the module able to import a database and create all entities itself, with correct table and column names of course.

Contributing

Using your local version

Create your local working copy :

  • Fork this module and create your local branch
  • In the module folder, yarn link
  • In an another, empty folder : yo jhipster
  • In the new app folder and for each new app :
    • yarn link generator-jhipster-db-helper
    • yo jhipster-db-helper

You can edit your local repository and test the changes in the app. No need to rebuild the app.

Branching

We work from the dev branch, not master.

When submitting, please do so from a new branch, not the master or dev one. Please name your branch according these rules :

  • descriptive name : fork is bad, bugfix/entity-name-validation si good.
  • all lowercase
  • use dash - as a word separator.
  • use a prefix to describe the branch's type :
    • feature/ : New thing
    • bugfix/ : Repairing something that wasn't working correctly
    • fix/ : Improving something without modifying its behaviour

Integration testing

We use Travis CI for integration testing. If you want our module to support another type of database, another application configuration or another set up of entities, the first thing you should do is adding your test case.

We've set up conventions and helper scripts. You don't even need to know our conventions if you use our scripts. Please, go check it out.

General guidelines

We also use the same guidelines as jhipster/generator-jhipster, if you don't know it, please read this.

Contact

Join the chat at https://gitter.im/generator-jhipster-db-helper/Lobby

License

Apache-2.0 © Adrien Horgnies & Bastien Michaux

About

A JHipster module for better interaction with an already existing database

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 88.7%
  • Shell 11.3%