-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from waquispe/develop
Develop
- Loading branch information
Showing
16 changed files
with
3,725 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } }] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
/node_modules | ||
/tmp | ||
/docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./lib/field-creator') |
Oops, something went wrong.