Skip to main content

Java/Spring CRUD code generator

Project description

Crudhex

PyPI version

⚠️ Warn: Alpha development stage


CLI tool to generate Java CRUD classes from a spec file. The target for this code generation is a Hexagonal architecture.

Motivation

Adding CRUD operation in a hexagonal project is quite a pain. You can take shortcuts that can be totally legit in cases of just CRUD operations, but most cases if there is already a rich domain/application layer for other use cases CRUD shortcuts can break the consistency of the project.

The target of this CLI is to ease my life and try to give a general solution to CRUD generations in Hexagonal architecture. There are some customizations you can make, but some aspects for now are closed to customization for now.

Getting started

Project config file

Project config file is used to know where things should go in the project. Usually contains a path to the sources folder (src/main/java in regular maven projects) and packages where things are located within that source folder. Here is a basic example:

src: src/main/java # Java source folder for single module apps (where your packages start)

domain-models-pkg: com.salpreh.baseapi.domain.models # domain models package
db-models-pkg: com.salpreh.baseapi.adapers.infrasturcture.db.models # db entities package
rest-models-pkg: com.salpreh.baseapi.adapters.api.models # rest api models

In case of multi-module project you will have to specify src path to each module (domain, rest adapter and db adapter). More examples of config can be found in (doc/examples/config).

The default name for this config file is .crudhex-conf.yaml, located in the root of the project (you can provide the path to config file by cli options, so you can place it anywhere you want)

Spec file

This is the file where you specify the crud model. Class name, attributes and some meta data about DB structure (relations, PK field, column name alias, etc).

An example of spec file:

Person: # Model name
  .meta:
    table-name: persons # OPTIONAL: Table name for entity
  id: # Field name
    type: Long
    id: sequence # PK marker. This field will be the primary key for the entity. 
                 # As value you specify generation strategy available in JPA with lower case.
  birthPlanet: # Field name
    type: Planet
    column: birth_planet # OPTIONAL: Column name alias
    relation: # OPTIONAL: DB relation meta data
      type: many-to-one # Relation type
      join-column: birth_planet_id # Join column for relation
  affiliations:
    type: Faction
    relation:
      type: many-to-many # In case of many-to-many we have a couple of more meta about DB setup
      join-table: person_affiliation 
      join-column: person_id
      inverse-join-column: faction_id
  backup:
    type: Person
    relation:
      type: one-to-one
      join-column: backup_id
  backing:
    type: Person
    relation:
      type: one-to-one
      mapped-by: backup # Mapping attribute for non-owning side of relation

Snippet config comments provide a overview of each relevant section in config. I'll dig further in config details in a dedicated section. For now, you can find some aditional examples in doc/examples/spec.

Installation

Package is published in Pypi public repositories. You can use pip (or another convinient python dependency manager) to install the package:

pip install crudhex

Once installed you should be able to use it as CLI tool:

crudhex --help

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crudhex-0.5.1.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

crudhex-0.5.1-py3-none-any.whl (34.2 kB view details)

Uploaded Python 3

File details

Details for the file crudhex-0.5.1.tar.gz.

File metadata

  • Download URL: crudhex-0.5.1.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.6 Linux/5.15.0-1014-azure

File hashes

Hashes for crudhex-0.5.1.tar.gz
Algorithm Hash digest
SHA256 7cf402728973d28a9318d72d6145e4b9df962f2001617c95e2d2ab257838b8f6
MD5 70e00993b9aed02255fad0631ffc3d40
BLAKE2b-256 5d114cd8b36e324677d79c568d88348745f4e8d9640fe3bf037980319aab4da2

See more details on using hashes here.

File details

Details for the file crudhex-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: crudhex-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 34.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.6 Linux/5.15.0-1014-azure

File hashes

Hashes for crudhex-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f3a440c8933e0186144a3ddd7bccf646bcb439a029bf2d49998445f1f6b59d6b
MD5 70cab19aedd1721674f90a7eddb0fe3a
BLAKE2b-256 cfb1a26d7eb3180cba038f1b01e616911fc0223a46ea917fdb9f9a8d5bace6c2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page