Giter VIP home page Giter VIP logo

dm.js's Introduction

DM.js

Requires Prototype 1.6+!

This project is still in the early phases.

What Works

  • HTML 5 and Google Gear back-ends
  • Simple models and schema generator
  • Base CRUD on models
  • Event callbacks for beforeCreate, afterCreate, beforeSave, and afterSave
  • Rudimentary Dataset class good for filtered reading of tables...

What Doesn't Work (Yet)

  • Adobe AIR back-end
  • Relationships (planned: hasMany, hasAndBelongsToMany, hasOne, belongsTo)
  • Finder WHERE clauses

Example Usage

In your application's initialization, you'll need to create the database object:

// the variable name doesn't matter...
var DB = new DM.Database({
  name:        'GraphicNovelist.db',
  displayName: 'Graphic Novelist',
  description: 'Graphic Novelist database... What?'
});

Now you can define your models:

var Script = new DM.Model('scripts', {
  
  // This is the schema builder function you'll need to fill out...
  schema: function(t){ 
    // An id field is automatically created for models
    t.text('title');
    t.text('source');
    t.text('html');
    // Creates created_on && updated_on
    t.timestamps('on');
    
    // Not implemented yet, but this is how it'll probably work...
    t.hasMany('Revision', { cascadeDelete:true });
    
    t.beforeSave(function(self){
      // use model#get and model#set to access attributes...
      var renderedSource = GraphicNovelist.render( self.get('source') );
      self.set('html', renderedSource );
    })
  }

  // Any model instance methods you'd like here...
});

After you've defined/included all of your models:

DM.Model.createModels(); // Executes CREATE TABLE IF EXISTS for each model's schema...

Creating a model instance:

var script = Script.create({ title:"A new title!" });

Typical model kinds of things to do:

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... 
  
  allScripts.each(function(script){
    // build DOM nodes, or whatever else you'd like...
  })
});

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

Todo

  • Need WHERE builder so finders can actually be useful
  • Tests, tests, and more tests!

dm.js's People

Contributors

mattmccray avatar

Stargazers

 avatar Angus H. avatar  avatar Luca avatar yohei sugigami avatar Ahmad Rizqi Meydiarso avatar Jonathan Rudenberg avatar Sandro Turriate avatar  avatar  avatar Norio Shimizu avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

galexcode

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.