DailyJS

DailyJS

The JavaScript blog.


Tagdatabases
Featured

meteor books plugins databases servers apps mysql sponsored-content jquery

Your First Meteor Application, OData Server, ItemSlide.js

Posted on .

Your First Meteor Application

Your First Meteor Application

David Turnbull's Your First Meteor Application is a highly focused, beginner-friendly introduction to Meteor. David updates the book regularly when Meteor changes, so it's worth checking back every so often to look for new content.

You can read the book online or download the PDF for free. If you prefer video, there are also screencasts for $39.

OData Server

The OData Server (GitHub: gizur/odataserver, License: MIT, npm: odataserver) by Jonas Colmsjö is an OData server that's backed by MySQL. It's easy to drop into an Express project, and it's designed to work as a quick "mobile backend as a service" type of app.

It has a simple HTTP API, and Jonas has included usage examples for curl that show you how to create users, databases, and insert data. It actually does things like MySQL database and schema creation, so it requires a MySQL administrator account to work correctly.

If you're interested in this and want to quickly try it out, the advanced usage guide has instructions for deploying it to Docker.

ItemSlide.js

ItemSlide.js (GitHub: itemslide/itemslide.github.io, License: MIT, npm: itemslide) by Nir Lichtman is a touch-friendly carousel.

With jQuery you can set it up like this:

var carousel = $('ul');  
carousel.itemslide({ swipe_out: true });  

And it has events for responding to user interaction:

carousel.on('pan', function(e) {});  
carousel.on('changeActiveIndex', function(e) {});  
carousel.on('changePos', function(e) {  
  console.log('new pos:', carousel.getCurrentPos());
});
carousel.on('swipeout', function(event) {  
  console.log('swiped out slide:', event.slide);
});

You don't have to use it with jQuery, but if you do you'll get things like mousewheel support.

Featured

libraries databases node modules angularjs

JOQULAR, angular-atomic-notify

Posted on .

JOQULAR

Simon Y. Blackwell sent in JOQULAR (GitHub: anywhichway/joqular, License: GPL3, npm: joqular), a query language that can be serialised safely as JSON. It has 30 built-in predicates and operators, and extensive date and time representations.

It manages indexes using a just-in-time in-memory database, which is faster than a linear search:

Because JOQULAR defers 75% of the indexing effort until the first query requiring the index, the up front cost of indexing is marginal. It also turns out that the just-in-time indexing has a negligible impact on the first query. What is avoided and passed onto the user as time savings is lots of thrashing during object inserts and updates.

The authors claim it's faster than IndexedDB and PouchDB for insert and search.

The library was created as part of commercial work by the company behind it (AnyWhichWay). The original work was capable of querying Google Cloud Datastore, Quickbase, Elastic Search, and some Amazon AWS services using the same expression language.

To make queries, you need to create some classes to index. You can use plain old prototype classes:

function Person(name,age) {  
  this.name = name;
  this.age = age;
}
Person.prototype = new Entity();

Person = JOQULAR.createIndex(Person, true);

var p1 = new Person('Joe', 24);  
var p2 = new Person('Mary', 18);

Person.joqularSave();  

And then make a query like this:

Person.joqularFind({ name: 'Joe' });  

It's got an ODM feel to it, but you could technically index anything. This example is based on the example code from the wiki -- if you want to read more take a look at the JOQULAR API documentation and the patterns page.

JOQULAR works with Chrome and Node out of the box, but Firefox and IE need polyfills for Object.Observe.

angular-atomic-notify

Maxi Gimenez's angular-atomic-notify (GitHub: maxigimenez/angular-atomic-notify, License: MIT, npm: angular-atomic-notify) is an AngularJS library for presenting notifications. There's an ng-atomic-notify directive, and methods like atomicNotify.info(message, delay) and atomicNotify.error.

The samples use Font Awesome for icons, and the overall design looks Material Design-inspired to me.

Featured

libraries databases node

ForerunnerDB, rdb

Posted on .

ForerunnerDB

ForerunnerDB

Rob Evans sent in ForerunnerDB (GitHub: Irrelon/ForerunnerDB, License: MIT, npm: forerunnerdb), a new database written with Node that uses MongoDB's query language.

ForerunnerDB was created primarily to allow web application developers to easily store, query and manipulate JSON data in the browser via a simple query language. It provides the ability to store data passed by an API to the front-end and query it throughout your application making handling JSON data client-side significantly easier.

Furthermore, if you use the optional data-binding module, changes to your JSON data stored in ForerunnerDB are automatically propagated to the DOM. Some web application frameworks provide similar functionality which is why data-binding is an optional module.

The data-binding layer is optional, and is provided through a separate module. It depends on jQuery, and works using data attributes. It's a little bit like KnockoutJS.

This project seems ideal if you're trying to create single page applications that receive initial chunks of JSON from the server, and if your team is used to MongoDB. Browser-based persistence is available through IndexedDB, WebSQL, and LocalStorage.

One unique feature of ForerunnerDB is iOS support. It's still experimental, but sounds like it could be useful for transitioning single page apps to native iOS applications:

The iOS version is part of the roadmap and will include data-binding for list structures like UITableView, as well as individual controls like UILabel. Data-persistence is already working as well as inserting and basic data queries, update and remove.

rdb

rdb (GitHub: alfateam/rdb, License: MIT, npm: rdb), a new ORM module, was posted to Hacker news today, and got lots of interest. Finding the right ORM is always difficult, but this one already has support for transactions, lazy loading, and promises. It supports PostgreSQL and MySQL. Someone on Hacker News mentioned the lack of SQLite support, but I always run a local version of the database I'm going to deploy against, just because I don't trust ORMs to work seamlessly between databases.

If you like promises, you may prefer rdb to the Active Record-inspired ORMs that most people seem to use. Given some suitable functions, you can write clean statements like this:

db.transaction()  
  .then(insert)
  .then(getById)
  .then(verifyInserted)
  .then(rdb.commit)
  .then(null, rdb.rollback)
  .then(onOk, onFailed);

I've taken this from the rdb documentation and examples. The main developer, Lars-Erik Roald, has been working on this module since May 2013, and he said it's used commercially on Hacker News, so you should give it a try if you haven't found the right ORM yet.

Featured

libraries JSON databases node modules

LowDB

Posted on .

LowDB (GitHub: typicode / lowdb, License: MIT, npm: lowdb) by typicode is a JSON database that uses Lo-Dash. Rather than using a MongoDB-inspired API, it feels more like functional JavaScript.

Data is queried using familiar chained operators, ending in value when you want to obtain the result:

var topFiveSongs = low('posts')  
  .where({ published: true })
  .sortBy('views')
  .first(5)
  .value();

LowDB accepts some configuration options, allowing you to control how it behaves. For example, if you want to use it like an in-memory database, then you can set autoSave to false:

var low = require('lowdb')  
low.autoSave = false;  

There's also a short syntax API for the basic operations. To perform a where query, you can do this:

low('songs', {title: 'low!'})  
// -> low('songs').where({title: 'low!'}).value()

low('songs', {published: false}, {published: true})  
// -> low('songs').updateWhere({published: false}, {published: true}).value()

It doesn't seem to work with localStorage, which I think would be cool, but it might work with Browserify.

Featured

databases node modules npm cluster

Node Roundup: 0.10.19, klei-migrate, division

Posted on .

Node 0.10.19 Released

Node 0.10.19 was released yesterday. This version updates uv, npm, and also some core modules: readline, stream, and tls.

When you read uv: Upgrade to v0.10.17 in the release notes, don't you wonder what that means? If you're interested in the changes in libuv, all you need to do is checkout the relevant tag from GitHub. In this case it's libuv/tree/v0.10.17:

2013.09.25, Version 0.10.17 (Stable)  
Changes since version 0.10.16:

* build: remove GCC_WARN_ABOUT_MISSING_NEWLINE (Ben Noordhuis)
* darwin: fix 10.6 build error in fsevents.c (Ben Noordhuis)

If you switch to 0.11.13, the latest unstable release, you'll see a whole load of interesting changes -- uv_fs_stat has been rewritten, FSEventStream is now shared between multiple filesystem watchers, so it removes the limit on the maximum number of file watchers that can be created on OS X. These are just some random changes that caught my eye, there are plenty more.

These libuv changes have a direct impact on Node's filesystem and networking modules, so it's worth paying attention if you can.

klei-migrate

klei-migrate (GitHub: klei-dev / migrate, License: MIT, npm: klei-migrate) by Joakim Bengtson is a database independent migration command-line tool. It also works as a module, and has a Grunt plugin.

Migrations can be created with klei-migrate new, and then run with klei-migrate run. There are also other commands designed to help deal with switching between git branches, which can be tied into a post-checkout hook.

division

division (GitHub: codename- / division, License: MIT, npm: division) is another cluster module wrapper:

division provides an easy to use, chainable API, with some built-in extensions (like signals handlers) and is built with performance, zero-downtime restart (of workers), stability and simplicity in mind. The main advantage of division is that it does not depend of other modules - less dependencies equal less places where something could went wrong.

var division = require('division');  
var cluster = new division();

// Configuration for development environment
cluster.configure('development', function() {  
  // Put your development configuration here
  cluster.set('args', ['--some-process-args', 'send-to-workers']);
});

cluster.configure('production', function() {  
  // Put your production configuration here
  cluster.enable('silent');
});

cluster.configure(function() {  
  this.set('path', 'app.js');
});

cluster.set('size', 2);  
cluster.use('debug').use('signals');

// Start your application as a cluster!
cluster.run(function() {  
  // `this` is pointing to the Master instance
});