npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

barbakoa

v0.0.17

Published

Fullstack framework based on [Koa](http://koajs.com/)

Downloads

47

Readme

barbakoa

Fullstack framework based on Koa

See axelhzf/barbakoa-base-app for usage example.

Installation

npm install barbakoa --save
barbakoa init

Create an application

var barbakoa = require("barbakoa");
var app = new barbakoa();
app.start();

Router

Barbakoa uses koa-router internally. The router is exposed via barbakoa.router.

var router = barbakoa.router;
router.get("/", function* () {
    this.body = "Hello world";
}

ORM

Barbakoa uses Sequelize for persistence.

Models defined in the folder app/server/models/ are auto initialized.

Define a model

var db = require("barbakoa").db;

module.exports = db.define("User", {
  name: db.types.STRING,
  password: db.types.STRING
});

Sequelize types:

db.types.STRING                      // VARCHAR(255)
db.types.STRING(1234)                // VARCHAR(1234)
db.types.STRING.BINARY               // VARCHAR BINARY
db.types.TEXT                        // TEXT
 
db.types.INTEGER                     // INTEGER
db.types.BIGINT                      // BIGINT
db.types.BIGINT(11)                  // BIGINT(11)
db.types.FLOAT                       // FLOAT
db.types.FLOAT(11)                   // FLOAT(11)
db.types.FLOAT(11, 12)               // FLOAT(11,12)
 
db.types.DECIMAL                     // DECIMAL
db.types.DECIMAL(10, 2)              // DECIMAL(10,2)
 
db.types.DATE                        // DATETIME for mysql / sqlite, TIMESTAMP WITH TIME ZONE for postgres
db.types.BOOLEAN                     // TINYINT(1)
 
db.types.ENUM('value 1', 'value 2')  // An ENUM with allowed values 'value 1' and 'value 2'
db.types.ARRAY(Sequelize.TEXT)       // Defines an array. PostgreSQL only.
 
db.types.BLOB                        // BLOB (bytea for PostgreSQL)
db.types.BLOB('tiny')                // TINYBLOB (bytea for PostgreSQL. Other options are medium and long)
db.types.UUID    

Custom types:

db.types.URL    //db.types.STRING(2000)

Model usage

var User = require("./models/User");
var router = require("barbakoa").router;

router.get("/api/users", function* () {
  var users = yield User.findAll();
  this.body = {users: users};
});

Model class methods

http://sequelize.readthedocs.org/en/latest/docs/models/

project = Project.build({
  title: 'my awesome project',
  description: 'woot woot. this will make me a rich man'
})
task = Task.create({ title: 'foo', description: 'bar', deadline: new Date() })
User.create({ username: 'barfooz', isAdmin: true }, [ 'username' ]) //filter properties


// search for one element
Project.find(123)
Project.find({ where: {title: 'aProject'} })
Project.find({
  where: {title: 'aProject'},
  attributes: ['id', ['name', 'title']]
})

User
  .findOrCreate({where: {username: 'sdepold'}, defaults: {job: 'Technical Lead JavaScript'}})
  .spread(function(user, created) {})
  
  
Project.findAndCountAll({where: { title: { $like: 'foo%'}}, offset: 10, limit: 2 })
  
Project.findAll()
Project.findAll({ where: ["id > ?", 25] })
  
Project.findAll({
  where: {
    id: {
      $gt: 6,                // id > 6
      $gte: 6,               // id >= 6
      $lt: 10,               // id < 10
      $lte: 10,              // id
      $ne: 20,               // id != 20
      $not: 3,               // id NOT 3
      $between: [6, 10],     // BETWEEN 6 AND 10
      $notBetween: [11, 15], // NOT BETWEEN 11 AND 15
      $in: [1, 2],           // IN [1, 2]
      $like: '%hat',         // LIKE '%hat'
      $notLike: '%hat'       // NOT LIKE '%hat'
      $iLike: '%hat'         // ILIKE '%hat' (case insensitive)
      $notILike: '%hat'      // NOT ILIKE '%hat'
      $overlap: [1, 2]       // && [1, 2] (PG array overlap operator)
      $contains: [1, 2]      // @> [1, 2] (PG array contains operator)
      $contained: [1, 2]     // <@ [1, 2] (PG array contained by operator)
    }
  }
})  
  
Project.find({
  where: { name: 'a project', $or: [{ id: [1,2,3] }, { id: { $gt: 10 } }]}
})

Project.findAll({ offset: 10, limit: 2 })
Project.findAll({order: 'title DESC'})
Project.findAll({group: 'name'})

Project.count({ where: ["id > ?", 25] })
Project.max('age')
Project.min('age')
Project.sum('age')

//eager loading
Task.findAll({ include: [ User ] })
User.findAll({ include: [{ model: Tool, as: 'Instruments' }] })


//bulk methods
User.bulkCreate([
  { username: 'barfooz', isAdmin: true },
  { username: 'foo', isAdmin: true }
])

User.bulkCreate([
  { username: 'foo' },
  { username: 'bar', admin: true}
], { fields: ['username'] })

Task.update(
  { status: 'inactive' }, 
  { where: { subject: 'programming' }}
)

Task.destroy({ where: {subject: 'programming'}})

Task.destroy({}, {truncate: true})

Model instance methods

http://sequelize.readthedocs.org/en/latest/docs/instances/

project.save()
task.updateAttributes({title: 'a very different title now'})
task.destroy()
person.reload()
user.increment('my-integer-field')
user.increment('my-integer-field', 2)
user.decrement('my-integer-field')

Migrations

Write your migrations in migrations folder

module.exports = {
  up: function* (migration, types) {
    yield migration.addIndex(
        'Votes', 
        ['UserId', 'SelfieId', "daysFromStart"], 
        {
            indexName: 'SuperDuperIndex',
            indicesType: 'UNIQUE' 
        }
    );
  },
  down: function () {

  }
};

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 = require("barbakoa").router;
var Joi = require("joi")

var idSchema = Joi.object().keys({
  id: Joi.number().integer().min(0).required()
});

router.get("/api/users/:id", function* () {
  var params = yield this.validateParams(idSchema);
  this.body = yield User.find(params.id)
});

Methods:

  • ctx.validateParams(schema) : validates ctx.params
  • ctx.validateQuery(schema) : validates ctx.query
  • ctx.validateBody(schema) : validates ctx.body

Configuration¡

Barbakoa uses node-config

Events

barbakoa.on("post-start", function* () {

});

Events:

  • pre-start
  • post-start

Gulp

Barbakoa comes with several gulp tasks defined.

Define your gulpfile like this to import these tasks

var gulp = require("gulp");
require("barbakoa/gulptasks")(gulp);

Tasks:

  • less : less + autoprefixer
  • jade : client side templating
  • es6 : es6to5 transformation
  • clean
  • build
  • default : clean + build

CLI

  • barbakoa dev : Run app in dev mode. Gulp watch and nodemon for server restart
  • barbakoa test : Run client and server test
  • barbakoa test-client
  • barbakoa test-server