  

  


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
        <title>Home - dm.js - GitHub</title>
    <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="GitHub" />
    <link rel="fluid-icon" href="http://github.com/fluidicon.png" title="GitHub" />


    <link href="http://assets3.github.com/stylesheets/bundle_common.css?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" media="screen" rel="stylesheet" type="text/css" />
<link href="http://assets2.github.com/stylesheets/bundle_github.css?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" media="screen" rel="stylesheet" type="text/css" />

    <script type="text/javascript" charset="utf-8">
      var GitHub = {}
      var github_user = null
    </script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
    <script src="http://assets1.github.com/javascripts/bundle_common.js?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" type="text/javascript"></script>
<script src="http://assets2.github.com/javascripts/bundle_github.js?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" type="text/javascript"></script>

    <script type="text/javascript" charset="utf-8">
      GitHub.spy({
        repo: "darthapo/dm.js"
      })
    </script>

    
  <link href="http://github.com/feeds/darthapo/commits/dm.js/master" rel="alternate" title="Recent Commits to dm.js:master" type="application/atom+xml" />

    <meta name="description" content="DM.js is a simple JavaScript ORM (loosely based on ActiveRecord) that supports the following sqlite browser backends: Safari/HTML5, Adobe Air, and Google Gears." />
    <script type="text/javascript">
      GitHub.nameWithOwner = GitHub.nameWithOwner || "darthapo/dm.js";
      GitHub.currentRef = "master";    
    </script>
  

    
  </head>

  

  <body>
    

    <div id="main">
      <div id="header" class="">
        <div class="site">
          <div class="logo">
            <a href="http://github.com"><img src="/images/modules/header/logov3.png" alt="github" /></a>
          </div>
          
          <div class="topsearch">
  
    <form action="http://github.com/search" id="top_search_form" method="get">
      <a href="http://github.com/search" class="advanced-search tooltipped downwards" title="Advanced Search">Advanced Search</a>
      <input type="search" class="search repo_autocompleter" name="q" results="5" placeholder="Search GitHub&hellip;" /> <input type="submit" value="Search", class="button" />
      <input type="hidden" name="type" value="Everything" />
      <input type="hidden" name="repo" value="" />
      <input type="hidden" name="langOverride" value="" />
      <input type="hidden" name="start_value" value="1" />
    </form>
  
  
    <ul class="nav logged_out">
      
        <li><a href="http://github.com">Home</a></li>
        <li class="pricing"><a href="http://github.com/plans">Pricing and Signup</a></li>
        <li><a href="http://github.com/popular/forked">Explore GitHub</a></li>
        
        <li><a href="/blog">Blog</a></li>
      
      <li></li>
    </ul>
  
</div>
        </div>
      </div>

      
        
      <div id="repo_menu">
        <div class="site">
          <ul>
            
              <li class=""><a href="http://github.com/darthapo/dm.js/tree/master">Source</a></li>

              <li class=""><a href="http://github.com/darthapo/dm.js/commits/master">Commits</a></li>

              
              <li class=""><a href="http://github.com/darthapo/dm.js/network">Network</a></li>

              

              
                
                
              

              
                
                <li class=""><a href="http://github.com/darthapo/dm.js/downloads">Downloads</a></li>
              

              
                
                <li class="active"><a href="http://wiki.github.com/darthapo/dm.js">Wiki</a></li>
              

              <li class=""><a href="http://github.com/darthapo/dm.js/graphs">Graphs</a></li>

              

            
          </ul>
        </div>
      </div>

    <div id="repo_sub_menu">
      <div class="site">
        <div class="joiner"></div>
        

        

        

        
      </div>
    </div>

    <div class="site">
      



<div id="repos">
  


<script type="text/javascript">
  GitHub.currentCommitRef = "master"
  GitHub.currentRepoOwner = "darthapo"
  GitHub.currentRepo = "dm.js"
  
</script>



  <div class="repo public" id="repo_details">
    <div class="title">
      <div class="path">
        <a href="/darthapo">darthapo</a> / <b><a href="http://github.com/darthapo/dm.js">dm.js</a></b>

        

          <span id="edit_button" style="display:none;">
            <a href="/darthapo/dm.js/edit"><img alt="edit" class="button" src="http://assets2.github.com/images/modules/repos/edit_button.png?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" /></a>
          </span>

          
            <span id="pull_request_button" style="display:none;">
              <a href="/darthapo/dm.js/pull_request/" class="pull_request_button"><img alt="pull request" class="button" src="http://assets1.github.com/images/modules/repos/pull_request_button.png?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" /></a>
            </span>

            <span id="fork_button">
              <form method="POST" action="/darthapo/dm.js/fork" style="display:inline;">
                <input alt="fork" class="button" src="http://assets2.github.com/images/modules/repos/fork_button.png?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" type="image" />
              </form>
            </span>
          

          <span id="watch_button">
            <a href="/darthapo/dm.js/toggle_watch" class="toggle_watch"><img alt="watch" class="button" src="http://assets1.github.com/images/modules/repos/watch_button.png?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" /></a>
          </span>

          <span id="unwatch_button" style="display:none;">
            <a href="/darthapo/dm.js/toggle_watch" class="toggle_watch"><img alt="watch" class="button" src="http://assets0.github.com/images/modules/repos/unwatch_button.png?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" /></a>
          </span>

          
            <a href="/darthapo/dm.js/archives/master" id="download_button">
              <img alt="download tarball" class="button" src="http://assets0.github.com/images/modules/repos/download_button.png?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" />
            </a>
          
        
      </div>

      <div class="security private_security" style="display:none">
        <a href="#private_repo" rel="facebox"><img src="/images/icons/private.png" alt="private" /></a>
      </div>

      <div id="private_repo" class="hidden">
        This repository is private.
        All pages are served over SSL and all pushing and pulling is done over SSH.
        No one may fork, clone, or view it unless they are added as a <a href="/darthapo/dm.js/edit">member</a>.

        <br/>
        <br/>
        Every repository with this icon (<img src="/images/icons/private.png" alt="private" />) is private.
      </div>

      <div class="security public_security" style="">
        <a href="#public_repo" rel="facebox"><img src="/images/icons/public.png" alt="public" /></a>
      </div>

      <div id="public_repo" class="hidden">
        This repository is public.
        Anyone may fork, clone, or view it.

        <br/>
        <br/>
        Every repository with this icon (<img src="/images/icons/public.png" alt="public" />) is public.
      </div>

      

        <div class="flexipill">
          <a href="/darthapo/dm.js/network">
          <table cellpadding="0" cellspacing="0">
            <tr><td><img alt="Forks" src="http://assets2.github.com/images/modules/repos/pills/forks.png?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" /></td><td class="middle"><span>0</span></td><td><img alt="Right" src="http://assets3.github.com/images/modules/repos/pills/right.png?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" /></td></tr>
          </table>
          </a>
        </div>

        <div class="flexipill">
          <a href="/darthapo/dm.js/watchers">
          <table cellpadding="0" cellspacing="0">
            <tr><td><img alt="Watchers" src="http://assets2.github.com/images/modules/repos/pills/watchers.png?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" /></td><td class="middle"><span>8</span></td><td><img alt="Right" src="http://assets3.github.com/images/modules/repos/pills/right.png?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" /></td></tr>
          </table>
          </a>
        </div>
      </div>

    <div class="meta">
      <table>
        
        <tr>
          <td class="label" style="vertical-align:top">Description:</td>
          <td>
            <span id="repository_description" rel="/darthapo/dm.js/edit/update">DM.js is a simple JavaScript ORM (loosely based on ActiveRecord) that supports the following sqlite browser backends: Safari/HTML5, Adobe Air, and Google Gears.</span>
            <a href="#description" class="edit_link action" style="display:none;">edit</a>
          </td>
        </tr>

        
      </table>

          </div>
  </div>






</div>

<div id="guides">
  <div class="guide">
    <!-- main content -->
    
    <div class="main">

      
        <div class="actions">
          <a href="http://wiki.github.com/darthapo/dm.js">Home</a> 
          | <a href="http://github.com/darthapo/dm.js/wikis/home/edit">Edit</a> | 
          <a href="http://github.com/darthapo/dm.js/wikis/new">New</a>
        </div>
      

      <h1>Home</h1>

      <div class="wikistyle">
        <p>DM.js is a simple JavaScript <span class="caps">ORM</span> (loosely based on ActiveRecord) that supports the following sqlite browser backends: Safari/HTML5, Adobe Air, and Google Gears.</p>
<p>This project is still in the early phases.</p>
<h2>What Works</h2>
<ul>
	<li><span class="caps">HTML</span> 5 and Google Gear back-ends</li>
	<li>Simple models and schema generator</li>
	<li>Base <span class="caps">CRUD</span> on models</li>
	<li>Event callbacks for beforeCreate, afterCreate, beforeSave, and afterSave</li>
</ul>
<h2>What Doesn&#8217;t Work (Yet)</h2>
<ul>
	<li>Adobe <span class="caps">AIR</span> back-end</li>
	<li>Relationships (planned: hasMany, hasAndBelongsToMany, hasOne, belongsTo)</li>
	<li>Finder <span class="caps">WHERE</span> clauses</li>
</ul>
<h1>Example Usage</h1>
<p>In your application&#8217;s initialization, you&#8217;ll need to create the database object:</p>
// the variable name doesn&#8217;t matter&#8230;
var DB = new DM.Database({
name:        &#8216;GraphicNovelist.db&#8217;,
displayName: &#8216;Graphic Novelist&#8217;,
description: &#8216;Graphic Novelist database&#8230; What?&#8217;
});

<p>Now you can define your models:</p>
var Script = new DM.Model(&#8216;scripts&#8217;, {

// This is the schema builder function you&#8217;ll need to fill out&#8230;
schema: function(t){
// An id field is automatically created for models
t.text(&#8216;title&#8217;);
t.text(&#8216;source&#8217;);
t.text(&#8216;html&#8217;);
// Creates created_on &amp;&amp; updated_on
t.timestamps(&#8216;on&#8217;);

// Not implemented yet, but this is how it&#8217;ll probably work&#8230;
t.hasMany(&#8216;Revision&#8217;, { cascadeDelete:true });

t.beforeSave(function(self){
// use model#get and model#set to access attributes&#8230;
var renderedSource = GraphicNovelist.render( self.get(&#8216;source&#8217;) );
self.set(&#8216;html&#8217;, renderedSource );
})
}

// Any model instance methods you&#8217;d like here&#8230;
});
<p>Creating a model instance:</p>
var script = Script.create({ title:&#8220;A new title!&#8221; });
<p>Typical model kinds of things to do:</p>
script.save();
script.destroy();

Script.all(function(allScripts){
// Since the HTML5 back-end is strictly asynchronous all
// database access methods require callbacks to work with
// the fetched models&#8230;

allScripts.each(function(script){
// build <span class="caps">DOM</span> nodes, or whatever else you&#8217;d like&#8230;
})
});

Script.find(1, function(script){
// Script 1 stuff here&#8230;
});

<h1>Todo</h1>
<ul>
	<li>Need <span class="caps">WHERE</span> builder so finders can actually be useful</li>
	<li>Tests, tests, and more tests!</li>
</ul>
      </div>
    </div>
    
    <!-- sidebar -->
    
    <div class="sidebar">
      <h3> 
        Pages 
        <a href="http://wiki.github.com/darthapo/dm.js/wikis.atom"><img alt="feed" src="http://assets3.github.com/images/icons/feed.png?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" title="Feed of recent dm.js wiki edits" /></a>
      </h3>
      
<!--# block name="pages" -->
      <ul>
  
    <li><b><a href="http://wiki.github.com/darthapo/dm.js">Home</a></b></li>
  
</ul>

<!--# endblock -->

<!--# include virtual="/darthapo/dm.js/_all_pages" stub="pages" -->
      
    </div>

  </div>
  
  <!-- admin -->
    
  
    <div class="admin">
      <div style="float:left;">
        <small>Last edited by <b>darthapo</b>, <abbr class="relatize" title="2008-09-02 23:12:57">Tue Sep 02 23:12:57 -0700 2008</abbr></small>

        <div class="actions">
          <a href="http://wiki.github.com/darthapo/dm.js">Home</a> 
          | <a href="http://github.com/darthapo/dm.js/wikis/home/edit">Edit</a> | 
          <a href="http://github.com/darthapo/dm.js/wikis/new">New</a>
        </div>
      </div>

      <div style="float:right;">
        <small>Versions:</small>
        <select id="versions_select" name="versions_select"><option value="http://github.com/darthapo/dm.js/wikis/home">Current</option><option value="http://wiki.github.com/darthapo/dm.js/home/2">Version 2 by darthapo</option><option value="http://wiki.github.com/darthapo/dm.js/home/1">Version 1 by darthapo</option></select>
      </div>
    </div>
      
</div>



    </div>
  
      

      <div class="push"></div>
    </div>

    <div id="footer">
      <div class="site">
        <div class="info">
          <div class="links">
            <a href="http://github.com/blog"><b>Blog</b></a> |
            <a href="http://support.github.com/">Support</a> |
            <a href="http://github.com/training">Training</a> |
            <a href="http://github.com/contact">Contact</a> |
            <a href="http://develop.github.com">API</a> |
            <a href="http://twitter.com/github">Status</a> |
            <a href="http://twitter.com/github">Twitter</a> |
            <a href="http://help.github.com">Help</a> |
            <a href="http://github.com/security">Security</a>
          </div>
          <div class="company">
            <span id="_rrt" title="0.05991s from fe1.rs.github.com">GitHub</span>&trade;
            is <a href="http://logicalawesome.com/" title="Just Awesome">Logical Awesome</a> &copy;2009 | <a href="/site/terms">Terms of Service</a> | <a href="/site/privacy">Privacy Policy</a>
          </div>
        </div>
        <div class="sponsor">
          <div>
            Powered by the <a href="http://www.rackspace.com ">Dedicated
            Servers</a> and<br/> <a href="http://www.rackspacecloud.com">Cloud
            Computing</a> of Rackspace Hosting<span>&reg;</span>
          </div>
          <a href="http://www.rackspace.com">
            <img alt="Dedicated Server" src="http://assets1.github.com/images/modules/footer/rackspace_logo.png?8099668d2dbaf40ae5ccf46dce0aa69bfc5896be" />
          </a>
        </div>
      </div>
    </div>

    <div id="coming_soon" style="display:none;">
      This feature is coming soon.  Sit tight!
    </div>

    
        <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-3769691-2");
    pageTracker._initData();
    pageTracker._trackPageview();
    </script>

    
  </body>
</html>

