YDN-DB: HTML5 Javascript database library for IndexedDB

yathit logo

OK. So I’m not even gonna lie. I had no idea what IndexedDB was before I came across YDN-DB. I’ve only dabbled with serious JavaScript development so far, and the framework-soup that has arisen in the space rivals Java at this point.

Anyway, on to the website!

YDN-DB is a pure javascript library, which uses HTML5 browser database sunch as IndexedDB, WebDatabase (WebSQL) and WebStorage (localStorage). Most
modern browsers including IE10, Chrome, Firefox and Safari support either IndexedDB or WebSQL. The library can also be used in web client such as
phonegap, WebView and UIWebView mobile clients.

Supports:

  • Chrome 4+ (IndexedDB or WebSql)
  • Firefox 3+ (IndexedDB draft), Firefox 10+ (IndexedDB)
  • IE 6 (userdata), IE7+ (localStorage), IE10+ desktop/mobile (IndexedDB)
  • Safari 3.1+ desktop/mobile/iOS web client (WebSql)
  • Android web client, Android browser 2.1+ (WebSql), 4+ (IndexedDB)
  • Opera 10+ (WebSql), Opera 15+ (IndexedDB)

Code snippets:

var db = new ydn.db.Storage('db-name');
db.put('store-name', {message: 'Hello world!'}, 'id1');
db.get('store-name', 'id1').always(function(record) {
  console.log(record);
});

Indexed Queries

var q = db.from('people').where('age', '>=', 25);
q.list(10).done(function(peoples) {
  console.log(peoples); // list of first 10 peoples
});

var q = db.from('people').where('country', '=', 'US').order('name');
q.list(10).done(function(peoples) {
  console.log(peoples); // list of first 10 peoples from US ordered by name
});
q.list(10).done(function(peoples) {
  console.log(peoples); // next 10 peoples
});

Streaming API for reduced memory usage

var q = db.from('author').where('first', 'starts', input_value);
var ul = document.getElementById('auto-suggestion-list');
ul.innerHTML = '';
q.open(function (cursor) {
  var li = document.createElement('li');
  var people = cursor.getValue();
  li.textContent = people.first + ' ' + people.last;
});

Synchronize with REST backend services

var schema = {
  stores: [{
        name: 'todo',
        keyPath: 'id',
        Sync: {
          format: 'gcs',  // Google Cloud Storage
          Options: {
            bucket: 'ydn-note-data',
            prefix: 'todo/'
          }
        }
  }]
};
var db = new ydn.db.Storage(db_name, schema);
// GET https://ydn-note-data.storage.googleapis.com/todo/id123
db.get('todo', 'id123');
// PUT https://ydn-note-data.storage.googleapis.com/todo/id123
db.put('todo', 'id123');
// DELETE https://ydn-note-data.storage.googleapis.com/todo/id123
db.remove('todo', 'id123');

JavaScript: The Right Way

JavaScript the right way site header

From the JavaScript: The Right Way site (via Hacker News):

…a JavaScript guide intended to introduce new developers and help experienced ones to the JavaScript’s best practices.
Despite the name, this guide doesn’t mean exactly “the right way” to do JavaScript.
We just gather all the stuff from top developers and put here. Since it come from exceptional folks, we could say that it is “the right way”, or
the best way to do so.

Dart: Google-backed programming language built to address issues in JavaScript

Dart Logo

I have to admit that this project pushes all of the right buttons for me. It looks like a fully structured language. It allows the use of types which opens the door for good tool support. It compiles down to JavaScript, so it will run in any browser. It can run on the server. Inheritance, generitc, isolates, annotations… I’m looking forward to building something in Dart.

From Wikipedia:

Dart is an open-source Web programming language developed by Google.

The goal of Dart is “ultimately to replace JavaScript as the lingua franca of web development on the open web platform”, but Dart currently relies
exclusively on its cross-compilation to JavaScript feature in order to run in mainstream browsers. Dart is intended to address issues with
JavaScript that Google engineers felt could not be solved by evolving the language, while offering better performance. Google works on Dart to help
it build more complex, full-featured client-side Web applications.
Dart is a class-based, single inheritance, object-oriented language with C-style syntax. It supports interfaces, abstract classes, reified
generics, and optional typing. Static type annotations do not affect the runtime semantics of the code. Instead, the type annotations can provide
documentation for tools like static checkers and dynamic run time checks.

From the Dart: Up and Running book on the Dart website:

Dart is easy to learn. A wide range of developers can learn Dart quickly. It’s an object-oriented language with classes, single inheritance,
lexical scope, top-level functions, and a familiar syntax. Most developers are up and running with Dart in just a few hours.

Dart compiles to JavaScript. Dart has been designed from the start to compile to JavaScript, so that Dart apps can run across the entire
modern web. Every feature considered for the language must somehow be translated to performant and logical JavaScript before it is added. Dart
draws a line in the sand and doesn’t support older, legacy browsers.

Dart runs in the client and on the server. The Dart virtual machine (VM) can be integrated into a web browser, but it can also run standalone
on the command line. With built-in library support for files, directories, sockets, and even web servers, you can use Dart for full end-to-end
apps.

Dart comes with a lightweight editor. You can use Dart Editor to write, launch, and debug Dart apps. The editor can help you with code
completion, detecting potential bugs, debugging both command-line and web apps, and even refactoring. Dart Editor isn’t required for writing
Dart; it’s just a tool that can help you write better code faster.

Dart supports types, without requiring them. You can omit types when you want to move very quickly, aren’t sure what structure to take, or
simply want to express something you can’t with the type system. You can add types as your program matures, the structure becomes more evident,
and more developers join the project. Dart’s optional types are static type annotations that act as documentation, clearly expressing your
intent. Using types means that fewer comments are required to document the code, and tools can give better warnings and error messages.

Dart scales from small scripts to large, complex apps. Web development is very much an iterative process. With the reload button acting as
your compiler, building the seed of a web app is often a fun experience of writing a few functions just to experiment. As the idea grows, you can
add more code and structure. Thanks to Dart’s support for top-level functions, optional types, classes, and libraries, your Dart programs can
start small and grow over time. Tools such as Dart Editor help you refactor and navigate your code as it evolves.

Dart has a wide array of built-in libraries. The core library supports built-in types and other fundamental features such as collections,
dates, and regular expressions. Web apps can use the HTML library—think DOM programming, but optimized for Dart. Command-line apps can use the
I/O library to work with files, directories, sockets, and servers. Other libraries include URI, UTF, Crypto, Math, and Unit test.

Dart supports safe, simple concurrency with isolates. Traditional shared-memory threads are difficult to debug and can lead to deadlocks.
Dart’s isolates, inspired by Erlang, provide an easier to understand model for running isolated, but concurrent, portions of your code. Spawning
new isolates is cheap and fast, and no state is shared.

Dart supports code sharing. Traditional web programming workflows can’t integrate third-party libraries from arbitrary sources or frameworks.
With the Dart package manager (pub) and language features such as libraries, you can easily discover, install, and integrate code from across the
web and enterprise.

Dart is open source. Dart was born for the web, and it’s available under a BSD-style license. You can find the project’s issue tracker and
source repository online. Maybe you’ll submit the next patch?