1.0.8 • Published 4 years ago

@atomicg/atomicg v1.0.8

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

AtomicG

AtomicG is a CLI model-first source code generation tool, that can be used to automate the generation of regular and boilerplate source code files for your project, like Rest API CRUDs handlers, SQL scripts, entity classes for ORMs, etc... You can read more about this tool in the official web site https://www.atomicg.dev/, also join the discussion in our discord server https://discord.gg/n65mRJZ or send us an email with any concern you have to info@atomicg.dev

Instalation

AtomicG cli client can be installed using npm, it's recommended to install it globally, so it can be use in any project of any supported platform.

npm i @atomicg/atomicg -g

Usage

The first thing to do is to create a model to work with. An initial AtomicG model can be generated with the init command.

atomicg init

This will create the atomicg.yml file in the current folder, the created model it's simply a starting point, entities and generators must be added to the model to create useful code for the project. The next section describes in detail how to write a model. To generate the source code for the current model just run the tool with no options.

atomicg    

Model Reference

This section describes the information that can be added to the model and the source code each one produce. The following is an example of an atomicg model.

model:
  name: MyModel
  description: My Model

  basepath:

  uses:
    - gen: mysql
    - gen: sequelize
    - gen: express

  # Entities to be generated for this model.
  entities:
    - name: User
      fields:
        - name: email
          type: string
        - name: password
          type: string
        - name: name
          type: string
    - name: Group
      fields:
        - name: name
          type: string

All model must have the root element model beneath it the following options are available.

optiondescriptionrequired
nameThe name of the model.yes
descriptionA short description to this model.no
usesThe list of generators to use.yes
entitiesThe list of entities to be generatedyes

The uses option allows to add a list with all the generators that will be generating code for this model. At this moment only 3 are supported, they are de following.

generatordescription
mysqlgenerates the DDL script for MySQL database.
sequelizegenerates a Sequelize model for each entity in the model.
expressgenerates an ExpressJS CRUD router for each entity in the model, that can be used as part of an API.

The entities tag is used to specify the entities of the model and each entity has the following options.

optiondescriptionrequired
namethe name of the entity, that will be used for classes and file names for this entity.yes
fieldsthe list of fields for this entity.yes

The tags for each field are the following.

optiondescriptionrequired
namethe name of the field, this info will be used to generate properties and columns for the field.yes
typethe data type of the field, see the table of the available types for more information.yes
requiredif the field is required or not, this determines if the column in the database allows null or not.no
lengththe length of the field for string and numeric types. for the text data type this field most be either null, tiny, medium or longno
decimalsthe number of decimals for floating-point data typesno
precisionthe precision of the field for decimals types.no
scalethe scale of the field for decimals types.no
indexif the field must be indexed, see the index type table for more info.no
transformthe transformation that are needed by default on the data of the field. see the transformations table for more info.no
valuesused with the enum datatype to specify the set of values that the enum accepts.no

The following table shows the available datatypes.

datatypedescriptionSQL typeSequelize type
booleana boolean (true or false, usually 1 byteBOOLEANBOOLEAN
bytea 1 byte (8 bits) integerTINYINT(length)TINYINT(length)
shorta 2 bytes (16 bits) integerINTEGER(length)INTEGER(length)
mediuma 3 bytes (24 bits) integerINTEGER(length)INTEGER(length)
integera 4 bytes (32 bits) integerINTEGER(length)INTEGER(length)
longa 8 bytes (64 bits) integerBIGINT(length)BIGINT(length)
chara fixed length string of charactersCHAR(length)CHAR(length)
stringa variable length string of charactersVARCHAR(length)STRING(length)
texta customizable (tiny, medium, long) text fieldTINYTEXT, TEXT, MEDIUMTEXT, LONGTEXTTEXT, TEXT('tiny', 'medium', 'long')
floata single-precision floating-point numberFLOAT(length, decimals)FLOAT(length, precision)
doublea double-precision floating-point numberDOUBLE(length, decimals)DOUBLE(length, precision)
decimala decimal number that can store exact numbers.DECIMAL(precision, scale)DECIMAL(precision, scale)
enuman enumeration field that only allows a set of valuesENUM(values)ENUM

The following table shows the available options for the index tag.

optiondescription
nonethis is the default option, it means that this field will not be indexed.
indexedthis options means that the database generator and the orm generator will create and index on this field.
uniquethis options is the same as indexed but the created index will be a unique index, meaning that this field will have unique values in the database.

The following table shows the available options for the transform tag.

transformdescription
trimit will trim the white spaces characters from both size to any value pass to the field.
upperit will convert to upper case any value that is pass to the field.
lowerit will convert to lower case any value that is pass to the field.
emptyToNullit will convert to null any empty string that is pass to the field.

NOTE: This transformations are applicable to string fields only.

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago