Skip to content

Commit

Permalink
Merge pull request #1 from waquispe/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
AlexQuispe committed Feb 27, 2018
2 parents a981870 + 38cc5b5 commit 1a5e2f6
Show file tree
Hide file tree
Showing 16 changed files with 3,725 additions and 26 deletions.
22 changes: 22 additions & 0 deletions .esdoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"source": "./lib",
"destination": "./docs/",
"includes": ["\\.js$"],
"plugins": [
{
"name": "esdoc-standard-plugin",
"option": {
"undocumentIdentifier": { "enable": false },
"unexportedIdentifier": { "enable": true },
"lint": { "enable": true },
"coverage": { "enable": true },
"typeInference": { "enable": true },
"brand": {
"title": "Field Creator",
"description": "Simplifica la definición de atributos para crear un modelo Sequelize.",
"repository": "https://github.com/waquispe/field-creator"
}
}
}
]
}
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
"env": {
"node": true,
"commonjs": true,
"es6": true
},
"extends": "standard",
"parserOptions": {
"ecmaVersion": 2017
},
"rules": {
"no-multi-spaces": "off",
"key-spacing": ["error", { align: "value", align: "colon", align: { beforeColon: true, afterColon: true, on: "colon" } }]
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/node_modules
/tmp
/docs
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Wilmer Alex Quispe Quispe <q.wilmer.alex@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
113 changes: 93 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,110 @@
# Insac Field
# Field creator

Simplifica la definición de atributos para crear un modelo Sequelize.

# Características

- Define atributos con la propiedad validate incluida.
- Crea objetos utilizando atributos predefinidos.
- Crea objetos de attributos.

## Atributos soportados:

Tipos básicos:

| Tipo | Descripción |
|------------|-------------------------------------------------------------------------|
| `STRING` | Atributo para representar cadenas de texto. |
| `INTEGER` | Atributo para representar números enteros. |
| `FLOAT` | Atributo para representar números en coma flotante. |
| `BOOLEAN` | Atributo para representar valores booleanos. |
| `DATE` | Atributo para representar fechas (día y hora). |
| `ENUM` | Atributo para representar datos enumerados. |
| `ARRAY` | Atributo para representar una lista de valores. |

Tipos personalizados:

| Tipo | Descripción |
|------------|-------------------------------------------------------------------------|
| `ID` | Atributo para representar una clave primaria. |

Funciones adicionales:

| Tipo | Descripción |
|------------|-------------------------------------------------------------------------|
| `CLONE` | Crea una copia a partir de otro atributo. |

# Instalación

Para instalar sobre un proyecto, ejecutar el siguiente comando:

$ `npm install --save field-creator`

# Ejemplos

# Ejemplo 1
## Ejemplo 1. Definición de modelos

Podemos crear modelos Sequelize de la siguiente manera:

Archivo `libro.model.js`
``` js
const { Field } = require('insac-field')
const { Field } = require('field-creator')

module.exports = (sequelize, Sequelize) => {
return sequelize.define('libro', {
id: Field.ID(),
titulo: Field.STRING(10),
precio: Field.FLOAT()
id : Field.ID(),
titulo : Field.STRING(10),
precio : Field.FLOAT()
})
}
```

# Ejemplo 2.
Es lo mismo que hacer:
``` js
const { Field, FieldContainer } = require('insac-field')

const container = new FieldContainer()
container.define('libro', {
id: Field.ID(),
titulo: Field.STRING(10),
precio: Field.FLOAT()
})
const INPUT = {
body: container.group('libro', {
titulo: Field.THIS({ allowNull: false }),
precio: Field.THIS({ allowNull: false })
module.exports = (sequelize, Sequelize) => {
return sequelize.define('libro', {
id: {
type : Sequelize.INTEGER(),
primaryKey : true,
autoIncrement : true,
allowNull : false,
validate : {
isInt : { args: [true] },
min : { args: [1] },
max : { args: [2147483647] }
}
},
titulo: {
type: Sequelize.STRING(10),
validate: {
len: { args: [0, 10] }
}
},
precio: {
type: Sequelize.INTEGER(),
validate: {
isFloat : { args: [true] },
min : { args: [0] },
max : { args: [1E+308] }
}
}
})
}
```

## Ejemplo 2. Definiendo grupos de fields

``` js
const { Field, THIS } = require('field-creator')
const fieldGroup = Field.group(sequelize.models.libro, {
id_libro : THIS(),
titulo : THIS({ allowNull: false }),
precio : THIS({ allowNull: false }),
autor : {
id_autor : THIS(),
nombre : THIS()
},
custom: Field.STRING({ comment: 'custom' })
})
```

La función `THIS`, indica que el campo es parte del modelo definido en el `group`.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/field-creator')

0 comments on commit 1a5e2f6

Please sign in to comment.