Skip to content
Browse files

working

  • Loading branch information...
1 parent eadb1c6 commit 1d8ead11d2e5a217ac13072e63245737bf0344eb @chrisdew committed Feb 9, 2011
View
2 docs/barricane-db.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html> <html> <head> <title>barricane-db.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="create-database.html"> create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="read-database.html"> read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> barricane-db.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
+<!DOCTYPE html> <html> <head> <title>barricane-db.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-create-database.html"> example-create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="example-read-database.html"> example-read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> barricane-db.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
Released under the MIT open source licence.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>This file is the entry point for the NPM barricane-db package.
It only exports symbols required from other modules.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">bdb</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./db&#39;</span><span class="p">);</span>
<span class="nx">exports</span><span class="p">.</span><span class="nx">DB</span> <span class="o">=</span> <span class="nx">bdb</span><span class="p">.</span><span class="nx">DB</span><span class="p">;</span>
View
2 docs/bdb-disk-manager.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html> <html> <head> <title>bdb-disk-manager.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="create-database.html"> create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="read-database.html"> read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> bdb-disk-manager.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>The DB Manager handles aspects such as loading DBs from disk and persistence.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">bdb</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;../lib/old-barricane-db&#39;</span><span class="p">);</span>
+<!DOCTYPE html> <html> <head> <title>bdb-disk-manager.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-create-database.html"> example-create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="example-read-database.html"> example-read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> bdb-disk-manager.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>The DB Manager handles aspects such as loading DBs from disk and persistence.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">bdb</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;../lib/old-barricane-db&#39;</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;fs&#39;</span><span class="p">);</span>
<span class="kd">function</span> <span class="nx">BDBDiskManager</span><span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
View
28 docs/db.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html> <html> <head> <title>db.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="create-database.html"> create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="read-database.html"> read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> db.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
+<!DOCTYPE html> <html> <head> <title>db.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-create-database.html"> example-create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="example-read-database.html"> example-read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> db.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
Released under the MIT open source licence.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>This module contains the database code.
It specifically eschews serialisation and io concerns.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">uuid</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;node-uuid&#39;</span><span class="p">)</span>
<span class="p">,</span> <span class="nx">dio</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./disk-io&#39;</span><span class="p">)</span>
@@ -37,21 +37,19 @@
<span class="k">this</span><span class="p">.</span><span class="nx">persist</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>This must be called once for every instance which needs to be persisted.
It is idiomatic to do this in the constructor, using a global
-<code>process.db</code> database.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">registerInstance</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">instance</span><span class="p">)</span> <span class="p">{</span>
- <span class="kd">var</span> <span class="nx">that</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
-
- <span class="nx">instance</span><span class="p">[</span><span class="k">this</span><span class="p">.</span><span class="nx">UUID_TAG</span><span class="p">]</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">uuid</span><span class="p">();</span>
-
+<code>process.db</code> database.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">registerInstance</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">instance</span><span class="p">,</span> <span class="nx">force</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">that</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>Skip register instance at this stage, unless forced.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">persist</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">force</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span><span class="p">;</span>
+ <span class="p">}</span>
+ </pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>Only create a new UUID if one does not exist.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">instance</span><span class="p">[</span><span class="k">this</span><span class="p">.</span><span class="nx">UUID_TAG</span><span class="p">]</span> <span class="o">=</span> <span class="nx">instance</span><span class="p">[</span><span class="k">this</span><span class="p">.</span><span class="nx">UUID_TAG</span><span class="p">]</span> <span class="o">||</span> <span class="k">this</span><span class="p">.</span><span class="nx">uuid</span><span class="p">();</span>
+
<span class="k">this</span><span class="p">.</span><span class="nx">instances</span><span class="p">[</span><span class="nx">instance</span><span class="p">[</span><span class="k">this</span><span class="p">.</span><span class="nx">UUID_TAG</span><span class="p">]]</span> <span class="o">=</span> <span class="nx">instance</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="p">{};</span> <span class="c1">// the backing store for the instance data</span>
<span class="k">this</span><span class="p">.</span><span class="nx">stores</span><span class="p">[</span><span class="nx">instance</span><span class="p">[</span><span class="k">this</span><span class="p">.</span><span class="nx">UUID_TAG</span><span class="p">]]</span> <span class="o">=</span> <span class="nx">store</span><span class="p">;</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;about to create setters&quot;</span><span class="p">);</span>
<span class="nx">util</span><span class="p">.</span><span class="nx">ownRealKeys</span><span class="p">(</span><span class="nx">instance</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">magic</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">p</span><span class="p">,</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">all</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">store</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span> <span class="o">=</span> <span class="nx">instance</span><span class="p">[</span><span class="nx">p</span><span class="p">];</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;creatig setter&quot;</span><span class="p">,</span> <span class="nx">p</span><span class="p">);</span>
<span class="nx">instance</span><span class="p">.</span><span class="nx">__defineSetter__</span><span class="p">(</span><span class="nx">p</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">val</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;setter called&quot;</span><span class="p">,</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">that</span><span class="p">.</span><span class="nx">persist</span><span class="p">));</span>
<span class="nx">store</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span> <span class="o">=</span> <span class="nx">val</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">that</span><span class="p">.</span><span class="nx">persist</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">that</span><span class="p">.</span><span class="nx">io</span><span class="p">.</span><span class="nx">persist</span><span class="p">(</span><span class="nx">instance</span><span class="p">);</span>
@@ -62,17 +60,17 @@
<span class="p">});</span>
<span class="p">});</span>
- </pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>Finally add the object to the log, if the database is not in the middle
+ </pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Finally add the object to the log, if the database is not in the middle
of reconstruction.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">persist</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">io</span><span class="p">.</span><span class="nx">persist</span><span class="p">(</span><span class="nx">instance</span><span class="p">);</span>
<span class="p">}</span>
-<span class="p">};</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>The database needs to keep track of constructors, so that it can call them
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>The database needs to keep track of constructors, so that it can call them
when loading a database.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">registerConstructors</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">args</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">constructors</span><span class="p">[</span><span class="nx">args</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="nx">args</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
<span class="p">}</span>
-<span class="p">};</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>This is a very inefficient and rudimentary query. It is envisaged that most
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>This is a very inefficient and rudimentary query. It is envisaged that most
objects will be accessed via O(1) traversal, rather than this naive O(N)
lookup.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">find</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">property</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">tmp</span> <span class="o">=</span> <span class="p">[];</span>
@@ -85,10 +83,10 @@
<span class="p">}</span>
<span class="k">return</span> <span class="nx">tmp</span><span class="p">;</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>Just a wrapper.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">deleteSync</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>Just a wrapper.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">deleteSync</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">io</span><span class="p">.</span><span class="nx">deleteSync</span><span class="p">();</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>Just a wrapper.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">end</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <p>Just a wrapper.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">end</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">io</span><span class="p">.</span><span class="nx">end</span><span class="p">(</span><span class="nx">callback</span><span class="p">);</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>Export the symbols.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">exports</span><span class="p">.</span><span class="nx">DB</span> <span class="o">=</span> <span class="nx">DB</span><span class="p">;</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <p>Export the symbols.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">exports</span><span class="p">.</span><span class="nx">DB</span> <span class="o">=</span> <span class="nx">DB</span><span class="p">;</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
35 docs/disk-io.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html> <html> <head> <title>disk-io.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="create-database.html"> create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="read-database.html"> read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> disk-io.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
+<!DOCTYPE html> <html> <head> <title>disk-io.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-create-database.html"> example-create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="example-read-database.html"> example-read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> disk-io.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
/ Released under the MIT open source licence.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>This module contains the DiskIO code.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>The DiskIO constructor creates an object which can be used by DB to interact
with the outside world. Other IOs will be possible in future, including
ReplicationIO.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">codec</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./swoj-codec&#39;</span><span class="p">)</span>
@@ -11,6 +11,7 @@
<span class="k">this</span><span class="p">.</span><span class="nx">path</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">path</span> <span class="o">||</span> <span class="s1">&#39;/tmp&#39;</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">name</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">name</span> <span class="o">||</span> <span class="s1">&#39;unnamed_db&#39;</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">codec</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">codec</span> <span class="o">||</span> <span class="k">new</span> <span class="nx">codec</span><span class="p">.</span><span class="nx">Codec</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">magic</span><span class="p">);</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">magic</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">magic</span> <span class="o">||</span> <span class="s1">&#39;__&#39;</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">db</span> <span class="o">=</span> <span class="nx">db</span><span class="p">;</span>
</pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Psuedo constants.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">FILENAME</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">name</span> <span class="o">+</span> <span class="s2">&quot;.&quot;</span>
<span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">codec</span><span class="p">.</span><span class="nx">defaultFileExtension</span> <span class="o">+</span> <span class="s2">&quot;.barricane-db&quot;</span><span class="p">;</span>
@@ -24,7 +25,6 @@
written.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">outstandingWrites</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>If end is requested, this will contain a callback.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">ending</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>This writes an object to disk.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DiskIO</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">persist</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">instance</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;persisting&quot;</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">that</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">outstandingWrites</span><span class="o">++</span><span class="p">;</span>
@@ -40,11 +40,8 @@
<span class="kd">var</span> <span class="nx">preexisting</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
</pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>First get the contents of the path.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">contents</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readdirSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">path</span><span class="p">);</span>
</pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>If there's a pre-existing file, we move it to old then read in the
-contents later.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;about to rename&quot;</span><span class="p">);</span>
- <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">contents</span><span class="p">)</span> <span class="p">{</span>
+contents later.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">contents</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">contents</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">===</span> <span class="k">this</span><span class="p">.</span><span class="nx">FILENAME</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;renaming &quot;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">path</span> <span class="o">+</span> <span class="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">FILENAME</span><span class="p">,</span>
- <span class="s2">&quot;to&quot;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">path</span> <span class="o">+</span> <span class="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">OLD_FILENAME</span><span class="p">);</span>
<span class="nx">fs</span><span class="p">.</span><span class="nx">renameSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">path</span> <span class="o">+</span> <span class="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">FILENAME</span><span class="p">,</span>
<span class="k">this</span><span class="p">.</span><span class="nx">path</span> <span class="o">+</span> <span class="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">OLD_FILENAME</span><span class="p">);</span>
<span class="nx">preexisting</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
@@ -56,27 +53,19 @@
<span class="k">if</span> <span class="p">(</span><span class="nx">preexisting</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">_load</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">path</span> <span class="o">+</span> <span class="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">OLD_FILENAME</span><span class="p">);</span>
<span class="p">}</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>This loads a database from disk.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DiskIO</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_load</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">filepath</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>this.oldFd = fs.openSync(filepath, 'r');
-FIXME: we need to do this incrementally, for large databases.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">data</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="nx">filepath</span><span class="p">,</span> <span class="s1">&#39;utf8&#39;</span><span class="p">);</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;data&quot;</span><span class="p">,</span> <span class="nx">data</span><span class="p">);</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>This loads a database from disk.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DiskIO</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_load</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">filepath</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>FIXME: we need to do this incrementally, for large databases.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">data</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="nx">filepath</span><span class="p">,</span> <span class="s1">&#39;utf8&#39;</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">lines</span> <span class="o">=</span> <span class="nx">data</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s1">&#39;\n&#39;</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">lines</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;line&quot;</span><span class="p">,</span> <span class="s2">&quot;|&quot;</span> <span class="o">+</span> <span class="nx">lines</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot;|&quot;</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">lines</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">===</span> <span class="s2">&quot;&quot;</span><span class="p">)</span> <span class="p">{</span>
<span class="k">continue</span><span class="p">;</span>
- <span class="p">}</span>
- <span class="kd">var</span> <span class="nx">object</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">codec</span><span class="p">.</span><span class="nx">deserialise</span><span class="p">(</span><span class="nx">lines</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span> <span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">.</span><span class="nx">constructors</span><span class="p">);</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;object&quot;</span><span class="p">,</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">object</span><span class="p">));</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;this.UUID_TAG&quot;</span><span class="p">,</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">UUID_TAG</span><span class="p">));</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;object[this.UUID_TAG]&quot;</span><span class="p">,</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">object</span><span class="p">[</span><span class="k">this</span><span class="p">.</span><span class="nx">UUID_TAG</span><span class="p">]));</span>
- <span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">.</span><span class="nx">instances</span><span class="p">[</span><span class="nx">object</span><span class="p">[</span><span class="k">this</span><span class="p">.</span><span class="nx">UUID_TAG</span><span class="p">]]</span> <span class="o">=</span> <span class="nx">object</span><span class="p">;</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;instances&quot;</span><span class="p">,</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">.</span><span class="nx">instances</span><span class="p">));</span>
- <span class="nx">process</span><span class="p">.</span><span class="nx">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>FIXME: We should do something about an exception here, if the
+database file was truncated.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">object</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">codec</span><span class="p">.</span><span class="nx">deserialise</span><span class="p">(</span><span class="nx">lines</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span> <span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">.</span><span class="nx">constructors</span><span class="p">);</span>
+ </pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Forcing this registration is required, as db.persist is currently
+false.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">.</span><span class="nx">registerInstance</span><span class="p">(</span><span class="nx">object</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">this</span><span class="p">.</span><span class="nx">codec</span><span class="p">.</span><span class="nx">fixRefs</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">.</span><span class="nx">instances</span><span class="p">);</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>This will delete any pre-existing database files - for now it just moves them
-aside.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DiskIO</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">deleteSync</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>First get the contents of the path.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">contents</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readdirSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">path</span><span class="p">);</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;contents:&#39;</span><span class="p">,</span> <span class="nx">contents</span><span class="p">);</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>This will delete any pre-existing database files - for now it just moves them
+aside.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DiskIO</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">deleteSync</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>First get the contents of the path.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">contents</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readdirSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">path</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">contents</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">contents</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">===</span> <span class="k">this</span><span class="p">.</span><span class="nx">FILENAME</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">fs</span><span class="p">.</span><span class="nx">renameSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">path</span> <span class="o">+</span> <span class="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">FILENAME</span><span class="p">,</span>
@@ -91,10 +80,10 @@
<span class="nx">DiskIO</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">end</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">outstandingWrites</span> <span class="o">===</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">fd</span><span class="p">.</span><span class="nx">end</span><span class="p">();</span> <span class="c1">// FIXME: we need to call the callback only after the end.</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">writeStream</span><span class="p">.</span><span class="nx">end</span><span class="p">();</span> <span class="c1">// FIXME: we need to call the callback only after the end.</span>
<span class="nx">callback</span><span class="p">(</span><span class="kc">false</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">this</span><span class="p">.</span><span class="nx">ending</span> <span class="o">=</span> <span class="nx">callback</span><span class="p">;</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>Export the symbols.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">exports</span><span class="p">.</span><span class="nx">DiskIO</span> <span class="o">=</span> <span class="nx">DiskIO</span><span class="p">;</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>Export the symbols.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">exports</span><span class="p">.</span><span class="nx">DiskIO</span> <span class="o">=</span> <span class="nx">DiskIO</span><span class="p">;</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
25 docs/example-create-database.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html> <html> <head> <title>example-create-database.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-create-database.html"> example-create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="example-read-database.html"> example-read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> example-create-database.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
+Released under the MIT open source licence.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">bdb</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;barricane-db&#39;</span><span class="p">)</span>
+ <span class="p">,</span> <span class="nx">model</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./example-model&#39;</span><span class="p">);</span>
+ <span class="p">;</span>
+ </pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Create a database instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">db</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">bdb</span><span class="p">.</span><span class="nx">DB</span><span class="p">({</span><span class="nx">path</span><span class="o">:</span> <span class="s1">&#39;/tmp&#39;</span><span class="p">,</span> <span class="nx">name</span><span class="o">:</span> <span class="s1">&#39;test_db&#39;</span><span class="p">});</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Make the database available globally with the process. If you don't do this,
+you can manually inject the database into appropriate constructors, or call
+<code>DB.registerInstance(instance)</code> every time you create an object. </p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">process</span><span class="p">.</span><span class="nx">db</span> <span class="o">=</span> <span class="nx">db</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Delete any database of the same path and name. Most applications will never
+use this. It's only used here so that we know this has created a brand new
+database.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">db</span><span class="p">.</span><span class="nx">deleteSync</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>process.exit(0);</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Open the database for business. Most once-per-process methods of DB are
+synchronous, as it's not really an issue and makes applications simpler.
+All persistence is done asynchronously.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">db</span><span class="p">.</span><span class="nx">openSync</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Construct a simple model from which objects can be persisted.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">house</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">model</span><span class="p">.</span><span class="nx">House</span><span class="p">(</span><span class="s2">&quot;301 Cobblestone Wy., Bedrock, 70777&quot;</span><span class="p">);</span>
+<span class="kd">var</span> <span class="nx">fred</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">model</span><span class="p">.</span><span class="nx">Person</span><span class="p">(</span><span class="s2">&quot;Fred&quot;</span><span class="p">,</span> <span class="s2">&quot;Flintstone&quot;</span><span class="p">);</span>
+<span class="nx">fred</span><span class="p">.</span><span class="nx">house</span> <span class="o">=</span> <span class="nx">house</span><span class="p">;</span>
+<span class="kd">var</span> <span class="nx">wilma</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">model</span><span class="p">.</span><span class="nx">Person</span><span class="p">(</span><span class="s2">&quot;Wilma&quot;</span><span class="p">,</span> <span class="s2">&quot;Flintstone&quot;</span><span class="p">);</span>
+<span class="nx">wilma</span><span class="p">.</span><span class="nx">house</span> <span class="o">=</span> <span class="nx">house</span><span class="p">;</span>
+<span class="nx">fred</span><span class="p">.</span><span class="nx">spouse</span> <span class="o">=</span> <span class="nx">wilma</span><span class="p">;</span>
+<span class="nx">wilma</span><span class="p">.</span><span class="nx">spouse</span> <span class="o">=</span> <span class="nx">fred</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>No save() needed - persistence is implicit.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Finally, close the database.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">db</span><span class="p">.</span><span class="nx">end</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">result</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;database has persisted successfully&#39;</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;error:&#39;</span><span class="p">,</span> <span class="nx">error</span><span class="p">);</span>
+ <span class="p">}</span>
+<span class="p">});</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
2 docs/example-model.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html> <html> <head> <title>example-model.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="create-database.html"> create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="read-database.html"> read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> example-model.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
+<!DOCTYPE html> <html> <head> <title>example-model.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-create-database.html"> example-create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="example-read-database.html"> example-read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> example-model.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
Released under the MIT open source licence.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>This is demonstration model code, as used in the examples.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>A house constructor.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">House</span><span class="p">(</span><span class="nx">address</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">address</span> <span class="o">=</span> <span class="nx">address</span><span class="p">;</span>
</pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Managed objects need to be registered - this causes them to be persisted.
View
28 docs/example-read-database.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html> <html> <head> <title>example-read-database.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-create-database.html"> example-create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="example-read-database.html"> example-read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> example-read-database.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
+Released under the MIT open source licence.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">bdb</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;barricane-db&#39;</span><span class="p">)</span>
+ <span class="p">,</span> <span class="nx">model</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./example-model&#39;</span><span class="p">)</span>
+ <span class="p">;</span>
+ </pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Create a database instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">db</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">bdb</span><span class="p">.</span><span class="nx">DB</span><span class="p">({</span><span class="nx">path</span><span class="o">:</span> <span class="s1">&#39;/tmp&#39;</span><span class="p">,</span> <span class="nx">name</span><span class="o">:</span> <span class="s1">&#39;test_db&#39;</span><span class="p">});</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Make the database available globally with the process. If you don't do this,
+you can manually inject the database into appropriate constructors, or call
+<code>DB.registerInstance(instance)</code> every time you create an object. </p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">process</span><span class="p">.</span><span class="nx">db</span> <span class="o">=</span> <span class="nx">db</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Your application must tell the DB about the constructors, before you ever
+open a previously existing database. This could be done in example-model.js,
+but the application would have to delay requiring 'example-model' until
+process.db was created.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">db</span><span class="p">.</span><span class="nx">registerConstructors</span><span class="p">(</span><span class="nx">model</span><span class="p">.</span><span class="nx">House</span><span class="p">,</span> <span class="nx">model</span><span class="p">.</span><span class="nx">Person</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Open the database for business.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">db</span><span class="p">.</span><span class="nx">openSync</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Find Fred</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">fred</span> <span class="o">=</span> <span class="nx">db</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s1">&#39;personalName&#39;</span><span class="p">,</span> <span class="s1">&#39;Fred&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">];</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Print out the values we read.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">fred</span><span class="p">.</span><span class="nx">familyName</span><span class="p">);</span>
+<span class="cm">/* --&gt; &#39;Flintstone&#39; */</span>
+
+<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">fred</span><span class="p">.</span><span class="nx">spouse</span><span class="p">.</span><span class="nx">personalName</span><span class="p">);</span>
+<span class="cm">/* --&gt; &#39;Wilma&#39; */</span>
+
+<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">fred</span><span class="p">.</span><span class="nx">spouse</span><span class="p">.</span><span class="nx">spouse</span><span class="p">.</span><span class="nx">personalName</span><span class="p">);</span>
+<span class="cm">/* --&gt; &#39;Fred&#39; */</span>
+
+<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">fred</span><span class="p">.</span><span class="nx">house</span><span class="p">.</span><span class="nx">address</span><span class="p">);</span>
+<span class="cm">/* --&gt; &#39;301 Cobblestone Wy., Bedrock, 70777&#39; */</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Finally, close the database.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">db</span><span class="p">.</span><span class="nx">end</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">result</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;database has persisted successfully&#39;</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;error:&#39;</span><span class="p">,</span> <span class="nx">error</span><span class="p">);</span>
+ <span class="p">}</span>
+<span class="p">});</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
2 docs/old-barricane-db.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html> <html> <head> <title>old-barricane-db.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="create-database.html"> create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="read-database.html"> read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> old-barricane-db.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">uuid</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;node-uuid&#39;</span><span class="p">)</span>
+<!DOCTYPE html> <html> <head> <title>old-barricane-db.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-create-database.html"> example-create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="example-read-database.html"> example-read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> old-barricane-db.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">uuid</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;node-uuid&#39;</span><span class="p">)</span>
<span class="nx">exports</span><span class="p">.</span><span class="nx">hello_world</span> <span class="o">=</span> <span class="s2">&quot;Hello World&quot;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>newClosure([args... ,] function<em>to</em>call)</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">newClosure</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">);</span>
View
2 docs/serialisation.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html> <html> <head> <title>serialisation.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="create-database.html"> create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="read-database.html"> read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> serialisation.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
+<!DOCTYPE html> <html> <head> <title>serialisation.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-create-database.html"> example-create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="example-read-database.html"> example-read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> serialisation.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<span class="cm"> * Serialisation (yes, I&#39;m English)</span>
<span class="cm"> * Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.</span>
<span class="cm"> * Released under the MIT open source licence.</span>
View
2 docs/swoj-codec.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html> <html> <head> <title>swoj-codec.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="create-database.html"> create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="read-database.html"> read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> swoj-codec.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
+<!DOCTYPE html> <html> <head> <title>swoj-codec.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-create-database.html"> example-create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="example-read-database.html"> example-read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> swoj-codec.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
Released under the MIT open source licence.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>This module contains my first attempt at Serialisation/Unserialisation code.
SWOJ is Simple Whole Object JSON.</p> </td> <td class="code"> <div class="highlight"><pre> </pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Other codecs could improve on this by serialising deltas or using a binary
format.</p> </td> <td class="code"> <div class="highlight"><pre> </pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>The codec system is designed to become pluggable - i.e. a database may be
View
2 docs/util.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html> <html> <head> <title>util.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="create-database.html"> create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="read-database.html"> read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> util.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
+<!DOCTYPE html> <html> <head> <title>util.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-create-database.html"> example-create-database.js </a> <a class="source" href="example-model.html"> example-model.js </a> <a class="source" href="example-read-database.html"> example-read-database.js </a> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="swoj-codec.html"> swoj-codec.js </a> <a class="source" href="util.html"> util.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> util.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
Released under the MIT open source licence.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>This is the obligatory dumping ground modules for all those bits which don't
fit well elsewhere.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>This finds all the objects keys.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">ownKeys</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">accumulator</span> <span class="o">=</span> <span class="p">[];</span>
View
2 examples/create-database.js → examples/example-create-database.js
@@ -36,7 +36,7 @@ wilma.spouse = fred;
// No save() needed - persistence is implicit.
-// This synchronously waits for all writes to complete.
+// Finally, close the database.
db.end(function(err, result) {
if (!err) {
console.log('database has persisted successfully');
View
10 examples/read-database.js → examples/example-read-database.js
@@ -38,5 +38,11 @@ console.log(fred.spouse.spouse.personalName);
console.log(fred.house.address);
/* --> '301 Cobblestone Wy., Bedrock, 70777' */
-// This synchronously waits for all writes to complete.
-db.endSync();
+// Finally, close the database.
+db.end(function(err, result) {
+ if (!err) {
+ console.log('database has persisted successfully');
+ } else {
+ console.log('error:', error);
+ }
+});
View
15 lib/db.js
@@ -68,21 +68,24 @@ DB.prototype.openSync = function() {
// This must be called once for every instance which needs to be persisted.
// It is idiomatic to do this in the constructor, using a global
// <code>process.db</code> database.
-DB.prototype.registerInstance = function(instance) {
+DB.prototype.registerInstance = function(instance, force) {
var that = this;
+
+ // Skip register instance at this stage, unless forced.
+ if (!this.persist && !force) {
+ return;
+ }
- instance[this.UUID_TAG] = this.uuid();
-
+ // Only create a new UUID if one does not exist.
+ instance[this.UUID_TAG] = instance[this.UUID_TAG] || this.uuid();
+
this.instances[instance[this.UUID_TAG]] = instance;
var store = {}; // the backing store for the instance data
this.stores[instance[this.UUID_TAG]] = store;
- console.log("about to create setters");
util.ownRealKeys(instance, this.magic).forEach(function(p, i, all) {
store[p] = instance[p];
- console.log("creatig setter", p);
instance.__defineSetter__(p, function(val) {
- console.log("setter called", JSON.stringify(that.persist));
store[p] = val;
if (that.persist) {
that.io.persist(instance);
View
23 lib/disk-io.js
@@ -17,6 +17,7 @@ function DiskIO(options, db) {
this.path = options.path || '/tmp';
this.name = options.name || 'unnamed_db';
this.codec = options.codec || new codec.Codec(options.magic);
+ this.magic = options.magic || '__';
this.db = db;
// Psuedo constants.
@@ -42,7 +43,6 @@ function DiskIO(options, db) {
// This writes an object to disk.
DiskIO.prototype.persist = function (instance) {
- console.log("persisting");
var that = this;
this.outstandingWrites++;
@@ -65,11 +65,8 @@ DiskIO.prototype.openSync = function() {
// If there's a pre-existing file, we move it to old then read in the
// contents later.
- console.log("about to rename");
for (var i in contents) {
if (contents[i] === this.FILENAME) {
- console.log("renaming ", this.path + "/" + this.FILENAME,
- "to", this.path + "/" + this.OLD_FILENAME);
fs.renameSync(this.path + "/" + this.FILENAME,
this.path + "/" + this.OLD_FILENAME);
preexisting = true;
@@ -87,23 +84,20 @@ DiskIO.prototype.openSync = function() {
// This loads a database from disk.
DiskIO.prototype._load = function(filepath) {
- //this.oldFd = fs.openSync(filepath, 'r');
// FIXME: we need to do this incrementally, for large databases.
var data = fs.readFileSync(filepath, 'utf8');
- console.log("data", data);
var lines = data.split('\n');
for (var i in lines) {
- console.log("line", "|" + lines[i] + "|");
if (lines[i] === "") {
continue;
}
+ // FIXME: We should do something about an exception here, if the
+ // database file was truncated.
var object = this.codec.deserialise(lines[i], this.db.constructors);
- console.log("object", JSON.stringify(object));
- console.log("this.UUID_TAG", JSON.stringify(this.UUID_TAG));
- console.log("object[this.UUID_TAG]", JSON.stringify(object[this.UUID_TAG]));
- this.db.instances[object[this.UUID_TAG]] = object;
- console.log("instances", JSON.stringify(this.db.instances));
- process.exit(0);
+
+ // Forcing this registration is required, as db.persist is currently
+ // false.
+ this.db.registerInstance(object, true);
}
this.codec.fixRefs(this.db.instances);
}
@@ -114,7 +108,6 @@ DiskIO.prototype._load = function(filepath) {
DiskIO.prototype.deleteSync = function() {
// First get the contents of the path.
var contents = fs.readdirSync(this.path);
- console.log('contents:', contents);
for (var i in contents) {
if (contents[i] === this.FILENAME) {
fs.renameSync(this.path + "/" + this.FILENAME,
@@ -129,7 +122,7 @@ DiskIO.prototype.deleteSync = function() {
DiskIO.prototype.end = function(callback) {
if (this.outstandingWrites === 0) {
- fd.end(); // FIXME: we need to call the callback only after the end.
+ this.writeStream.end(); // FIXME: we need to call the callback only after the end.
callback(false, '');
}
this.ending = callback;

0 comments on commit 1d8ead1

Please sign in to comment.
Something went wrong with that request. Please try again.