Options
All
  • Public
  • Public/Protected
  • All
Menu

entity-baker

npm npm

node-entity-baker

Node.js application / library, which generates simple and powerful entity classes for ORM systems, like Doctrine and/or Entity Framework, wriiten in TypeScript.

Installation

As command line tool:

npm install -g entity-baker

As module:

npm install --save entity-baker

Usage

First create a entities.json file inside your working directory (can also be in XML or YAML format, s. examples folder):

{
    "namespace": "MarcelJoachimKloubert.Database",

    "entities": {
        "Log": {
            "table": "logs",

            "columns": {
                "id": {
                    "id": true,
                    "auto": true,
                    "type": "int32"
                },

                "level": {
                    "null": true,
                    "type": "int16"
                },

                "message": "string",
                "tag": {
                    "null": true,
                    "type": "string"
                },

                "context": {
                    "null": true,
                    "type": "json"
                }
            }
        }
    }
}

From command line

# run it from your working directory
entity-baker --doctrine --entity-framework --entity-framework-core

As module

JavaScript

var EntityBaker = require('entity-baker');

TypeScript

import * as EntityBaker from 'entity-baker';

compile

var fs = require('fs');

var entityFile = JSON.parse(
    fs.readFileSync('./entities.json', 'utf8')
);

EntityBaker.compile({
    cwd: '/path/to/working/directory',
    file: entityFile,
    outDir: '/path/to/output/directory',
       target: 1,  // Doctrine
    // target: 2  // Entity Framework
    // target: 3  // Entity Framework Core

    callbacks: {
        onBeforeGenerateClass: function(className, target) {
        },

        onClassGenerated: function(err, className, target) {
        }
    }
}).then(function() {
    // files generated
}, function (err) {
    // error while generating files
});

Data types

Type Doctrine Entity Framework
bigint bigint System.Int64.aspx)
bin binary System.Byte[].aspx)
binary binary System.Byte[].aspx)
blob blob System.Byte[].aspx)
bool boolean System.Boolean.aspx)
boolean boolean System.Boolean.aspx)
date date System.Int64.aspx)
datetime datetime System.Int64.aspx)
datetimetz datetimetz System.DateTimeOffset.aspx)
decimal decimal System.Decimal.aspx)
float float System.Single.aspx)
guid guid System.Guid.aspx)
int integer System.Int32.aspx)
int16 smallint System.Int16.aspx)
int32 integer System.Int32.aspx)
int64 bigint System.Int64.aspx)
integer integer System.Int32.aspx)
json json dynamic.aspx)
smallint smallint System.Int16.aspx)
str string System.String.aspx)
string string System.String.aspx)
text text System.String.aspx)
time time System.TimeSpan.aspx)
uint16 smallint System.UInt16.aspx)
uint32 integer System.UInt32.aspx)
uint64 bigint System.UInt64.aspx)
uuid guid System.Guid.aspx)

If you do not define a data type, it set to

  • int32, if the column is a primary key, or...
  • string, if nothing else matches

Support and contribute []

If you like the module, you can support the project by sending a donation via PayPal to me.

To contribute, you can open an issue and/or fork this repository.

To work with the code:

  • clone this repository
  • create and change to a new branch, like git checkout -b my_new_feature
  • run npm install from your project folder
  • edit and debug in your favorite editor, like Visual Studio Code
  • commit your changes to your new branch and sync it with your forked GitHub repo
  • make a pull request

The API documentation can be found here.

Generated using TypeDoc