barbakoa
Fullstack framework based on Koa
See axelhzf/barbakoa-base-app for usage example.
Installation
npm install barbakoa --savebarbakoa init
Create an application
var barbakoa = ;var app = ;appstart;
Router
Barbakoa uses koa-router internally. The router is exposed via barbakoa.router
.
var router = barbakoarouter;router
ORM
Barbakoa uses Sequelize for persistence.
Models defined in the folder app/server/models/
are auto initialized.
Define a model
var db = db; moduleexports = db;
dbtypesSTRING // VARCHAR(255)dbtypes // VARCHAR(1234)dbtypesSTRINGBINARY // VARCHAR BINARYdbtypesTEXT // TEXT dbtypesINTEGER // INTEGERdbtypesBIGINT // BIGINTdbtypes // BIGINT(11)dbtypesFLOAT // FLOATdbtypes // FLOAT(11)dbtypes // FLOAT(11,12) dbtypesDECIMAL // DECIMALdbtypes // DECIMAL(10,2) dbtypesDATE // DATETIME for mysql / sqlite, TIMESTAMP WITH TIME ZONE for postgresdbtypesBOOLEAN // TINYINT(1) dbtypes // An ENUM with allowed values 'value 1' and 'value 2'dbtypes // Defines an array. PostgreSQL only. dbtypesBLOB // BLOB (bytea for PostgreSQL)dbtypes // TINYBLOB (bytea for PostgreSQL. Other options are medium and long)dbtypesUUID
Custom types:
dbtypesURL //db.types.STRING(2000)
Model usage
var User = ;var router = router; router;
Model class methods
http://sequelize.readthedocs.org/en/latest/docs/models/
project = Projecttask = TaskUser //filter properties // search for one elementProjectProjectProject User Project ProjectProject Project Project ProjectProjectProject ProjectProjectProjectProject //eager loadingTaskUser //bulk methodsUser User Task Task Task
Model instance methods
http://sequelize.readthedocs.org/en/latest/docs/instances/
projecttasktaskpersonuseruseruser
Migrations
Write your migrations in migrations
folder
moduleexports = { migration; } { };
Migration methods
http://sequelize.readthedocs.org/en/latest/docs/migrations/
createTable(tableName, attributes, options)
dropTable(tableName)
dropAllTables()
renameTable(before, after)
showAllTables()
describeTable(tableName)
addColumn(tableName, attributeName, dataTypeOrOptions)
removeColumn(tableName, attributeName)
changeColumn(tableName, attributeName, dataTypeOrOptions)
renameColumn(tableName, attrNameBefore, attrNameAfter)
addIndex(tableName, attributes, options)
removeIndex(tableName, indexNameOrAttributes)
Request parsing and validation
var router = router;var Joi = var idSchema = Joiobject; router;
Methods:
ctx.validateParams(schema)
: validates ctx.paramsctx.validateQuery(schema)
: validates ctx.queryctx.validateBody(schema)
: validates ctx.body
Configuration¡
Barbakoa uses node-config
Events
barbakoa;
Events:
- pre-start
- post-start
Gulp
Barbakoa comes with several gulp tasks defined.
Define your gulpfile
like this to import these tasks
var gulp = ;gulp;
Tasks:
less
: less + autoprefixerjade
: client side templatinges6
: es6to5 transformationclean
build
default
: clean + build
CLI
barbakoa dev
: Run app in dev mode. Gulp watch and nodemon for server restartbarbakoa test
: Run client and server testbarbakoa test-client
barbakoa test-server