Permalink
Browse files

broken

  • Loading branch information...
1 parent 500a3f2 commit 952bd1b256d24323e28913b48789fd6be6d4c4cd chrisdew committed Feb 9, 2011
@@ -1,19 +1,20 @@
<!DOCTYPE html> <html> <head> <title>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="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> 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>Import the model, now that we have defined <code>process.db</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</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></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Delete any database of the same path and name. Most applications will never
+<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-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>process.exit(0);</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Open the database for business. Most once-per-process methods of DB are
+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-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#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>
+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-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#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-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>This synchronously waits for all writes to complete.</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="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>This synchronously waits for all writes to complete.</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>
Oops, something went wrong.

0 comments on commit 952bd1b

Please sign in to comment.